diff options
Diffstat (limited to 'tests/ChunkData')
-rw-r--r-- | tests/ChunkData/ArraytoCoord.cpp | 90 | ||||
-rw-r--r-- | tests/ChunkData/Coordinates.cpp | 38 | ||||
-rw-r--r-- | tests/ChunkData/Copies.cpp | 135 |
3 files changed, 87 insertions, 176 deletions
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); } } |