From c8f86040f6163710aff986446766acb69d1cb92a Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Tue, 3 Dec 2013 11:23:17 +0100 Subject: Fix DocumentGallery returning encoded urls. Tracker stores url properties in encoded form, these need to be decoded before they are returned and encoded when used in queries. Cherry pick of c4a36f94bd50d0236aaa7bddbe72bc7e0fbdac4f from qt-mobility. Change-Id: I8075490d6079311b94fe1234857a69af88218dc6 Reviewed-by: Marko Mattila Reviewed-by: Christopher Adams Reviewed-by: Alex Blasche --- .../tst_qgallerytrackerschema.cpp | 95 ++++++++++++++++++++-- 1 file changed, 86 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp b/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp index 1c937ee..7d9c14e 100644 --- a/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp +++ b/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp @@ -101,6 +101,8 @@ private Q_SLOTS: void queryResponseRootItem(); void queryResponseFilter_data(); void queryResponseFilter(); + void queryResponseItemUrl_data(); + void queryResponseItemUrl(); void queryResponseValueColumnToVariant_data(); void queryResponseValueColumnToVariant(); void queryResponseValueColumnToString_data(); @@ -495,7 +497,7 @@ void tst_QGalleryTrackerSchema::prepareValidItemResponse_data() << QStringList() << (QVector() << QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559") - << QLatin1String("file:///path/to/file.ext") + << QUrl(QLatin1String("file:///path/to/file.ext")) << 0) << QVariant(QUrl(QLatin1String("file:///path/to/file.ext"))) << QVariant(QLatin1String("File")) @@ -620,7 +622,7 @@ void tst_QGalleryTrackerSchema::queryResponseRootType_data() << 1 << (QVector() << QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559") - << QLatin1String("file:///path/to/file.ext") + << QUrl(QLatin1String("file:///path/to/file.ext")) << 0) << "file::uuid:ff172362-d959-99e0-a792-0ddafdd2c559" << QVariant(QUrl(QLatin1String("file:///path/to/file.ext"))) @@ -635,7 +637,7 @@ void tst_QGalleryTrackerSchema::queryResponseRootType_data() << 1 << (QVector() << QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559") - << QLatin1String("file:///path/to/image.png") + << QUrl(QLatin1String("file:///path/to/image.png")) << 4) << "image::uuid:ff172362-d959-99e0-a792-0ddafdd2c559" << QVariant(QUrl(QLatin1String("file:///path/to/image.png"))) @@ -650,7 +652,7 @@ void tst_QGalleryTrackerSchema::queryResponseRootType_data() << 1 << (QVector() << QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559") - << QLatin1String("file:///path/to/text.txt") + << QUrl(QLatin1String("file:///path/to/text.txt")) << 7) << "text::uuid:ff172362-d959-99e0-a792-0ddafdd2c559" << QVariant(QUrl(QLatin1String("file:///path/to/text.txt"))) @@ -1728,6 +1730,21 @@ void tst_QGalleryTrackerSchema::queryResponseFilter_data() "FILTER((nie:url(?x)='http://example.com/index.html'))" "} " "GROUP BY ?x"; + } { + QGalleryFilter filter + = QDocumentGallery::url == QUrl::fromLocalFile(QString::fromUtf8("/path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg")); + + QTest::newRow("File.url == file:///path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg") + << "File" + << QString() + << QGalleryQueryRequest::AllDescendants + << filter + << "SELECT ?x nie:url(?x) rdf:type(?x) " + "WHERE {" + "{?x rdf:type nfo:FileDataObject}" + "FILTER((nie:url(?x)='file:///path/to/K%C3%A4rp%C3%A4ssieni.jpg'))" + "} " + "GROUP BY ?x"; } { QGalleryFilter filter = QDocumentGallery::filePath == QLatin1String("/path/to/file.ext"); @@ -1742,6 +1759,21 @@ void tst_QGalleryTrackerSchema::queryResponseFilter_data() "FILTER((nie:url(?x)='file:///path/to/file.ext'))" "} " "GROUP BY ?x"; + } { + QGalleryFilter filter + = QDocumentGallery::filePath == QString::fromUtf8("/path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg"); + + QTest::newRow("File.filePath == /path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg") + << "File" + << QString() + << QGalleryQueryRequest::AllDescendants + << filter + << "SELECT ?x nie:url(?x) rdf:type(?x) " + "WHERE {" + "{?x rdf:type nfo:FileDataObject}" + "FILTER((nie:url(?x)='file:///path/to/K%C3%A4rp%C3%A4ssieni.jpg'))" + "} " + "GROUP BY ?x"; } { QGalleryFilter filter = QDocumentGallery::filePath > QLatin1String("/path/to/file.ext"); @@ -2290,6 +2322,51 @@ void tst_QGalleryTrackerSchema::queryResponseFilter() QCOMPARE(arguments.sparql, sparql); } + +void tst_QGalleryTrackerSchema::queryResponseItemUrl_data() +{ + QTest::addColumn("rootType"); + QTest::addColumn("encodedUrl"); + QTest::addColumn("url"); + + QTest::newRow("File ascii") + << "File" + << QByteArray("file://path/to/file.ext") + << QUrl(QLatin1String("file://path/to/file.ext")); + + QTest::newRow("Image encoded") + << "Image" + << QByteArray("file://path/to/K%C3%A4rp%C3%A4ssieni.jpg") + << QUrl(QString::fromUtf8("file://path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg")); +} + +void tst_QGalleryTrackerSchema::queryResponseItemUrl() +{ + QFETCH(QString, rootType); + QFETCH(QByteArray, encodedUrl); + QFETCH(QUrl, url); + + QGalleryTrackerResultSetArguments arguments; + + QGalleryTrackerSchema schema(rootType); + + QCOMPARE( + schema.prepareQueryResponse( + &arguments, + this, + QGalleryQueryRequest::AllDescendants, + QString(), + QGalleryFilter(), + QStringList(), + QStringList(), + 0, + 0), + QDocumentGallery::NoError); + + QCOMPARE(arguments.valueColumns.count(), 3); + QCOMPARE(arguments.valueColumns.at(1)->toVariant(encodedUrl).toUrl(), url); +} + void tst_QGalleryTrackerSchema::queryResponseValueColumnToVariant_data() { QTest::addColumn("rootType"); @@ -2566,7 +2643,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data() << QString::fromLatin1("filePath") << (QVector() << QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559") - << QLatin1String("file:///path/to/file.ext") + << QUrl(QLatin1String("file:///path/to/file.ext")) << QLatin1String("Files")) << QVariant(QLatin1String("/path/to/file.ext")); @@ -2575,7 +2652,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data() << QString::fromLatin1("path") << (QVector() << QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559") - << QLatin1String("file:///path/to/file.ext") + << QUrl(QLatin1String("file:///path/to/file.ext")) << QLatin1String("Files")) << QVariant(QLatin1String("/path/to")); @@ -2584,7 +2661,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data() << QString::fromLatin1("path") << (QVector() << QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559") - << QLatin1String("file:///path/to/") + << QUrl(QLatin1String("file:///path/to/")) << QLatin1String("Files")) << QVariant(QLatin1String("/path/to")); @@ -2593,7 +2670,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data() << QString::fromLatin1("fileExtension") << (QVector() << QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559") - << QLatin1String("file:///path/to/file.ext") + << QUrl(QLatin1String("file:///path/to/file.ext")) << QLatin1String("Files")) << QVariant(QLatin1String("ext")); @@ -2603,7 +2680,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data() << QString::fromLatin1("fileExtension") << (QVector() << QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559") - << QLatin1String("file:///path/to") + << QUrl(QLatin1String("file:///path/to")) << QLatin1String("Files")) << QVariant(); } -- cgit v1.2.3