Moved cPrefab parser self-check to the LoadablePieces test. (#3536)
This commit is contained in:
parent
5ffe920f29
commit
e28cecb3d1
@ -15,111 +15,6 @@ uses a prefabricate in a cBlockArea for drawing itself.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef SELF_TEST
|
|
||||||
|
|
||||||
// Create one static prefab to test the parser:
|
|
||||||
static const cPrefab::sDef g_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,
|
|
||||||
};
|
|
||||||
|
|
||||||
static cPrefab g_TestPrefab(g_TestPrefabDef);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cPrefab::cPrefab(const cPrefab::sDef & a_Def) :
|
cPrefab::cPrefab(const cPrefab::sDef & a_Def) :
|
||||||
m_Size(a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ),
|
m_Size(a_Def.m_SizeX, a_Def.m_SizeY, a_Def.m_SizeZ),
|
||||||
m_HitBox(
|
m_HitBox(
|
||||||
|
@ -88,7 +88,8 @@ endif()
|
|||||||
|
|
||||||
source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
|
source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
|
||||||
source_group("Sources" FILES ${SRCS})
|
source_group("Sources" FILES ${SRCS})
|
||||||
add_executable(LoadablePieces ${SRCS} ${SHARED_SRCS} ${SHARED_HDRS})
|
source_group("Data files" FILES Test.cubeset Test1.schematic)
|
||||||
|
add_executable(LoadablePieces ${SRCS} ${SHARED_SRCS} ${SHARED_HDRS} Test.cubeset Test1.schematic)
|
||||||
target_link_libraries(LoadablePieces tolualib zlib)
|
target_link_libraries(LoadablePieces tolualib zlib)
|
||||||
add_test(NAME LoadablePieces-test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND LoadablePieces)
|
add_test(NAME LoadablePieces-test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND LoadablePieces)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int DoTest(void)
|
static int DoLoaderTest(void)
|
||||||
{
|
{
|
||||||
cPrefabPiecePool test;
|
cPrefabPiecePool test;
|
||||||
auto res = test.LoadFromFile("Test.cubeset", true);
|
auto res = test.LoadFromFile("Test.cubeset", true);
|
||||||
@ -39,6 +39,117 @@ static int DoTest(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
LOGD("Test started");
|
LOGD("Test started");
|
||||||
@ -48,9 +159,18 @@ int main(int argc, char * argv[])
|
|||||||
GetCurrentFolder(folder, sizeof(folder));
|
GetCurrentFolder(folder, sizeof(folder));
|
||||||
LOG("Running cPrefabPiecePool test from folder \"%s\".", folder);
|
LOG("Running cPrefabPiecePool test from folder \"%s\".", folder);
|
||||||
|
|
||||||
// Run the test:
|
// Run the Loader test:
|
||||||
int res = DoTest();
|
int res = DoLoaderTest();
|
||||||
LOG("cPrefabPiecePool loading test done: %s", (res == 0) ? "success" : "failure");
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,9 +106,10 @@ Cubeset =
|
|||||||
["MergeStrategy"] = "msSpongePrint",
|
["MergeStrategy"] = "msSpongePrint",
|
||||||
["IsStarting"] = "1",
|
["IsStarting"] = "1",
|
||||||
["DepthWeight"] = "",
|
["DepthWeight"] = "",
|
||||||
["ShouldExpandFloor"] = "1",
|
["ExpandFloorStrategy"] = "None",
|
||||||
["MoveToGround"] = "1",
|
["MoveToGround"] = "1",
|
||||||
["AddWeightIfSame"] = "0",
|
["AddWeightIfSame"] = "0",
|
||||||
|
["VerticalStrategy"] = "Fixed|150",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -141,7 +142,7 @@ Cubeset =
|
|||||||
["MergeStrategy"] = "msSpongePrint",
|
["MergeStrategy"] = "msSpongePrint",
|
||||||
["IsStarting"] = "0",
|
["IsStarting"] = "0",
|
||||||
["DepthWeight"] = "",
|
["DepthWeight"] = "",
|
||||||
["ShouldExpandFloor"] = "1",
|
["ExpandFloorStrategy"] = "None",
|
||||||
["MoveToGround"] = "0",
|
["MoveToGround"] = "0",
|
||||||
["AddWeightIfSame"] = "0",
|
["AddWeightIfSame"] = "0",
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user