From 76c07b1ec72033d05a4dd54360451f6492c2a31e Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 30 May 2014 17:44:24 +0200 Subject: Added a cChunkData::CopyBlockTypes() unit test. --- tests/ChunkData/CopyBlocks.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/ChunkData/CopyBlocks.cpp (limited to 'tests/ChunkData/CopyBlocks.cpp') diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp new file mode 100644 index 000000000..d132411db --- /dev/null +++ b/tests/ChunkData/CopyBlocks.cpp @@ -0,0 +1,65 @@ + +// CopyBlocks.cpp + +// Implements the test for cChunkData::CopyBlockTypes() range copying + + + + + +#include "Globals.h" +#include "ChunkData.h" + + + + + +int main(int argc, char ** argv) +{ + // Set up a cChunkData with known contents - all blocks 0x01, all metas 0x02: + cChunkData Data; + 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]; + memset(TestBuffer, 0x03, sizeof(TestBuffer)); + for (size_t idx = 0; idx < 5000; idx++) + { + for (size_t len = 1; len < 1000; len += 15) + { + printf("Testing copying %u blocks from index %u\n", (unsigned)len, (unsigned)idx); + + Data.CopyBlockTypes(WritePosition, idx, len); + + // Verify the data copied: + for (size_t i = 0; i < len; i++) + { + assert_test(WritePosition[i] == 0x01); + } + // Verify the space before the copied data hasn't been changed: + for (size_t i = 0; i < WritePosIdx + idx; i++) + { + assert_test(TestBuffer[i] == 0x03); + } + // Verify the space after the copied data hasn't been changed: + for (size_t i = WritePosIdx + idx + len; i < ARRAYCOUNT(TestBuffer); i++) + { + assert_test(TestBuffer[i] == 0x03); + } + } + } // for idx + return 0; +} + + + + + -- cgit v1.2.3 From cbb9e152577e3db07832b96583f0ab0618d0d983 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 30 May 2014 17:13:36 +0100 Subject: Fix bugs in test --- tests/ChunkData/CopyBlocks.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/ChunkData/CopyBlocks.cpp') diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp index d132411db..b31ce3c63 100644 --- a/tests/ChunkData/CopyBlocks.cpp +++ b/tests/ChunkData/CopyBlocks.cpp @@ -30,12 +30,14 @@ int main(int argc, char ** argv) BLOCKTYPE TestBuffer[5 * cChunkDef::NumBlocks]; size_t WritePosIdx = 2 * cChunkDef::NumBlocks; BLOCKTYPE * WritePosition = &TestBuffer[WritePosIdx]; - memset(TestBuffer, 0x03, sizeof(TestBuffer)); for (size_t idx = 0; idx < 5000; idx++) { for (size_t len = 1; len < 1000; len += 15) { - printf("Testing copying %u blocks from index %u\n", (unsigned)len, (unsigned)idx); + //printf("Testing copying %u blocks from index %u\n", (unsigned)len, (unsigned)idx); + + //initalize buffer + memset(TestBuffer, 0x03, sizeof(TestBuffer)); Data.CopyBlockTypes(WritePosition, idx, len); @@ -45,7 +47,7 @@ int main(int argc, char ** argv) assert_test(WritePosition[i] == 0x01); } // Verify the space before the copied data hasn't been changed: - for (size_t i = 0; i < WritePosIdx + idx; i++) + for (size_t i = 0; i < WritePosIdx; i++) { assert_test(TestBuffer[i] == 0x03); } -- cgit v1.2.3 From f2470ff7c11fc8226b20a5d53f5a4e8ee0e8454e Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 30 May 2014 18:32:15 +0200 Subject: Reduced the number of cChunkData::CopyBlockTypes() tests, added progress. --- tests/ChunkData/CopyBlocks.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'tests/ChunkData/CopyBlocks.cpp') diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp index b31ce3c63..be8cab234 100644 --- a/tests/ChunkData/CopyBlocks.cpp +++ b/tests/ChunkData/CopyBlocks.cpp @@ -30,15 +30,18 @@ int main(int argc, char ** argv) BLOCKTYPE TestBuffer[5 * cChunkDef::NumBlocks]; size_t WritePosIdx = 2 * cChunkDef::NumBlocks; BLOCKTYPE * WritePosition = &TestBuffer[WritePosIdx]; - for (size_t idx = 0; idx < 5000; idx++) + memset(TestBuffer, 0x03, sizeof(TestBuffer)); + size_t LastReportedStep = 1; + for (size_t idx = 0; idx < 5000; idx += 7) { - for (size_t len = 1; len < 1000; len += 15) + if (idx / 500 != LastReportedStep) { - //printf("Testing copying %u blocks from index %u\n", (unsigned)len, (unsigned)idx); - - //initalize buffer - memset(TestBuffer, 0x03, sizeof(TestBuffer)); + printf("Testing index %u...\n", (unsigned)idx); + LastReportedStep = idx / 500; + } + for (size_t len = 3; len < 1000; len += 13) + { Data.CopyBlockTypes(WritePosition, idx, len); // Verify the data copied: @@ -56,7 +59,13 @@ int main(int argc, char ** argv) { assert_test(TestBuffer[i] == 0x03); } - } + + // Re-initialize the buffer for the next test: + for (size_t i = 0; i < len; i++) + { + WritePosition[i] = 0x03; + } + } // for len } // for idx return 0; } -- cgit v1.2.3 From ee50790398791c38e563eee04cf12780fab74baf Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 16 Jun 2014 15:12:50 +0100 Subject: Merge branch 'master' of github.com:mc-server/MCServer --- tests/ChunkData/CopyBlocks.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'tests/ChunkData/CopyBlocks.cpp') diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp index be8cab234..ec9451099 100644 --- a/tests/ChunkData/CopyBlocks.cpp +++ b/tests/ChunkData/CopyBlocks.cpp @@ -17,7 +17,20 @@ int main(int argc, char ** argv) { // Set up a cChunkData with known contents - all blocks 0x01, all metas 0x02: - cChunkData Data; + class cMockAllocationPool + : public cAllocationPool + { + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; + cChunkData Data(Pool); cChunkDef::BlockTypes BlockTypes; cChunkDef::BlockNibbles BlockMetas; memset(BlockTypes, 0x01, sizeof(BlockTypes)); -- cgit v1.2.3