Fix resource leaks in unit tests.
parent
ebb209a0d6
commit
7c63208515
|
@ -7,31 +7,9 @@
|
||||||
// We need to be sure to have the same STL settings as Assimp
|
// We need to be sure to have the same STL settings as Assimp
|
||||||
|
|
||||||
#include <assimp/cimport.h>
|
#include <assimp/cimport.h>
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <memory>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct TDataArray {
|
|
||||||
size_t m_numItems;
|
|
||||||
T *m_items;
|
|
||||||
|
|
||||||
TDataArray( size_t numItems )
|
|
||||||
: m_numItems( numItems )
|
|
||||||
, m_items( nullptr ) {
|
|
||||||
m_items = new T[ numItems ];
|
|
||||||
}
|
|
||||||
|
|
||||||
~TDataArray() {
|
|
||||||
delete [] m_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
T operator [] ( size_t index ) const {
|
|
||||||
EXPECT_TRUE( index < m_numItems );
|
|
||||||
return m_items[ index ];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#undef min
|
#undef min
|
||||||
#undef max
|
#undef max
|
||||||
|
|
|
@ -79,21 +79,20 @@ TEST_F(ColladaExportCamera, testExportCamera)
|
||||||
|
|
||||||
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));
|
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));
|
||||||
const unsigned int origNumCams( pTest->mNumCameras );
|
const unsigned int origNumCams( pTest->mNumCameras );
|
||||||
//float *origFOV = new float[ origNumCams ];
|
std::unique_ptr<float[]> origFOV( new float[ origNumCams ] );
|
||||||
TDataArray<float> origFOV( origNumCams );
|
std::unique_ptr<float[]> orifClipPlaneNear( new float[ origNumCams ] );
|
||||||
TDataArray<float> orifClipPlaneNear( origNumCams );
|
std::unique_ptr<float[]> orifClipPlaneFar( new float[ origNumCams ] );
|
||||||
TDataArray<float> orifClipPlaneFar( origNumCams );
|
std::unique_ptr<aiString[]> names( new aiString[ origNumCams ] );
|
||||||
TDataArray<aiString> names( origNumCams );
|
std::unique_ptr<aiVector3D[]> pos( new aiVector3D[ origNumCams ] );
|
||||||
TDataArray<aiVector3D> pos( origNumCams );
|
|
||||||
for (size_t i = 0; i < origNumCams; i++) {
|
for (size_t i = 0; i < origNumCams; i++) {
|
||||||
const aiCamera *orig = pTest->mCameras[ i ];
|
const aiCamera *orig = pTest->mCameras[ i ];
|
||||||
ASSERT_TRUE( orig != nullptr );
|
ASSERT_TRUE( orig != nullptr );
|
||||||
|
|
||||||
origFOV.m_items[ i ] = orig->mHorizontalFOV;
|
origFOV[ i ] = orig->mHorizontalFOV;
|
||||||
orifClipPlaneNear.m_items[ i ] = orig->mClipPlaneNear;
|
orifClipPlaneNear[ i ] = orig->mClipPlaneNear;
|
||||||
orifClipPlaneFar.m_items[ i ] = orig->mClipPlaneFar;
|
orifClipPlaneFar[ i ] = orig->mClipPlaneFar;
|
||||||
names.m_items[ i ] = orig->mName;
|
names[ i ] = orig->mName;
|
||||||
pos.m_items[ i ] = orig->mPosition;
|
pos[ i ] = orig->mPosition;
|
||||||
}
|
}
|
||||||
const aiScene* imported = im->ReadFile(file,0);
|
const aiScene* imported = im->ReadFile(file,0);
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
class ColladaExportLight : public ::testing::Test {
|
class ColladaExportLight : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void SetUp()
|
virtual void SetUp()
|
||||||
{
|
{
|
||||||
ex = new Assimp::Exporter();
|
ex = new Assimp::Exporter();
|
||||||
|
@ -63,8 +62,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
Assimp::Exporter* ex;
|
Assimp::Exporter* ex;
|
||||||
Assimp::Importer* im;
|
Assimp::Importer* im;
|
||||||
};
|
};
|
||||||
|
@ -79,7 +76,7 @@ TEST_F(ColladaExportLight, testExportLight)
|
||||||
ASSERT_TRUE(pTest->HasLights());
|
ASSERT_TRUE(pTest->HasLights());
|
||||||
|
|
||||||
const unsigned int origNumLights( pTest->mNumLights );
|
const unsigned int origNumLights( pTest->mNumLights );
|
||||||
aiLight *origLights = new aiLight[ origNumLights ];
|
std::unique_ptr<aiLight[]> origLights( new aiLight[ origNumLights ] );
|
||||||
std::vector<std::string> origNames;
|
std::vector<std::string> origNames;
|
||||||
for (size_t i = 0; i < origNumLights; i++) {
|
for (size_t i = 0; i < origNumLights; i++) {
|
||||||
origNames.push_back( pTest->mLights[ i ]->mName.C_Str() );
|
origNames.push_back( pTest->mLights[ i ]->mName.C_Str() );
|
||||||
|
@ -94,14 +91,11 @@ TEST_F(ColladaExportLight, testExportLight)
|
||||||
|
|
||||||
EXPECT_TRUE(imported->HasLights());
|
EXPECT_TRUE(imported->HasLights());
|
||||||
EXPECT_EQ( origNumLights,imported->mNumLights );
|
EXPECT_EQ( origNumLights,imported->mNumLights );
|
||||||
for(size_t i=0; i< origNumLights; i++){
|
for(size_t i=0; i< origNumLights; i++) {
|
||||||
|
|
||||||
const aiLight *orig = &origLights[ i ];
|
const aiLight *orig = &origLights[ i ];
|
||||||
|
|
||||||
const aiLight *read = imported->mLights[i];
|
const aiLight *read = imported->mLights[i];
|
||||||
|
EXPECT_EQ( 0,strncmp(origNames[ i ].c_str(),read->mName.C_Str(), origNames[ i ].size() ) );
|
||||||
EXPECT_EQ(0,strncmp(origNames[ i ].c_str(),read->mName.C_Str(), origNames[ i ].size() ) );
|
EXPECT_EQ( orig->mType,read->mType);
|
||||||
EXPECT_EQ(orig->mType,read->mType);
|
|
||||||
EXPECT_FLOAT_EQ(orig->mAttenuationConstant,read->mAttenuationConstant);
|
EXPECT_FLOAT_EQ(orig->mAttenuationConstant,read->mAttenuationConstant);
|
||||||
EXPECT_FLOAT_EQ(orig->mAttenuationLinear,read->mAttenuationLinear);
|
EXPECT_FLOAT_EQ(orig->mAttenuationLinear,read->mAttenuationLinear);
|
||||||
EXPECT_NEAR(orig->mAttenuationQuadratic,read->mAttenuationQuadratic, 0.001f);
|
EXPECT_NEAR(orig->mAttenuationQuadratic,read->mAttenuationQuadratic, 0.001f);
|
||||||
|
@ -121,12 +115,6 @@ TEST_F(ColladaExportLight, testExportLight)
|
||||||
EXPECT_NEAR(orig->mAngleInnerCone,read->mAngleInnerCone,0.001);
|
EXPECT_NEAR(orig->mAngleInnerCone,read->mAngleInnerCone,0.001);
|
||||||
EXPECT_NEAR(orig->mAngleOuterCone,read->mAngleOuterCone,0.001);
|
EXPECT_NEAR(orig->mAngleOuterCone,read->mAngleOuterCone,0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] origLights;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // ASSIMP_BUILD_NO_EXPORT
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,15 +46,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
class FindDegeneratesProcessTest : public ::testing::Test
|
class FindDegeneratesProcessTest : public ::testing::Test {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void SetUp();
|
virtual void SetUp();
|
||||||
virtual void TearDown();
|
virtual void TearDown();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
aiMesh* mesh;
|
aiMesh* mesh;
|
||||||
FindDegeneratesProcess* process;
|
FindDegeneratesProcess* process;
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,12 +50,10 @@ using namespace Assimp;
|
||||||
class FindInvalidDataProcessTest : public ::testing::Test
|
class FindInvalidDataProcessTest : public ::testing::Test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void SetUp();
|
virtual void SetUp();
|
||||||
virtual void TearDown();
|
virtual void TearDown();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
aiMesh* pcMesh;
|
aiMesh* pcMesh;
|
||||||
FindInvalidDataProcess* piProcess;
|
FindInvalidDataProcess* piProcess;
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,14 +41,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "UnitTestPCH.h"
|
#include "UnitTestPCH.h"
|
||||||
#include <GenVertexNormalsProcess.h>
|
#include <GenVertexNormalsProcess.h>
|
||||||
|
|
||||||
|
using namespace ::std;
|
||||||
using namespace std;
|
using namespace ::Assimp;
|
||||||
using namespace Assimp;
|
|
||||||
|
|
||||||
class GenNormalsTest : public ::testing::Test
|
class GenNormalsTest : public ::testing::Test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void SetUp();
|
virtual void SetUp();
|
||||||
virtual void TearDown();
|
virtual void TearDown();
|
||||||
|
|
||||||
|
|
|
@ -46,15 +46,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <BaseImporter.h>
|
#include <BaseImporter.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace ::std;
|
||||||
using namespace Assimp;
|
using namespace ::Assimp;
|
||||||
|
|
||||||
class ImporterTest : public ::testing::Test
|
class ImporterTest : public ::testing::Test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual void SetUp() {
|
||||||
virtual void SetUp() { pImp = new Importer(); }
|
pImp = new Importer();
|
||||||
virtual void TearDown() { delete pImp; }
|
}
|
||||||
|
|
||||||
|
virtual void TearDown() {
|
||||||
|
delete pImp;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Importer* pImp;
|
Importer* pImp;
|
||||||
|
@ -109,7 +113,6 @@ static unsigned char InputData_abRawBlock[1310] = {
|
||||||
|
|
||||||
#define AIUT_DEF_ERROR_TEXT "sorry, this is a test"
|
#define AIUT_DEF_ERROR_TEXT "sorry, this is a test"
|
||||||
|
|
||||||
|
|
||||||
static const aiImporterDesc desc = {
|
static const aiImporterDesc desc = {
|
||||||
"UNIT TEST - IMPORTER",
|
"UNIT TEST - IMPORTER",
|
||||||
"",
|
"",
|
||||||
|
@ -123,11 +126,9 @@ static const aiImporterDesc desc = {
|
||||||
"apple mac linux windows"
|
"apple mac linux windows"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class TestPlugin : public BaseImporter
|
class TestPlugin : public BaseImporter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual bool CanRead(
|
virtual bool CanRead(
|
||||||
const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*test*/) const
|
const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*test*/) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,12 +50,10 @@ using namespace Assimp;
|
||||||
class JoinVerticesTest : public ::testing::Test
|
class JoinVerticesTest : public ::testing::Test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void SetUp();
|
virtual void SetUp();
|
||||||
virtual void TearDown();
|
virtual void TearDown();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
JoinVerticesProcess* piProcess;
|
JoinVerticesProcess* piProcess;
|
||||||
aiMesh* pcMesh;
|
aiMesh* pcMesh;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue