From c61146f52e0555fe803ded2bd6ca64e44d7a817c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 21 Nov 2016 23:54:39 +0100 Subject: [PATCH] Add unittest fixure for aiMetadata. --- code/Subdivision.cpp | 15 ++++---- include/assimp/metadata.h | 24 ++++++------- test/CMakeLists.txt | 1 + test/unit/utMatrix4x4.cpp | 6 ++-- test/unit/utMetadata.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 25 deletions(-) create mode 100644 test/unit/utMetadata.cpp diff --git a/code/Subdivision.cpp b/code/Subdivision.cpp index 012c700..0a67ad5 100644 --- a/code/Subdivision.cpp +++ b/code/Subdivision.cpp @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SpatialSort.h" #include "ProcessHelper.h" #include "Vertex.h" +#include #include using namespace Assimp; @@ -55,9 +56,7 @@ void mydummy() {} // ------------------------------------------------------------------------------------------------ class CatmullClarkSubdivider : public Subdivider { - public: - void Subdivide (aiMesh* mesh, aiMesh*& out, unsigned int num, bool discard_input); void Subdivide (aiMesh** smesh, size_t nmesh, aiMesh** out, unsigned int num, bool discard_input); @@ -74,8 +73,6 @@ public: unsigned int ref; }; - - typedef std::vector UIntVector; typedef std::map EdgeMap; @@ -99,7 +96,6 @@ public: unsigned int eh_tmp0__, eh_tmp1__; private: - void InternSubdivide (const aiMesh* const * smesh, size_t nmesh,aiMesh** out, unsigned int num); }; @@ -128,7 +124,8 @@ void CatmullClarkSubdivider::Subdivide ( bool discard_input ) { - assert(mesh != out); + ai_assert(mesh != out); + Subdivide(&mesh,1,&out,num,discard_input); } @@ -142,12 +139,12 @@ void CatmullClarkSubdivider::Subdivide ( bool discard_input ) { - ai_assert(NULL != smesh && NULL != out); + ai_assert( NULL != smesh ); + ai_assert( NULL != out ); // course, both regions may not overlap - assert(smeshout+nmesh); + ai_assert(smeshout+nmesh); if (!num) { - // No subdivision at all. Need to copy all the meshes .. argh. if (discard_input) { for (size_t s = 0; s < nmesh; ++s) { diff --git a/include/assimp/metadata.h b/include/assimp/metadata.h index da9d457..8d6912f 100644 --- a/include/assimp/metadata.h +++ b/include/assimp/metadata.h @@ -46,8 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_METADATA_H_INC #define AI_METADATA_H_INC -#include - #if defined(_MSC_VER) && (_MSC_VER <= 1500) #include "Compiler/pstdint.h" #else @@ -55,8 +53,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #endif - - // ------------------------------------------------------------------------------- /** * Enum used to distinguish data types @@ -77,8 +73,6 @@ typedef enum aiMetadataType #endif } aiMetadataType; - - // ------------------------------------------------------------------------------- /** * Metadata entry @@ -179,7 +173,6 @@ struct aiMetadata case FORCE_32BIT: #endif default: - assert(false); break; } } @@ -190,13 +183,13 @@ struct aiMetadata } } - - template - inline void Set( unsigned index, const std::string& key, const T& value ) + inline bool Set( unsigned index, const std::string& key, const T& value ) { // In range assertion - assert(index < mNumProperties); + if ( index >= mNumProperties ) { + return false; + } // Set metadata key mKeys[index] = key; @@ -205,13 +198,17 @@ struct aiMetadata mValues[index].mType = GetAiType(value); // Copy the given value to the dynamic storage mValues[index].mData = new T(value); + + return true; } template inline bool Get( unsigned index, T& value ) { // In range assertion - assert(index < mNumProperties); + if ( index >= mNumProperties ) { + return false; + } // Return false if the output data type does // not match the found value's data type @@ -226,7 +223,8 @@ struct aiMetadata } template - inline bool Get( const aiString& key, T& value ) + inline + bool Get( const aiString& key, T& value ) { // Search for the given key for (unsigned i=0; i + +using namespace ::Assimp; + +class utMetadata: public ::testing::Test { +protected: + aiMetadata *m_data; + + virtual void SetUp() { + m_data = new aiMetadata(); + } + + virtual void TearDown() { + delete m_data; + } + +}; + +TEST_F( utMetadata, creationTest ) { + bool ok( true ); + try { + aiMetadata data; + } catch ( ... ) { + ok = false; + } + EXPECT_TRUE( ok ); +} + +TEST_F( utMetadata, get_set_Test ) { + m_data->mNumProperties = 1; + m_data->mKeys = new aiString[ m_data->mNumProperties ](); + m_data->mValues = new aiMetadataEntry[ m_data->mNumProperties ](); + unsigned int index( 0 ); + bool success( false ); + const std::string key = "test"; + success = m_data->Set( index, key, aiString( std::string( "test" ) ) ); + EXPECT_TRUE( success ); + + aiString result; + success = m_data->Get( key, result ); + EXPECT_TRUE( success ); + + success = m_data->Get( "bla", result ); + EXPECT_FALSE( success ); +} -- 2.7.4