From 1bfff8ba1dcf7000d2bf08fb36a2974e947e2c93 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 22 May 2017 21:11:01 +0200 Subject: [PATCH 1/4] ObjImporter: Add unittest. --- test/CMakeLists.txt | 1 + test/unit/utObjTools.cpp | 65 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/unit/utObjTools.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e6c3624ea..781cadf6b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -106,6 +106,7 @@ SET( TEST_SRCS unit/SceneDiffer.cpp unit/utSIBImporter.cpp unit/utObjImportExport.cpp + unit/utObjTools.cpp unit/utPretransformVertices.cpp unit/utPLYImportExport.cpp unit/utRemoveComments.cpp diff --git a/test/unit/utObjTools.cpp b/test/unit/utObjTools.cpp new file mode 100644 index 000000000..d332f0fc8 --- /dev/null +++ b/test/unit/utObjTools.cpp @@ -0,0 +1,65 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (assimp) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2017, assimp team + + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above +copyright notice, this list of conditions and the +following disclaimer. + +* Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the +following disclaimer in the documentation and/or other +materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its +contributors may be used to endorse or promote products +derived from this software without specific prior +written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ +#include "UnitTestPCH.h" +#include "ObjTools.h" + +using namespace ::Assimp; + +class utObjTools : public ::testing::Test { + // empty +}; + +TEST_F( utObjTools, skipDataLine_OneLine_Success ) { + std::vector buffer; + std::string data( "v -0.5 -0.5 0.5\nend" ); + buffer.resize( data.size() ); + ::memcpy( &buffer[ 0 ], &data[ 0 ], data.size() ); + std::vector::iterator itBegin( buffer.begin() ), itEnd( buffer.end() ); + unsigned int line = 0; + std::vector::iterator current = skipLine::iterator>( itBegin, itEnd, line ); + EXPECT_EQ( 'e', *current ); +} + +TEST_F( utObjTools, skipDataLine_TwoLines_Success ) { + std::string data( "vn - 2.061493116917992e-15 - 0.9009688496589661 \ \n- 0.4338837265968323 " ); + +} \ No newline at end of file From fb33199d99862ef6d6bde108401a24f73d5fb5a2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 25 May 2017 22:34:45 +0200 Subject: [PATCH 2/4] GLTFImporter: exclude headers from build whem no_glft_importer is defined. --- code/glTFAsset.h | 10 +++++++--- code/glTFAssetWriter.h | 10 +++++++--- code/glTFExporter.h | 6 +++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/code/glTFAsset.h b/code/glTFAsset.h index 8e45fec13..41d0dfd06 100644 --- a/code/glTFAsset.h +++ b/code/glTFAsset.h @@ -46,8 +46,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * KHR_binary_glTF: full * KHR_materials_common: full */ -#ifndef glTFAsset_H_INC -#define glTFAsset_H_INC +#ifndef GLTFASSET_H_INC +#define GLTFASSET_H_INC + +#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER #include #include @@ -1187,4 +1189,6 @@ namespace glTF // Include the implementation of the methods #include "glTFAsset.inl" -#endif +#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER + +#endif // GLTFASSET_H_INC diff --git a/code/glTFAssetWriter.h b/code/glTFAssetWriter.h index ccfb9986d..186d32a15 100644 --- a/code/glTFAssetWriter.h +++ b/code/glTFAssetWriter.h @@ -46,8 +46,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * KHR_binary_glTF: full * KHR_materials_common: full */ -#ifndef glTFAssetWriter_H_INC -#define glTFAssetWriter_H_INC +#ifndef GLTFASSETWRITER_H_INC +#define GLTFASSETWRITER_H_INC + +#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER #include "glTFAsset.h" @@ -88,4 +90,6 @@ public: // Include the implementation of the methods #include "glTFAssetWriter.inl" -#endif +#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER + +#endif // GLTFASSETWRITER_H_INC diff --git a/code/glTFExporter.h b/code/glTFExporter.h index 835b67dc9..c813fff44 100644 --- a/code/glTFExporter.h +++ b/code/glTFExporter.h @@ -45,6 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_GLTFEXPORTER_H_INC #define AI_GLTFEXPORTER_H_INC +#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER + #include #include @@ -111,4 +113,6 @@ namespace Assimp } -#endif +#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER + +#endif // AI_GLTFEXPORTER_H_INC From f3407ef80477d722efe2849f37e98b533608ee42 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 25 May 2017 22:35:27 +0200 Subject: [PATCH 3/4] aiMetaData: introduce aiMetaData::Dealloc. --- include/assimp/metadata.h | 9 ++++++++- test/unit/utMetadata.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/assimp/metadata.h b/include/assimp/metadata.h index e57525092..ded08d14b 100644 --- a/include/assimp/metadata.h +++ b/include/assimp/metadata.h @@ -134,7 +134,6 @@ struct aiMetadata { // empty } - /** * @brief The destructor. */ @@ -199,6 +198,14 @@ struct aiMetadata { return data; } + /** + * @brief Deallocates property fields + keys. + */ + static inline + void Dealloc( aiMetadata *metadata ) { + delete metadata; + } + template inline void Add(const std::string& key, const T& value) { diff --git a/test/unit/utMetadata.cpp b/test/unit/utMetadata.cpp index fc9216266..b44de1eb2 100644 --- a/test/unit/utMetadata.cpp +++ b/test/unit/utMetadata.cpp @@ -55,7 +55,7 @@ protected: } virtual void TearDown() { - delete m_data; + aiMetadata::Dealloc( m_data ); } }; From e93355c8b435046e6157681ff4fe626ce67c0a84 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 26 May 2017 09:18:23 +0200 Subject: [PATCH 4/4] Build: fix some compiler warnings for g++. --- code/ObjExporter.cpp | 9 +++++++-- code/ObjExporter.h | 3 --- code/SIBImporter.cpp | 27 ++++++++++++--------------- test/unit/utBlendImportMaterials.cpp | 6 +++--- test/unit/utIOSystem.cpp | 7 ++++--- test/unit/utOpenGEXImportExport.cpp | 1 + 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/code/ObjExporter.cpp b/code/ObjExporter.cpp index e309faf79..14035c262 100644 --- a/code/ObjExporter.cpp +++ b/code/ObjExporter.cpp @@ -87,11 +87,16 @@ static const std::string MaterialExt = ".mtl"; ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene) : filename(_filename) , pScene(pScene) -, endl("\n") , vp() , vn() , vt() -, vc() { +, vc() +, vpMap() +, vnMap() +, vtMap() +, vcMap() +, meshes() +, endl("\n") { // make sure that all formatting happens using the standard, C locale and not the user's current locale const std::locale& l = std::locale("C"); mOutput.imbue(l); diff --git a/code/ObjExporter.h b/code/ObjExporter.h index 754202d7b..0ba042b0b 100644 --- a/code/ObjExporter.h +++ b/code/ObjExporter.h @@ -98,16 +98,13 @@ private: void WriteHeader(std::ostringstream& out); void WriteMaterialFile(); void WriteGeometryFile(); - std::string GetMaterialName(unsigned int index); - void AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat); void AddNode(const aiNode* nd, const aiMatrix4x4& mParent); private: std::string filename; const aiScene* const pScene; - std::vector vp, vn, vt; std::vector vc; diff --git a/code/SIBImporter.cpp b/code/SIBImporter.cpp index bf5d2bfd3..87e0d1585 100644 --- a/code/SIBImporter.cpp +++ b/code/SIBImporter.cpp @@ -66,7 +66,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include - using namespace Assimp; static const aiImporterDesc desc = { @@ -80,25 +79,26 @@ static const aiImporterDesc desc = { "sib" }; -struct SIBChunk -{ +struct SIBChunk { uint32_t Tag; uint32_t Size; } PACK_STRUCT; -enum { POS, NRM, UV, N }; +enum { + POS, + NRM, + UV, + N +}; typedef std::pair SIBPair; -static SIBPair makePair(uint32_t a, uint32_t b) { return (a pos, nrm, uv; @@ -109,15 +109,13 @@ struct SIBMesh std::map edgeMap; }; -struct SIBObject -{ +struct SIBObject { aiString name; aiMatrix4x4 axis; size_t meshIdx, meshCount; }; -struct SIB -{ +struct SIB { std::vector mtls; std::vector meshes; std::vector lights; @@ -125,8 +123,7 @@ struct SIB }; // ------------------------------------------------------------------------------------------------ -static SIBEdge& GetEdge(SIBMesh* mesh, uint32_t posA, uint32_t posB) -{ +static SIBEdge& GetEdge(SIBMesh* mesh, uint32_t posA, uint32_t posB) { SIBPair pair = (posA < posB) ? SIBPair(posA, posB) : SIBPair(posB, posA); std::map::iterator it = mesh->edgeMap.find(pair); if (it != mesh->edgeMap.end()) diff --git a/test/unit/utBlendImportMaterials.cpp b/test/unit/utBlendImportMaterials.cpp index 6e20d1299..dd67482ed 100644 --- a/test/unit/utBlendImportMaterials.cpp +++ b/test/unit/utBlendImportMaterials.cpp @@ -70,7 +70,7 @@ TEST_F(BlendImportMaterials, testImportMaterial) ASSERT_TRUE(pTest != NULL); ASSERT_TRUE(pTest->HasMaterials()); - ASSERT_EQ(1, pTest->mNumMaterials); + ASSERT_EQ(1U, pTest->mNumMaterials); auto alpha = pTest->mMaterials[0]; @@ -86,8 +86,8 @@ TEST_F(BlendImportMaterials, testImportMaterial) ASSERT_PROPERTY_EQ(aiColor3D(0.1f, 0.2f, 0.3f), "diffuse.color", diffuseColor); ASSERT_PROPERTY_EQ(0.4f, "diffuse.intensity", diffuseIntensity); - ASSERT_PROPERTY_EQ(1, "diffuse.shader", diffuseShader); - ASSERT_PROPERTY_EQ(0, "diffuse.ramp", diffuseRamp); + ASSERT_PROPERTY_EQ(1U, "diffuse.shader", diffuseShader); + ASSERT_PROPERTY_EQ(0U, "diffuse.ramp", diffuseRamp); ASSERT_PROPERTY_EQ(aiColor3D(0.5f, 0.6f, 0.7f), "specular.color", specularColor); ASSERT_PROPERTY_EQ(0.8f, "specular.intensity", specularIntensity); diff --git a/test/unit/utIOSystem.cpp b/test/unit/utIOSystem.cpp index b339f9ee1..f33b22039 100644 --- a/test/unit/utIOSystem.cpp +++ b/test/unit/utIOSystem.cpp @@ -63,12 +63,13 @@ protected: TEST_F( IOSystemTest, accessDirectoryStackTest ) { EXPECT_FALSE( pImp->PopDirectory() ); - EXPECT_EQ( 0, pImp->StackSize() ); + EXPECT_EQ( 0U, pImp->StackSize() ); EXPECT_FALSE( pImp->PushDirectory( "" ) ); std::string path = "test/"; EXPECT_TRUE( pImp->PushDirectory( path ) ); - EXPECT_EQ( 1, pImp->StackSize() ); + EXPECT_EQ( 1U, pImp->StackSize() ); EXPECT_EQ( path, pImp->CurrentDirectory() ); EXPECT_TRUE( pImp->PopDirectory() ); - EXPECT_EQ( 0, pImp->StackSize() ); + EXPECT_EQ( 0U, pImp->StackSize() ); } + diff --git a/test/unit/utOpenGEXImportExport.cpp b/test/unit/utOpenGEXImportExport.cpp index c9454f6f6..60e8ce3a2 100644 --- a/test/unit/utOpenGEXImportExport.cpp +++ b/test/unit/utOpenGEXImportExport.cpp @@ -66,5 +66,6 @@ TEST_F( utOpenGEXImportExport, importLWSFromFileTest ) { TEST_F( utOpenGEXImportExport, Importissue1262_NoCrash ) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/OpenGEX/light_issue1262.ogex", 0 ); + EXPECT_NE( nullptr, scene ); }