TEST_F( OpenDDLDefectsTest, no_whitespace ) {
    char token [] = {
        "GeometryNode$node2"
        "{"
        "Name{string{\"Plane\"}}"
        "ObjectRef{ref{$geometry1}}"
        "MaterialRef(index=0){ref{$material1}}"
        "Transform"
        "{"
        "float[16]"
        "{"
        "{1.0,0.0,0.0,0.0,"
        "0.0,1.0,0.0,0.0,"
        "0.0,0.0,1.0,0.0,"
        "0.0,0.0,0.0,1.0}"
        "}"
        "}"
        "}"
    };

    OpenDDLParser myParser;
    myParser.setBuffer( token, strlen( token ) );
    const bool ok( myParser.parse() );
    EXPECT_TRUE( ok );
    DDLNode *root = myParser.getRoot();
    DDLNode::DllNodeList childs = root->getChildNodeList();
    EXPECT_STREQ( "node2", childs[0]->getName().c_str());
    EXPECT_STREQ( "GeometryNode", childs[0]->getType().c_str());
}
TEST_F( OpenDDLDefectsTest, assimp_issues_665 ) {
    char token [] = {
        "GeometryNode $node2\n"
        "{\n"
        "    Name{ string{ \"Plane\" } }\n"
        "    ObjectRef{ ref{ $geometry1 } }\n"
        "    MaterialRef( index = 0 ) { ref{ $material1 } }\n"
        "    Transform\n"
        "    {\n"
        "        float[ 16 ]\n"
        "        {\n"
        "            { 1.0, 0.0, 0.0, 0.0,\n"
        "              0.0, 1.0, 0.0, 0.0,\n"
        "              0.0, 0.0, 1.0, 0.0,\n"
        "              0.0, 0.0, 0.0, 1.0 }\n"
        "        }\n"
        "    }\n"
        "}\n"
    };

    OpenDDLParser myParser;
    myParser.setBuffer( token, strlen( token ) );
    const bool ok( myParser.parse() );
    EXPECT_TRUE( ok );
}
TEST_F( OpenDDLDefectsTest, invalid_handling_of_embedded_comments ) {
    char token[] = {
        "GeometryObject /*mesh*/ $geometry1 {\n"
        "    Mesh (primitive = \"triangle_strip\") {\n"
        "        VertexArray (attrib = \"position\") {\n" 
        "            float[3] {\n"
        "                {0.0, 1.0, 3.0},\n"
        "                {-1.0, 2.0, 2.0},\n" 
        "                {3.0, 3.0, 1.0}\n"
        "            }\n"
        "        }\n"
        "    }\n"
        "}\n"
    };	
    OpenDDLParser myParser;
    myParser.setBuffer( token, strlen( token ) );
    const bool ok( myParser.parse() );
    EXPECT_TRUE( ok );
}
TEST_F( OpenDDLDefectsTest, invalid_normalizing ) {
    char token[] = {
        "Metric( key = \"up\" ) { string{ \"y\" } }\n"
        "\n"
        "GeometryObject /*mesh*/{\n"
        "   Mesh( primitive = \"triangle_strip\" ) {\n"
        "       VertexArray( attrib = \"position\" ) {\n"
        "           float[ 3 ]{\n"
        "               { 0.0, 1.0, 3.0 },{ -1.0, 2.0, 2.0 },{ 3.0, 3.0, 1.0 }\n"
        "           }\n"
        "       }\n"
        "   }\n"
        "}\n"
    };
     
    OpenDDLParser myParser;
    myParser.setBuffer( token, strlen( token ) );
    const bool ok( myParser.parse() );
    EXPECT_TRUE( ok );
}
TEST_F( OpenDDLDefectsTest, parse_hexa_float_issue ) {
    char token[] = {
        "VertexArray( attrib = \"position\" )\n"
        "{\n"
        "   float[ 3 ]		// 24\n"
        "   {\n"
        "        { 0xC2501375, 0xC24C468A, 0x00000000 },{ 0xC2501375, 0x424C468A, 0x00000000 },{ 0x42501375, 0x424C468A, 0x00000000 },{ 0x42501375, 0xC24C468A, 0x00000000 },{ 0xC2501375, 0xC24C468A, 0x42BA3928 },{ 0x42501375, 0xC24C468A, 0x42BA3928 },{ 0x42501375, 0x424C468A, 0x42BA3928 },{ 0xC2501375, 0x424C468A, 0x42BA3928 },\n"
        "        { 0xC2501375, 0xC24C468A, 0x00000000 },{ 0x42501375, 0xC24C468A, 0x00000000 },{ 0x42501375, 0xC24C468A, 0x42BA3928 },{ 0xC2501375, 0xC24C468A, 0x42BA3928 },{ 0x42501375, 0xC24C468A, 0x00000000 },{ 0x42501375, 0x424C468A, 0x00000000 },{ 0x42501375, 0x424C468A, 0x42BA3928 },{ 0x42501375, 0xC24C468A, 0x42BA3928 },\n"
        "        { 0x42501375, 0x424C468A, 0x00000000 },{ 0xC2501375, 0x424C468A, 0x00000000 },{ 0xC2501375, 0x424C468A, 0x42BA3928 },{ 0x42501375, 0x424C468A, 0x42BA3928 },{ 0xC2501375, 0x424C468A, 0x00000000 },{ 0xC2501375, 0xC24C468A, 0x00000000 },{ 0xC2501375, 0xC24C468A, 0x42BA3928 },{ 0xC2501375, 0x424C468A, 0x42BA3928 }\n"
        "   }\n"
        "}\n"
    };
    OpenDDLParser myParser;
    myParser.setBuffer( token, strlen( token ) );
    const bool ok( myParser.parse() );
    EXPECT_TRUE( ok );
    DDLNode *root = myParser.getRoot();
    EXPECT_TRUE( ddl_nullptr != root );
    DDLNode::DllNodeList childs = root->getChildNodeList();
    EXPECT_EQ( 1U, childs.size() );
}
TEST_F( OpenDDLDefectsTest, parse_light_object_issue38 ) {
    char token[] = {
        "LightObject $light1( type = \"point\" ) // Lamp\n"
        "{\n"
        "    Color( attrib = \"light\" ) { float[ 3 ]{ { 1.0, 1.0, 1.0 } } }\n"
        "\n"
        "    Atten( curve = \"inverse_square\" )\n"
        "    {\n"
        "        Param( attrib = \"scale\" ) { float{ 5.47722400800463 } }\n"
        "    }\n"
        "}\n"
    };
    
    OpenDDLParser myParser;
    myParser.setBuffer( token, strlen( token ) );
    const bool ok( myParser.parse() );
    EXPECT_TRUE( ok );
    DDLNode *root = myParser.getRoot();
    EXPECT_TRUE( ddl_nullptr != root );

}
TEST_F( OpenDDLDefectsTest, strings_with_the_comment_syntax_in_them_breaks_the_parser ) {
    char token[] = {
        "Material $material1\n"
        "{\n"
        "    Name { string { \"defaultMat\" } }\n"
        "\n"
        "    Color( attrib = \"diffuse\" ) { float[ 3 ] {{0.6400000190734865, 0.6400000190734865, 0.6400000190734865}} }\n"
        "    Color( attrib = \"specular\" ) { float[ 3 ] {{0.5, 0.5, 0.5}} }\n"
        "    Param( attrib = \"specular_power\" ) { float { 50 } }\n"
        "\n"
        "    Texture( attrib = \"diffuse\" )\n"
        "    {\n"
        "        string { \"//f/kittylow.bmp\" }\n"
        "    }\n"
        "}\n"
    };

    OpenDDLParser myParser;
    myParser.setBuffer( token, strlen( token ) );
    const bool ok( myParser.parse() );
    EXPECT_TRUE( ok );

}
Пример #8
0
int main( int argc, char *argv[] ) {
    if( argc < 3 ) {
        showhelp();
        return Error;
    }

    char *filename( ddl_nullptr ), *exportFilename( ddl_nullptr );
    bool dump( false ), exportToFile( false );
    for ( int i = 1; i < argc; i++) {
        if (0 == strncmp(FileOption, argv[i], strlen(FileOption))) {
            if ((i + 1) >= argc) {
                std::cerr << "No filename specified" << std::endl;
                return Error;
            }

            filename = argv[ i+1 ];
        }

        if (0 == strncmp(DumpOption, argv[ i ], strlen( DumpOption) ) ) {
            dump = true;
        }

        if( 0==strncmp(ExportOption, argv[i], strlen(ExportOption ) ) ) {
            if ((i + 1) >= argc) {
                std::cerr << "No filename for export specified" << std::endl;
                return Error;
            } else {
                exportToFile = true;
                exportFilename = argv[i+1];
            }
        }
    }

    std::cout << "file to import: " << filename << std::endl;

    if(ddl_nullptr == filename ) {
        std::cerr << "Invalid filename." << std::endl;
        return Error;
    }

    FILE *fileStream = fopen( filename, "rb+" );
    if(ddl_nullptr == fileStream ) {
        std::cerr << "Cannot open file " << filename << std::endl;
        return Error;
    }

    // obtain file size:
    fseek( fileStream, 0, SEEK_END );
    const size_t size( ftell( fileStream ) );

    ::rewind( fileStream );

    if( size > 0 ) {
        char *buffer = new char[ size ];
        const size_t readSize( fread( buffer, sizeof( char ), size, fileStream ) );
        assert( readSize == size );
        OpenDDLParser theParser;
        theParser.setBuffer( buffer, size );
        const bool result( theParser.parse() );
        if( !result ) {
            std::cerr << "Error while parsing file " << filename << "." << std::endl;
        } else {
            DDLNode *root = theParser.getRoot();
            if ( dump ) {
                dumpDDLNodeTree(root);
            }
            if ( exportToFile ) {
                OpenDDLExport theExporter;
                theExporter.exportContext( theParser.getContext(), exportFilename );
            }
        }
    }

    return 0;
}
TEST_F( OpenDDLDefectsTest, invalid_handling_of_unsigned_int_16 ) {
    char token[] = {
        "Metric( key = \"up\" ) { string{ \"y\" } }\n"
        "\n"
        "GeometryObject /*mesh*/{\n"
        "   Mesh( primitive = \"triangle_strip\" ) {\n"
        "       VertexArray( attrib = \"position\" ) {\n"
        "           float[ 3 ]{\n"
        "               { 0.0, 1.0, 3.0 },{ -1.0, 2.0, 2.0 },{ 3.0, 3.0, 1.0 }\n"
        "           }\n"
        "       }\n"
        "       VertexArray( attrib = \"normal\" ) {\n"
        "           float[ 3 ]{\n"
        "               { 0.0, 1.0, 0.0 },{ -1.0, 0.0, 0.0 },{ 0.0, 0.0, 1.0 }\n"
        "           }\n"
        "       }\n"
        "       VertexArray( attrib = \"texcoord\" ) {\n"
        "           float[ 2 ]{\n"
        "               { 0.5, 0.5 },{ 0.5, 1.0 },{ 1.0, 1.0 }\n"
        "           }\n"
        "       }\n"
        "       VertexArray( attrib = \"texcoord\" ) {\n"
        "           float[ 2 ]{\n"
        "               { 0.5, 1.0 },{ 1.0, 0.5 },{ 0.5, 0.5 }\n"
        "           }\n"
        "       }\n"
        "       VertexArray( attrib = \"color\" ) { float{} }\n"
        "   }\n"
        "}\n"
        "\n"
        "GeometryObject /*meshIndexed*/{\n"
        "   Mesh( primitive = \"triangles\" ) {\n"
        "       VertexArray( attrib = \"position\" ) {\n"
        "           float[ 3 ]{\n"
        "               { 0.0, 1.0, 3.0 },{ -1.0, 2.0, 2.0 },{ 3.0, 3.0, 1.0 },{ 5.0, 7.0, 0.5 }\n"
        "           }\n"
        "       }\n"
        "\n"
        "   IndexArray{ unsigned_int16[ 3 ]{\n"
        "       { 2, 0, 1 },{ 1, 2, 3 }\n"
        "   }\n" 
        "}\n"
        "}\n"
        "}\n"
        "\n"
        "GeometryObject /*meshEnlargeShrink*/{\n"
        "Mesh{\n"
        "VertexArray( attrib = \"position\" ) {\n"
        "float[ 4 ]{\n"
        "    { 0.0, 1.0, 3.0, 0.5 },{ -1.0, 2.0, 2.0, 1.0 },{ 3.0, 3.0, 1.0, 1.0 }\n"
        "}\n"
        "}\n"
        "VertexArray( attrib = \"normal\" ) {\n"
        "float[ 2 ]{\n"
        "    { 0.0, 1.0 },{ -1.0, 0.0 },{ 1.0, 0.0 }\n"
        "}\n"
        "}\n"
        "VertexArray( attrib = \"texcoord\" ) {\n"
        "    float[ 1 ]{\n"
        "        { 0.5 },{ 0.0 },{ 1.0 }\n"
        "    }\n"
        "}\n"
        "}\n"
        "}\n" 
    };
    OpenDDLParser myParser;
    myParser.setBuffer( token, strlen( token ) );
    const bool ok( myParser.parse() );
    //EXPECT_TRUE( ok );
}