1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "test.h"
#include <algorithm>
#include "gamedef.h"
#include "log.h"
#include "voxel.h"
class TestVoxelManipulator : public TestBase
{
public:
TestVoxelManipulator() { TestManager::registerTestModule(this); }
const char *getName() { return "TestVoxelManipulator"; }
void runTests(IGameDef *gamedef);
void testVoxelArea();
void testVoxelManipulator(const NodeDefManager *nodedef);
};
static TestVoxelManipulator g_test_instance;
void TestVoxelManipulator::runTests(IGameDef *gamedef)
{
TEST(testVoxelArea);
TEST(testVoxelManipulator, gamedef->getNodeDefManager());
}
////////////////////////////////////////////////////////////////////////////////
void TestVoxelManipulator::testVoxelArea()
{
VoxelArea a(v3s16(-1, -1, -1), v3s16(1, 1, 1));
UASSERT(a.index(0, 0, 0) == 1 * 3 * 3 + 1 * 3 + 1);
UASSERT(a.index(-1, -1, -1) == 0);
VoxelArea c(v3s16(-2, -2, -2), v3s16(2, 2, 2));
// An area that is 1 bigger in x+ and z-
VoxelArea d(v3s16(-2, -2, -3), v3s16(3, 2, 2));
std::list<VoxelArea> aa;
d.diff(c, aa);
// Correct results
std::vector<VoxelArea> results;
results.emplace_back(v3s16(-2, -2, -3), v3s16(3, 2, -3));
results.emplace_back(v3s16(3, -2, -2), v3s16(3, 2, 2));
UASSERT(aa.size() == results.size());
infostream << "Result of diff:" << std::endl;
for (std::list<VoxelArea>::const_iterator it = aa.begin(); it != aa.end(); ++it) {
it->print(infostream);
infostream << std::endl;
std::vector<VoxelArea>::iterator j;
j = std::find(results.begin(), results.end(), *it);
UASSERT(j != results.end());
results.erase(j);
}
}
void TestVoxelManipulator::testVoxelManipulator(const NodeDefManager *nodedef)
{
VoxelManipulator v;
v.print(infostream, nodedef);
infostream << "*** Setting (-1,0,-1)=2 ***" << std::endl;
v.setNodeNoRef(v3s16(-1, 0, -1), MapNode(t_CONTENT_GRASS));
v.print(infostream, nodedef);
UASSERT(v.getNode(v3s16(-1, 0, -1)).getContent() == t_CONTENT_GRASS);
infostream << "*** Reading from inexistent (0,0,-1) ***" << std::endl;
EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0, 0, -1)));
v.print(infostream, nodedef);
infostream << "*** Adding area ***" << std::endl;
VoxelArea a(v3s16(-1, -1, -1), v3s16(1, 1, 1));
v.addArea(a);
v.print(infostream, nodedef);
UASSERT(v.getNode(v3s16(-1, 0, -1)).getContent() == t_CONTENT_GRASS);
EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0, 1, 1)));
}
|