From 024027db89ca833406147b79b7be74fc92906bbe Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 19:58:48 +0100 Subject: Renamed cChunkBuffer to cChunkData --- tests/ChunkData/ArraytoCoord.cpp | 116 +++++++++++++++++++++++ tests/ChunkData/CMakeLists.txt | 25 +++++ tests/ChunkData/Coordinates.cpp | 143 +++++++++++++++++++++++++++++ tests/ChunkData/Copies.cpp | 193 +++++++++++++++++++++++++++++++++++++++ tests/ChunkData/creatable.cpp | 9 ++ 5 files changed, 486 insertions(+) create mode 100644 tests/ChunkData/ArraytoCoord.cpp create mode 100644 tests/ChunkData/CMakeLists.txt create mode 100644 tests/ChunkData/Coordinates.cpp create mode 100644 tests/ChunkData/Copies.cpp create mode 100644 tests/ChunkData/creatable.cpp (limited to 'tests/ChunkData') 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; +} -- cgit v1.2.3 From 8f964886e0ccbf51dac07227f0ac4c739b47d3a5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 24 May 2014 13:33:40 +0100 Subject: Implemented style changes --- tests/ChunkData/ArraytoCoord.cpp | 90 +++++++++----------------- tests/ChunkData/Coordinates.cpp | 38 +++++------ tests/ChunkData/Copies.cpp | 135 +++++++++++---------------------------- 3 files changed, 87 insertions(+), 176 deletions(-) (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp index fe82a3a7b..1138fb5b6 100644 --- a/tests/ChunkData/ArraytoCoord.cpp +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -10,107 +10,77 @@ int main(int argc, char** argv) // Test first segment cChunkData buffer; - BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - SrcBlockBuffer[7+4*16+5*16*16] = 0xCD; + 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; + 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); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; + testassert(buffer.GetMeta(6, 2, 1) == 0xE); - 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; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2); + SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xE; + buffer.SetBlockLight(SrcNibbleBuffer); + testassert(buffer.GetBlockLight(6, 2, 1) == 0xE); - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE; + 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; + testassert(buffer.GetSkyLight(6, 2, 1) == 0xE); } { // test following segment cChunkData buffer; - BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - SrcBlockBuffer[7+4*16+24*16*16] = 0xCD; + SrcBlockBuffer[7 + (4 * 16) + (24 * 16 * 16)] = 0xCD; buffer.SetBlocks(SrcBlockBuffer); - testassert(buffer.GetBlock(7,24,4) == 0xCD); - delete SrcBlockBuffer; - SrcBlockBuffer = NULL; + testassert(buffer.GetBlock(7, 24, 4) == 0xCD); - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE; + 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); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; + testassert(buffer.GetMeta(6, 24, 1) == 0xE); - 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); + buffer.SetBlockLight(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; + memset(SrcNibbleBuffer, 0xFF, 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; + testassert(buffer.GetSkyLight(6, 24, 1) == 0xE); } { // test zeros cChunkData buffer; - BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); buffer.SetBlocks(SrcBlockBuffer); - testassert(buffer.GetBlock(7,24,4) == 0x00); - delete SrcBlockBuffer; - SrcBlockBuffer = NULL; + testassert(buffer.GetBlock(7, 24, 4) == 0x00); - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + NIBBLETYPE SrcNibbleBuffer[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; + testassert(buffer.GetMeta(6, 24, 1) == 0x0); - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - buffer.SetLight(SrcNibbleBuffer); + buffer.SetBlockLight(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; + testassert(buffer.GetSkyLight(6, 24, 1) == 0xF); } } diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index c0c46000e..f02b68d40 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -10,18 +10,18 @@ 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); + 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); + 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); + testassert(buffer.GetBlock(0, 32, 0) == 0x0); + testassert(buffer.GetMeta(0, 48, 0) == 0x0); // Out of Range CheckAsserts( @@ -108,35 +108,35 @@ int main(int argc, char** argv) 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.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); + 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); + 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); + 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); + testassert(copy.GetBlock(0, 0, 0) == 0x42); } return 0; diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp index 145ffd8e0..b10ddb759 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -9,14 +9,14 @@ int main(int argc, char** argv) { cChunkData buffer; - buffer.SetBlock(3,1,4,0xDE); - buffer.SetMeta(3,1,4,0xA); + 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); + testassert(copy.GetBlock(3, 1, 4) == 0xDE); + testassert(copy.GetMeta(3, 1, 4) == 0xA); - BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; for (int i = 0; i < 16 * 16 * 256; i += 4) { SrcBlockBuffer[i+0] = 0xDE; @@ -26,30 +26,20 @@ int main(int argc, char** argv) } buffer.SetBlocks(SrcBlockBuffer); - BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + BLOCKTYPE DstBlockBuffer[16 * 16 * 256]; buffer.CopyBlocks(DstBlockBuffer); - testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0); - delete SrcBlockBuffer; - delete DstBlockBuffer; - SrcBlockBuffer = NULL; - DstBlockBuffer = NULL; + testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0); - 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; + testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0); } { cChunkData buffer; - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) { SrcNibbleBuffer[i+0] = 0xEF; @@ -59,30 +49,21 @@ int main(int argc, char** argv) } buffer.SetMeta(SrcNibbleBuffer); - NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + NIBBLETYPE DstNibbleBuffer[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; + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); - 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; + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); + } { cChunkData buffer; - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) { SrcNibbleBuffer[i+0] = 0xDE; @@ -91,32 +72,22 @@ int main(int argc, char** argv) 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; + buffer.SetBlockLight(SrcNibbleBuffer); + NIBBLETYPE DstNibbleBuffer[16 * 16 * 256 / 2]; + buffer.CopyBlockLight(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1) == 0); - 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; + buffer.SetBlockLight(SrcNibbleBuffer); + buffer.CopyBlockLight(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1) == 0); } { cChunkData buffer; - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) { SrcNibbleBuffer[i+0] = 0xAD; @@ -126,68 +97,38 @@ int main(int argc, char** argv) } buffer.SetSkyLight(SrcNibbleBuffer); - NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + NIBBLETYPE DstNibbleBuffer[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; + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0xFF, 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; + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); } { cChunkData buffer; - BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + BLOCKTYPE DstBlockBuffer[16 * 16 * 256]; buffer.CopyBlocks(DstBlockBuffer); - testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0); - delete SrcBlockBuffer; - delete DstBlockBuffer; - SrcBlockBuffer = NULL; - DstBlockBuffer = NULL; + testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0); - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2); + NIBBLETYPE DstNibbleBuffer[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; + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); - 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; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2); + buffer.CopyBlockLight(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2); - DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + memset(SrcNibbleBuffer, 0xFF, 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; + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); } } -- cgit v1.2.3 From 944d29c0ae3929471a11ea11aa98441bc31f4d7d Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 24 May 2014 14:09:51 +0100 Subject: inject TestGlobals.h correctly --- tests/ChunkData/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt index 3f6653bb5..a2bd9fd22 100644 --- a/tests/ChunkData/CMakeLists.txt +++ b/tests/ChunkData/CMakeLists.txt @@ -4,6 +4,7 @@ enable_testing() include_directories(${CMAKE_SOURCE_DIR}/src/) +add_definitions(-DTEST_GLOBALS=1) add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkData.cpp) -- cgit v1.2.3 From 19df18c46199f06f3bf2058cc0efee9126e7670a Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 27 May 2014 12:44:56 +0100 Subject: Fixed test globals to work with precompiled headers --- tests/ChunkData/ArraytoCoord.cpp | 2 +- tests/ChunkData/Coordinates.cpp | 2 +- tests/ChunkData/Copies.cpp | 2 +- tests/ChunkData/creatable.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp index 1138fb5b6..37533de77 100644 --- a/tests/ChunkData/ArraytoCoord.cpp +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -1,5 +1,5 @@ -#include "TestGlobals.h" +#include "Globals.h" #include "ChunkData.h" diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index f02b68d40..938c66dcc 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -1,5 +1,5 @@ -#include "TestGlobals.h" +#include "Globals.h" #include "ChunkData.h" diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp index b10ddb759..78a458f5b 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -1,5 +1,5 @@ -#include "TestGlobals.h" +#include "Globals.h" #include "ChunkData.h" diff --git a/tests/ChunkData/creatable.cpp b/tests/ChunkData/creatable.cpp index 74025cb14..1321bf49b 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) -- cgit v1.2.3 From c5763f3af700fe2df0be0ceb2fe9a580384c839e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 29 May 2014 19:42:39 +0200 Subject: Fixed test compilation. --- tests/ChunkData/ArraytoCoord.cpp | 12 ++++++------ tests/ChunkData/Copies.cpp | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp index 37533de77..4942ababb 100644 --- a/tests/ChunkData/ArraytoCoord.cpp +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -13,13 +13,13 @@ int main(int argc, char** argv) BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); SrcBlockBuffer[7 + (4 * 16) + (5 * 16 * 16)] = 0xCD; - buffer.SetBlocks(SrcBlockBuffer); + 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); + buffer.SetMetas(SrcNibbleBuffer); testassert(buffer.GetMeta(6, 2, 1) == 0xE); memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2); @@ -40,13 +40,13 @@ int main(int argc, char** argv) BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); SrcBlockBuffer[7 + (4 * 16) + (24 * 16 * 16)] = 0xCD; - buffer.SetBlocks(SrcBlockBuffer); + 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); + buffer.SetMetas(SrcNibbleBuffer); testassert(buffer.GetMeta(6, 24, 1) == 0xE); memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); @@ -66,12 +66,12 @@ int main(int argc, char** argv) BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - buffer.SetBlocks(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); + buffer.SetMetas(SrcNibbleBuffer); testassert(buffer.GetMeta(6, 24, 1) == 0x0); memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp index 78a458f5b..ef0329451 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -25,14 +25,14 @@ int main(int argc, char** argv) 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); } @@ -48,14 +48,14 @@ int main(int argc, char** argv) SrcNibbleBuffer[i+3] = 0xBE; } - 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); @@ -114,13 +114,13 @@ int main(int argc, char** argv) 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); -- cgit v1.2.3 From 59068b77b7215461b4aaf11c2db91c1657b7f91d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 29 May 2014 20:18:37 +0200 Subject: Fixed wrong block sizes for copying / setting. --- tests/ChunkData/Copies.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp index ef0329451..788d2c558 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -19,10 +19,10 @@ 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.SetBlockTypes(SrcBlockBuffer); @@ -42,10 +42,10 @@ int main(int argc, char** argv) 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.SetMetas(SrcNibbleBuffer); @@ -66,10 +66,10 @@ int main(int argc, char** argv) 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); @@ -90,10 +90,10 @@ int main(int argc, char** argv) 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); -- cgit v1.2.3 From 0b49529e4273a96e7f582ef4c321eaf8d65c629f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 30 May 2014 09:17:50 +0200 Subject: Fixed test return values. --- tests/ChunkData/ArraytoCoord.cpp | 65 +++++++++++++++++++++------------------- tests/ChunkData/Copies.cpp | 14 ++++----- 2 files changed, 41 insertions(+), 38 deletions(-) (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp index 4942ababb..0daf38f7b 100644 --- a/tests/ChunkData/ArraytoCoord.cpp +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -11,26 +11,26 @@ int main(int argc, char** argv) cChunkData buffer; BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; - memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - SrcBlockBuffer[7 + (4 * 16) + (5 * 16 * 16)] = 0xCD; + memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer)); + SrcBlockBuffer[7 + (4 * 16) + (5 * 16 * 16)] = 0xcd; buffer.SetBlockTypes(SrcBlockBuffer); - testassert(buffer.GetBlock(7,5,4) == 0xCD); + 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; + memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer)); + SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xe; buffer.SetMetas(SrcNibbleBuffer); - testassert(buffer.GetMeta(6, 2, 1) == 0xE); + 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); } { @@ -38,26 +38,26 @@ int main(int argc, char** argv) cChunkData buffer; BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; - memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - SrcBlockBuffer[7 + (4 * 16) + (24 * 16 * 16)] = 0xCD; + memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer)); + SrcBlockBuffer[7 + (4 * 16) + (24 * 16 * 16)] = 0xcd; buffer.SetBlockTypes(SrcBlockBuffer); - testassert(buffer.GetBlock(7, 24, 4) == 0xCD); + 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; + memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer)); + SrcNibbleBuffer[(6 + (1 * 16) + (24 * 16 * 16)) / 2] = 0xe; buffer.SetMetas(SrcNibbleBuffer); - testassert(buffer.GetMeta(6, 24, 1) == 0xE); + 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); } { @@ -65,22 +65,25 @@ int main(int argc, char** argv) cChunkData buffer; BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; - memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); + 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); + 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/Copies.cpp b/tests/ChunkData/Copies.cpp index 788d2c558..312441eee 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -34,8 +34,8 @@ int main(int argc, char** argv) buffer.SetBlockTypes(SrcBlockBuffer); buffer.CopyBlockTypes(DstBlockBuffer); testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0); - } + { cChunkData buffer; @@ -57,9 +57,8 @@ int main(int argc, char** argv) buffer.SetMetas(SrcNibbleBuffer); buffer.CopyMetas(DstNibbleBuffer); testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); - - } + { cChunkData buffer; @@ -81,9 +80,8 @@ int main(int argc, char** argv) buffer.SetBlockLight(SrcNibbleBuffer); buffer.CopyBlockLight(DstNibbleBuffer); testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1) == 0); - - } + { cChunkData buffer; @@ -101,13 +99,12 @@ 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; @@ -131,4 +128,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; } -- cgit v1.2.3 From 0b60caac4ae8e7762cc530a0a7b6a7abe8c33262 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 30 May 2014 10:56:12 +0200 Subject: Test failures are reported verbosely and into the debug console on Win. --- tests/ChunkData/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt index a2bd9fd22..fd508cc6e 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) -- cgit v1.2.3 From e136f6e0f5b41ee7c9d784009ef40c9ac2e2e6fe Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 30 May 2014 11:35:29 +0200 Subject: Fixed cChunkData nibble copying. --- tests/ChunkData/Coordinates.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index 938c66dcc..48d731c7e 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -109,14 +109,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); } -- cgit v1.2.3 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/CMakeLists.txt | 3 ++ tests/ChunkData/CopyBlocks.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/ChunkData/CopyBlocks.cpp (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt index fd508cc6e..381e11cc2 100644 --- a/tests/ChunkData/CMakeLists.txt +++ b/tests/ChunkData/CMakeLists.txt @@ -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/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') 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') 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/ArraytoCoord.cpp | 20 +++++++++++++++++--- tests/ChunkData/Coordinates.cpp | 21 +++++++++++++++++---- tests/ChunkData/Copies.cpp | 23 ++++++++++++++++++----- tests/ChunkData/CopyBlocks.cpp | 15 ++++++++++++++- tests/ChunkData/creatable.cpp | 15 ++++++++++++++- 5 files changed, 80 insertions(+), 14 deletions(-) (limited to 'tests/ChunkData') diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp index 0daf38f7b..9d0ca6c8c 100644 --- a/tests/ChunkData/ArraytoCoord.cpp +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -6,9 +6,23 @@ int main(int argc, char** argv) { + class cMockAllocationPool + : public cAllocationPool + { + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; { + // Test first segment - cChunkData buffer; + cChunkData buffer(Pool); BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer)); @@ -35,7 +49,7 @@ int main(int argc, char** argv) { // test following segment - cChunkData buffer; + cChunkData buffer(Pool); BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer)); @@ -62,7 +76,7 @@ int main(int argc, char** argv) { // test zeros - cChunkData buffer; + cChunkData buffer(Pool); BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer)); diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index 48d731c7e..b3c66dde5 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -6,8 +6,21 @@ int main(int argc, char** argv) { + class cMockAllocationPool + : public cAllocationPool + { + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; { - cChunkData buffer; + cChunkData buffer(Pool); // Empty chunks buffer.SetBlock(0, 0, 0, 0xAB); @@ -105,7 +118,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); // Zero's buffer.SetBlock(0, 0, 0, 0x0); @@ -122,9 +135,9 @@ int main(int argc, char** argv) { // Operator = - cChunkData buffer; + cChunkData buffer(Pool); buffer.SetBlock(0, 0, 0, 0x42); - cChunkData copy; + cChunkData copy(Pool); #if __cplusplus < 201103L copy = buffer; #else diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp index 312441eee..440819e91 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -6,8 +6,21 @@ int main(int argc, char** argv) { + class cMockAllocationPool + : public cAllocationPool + { + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; { - cChunkData buffer; + cChunkData buffer(Pool); buffer.SetBlock(3, 1, 4, 0xDE); buffer.SetMeta(3, 1, 4, 0xA); @@ -37,7 +50,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) @@ -60,7 +73,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) @@ -83,7 +96,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) @@ -106,7 +119,7 @@ int main(int argc, char** argv) } { - cChunkData buffer; + cChunkData buffer(Pool); BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); 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)); diff --git a/tests/ChunkData/creatable.cpp b/tests/ChunkData/creatable.cpp index 1321bf49b..fc786f688 100644 --- a/tests/ChunkData/creatable.cpp +++ b/tests/ChunkData/creatable.cpp @@ -4,6 +4,19 @@ int main(int argc, char** argv) { - cChunkData buffer; + class cMockAllocationPool + : public cAllocationPool + { + virtual cChunkData::sChunkSection * Allocate() + { + return new cChunkData::sChunkSection(); + } + + virtual void Free(cChunkData::sChunkSection * a_Ptr) + { + delete a_Ptr; + } + } Pool; + cChunkData buffer(Pool); return 0; } -- cgit v1.2.3