Fix resource leaks in unit tests.

pull/933/head
Kim Kulling 2016-07-04 22:15:23 +02:00
parent ebb209a0d6
commit 7c63208515
8 changed files with 28 additions and 71 deletions

View File

@ -7,31 +7,9 @@
// We need to be sure to have the same STL settings as Assimp
#include <assimp/cimport.h>
#include <gtest/gtest.h>
#include <memory>
#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 max

View File

@ -79,21 +79,20 @@ TEST_F(ColladaExportCamera, testExportCamera)
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));
const unsigned int origNumCams( pTest->mNumCameras );
//float *origFOV = new float[ origNumCams ];
TDataArray<float> origFOV( origNumCams );
TDataArray<float> orifClipPlaneNear( origNumCams );
TDataArray<float> orifClipPlaneFar( origNumCams );
TDataArray<aiString> names( origNumCams );
TDataArray<aiVector3D> pos( origNumCams );
std::unique_ptr<float[]> origFOV( new float[ origNumCams ] );
std::unique_ptr<float[]> orifClipPlaneNear( new float[ origNumCams ] );
std::unique_ptr<float[]> orifClipPlaneFar( new float[ origNumCams ] );
std::unique_ptr<aiString[]> names( new aiString[ origNumCams ] );
std::unique_ptr<aiVector3D[]> pos( new aiVector3D[ origNumCams ] );
for (size_t i = 0; i < origNumCams; i++) {
const aiCamera *orig = pTest->mCameras[ i ];
ASSERT_TRUE( orig != nullptr );
origFOV.m_items[ i ] = orig->mHorizontalFOV;
orifClipPlaneNear.m_items[ i ] = orig->mClipPlaneNear;
orifClipPlaneFar.m_items[ i ] = orig->mClipPlaneFar;
names.m_items[ i ] = orig->mName;
pos.m_items[ i ] = orig->mPosition;
origFOV[ i ] = orig->mHorizontalFOV;
orifClipPlaneNear[ i ] = orig->mClipPlaneNear;
orifClipPlaneFar[ i ] = orig->mClipPlaneFar;
names[ i ] = orig->mName;
pos[ i ] = orig->mPosition;
}
const aiScene* imported = im->ReadFile(file,0);

View File

@ -49,7 +49,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class ColladaExportLight : public ::testing::Test {
public:
virtual void SetUp()
{
ex = new Assimp::Exporter();
@ -63,8 +62,6 @@ public:
}
protected:
Assimp::Exporter* ex;
Assimp::Importer* im;
};
@ -79,7 +76,7 @@ TEST_F(ColladaExportLight, testExportLight)
ASSERT_TRUE(pTest->HasLights());
const unsigned int origNumLights( pTest->mNumLights );
aiLight *origLights = new aiLight[ origNumLights ];
std::unique_ptr<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() );
@ -95,11 +92,8 @@ TEST_F(ColladaExportLight, testExportLight)
EXPECT_TRUE(imported->HasLights());
EXPECT_EQ( origNumLights,imported->mNumLights );
for(size_t i=0; i< origNumLights; i++) {
const aiLight *orig = &origLights[ i ];
const aiLight *read = imported->mLights[i];
EXPECT_EQ( 0,strncmp(origNames[ i ].c_str(),read->mName.C_Str(), origNames[ i ].size() ) );
EXPECT_EQ( orig->mType,read->mType);
EXPECT_FLOAT_EQ(orig->mAttenuationConstant,read->mAttenuationConstant);
@ -121,12 +115,6 @@ TEST_F(ColladaExportLight, testExportLight)
EXPECT_NEAR(orig->mAngleInnerCone,read->mAngleInnerCone,0.001);
EXPECT_NEAR(orig->mAngleOuterCone,read->mAngleOuterCone,0.001);
}
delete [] origLights;
}
#endif
#endif // ASSIMP_BUILD_NO_EXPORT

View File

@ -46,15 +46,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace std;
using namespace Assimp;
class FindDegeneratesProcessTest : public ::testing::Test
{
class FindDegeneratesProcessTest : public ::testing::Test {
public:
virtual void SetUp();
virtual void TearDown();
protected:
aiMesh* mesh;
FindDegeneratesProcess* process;
};

View File

@ -50,12 +50,10 @@ using namespace Assimp;
class FindInvalidDataProcessTest : public ::testing::Test
{
public:
virtual void SetUp();
virtual void TearDown();
protected:
aiMesh* pcMesh;
FindInvalidDataProcess* piProcess;
};

View File

@ -41,14 +41,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "UnitTestPCH.h"
#include <GenVertexNormalsProcess.h>
using namespace std;
using namespace Assimp;
using namespace ::std;
using namespace ::Assimp;
class GenNormalsTest : public ::testing::Test
{
public:
virtual void SetUp();
virtual void TearDown();

View File

@ -46,15 +46,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <BaseImporter.h>
using namespace std;
using namespace Assimp;
using namespace ::std;
using namespace ::Assimp;
class ImporterTest : public ::testing::Test
{
public:
virtual void SetUp() {
pImp = new Importer();
}
virtual void SetUp() { pImp = new Importer(); }
virtual void TearDown() { delete pImp; }
virtual void TearDown() {
delete pImp;
}
protected:
Importer* pImp;
@ -109,7 +113,6 @@ static unsigned char InputData_abRawBlock[1310] = {
#define AIUT_DEF_ERROR_TEXT "sorry, this is a test"
static const aiImporterDesc desc = {
"UNIT TEST - IMPORTER",
"",
@ -123,11 +126,9 @@ static const aiImporterDesc desc = {
"apple mac linux windows"
};
class TestPlugin : public BaseImporter
{
public:
virtual bool CanRead(
const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*test*/) const
{

View File

@ -50,12 +50,10 @@ using namespace Assimp;
class JoinVerticesTest : public ::testing::Test
{
public:
virtual void SetUp();
virtual void TearDown();
protected:
JoinVerticesProcess* piProcess;
aiMesh* pcMesh;
};