summaryrefslogtreecommitdiffstats
path: root/tests/ChunkData/CopyBlocks.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-06-01 10:43:37 +0200
committerMattes D <github@xoft.cz>2014-06-01 10:43:37 +0200
commit2059944d1e39e952c164b8a87c0c3f216b3b731e (patch)
treefd210c1cf1bfcda2f7ed1292df01a26f9555c057 /tests/ChunkData/CopyBlocks.cpp
parentInitial commit of the Generator article. (diff)
parentUpdated AlchemistVillage prefabs. (diff)
downloadcuberite-2059944d1e39e952c164b8a87c0c3f216b3b731e.tar
cuberite-2059944d1e39e952c164b8a87c0c3f216b3b731e.tar.gz
cuberite-2059944d1e39e952c164b8a87c0c3f216b3b731e.tar.bz2
cuberite-2059944d1e39e952c164b8a87c0c3f216b3b731e.tar.lz
cuberite-2059944d1e39e952c164b8a87c0c3f216b3b731e.tar.xz
cuberite-2059944d1e39e952c164b8a87c0c3f216b3b731e.tar.zst
cuberite-2059944d1e39e952c164b8a87c0c3f216b3b731e.zip
Diffstat (limited to 'tests/ChunkData/CopyBlocks.cpp')
-rw-r--r--tests/ChunkData/CopyBlocks.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp
new file mode 100644
index 000000000..be8cab234
--- /dev/null
+++ b/tests/ChunkData/CopyBlocks.cpp
@@ -0,0 +1,76 @@
+
+// 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));
+ size_t LastReportedStep = 1;
+ for (size_t idx = 0; idx < 5000; idx += 7)
+ {
+ if (idx / 500 != LastReportedStep)
+ {
+ 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:
+ 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; 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);
+ }
+
+ // 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;
+}
+
+
+
+
+