Skip to content

Commit e3e2e11

Browse files
committed
CgltfImporter: test missing buffers for all code paths
1 parent f01abff commit e3e2e11

File tree

5 files changed

+268
-0
lines changed

5 files changed

+268
-0
lines changed

src/MagnumPlugins/CgltfImporter/Test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ corrade_add_test(CgltfImporterTest
5959
${CgltfImporterTest_RESOURCES}
6060
LIBRARIES Magnum::Trade
6161
FILES
62+
animation-buffer-notfound.gltf
6263
# modified version of animation-patching.* from TinyGltfImporter
6364
# without size mismatch between input and output samplers
6465
animation-patching-fixed.bin
@@ -74,12 +75,14 @@ corrade_add_test(CgltfImporterTest
7475
external-data-order.gltf
7576
image-buffer-notfound.gltf
7677
image-no-data.gltf
78+
mesh-indices-buffer-notfound.gltf
7779
mesh-invalid-accessor-types.gltf
7880
mesh-invalid-skin-attributes.gltf
7981
mesh-skin-attributes.bin
8082
mesh-skin-attributes.gltf
8183
scene-invalid-child-not-root.gltf
8284
scene-invalid-multiple-parents.gltf
85+
skin-buffer-notfound.gltf
8386
texture-extensions-invalid-basisu-oob.gltf
8487
texture-extensions-invalid.gltf
8588
texture-extensions.gltf

src/MagnumPlugins/CgltfImporter/Test/CgltfImporterTest.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct CgltfImporterTest: TestSuite::Tester {
8484
void animation();
8585
void animationOutOfBounds();
8686
void animationInvalid();
87+
void animationInvalidBufferNotFound();
8788
void animationInvalidInterpolation();
8889
void animationMismatchingCount();
8990
void animationMissingTargetNode();
@@ -122,6 +123,7 @@ struct CgltfImporterTest: TestSuite::Tester {
122123
void skin();
123124
void skinOutOfBounds();
124125
void skinInvalid();
126+
void skinInvalidBufferNotFound();
125127
void skinNoJointsProperty();
126128

127129
void mesh();
@@ -138,6 +140,7 @@ struct CgltfImporterTest: TestSuite::Tester {
138140
void meshPrimitivesTypes();
139141
void meshOutOfBounds();
140142
void meshInvalid();
143+
void meshInvalidIndicesBufferNotFound();
141144
void meshInvalidSkinAttributes();
142145
void meshInvalidTypes();
143146

@@ -258,6 +261,14 @@ constexpr struct {
258261
{"unsupported path", "unsupported track target 0"}
259262
};
260263

264+
constexpr struct {
265+
const char* name;
266+
const char* message;
267+
} AnimationInvalidBufferNotFoundData[]{
268+
{"input buffer not found", "error opening file: /nonexistent1.bin : file not found"},
269+
{"output buffer not found", "error opening file: /nonexistent2.bin : file not found"}
270+
};
271+
261272
constexpr struct {
262273
const char* name;
263274
const char* message;
@@ -603,6 +614,9 @@ CgltfImporterTest::CgltfImporterTest() {
603614
addInstancedTests({&CgltfImporterTest::animationInvalid},
604615
Containers::arraySize(AnimationInvalidData));
605616

617+
addInstancedTests({&CgltfImporterTest::animationInvalidBufferNotFound},
618+
Containers::arraySize(AnimationInvalidBufferNotFoundData));
619+
606620
addTests({&CgltfImporterTest::animationInvalidInterpolation,
607621
&CgltfImporterTest::animationMismatchingCount,
608622
&CgltfImporterTest::animationMissingTargetNode});
@@ -661,6 +675,8 @@ CgltfImporterTest::CgltfImporterTest() {
661675
addInstancedTests({&CgltfImporterTest::skinInvalid},
662676
Containers::arraySize(SkinInvalidData));
663677

678+
addTests({&CgltfImporterTest::skinInvalidBufferNotFound});
679+
664680
addInstancedTests({&CgltfImporterTest::skinOutOfBounds},
665681
Containers::arraySize(SkinOutOfBoundsData));
666682

@@ -689,6 +705,8 @@ CgltfImporterTest::CgltfImporterTest() {
689705
addInstancedTests({&CgltfImporterTest::meshInvalid},
690706
Containers::arraySize(MeshInvalidData));
691707

708+
addTests({&CgltfImporterTest::meshInvalidIndicesBufferNotFound});
709+
692710
addInstancedTests({&CgltfImporterTest::meshInvalidSkinAttributes},
693711
Containers::arraySize(MeshInvalidSkinAttributesData));
694712

@@ -1200,6 +1218,27 @@ void CgltfImporterTest::animationInvalid() {
12001218
CORRADE_COMPARE(out.str(), Utility::formatString("Trade::CgltfImporter::animation(): {}\n", data.message));
12011219
}
12021220

1221+
void CgltfImporterTest::animationInvalidBufferNotFound() {
1222+
auto&& data = AnimationInvalidBufferNotFoundData[testCaseInstanceId()];
1223+
setTestCaseDescription(data.name);
1224+
1225+
/* These tests have to be separate from TinyGltfImporter because it errors
1226+
out during import trying to load the buffer */
1227+
1228+
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("CgltfImporter");
1229+
1230+
CORRADE_VERIFY(importer->openFile(Utility::Directory::join(CGLTFIMPORTER_TEST_DIR,
1231+
"animation-buffer-notfound.gltf")));
1232+
1233+
/* Check we didn't forget to test anything */
1234+
CORRADE_COMPARE(importer->animationCount(), Containers::arraySize(AnimationInvalidBufferNotFoundData));
1235+
1236+
std::ostringstream out;
1237+
Error redirectError{&out};
1238+
CORRADE_VERIFY(!importer->animation(data.name));
1239+
CORRADE_COMPARE(out.str(), Utility::formatString("Trade::CgltfImporter::animation(): {}\n", data.message));
1240+
}
1241+
12031242
void CgltfImporterTest::animationInvalidInterpolation() {
12041243
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("CgltfImporter");
12051244

@@ -2285,6 +2324,23 @@ void CgltfImporterTest::skinInvalid() {
22852324
CORRADE_COMPARE(out.str(), Utility::formatString("Trade::CgltfImporter::skin3D(): {}\n", data.message));
22862325
}
22872326

2327+
void CgltfImporterTest::skinInvalidBufferNotFound() {
2328+
/* This test has to be separate from TinyGltfImporter because it errors
2329+
out during import trying to load the buffer */
2330+
2331+
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("CgltfImporter");
2332+
2333+
CORRADE_VERIFY(importer->openFile(Utility::Directory::join(CGLTFIMPORTER_TEST_DIR,
2334+
"skin-buffer-notfound.gltf")));
2335+
2336+
CORRADE_COMPARE(importer->skin3DCount(), 1);
2337+
2338+
std::ostringstream out;
2339+
Error redirectError{&out};
2340+
CORRADE_VERIFY(!importer->skin3D("buffer not found"));
2341+
CORRADE_COMPARE(out.str(), "Trade::CgltfImporter::skin3D(): error opening file: /nonexistent.bin : file not found\n");
2342+
}
2343+
22882344
void CgltfImporterTest::skinNoJointsProperty() {
22892345
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("CgltfImporter");
22902346

@@ -3117,6 +3173,26 @@ void CgltfImporterTest::meshInvalid() {
31173173
CORRADE_COMPARE(out.str(), Utility::formatString("Trade::CgltfImporter::mesh(): {}\n", data.message));
31183174
}
31193175

3176+
void CgltfImporterTest::meshInvalidIndicesBufferNotFound() {
3177+
/* This test has to be separate from TinyGltfImporter because it errors
3178+
out during import trying to load the buffer.
3179+
3180+
Not testing this for the attribute buffer since that's already done by
3181+
openExternalDataNotFound(). */
3182+
3183+
Containers::Pointer<AbstractImporter> importer = _manager.instantiate("CgltfImporter");
3184+
3185+
CORRADE_VERIFY(importer->openFile(Utility::Directory::join(CGLTFIMPORTER_TEST_DIR,
3186+
"mesh-indices-buffer-notfound.gltf")));
3187+
3188+
CORRADE_COMPARE(importer->meshCount(), 1);
3189+
3190+
std::ostringstream out;
3191+
Error redirectError{&out};
3192+
CORRADE_VERIFY(!importer->mesh("indices buffer not found"));
3193+
CORRADE_COMPARE(out.str(), "Trade::CgltfImporter::mesh(): error opening file: /nonexistent.bin : file not found\n");
3194+
}
3195+
31203196
void CgltfImporterTest::meshInvalidSkinAttributes() {
31213197
auto&& data = MeshInvalidSkinAttributesData[testCaseInstanceId()];
31223198
setTestCaseDescription(data.name);
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"asset": {
3+
"version": "2.0"
4+
},
5+
"animations": [
6+
{
7+
"name": "input buffer not found",
8+
"channels": [
9+
{
10+
"sampler": 0,
11+
"target": {
12+
"node": 0,
13+
"path": "rotation"
14+
}
15+
}
16+
],
17+
"samplers": [
18+
{
19+
"input": 2,
20+
"interpolation": "LINEAR",
21+
"output": 1
22+
}
23+
]
24+
},
25+
{
26+
"name": "output buffer not found",
27+
"channels": [
28+
{
29+
"sampler": 0,
30+
"target": {
31+
"node": 0,
32+
"path": "rotation"
33+
}
34+
}
35+
],
36+
"samplers": [
37+
{
38+
"input": 0,
39+
"interpolation": "LINEAR",
40+
"output": 3
41+
}
42+
]
43+
}
44+
],
45+
"accessors": [
46+
{
47+
"bufferView": 0,
48+
"byteOffset": 0,
49+
"componentType": 5126,
50+
"count": 9,
51+
"type": "SCALAR"
52+
},
53+
{
54+
"bufferView": 1,
55+
"byteOffset": 0,
56+
"componentType": 5126,
57+
"count": 9,
58+
"type": "VEC4"
59+
},
60+
{
61+
"bufferView": 2,
62+
"byteOffset": 0,
63+
"componentType": 5126,
64+
"count": 9,
65+
"type": "SCALAR"
66+
},
67+
{
68+
"bufferView": 3,
69+
"byteOffset": 0,
70+
"componentType": 5126,
71+
"count": 9,
72+
"type": "VEC4"
73+
}
74+
],
75+
"bufferViews": [
76+
{
77+
"buffer": 0,
78+
"byteOffset": 0,
79+
"byteLength": 36
80+
},
81+
{
82+
"buffer": 0,
83+
"byteOffset": 36,
84+
"byteLength": 192
85+
},
86+
{
87+
"buffer": 1,
88+
"byteOffset": 0,
89+
"byteLength": 36
90+
},
91+
{
92+
"buffer": 2,
93+
"byteOffset": 36,
94+
"byteLength": 192
95+
}
96+
],
97+
"buffers": [
98+
{
99+
"byteLength": 228,
100+
"uri": "animation-patching-fixed.bin"
101+
},
102+
{
103+
"byteLength": 228,
104+
"uri": "/nonexistent1.bin"
105+
},
106+
{
107+
"byteLength": 228,
108+
"uri": "/nonexistent2.bin"
109+
}
110+
],
111+
"nodes": [
112+
{}
113+
]
114+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"asset": {
3+
"version": "2.0"
4+
},
5+
"meshes": [
6+
{
7+
"name": "indices buffer not found",
8+
"primitives": [
9+
{
10+
"attributes": {},
11+
"indices": 0
12+
}
13+
]
14+
}
15+
],
16+
"accessors": [
17+
{
18+
"bufferView": 0,
19+
"componentType": 5121,
20+
"count": 3,
21+
"type": "SCALAR"
22+
}
23+
],
24+
"bufferViews": [
25+
{
26+
"buffer": 0,
27+
"byteOffset": 0,
28+
"byteLength": 3
29+
}
30+
],
31+
"buffers": [
32+
{
33+
"byteLength": 160,
34+
"uri": "/nonexistent.bin"
35+
}
36+
]
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"asset": {
3+
"version": "2.0"
4+
},
5+
"nodes": [
6+
{},
7+
{}
8+
],
9+
"skins": [
10+
{
11+
"name": "buffer not found",
12+
"inverseBindMatrices": 0,
13+
"joints": [0, 1]
14+
}
15+
],
16+
"accessors": [
17+
{
18+
"bufferView": 0,
19+
"byteOffset": 0,
20+
"componentType": 5126,
21+
"count": 2,
22+
"type": "MAT4"
23+
}
24+
],
25+
"bufferViews": [
26+
{
27+
"buffer": 0,
28+
"byteOffset": 0,
29+
"byteLength": 192
30+
}
31+
],
32+
"buffers": [
33+
{
34+
"byteLength": 192,
35+
"uri": "/nonexistent.bin"
36+
}
37+
]
38+
}

0 commit comments

Comments
 (0)