summaryrefslogtreecommitdiffstats
path: root/tests/ChunkData/Copies.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/ChunkData/Copies.cpp100
1 files changed, 58 insertions, 42 deletions
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()
)