Skip to content

Commit 1f5b8f8

Browse files
committedMar 25, 2024
tester.cc - extend MSFT_lod test
1 parent b274b34 commit 1f5b8f8

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed
 

‎tests/tester.cc

+41-16
Original file line numberDiff line numberDiff line change
@@ -978,19 +978,20 @@ TEST_CASE("serialize-lods", "[lods]") {
978978
{
979979
tinygltf::Model m;
980980

981-
m.nodes.resize(3);
981+
m.nodes.resize(4);
982982
// Add Node 1 and Node 2 as lods to Node 0
983983
m.nodes[0].lods.push_back(1);
984984
m.nodes[0].lods.push_back(2);
985985

986986
// Add Material 1 and Material 2 as lods to Material 0
987-
m.materials.resize(3);
987+
m.materials.resize(4);
988988
m.materials[0].lods.push_back(1);
989989
m.materials[0].lods.push_back(2);
990990

991991
tinygltf::Scene scene;
992-
// Scene uses Node 0 as root node
992+
// Scene uses Node 0 and 3 as root node
993993
scene.nodes.push_back(0);
994+
scene.nodes.push_back(3);
994995
// Add scene to the model
995996
m.scenes.push_back(scene);
996997

@@ -1006,28 +1007,52 @@ TEST_CASE("serialize-lods", "[lods]") {
10061007
// Parse the serialized model
10071008
bool ok = ctx.LoadASCIIFromString(&m, nullptr, nullptr, os.str().c_str(), os.str().size(), "");
10081009
REQUIRE(true == ok);
1009-
1010-
// Make sure all three materials are there
1011-
REQUIRE(3 == m.materials.size());
1010+
// Make sure the model's used extensions hold MSFT_lod
1011+
CHECK(m.extensionsUsed.size() == 1);
1012+
CHECK(m.extensionsUsed[0].compare("MSFT_lod") == 0);
1013+
// MSFT_lod is not a required extension
1014+
CHECK(m.extensionsRequired.size() == 0);
1015+
1016+
// Make sure all four materials are there
1017+
REQUIRE(4 == m.materials.size());
10121018
// Make sure the first material has both lod materials
10131019
REQUIRE(2 == m.materials[0].lods.size());
10141020
// Make sure the order is still the same after serialization and deserialization
10151021
CHECK(1 == m.materials[0].lods[0]);
10161022
CHECK(2 == m.materials[0].lods[1]);
1023+
// Make sure the material with lods exposes the MSFT_lod extension
1024+
CHECK(m.materials[0].extensions.size() == 1);
1025+
CHECK(m.materials[0].extensions.count("MSFT_lod") == 1);
1026+
// Make sure the last material has no lod materials
1027+
CHECK(0 == m.materials[3].lods.size());
1028+
// Make sure the material without lods does not exposes the MSFT_lod extension
1029+
CHECK(m.materials[3].extensions.size() == 0);
1030+
CHECK(m.materials[3].extensions.count("MSFT_lod") == 0);
10171031

10181032
// Make sure the single scene is there
10191033
REQUIRE(1 == m.scenes.size());
1020-
// Make sure all three nodes are there
1021-
REQUIRE(3 == m.nodes.size());
1022-
// Make sure the single root node of the scene is there
1023-
REQUIRE(1 == m.scenes[0].nodes.size());
1034+
// Make sure all four nodes are there
1035+
REQUIRE(4 == m.nodes.size());
1036+
// Make sure the two root nodes of the scene are there
1037+
REQUIRE(2 == m.scenes[0].nodes.size());
10241038
REQUIRE(0 == m.scenes[0].nodes[0]);
1025-
// Retrieve the scene root node
1026-
const tinygltf::Node& node = m.nodes[m.scenes[0].nodes[0]];
1027-
// Make sure the single root node has both lod nodes
1028-
REQUIRE(2 == node.lods.size());
1039+
REQUIRE(3 == m.scenes[0].nodes[1]);
1040+
// Retrieve the node with lods
1041+
const tinygltf::Node& nodeWithLods = m.nodes[m.scenes[0].nodes[0]];
1042+
// Make sure the node has both lod nodes
1043+
REQUIRE(2 == nodeWithLods.lods.size());
10291044
// Make sure the order is still the same after serialization and deserialization
1030-
CHECK(1 == node.lods[0]);
1031-
CHECK(2 == node.lods[1]);
1045+
CHECK(1 == nodeWithLods.lods[0]);
1046+
CHECK(2 == nodeWithLods.lods[1]);
1047+
// Make sure the node with lods exposes the MSFT_lod extension
1048+
CHECK(nodeWithLods.extensions.size() == 1);
1049+
CHECK(nodeWithLods.extensions.count("MSFT_lod") == 1);
1050+
// Retrieve the node without lods
1051+
const tinygltf::Node& nodeWithoutLods = m.nodes[m.scenes[0].nodes[1]];
1052+
// Make sure the node has no lod nodes
1053+
CHECK(0 == nodeWithoutLods.lods.size());
1054+
// Make sure the node without lods does not exposes the MSFT_lod extension
1055+
CHECK(nodeWithoutLods.extensions.size() == 0);
1056+
CHECK(nodeWithoutLods.extensions.count("MSFT_lod") == 0);
10321057
}
10331058
}

0 commit comments

Comments
 (0)
Please sign in to comment.