summaryrefslogtreecommitdiffstats
path: root/tests/ChunkBuffer
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/ChunkBuffer/CMakeLists.txt20
-rw-r--r--tests/ChunkBuffer/Coordinates.cpp106
-rw-r--r--tests/ChunkBuffer/Copies.cpp53
-rw-r--r--tests/ChunkBuffer/creatable.cpp9
4 files changed, 188 insertions, 0 deletions
diff --git a/tests/ChunkBuffer/CMakeLists.txt b/tests/ChunkBuffer/CMakeLists.txt
new file mode 100644
index 000000000..73dc79e25
--- /dev/null
+++ b/tests/ChunkBuffer/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required (VERSION 2.6)
+
+enable_testing()
+
+include_directories(${CMAKE_SOURCE_DIR}/src/)
+
+add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkBuffer.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)
diff --git a/tests/ChunkBuffer/Coordinates.cpp b/tests/ChunkBuffer/Coordinates.cpp
new file mode 100644
index 000000000..a6a8aa18f
--- /dev/null
+++ b/tests/ChunkBuffer/Coordinates.cpp
@@ -0,0 +1,106 @@
+
+#include "TestGlobals.h"
+#include "ChunkBuffer.h"
+
+
+
+int main(int argc, char** argv)
+{
+ cChunkBuffer 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);
+ );
+
+ return 0;
+}
diff --git a/tests/ChunkBuffer/Copies.cpp b/tests/ChunkBuffer/Copies.cpp
new file mode 100644
index 000000000..6bdf80268
--- /dev/null
+++ b/tests/ChunkBuffer/Copies.cpp
@@ -0,0 +1,53 @@
+
+#include "TestGlobals.h"
+#include "ChunkBuffer.h"
+
+
+
+int main(int argc, char** argv)
+{
+ cChunkBuffer buffer;
+
+ buffer.SetBlock(3,1,4,0xDE);
+ buffer.SetMeta(3,1,4,0xA);
+
+ cChunkBuffer 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;
+
+ 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;
+}
diff --git a/tests/ChunkBuffer/creatable.cpp b/tests/ChunkBuffer/creatable.cpp
new file mode 100644
index 000000000..49204c879
--- /dev/null
+++ b/tests/ChunkBuffer/creatable.cpp
@@ -0,0 +1,9 @@
+
+#include "TestGlobals.h"
+#include "ChunkBuffer.h"
+
+int main(int argc, char** argv)
+{
+ cChunkBuffer buffer;
+ return 0;
+}