assimp/test/unit/utColladaExportLight.cpp

101 lines
2.9 KiB
C++
Raw Normal View History

2015-05-19 19:57:51 +00:00
/*
* ColladaCameraExporter.cpp
*
* Created on: May 17, 2015
* Author: wise
*/
#include "UnitTestPCH.h"
#include <assimp/cexport.h>
#include <assimp/Exporter.hpp>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#ifndef ASSIMP_BUILD_NO_EXPORT
class ColladaExportLight : public ::testing::Test {
public:
2015-05-19 04:26:05 +00:00
virtual void SetUp()
{
ex = new Assimp::Exporter();
im = new Assimp::Importer();
2015-05-19 19:57:51 +00:00
2015-05-19 04:26:05 +00:00
}
2015-05-19 19:57:51 +00:00
2015-05-19 04:26:05 +00:00
virtual void TearDown()
{
delete ex;
delete im;
}
2015-05-19 19:57:51 +00:00
protected:
2015-05-19 04:26:05 +00:00
Assimp::Exporter* ex;
Assimp::Importer* im;
2015-05-19 19:57:51 +00:00
};
// ------------------------------------------------------------------------------------------------
TEST_F(ColladaExportLight, testExportLight)
{
2015-05-19 04:26:05 +00:00
const char* file = "cameraExp.dae";
2015-05-19 19:57:51 +00:00
const aiScene* pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/lights.dae",0);
2015-05-19 04:26:05 +00:00
ASSERT_TRUE(pTest!=NULL);
ASSERT_TRUE(pTest->HasLights());
2015-05-19 19:57:51 +00:00
const unsigned int origNumLights( pTest->mNumLights );
aiLight *origLights = new aiLight[ origNumLights ];
std::vector<std::string> origNames;
for (size_t i = 0; i < origNumLights; i++) {
origNames.push_back( pTest->mLights[ i ]->mName.C_Str() );
origLights[ i ] = *(pTest->mLights[ i ]);
}
2015-05-19 19:57:51 +00:00
2015-05-19 04:26:05 +00:00
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada","lightsExp.dae"));
2015-05-19 19:57:51 +00:00
2015-05-19 04:26:05 +00:00
const aiScene* imported = im->ReadFile(file,0);
2015-05-19 19:57:51 +00:00
2015-05-19 04:26:05 +00:00
ASSERT_TRUE(imported!=NULL);
2015-05-19 19:57:51 +00:00
2015-05-19 04:26:05 +00:00
EXPECT_TRUE(imported->HasLights());
EXPECT_EQ( origNumLights,imported->mNumLights );
for(size_t i=0; i< origNumLights; i++){
2015-05-23 09:03:56 +00:00
const aiLight *orig = &origLights[ i ];
2015-05-19 04:26:05 +00:00
const aiLight *read = imported->mLights[i];
2015-05-19 19:57:51 +00:00
EXPECT_EQ(0,strncmp(origNames[ i ].c_str(),read->mName.C_Str(), origNames[ i ].size() ) );
2015-05-19 04:26:05 +00:00
EXPECT_EQ(orig->mType,read->mType);
EXPECT_FLOAT_EQ(orig->mAttenuationConstant,read->mAttenuationConstant);
EXPECT_FLOAT_EQ(orig->mAttenuationLinear,read->mAttenuationLinear);
EXPECT_NEAR(orig->mAttenuationQuadratic,read->mAttenuationQuadratic, 0.001f);
2015-05-23 09:03:56 +00:00
2015-05-19 04:26:05 +00:00
EXPECT_FLOAT_EQ(orig->mColorAmbient.r,read->mColorAmbient.r);
EXPECT_FLOAT_EQ(orig->mColorAmbient.g,read->mColorAmbient.g);
EXPECT_FLOAT_EQ(orig->mColorAmbient.b,read->mColorAmbient.b);
2015-05-23 09:03:56 +00:00
2015-05-19 04:26:05 +00:00
EXPECT_FLOAT_EQ(orig->mColorDiffuse.r,read->mColorDiffuse.r);
EXPECT_FLOAT_EQ(orig->mColorDiffuse.g,read->mColorDiffuse.g);
EXPECT_FLOAT_EQ(orig->mColorDiffuse.b,read->mColorDiffuse.b);
2015-05-23 09:03:56 +00:00
2015-05-19 04:26:05 +00:00
EXPECT_FLOAT_EQ(orig->mColorSpecular.r,read->mColorSpecular.r);
EXPECT_FLOAT_EQ(orig->mColorSpecular.g,read->mColorSpecular.g);
EXPECT_FLOAT_EQ(orig->mColorSpecular.b,read->mColorSpecular.b);
2015-05-19 19:57:51 +00:00
2015-05-19 04:26:05 +00:00
EXPECT_NEAR(orig->mAngleInnerCone,read->mAngleInnerCone,0.001);
EXPECT_NEAR(orig->mAngleOuterCone,read->mAngleOuterCone,0.001);
}
delete [] origLights;
2015-05-19 19:57:51 +00:00
}
#endif