2014-05-30 11:44:24 -04:00
|
|
|
|
|
|
|
// CopyBlocks.cpp
|
|
|
|
|
|
|
|
// Implements the test for cChunkData::CopyBlockTypes() range copying
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Globals.h"
|
2019-08-26 15:38:34 -04:00
|
|
|
#include "../TestHelpers.h"
|
2014-05-30 11:44:24 -04:00
|
|
|
#include "ChunkData.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-26 15:38:34 -04:00
|
|
|
/** Performs the entire CopyBlocks test. */
|
|
|
|
static void test()
|
2014-05-30 11:44:24 -04:00
|
|
|
{
|
|
|
|
// Set up a cChunkData with known contents - all blocks 0x01, all metas 0x02:
|
2014-06-16 10:12:50 -04:00
|
|
|
class cMockAllocationPool
|
|
|
|
: public cAllocationPool<cChunkData::sChunkSection>
|
2018-07-23 14:12:51 -04:00
|
|
|
{
|
|
|
|
virtual cChunkData::sChunkSection * Allocate() override
|
2014-06-16 10:12:50 -04:00
|
|
|
{
|
|
|
|
return new cChunkData::sChunkSection();
|
|
|
|
}
|
2018-07-23 14:12:51 -04:00
|
|
|
|
|
|
|
virtual void Free(cChunkData::sChunkSection * a_Ptr) override
|
2014-06-16 10:12:50 -04:00
|
|
|
{
|
|
|
|
delete a_Ptr;
|
|
|
|
}
|
2018-07-23 14:12:51 -04:00
|
|
|
|
2020-05-10 12:16:38 -04:00
|
|
|
virtual bool DoIsEqual(const cAllocationPool<cChunkData::sChunkSection> &) const noexcept override
|
2018-07-23 14:12:51 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-16 10:12:50 -04:00
|
|
|
} Pool;
|
|
|
|
cChunkData Data(Pool);
|
2014-05-30 11:44:24 -04:00
|
|
|
cChunkDef::BlockTypes BlockTypes;
|
|
|
|
cChunkDef::BlockNibbles BlockMetas;
|
|
|
|
memset(BlockTypes, 0x01, sizeof(BlockTypes));
|
|
|
|
memset(BlockMetas, 0x02, sizeof(BlockMetas));
|
|
|
|
Data.SetBlockTypes(BlockTypes);
|
|
|
|
Data.SetMetas(BlockMetas);
|
|
|
|
|
|
|
|
// Try to read varying amounts of blocktypes from the cChunkData.
|
|
|
|
// Verify that the exact amount of memory is copied, by copying to a larger buffer and checking its boundaries
|
|
|
|
BLOCKTYPE TestBuffer[5 * cChunkDef::NumBlocks];
|
|
|
|
size_t WritePosIdx = 2 * cChunkDef::NumBlocks;
|
|
|
|
BLOCKTYPE * WritePosition = &TestBuffer[WritePosIdx];
|
2014-05-30 12:32:15 -04:00
|
|
|
memset(TestBuffer, 0x03, sizeof(TestBuffer));
|
|
|
|
size_t LastReportedStep = 1;
|
2014-09-01 15:31:27 -04:00
|
|
|
for (size_t idx = 0; idx < 5000; idx += 73)
|
2014-05-30 11:44:24 -04:00
|
|
|
{
|
2014-05-30 12:32:15 -04:00
|
|
|
if (idx / 500 != LastReportedStep)
|
2014-05-30 11:44:24 -04:00
|
|
|
{
|
2016-08-24 15:45:03 -04:00
|
|
|
printf("Testing index %u...\n", static_cast<unsigned>(idx));
|
2014-05-30 12:32:15 -04:00
|
|
|
LastReportedStep = idx / 500;
|
|
|
|
}
|
2014-05-30 11:44:24 -04:00
|
|
|
|
2014-09-01 15:31:27 -04:00
|
|
|
for (size_t len = 3; len < 700; len += 13)
|
2014-05-30 12:32:15 -04:00
|
|
|
{
|
2014-05-30 11:44:24 -04:00
|
|
|
Data.CopyBlockTypes(WritePosition, idx, len);
|
|
|
|
|
|
|
|
// Verify the data copied:
|
|
|
|
for (size_t i = 0; i < len; i++)
|
|
|
|
{
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(WritePosition[i], 0x01);
|
2014-05-30 11:44:24 -04:00
|
|
|
}
|
|
|
|
// Verify the space before the copied data hasn't been changed:
|
2014-05-30 12:13:36 -04:00
|
|
|
for (size_t i = 0; i < WritePosIdx; i++)
|
2014-05-30 11:44:24 -04:00
|
|
|
{
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(TestBuffer[i], 0x03);
|
2014-05-30 11:44:24 -04:00
|
|
|
}
|
|
|
|
// Verify the space after the copied data hasn't been changed:
|
|
|
|
for (size_t i = WritePosIdx + idx + len; i < ARRAYCOUNT(TestBuffer); i++)
|
|
|
|
{
|
2019-08-26 15:38:34 -04:00
|
|
|
TEST_EQUAL(TestBuffer[i], 0x03);
|
2014-05-30 11:44:24 -04:00
|
|
|
}
|
2014-05-30 12:32:15 -04:00
|
|
|
|
|
|
|
// Re-initialize the buffer for the next test:
|
|
|
|
for (size_t i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
WritePosition[i] = 0x03;
|
|
|
|
}
|
|
|
|
} // for len
|
2014-05-30 11:44:24 -04:00
|
|
|
} // for idx
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-26 15:38:34 -04:00
|
|
|
IMPLEMENT_TEST_MAIN("ChunkData CopyBlocks",
|
|
|
|
test()
|
|
|
|
)
|