summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-03-05 14:03:55 +0100
committerGitHub <noreply@github.com>2021-03-05 14:03:55 +0100
commit868cd94ee9a5a0638c014a4cc42224f01ff234c8 (patch)
treecd23dc866f77de5b0b3e89a5eafeeb2ef24ffbdd /tests
parentfixed the crash on generating in the SinglePiceStructuresGen (#5136) (diff)
downloadcuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.gz
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.bz2
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.lz
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.xz
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.tar.zst
cuberite-868cd94ee9a5a0638c014a4cc42224f01ff234c8.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/ChunkData/ArraytoCoord.cpp99
-rw-r--r--tests/ChunkData/CMakeLists.txt10
-rw-r--r--tests/ChunkData/Coordinates.cpp83
-rw-r--r--tests/ChunkData/Copies.cpp100
-rw-r--r--tests/ChunkData/CopyBlocks.cpp98
-rw-r--r--tests/ChunkData/Creatable.cpp34
-rw-r--r--tests/ChunkData/creatable.cpp29
7 files changed, 187 insertions, 266 deletions
diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp
index 1fdaf3365..89fd8f731 100644
--- a/tests/ChunkData/ArraytoCoord.cpp
+++ b/tests/ChunkData/ArraytoCoord.cpp
@@ -8,100 +8,99 @@
/** Performs the entire ArrayToCoords test. */
static void test()
{
-
- class cMockAllocationPool
- : public cAllocationPool<cChunkData::sChunkSection>
- {
- virtual cChunkData::sChunkSection * Allocate() override
- {
- return new cChunkData::sChunkSection();
- }
-
- virtual void Free(cChunkData::sChunkSection * a_Ptr) override
- {
- delete a_Ptr;
- }
-
- virtual bool DoIsEqual(const cAllocationPool<cChunkData::sChunkSection> &) const noexcept override
- {
- return false;
- }
- } Pool;
{
-
- // Test first segment
- cChunkData buffer(Pool);
+ // Test first segment (blocks)
+ ChunkBlockData buffer;
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer));
SrcBlockBuffer[7 + (4 * 16) + (5 * 16 * 16)] = 0xcd;
- buffer.SetBlockTypes(SrcBlockBuffer);
- 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);
+
+ buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
+
+ TEST_EQUAL(buffer.GetBlock({ 7, 5, 4 }), 0xcd);
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);
- TEST_EQUAL(buffer.GetBlockLight({ 6, 2, 1 }), 0xe);
+ {
+ // Test first segment (lights)
+ ChunkLightData buffer;
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xe;
- buffer.SetSkyLight(SrcNibbleBuffer);
+
+ buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
+
+ TEST_EQUAL(buffer.GetBlockLight({ 6, 2, 1 }), 0xe);
TEST_EQUAL(buffer.GetSkyLight({ 6, 2, 1 }), 0xe);
}
{
- // test following segment
- cChunkData buffer(Pool);
+ // test following segment (blocks)
+ ChunkBlockData buffer;
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer));
SrcBlockBuffer[7 + (4 * 16) + (24 * 16 * 16)] = 0xcd;
- buffer.SetBlockTypes(SrcBlockBuffer);
- 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);
+
+ buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
+
+ TEST_EQUAL(buffer.GetBlock({ 7, 24, 4 }), 0xcd);
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);
- TEST_EQUAL(buffer.GetBlockLight({ 6, 24, 1 }), 0xe);
+ {
+ // test following segment (lights)
+ ChunkLightData buffer;
- memset(SrcNibbleBuffer, 0xff, sizeof(SrcNibbleBuffer));
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
+ memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
SrcNibbleBuffer[(6 + (1 * 16) + (24 * 16 * 16)) / 2] = 0xe;
- buffer.SetSkyLight(SrcNibbleBuffer);
+
+ buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
+
+ TEST_EQUAL(buffer.GetBlockLight({ 6, 24, 1 }), 0xe);
TEST_EQUAL(buffer.GetSkyLight({ 6, 24, 1 }), 0xe);
}
{
- // test zeros
- cChunkData buffer(Pool);
+ // test zeros (blocks)
+ ChunkBlockData buffer;
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, sizeof(SrcBlockBuffer));
- buffer.SetBlockTypes(SrcBlockBuffer);
- TEST_EQUAL(buffer.GetBlock({ 7, 24, 4 }), 0x00);
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
- buffer.SetMetas(SrcNibbleBuffer);
+
+ buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
+
+ TEST_EQUAL(buffer.GetBlock({ 7, 24, 4 }), 0x00);
TEST_EQUAL(buffer.GetMeta({ 6, 24, 1 }), 0x0);
+ }
+
+ {
+ // test zeros (lights)
+ ChunkLightData buffer;
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
memset(SrcNibbleBuffer, 0x00, sizeof(SrcNibbleBuffer));
- buffer.SetBlockLight(SrcNibbleBuffer);
- TEST_EQUAL(buffer.GetBlockLight({ 6, 24, 1 }), 0x0);
- memset(SrcNibbleBuffer, 0xff, sizeof(SrcNibbleBuffer));
- buffer.SetSkyLight(SrcNibbleBuffer);
+ NIBBLETYPE SrcNibbleBuffer2[16 * 16 * 256 / 2];
+ memset(SrcNibbleBuffer2, 0xff, sizeof(SrcNibbleBuffer2));
+
+ buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer2);
+
+ TEST_EQUAL(buffer.GetBlockLight({ 6, 24, 1 }), 0x0);
TEST_EQUAL(buffer.GetSkyLight({ 6, 24, 1 }), 0xf);
}
}
diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt
index 705d46b35..8c2de41a1 100644
--- a/tests/ChunkData/CMakeLists.txt
+++ b/tests/ChunkData/CMakeLists.txt
@@ -4,7 +4,7 @@ add_library(ChunkBuffer ${PROJECT_SOURCE_DIR}/src/ChunkData.cpp ${PROJECT_SOURCE
target_link_libraries(ChunkBuffer PUBLIC fmt::fmt)
-add_executable(creatable-exe creatable.cpp)
+add_executable(creatable-exe Creatable.cpp)
target_link_libraries(creatable-exe ChunkBuffer)
add_test(NAME creatable-test COMMAND creatable-exe)
@@ -20,19 +20,11 @@ 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)
-
-
-
-
# Put all test projects into a separate folder:
set_target_properties(
arraystocoords-exe
coordinates-exe
copies-exe
- copyblocks-exe
creatable-exe
PROPERTIES FOLDER Tests/ChunkData
)
diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp
index 97c3f3a15..3e7949662 100644
--- a/tests/ChunkData/Coordinates.cpp
+++ b/tests/ChunkData/Coordinates.cpp
@@ -9,26 +9,8 @@
/** Performs the entire cChunkData coordinates test. */
static void test()
{
- class cMockAllocationPool
- : public cAllocationPool<cChunkData::sChunkSection>
{
- virtual cChunkData::sChunkSection * Allocate() override
- {
- return new cChunkData::sChunkSection();
- }
-
- virtual void Free(cChunkData::sChunkSection * a_Ptr) override
- {
- delete a_Ptr;
- }
-
- virtual bool DoIsEqual(const cAllocationPool<cChunkData::sChunkSection> &) const noexcept override
- {
- return false;
- }
- } Pool;
- {
- cChunkData buffer(Pool);
+ ChunkBlockData buffer;
// Empty chunks
buffer.SetBlock({ 0, 0, 0 }, 0xAB);
@@ -44,6 +26,26 @@ static void test()
TEST_EQUAL(buffer.GetBlock({ 0, 32, 0 }), 0x0);
TEST_EQUAL(buffer.GetMeta({ 0, 48, 0 }), 0x0);
+ // Out of range GetBlock
+ TEST_ASSERTS(
+ buffer.GetBlock({ -1, 0, 0 });
+ );
+ TEST_ASSERTS(
+ buffer.GetBlock({ 0, -1, 0 });
+ );
+ TEST_ASSERTS(
+ buffer.GetBlock({ 0, 0, -1 });
+ );
+ TEST_ASSERTS(
+ buffer.GetBlock({ 256, 0, 0 });
+ );
+ TEST_ASSERTS(
+ buffer.GetBlock({ 0, 256, 0 });
+ );
+ TEST_ASSERTS(
+ buffer.GetBlock({ 0, 0, 256 });
+ );
+
// Out of range SetBlock
TEST_ASSERTS(
buffer.SetBlock({ -1, 0, 0 }, 0)
@@ -63,6 +65,27 @@ static void test()
TEST_ASSERTS(
buffer.SetBlock({ 0, 0, 256 }, 0)
);
+
+ // Out of range GetMeta
+ TEST_ASSERTS(
+ buffer.GetMeta({ -1, 0, 0 });
+ );
+ TEST_ASSERTS(
+ buffer.GetMeta({ 0, -1, 0 });
+ );
+ TEST_ASSERTS(
+ buffer.GetMeta({ 0, 0, -1 });
+ );
+ TEST_ASSERTS(
+ buffer.GetMeta({ 256, 0, 0 });
+ );
+ TEST_ASSERTS(
+ buffer.GetMeta({ 0, 256, 0 });
+ );
+ TEST_ASSERTS(
+ buffer.GetMeta({ 0, 0, 256 });
+ );
+
// Out of range SetMeta
TEST_ASSERTS(
buffer.SetMeta({ -1, 0, 0 }, 0)
@@ -82,26 +105,10 @@ static void test()
TEST_ASSERTS(
buffer.SetMeta({ 0, 0, 256 }, 0)
);
-
- // Reading out of range blocks should return air
- 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
- 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);
}
{
- cChunkData buffer(Pool);
+ ChunkBlockData buffer;
// Zero's
buffer.SetBlock({ 0, 0, 0 }, 0x0);
@@ -118,9 +125,9 @@ static void test()
{
// Operator =
- cChunkData buffer(Pool);
+ ChunkBlockData buffer;
buffer.SetBlock({ 0, 0, 0 }, 0x42);
- cChunkData copy(Pool);
+ ChunkBlockData copy;
copy = std::move(buffer);
TEST_EQUAL(copy.GetBlock({ 0, 0, 0 }), 0x42);
}
diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp
index 9b9cbbaf1..3555d4301 100644
--- a/tests/ChunkData/Copies.cpp
+++ b/tests/ChunkData/Copies.cpp
@@ -7,41 +7,50 @@
-/** Performs the entire Copies test. */
-static void test()
+/** Helper that copies a data store into a contiguous flat array, filling in a default value for sections that aren't present. */
+template <class StoreType, typename GetType, typename DefaultType, typename OutType>
+static void CopyAll(const StoreType & Data, GetType Getter, DefaultType Default, OutType & Out)
{
- LOGD("Test started");
+ constexpr auto SectionCount = std::extent_v<OutType> / 16;
- class cMockAllocationPool
- : public cAllocationPool<cChunkData::sChunkSection>
+ for (size_t Y = 0; Y != 16; Y++)
{
- virtual cChunkData::sChunkSection * Allocate() override
- {
- return new cChunkData::sChunkSection();
- }
+ const auto Section = (Data.*Getter)(Y);
+ static_assert(SectionCount == std::tuple_size<std::remove_pointer_t<decltype(Section)>>::value, "Output array has wrong size");
- virtual void Free(cChunkData::sChunkSection * a_Ptr) override
+ if (Section == nullptr)
{
- delete a_Ptr;
+ std::fill_n(Out + Y * SectionCount, SectionCount, Default);
}
-
- virtual bool DoIsEqual(const cAllocationPool<cChunkData::sChunkSection>&) const noexcept override
+ else
{
- return false;
+ std::copy(Section->begin(), Section->end(), Out + Y * SectionCount);
}
- } Pool;
+ }
+}
+
+
+
+
+
+/** Performs the entire Copies test. */
+static void Test()
+{
+ LOGD("Test started");
+
{
- cChunkData buffer(Pool);
+ ChunkBlockData buffer;
buffer.SetBlock({ 3, 1, 4 }, 0xDE);
buffer.SetMeta({ 3, 1, 4 }, 0xA);
- cChunkData copy(Pool);
+ ChunkBlockData copy;
copy.Assign(buffer);
TEST_EQUAL(copy.GetBlock({ 3, 1, 4 }), 0xDE);
TEST_EQUAL(copy.GetMeta({ 3, 1, 4 }), 0xA);
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2]{};
for (int i = 0; i < 16 * 16 * 256; i += 4)
{
SrcBlockBuffer[i + 0] = 0xde;
@@ -50,20 +59,21 @@ static void test()
SrcBlockBuffer[i + 3] = 0xef;
}
- buffer.SetBlockTypes(SrcBlockBuffer);
+ buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
BLOCKTYPE DstBlockBuffer[16 * 16 * 256];
- buffer.CopyBlockTypes(DstBlockBuffer);
+ CopyAll(buffer, &ChunkBlockData::GetSection, ChunkBlockData::DefaultValue, DstBlockBuffer);
TEST_EQUAL(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1), 0);
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
- buffer.SetBlockTypes(SrcBlockBuffer);
- buffer.CopyBlockTypes(DstBlockBuffer);
+ buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
+ CopyAll(buffer, &ChunkBlockData::GetSection, ChunkBlockData::DefaultValue, DstBlockBuffer);
TEST_EQUAL(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1), 0);
}
{
- cChunkData buffer(Pool);
+ ChunkBlockData buffer;
+ BLOCKTYPE SrcBlockBuffer[16 * 16 * 256]{};
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
{
@@ -73,19 +83,19 @@ static void test()
SrcNibbleBuffer[i + 3] = 0xef;
}
- buffer.SetMetas(SrcNibbleBuffer);
+ buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256/ 2];
- buffer.CopyMetas(DstNibbleBuffer);
+ CopyAll(buffer, &ChunkBlockData::GetMetaSection, ChunkBlockData::DefaultMetaValue, DstNibbleBuffer);
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
- buffer.SetMetas(SrcNibbleBuffer);
- buffer.CopyMetas(DstNibbleBuffer);
+ buffer.SetAll(SrcBlockBuffer, SrcNibbleBuffer);
+ CopyAll(buffer, &ChunkBlockData::GetMetaSection, ChunkBlockData::DefaultMetaValue, DstNibbleBuffer);
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
}
{
- cChunkData buffer(Pool);
+ ChunkLightData buffer;
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
@@ -96,19 +106,19 @@ static void test()
SrcNibbleBuffer[i + 3] = 0xef;
}
- buffer.SetBlockLight(SrcNibbleBuffer);
+ buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256 / 2];
- buffer.CopyBlockLight(DstNibbleBuffer);
+ CopyAll(buffer, &ChunkLightData::GetBlockLightSection, ChunkLightData::DefaultBlockLightValue, DstNibbleBuffer);
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1), 0);
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
- buffer.SetBlockLight(SrcNibbleBuffer);
- buffer.CopyBlockLight(DstNibbleBuffer);
+ buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
+ CopyAll(buffer, &ChunkLightData::GetBlockLightSection, ChunkLightData::DefaultBlockLightValue, DstNibbleBuffer);
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1), 0);
}
{
- cChunkData buffer(Pool);
+ ChunkLightData buffer;
NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
@@ -119,38 +129,44 @@ static void test()
SrcNibbleBuffer[i + 3] = 0xef;
}
- buffer.SetSkyLight(SrcNibbleBuffer);
+ buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
NIBBLETYPE DstNibbleBuffer[16 * 16 * 256/ 2];
- buffer.CopySkyLight(DstNibbleBuffer);
+ CopyAll(buffer, &ChunkLightData::GetSkyLightSection, ChunkLightData::DefaultSkyLightValue, DstNibbleBuffer);
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 / 2);
- buffer.SetSkyLight(SrcNibbleBuffer);
- buffer.CopySkyLight(DstNibbleBuffer);
+ buffer.SetAll(SrcNibbleBuffer, SrcNibbleBuffer);
+ CopyAll(buffer, &ChunkLightData::GetSkyLightSection, ChunkLightData::DefaultSkyLightValue, DstNibbleBuffer);
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
}
{
- cChunkData buffer(Pool);
+ ChunkBlockData buffer;
BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
BLOCKTYPE DstBlockBuffer[16 * 16 * 256];
- buffer.CopyBlockTypes(DstBlockBuffer);
+ CopyAll(buffer, &ChunkBlockData::GetSection, ChunkBlockData::DefaultValue, DstBlockBuffer);
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);
+ CopyAll(buffer, &ChunkBlockData::GetMetaSection, ChunkBlockData::DefaultMetaValue, DstNibbleBuffer);
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
+ }
+
+ {
+ ChunkLightData buffer;
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
- buffer.CopyBlockLight(DstNibbleBuffer);
+ NIBBLETYPE DstNibbleBuffer[16 * 16 * 256 / 2];
+ CopyAll(buffer, &ChunkLightData::GetBlockLightSection, ChunkLightData::DefaultBlockLightValue, DstNibbleBuffer);
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 / 2);
- buffer.CopySkyLight(DstNibbleBuffer);
+ CopyAll(buffer, &ChunkLightData::GetSkyLightSection, ChunkLightData::DefaultSkyLightValue, DstNibbleBuffer);
TEST_EQUAL(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1), 0);
}
}
@@ -160,5 +176,5 @@ static void test()
IMPLEMENT_TEST_MAIN("ChunkData Copies",
- test()
+ Test()
)
diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp
deleted file mode 100644
index c86a9e754..000000000
--- a/tests/ChunkData/CopyBlocks.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-
-// CopyBlocks.cpp
-
-// Implements the test for cChunkData::CopyBlockTypes() range copying
-
-
-
-
-
-#include "Globals.h"
-#include "../TestHelpers.h"
-#include "ChunkData.h"
-
-
-
-
-
-/** Performs the entire CopyBlocks test. */
-static void test()
-{
- // Set up a cChunkData with known contents - all blocks 0x01, all metas 0x02:
- class cMockAllocationPool
- : public cAllocationPool<cChunkData::sChunkSection>
- {
- virtual cChunkData::sChunkSection * Allocate() override
- {
- return new cChunkData::sChunkSection();
- }
-
- virtual void Free(cChunkData::sChunkSection * a_Ptr) override
- {
- delete a_Ptr;
- }
-
- virtual bool DoIsEqual(const cAllocationPool<cChunkData::sChunkSection> &) const noexcept override
- {
- return false;
- }
- } Pool;
- cChunkData Data(Pool);
- cChunkDef::BlockTypes BlockTypes;
- cChunkDef::BlockNibbles BlockMetas;
- memset(BlockTypes, 0x01, sizeof(BlockTypes));
- memset(BlockMetas, 0x02, sizeof(BlockMetas));
- Data.SetBlockTypes(BlockTypes);
- Data.SetMetas(BlockMetas);
-
- // Try to read varying amounts of blocktypes from the cChunkData.
- // Verify that the exact amount of memory is copied, by copying to a larger buffer and checking its boundaries
- BLOCKTYPE TestBuffer[5 * cChunkDef::NumBlocks];
- size_t WritePosIdx = 2 * cChunkDef::NumBlocks;
- BLOCKTYPE * WritePosition = &TestBuffer[WritePosIdx];
- memset(TestBuffer, 0x03, sizeof(TestBuffer));
- size_t LastReportedStep = 1;
- for (size_t idx = 0; idx < 5000; idx += 73)
- {
- if (idx / 500 != LastReportedStep)
- {
- printf("Testing index %u...\n", static_cast<unsigned>(idx));
- LastReportedStep = idx / 500;
- }
-
- for (size_t len = 3; len < 700; len += 13)
- {
- Data.CopyBlockTypes(WritePosition, idx, len);
-
- // Verify the data copied:
- for (size_t i = 0; i < len; i++)
- {
- TEST_EQUAL(WritePosition[i], 0x01);
- }
- // Verify the space before the copied data hasn't been changed:
- for (size_t i = 0; i < WritePosIdx; i++)
- {
- 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++)
- {
- TEST_EQUAL(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
-}
-
-
-
-
-
-IMPLEMENT_TEST_MAIN("ChunkData CopyBlocks",
- test()
-)
diff --git a/tests/ChunkData/Creatable.cpp b/tests/ChunkData/Creatable.cpp
new file mode 100644
index 000000000..278885b9d
--- /dev/null
+++ b/tests/ChunkData/Creatable.cpp
@@ -0,0 +1,34 @@
+
+#include "Globals.h"
+#include "../TestHelpers.h"
+#include "ChunkData.h"
+
+
+
+
+
+static void Test()
+{
+ LOGD("Test started");
+
+ ChunkBlockData train;
+ ChunkLightData buffer;
+
+ /*
+
+ /-|===D
+ / |===D
+ /---|
+ / |
+ ====/=====|===============
+
+ */
+}
+
+
+
+
+
+IMPLEMENT_TEST_MAIN("ChunkData Creatable",
+ Test()
+);
diff --git a/tests/ChunkData/creatable.cpp b/tests/ChunkData/creatable.cpp
deleted file mode 100644
index 9767c31b4..000000000
--- a/tests/ChunkData/creatable.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-
-#include "Globals.h"
-#include "ChunkData.h"
-
-int main(int argc, char** argv)
-{
- LOGD("Test started");
-
- class cMockAllocationPool
- : public cAllocationPool<cChunkData::sChunkSection>
- {
- virtual cChunkData::sChunkSection * Allocate() override
- {
- return new cChunkData::sChunkSection();
- }
-
- virtual void Free(cChunkData::sChunkSection * a_Ptr) override
- {
- delete a_Ptr;
- }
-
- virtual bool DoIsEqual(const cAllocationPool<cChunkData::sChunkSection> &) const noexcept override
- {
- return false;
- }
- } Pool;
- cChunkData buffer(Pool);
- return 0;
-}