diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 911c2eed6..c729fc7e5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -56,6 +56,7 @@ SOURCE_GROUP( unit FILES SET( TEST_SRCS unit/TestIOSystem.h + unit/TestModelFactory.h unit/utAnim.cpp unit/AssimpAPITest.cpp unit/utBatchLoader.cpp diff --git a/test/unit/TestModelFactory.h b/test/unit/TestModelFactory.h new file mode 100644 index 000000000..ae44b5921 --- /dev/null +++ b/test/unit/TestModelFactory.h @@ -0,0 +1,57 @@ +#pragma once + +#include "UnitTestPCH.h" +#include +#include + +namespace Assimp { + +class TestModelFacttory { +public: + TestModelFacttory() { + // empty + } + + ~TestModelFacttory() { + // empty + } + + static aiScene *createDefaultTestModel( float &opacity ) { + aiScene *scene( new aiScene ); + scene->mNumMaterials = 1; + scene->mMaterials = new aiMaterial*; + scene->mMaterials[ 0 ] = new aiMaterial; + aiColor3D color( 1, 0, 0 ); + EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &color, 1, AI_MATKEY_COLOR_DIFFUSE ) ); + + ::srand( static_cast< unsigned int >( ::time( NULL ) ) ); + opacity = float( rand() ) / float( RAND_MAX ); + EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &opacity, 1, AI_MATKEY_OPACITY ) ); + + scene->mNumMeshes = 1; + scene->mMeshes = new aiMesh*; + scene->mMeshes[ 0 ] = new aiMesh; + scene->mMeshes[ 0 ]->mMaterialIndex = 0; + scene->mMeshes[ 0 ]->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; + scene->mMeshes[ 0 ]->mNumVertices = 3; + scene->mMeshes[ 0 ]->mVertices = new aiVector3D[ 3 ]; + scene->mMeshes[ 0 ]->mVertices[ 0 ] = aiVector3D( 1, 0, 0 ); + scene->mMeshes[ 0 ]->mVertices[ 1 ] = aiVector3D( 0, 1, 0 ); + scene->mMeshes[ 0 ]->mVertices[ 2 ] = aiVector3D( 0, 0, 1 ); + scene->mMeshes[ 0 ]->mNumFaces = 1; + scene->mMeshes[ 0 ]->mFaces = new aiFace; + scene->mMeshes[ 0 ]->mFaces[ 0 ].mNumIndices = 3; + scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices = new unsigned int[ 3 ]; + scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 0 ] = 0; + scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 1 ] = 1; + scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 2 ] = 2; + + scene->mRootNode = new aiNode; + scene->mRootNode->mNumMeshes = 1; + scene->mRootNode->mMeshes = new unsigned int( 0 ); + + return scene; + } +}; + +} diff --git a/test/unit/utIssues.cpp b/test/unit/utIssues.cpp index 564ff84dc..cae5ee8cc 100644 --- a/test/unit/utIssues.cpp +++ b/test/unit/utIssues.cpp @@ -44,6 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include "TestModelFactory.h" + using namespace Assimp; class utIssues : public ::testing::Test { @@ -53,59 +55,23 @@ class utIssues : public ::testing::Test { #ifndef ASSIMP_BUILD_NO_EXPORT TEST_F( utIssues, OpacityBugWhenExporting_727 ) { - aiScene *scene( new aiScene ); - - scene->mNumMaterials = 1; - scene->mMaterials = new aiMaterial*; - scene->mMaterials[ 0 ] = new aiMaterial; - aiColor3D color( 1, 0, 0 ); - EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &color, 1, AI_MATKEY_COLOR_DIFFUSE ) ); - - ::srand( static_cast( ::time( NULL ) ) ); - float opacity( float( rand() ) / float( RAND_MAX ) ); - EXPECT_EQ( AI_SUCCESS, scene->mMaterials[ 0 ]->AddProperty( &opacity, 1, AI_MATKEY_OPACITY ) ); - - scene->mNumMeshes = 1; - scene->mMeshes = new aiMesh*; - scene->mMeshes[ 0 ] = new aiMesh; - scene->mMeshes[ 0 ]->mMaterialIndex = 0; - scene->mMeshes[ 0 ]->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; - scene->mMeshes[ 0 ]->mNumVertices = 3; - scene->mMeshes[ 0 ]->mVertices = new aiVector3D[ 3 ]; - scene->mMeshes[ 0 ]->mVertices[ 0 ] = aiVector3D( 1, 0, 0 ); - scene->mMeshes[ 0 ]->mVertices[ 1 ] = aiVector3D( 0, 1, 0 ); - scene->mMeshes[ 0 ]->mVertices[ 2 ] = aiVector3D( 0, 0, 1 ); - scene->mMeshes[ 0 ]->mNumFaces = 1; - scene->mMeshes[ 0 ]->mFaces = new aiFace; - scene->mMeshes[ 0 ]->mFaces[ 0 ].mNumIndices = 3; - scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices = new unsigned int[ 3 ]; - scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 0 ] = 0; - scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 1 ] = 1; - scene->mMeshes[ 0 ]->mFaces[ 0 ].mIndices[ 2 ] = 2; - - scene->mRootNode = new aiNode; - scene->mRootNode->mNumMeshes = 1; - scene->mRootNode->mMeshes = new unsigned int( 0 ); - + float opacity; + aiScene *scene( TestModelFacttory::createDefaultTestModel( opacity ) ); Assimp::Importer importer; Assimp::Exporter exporter; - for ( std::size_t i( 0 ); i < exporter.GetExportFormatCount(); ++i ) { - std::string path; - const aiExportFormatDesc *desc( exporter.GetExportFormatDescription( i ) ); - EXPECT_NE( desc, nullptr ); - path.append( desc->fileExtension ); - if ( "dae" == path ) { - EXPECT_EQ( AI_SUCCESS, exporter.Export( scene, desc->id, path ) ); - const aiScene *newScene( importer.ReadFile( path, 0 ) ); - EXPECT_TRUE( NULL != newScene ); - float newOpacity; - if ( newScene->mNumMaterials > 0 ) { - std::cout << "Desc = " << desc->description << "\n"; - EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) ); - EXPECT_EQ( opacity, newOpacity ); - } - } + std::string path = "dae"; + const aiExportFormatDesc *desc( exporter.GetExportFormatDescription( 0 ) ); + EXPECT_NE( desc, nullptr ); + path.append( desc->fileExtension ); + EXPECT_EQ( AI_SUCCESS, exporter.Export( scene, desc->id, path ) ); + const aiScene *newScene( importer.ReadFile( path, 0 ) ); + EXPECT_TRUE( NULL != newScene ); + float newOpacity; + if ( newScene->mNumMaterials > 0 ) { + std::cout << "Desc = " << desc->description << "\n"; + EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) ); + EXPECT_EQ( opacity, newOpacity ); } }