diff --git a/autotests/unit/file/CMakeLists.txt b/autotests/unit/file/CMakeLists.txt --- a/autotests/unit/file/CMakeLists.txt +++ b/autotests/unit/file/CMakeLists.txt @@ -41,3 +41,12 @@ LINK_LIBRARIES Qt5::Test Qt5::DBus KF5::Baloo baloofilecommon ) +# +# Result Test +# +set(resultTest_SRC resulttest.cpp ../../../src/file/extractor/result.cpp) +ecm_add_test(${resultTest_SRC} + TEST_NAME "resulttest" + LINK_LIBRARIES Qt5::Test Qt5::DBus KF5::Baloo baloofilecommon +) + diff --git a/autotests/unit/file/resulttest.cpp b/autotests/unit/file/resulttest.cpp new file mode 100644 --- /dev/null +++ b/autotests/unit/file/resulttest.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2019 Alexander Stippich + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "document.h" +#include "extractor/result.h" + +#include + +#include + +using namespace Baloo; + +class Baloo::ResultTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testDocument(); + void testDocument_data(); + +}; + +struct TermData { + QVector positions; +}; + +void ResultTest::testDocument() +{ + QFETCH(KFileMetaData::Property::Property, property); + QFETCH(QVariant, value); + QFETCH(int, position); + + Result result(QStringLiteral("test"), QStringLiteral("audio/mpeg3"), + KFileMetaData::ExtractionResult::ExtractEverything); + + result.add(property, value); + + result.finish(); + + Document doc = result.document(); + + QByteArray prefix = 'X' + QByteArray::number(property) + '-'; + QCOMPARE(doc.m_terms.find(prefix + value.toString().toUtf8()).value().positions.first(), position); +} + +void ResultTest::testDocument_data() +{ + QTest::addColumn("property"); + QTest::addColumn("value"); + QTest::addColumn("position"); + + QTest::addRow("ReleaseYear_int") + << KFileMetaData::Property::ReleaseYear + << QVariant(2018) + << 0; + + QTest::addRow("Height_uint") + << KFileMetaData::Property::Height + << QVariant(50u) + << 0; + + QTest::addRow("GpsAltitude_double") + << KFileMetaData::Property::PhotoGpsAltitude + << QVariant(20.5) + << 1; + + QTest::addRow("Artist_string") + << KFileMetaData::Property::Artist + << QVariant(QStringLiteral("artist")) + << 1; +} + +QTEST_MAIN(ResultTest) + +#include "resulttest.moc" diff --git a/src/engine/document.h b/src/engine/document.h --- a/src/engine/document.h +++ b/src/engine/document.h @@ -30,6 +30,7 @@ class WriteTransaction; class TermGeneratorTest; +class ResultTest; /** * A document represents an indexed file to be stored in the Baloo engine. @@ -91,6 +92,7 @@ friend class WriteTransaction; friend class TermGeneratorTest; + friend class ResultTest; }; inline QDebug operator<<(QDebug dbg, const Document &doc) {