summaryrefslogtreecommitdiffstats
path: root/tests/ChunkData
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/ChunkData/ArraytoCoord.cpp79
-rw-r--r--tests/ChunkData/CMakeLists.txt5
-rw-r--r--tests/ChunkData/Coordinates.cpp10
-rw-r--r--tests/ChunkData/Copies.cpp68
-rw-r--r--tests/ChunkData/CopyBlocks.cpp76
-rw-r--r--tests/ChunkData/creatable.cpp2
6 files changed, 161 insertions, 79 deletions
diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp
index f800d8e05..80bcc5283 100644
--- a/tests/ChunkData/ArraytoCoord.cpp
+++ b/tests/ChunkData/ArraytoCoord.cpp
@@ -1,5 +1,5 @@
-#include "TestGlobals.h"
+#include "Globals.h"
#include "ChunkData.h"
@@ -20,26 +20,26 @@ int main(int argc, char** argv)
cChunkData buffer(Pool);
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
- memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
- SrcBlockBuffer[7 + (4 * 16) + (5 * 16 * 16)] = 0xCD;
- buffer.SetBlocks(SrcBlockBuffer);
- testassert(buffer.GetBlock(7,5,4) == 0xCD);
+ memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer));
+ SrcBlockBuffer[7 + (4 * 16) + (5 * 16 * 16)] = 0xcd;
+ buffer.SetBlockTypes(SrcBlockBuffer);
+ testassert(buffer.GetBlock(7, 5, 4) == 0xcd);
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
- SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xE;
- buffer.SetMeta(SrcNibbleBuffer);
- testassert(buffer.GetMeta(6, 2, 1) == 0xE);
+ memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
+ SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xe;
+ buffer.SetMetas(SrcNibbleBuffer);
+ testassert(buffer.GetMeta(6, 2, 1) == 0xe);
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
- SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xE;
+ memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
+ SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xe;
buffer.SetBlockLight(SrcNibbleBuffer);
- testassert(buffer.GetBlockLight(6, 2, 1) == 0xE);
+ testassert(buffer.GetBlockLight(6, 2, 1) == 0xe);
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
- SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xE;
+ memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
+ SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xe;
buffer.SetSkyLight(SrcNibbleBuffer);
- testassert(buffer.GetSkyLight(6, 2, 1) == 0xE);
+ testassert(buffer.GetSkyLight(6, 2, 1) == 0xe);
}
{
@@ -47,26 +47,26 @@ int main(int argc, char** argv)
cChunkData buffer(Pool);
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
- memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
- SrcBlockBuffer[7 + (4 * 16) + (24 * 16 * 16)] = 0xCD;
- buffer.SetBlocks(SrcBlockBuffer);
- testassert(buffer.GetBlock(7, 24, 4) == 0xCD);
+ memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer));
+ SrcBlockBuffer[7 + (4 * 16) + (24 * 16 * 16)] = 0xcd;
+ buffer.SetBlockTypes(SrcBlockBuffer);
+ testassert(buffer.GetBlock(7, 24, 4) == 0xcd);
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
- SrcNibbleBuffer[(6 + (1 * 16) + (24 * 16 * 16)) / 2] = 0xE;
- buffer.SetMeta(SrcNibbleBuffer);
- testassert(buffer.GetMeta(6, 24, 1) == 0xE);
+ memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
+ SrcNibbleBuffer[(6 + (1 * 16) + (24 * 16 * 16)) / 2] = 0xe;
+ buffer.SetMetas(SrcNibbleBuffer);
+ testassert(buffer.GetMeta(6, 24, 1) == 0xe);
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
- SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE;
+ memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
+ SrcNibbleBuffer[(6 + 1 * 16 + 24 * 16 * 16) / 2] = 0xe;
buffer.SetBlockLight(SrcNibbleBuffer);
- testassert(buffer.GetBlockLight(6,24,1) == 0xE);
+ testassert(buffer.GetBlockLight(6, 24, 1) == 0xe);
- memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 / 2);
- SrcNibbleBuffer[(6 + (1 * 16) + (24 * 16 * 16))/2] = 0xE;
+ memset(SrcNibbleBuffer, 0xff, sizeof(SrcNibbleBuffer));
+ SrcNibbleBuffer[(6 + (1 * 16) + (24 * 16 * 16)) / 2] = 0xe;
buffer.SetSkyLight(SrcNibbleBuffer);
- testassert(buffer.GetSkyLight(6, 24, 1) == 0xE);
+ testassert(buffer.GetSkyLight(6, 24, 1) == 0xe);
}
{
@@ -74,22 +74,25 @@ int main(int argc, char** argv)
cChunkData buffer(Pool);
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
- memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
- buffer.SetBlocks(SrcBlockBuffer);
+ memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer));
+ buffer.SetBlockTypes(SrcBlockBuffer);
testassert(buffer.GetBlock(7, 24, 4) == 0x00);
- NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256/2];
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
- buffer.SetMeta(SrcNibbleBuffer);
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
+ memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
+ buffer.SetMetas(SrcNibbleBuffer);
testassert(buffer.GetMeta(6, 24, 1) == 0x0);
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
buffer.SetBlockLight(SrcNibbleBuffer);
- testassert(buffer.GetBlockLight(6,24,1) == 0x0);
+ testassert(buffer.GetBlockLight(6, 24, 1) == 0x0);
- memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2);
+ memset(SrcNibbleBuffer, 0xff, sizeof(SrcNibbleBuffer));
buffer.SetSkyLight(SrcNibbleBuffer);
- testassert(buffer.GetSkyLight(6, 24, 1) == 0xF);
+ testassert(buffer.GetSkyLight(6, 24, 1) == 0xf);
}
+
+ // All tests passed:
+ return 0;
}
diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt
index a2bd9fd22..381e11cc2 100644
--- a/tests/ChunkData/CMakeLists.txt
+++ b/tests/ChunkData/CMakeLists.txt
@@ -5,7 +5,7 @@ enable_testing()
include_directories(${CMAKE_SOURCE_DIR}/src/)
add_definitions(-DTEST_GLOBALS=1)
-add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkData.cpp)
+add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkData.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp)
add_executable(creatable-exe creatable.cpp)
@@ -24,3 +24,6 @@ add_executable(arraystocoords-exe ArraytoCoord.cpp)
target_link_libraries(arraystocoords-exe ChunkBuffer)
add_test(NAME arraystocoords-test COMMAND arraystocoords-exe)
+add_executable(copyblocks-exe CopyBlocks.cpp)
+target_link_libraries(copyblocks-exe ChunkBuffer)
+add_test(NAME copyblocks-test COMMAND copyblocks-exe)
diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp
index 3a4477fd6..d5abbb143 100644
--- a/tests/ChunkData/Coordinates.cpp
+++ b/tests/ChunkData/Coordinates.cpp
@@ -1,5 +1,5 @@
-#include "TestGlobals.h"
+#include "Globals.h"
#include "ChunkData.h"
@@ -117,14 +117,14 @@ int main(int argc, char** argv)
// Zero's
buffer.SetBlock(0, 0, 0, 0x0);
- buffer.SetBlock(0, 0, 1, 0xAB);
+ buffer.SetBlock(0, 0, 1, 0xab);
testassert(buffer.GetBlock(0, 0, 0) == 0x0);
- testassert(buffer.GetBlock(0, 0, 1) == 0xAB);
+ testassert(buffer.GetBlock(0, 0, 1) == 0xab);
buffer.SetMeta(0, 16, 0, 0x0);
- buffer.SetMeta(0, 16, 1, 0xC);
+ buffer.SetMeta(0, 16, 1, 0xc);
testassert(buffer.GetMeta(0, 16, 0) == 0x0);
- testassert(buffer.GetMeta(0, 16, 1) == 0xC);
+ testassert(buffer.GetMeta(0, 16, 1) == 0xc);
}
diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp
index 502a969e8..6f5d40792 100644
--- a/tests/ChunkData/Copies.cpp
+++ b/tests/ChunkData/Copies.cpp
@@ -1,5 +1,5 @@
-#include "TestGlobals.h"
+#include "Globals.h"
#include "ChunkData.h"
@@ -27,57 +27,56 @@ int main(int argc, char** argv)
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
for (int i = 0; i < 16 * 16 * 256; i += 4)
{
- SrcBlockBuffer[i+0] = 0xDE;
- SrcBlockBuffer[i+1] = 0xAD;
- SrcBlockBuffer[i+2] = 0xBE;
- SrcBlockBuffer[i+3] = 0xEF;
+ SrcBlockBuffer[i + 0] = 0xde;
+ SrcBlockBuffer[i + 1] = 0xad;
+ SrcBlockBuffer[i + 2] = 0xbe;
+ SrcBlockBuffer[i + 3] = 0xef;
}
- buffer.SetBlocks(SrcBlockBuffer);
+ buffer.SetBlockTypes(SrcBlockBuffer);
BLOCKTYPE DstBlockBuffer[16 * 16 * 256];
- buffer.CopyBlocks(DstBlockBuffer);
+ buffer.CopyBlockTypes(DstBlockBuffer);
testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0);
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
- buffer.SetBlocks(SrcBlockBuffer);
- buffer.CopyBlocks(DstBlockBuffer);
+ buffer.SetBlockTypes(SrcBlockBuffer);
+ buffer.CopyBlockTypes(DstBlockBuffer);
testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0);
-
}
+
{
cChunkData buffer(Pool);
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
{
- SrcNibbleBuffer[i+0] = 0xEF;
- SrcNibbleBuffer[i+1] = 0xDE;
- SrcNibbleBuffer[i+2] = 0xAD;
- SrcNibbleBuffer[i+3] = 0xBE;
+ SrcNibbleBuffer[i + 0] = 0xde;
+ SrcNibbleBuffer[i + 1] = 0xad;
+ SrcNibbleBuffer[i + 2] = 0xbe;
+ SrcNibbleBuffer[i + 3] = 0xef;
}
- buffer.SetMeta(SrcNibbleBuffer);
+ buffer.SetMetas(SrcNibbleBuffer);
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256/ 2];
- buffer.CopyMeta(DstNibbleBuffer);
+ buffer.CopyMetas(DstNibbleBuffer);
testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
- buffer.SetMeta(SrcNibbleBuffer);
- buffer.CopyMeta(DstNibbleBuffer);
+ buffer.SetMetas(SrcNibbleBuffer);
+ buffer.CopyMetas(DstNibbleBuffer);
testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
-
-
}
+
{
cChunkData buffer(Pool);
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
{
- SrcNibbleBuffer[i+0] = 0xDE;
- SrcNibbleBuffer[i+1] = 0xAD;
- SrcNibbleBuffer[i+2] = 0xBE;
- SrcNibbleBuffer[i+3] = 0xEF;
+ SrcNibbleBuffer[i + 0] = 0xde;
+ SrcNibbleBuffer[i + 1] = 0xad;
+ SrcNibbleBuffer[i + 2] = 0xbe;
+ SrcNibbleBuffer[i + 3] = 0xef;
}
buffer.SetBlockLight(SrcNibbleBuffer);
@@ -89,19 +88,18 @@ int main(int argc, char** argv)
buffer.SetBlockLight(SrcNibbleBuffer);
buffer.CopyBlockLight(DstNibbleBuffer);
testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1) == 0);
-
-
}
+
{
cChunkData buffer(Pool);
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
{
- SrcNibbleBuffer[i+0] = 0xAD;
- SrcNibbleBuffer[i+1] = 0xBE;
- SrcNibbleBuffer[i+2] = 0xEF;
- SrcNibbleBuffer[i+3] = 0xDE;
+ SrcNibbleBuffer[i + 0] = 0xde;
+ SrcNibbleBuffer[i + 1] = 0xad;
+ SrcNibbleBuffer[i + 2] = 0xbe;
+ SrcNibbleBuffer[i + 3] = 0xef;
}
buffer.SetSkyLight(SrcNibbleBuffer);
@@ -109,26 +107,25 @@ int main(int argc, char** argv)
buffer.CopySkyLight(DstNibbleBuffer);
testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
-
memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 / 2);
buffer.SetSkyLight(SrcNibbleBuffer);
buffer.CopySkyLight(DstNibbleBuffer);
testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
-
}
+
{
cChunkData buffer(Pool);
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
BLOCKTYPE DstBlockBuffer[16 * 16 * 256];
- buffer.CopyBlocks(DstBlockBuffer);
+ buffer.CopyBlockTypes(DstBlockBuffer);
testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0);
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256 / 2];
- buffer.CopyMeta(DstNibbleBuffer);
+ buffer.CopyMetas(DstNibbleBuffer);
testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
@@ -139,4 +136,7 @@ int main(int argc, char** argv)
buffer.CopySkyLight(DstNibbleBuffer);
testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
}
+
+ // All tests successful:
+ return 0;
}
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;
+}
+
+
+
+
+
diff --git a/tests/ChunkData/creatable.cpp b/tests/ChunkData/creatable.cpp
index 78b1a82d1..0dde8cf3b 100644
--- a/tests/ChunkData/creatable.cpp
+++ b/tests/ChunkData/creatable.cpp
@@ -1,5 +1,5 @@
-#include "TestGlobals.h"
+#include "Globals.h"
#include "ChunkData.h"
int main(int argc, char** argv)