Forráskód Böngészése

INtroduce unittests.

Kim Kulling 7 éve
szülő
commit
9f6238f3af

+ 6 - 11
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 <vector>
-#include <string.h> //memset
+#include <string.h>
 #include <string>
 
 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

+ 29 - 31
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<rNormalizedPath.size(); j++ )
-        {
-            if ( rNormalizedPath[j] == delimiter )
-            {
-                rNormalizedPath[ j ] = sep[ 0 ];
+    normalizedPath = rPath;
+    for (const char delimiter : delimiters) {
+        for ( size_t j=0; j<normalizedPath.size(); ++j ) {
+            if ( normalizedPath[j] == delimiter ) {
+                normalizedPath[ j ] = sep[ 0 ];
             }
         }
     }
@@ -139,9 +136,10 @@ static void normalizePathName( const std::string &rPath, std::string &rNormalize
 
 // ------------------------------------------------------------------------------------------------
 //  Constructor.
-Q3BSPFileImporter::Q3BSPFileImporter() :
-    m_pCurrentMesh( NULL ),
-    m_pCurrentFace( NULL ),
+Q3BSPFileImporter::Q3BSPFileImporter()
+:
+    m_pCurrentMesh( nullptr ),
+    m_pCurrentFace(nullptr),
     m_MaterialLookupMap(),
     mTextures()
 {
@@ -151,8 +149,8 @@ Q3BSPFileImporter::Q3BSPFileImporter() :
 // ------------------------------------------------------------------------------------------------
 //  Destructor.
 Q3BSPFileImporter::~Q3BSPFileImporter() {
-    m_pCurrentMesh = NULL;
-    m_pCurrentFace = NULL;
+    m_pCurrentMesh = nullptr;
+    m_pCurrentFace = nullptr;
 
     // Clear face-to-material map
     for ( FaceMap::iterator it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it ) {

+ 3 - 3
code/Q3BSPFileImporter.h

@@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <assimp/BaseImporter.h>
 
 #include <map>
+#include <string>
 
 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<std::string, std::vector<Q3BSP::sQ3BSPFace*>*> FaceMap;
     typedef std::map<std::string, std::vector<Q3BSP::sQ3BSPFace*>* >::iterator FaceMapIt;
     typedef std::map<std::string, std::vector<Q3BSP::sQ3BSPFace*>*>::const_iterator FaceMapConstIt;
@@ -115,5 +116,4 @@ private:
 
 } // Namespace Assimp
 
-
 #endif // ASSIMP_Q3BSPFILEIMPORTER_H_INC

+ 1 - 2
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;
     }

+ 3 - 0
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} )
 

BIN
test/models-nonbsd/PK3/SGDTT3.pk3


+ 64 - 0
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 <assimp/Importer.hpp>
+#include <assimp/postprocess.h>
+
+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());
+}

+ 64 - 0
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 <assimp/Importer.hpp>
+#include <assimp/postprocess.h>
+
+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());
+}