diff options
author | Mattes D <github@xoft.cz> | 2019-08-26 21:38:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-26 21:38:34 +0200 |
commit | 74579fbadf0f89154cba5d9157a57f59fcda8f70 (patch) | |
tree | 2aca1ce5d8e41e91adcfe25dfb4bb51369fb865e /tests/ChunkData | |
parent | Added BlockState implementation for 1.13 support. (diff) | |
download | cuberite-74579fbadf0f89154cba5d9157a57f59fcda8f70.tar cuberite-74579fbadf0f89154cba5d9157a57f59fcda8f70.tar.gz cuberite-74579fbadf0f89154cba5d9157a57f59fcda8f70.tar.bz2 cuberite-74579fbadf0f89154cba5d9157a57f59fcda8f70.tar.lz cuberite-74579fbadf0f89154cba5d9157a57f59fcda8f70.tar.xz cuberite-74579fbadf0f89154cba5d9157a57f59fcda8f70.tar.zst cuberite-74579fbadf0f89154cba5d9157a57f59fcda8f70.zip |
Diffstat (limited to '')
-rw-r--r-- | tests/ChunkData/ArraytoCoord.cpp | 39 | ||||
-rw-r--r-- | tests/ChunkData/Coordinates.cpp | 111 | ||||
-rw-r--r-- | tests/ChunkData/Copies.cpp | 45 | ||||
-rw-r--r-- | tests/ChunkData/CopyBlocks.cpp | 16 |
4 files changed, 117 insertions, 94 deletions
diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp index 440730e46..e4ca9ce8d 100644 --- a/tests/ChunkData/ArraytoCoord.cpp +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -1,12 +1,13 @@ #include "Globals.h" +#include "../TestHelpers.h" #include "ChunkData.h" -int main(int argc, char** argv) +/** Performs the entire ArrayToCoords test. */ +static void test() { - LOGD("Test started"); class cMockAllocationPool : public cAllocationPool<cChunkData::sChunkSection> @@ -35,23 +36,23 @@ int main(int argc, char** argv) memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer)); SrcBlockBuffer[7 + (4 * 16) + (5 * 16 * 16)] = 0xcd; buffer.SetBlockTypes(SrcBlockBuffer); - testassert(buffer.GetBlock({ 7, 5, 4 }) == 0xcd); + TEST_EQUAL(buffer.GetBlock({ 7, 5, 4 }), 0xcd); NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer)); SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xe; buffer.SetMetas(SrcNibbleBuffer); - testassert(buffer.GetMeta({ 6, 2, 1 }) == 0xe); + TEST_EQUAL(buffer.GetMeta({ 6, 2, 1 }), 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); + TEST_EQUAL(buffer.GetBlockLight({ 6, 2, 1 }), 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); + TEST_EQUAL(buffer.GetSkyLight({ 6, 2, 1 }), 0xe); } { @@ -62,23 +63,23 @@ int main(int argc, char** argv) memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer)); SrcBlockBuffer[7 + (4 * 16) + (24 * 16 * 16)] = 0xcd; buffer.SetBlockTypes(SrcBlockBuffer); - testassert(buffer.GetBlock({ 7, 24, 4 }) == 0xcd); + TEST_EQUAL(buffer.GetBlock({ 7, 24, 4 }), 0xcd); NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer)); SrcNibbleBuffer[(6 + (1 * 16) + (24 * 16 * 16)) / 2] = 0xe; buffer.SetMetas(SrcNibbleBuffer); - testassert(buffer.GetMeta({ 6, 24, 1 }) == 0xe); + TEST_EQUAL(buffer.GetMeta({ 6, 24, 1 }), 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); + TEST_EQUAL(buffer.GetBlockLight({ 6, 24, 1 }), 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); + TEST_EQUAL(buffer.GetSkyLight({ 6, 24, 1 }), 0xe); } { @@ -88,23 +89,27 @@ int main(int argc, char** argv) BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer)); buffer.SetBlockTypes(SrcBlockBuffer); - testassert(buffer.GetBlock({ 7, 24, 4 }) == 0x00); + TEST_EQUAL(buffer.GetBlock({ 7, 24, 4 }), 0x00); NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]; memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer)); buffer.SetMetas(SrcNibbleBuffer); - testassert(buffer.GetMeta({ 6, 24, 1 }) == 0x0); + TEST_EQUAL(buffer.GetMeta({ 6, 24, 1 }), 0x0); memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer)); buffer.SetBlockLight(SrcNibbleBuffer); - testassert(buffer.GetBlockLight({ 6, 24, 1 }) == 0x0); + TEST_EQUAL(buffer.GetBlockLight({ 6, 24, 1 }), 0x0); memset(SrcNibbleBuffer, 0xff, sizeof(SrcNibbleBuffer)); buffer.SetSkyLight(SrcNibbleBuffer); - testassert(buffer.GetSkyLight({ 6, 24, 1 }) == 0xf); + TEST_EQUAL(buffer.GetSkyLight({ 6, 24, 1 }), 0xf); } - - // All tests passed: - return 0; } + + + + +IMPLEMENT_TEST_MAIN("ChunkData ArrayToCoord", + test(); +) diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index 304df191f..5070f2cda 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -1,13 +1,14 @@ #include "Globals.h" +#include "../TestHelpers.h" #include "ChunkData.h" -int main(int argc, char** argv) -{ - LOGD("Test started"); +/** Performs the entire cChunkData coordinates test. */ +static void test() +{ class cMockAllocationPool : public cAllocationPool<cChunkData::sChunkSection> { @@ -31,72 +32,72 @@ int main(int argc, char** argv) // Empty chunks buffer.SetBlock({ 0, 0, 0 }, 0xAB); - testassert(buffer.GetBlock({ 0, 0, 0 }) == 0xAB); + TEST_EQUAL(buffer.GetBlock({ 0, 0, 0 }), 0xAB); buffer.SetMeta({ 0, 16, 0 }, 0xC); - testassert(buffer.GetMeta({ 0, 16, 0 }) == 0xC); + TEST_EQUAL(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); + TEST_EQUAL(buffer.GetBlock({ 1, 0, 0 }), 0x0); + TEST_EQUAL(buffer.GetMeta({ 1, 16, 0 }), 0x0); // Notloaded segments - testassert(buffer.GetBlock({ 0, 32, 0 }) == 0x0); - testassert(buffer.GetMeta({ 0, 48, 0 }) == 0x0); + TEST_EQUAL(buffer.GetBlock({ 0, 32, 0 }), 0x0); + TEST_EQUAL(buffer.GetMeta({ 0, 48, 0 }), 0x0); // Out of range SetBlock - CheckAsserts( - buffer.SetBlock({ -1, 0, 0 }, 0); + TEST_ASSERTS( + buffer.SetBlock({ -1, 0, 0 }, 0) ); - CheckAsserts( - buffer.SetBlock({ 0, -1, 0 }, 0); + TEST_ASSERTS( + buffer.SetBlock({ 0, -1, 0 }, 0) ); - CheckAsserts( - buffer.SetBlock({ 0, 0, -1 }, 0); + TEST_ASSERTS( + buffer.SetBlock({ 0, 0, -1 }, 0) ); - CheckAsserts( - buffer.SetBlock({ 256, 0, 0 }, 0); + TEST_ASSERTS( + buffer.SetBlock({ 256, 0, 0 }, 0) ); - CheckAsserts( - buffer.SetBlock({ 0, 256, 0 }, 0); + TEST_ASSERTS( + buffer.SetBlock({ 0, 256, 0 }, 0) ); - CheckAsserts( - buffer.SetBlock({ 0, 0, 256 }, 0); + TEST_ASSERTS( + buffer.SetBlock({ 0, 0, 256 }, 0) ); // Out of range SetMeta - CheckAsserts( - buffer.SetMeta({ -1, 0, 0 }, 0); + TEST_ASSERTS( + buffer.SetMeta({ -1, 0, 0 }, 0) ); - CheckAsserts( - buffer.SetMeta({ 0, -1, 0 }, 0); + TEST_ASSERTS( + buffer.SetMeta({ 0, -1, 0 }, 0) ); - CheckAsserts( - buffer.SetMeta({ 0, 0, -1 }, 0); + TEST_ASSERTS( + buffer.SetMeta({ 0, 0, -1 }, 0) ); - CheckAsserts( - buffer.SetMeta({ 256, 0, 0 }, 0); + TEST_ASSERTS( + buffer.SetMeta({ 256, 0, 0 }, 0) ); - CheckAsserts( - buffer.SetMeta({ 0, 256, 0 }, 0); + TEST_ASSERTS( + buffer.SetMeta({ 0, 256, 0 }, 0) ); - CheckAsserts( - buffer.SetMeta({ 0, 0, 256 }, 0); + TEST_ASSERTS( + buffer.SetMeta({ 0, 0, 256 }, 0) ); // Reading out of range blocks should return air - testassert(buffer.GetBlock({ -1, 0, 0 }) == 0); - testassert(buffer.GetBlock({ 0, -1, 0 }) == 0); - testassert(buffer.GetBlock({ 0, 0, -1 }) == 0); - testassert(buffer.GetBlock({ 256, 0, 0 }) == 0); - testassert(buffer.GetBlock({ 0, 256, 0 }) == 0); - testassert(buffer.GetBlock({ 0, 0, 256 }) == 0); + TEST_EQUAL(buffer.GetBlock({ -1, 0, 0 }), 0); + TEST_EQUAL(buffer.GetBlock({ 0, -1, 0 }), 0); + TEST_EQUAL(buffer.GetBlock({ 0, 0, -1 }), 0); + TEST_EQUAL(buffer.GetBlock({ 256, 0, 0 }), 0); + TEST_EQUAL(buffer.GetBlock({ 0, 256, 0 }), 0); + TEST_EQUAL(buffer.GetBlock({ 0, 0, 256 }), 0); // Reading out of range metas should return 0 - testassert(buffer.GetMeta({ -1, 0, 0 }) == 0); - testassert(buffer.GetMeta({ 0, -1, 0 }) == 0); - testassert(buffer.GetMeta({ 0, 0, -1 }) == 0); - testassert(buffer.GetMeta({ 256, 0, 0 }) == 0); - testassert(buffer.GetMeta({ 0, 256, 0 }) == 0); - testassert(buffer.GetMeta({ 0, 0, 256 }) == 0); + TEST_EQUAL(buffer.GetMeta({ -1, 0, 0 }), 0); + TEST_EQUAL(buffer.GetMeta({ 0, -1, 0 }), 0); + TEST_EQUAL(buffer.GetMeta({ 0, 0, -1 }), 0); + TEST_EQUAL(buffer.GetMeta({ 256, 0, 0 }), 0); + TEST_EQUAL(buffer.GetMeta({ 0, 256, 0 }), 0); + TEST_EQUAL(buffer.GetMeta({ 0, 0, 256 }), 0); } { @@ -105,13 +106,13 @@ int main(int argc, char** argv) // 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); + TEST_EQUAL(buffer.GetBlock({ 0, 0, 0 }), 0x0); + TEST_EQUAL(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); + TEST_EQUAL(buffer.GetMeta({ 0, 16, 0 }), 0x0); + TEST_EQUAL(buffer.GetMeta({ 0, 16, 1 }), 0xc); } @@ -121,8 +122,14 @@ int main(int argc, char** argv) buffer.SetBlock({ 0, 0, 0 }, 0x42); cChunkData copy(Pool); copy = std::move(buffer); - testassert(copy.GetBlock({ 0, 0, 0 }) == 0x42); + TEST_EQUAL(copy.GetBlock({ 0, 0, 0 }), 0x42); } - - return 0; } + + + + + +IMPLEMENT_TEST_MAIN("ChunkData Coordinates", + test(); +) diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp index 7fc027ece..6cbb58387 100644 --- a/tests/ChunkData/Copies.cpp +++ b/tests/ChunkData/Copies.cpp @@ -1,10 +1,14 @@ #include "Globals.h" +#include "../TestHelpers.h" #include "ChunkData.h" -int main(int argc, char** argv) + + +/** Performs the entire Copies test. */ +static void test() { LOGD("Test started"); @@ -34,8 +38,8 @@ int main(int argc, char** argv) cChunkData copy(Pool); copy.Assign(buffer); - testassert(copy.GetBlock({ 3, 1, 4 }) == 0xDE); - testassert(copy.GetMeta({ 3, 1, 4 }) == 0xA); + TEST_EQUAL(copy.GetBlock({ 3, 1, 4 }), 0xDE); + TEST_EQUAL(copy.GetMeta({ 3, 1, 4 }), 0xA); BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]; for (int i = 0; i < 16 * 16 * 256; i += 4) @@ -49,12 +53,12 @@ int main(int argc, char** argv) buffer.SetBlockTypes(SrcBlockBuffer); BLOCKTYPE DstBlockBuffer[16 * 16 * 256]; buffer.CopyBlockTypes(DstBlockBuffer); - testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0); + TEST_EQUAL(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1), 0); memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); buffer.SetBlockTypes(SrcBlockBuffer); buffer.CopyBlockTypes(DstBlockBuffer); - testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0); + TEST_EQUAL(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1), 0); } { @@ -72,12 +76,12 @@ int main(int argc, char** argv) buffer.SetMetas(SrcNibbleBuffer); NIBBLETYPE DstNibbleBuffer[16 * 16 * 256/ 2]; buffer.CopyMetas(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); + TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0); memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); buffer.SetMetas(SrcNibbleBuffer); buffer.CopyMetas(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); + TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0); } { @@ -95,12 +99,12 @@ int main(int argc, char** argv) buffer.SetBlockLight(SrcNibbleBuffer); NIBBLETYPE DstNibbleBuffer[16 * 16 * 256 / 2]; buffer.CopyBlockLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1) == 0); + TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1), 0); memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); buffer.SetBlockLight(SrcNibbleBuffer); buffer.CopyBlockLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1) == 0); + TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1), 0); } { @@ -118,12 +122,12 @@ int main(int argc, char** argv) buffer.SetSkyLight(SrcNibbleBuffer); NIBBLETYPE DstNibbleBuffer[16 * 16 * 256/ 2]; buffer.CopySkyLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); + TEST_EQUAL(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); + TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0); } { @@ -133,23 +137,28 @@ int main(int argc, char** argv) memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); BLOCKTYPE DstBlockBuffer[16 * 16 * 256]; buffer.CopyBlockTypes(DstBlockBuffer); - testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0); + TEST_EQUAL(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.CopyMetas(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); + TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0); memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2); buffer.CopyBlockLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); + TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0); memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 / 2); buffer.CopySkyLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0); + TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0); } - - // All tests successful: - return 0; } + + + + + +IMPLEMENT_TEST_MAIN("ChunkData Copies", + test() +) diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp index 623ed208b..ad1524fe5 100644 --- a/tests/ChunkData/CopyBlocks.cpp +++ b/tests/ChunkData/CopyBlocks.cpp @@ -8,16 +8,16 @@ #include "Globals.h" +#include "../TestHelpers.h" #include "ChunkData.h" -int main(int argc, char ** argv) +/** Performs the entire CopyBlocks test. */ +static void test() { - LOGD("Test started"); - // Set up a cChunkData with known contents - all blocks 0x01, all metas 0x02: class cMockAllocationPool : public cAllocationPool<cChunkData::sChunkSection> @@ -67,17 +67,17 @@ int main(int argc, char ** argv) // Verify the data copied: for (size_t i = 0; i < len; i++) { - assert_test(WritePosition[i] == 0x01); + TEST_EQUAL(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); + TEST_EQUAL(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); + TEST_EQUAL(TestBuffer[i], 0x03); } // Re-initialize the buffer for the next test: @@ -87,10 +87,12 @@ int main(int argc, char ** argv) } } // for len } // for idx - return 0; } +IMPLEMENT_TEST_MAIN("ChunkData CopyBlocks", + test() +) |