From 7e7161852ae2a724e1f44667294b048a3281f670 Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Wed, 15 Jul 2020 11:19:10 +0100 Subject: [PATCH] Add a unit test. --- .../glTF2/IndexOutOfRange/IndexOutOfRange.bin | Bin 0 -> 648 bytes .../IndexOutOfRange/IndexOutOfRange.gltf | 142 ++++++++++++++++++ test/unit/utglTF2ImportExport.cpp | 28 ++++ 3 files changed, 170 insertions(+) create mode 100644 test/models/glTF2/IndexOutOfRange/IndexOutOfRange.bin create mode 100644 test/models/glTF2/IndexOutOfRange/IndexOutOfRange.gltf diff --git a/test/models/glTF2/IndexOutOfRange/IndexOutOfRange.bin b/test/models/glTF2/IndexOutOfRange/IndexOutOfRange.bin new file mode 100644 index 0000000000000000000000000000000000000000..b7cfe377b9cdabc5bc9ed9879730941916b3946e GIT binary patch literal 648 zcmb7;0Sbap5JaDqm6es1bsVqe%{p4`2t&(9kc7v~?hM}rf8$^WOMZN(?t))>OE2Y4 zIp=K7|8vXl>iFlv-P0ZFm?6B-oYniRxnr+fzC`YAz-dW4cdufTg sR^{^3{GnpSI;hxCvt<|5>}fb~3>r?foVf%oS2}LogN_G1PhLUK7moElJ^%m! literal 0 HcmV?d00001 diff --git a/test/models/glTF2/IndexOutOfRange/IndexOutOfRange.gltf b/test/models/glTF2/IndexOutOfRange/IndexOutOfRange.gltf new file mode 100644 index 000000000..67561c591 --- /dev/null +++ b/test/models/glTF2/IndexOutOfRange/IndexOutOfRange.gltf @@ -0,0 +1,142 @@ +{ + "asset": { + "generator": "COLLADA2GLTF", + "version": "2.0" + }, + "scene": 0, + "scenes": [ + { + "nodes": [ + 0 + ] + } + ], + "nodes": [ + { + "children": [ + 1 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -1.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0 + ] + }, + { + "mesh": 0 + } + ], + "meshes": [ + { + "primitives": [ + { + "attributes": { + "NORMAL": 1, + "POSITION": 2 + }, + "indices": 0, + "mode": 4, + "material": 0 + } + ], + "name": "Mesh" + } + ], + "accessors": [ + { + "bufferView": 0, + "byteOffset": 0, + "componentType": 5123, + "count": 36, + "max": [ + 255 + ], + "min": [ + 0 + ], + "type": "SCALAR" + }, + { + "bufferView": 1, + "byteOffset": 0, + "componentType": 5126, + "count": 24, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 1, + "byteOffset": 288, + "componentType": 5126, + "count": 24, + "max": [ + 0.5, + 0.5, + 0.5 + ], + "min": [ + -0.5, + -0.5, + -0.5 + ], + "type": "VEC3" + } + ], + "materials": [ + { + "pbrMetallicRoughness": { + "baseColorFactor": [ + 0.800000011920929, + 0.0, + 0.0, + 1.0 + ], + "metallicFactor": 0.0 + }, + "name": "Red" + } + ], + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 576, + "byteLength": 72, + "target": 34963 + }, + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 576, + "byteStride": 12, + "target": 34962 + } + ], + "buffers": [ + { + "byteLength": 648, + "uri": "IndexOutOfRange.bin" + } + ] +} diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 6791d5f89..8bc20e950 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -541,3 +541,31 @@ TEST_F(utglTF2ImportExport, norootnode_issue_3269) { const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/issue_3269/texcoord_crash.gltf", aiProcess_ValidateDataStructure); ASSERT_EQ(scene, nullptr); } + +#include +#include + +TEST_F(utglTF2ImportExport, indexOutOfRange) { + // The contents of an asset should not lead to an assert. + Assimp::Importer importer; + + struct WarningObserver : Assimp::LogStream + { + bool m_observedWarning = false; + void write(const char *message) override + { + m_observedWarning = m_observedWarning || std::strstr(message, "faces were dropped"); + } + }; + WarningObserver warningObserver; + + DefaultLogger::get()->attachStream(&warningObserver); + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/IndexOutOfRange/IndexOutOfRange.gltf", aiProcess_ValidateDataStructure); + ASSERT_NE(scene, nullptr); + ASSERT_NE(scene->mRootNode, nullptr); + ASSERT_EQ(scene->mNumMeshes, 1); + EXPECT_EQ(scene->mMeshes[0]->mNumFaces, 11); + DefaultLogger::get()->detachStream(&warningObserver); + EXPECT_TRUE(warningObserver.m_observedWarning); +} +