summaryrefslogtreecommitdiff
path: root/libs/assimp/test/unit/utExport.cpp
blob: b3ab5e37215686fb6af77bbfac3ca76af958b0af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "UnitTestPCH.h"

#include <assimp/cexport.h>
#include <assimp/Exporter.hpp>


#ifndef ASSIMP_BUILD_NO_EXPORT

class ExporterTest : public ::testing::Test {
public:

    virtual void SetUp()
    {
        ex = new Assimp::Exporter();
        im = new Assimp::Importer();

        pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/X/test.x", aiProcess_ValidateDataStructure);
    }

    virtual void TearDown()
    {
        delete ex;
        delete im;
    }

protected:

    const aiScene* pTest;
    Assimp::Exporter* ex;
    Assimp::Importer* im;
};

// ------------------------------------------------------------------------------------------------
TEST_F(ExporterTest, testExportToFile)
{
    const char* file = "unittest_output.dae";
    EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));

    // check if we can read it again
    EXPECT_TRUE(im->ReadFile(file, aiProcess_ValidateDataStructure));
}

// ------------------------------------------------------------------------------------------------
TEST_F(ExporterTest, testExportToBlob)
{
    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);

    // XXX test chained blobs (i.e. obj file with accompanying mtl script)

    // check if we can read it again
    EXPECT_TRUE(im->ReadFileFromMemory(blob->data,blob->size,0,"dae"));
}

// ------------------------------------------------------------------------------------------------
TEST_F(ExporterTest, testCppExportInterface)
{
    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());
}

// ------------------------------------------------------------------------------------------------
TEST_F(ExporterTest, testCExportInterface)
{
    EXPECT_TRUE(aiGetExportFormatCount() > 0);
    for(size_t i = 0; i < aiGetExportFormatCount(); ++i) {
        const aiExportFormatDesc* const desc = aiGetExportFormatDescription(i);
        EXPECT_TRUE(desc);
        // rest has already been validated by testCppExportInterface
    }
}

#endif