diff options
Diffstat (limited to 'src/unittest/test_schematic.cpp')
-rw-r--r-- | src/unittest/test_schematic.cpp | 256 |
1 files changed, 145 insertions, 111 deletions
diff --git a/src/unittest/test_schematic.cpp b/src/unittest/test_schematic.cpp index da4ce50d2..cee5abdd8 100644 --- a/src/unittest/test_schematic.cpp +++ b/src/unittest/test_schematic.cpp @@ -1,4 +1,4 @@ - /* +/* Minetest Copyright (C) 2010-2014 kwolekr, Ryan Kwolek <kwolekr@minetest.net> @@ -23,7 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gamedef.h" #include "nodedef.h" -class TestSchematic : public TestBase { +class TestSchematic : public TestBase +{ public: TestSchematic() { TestManager::registerTestModule(this); } const char *getName() { return "TestSchematic"; } @@ -44,8 +45,7 @@ static TestSchematic g_test_instance; void TestSchematic::runTests(IGameDef *gamedef) { - NodeDefManager *ndef = - (NodeDefManager *)gamedef->getNodeDefManager(); + NodeDefManager *ndef = (NodeDefManager *)gamedef->getNodeDefManager(); ndef->setNodeRegistrationStatus(true); @@ -63,8 +63,8 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef) static const v3s16 size(7, 6, 4); static const u32 volume = size.X * size.Y * size.Z; - std::stringstream ss(std::ios_base::binary | - std::ios_base::in | std::ios_base::out); + std::stringstream ss( + std::ios_base::binary | std::ios_base::in | std::ios_base::out); std::vector<std::string> names; names.emplace_back("foo"); @@ -74,9 +74,9 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef) Schematic schem, schem2; - schem.flags = 0; - schem.size = size; - schem.schemdata = new MapNode[volume]; + schem.flags = 0; + schem.size = size; + schem.schemdata = new MapNode[volume]; schem.slice_probs = new u8[size.Y]; for (size_t i = 0; i != volume; i++) schem.schemdata[i] = MapNode(test_schem1_data[i], MTSCHEM_PROB_ALWAYS, 0); @@ -103,7 +103,6 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef) UASSERTEQ(u8, schem2.slice_probs[y], schem.slice_probs[y]); } - void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef) { static const v3s16 size(3, 3, 3); @@ -111,9 +110,9 @@ void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef) Schematic schem; - schem.flags = 0; - schem.size = size; - schem.schemdata = new MapNode[volume]; + schem.flags = 0; + schem.size = size; + schem.schemdata = new MapNode[volume]; schem.slice_probs = new u8[size.Y]; for (size_t i = 0; i != volume; i++) schem.schemdata[i] = MapNode(test_schem2_data[i], test_schem2_prob[i], 0); @@ -131,20 +130,19 @@ void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef) UASSERTEQ(std::string, ss.str(), expected_lua_output); } - void TestSchematic::testFileSerializeDeserialize(const NodeDefManager *ndef) { static const v3s16 size(3, 3, 3); static const u32 volume = size.X * size.Y * size.Z; static const content_t content_map[] = { - CONTENT_AIR, - t_CONTENT_STONE, - t_CONTENT_LAVA, + CONTENT_AIR, + t_CONTENT_STONE, + t_CONTENT_LAVA, }; static const content_t content_map2[] = { - CONTENT_AIR, - t_CONTENT_STONE, - t_CONTENT_WATER, + CONTENT_AIR, + t_CONTENT_STONE, + t_CONTENT_WATER, }; StringMap replace_names; replace_names["default:lava"] = "default:water"; @@ -152,10 +150,10 @@ void TestSchematic::testFileSerializeDeserialize(const NodeDefManager *ndef) Schematic schem1, schem2; //// Construct the schematic to save - schem1.flags = 0; - schem1.size = size; - schem1.schemdata = new MapNode[volume]; - schem1.slice_probs = new u8[size.Y]; + schem1.flags = 0; + schem1.size = size; + schem1.schemdata = new MapNode[volume]; + schem1.slice_probs = new u8[size.Y]; schem1.slice_probs[0] = 80; schem1.slice_probs[1] = 160; schem1.slice_probs[2] = 240; @@ -180,101 +178,137 @@ void TestSchematic::testFileSerializeDeserialize(const NodeDefManager *ndef) } } - // Should form a cross-shaped-thing...? const content_t TestSchematic::test_schem1_data[7 * 6 * 4] = { - 3, 3, 1, 1, 1, 3, 3, // Y=0, Z=0 - 3, 0, 1, 2, 1, 0, 3, // Y=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Y=2, Z=1 + 1, 1, 1, 2, 1, 1, 1, // Y=3, Z=1 + 1, 2, 2, 2, 2, 2, 1, // Y=4, Z=1 + 1, 1, 1, 2, 1, 1, 1, // Y=5, Z=1 + + 0, 0, 1, 1, 1, 0, 0, // Y=0, Z=2 + 0, 0, 1, 2, 1, 0, 0, // Y=1, Z=2 + 0, 0, 1, 2, 1, 0, 0, // Y=2, Z=2 + 1, 1, 1, 2, 1, 1, 1, // Y=3, Z=2 + 1, 2, 2, 2, 2, 2, 1, // Y=4, Z=2 + 1, 1, 1, 2, 1, 1, 1, // Y=5, Z=2 + + 3, 3, 1, 1, 1, 3, 3, // Y=0, Z=3 + 3, 0, 1, 2, 1, 0, 3, // Y=1, Z=3 + 3, 0, 1, 2, 1, 0, 3, // Y=2, Z=3 + 3, 1, 1, 2, 1, 1, 3, // Y=3, Z=3 + 3, 2, 2, 2, 2, 2, 3, // Y=4, Z=3 + 3, 1, 1, 2, 1, 1, 3, // Y=5, Z=3 }; const content_t TestSchematic::test_schem2_data[3 * 3 * 3] = { - 0, 0, 0, - 0, 2, 0, - 0, 0, 0, - - 0, 2, 0, - 2, 1, 2, - 0, 2, 0, - - 0, 0, 0, - 0, 2, 0, - 0, 0, 0, + 0, + 0, + 0, + 0, + 2, + 0, + 0, + 0, + 0, + + 0, + 2, + 0, + 2, + 1, + 2, + 0, + 2, + 0, + + 0, + 0, + 0, + 0, + 2, + 0, + 0, + 0, + 0, }; const u8 TestSchematic::test_schem2_prob[3 * 3 * 3] = { - 0x00, 0x00, 0x00, - 0x00, 0xFF, 0x00, - 0x00, 0x00, 0x00, - - 0x00, 0xFF, 0x00, - 0xFF, 0xFF, 0xFF, - 0x00, 0xFF, 0x00, - - 0x00, 0x00, 0x00, - 0x00, 0xFF, 0x00, - 0x00, 0x00, 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xFF, + 0x00, + 0x00, + 0x00, + 0x00, + + 0x00, + 0xFF, + 0x00, + 0xFF, + 0xFF, + 0xFF, + 0x00, + 0xFF, + 0x00, + + 0x00, + 0x00, + 0x00, + 0x00, + 0xFF, + 0x00, + 0x00, + 0x00, + 0x00, }; const char *TestSchematic::expected_lua_output = - "schematic = {\n" - "\tsize = {x=3, y=3, z=3},\n" - "\tyslice_prob = {\n" - "\t\t{ypos=0, prob=254},\n" - "\t\t{ypos=1, prob=254},\n" - "\t\t{ypos=2, prob=254},\n" - "\t},\n" - "\tdata = {\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" - "\t\t{name=\"default:lava_source\", prob=254, param2=0, force_place=true},\n" - "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t\t{name=\"air\", prob=0, param2=0},\n" - "\t},\n" - "}\n"; + "schematic = {\n" + "\tsize = {x=3, y=3, z=3},\n" + "\tyslice_prob = {\n" + "\t\t{ypos=0, prob=254},\n" + "\t\t{ypos=1, prob=254},\n" + "\t\t{ypos=2, prob=254},\n" + "\t},\n" + "\tdata = {\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" + "\t\t{name=\"default:lava_source\", prob=254, param2=0, " + "force_place=true},\n" + "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"default:glass\", prob=254, param2=0, force_place=true},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t\t{name=\"air\", prob=0, param2=0},\n" + "\t},\n" + "}\n"; |