From 9f6238f3af3a013ac77bb2da285167abcc84338b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 22 Sep 2018 15:50:40 +0200 Subject: [PATCH] INtroduce unittests. --- code/Q3BSPFileData.h | 17 ++--- code/Q3BSPFileImporter.cpp | 60 ++++++++-------- code/Q3BSPFileImporter.h | 6 +- code/Q3BSPFileParser.cpp | 3 +- test/CMakeLists.txt | 3 + test/models-nonbsd/PK3/SGDTT3.pk3 | Bin 314762 -> 314764 bytes test/unit/ImportExport/utOgreImportExport.cpp | 64 ++++++++++++++++++ .../ImportExport/utQ3BSPFileImportExport.cpp | 64 ++++++++++++++++++ 8 files changed, 170 insertions(+), 47 deletions(-) create mode 100644 test/unit/ImportExport/utOgreImportExport.cpp create mode 100644 test/unit/ImportExport/utQ3BSPFileImportExport.cpp diff --git a/code/Q3BSPFileData.h b/code/Q3BSPFileData.h index eb3a1444a..d814837c2 100644 --- a/code/Q3BSPFileData.h +++ b/code/Q3BSPFileData.h @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define ASSIMP_Q3BSPFILEDATA_H_INC #include -#include //memset +#include #include namespace Assimp { @@ -77,25 +77,21 @@ struct sQ3BSPHeader { }; /// Describes an entry. -struct sQ3BSPLump -{ +struct sQ3BSPLump { int iOffset; ///< Offset from start pointer of file int iSize; ///< Size of part }; -struct vec2f -{ +struct vec2f { float x,y; }; -struct vec3f -{ +struct vec3f { float x, y, z; }; /// Vertex of a Q3 level -struct sQ3BSPVertex -{ +struct sQ3BSPVertex { vec3f vPosition; ///< Position of vertex vec2f vTexCoord; ///< (u,v) Texturecoordinate of detailtexture vec2f vLightmap; ///< (u,v) Texturecoordinate of lightmap @@ -104,8 +100,7 @@ struct sQ3BSPVertex }; /// A face in bsp format info -struct sQ3BSPFace -{ +struct sQ3BSPFace { int iTextureID; ///< Index in texture array int iEffect; ///< Index in effect array (-1 = no effect) int iType; ///< 1=Polygon, 2=Patch, 3=Mesh, 4=Billboard diff --git a/code/Q3BSPFileImporter.cpp b/code/Q3BSPFileImporter.cpp index aad2bf93c..c06636df0 100644 --- a/code/Q3BSPFileImporter.cpp +++ b/code/Q3BSPFileImporter.cpp @@ -82,39 +82,39 @@ using namespace Q3BSP; // ------------------------------------------------------------------------------------------------ // Local function to create a material key name. -static void createKey( int id1, int id2, std::string &rKey ) -{ +static void createKey( int id1, int id2, std::string &key ) { std::ostringstream str; str << id1 << "." << id2; - rKey = str.str(); + key = str.str(); } // ------------------------------------------------------------------------------------------------ // Local function to extract the texture ids from a material key-name. -static void extractIds( const std::string &rKey, int &rId1, int &rId2 ) -{ - rId1 = -1; - rId2 = -1; - if ( rKey.empty() ) +static void extractIds( const std::string &key, int &id1, int &id2 ) { + id1 = -1; + id2 = -1; + if (key.empty()) { return; + } - std::string::size_type pos = rKey.find( "." ); - if ( std::string::npos == pos ) + const std::string::size_type pos = key.find( "." ); + if (std::string::npos == pos) { return; + } - std::string tmp1 = rKey.substr( 0, pos ); - std::string tmp2 = rKey.substr( pos + 1, rKey.size() - pos - 1 ); - rId1 = atoi( tmp1.c_str() ); - rId2 = atoi( tmp2.c_str() ); + std::string tmp1 = key.substr( 0, pos ); + std::string tmp2 = key.substr( pos + 1, key.size() - pos - 1 ); + id1 = atoi( tmp1.c_str() ); + id2 = atoi( tmp2.c_str() ); } // ------------------------------------------------------------------------------------------------ // Local helper function to normalize filenames. -static void normalizePathName( const std::string &rPath, std::string &rNormalizedPath ) -{ - rNormalizedPath = ""; - if ( rPath.empty() ) +static void normalizePathName( const std::string &rPath, std::string &normalizedPath ) { + normalizedPath = ""; + if (rPath.empty()) { return; + } #ifdef _WIN32 std::string sep = "\\"; @@ -124,14 +124,11 @@ static void normalizePathName( const std::string &rPath, std::string &rNormalize static const unsigned int numDelimiters = 2; const char delimiters[ numDelimiters ] = { '/', '\\' }; - rNormalizedPath = rPath; - for (const char delimiter : delimiters) - { - for ( size_t j=0; j #include +#include struct aiMesh; struct aiNode; @@ -53,6 +54,7 @@ struct aiMaterial; struct aiTexture; namespace Assimp { + namespace Q3BSP { class Q3BSPZipArchive; struct Q3BSPModel; @@ -71,12 +73,11 @@ public: /// @brief Destructor. ~Q3BSPFileImporter(); -public: /// @brief Returns whether the class can handle the format of the given file. /// @remark See BaseImporter::CanRead() for details. bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig ) const; -private: +protected: typedef std::map*> FaceMap; typedef std::map* >::iterator FaceMapIt; typedef std::map*>::const_iterator FaceMapConstIt; @@ -115,5 +116,4 @@ private: } // Namespace Assimp - #endif // ASSIMP_Q3BSPFILEIMPORTER_H_INC diff --git a/code/Q3BSPFileParser.cpp b/code/Q3BSPFileParser.cpp index c53280cb5..f4aea28e6 100644 --- a/code/Q3BSPFileParser.cpp +++ b/code/Q3BSPFileParser.cpp @@ -103,8 +103,7 @@ bool Q3BSPFileParser::readData( const std::string &rMapName ) m_Data.resize( size ); const size_t readSize = pMapFile->Read( &m_Data[0], sizeof( char ), size ); - if ( readSize != size ) - { + if ( readSize != size ) { m_Data.clear(); return false; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2c1496d65..687432085 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -118,6 +118,8 @@ SET( IMPORTERS unit/utMDCImportExport.cpp unit/utAssbinImportExport.cpp unit/ImportExport/utCOBImportExport.cpp + unit/ImportExport/utOgreImportExport.cpp + unit/ImportExport/utQ3BSPFileImportExport.cpp ) SET( MATERIAL @@ -175,6 +177,7 @@ add_executable( unit ) add_definitions(-DASSIMP_TEST_MODELS_DIR="${CMAKE_CURRENT_LIST_DIR}/models") +add_definitions(-DASSIMP_TEST_MODELS_NONBSD_DIR="${CMAKE_CURRENT_LIST_DIR}/models-nonbsd") SET_PROPERTY( TARGET assimp PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} ) diff --git a/test/models-nonbsd/PK3/SGDTT3.pk3 b/test/models-nonbsd/PK3/SGDTT3.pk3 index 3eeb015c32ccc14a97fdbecb3fd4cabdf2587fea..0d997e5d92421a0a509d637f0ffaea1117b761e2 100644 GIT binary patch delta 33 ncmeC0E!;C(xS@ryg{g&k3roNRM&9iK6Ig@=fpqdh7Ihr}y(0<= delta 29 lcmeB~E!;I*xS@ryg{g&k3roO+?ST_mgax;!E@V;H0RW&D3Gn~` diff --git a/test/unit/ImportExport/utOgreImportExport.cpp b/test/unit/ImportExport/utOgreImportExport.cpp new file mode 100644 index 000000000..1950fc90a --- /dev/null +++ b/test/unit/ImportExport/utOgreImportExport.cpp @@ -0,0 +1,64 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (assimp) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2018, 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 "SceneDiffer.h" +#include "AbstractImportExportBase.h" + +#include +#include + +using namespace Assimp; + +class utOgreImportExport : public AbstractImportExportBase { +public: + virtual bool importerTest() { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/Ogre/TheThing/Mesh.mesh.xml", aiProcess_ValidateDataStructure); + return nullptr != scene; + } +}; + +TEST_F(utOgreImportExport, importerTest ) { + EXPECT_TRUE(importerTest()); +} diff --git a/test/unit/ImportExport/utQ3BSPFileImportExport.cpp b/test/unit/ImportExport/utQ3BSPFileImportExport.cpp new file mode 100644 index 000000000..ba12652b4 --- /dev/null +++ b/test/unit/ImportExport/utQ3BSPFileImportExport.cpp @@ -0,0 +1,64 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (assimp) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2018, 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 "SceneDiffer.h" +#include "AbstractImportExportBase.h" + +#include +#include + +using namespace Assimp; + +class utQ3BSPImportExport : public AbstractImportExportBase { +public: + virtual bool importerTest() { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_NONBSD_DIR "/PK3/SGDTT3.pk3", 0); + return nullptr != scene; + } +}; + +TEST_F(utQ3BSPImportExport, importerTest) { + EXPECT_TRUE(importerTest()); +}