Generate TestModelFactory for uniform test models in unittests.
parent
12ea506504
commit
a46b481985
|
@ -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
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#pragma once
|
||||
|
||||
#include "UnitTestPCH.h"
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/material.h>
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -44,6 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
|
||||
#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<unsigned int>( ::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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue