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, 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 );

}
示例#4
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;
}