3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 class TestVoxelManipulator : public TestBase {
30 TestVoxelManipulator() { TestManager::registerTestModule(this); }
31 const char *getName() { return "TestVoxelManipulator"; }
33 void runTests(IGameDef *gamedef);
36 void testVoxelManipulator(INodeDefManager *nodedef);
39 static TestVoxelManipulator g_test_instance;
41 void TestVoxelManipulator::runTests(IGameDef *gamedef)
44 TEST(testVoxelManipulator, gamedef->getNodeDefManager());
47 ////////////////////////////////////////////////////////////////////////////////
49 void TestVoxelManipulator::testVoxelArea()
51 VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
52 UASSERT(a.index(0,0,0) == 1*3*3 + 1*3 + 1);
53 UASSERT(a.index(-1,-1,-1) == 0);
55 VoxelArea c(v3s16(-2,-2,-2), v3s16(2,2,2));
56 // An area that is 1 bigger in x+ and z-
57 VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2));
59 std::list<VoxelArea> aa;
63 std::vector<VoxelArea> results;
64 results.push_back(VoxelArea(v3s16(-2,-2,-3), v3s16(3,2,-3)));
65 results.push_back(VoxelArea(v3s16(3,-2,-2), v3s16(3,2,2)));
67 UASSERT(aa.size() == results.size());
69 infostream<<"Result of diff:"<<std::endl;
70 for (std::list<VoxelArea>::const_iterator
71 it = aa.begin(); it != aa.end(); ++it) {
72 it->print(infostream);
73 infostream << std::endl;
75 std::vector<VoxelArea>::iterator j;
76 j = std::find(results.begin(), results.end(), *it);
77 UASSERT(j != results.end());
83 void TestVoxelManipulator::testVoxelManipulator(INodeDefManager *nodedef)
87 v.print(infostream, nodedef);
89 infostream << "*** Setting (-1,0,-1)=2 ***" << std::endl;
90 v.setNodeNoRef(v3s16(-1,0,-1), MapNode(t_CONTENT_GRASS));
92 v.print(infostream, nodedef);
93 UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == t_CONTENT_GRASS);
95 infostream << "*** Reading from inexistent (0,0,-1) ***" << std::endl;
97 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
98 v.print(infostream, nodedef);
100 infostream << "*** Adding area ***" << std::endl;
102 VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
104 v.print(infostream, nodedef);
106 UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == t_CONTENT_GRASS);
107 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));