assimp/test/unit/utExport.cpp

85 lines
2.4 KiB
C++
Raw Permalink Normal View History

2015-05-19 04:24:07 +00:00
#include "UnitTestPCH.h"
#include <assimp/cexport.h>
#include <assimp/Exporter.hpp>
#ifndef ASSIMP_BUILD_NO_EXPORT
class ExporterTest : 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 04:24:07 +00:00
pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/X/test.x", aiProcess_ValidateDataStructure);
2015-05-19 04:26:05 +00:00
}
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
virtual void TearDown()
{
delete ex;
delete im;
}
2015-05-19 04:24:07 +00:00
protected:
2015-05-19 04:26:05 +00:00
const aiScene* pTest;
Assimp::Exporter* ex;
Assimp::Importer* im;
2015-05-19 04:24:07 +00:00
};
// ------------------------------------------------------------------------------------------------
TEST_F(ExporterTest, testExportToFile)
{
2015-05-19 04:26:05 +00:00
const char* file = "unittest_output.dae";
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
// check if we can read it again
EXPECT_TRUE(im->ReadFile(file, aiProcess_ValidateDataStructure));
2015-05-19 04:24:07 +00:00
}
// ------------------------------------------------------------------------------------------------
TEST_F(ExporterTest, testExportToBlob)
{
2015-05-19 04:26:05 +00:00
const aiExportDataBlob* blob = ex->ExportToBlob(pTest,"collada");
ASSERT_TRUE(blob);
EXPECT_TRUE(blob->data);
EXPECT_GT(blob->size, 0U);
EXPECT_EQ(0U, blob->name.length);
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
// XXX test chained blobs (i.e. obj file with accompanying mtl script)
2015-05-19 04:24:07 +00:00
2015-05-19 04:26:05 +00:00
// check if we can read it again
EXPECT_TRUE(im->ReadFileFromMemory(blob->data,blob->size,0,"dae"));
2015-05-19 04:24:07 +00:00
}
// ------------------------------------------------------------------------------------------------
TEST_F(ExporterTest, testCppExportInterface)
{
2015-05-19 04:26:05 +00:00
EXPECT_TRUE(ex->GetExportFormatCount() > 0);
for(size_t i = 0; i < ex->GetExportFormatCount(); ++i) {
const aiExportFormatDesc* const desc = ex->GetExportFormatDescription(i);
ASSERT_TRUE(desc);
EXPECT_TRUE(desc->description && strlen(desc->description));
EXPECT_TRUE(desc->fileExtension && strlen(desc->fileExtension));
EXPECT_TRUE(desc->id && strlen(desc->id));
}
EXPECT_TRUE(ex->IsDefaultIOHandler());
2015-05-19 04:24:07 +00:00
}
// ------------------------------------------------------------------------------------------------
TEST_F(ExporterTest, testCExportInterface)
{
2015-05-19 04:26:05 +00:00
EXPECT_TRUE(aiGetExportFormatCount() > 0);
for(size_t i = 0; i < aiGetExportFormatCount(); ++i) {
const aiExportFormatDesc* const desc = aiGetExportFormatDescription(i);
EXPECT_TRUE(desc);
2017-04-11 20:33:13 +00:00
// rest has already been validated by testCppExportInterface
2015-05-19 04:26:05 +00:00
}
2015-05-19 04:24:07 +00:00
}
#endif