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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
// LoadablePieces.cpp
// Implements the LoadablePieces test main entrypoint
#include "Globals.h"
#ifdef _WIN32
#include <direct.h>
#define GetCurrentFolder _getcwd
#else
#include <unistd.h>
#define GetCurrentFolder getcwd
#endif
#include "../TestHelpers.h"
#include "Generating/PrefabPiecePool.h"
static int DoLoaderTest(void)
{
cPrefabPiecePool test;
auto res = test.LoadFromFile("Test.cubeset", true);
if (!res)
{
LOGWARNING("Loading from file \"Test.cubeset\" failed.");
return 1;
}
LOG("Loaded %u regular pieces and %u starting pieces", static_cast<unsigned>(test.GetAllPiecesCount()), static_cast<unsigned>(test.GetStartingPiecesCount()));
// Check that we loaded all the pieces:
TEST_EQUAL(test.GetAllPiecesCount(), 1);
TEST_EQUAL(test.GetStartingPiecesCount(), 1);
return 0;
}
static int DoParserTest(void)
{
// Create one static prefab to test the parser:
static const cPrefab::sDef testPrefabDef =
{
// Size:
7, 6, 7, // SizeX = 7, SizeY = 6, SizeZ = 7
// Hitbox (relative to bounding box):
0, 0, 0, // MinX, MinY, MinZ
6, 5, 6, // MaxX, MaxY, MaxZ
// Block definitions:
".: 0: 0\n" /* 0 */
"a:112: 0\n" /* netherbrick */
"b:113: 0\n" /* netherbrickfence */,
// Block data:
// Level 1
"aaaaaaa"
"aaaaaaa"
"aaaaaaa"
"aaaaaaa"
"aaaaaaa"
"aaaaaaa"
"aaaaaaa"
// Level 2
"aa...aa"
"a.....a"
"......."
"......."
"......."
"a.....a"
"aa...aa"
// Level 3
"aa...aa"
"a.....a"
"......."
"......."
"......."
"a.....a"
"aa...aa"
// Level 4
"aa...aa"
"a.....a"
"......."
"......."
"......."
"a.....a"
"aa...aa"
// Level 5
"aabbbaa"
"a.....a"
"b.....b"
"b.....b"
"b.....b"
"a.....a"
"aabbbaa"
// Level 6
"aaaaaaa"
"a.....a"
"a.....a"
"a.....a"
"a.....a"
"a.....a"
"aaaaaaa",
// Connections:
"0: 0, 3, 2: 4\n"
"0: 2, 3, 0: 2\n",
// AllowedRotations:
7, /* 1, 2, 3 CCW rotations */
// Merge strategy:
cBlockArea::msImprint,
// ExtendFloorStrategy:
cPrefab::efsNone,
// DefaultWeight:
10,
// DepthWeight:
"",
// AddWeightIfSame:
1000,
// MoveToGround:
false,
};
cPrefab testPrefab(testPrefabDef);
cPiece & prefabAsPiece(testPrefab); // GetConnectors() is private in cPrefab, need to cast to parent cPiece where it is public
if (prefabAsPiece.GetConnectors().size() != 2)
{
LOGWARNING("Piece parsing failed, connectors not parsed properly. Expected 2 connectors, got %u", static_cast<unsigned>(prefabAsPiece.GetConnectors().size()));
}
return 0;
}
int main(int argc, char * argv[])
{
LOGD("Test started");
// Print the current directory for reference:
char folder[FILENAME_MAX];
GetCurrentFolder(folder, sizeof(folder));
LOG("Running cPrefabPiecePool test from folder \"%s\".", folder);
// Run the Loader test:
int res = DoLoaderTest();
LOG("cPrefabPiecePool loading test done: %s", (res == 0) ? "success" : "failure");
if (res != 0)
{
return res;
}
// Run the Parser test:
res = DoParserTest();
LOG("cPrefab parser test done: %s", (res == 0) ? "success" : "failure");
return res;
}
|