diff -Naur soprano-2.6.51/backends/redland/redlandqueryresult.cpp soprano/backends/redland/redlandqueryresult.cpp --- soprano-2.6.51/backends/redland/redlandqueryresult.cpp 2011-06-05 10:38:25.000000000 +0200 +++ soprano/backends/redland/redlandqueryresult.cpp 2011-07-19 18:49:58.000000000 +0200 @@ -77,9 +77,10 @@ d->model = model; const char** names = 0; + int number = librdf_query_results_get_bindings_count(d->result); if ( !librdf_query_results_get_bindings( d->result, &names, 0 ) ) { - for ( ; *names; names++ ) { - d->names.append( QString::fromUtf8( *names ) ); + for ( int i = 0; i < number; i++ ) { + d->names.append( QString::fromUtf8( names[i] ) ); } } } diff -Naur soprano-2.6.51/ChangeLog soprano/ChangeLog --- soprano-2.6.51/ChangeLog 2011-06-05 10:38:25.000000000 +0200 +++ soprano/ChangeLog 2011-07-19 18:49:58.000000000 +0200 @@ -2,6 +2,8 @@ * Use the new Virtuoso parameter XAnyNormalization to use normalized accents for full-text searching by default. * Updated NAO Vocabulary namespace to include changes from SDO 0.7. * Added method LiteralValue::fromVariant which provides some useful type conversions. + * Fixed incorrect binding names counting in redland queries + * Ported Raptor serializer and parser plugins to Raptor2. 2.6.1 * Let onto2vocabularyclass convert dots in entity names to underscores to create valid C++ names. diff -Naur soprano-2.6.51/cmake/modules/FindRaptor.cmake soprano/cmake/modules/FindRaptor.cmake --- soprano-2.6.51/cmake/modules/FindRaptor.cmake 2011-06-05 10:38:25.000000000 +0200 +++ soprano/cmake/modules/FindRaptor.cmake 2011-07-19 18:49:58.000000000 +0200 @@ -5,9 +5,13 @@ # RAPTOR_LIBRARIES - Link these to use Raptor # RAPTOR_INCLUDE_DIR - Include directory for using Raptor # RAPTOR_DEFINITIONS - Compiler switches required for using Raptor -# RAPTOR_VERSION - The Raptor version string +# +# Capabilities +# RAPTOR_HAVE_TRIG - Set if raptor has TRIG -# (c) 2007-2009 Sebastian Trueg +# (c) 2007-2011 Sebastian Trueg +# (c) 2011 Artem Serebriyskiy +# (c) 2011 Michael Jansen # # Based on FindFontconfig Copyright (c) 2006,2007 Laurent Montel, # @@ -15,89 +19,83 @@ # For details see the accompanying COPYING-CMAKE-SCRIPTS file. -INCLUDE(MacroEnsureVersion) - +MACRO ( FIND_RAPTOR libname libhints includehints ) + find_library_with_debug( + RAPTOR_LIBRARIES + WIN32_DEBUG_POSTFIX d + NAMES ${libname} + HINTS ${libhints}) + find_path( + RAPTOR_INCLUDE_DIR raptor.h + HINTS ${includehints} + PATH_SUFFIXES ${libname}) +ENDMACRO () + + + +# Check if we have cached results in case the last round was successful. +if ( NOT( RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES ) OR NOT RAPTOR_FOUND ) + + include(FindLibraryWithDebug) + include(MacroEnsureVersion) + find_package(PkgConfig) + + # Vy default look for version 2.0 + if (NOT Raptor_FIND_VERSION ) + set( Raptor_FIND_VERSION "2.0") + set( Raptor_FIND_VERSION_MAJOR "2" ) + set( Raptor_FIND_VERSION_MINOR "0" ) + endif () + + if ( Raptor_FIND_VERSION_MAJOR EQUAL "2" ) + + if ( NOT WIN32 ) + pkg_check_modules(PC_RAPTOR2 QUIET raptor2) + if ( PC_RAPTOR2_FOUND ) + set(RAPTOR_DEFINITIONS ${PC_RAPTOR2_CFLAGS_OTHER}) + set(RAPTOR_VERSION ${PC_RAPTOR2_VERSION} CACHE STRING "Raptor Version found" ) + endif () + endif () + find_raptor( raptor2 "${PC_RAPTOR2_LIBDIR};${PC_RAPTOR2_LIBRARY_DIRS}" "${PC_RAPTOR2_INCLUDEDIR};${PC_RAPTOR2_INCLUDE_DIRS}") + + elseif ( Raptor_FIND_VERSION_MAJOR EQUAL "1" ) + + if ( NOT WIN32 ) + pkg_check_modules(PC_RAPTOR QUIET raptor) + if ( PC_RAPTOR_FOUND ) + set(RAPTOR_DEFINITIONS ${PC_RAPTOR_CFLAGS_OTHER}) + set(RAPTOR_VERSION ${PC_RAPTOR_VERSION} CACHE STRING "Raptor Version found" ) + endif () + endif () + find_raptor( raptor "${PC_RAPTOR_LIBDIR};${PC_RAPTOR_LIBRARY_DIRS}" "${PC_RAPTOR_INCLUDEDIR};${PC_RAPTOR_INCLUDE_DIRS}") + + else () + + message( FATAL_ERROR "No idea how to check for version : ${Raptor_FIND_VERSION}") + + endif() + + if (RAPTOR_VERSION) + MACRO_ENSURE_VERSION("1.4.16" ${RAPTOR_VERSION} RAPTOR_HAVE_TRIG) + endif (RAPTOR_VERSION) + + mark_as_advanced(RAPTOR_INCLUDE_DIR RAPTOR_LIBRARIES) + +endif () # Check for cached values + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( + Raptor + VERSION_VAR RAPTOR_VERSION + REQUIRED_VARS RAPTOR_LIBRARIES RAPTOR_INCLUDE_DIR) + +mark_as_advanced(RAPTOR_VERSION) + +if (NOT RAPTOR_FOUND AND Raptor_FIND_VERSION_MAJOR EQUAL "2" AND NOT Raptor_FIND_QUIET ) + pkg_check_modules(PC_RAPTOR QUIET raptor) + if (PC_RAPTOR_FOUND) + message( STATUS "You have raptor1 version ${PC_RAPTOR_VERSION} installed. Please update." ) + endif () +endif () -if(WINCE) -FIND_PROGRAM( - RAPTOR_CONFIG - NAMES raptor-config - PATHS ${HOST_BINDIR} NO_DEFAULT_PATH - ) -else(WINCE) -FIND_PROGRAM( - RAPTOR_CONFIG - NAMES raptor-config - ) -endif(WINCE) - -if(RAPTOR_CONFIG) - EXECUTE_PROCESS( - COMMAND ${RAPTOR_CONFIG} --version - OUTPUT_VARIABLE RAPTOR_VERSION - ) - if(RAPTOR_VERSION) - STRING(REPLACE "\n" "" RAPTOR_VERSION ${RAPTOR_VERSION}) - - MACRO_ENSURE_VERSION("1.4.16" ${RAPTOR_VERSION} RAPTOR_HAVE_TRIG) - - # extract include paths from raptor-config - EXECUTE_PROCESS( - COMMAND ${RAPTOR_CONFIG} --cflags - OUTPUT_VARIABLE raptor_CFLAGS_ARGS) - STRING( REPLACE " " ";" raptor_CFLAGS_ARGS ${raptor_CFLAGS_ARGS} ) - FOREACH( _ARG ${raptor_CFLAGS_ARGS} ) - IF(${_ARG} MATCHES "^-I") - STRING(REGEX REPLACE "^-I" "" _ARG ${_ARG}) - STRING( REPLACE "\n" "" _ARG ${_ARG} ) - LIST(APPEND raptor_INCLUDE_DIRS ${_ARG}) - ENDIF(${_ARG} MATCHES "^-I") - ENDFOREACH(_ARG) - - # extract lib paths from raptor-config - EXECUTE_PROCESS( - COMMAND ${RAPTOR_CONFIG} --libs - OUTPUT_VARIABLE raptor_CFLAGS_ARGS) - STRING( REPLACE " " ";" raptor_CFLAGS_ARGS ${raptor_CFLAGS_ARGS} ) - FOREACH( _ARG ${raptor_CFLAGS_ARGS} ) - IF(${_ARG} MATCHES "^-L") - STRING(REGEX REPLACE "^-L" "" _ARG ${_ARG}) - LIST(APPEND raptor_LIBRARY_DIRS ${_ARG}) - ENDIF(${_ARG} MATCHES "^-L") - ENDFOREACH(_ARG) - endif(RAPTOR_VERSION) -else(RAPTOR_CONFIG) - SET(RAPTOR_VERSION "1.0.0") -endif(RAPTOR_CONFIG) - -find_path(RAPTOR_INCLUDE_DIR raptor.h - PATHS - ${redland_INCLUDE_DIRS} - ${raptor_INCLUDE_DIRS} - /usr/X11/include - PATH_SUFFIXES redland - ) - -find_library(RAPTOR_LIBRARIES NAMES raptor libraptor - PATHS - ${raptor_LIBRARY_DIRS} - ) - -if (RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES) - set(RAPTOR_FOUND TRUE) -endif (RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES) - -if (RAPTOR_FOUND) - set(RAPTOR_DEFINITIONS ${raptor_CFLAGS}) - if (NOT Raptor_FIND_QUIETLY) - message(STATUS "Found Raptor ${RAPTOR_VERSION}: libs - ${RAPTOR_LIBRARIES}; includes - ${RAPTOR_INCLUDE_DIR}") - endif (NOT Raptor_FIND_QUIETLY) -else (RAPTOR_FOUND) - if (Raptor_FIND_REQUIRED) - message(FATAL_ERROR "Could NOT find Raptor") - endif (Raptor_FIND_REQUIRED) -endif (RAPTOR_FOUND) - -mark_as_advanced(RAPTOR_INCLUDE_DIR_TMP - RAPTOR_INCLUDE_DIR - RAPTOR_LIBRARIES) diff -Naur soprano-2.6.51/CMakeLists.txt soprano/CMakeLists.txt --- soprano-2.6.51/CMakeLists.txt 2011-06-05 10:38:25.000000000 +0200 +++ soprano/CMakeLists.txt 2011-07-19 18:49:58.000000000 +0200 @@ -7,7 +7,7 @@ ################## Soprano version ################################ set(CMAKE_SOPRANO_VERSION_MAJOR 2) set(CMAKE_SOPRANO_VERSION_MINOR 6) -set(CMAKE_SOPRANO_VERSION_RELEASE 51) +set(CMAKE_SOPRANO_VERSION_RELEASE 52) set(CMAKE_SOPRANO_VERSION_STRING "${CMAKE_SOPRANO_VERSION_MAJOR}.${CMAKE_SOPRANO_VERSION_MINOR}.${CMAKE_SOPRANO_VERSION_RELEASE}") diff -Naur soprano-2.6.51/parsers/raptor/CMakeLists.txt soprano/parsers/raptor/CMakeLists.txt --- soprano-2.6.51/parsers/raptor/CMakeLists.txt 2011-06-05 10:38:25.000000000 +0200 +++ soprano/parsers/raptor/CMakeLists.txt 2011-07-19 18:49:58.000000000 +0200 @@ -13,13 +13,11 @@ raptorparser.cpp ) -configure_file(raptor-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/raptor-config.h) - qt4_automoc(${raptor_parser_SRC}) -add_library(soprano_raptorparser MODULE ${raptor_parser_SRC}) +add_library(soprano_raptorparser MODULE ${raptor_parser_SRC}) -TARGET_LINK_LIBRARIES(soprano_raptorparser soprano ${RAPTOR_LIBRARIES}) +TARGET_LINK_LIBRARIES(soprano_raptorparser soprano raptor2 ${RAPTOR_LIBRARIES}) set_target_properties(soprano_raptorparser PROPERTIES DEFINE_SYMBOL MAKE_RAPTORPARSER_LIB diff -Naur soprano-2.6.51/parsers/raptor/raptor-config.h.cmake soprano/parsers/raptor/raptor-config.h.cmake --- soprano-2.6.51/parsers/raptor/raptor-config.h.cmake 2011-06-05 10:38:25.000000000 +0200 +++ soprano/parsers/raptor/raptor-config.h.cmake 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ -#cmakedefine RAPTOR_HAVE_TRIG diff -Naur soprano-2.6.51/parsers/raptor/raptorparser.cpp soprano/parsers/raptor/raptorparser.cpp --- soprano-2.6.51/parsers/raptor/raptorparser.cpp 2011-06-05 10:38:25.000000000 +0200 +++ soprano/parsers/raptor/raptorparser.cpp 2011-07-19 18:49:58.000000000 +0200 @@ -3,7 +3,7 @@ * This file is part of Soprano Project * * Copyright (C) 2006 Duncan Mac-Vicar - * Copyright (C) 2007 Sebastian Trueg + * Copyright (C) 2007,2011 Sebastian Trueg * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,14 +22,13 @@ */ #include "raptorparser.h" -#include "raptor-config.h" #include "util/simplestatementiterator.h" #include "statement.h" #include "locator.h" #include "error.h" -#include +#include #include #include @@ -40,88 +39,71 @@ #include -namespace { - class RaptorInitHelper - { - public: - RaptorInitHelper() { - raptor_init(); - } - ~RaptorInitHelper() { - raptor_finish(); - } - }; -} - Q_EXPORT_PLUGIN2(soprano_raptorparser, Soprano::Raptor::Parser) namespace { - // for some strange reason raptor <= 1.4.15 can only handle application/turtle when parsing - // and application/x-turtle when serializing, but not the other way around - QString mimeTypeString( Soprano::RdfSerialization s, const QString& userSerialization ) - { -#ifndef RAPTOR_HAVE_TRIG - if ( s == Soprano::SerializationTurtle ) { - return "application/turtle"; // x-turtle does not work.... - } - else -#endif - { - return serializationMimeType( s, userSerialization ); - } - } - - - void raptorMessageHandler( void* userData, raptor_locator* locator, const char* message ) + void raptorLogHandler(void *userData,raptor_log_message *message) { Soprano::Raptor::Parser* p = static_cast( userData ); - if ( locator ) { - p->setError( Soprano::Error::ParserError( Soprano::Error::Locator( locator->line, locator->column, locator->byte ), - QString::fromUtf8( message ), + if ( message->locator ) { + p->setError( Soprano::Error::ParserError( Soprano::Error::Locator( message->locator->line, message->locator->column, message->locator->byte ), + QString::fromUtf8( message->text ), Soprano::Error::ErrorParsingFailed ) ); } else { - p->setError( Soprano::Error::Error( QString::fromUtf8( message ), Soprano::Error::ErrorUnknown ) ); + p->setError( Soprano::Error::Error( QString::fromUtf8( message->text ), Soprano::Error::ErrorUnknown ) ); } } - - Soprano::Node convertNode( const void* data, raptor_identifier_type type, - raptor_uri* objectLiteralDatatype = 0, const unsigned char* objectLiteralLanguage = 0 ) + Soprano::Node convertNode( raptor_term * term ) { - switch( type ) { - case RAPTOR_IDENTIFIER_TYPE_RESOURCE: - case RAPTOR_IDENTIFIER_TYPE_PREDICATE: - case RAPTOR_IDENTIFIER_TYPE_ORDINAL: - return Soprano::Node::createResourceNode( QString::fromUtf8( ( char* )raptor_uri_as_string( ( raptor_uri* )data ) ) ); - - case RAPTOR_IDENTIFIER_TYPE_ANONYMOUS: - return Soprano::Node::createBlankNode( QString::fromUtf8( ( const char* )data ) ); - - case RAPTOR_IDENTIFIER_TYPE_LITERAL: - case RAPTOR_IDENTIFIER_TYPE_XML_LITERAL: - if ( objectLiteralDatatype ) { - return Soprano::Node::createLiteralNode( Soprano::LiteralValue::fromString( QString::fromUtf8( ( const char* )data ), - QString::fromUtf8( ( char* )raptor_uri_as_string( objectLiteralDatatype ) ) ) ); + if(!term) { + return Soprano::Node(); + } + + switch( term->type ) { + case RAPTOR_TERM_TYPE_URI: { + return Soprano::Node::createResourceNode( + QString::fromUtf8( ( char* )raptor_uri_as_string( term->value.uri ) ) ); + } + + case RAPTOR_TERM_TYPE_BLANK: { + return Soprano::Node::createBlankNode( + QString::fromUtf8( ( const char* )(term->value.blank.string) ) ); + } + + case RAPTOR_TERM_TYPE_LITERAL: { + if ( term->value.literal.datatype ) { + return Soprano::Node::createLiteralNode( + Soprano::LiteralValue::fromString( + QString::fromUtf8( ( const char* )term->value.literal.string ), + QString::fromUtf8( + ( char* )raptor_uri_as_string(term->value.literal.datatype ) ) + ) + ); } else { - return Soprano::Node::createLiteralNode( Soprano::LiteralValue::createPlainLiteral( QString::fromUtf8( ( const char* )data ), - QString::fromUtf8( ( const char* )objectLiteralLanguage ) ) ); + return Soprano::Node::createLiteralNode( + Soprano::LiteralValue::createPlainLiteral( + QString::fromUtf8( ( const char* )term->value.literal.string ), + QString::fromUtf8( ( const char* )term->value.literal.language ) ) ); } + } default: return Soprano::Node(); } - } + // make gcc shut up + return Soprano::Node(); + } Soprano::Statement convertTriple( const raptor_statement* triple ) { - return Soprano::Statement( convertNode( triple->subject, triple->subject_type ), - convertNode( triple->predicate, triple->predicate_type ), - convertNode( triple->object, triple->object_type, - triple->object_literal_datatype, - triple->object_literal_language ) ); + return Soprano::Statement( convertNode( triple->subject ), + convertNode( triple->predicate ), + convertNode( triple->object ), + convertNode( triple->graph ) ); } @@ -132,47 +114,48 @@ }; - void raptorTriplesHandler( void* userData, const raptor_statement* triple ) + void raptorTriplesHandler( void* userData, raptor_statement* triple ) { + Q_ASSERT(userData); ParserData* pd = static_cast( userData ); - Soprano::Statement s = convertTriple( triple ); -// qDebug() << "got triple: " << s; - s.setContext( pd->currentContext ); - pd->statements.append( s ); + pd->statements.append( convertTriple( triple ) ); } +} - void raptorGraphHandler( void* userData, raptor_uri* graph ) - { - Soprano::Node context = Soprano::Node::createResourceNode( QString::fromUtf8( ( char* )raptor_uri_as_string( graph ) ) ); - ParserData* pd = static_cast( userData ); - pd->currentContext = context; -// qDebug() << "got graph: " << context; - } -} +class Soprano::Raptor::Parser::Private +{ +public: + raptor_world * world; + mutable QMutex mutex; +}; Soprano::Raptor::Parser::Parser() : QObject(), - Soprano::Parser( "raptor" ) + Soprano::Parser( "raptor" ), + d(new Private()) { + d->world = raptor_new_world(); + raptor_world_open(d->world); + Q_ASSERT(d->world); } Soprano::Raptor::Parser::~Parser() { + raptor_free_world(d->world); + delete d; } Soprano::RdfSerializations Soprano::Raptor::Parser::supportedSerializations() const { - return( SerializationRdfXml - |SerializationNTriples - |SerializationTurtle -#ifdef RAPTOR_HAVE_TRIG - |SerializationTrig -#endif - ); + return( SerializationRdfXml + |SerializationNTriples + |SerializationTurtle + |SerializationTrig + ); } @@ -180,13 +163,14 @@ const QString& userSerialization ) const { // create the parser - QString mimeType = mimeTypeString( serialization, userSerialization ); + const QString mimeType = Soprano::serializationMimeType( serialization, userSerialization ); raptor_parser* parser = 0; if ( serialization == Soprano::SerializationNTriples ) { - parser = raptor_new_parser( "ntriples" ); // mimetype for ntriple is text/plain which is useless for the method below + parser = raptor_new_parser(d->world,"ntriples"); // mimetype for ntriple is text/plain which is useless for the method below } else { - parser = raptor_new_parser_for_content( 0, + parser = raptor_new_parser_for_content( d->world, + 0, mimeType.toLatin1().data(), 0, 0, @@ -194,16 +178,14 @@ } if ( !parser ) { - qDebug() << "(Soprano::Raptor::Parser) no parser for serialization " << mimeTypeString( serialization, userSerialization ); - setError( QString( "Failed to create parser for serialization %1" ).arg( mimeTypeString( serialization, userSerialization ) ) ); + qDebug() << "(Soprano::Raptor::Parser) no parser for serialization " << Soprano::serializationMimeType( serialization, userSerialization ); + setError( QString( "Failed to create parser for serialization %1" ).arg( Soprano::serializationMimeType( serialization, userSerialization ) ) ); return 0; } - // set the erro handling method + // set the error handling method Parser* that = const_cast( this ); - raptor_set_fatal_error_handler( parser, that, raptorMessageHandler ); - raptor_set_error_handler( parser, that, raptorMessageHandler ); - raptor_set_warning_handler( parser, that, raptorMessageHandler ); + raptor_world_set_log_handler(d->world, that, raptorLogHandler); return parser; } @@ -223,48 +205,6 @@ setError( QString( "Could not open file %1 for reading." ).arg( filename ) ); return StatementIterator(); } - -// clearError(); - -// raptor_parser* parser = createParser( serialization, userSerialization ); -// if ( !parser ) { -// return StatementIterator(); -// } - -// // prepare the container for the parsed data -// QList statements; -// raptor_set_statement_handler( parser, &statements, raptorTriplesHandler ); - -// // start the atual parsing -// QUrl uri( QUrl::fromLocalFile( filename ) ); -// if ( uri.scheme().isEmpty() ) { -// // we need to help the stupid librdf file url handling -// uri.setScheme("file"); -// } -// raptor_uri* raptorBaseUri = 0; -// if ( !baseUri.toString().isEmpty() ) { -// raptorBaseUri = raptor_new_uri( (unsigned char *) baseUri.toString().toUtf8().data() ); -// } -// raptor_uri* raptorUri = raptor_new_uri( (unsigned char *) uri.toString().toUtf8().data() ); -// if ( !raptorUri ) { -// setError( QLatin1String( "Internal: Failed to create raptor_uri instance for '%1'" ).arg( uri ) ); -// return StatementIterator(); -// } - -// int r = raptor_parse_uri( parser, raptorUri, raptorBaseUri ); - -// raptor_free_parser( parser ); -// raptor_free_uri( raptorUri ); -// if ( raptorBaseUri ) { -// raptor_free_uri( raptorBaseUri ); -// } - -// if ( r == 0 ) { -// return SimpleStatementIterator( statements ); -// } -// else { -// return StatementIterator(); -// } } @@ -279,14 +219,12 @@ } -Soprano::StatementIterator -Soprano::Raptor::Parser::parseStream( QTextStream& stream, - const QUrl& baseUri, - RdfSerialization serialization, - const QString& userSerialization ) const +Soprano::StatementIterator Soprano::Raptor::Parser::parseStream( QTextStream& stream, + const QUrl& baseUri, + RdfSerialization serialization, + const QString& userSerialization ) const { - QMutexLocker lock( &m_mutex ); - RaptorInitHelper raptorInitHelper; + QMutexLocker lock( &d->mutex ); clearError(); @@ -297,22 +235,19 @@ // prepare the container for the parsed data ParserData data; - raptor_set_statement_handler( parser, &data, raptorTriplesHandler ); -#ifdef RAPTOR_HAVE_TRIG - raptor_set_graph_handler( parser, &data, raptorGraphHandler ); -#endif + raptor_parser_set_statement_handler( parser, &data, raptorTriplesHandler ); // start the atual parsing raptor_uri* raptorBaseUri = 0; if ( baseUri.isValid() ) { - raptorBaseUri = raptor_new_uri( (unsigned char *) baseUri.toString().toUtf8().data() ); + raptorBaseUri = raptor_new_uri( d->world,(unsigned char *) baseUri.toString().toUtf8().data() ); } else { - raptorBaseUri = raptor_new_uri( (unsigned char *) "http://soprano.sourceforge.net/dummyBaseUri" ); + raptorBaseUri = raptor_new_uri( d->world, (unsigned char *) "http://soprano.sourceforge.net/dummyBaseUri" ); } clearError(); - if ( raptor_start_parse( parser, raptorBaseUri ) ) { + if ( raptor_parser_parse_start( parser, raptorBaseUri ) != 0 ) { if ( !lastError() ) { ErrorCache::setError( QLatin1String( "Failed to start parsing." ) ); } @@ -331,7 +266,10 @@ while ( !dev->atEnd() ) { qint64 r = dev->read( buf.data(), buf.size() ); if ( r <= 0 || - raptor_parse_chunk( parser, ( const unsigned char* )buf.data(), r, 0 ) ) { + raptor_parser_parse_chunk( parser, ( const unsigned char* )buf.data(), r, 0 ) ) { + // parse_chunck return failure code. + // Call it with END=true and then free + raptor_parser_parse_chunk(parser,0,0,/*END=*/1); raptor_free_parser( parser ); if ( raptorBaseUri ) { raptor_free_uri( raptorBaseUri ); @@ -344,7 +282,10 @@ while ( !stream.atEnd() ) { QString buf = stream.read( bufSize ); QByteArray utf8Data = buf.toUtf8(); - if ( raptor_parse_chunk( parser, ( const unsigned char* )utf8Data.data(), utf8Data.length(), 0 ) ) { + if ( raptor_parser_parse_chunk( parser, ( const unsigned char* )utf8Data.data(), utf8Data.length(), 0 ) ) { + // parse_chunck return failure code. + // Call it with END=true and then free + raptor_parser_parse_chunk(parser,0,0,/*END=*/1); raptor_free_parser( parser ); if ( raptorBaseUri ) { raptor_free_uri( raptorBaseUri ); @@ -353,7 +294,8 @@ } } } - raptor_parse_chunk( parser, 0, 0, 1 ); + // Call parse_chunk with END=true + raptor_parser_parse_chunk( parser, 0, 0, 1 ); raptor_free_parser( parser ); if ( raptorBaseUri ) { diff -Naur soprano-2.6.51/parsers/raptor/raptorparser.h soprano/parsers/raptor/raptorparser.h --- soprano-2.6.51/parsers/raptor/raptorparser.h 2011-06-05 10:38:25.000000000 +0200 +++ soprano/parsers/raptor/raptorparser.h 2011-07-19 18:49:58.000000000 +0200 @@ -29,13 +29,11 @@ #include "parser.h" -#include - +#include namespace Soprano { namespace Raptor { - class Parser : public QObject, public Soprano::Parser - { + class Parser : public QObject, public Soprano::Parser { Q_OBJECT Q_INTERFACES(Soprano::Parser) @@ -43,7 +41,7 @@ Parser(); ~Parser(); - RdfSerializations supportedSerializations() const; + RdfSerializations supportedSerializations() const; StatementIterator parseFile( const QString& filename, const QUrl& baseUri, @@ -64,7 +62,10 @@ raptor_parser* createParser( RdfSerialization serialization, const QString& userSerialization = QString() ) const; - mutable QMutex m_mutex; + class Private; + Private * d; + + }; } } diff -Naur soprano-2.6.51/serializers/raptor/CMakeLists.txt soprano/serializers/raptor/CMakeLists.txt --- soprano-2.6.51/serializers/raptor/CMakeLists.txt 2011-06-05 10:38:25.000000000 +0200 +++ soprano/serializers/raptor/CMakeLists.txt 2011-07-19 18:49:58.000000000 +0200 @@ -9,13 +9,8 @@ ${RAPTOR_INCLUDE_DIR} ) -include(CheckFunctionExists) set(CMAKE_REQUIRED_INCLUDES ${RAPTOR_INCLUDE_DIR}) set(CMAKE_REQUIRED_LIBRARIES ${RAPTOR_LIBRARIES}) -check_function_exists( raptor_new_iostream_from_handler2 HAVE_IOSTREAM_HANDLER2 ) -if(HAVE_IOSTREAM_HANDLER2) - add_definitions(-DHAVE_IOSTREAM_HANDLER2) -endif(HAVE_IOSTREAM_HANDLER2) set(raptor_serializer_SRC raptorserializer.cpp diff -Naur soprano-2.6.51/serializers/raptor/raptorserializer.cpp soprano/serializers/raptor/raptorserializer.cpp --- soprano-2.6.51/serializers/raptor/raptorserializer.cpp 2011-06-05 10:38:25.000000000 +0200 +++ soprano/serializers/raptor/raptorserializer.cpp 2011-07-19 18:49:58.000000000 +0200 @@ -38,54 +38,135 @@ class RaptorInitHelper { public: + raptor_world* world; + RaptorInitHelper() { - raptor_init(); + world = raptor_new_world(); + raptor_world_open(world); } ~RaptorInitHelper() { - raptor_finish(); + raptor_free_world(world); } }; - bool convertNode( const Soprano::Node& node, const void** data, raptor_identifier_type* type, raptor_uri** dataType = 0, const unsigned char** lang = 0 ) + /* Probably unnecessary for serializer*/ + /* + QString mimeTypeString( Soprano::RdfSerialization s, const QString& userSerialization ) + { + if ( s == Soprano::SerializationTurtle ) { + return "application/turtle"; // x-turtle does not work.... + } + else { + return serializationMimeType( s, userSerialization ); + } + }*/ + + raptor_term * convertNode( raptor_world * world, const Soprano::Node& node) { + raptor_term * answer = 0; + /* According to documentation, raptor_new_term family takes copy of + * all given input parameters + */ if ( node.isResource() ) { - *data = raptor_new_uri( ( const unsigned char* )node.uri().toEncoded().data() ); - *type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; - return true; + raptor_uri * uri = raptor_new_uri(world, ( const unsigned char* )node.uri().toEncoded().data() ); + answer = raptor_new_term_from_uri(world,uri); + + raptor_free_uri(uri); } else if ( node.isBlank() ) { - *data = qstrdup( node.identifier().toUtf8().data() ); - *type = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS; - return true; + answer = raptor_new_term_from_blank( + world, (const unsigned char*)node.identifier().toUtf8().data() ); } else if ( node.isLiteral() ) { - *data = qstrdup( node.toString().toUtf8().data() ); + // Because QByteArray.data() is valid as long as QByteArray itself is + // alive, we store langBA ( and others _x_BA untill function exits + + //const unsigned char * literal = 0; + QByteArray langBA; + const unsigned char * lang = 0; + raptor_uri * datatype = 0; + if ( node.literal().isPlain() ) { if ( !node.language().isEmpty() ) - *lang = ( unsigned char* )qstrdup( ( const char* )node.language().toUtf8().data() ); + langBA = node.language().toUtf8(); + lang = ( const unsigned char* )( langBA.constData() ); } else { - *dataType = raptor_new_uri( ( const unsigned char* )node.dataType().toEncoded().data() ); + datatype = raptor_new_uri( world, ( const unsigned char* )node.dataType().toEncoded().data() ); } - *type = RAPTOR_IDENTIFIER_TYPE_LITERAL; - return true; + + // Now we costructs statement + answer = raptor_new_term_from_literal(world,(const unsigned char*)node.literal().toByteArray().constData(),datatype,lang); + + // And free unnecessary resources + if ( datatype) + raptor_free_uri(datatype); + } - return false; + return answer; } - raptor_statement* convertStatement( const Soprano::Statement& statement ) + raptor_statement* convertStatement(raptor_world * world, const Soprano::Statement& statement ) { - raptor_statement* s = new raptor_statement; - memset( s, 0, sizeof( raptor_statement ) ); - convertNode( statement.subject(), &s->subject, &s->subject_type ); - convertNode( statement.predicate(), &s->predicate, &s->predicate_type ); - convertNode( statement.object(), &s->object, &s->object_type, &s->object_literal_datatype, &s->object_literal_language ); + // Get terms + raptor_term * subject_term = 0, *object_term = 0, * predicate_term = 0; + raptor_term * graph_term = 0; + + subject_term = convertNode(world,statement.subject()); + if ( !subject_term) { + qDebug() << "Failed to convert subject to raptor_term"; + return 0; + } + + predicate_term = convertNode(world,statement.predicate()); + if (!predicate_term) { + qDebug() << "Failed to convert predicate to raptor_term"; + raptor_free_term(subject_term); + return 0; + } + + object_term = convertNode(world,statement.object()); + if (!object_term) { + qDebug() << "Failed to convert object to raptor_term"; + raptor_free_term(subject_term); + raptor_free_term(predicate_term); + return 0; + } + + if ( !statement.context().isEmpty() ) { + graph_term = convertNode(world,statement.context()); + if(!graph_term) { + qDebug() << "Failed to convert graph/context to raptor_term. Node is" << statement.context(); + raptor_free_term(subject_term); + raptor_free_term(predicate_term); + raptor_free_term(object_term); + return 0; + } + } + + + raptor_statement* s = raptor_new_statement_from_nodes( + world, + subject_term, + predicate_term, + object_term, + graph_term); + + if (!s) { + qDebug() << "Failed to build raptor_statement from terms"; + raptor_free_term(subject_term); + raptor_free_term(predicate_term); + raptor_free_term(object_term); + raptor_free_term(graph_term); + } + return s; } + /* void free_node( const void* data, raptor_identifier_type type ) { switch( type ) { @@ -109,6 +190,7 @@ free( ( char* )s->object_literal_language ); delete s; } + */ int raptorIOStreamWriteByte( void* data, const int byte ) @@ -121,6 +203,7 @@ else { ( *s ) << ( char )byte; } + //qDebug() << "Write char:" << (char)(byte); return 0; } @@ -140,6 +223,7 @@ raptorIOStreamWriteByte( data, p[i] ); } } + //qDebug() << "Write string: " << p; break; } default: @@ -153,15 +237,36 @@ Q_EXPORT_PLUGIN2(soprano_raptorserializer, Soprano::Raptor::Serializer) + +/* We can not rely on RaptorInitHelper anymore because + * we need raptor_world in supportedUserSerializations. + * Instead of constantly creating new raptor_world just to + * detect user supported serializations, it is easier to + * embed raptor_world into class. + * And we can not declare raptor_world as a member of + * Serializer directly, because raptor_world is a typedef, + * not a class. So it can not be forward declarated + */ +class Soprano::Raptor::Serializer::Private +{ + public: + raptor_world * world; +}; + Soprano::Raptor::Serializer::Serializer() : QObject(), Soprano::Serializer( "raptor" ) { + this->d = new Private(); + this->d->world = raptor_new_world(); + raptor_world_open(d->world); } Soprano::Raptor::Serializer::~Serializer() { + raptor_free_world(d->world); + delete d; } @@ -174,17 +279,19 @@ QStringList Soprano::Raptor::Serializer::supportedUserSerializations() const { QStringList sl; - int i = 0; - const char* name = 0; - const char* label = 0; - const char* mimeType = 0; - const unsigned char* uri = 0; - while ( !raptor_serializers_enumerate( i, - &name, - &label, - &mimeType, - &uri ) ) { - sl << QString::fromUtf8( name ); + const raptor_syntax_description * serializer_descr = 0; + for ( int i = 0; 1; ++i ) { + serializer_descr = + raptor_world_get_serializer_description(d->world,i); + + /* raptor_world_get_serializer_description will return + * NULL when conter runs out of bonds and there is no + * more serializers + */ + if (!serializer_descr) + break; + + sl << QString::fromUtf8( serializer_descr->names[0] ); ++i; } return sl; @@ -198,28 +305,43 @@ { clearError(); - RaptorInitHelper raptorHelper; + raptor_world * world = this->d->world; raptor_serializer* serializer = 0; + QString mimeType = serializationMimeType(serialization,userSerialization); + if ( serialization == SerializationRdfXml ) { - serializer = raptor_new_serializer( "rdfxml-abbrev" ); // we always want the abbreviated xmlrdf + serializer = raptor_new_serializer( world, "rdfxml-abbrev" ); // we always want the abbreviated xmlrdf } else { + const raptor_syntax_description * serializer_descr = 0; for ( int i = 0; 1; ++i ) { - const char* syntax_name = 0; - const char* syntax_label = 0; - const char* mime_type = 0; - const unsigned char* uri_string = 0; - if ( raptor_serializers_enumerate( i, - &syntax_name, - &syntax_label, - &mime_type, - &uri_string ) ) - break; - if ( !qstrcmp( serializationMimeType( serialization, userSerialization ).toLatin1().data(), mime_type ) ) { - serializer = raptor_new_serializer( syntax_name ); + serializer_descr = + raptor_world_get_serializer_description(world,i); + + /* raptor_world_get_serializer_description will return + * NULL when conter runs out of bonds and there is no + * more serializers + */ + if (!serializer_descr) break; + + /* In serializer_descr->mime_types we have a array of pairs + * (mime_type,Q) of mime_type for this syntax. It looks like + * we can ignore Q value in this case + * Acording to documentation, this array can have zero elements + */ + for( int mt_number = 0; mt_number < serializer_descr->mime_types_count; + mt_number++) + { + const char * mime_type_N = serializer_descr->mime_types[mt_number].mime_type; + if ( !qstrcmp( serializationMimeType( serialization, userSerialization ).toLatin1().data(), mime_type_N ) ) { + serializer = raptor_new_serializer( world, serializer_descr->names[0] ); + break; + } } + if ( serializer ) + break; } } @@ -232,8 +354,8 @@ QHash namespaces = prefixes(); for ( QHash::const_iterator pfit = namespaces.constBegin(); pfit != namespaces.constEnd(); ++pfit ) { - raptor_uri* ns = raptor_new_uri( reinterpret_cast( pfit.value().toEncoded().data() ) ); - raptor_serialize_set_namespace( serializer, + raptor_uri* ns = raptor_new_uri( world,reinterpret_cast( pfit.value().toEncoded().data() ) ); + raptor_serializer_set_namespace( serializer, ns, ( unsigned char* )pfit.key().toLatin1().data() ); raptor_free_uri( ns ); @@ -241,42 +363,53 @@ bool success = true; -#ifdef HAVE_IOSTREAM_HANDLER2 - raptor_iostream_handler2 raptorStreamHandler = { - 2, - 0, - 0, - raptorIOStreamWriteByte, - raptorIOStreamWriteBytes, - 0, - 0, - 0 - }; - raptor_iostream* raptorStream = raptor_new_iostream_from_handler2( &stream, - &raptorStreamHandler ); -#else - raptor_iostream_handler raptorStreamHandler = { - 0, - 0, - raptorIOStreamWriteByte, - raptorIOStreamWriteBytes, - 0 - }; - raptor_iostream* raptorStream = raptor_new_iostream_from_handler( &stream, - &raptorStreamHandler ); -#endif + raptor_iostream_handler raptorStreamHandler; + // ATTENTION: Raptor documentation is incorrect! Always set + // version to 2 and raptor_iostream_calculate_modes internal + // call will correctly determine operation mode ( read,write,readwrite) + raptorStreamHandler.version = 2; + raptorStreamHandler.init = 0; + raptorStreamHandler.finish = 0; + raptorStreamHandler.write_byte = raptorIOStreamWriteByte; + raptorStreamHandler.write_bytes = raptorIOStreamWriteBytes; + raptorStreamHandler.write_end = 0; + raptorStreamHandler.read_bytes = 0; + raptorStreamHandler.read_eof = 0; + + raptor_iostream* raptorStream = raptor_new_iostream_from_handler( + world, + &stream, + &raptorStreamHandler + ); + + if (!raptorStream) { + qDebug() << "Can not create raptor iostream"; + raptor_free_serializer(serializer); + return false; + } // raptor_serialize_start takes ownership of raptorStream - raptor_serialize_start( serializer, 0, raptorStream ); + raptor_serializer_start_to_iostream( serializer,0, raptorStream ); while ( it.next() ) { - raptor_statement* rs = convertStatement( *it ); - raptor_serialize_statement( serializer, rs ); - free_statement( rs ); + raptor_statement * rs = convertStatement(world, *it ); + if (rs) { + //qDebug() << "Serializing statement: " << *it; + raptor_serializer_serialize_statement(serializer, rs ); + raptor_free_statement( rs ); + } + else { + qDebug() << "Fail to convert Soprano::Statement " << + *it << + " to raptor_statement"; + success = false; + break; + } } - raptor_serialize_end( serializer ); + raptor_serializer_serialize_end( serializer ); raptor_free_serializer( serializer ); + raptor_free_iostream(raptorStream); return success; } diff -Naur soprano-2.6.51/serializers/raptor/raptorserializer.h soprano/serializers/raptor/raptorserializer.h --- soprano-2.6.51/serializers/raptor/raptorserializer.h 2011-06-05 10:38:25.000000000 +0200 +++ soprano/serializers/raptor/raptorserializer.h 2011-07-19 18:49:58.000000000 +0200 @@ -28,7 +28,6 @@ #include "serializer.h" - namespace Soprano { namespace Raptor { class Serializer : public QObject, public Soprano::Serializer @@ -47,6 +46,12 @@ QTextStream& stream, RdfSerialization serialization, const QString& userSerialization = QString() ) const; + private: + /* See source file comments, that explain why it is necessary to + * use Private class and RaptorInitHelper is not succifient anymore + */ + class Private; + Private * d; }; } } diff -Naur soprano-2.6.51/soprano/inference/inferenceruleset.cpp soprano/soprano/inference/inferenceruleset.cpp --- soprano-2.6.51/soprano/inference/inferenceruleset.cpp 2011-06-05 10:38:25.000000000 +0200 +++ soprano/soprano/inference/inferenceruleset.cpp 2011-07-19 18:49:58.000000000 +0200 @@ -27,7 +27,10 @@ #include #include - +#ifdef Q_OS_WIN +#include +#include +#endif class Soprano::Inference::RuleSet::Private : public QSharedData { @@ -138,5 +141,22 @@ RuleParser parser; parser.parseFile( path ); +#ifdef Q_OS_WIN + // Additionally try to look up the rules based on the runtime Path if + // they can not be found at the install prefix + if (!parser.rules().count()) { + path = QDir( QCoreApplication::applicationDirPath() ).absoluteFilePath( ".." ); + path += "/share/soprano/rules/"; + + switch( set ) { + case RDFS: + path += "rdfs.rules"; + break; + case NRL: + path += "nrl.rules"; + break; + } + } +#endif return parser.rules(); } diff -Naur soprano-2.6.51/soprano/sopranodirs.cpp soprano/soprano/sopranodirs.cpp --- soprano-2.6.51/soprano/sopranodirs.cpp 2011-06-05 10:38:25.000000000 +0200 +++ soprano/soprano/sopranodirs.cpp 2011-07-19 18:49:58.000000000 +0200 @@ -28,8 +28,12 @@ #include #include - -#if defined _WIN32 || defined _WIN64 +#ifdef Q_OS_WIN +static inline QString getWinPrefix() +{ + // returns the parent directory of the application + return QDir( QCoreApplication::applicationDirPath() ).absoluteFilePath( ".." ); +} #define PATH_SEPARATOR ';' #else #define PATH_SEPARATOR ':' @@ -123,6 +127,8 @@ paths << QLatin1String( SOPRANO_PREFIX"/lib"SOPRANO_LIB_SUFFIX ); #ifdef Q_OS_WIN paths << QLatin1String( SOPRANO_PREFIX"/bin" ); + paths << getWinPrefix() + QLatin1String( "/bin" ); + paths << getWinPrefix() + QLatin1String( "/lib"SOPRANO_LIB_SUFFIX ); #else paths << QLatin1String( "/usr/lib"SOPRANO_LIB_SUFFIX ); paths << QLatin1String( "/usr/local/lib"SOPRANO_LIB_SUFFIX ); @@ -136,6 +142,9 @@ { QStringList paths; paths << QLatin1String( SOPRANO_PREFIX"/share" ) +#ifdef Q_OS_WIN + << getWinPrefix() + QLatin1String( "/share" ) +#endif << Soprano::envDirList( "SOPRANO_DIRS" ) << Soprano::envDirList( "XDG_DATA_DIRS" ); return paths; @@ -146,6 +155,9 @@ { QStringList paths; paths << QLatin1String( SOPRANO_PREFIX"/bin" ) +#ifdef Q_OS_WIN + << getWinPrefix() + QLatin1String( "/bin" ) +#endif << envDirList( "PATH" ); return paths; } diff -Naur soprano-2.6.51/test/CMakeLists.txt soprano/test/CMakeLists.txt --- soprano-2.6.51/test/CMakeLists.txt 2011-06-05 10:38:25.000000000 +0200 +++ soprano/test/CMakeLists.txt 2011-07-19 18:49:58.000000000 +0200 @@ -135,6 +135,12 @@ target_link_libraries(parsertest soprano ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY}) add_test(parsertest ${EXECUTABLE_OUTPUT_PATH}/parsertest) +# serializer test +qt4_automoc(serializetest serializetest.cpp) +add_executable(serializertest serializetest.cpp) +target_link_libraries(serializertest soprano ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY}) +add_test(serializertest ${EXECUTABLE_OUTPUT_PATH}/serializertest) + # Error test qt4_automoc(errortest errortest.cpp) add_executable(errortest errortest.cpp) diff -Naur soprano-2.6.51/test/serializetest.cpp soprano/test/serializetest.cpp --- soprano-2.6.51/test/serializetest.cpp 1970-01-01 01:00:00.000000000 +0100 +++ soprano/test/serializetest.cpp 2011-07-19 18:49:58.000000000 +0200 @@ -0,0 +1,167 @@ +/* + * This file is part of Soprano Project. + * + * Copyright (C) 2007-2008 Sebastian Trueg + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "serializetest.h" +#include "config-testdata.h" + +#include "serializer.h" +#include "parser.h" +#include "pluginmanager.h" +#include "statementiterator.h" +#include "simplestatementiterator.h" +#include "statement.h" +#include "vocabulary.h" + +#include +#include +#include + + +using namespace Soprano; + +#include "testdata.h" + + +void SerializerTest::init() +{ +#if 0 + // Init reference statements list + const Parser * parser = PluginManager::instance()->discoverParserForSerialization(SerializationTrig); + QVERIFY(parser); + StatementIterator refIt = parser->parseFile( + SOPRANO_TEST_DATA_DIR"/trig-testdata.trig", + QUrl("http://soprano.sf.net/testdata/"), + SerializationTrig); + this->referenceStatements = refIt.allStatements(); +#endif +} + +Q_DECLARE_METATYPE( Soprano::RdfSerialization ) + +void SerializerTest::testSerializer_data() +{ + + QTest::addColumn( "serialization" ); + QTest::addColumn( "withContext" ); + + QTest::newRow("rdf_xml") << SerializationRdfXml << false; + QTest::newRow("turtle") << SerializationTurtle << false; + QTest::newRow("trig") << SerializationTrig << true; +} + + + +void SerializerTest::testSerializer() +{ + QFETCH( RdfSerialization, serialization ); + QFETCH( bool, withContext ); + + //qDebug() << "Serialization: " << serializationMimeType(serialization); + QList serializers = PluginManager::instance()->allSerializers(); + + + /* Step 1 - create reference statements */ + QList referenceStatements = testData(withContext); + //QList testStatements = testData( withContext ); + + Q_FOREACH( const Serializer * serializer, serializers ) { + if ( serializer->supportsSerialization( serialization ) ) { + // Find if we have Parser for this serialization, to parse data back. + // If not, then oops ) + const Parser * back_parser = PluginManager::instance()->discoverParserForSerialization(serialization); + if ( !back_parser ) { + qDebug() << "We can not found parser for" << + serializationMimeType(serialization) << + " Skipping it"; + continue; + } + + // Now serialize reference data + QByteArray data_array; + QTextStream serializationStorage(&data_array,QIODevice::ReadWrite); + + bool result = serializer->serialize( + /*what*/Util::SimpleStatementIterator(referenceStatements), + /*where*/serializationStorage, + /*type*/serialization + ); + QVERIFY(result); + + //qDebug() << "Serialization storage: " << data_array; + + // Now parse gained text stream back + QTextStream readStorageStream(&data_array, QIODevice::ReadOnly); + StatementIterator it = back_parser->parseStream( + readStorageStream, + QUrl("http://soprano.sf.net/testdata/"), + serialization); + + QList all = it.allStatements(); + + + // Now compare recieved with reference + QCOMPARE( all.count(), referenceStatements.count() ); + + Q_FOREACH( Statement s, referenceStatements ) { + bool contains = all.contains(s); + if ( !contains ) { + qDebug() << "Not found in parsed: " << s; + } + + QVERIFY( contains ); + } + + } + } +} + + +#if 0 +void SerializerTest::testEncoding() +{ + // FIXME: provide test data for all supported encodings (no big problem so far since we only have the raptor parser) + + // parse both files, same content, different encodings and compare the results + const QString utf8File = SOPRANO_TEST_DATA_DIR"/rdf_xml-testdata-utf8.rdf"; + const QString isoFile = SOPRANO_TEST_DATA_DIR"/rdf_xml-testdata-iso8859.rdf"; + + const Soprano::Parser* parser = PluginManager::instance()->discoverParserForSerialization( SerializationRdfXml ); + if ( parser ) { + QList utf8Statements = parser->parseFile( utf8File, QUrl(), SerializationRdfXml ).allStatements(); + QList isoStatements = parser->parseFile( isoFile, QUrl(), SerializationRdfXml ).allStatements(); + + // brute force comparision, time is not an issue, no need to get inventive. ;) + foreach( const Statement& s, utf8Statements ) { + if ( !isoStatements.contains( s ) ) qDebug() << s; + QVERIFY( isoStatements.contains( s ) ); + } + foreach( const Statement& s, isoStatements ) { + if ( !utf8Statements.contains( s ) ) qDebug() << s; + QVERIFY( utf8Statements.contains( s ) ); + } + } +} +#endif + +QTEST_MAIN( SerializerTest ) + +#include "serializetest.moc" + diff -Naur soprano-2.6.51/test/serializetest.h soprano/test/serializetest.h --- soprano-2.6.51/test/serializetest.h 1970-01-01 01:00:00.000000000 +0100 +++ soprano/test/serializetest.h 2011-07-19 18:49:58.000000000 +0200 @@ -0,0 +1,52 @@ +/* + * This file is part of Soprano Project. + * + * Copyright (C) 2007-2008 Sebastian Trueg + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef SOPRANO_SERIALIZER_TEST_H +#define SOPRANO_SERIALIZER_TEST_H + +#include +#include + +#include "statement.h" + + +/* Workflow: + * 1) Prepare one QList with data, used as reference + * 2) For each serializer: + * 2.1) Serialize reference to memory + * 2.2) Parse this memory back to QList + * 2.3) Compare with reference + */ +class SerializerTest: public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void init(); + void testSerializer_data(); + void testSerializer(); + //void testEncoding(); + private: + //QList referenceStatements; +}; + +#endif +