summaryrefslogtreecommitdiffstats
path: root/tests/ChunkData
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-05-21 20:58:48 +0200
committerTycho <work.tycho+git@gmail.com>2014-05-21 20:58:48 +0200
commit024027db89ca833406147b79b7be74fc92906bbe (patch)
tree844345e33c2a9c8fb7f5ca255f0bd1236a41b446 /tests/ChunkData
parentFixed minor style issues (diff)
downloadcuberite-024027db89ca833406147b79b7be74fc92906bbe.tar
cuberite-024027db89ca833406147b79b7be74fc92906bbe.tar.gz
cuberite-024027db89ca833406147b79b7be74fc92906bbe.tar.bz2
cuberite-024027db89ca833406147b79b7be74fc92906bbe.tar.lz
cuberite-024027db89ca833406147b79b7be74fc92906bbe.tar.xz
cuberite-024027db89ca833406147b79b7be74fc92906bbe.tar.zst
cuberite-024027db89ca833406147b79b7be74fc92906bbe.zip
Diffstat (limited to 'tests/ChunkData')
-rw-r--r--tests/ChunkData/ArraytoCoord.cpp116
-rw-r--r--tests/ChunkData/CMakeLists.txt25
-rw-r--r--tests/ChunkData/Coordinates.cpp143
-rw-r--r--tests/ChunkData/Copies.cpp193
-rw-r--r--tests/ChunkData/creatable.cpp9
5 files changed, 486 insertions, 0 deletions
diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp
new file mode 100644
index 000000000..fe82a3a7b
--- /dev/null
+++ b/tests/ChunkData/ArraytoCoord.cpp
@@ -0,0 +1,116 @@
+
+#include "TestGlobals.h"
+#include "ChunkData.h"
+
+
+
+int main(int argc, char** argv)
+{
+ {
+ // Test first segment
+ cChunkData buffer;
+
+ BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[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);
+ delete SrcBlockBuffer;
+ SrcBlockBuffer = NULL;
+
+ NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[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);
+ delete SrcNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE;
+ buffer.SetLight(SrcNibbleBuffer);
+ testassert(buffer.GetBlockLight(6,2,1) == 0xE);
+ delete SrcNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE;
+ buffer.SetSkyLight(SrcNibbleBuffer);
+ testassert(buffer.GetSkyLight(6,2,1) == 0xE);
+ delete SrcNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ }
+
+ {
+ // test following segment
+ cChunkData buffer;
+
+ BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[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);
+ delete SrcBlockBuffer;
+ SrcBlockBuffer = NULL;
+
+ NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[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);
+ delete SrcNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE;
+ buffer.SetLight(SrcNibbleBuffer);
+ testassert(buffer.GetBlockLight(6,24,1) == 0xE);
+ delete SrcNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE;
+ buffer.SetSkyLight(SrcNibbleBuffer);
+ testassert(buffer.GetSkyLight(6,24,1) == 0xE);
+ delete SrcNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ }
+
+ {
+ // test zeros
+ cChunkData buffer;
+
+ BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
+ buffer.SetBlocks(SrcBlockBuffer);
+ testassert(buffer.GetBlock(7,24,4) == 0x00);
+ delete SrcBlockBuffer;
+ SrcBlockBuffer = NULL;
+
+ NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ buffer.SetMeta(SrcNibbleBuffer);
+ testassert(buffer.GetMeta(6,24,1) == 0x0);
+ delete SrcNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ buffer.SetLight(SrcNibbleBuffer);
+ testassert(buffer.GetBlockLight(6,24,1) == 0x0);
+ delete SrcNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2);
+ buffer.SetSkyLight(SrcNibbleBuffer);
+ testassert(buffer.GetSkyLight(6,24,1) == 0xF);
+ delete SrcNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ }
+}
+
diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt
new file mode 100644
index 000000000..3f6653bb5
--- /dev/null
+++ b/tests/ChunkData/CMakeLists.txt
@@ -0,0 +1,25 @@
+cmake_minimum_required (VERSION 2.6)
+
+enable_testing()
+
+include_directories(${CMAKE_SOURCE_DIR}/src/)
+
+add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkData.cpp)
+
+
+add_executable(creatable-exe creatable.cpp)
+target_link_libraries(creatable-exe ChunkBuffer)
+add_test(NAME creatable-test COMMAND creatable-exe)
+
+add_executable(coordinates-exe Coordinates.cpp)
+target_link_libraries(coordinates-exe ChunkBuffer)
+add_test(NAME coordinates-test COMMAND coordinates-exe)
+
+add_executable(copies-exe Copies.cpp)
+target_link_libraries(copies-exe ChunkBuffer)
+add_test(NAME copies-test COMMAND copies-exe)
+
+add_executable(arraystocoords-exe ArraytoCoord.cpp)
+target_link_libraries(arraystocoords-exe ChunkBuffer)
+add_test(NAME arraystocoords-test COMMAND arraystocoords-exe)
+
diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp
new file mode 100644
index 000000000..c0c46000e
--- /dev/null
+++ b/tests/ChunkData/Coordinates.cpp
@@ -0,0 +1,143 @@
+
+#include "TestGlobals.h"
+#include "ChunkData.h"
+
+
+
+int main(int argc, char** argv)
+{
+ {
+ cChunkData buffer;
+
+ // Empty chunks
+ buffer.SetBlock(0,0,0, 0xAB);
+ testassert(buffer.GetBlock(0,0,0) == 0xAB);
+ buffer.SetMeta(0,16,0, 0xC);
+ testassert(buffer.GetMeta(0,16,0) == 0xC);
+
+ // loaded but not written segments
+ testassert(buffer.GetBlock(1,0,0) == 0x0);
+ testassert(buffer.GetMeta(1,16,0) == 0x0);
+
+ // Notloaded segments
+ testassert(buffer.GetBlock(0,32,0) == 0x0);
+ testassert(buffer.GetMeta(0,48,0) == 0x0);
+
+ // Out of Range
+ CheckAsserts(
+ buffer.SetBlock(-1, 0, 0, 0);
+ );
+ CheckAsserts(
+ buffer.SetBlock(0, -1, 0, 0);
+ );
+ CheckAsserts(
+ buffer.SetBlock(0, 0, -1, 0);
+ );
+ CheckAsserts(
+ buffer.SetBlock(256, 0, 0, 0);
+ );
+ CheckAsserts(
+ buffer.SetBlock(0, 256, 0, 0);
+ );
+ CheckAsserts(
+ buffer.SetBlock(0, 0, 256, 0);
+ );
+
+ // Out of Range
+ CheckAsserts(
+ buffer.GetBlock(-1, 0, 0);
+ );
+ CheckAsserts(
+ buffer.GetBlock(0, -1, 0);
+ );
+ CheckAsserts(
+ buffer.GetBlock(0, 0, -1);
+ );
+ CheckAsserts(
+ buffer.GetBlock(256, 0, 0);
+ );
+ CheckAsserts(
+ buffer.GetBlock(0, 256, 0);
+ );
+ CheckAsserts(
+ buffer.GetBlock(0, 0, 256);
+ );
+
+ // Out of Range
+ CheckAsserts(
+ buffer.SetMeta(-1, 0, 0, 0);
+ );
+ CheckAsserts(
+ buffer.SetMeta(0, -1, 0, 0);
+ );
+ CheckAsserts(
+ buffer.SetMeta(0, 0, -1, 0);
+ );
+ CheckAsserts(
+ buffer.SetMeta(256, 0, 0, 0);
+ );
+ CheckAsserts(
+ buffer.SetMeta(0, 256, 0, 0);
+ );
+ CheckAsserts(
+ buffer.SetMeta(0, 0, 256, 0);
+ );
+
+ // Out of Range
+ CheckAsserts(
+ buffer.GetMeta(-1, 0, 0);
+ );
+ CheckAsserts(
+ buffer.GetMeta(0, -1, 0);
+ );
+ CheckAsserts(
+ buffer.GetMeta(0, 0, -1);
+ );
+ CheckAsserts(
+ buffer.GetMeta(256, 0, 0);
+ );
+ CheckAsserts(
+ buffer.GetMeta(0, 256, 0);
+ );
+ CheckAsserts(
+ buffer.GetMeta(0, 0, 256);
+ );
+ }
+
+ {
+ cChunkData buffer;
+
+ // Zero's
+ buffer.SetBlock(0,0,0, 0x0);
+ buffer.SetBlock(0,0,1, 0xAB);
+ testassert(buffer.GetBlock(0,0,0) == 0x0);
+ testassert(buffer.GetBlock(0,0,1) == 0xAB);
+
+ buffer.SetMeta(0,16,0, 0x0);
+ buffer.SetMeta(0,16,1, 0xC);
+ testassert(buffer.GetMeta(0,16,0) == 0x0);
+ testassert(buffer.GetMeta(0,16,1) == 0xC);
+ }
+
+
+ {
+ // Operator =
+ cChunkData buffer;
+ buffer.SetBlock(0,0,0,0x42);
+ cChunkData copy;
+ #if __cplusplus < 201103L
+ copy = buffer;
+ #else
+ copy = std::move(buffer);
+ #endif
+ testassert(copy.GetBlock(0,0,0) == 0x42);
+ #if __cplusplus < 201103L
+ copy = copy;
+ #else
+ copy = std::move(copy);
+ #endif
+ testassert(copy.GetBlock(0,0,0) == 0x42);
+ }
+
+ return 0;
+}
diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp
new file mode 100644
index 000000000..145ffd8e0
--- /dev/null
+++ b/tests/ChunkData/Copies.cpp
@@ -0,0 +1,193 @@
+
+#include "TestGlobals.h"
+#include "ChunkData.h"
+
+
+
+int main(int argc, char** argv)
+{
+ {
+ cChunkData buffer;
+
+ buffer.SetBlock(3,1,4,0xDE);
+ buffer.SetMeta(3,1,4,0xA);
+
+ cChunkData copy = buffer.Copy();
+ testassert(copy.GetBlock(3,1,4) == 0xDE);
+ testassert(copy.GetMeta(3,1,4) == 0xA);
+
+ BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[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;
+ }
+
+ buffer.SetBlocks(SrcBlockBuffer);
+ BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ buffer.CopyBlocks(DstBlockBuffer);
+ testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0);
+ delete SrcBlockBuffer;
+ delete DstBlockBuffer;
+ SrcBlockBuffer = NULL;
+ DstBlockBuffer = NULL;
+
+ SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
+ buffer.SetBlocks(SrcBlockBuffer);
+ DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ buffer.CopyBlocks(DstBlockBuffer);
+ testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0);
+ delete SrcBlockBuffer;
+ delete DstBlockBuffer;
+ SrcBlockBuffer = NULL;
+ DstBlockBuffer = NULL;
+
+ }
+ {
+ cChunkData buffer;
+
+ NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[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;
+ }
+
+ buffer.SetMeta(SrcNibbleBuffer);
+ NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ buffer.CopyMeta(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0);
+ delete SrcNibbleBuffer;
+ delete DstNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ DstNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ buffer.SetMeta(SrcNibbleBuffer);
+ DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ buffer.CopyMeta(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0);
+ delete SrcNibbleBuffer;
+ delete DstNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ DstNibbleBuffer = NULL;
+
+ }
+ {
+ cChunkData buffer;
+
+ NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[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;
+ }
+
+ buffer.SetLight(SrcNibbleBuffer);
+ NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ buffer.CopyLight(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0);
+ delete SrcNibbleBuffer;
+ delete DstNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ DstNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ buffer.SetLight(SrcNibbleBuffer);
+ DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ buffer.CopyLight(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0);
+ delete SrcNibbleBuffer;
+ delete DstNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ DstNibbleBuffer = NULL;
+
+
+ }
+ {
+ cChunkData buffer;
+
+ NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[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;
+ }
+
+ buffer.SetSkyLight(SrcNibbleBuffer);
+ NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ buffer.CopySkyLight(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0);
+ delete SrcNibbleBuffer;
+ delete DstNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ DstNibbleBuffer = NULL;
+
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2);
+ buffer.SetSkyLight(SrcNibbleBuffer);
+ DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ buffer.CopySkyLight(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0);
+ delete SrcNibbleBuffer;
+ delete DstNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ DstNibbleBuffer = NULL;
+
+ }
+ {
+ cChunkData buffer;
+
+ BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
+ BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ buffer.CopyBlocks(DstBlockBuffer);
+ testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0);
+ delete SrcBlockBuffer;
+ delete DstBlockBuffer;
+ SrcBlockBuffer = NULL;
+ DstBlockBuffer = NULL;
+
+ NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ buffer.CopyMeta(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0);
+ delete SrcNibbleBuffer;
+ delete DstNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ DstNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
+ DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ buffer.CopyLight(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0);
+ delete SrcNibbleBuffer;
+ delete DstNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ DstNibbleBuffer = NULL;
+
+ SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2);
+ DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ buffer.CopySkyLight(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0);
+ delete SrcNibbleBuffer;
+ delete DstNibbleBuffer;
+ SrcNibbleBuffer = NULL;
+ DstNibbleBuffer = NULL;
+ }
+}
diff --git a/tests/ChunkData/creatable.cpp b/tests/ChunkData/creatable.cpp
new file mode 100644
index 000000000..74025cb14
--- /dev/null
+++ b/tests/ChunkData/creatable.cpp
@@ -0,0 +1,9 @@
+
+#include "TestGlobals.h"
+#include "ChunkData.h"
+
+int main(int argc, char** argv)
+{
+ cChunkData buffer;
+ return 0;
+}