diff --git a/autotests/epubextractortest.cpp b/autotests/epubextractortest.cpp index c4439ed..cf074b8 100644 --- a/autotests/epubextractortest.cpp +++ b/autotests/epubextractortest.cpp @@ -1,75 +1,75 @@ /* * * Copyright (C) 2014 Vishesh Handa * * 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 "epubextractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/epubextractor.h" #include #include #include using namespace KFileMetaData; QString EPubExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void EPubExtractorTest::test() { QScopedPointer plugin(new EPubExtractor(this)); SimpleExtractionResult result(testFilePath("test.epub"), "application/epub+zip"); plugin->extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().first(), Type::Document); // We're doing a contains instead of an exact check cause the epub file contains // a ton of css and other garbage. QVERIFY(result.text().contains(QStringLiteral("This is a sample PDF file for KFileMetaData."))); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Happy Man"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Happy Publisher"))); QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("The Big Brown Bear"))); QCOMPARE(result.properties().value(Property::Subject), QVariant(QStringLiteral("Baloo KFileMetaData"))); QDateTime dt(QDate(2014, 1, 1), QTime(1, 1, 1)); dt.setTimeSpec(Qt::UTC); QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); QCOMPARE(result.properties().size(), 5); } void EPubExtractorTest::testMetaDataOnly() { QScopedPointer plugin(new EPubExtractor(this)); SimpleExtractionResult result(testFilePath("test.epub"), "application/epub+zip", ExtractionResult::ExtractMetaData); plugin->extract(&result); QVERIFY(!result.types().isEmpty()); QVERIFY(!result.properties().isEmpty()); QVERIFY(result.text().isEmpty()); } -QTEST_MAIN(EPubExtractorTest) +QTEST_GUILESS_MAIN(EPubExtractorTest) diff --git a/autotests/exiv2extractortest.cpp b/autotests/exiv2extractortest.cpp index 6193a2f..fd2cb68 100644 --- a/autotests/exiv2extractortest.cpp +++ b/autotests/exiv2extractortest.cpp @@ -1,55 +1,55 @@ /* * * Copyright (C) 2014 Vishesh Handa * * 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 "exiv2extractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/exiv2extractor.h" #include #include #include using namespace KFileMetaData; QString Exiv2ExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void Exiv2ExtractorTest::test() { QScopedPointer plugin(new Exiv2Extractor(this)); SimpleExtractionResult result(testFilePath("test.jpg"), "image/jpeg"); plugin->extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().first(), Type::Image); using namespace KFileMetaData::Property; double lat = 41.4114341666667; double lon = 2.1736409444444; QCOMPARE(result.properties().value(PhotoGpsLatitude).toDouble(), lat); QCOMPARE(result.properties().value(PhotoGpsLongitude).toDouble(), lon); QCOMPARE(result.properties().value(PhotoGpsAltitude), QVariant()); } -QTEST_MAIN(Exiv2ExtractorTest) +QTEST_GUILESS_MAIN(Exiv2ExtractorTest) diff --git a/autotests/externalextractortest.cpp b/autotests/externalextractortest.cpp index 7d157bd..e24b170 100644 --- a/autotests/externalextractortest.cpp +++ b/autotests/externalextractortest.cpp @@ -1,55 +1,55 @@ /* * * Copyright (C) 2014 Vishesh Handa * * 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 "externalextractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "externalextractor.h" #include "config-kfilemetadata.h" #include #include #include #include using namespace KFileMetaData; QString ExternalExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void ExternalExtractorTest::test() { QTemporaryFile file; file.open(); file.write("Hello"); file.close(); QScopedPointer plugin(new ExternalExtractor( testFilePath("testexternalextractor") )); SimpleExtractionResult result(file.fileName(), "application/text"); plugin->extract(&result); QCOMPARE(result.text(), QStringLiteral("Hello ")); } -QTEST_MAIN(ExternalExtractorTest) +QTEST_GUILESS_MAIN(ExternalExtractorTest) diff --git a/autotests/externalwritertest.cpp b/autotests/externalwritertest.cpp index b7ed143..9edd392 100644 --- a/autotests/externalwritertest.cpp +++ b/autotests/externalwritertest.cpp @@ -1,53 +1,53 @@ /* * * Copyright (C) 2014 Vishesh Handa * * 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 "externalwritertest.h" #include "writedata.h" #include "indexerextractortestsconfig.h" #include "externalwriter.h" #include "config-kfilemetadata.h" #include #include #include #include using namespace KFileMetaData; QString ExternalWriterTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void ExternalWriterTest::test() { QTemporaryFile file; QScopedPointer plugin( new ExternalWriter(testFilePath("testexternalwriter") )); file.open(); WriteData data(file.fileName(), "application/text"); plugin->write(data); QCOMPARE(QString(file.readAll()), QStringLiteral("{}")); } -QTEST_MAIN(ExternalWriterTest) +QTEST_GUILESS_MAIN(ExternalWriterTest) diff --git a/autotests/extractorcollectiontest.cpp b/autotests/extractorcollectiontest.cpp index dd5f396..ae9990d 100644 --- a/autotests/extractorcollectiontest.cpp +++ b/autotests/extractorcollectiontest.cpp @@ -1,45 +1,45 @@ /* * This file is part of the KDE KFileMetaData project * Copyright (C) 2014 Vishesh Handa * 2017 Igor Poboiko * * 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 #include #include #include "extractorcollection.h" #include "extractors/plaintextextractor.h" using namespace KFileMetaData; class ExtractorCollectionTest : public QObject { Q_OBJECT private Q_SLOTS: void testFetchExtractors() { ExtractorCollection collection; QVERIFY(collection.fetchExtractors("unknown/mimetype").isEmpty()); QVERIFY(!collection.fetchExtractors("text/plain").isEmpty()); } }; -QTEST_MAIN(ExtractorCollectionTest) +QTEST_GUILESS_MAIN(ExtractorCollectionTest) #include "extractorcollectiontest.moc" diff --git a/autotests/indexerextractortests.cpp b/autotests/indexerextractortests.cpp index dce6c1b..071b05a 100644 --- a/autotests/indexerextractortests.cpp +++ b/autotests/indexerextractortests.cpp @@ -1,108 +1,108 @@ /* This file is part of the Nepomuk KDE project. Copyright (C) 2013 David Edmundson Copyright (C) 2014 Vishesh Handa 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) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. 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, see . */ #include "indexerextractortests.h" #include #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/plaintextextractor.h" using namespace KFileMetaData; IndexerExtractorTests::IndexerExtractorTests(QObject* parent) : QObject(parent) { } QString IndexerExtractorTests::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void IndexerExtractorTests::benchMarkPlainTextExtractor() { PlainTextExtractor plugin(this); // generate a test file with varying number of words per line QTemporaryFile file(QStringLiteral("XXXXXX.txt")); QVERIFY(file.open()); QByteArray chunk("foo bar "); for (int line = 0; line < 10000; ++line) { for (int i = 0; i < line % 100; ++i) { file.write(chunk); } file.write("\n"); } SimpleExtractionResult result(file.fileName(), QStringLiteral("text/plain")); QBENCHMARK { plugin.extract(&result); } } void IndexerExtractorTests::testPlainTextExtractor() { QScopedPointer plugin(new PlainTextExtractor(this)); SimpleExtractionResult result(testFilePath(QStringLiteral("plain_text_file.txt")), QStringLiteral("text/plain")); plugin->extract(&result); QString content; QTextStream(&content) << "This is a text file\n" << "it is four lines long\n" << "it has 77 characters\n" << "and 17 words.\n"; QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().at(0), Type::Text); QCOMPARE(result.properties().size(), 1); QCOMPARE(result.properties().value(Property::LineCount), QVariant(4)); content.replace(QLatin1Char('\n'), QLatin1Char(' ')); QCOMPARE(result.text(), content); } void IndexerExtractorTests::testPlainTextExtractorNoPlainText() { QScopedPointer plugin(new PlainTextExtractor(this)); SimpleExtractionResult result(testFilePath(QStringLiteral("plain_text_file.txt")), QStringLiteral("text/plain"), ExtractionResult::ExtractMetaData); plugin->extract(&result); QString content; QTextStream(&content) << "This is a text file\n" << "it is four lines long\n" << "it has 77 characters\n" << "and 17 words.\n"; QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().at(0), Type::Text); QCOMPARE(result.properties().size(), 0); } -QTEST_MAIN(IndexerExtractorTests) +QTEST_GUILESS_MAIN(IndexerExtractorTests) diff --git a/autotests/mobiextractortest.cpp b/autotests/mobiextractortest.cpp index 0f1aefc..4115af9 100644 --- a/autotests/mobiextractortest.cpp +++ b/autotests/mobiextractortest.cpp @@ -1,62 +1,62 @@ /* * * Copyright (C) 2014 Vishesh Handa * * 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 "mobiextractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/epubextractor.h" #include #include #include using namespace KFileMetaData; QString MobiExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void MobiExtractorTest::test() { QScopedPointer plugin(new EPubExtractor(this, QVariantList())); SimpleExtractionResult result(testFilePath("test.mobi"), "application/epub+zip"); plugin->extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().first(), Type::Document); // We're doing a contains instead of an exact check cause the epub file contains // a ton of css and other garbage. QVERIFY(result.text().contains(QStringLiteral("This is a sample PDF file for KFileMetaData."))); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Happy Man"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Happy Publisher"))); QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("The Big Brown Bear"))); QCOMPARE(result.properties().value(Property::Subject), QVariant(QStringLiteral("Baloo KFileMetaData"))); QDateTime dt(QDate(2014, 1, 1), QTime(1, 1, 1)); dt.setTimeSpec(Qt::UTC); QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); QCOMPARE(result.properties().size(), 5); } -QTEST_MAIN(MobiExtractorTest) +QTEST_GUILESS_MAIN(MobiExtractorTest) diff --git a/autotests/odfextractortest.cpp b/autotests/odfextractortest.cpp index 1b68d3b..f74d110 100644 --- a/autotests/odfextractortest.cpp +++ b/autotests/odfextractortest.cpp @@ -1,110 +1,110 @@ /* * * Copyright (C) 2014 Vishesh Handa * Copyright (C) 2016 Christoph Cullmann * * 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 "odfextractortest.h" #include #include #include #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/odfextractor.h" using namespace KFileMetaData; QString OdfExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void OdfExtractorTest::testText() { QScopedPointer plugin(new OdfExtractor()); SimpleExtractionResult result(testFilePath(QStringLiteral("test.odt")), QStringLiteral("application/vnd.oasis.opendocument.text")); plugin->extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().at(0), Type::Document); QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("KFileMetaData Title"))); QCOMPARE(result.properties().value(Property::Subject), QVariant(QStringLiteral("KFileMetaData Subject"))); QCOMPARE(result.properties().value(Property::Keywords), QVariant(QStringLiteral("KFileMetaData keyword"))); QCOMPARE(result.properties().value(Property::Comment), QVariant(QStringLiteral("KFileMetaData comment"))); QVERIFY(result.properties().value(Property::Generator).toString().contains(QStringLiteral("LibreOffice"))); QDateTime dt(QDate(2014, 07, 01), QTime(17, 37, 40, 690)); QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); QCOMPARE(result.properties().value(Property::WordCount), QVariant(4)); QCOMPARE(result.properties().value(Property::PageCount), QVariant(1)); QCOMPARE(result.text(), QStringLiteral("Test file for KFileMetaData. ")); QCOMPARE(result.properties().size(), 8); } void OdfExtractorTest::testTextMetaDataOnly() { QScopedPointer plugin(new OdfExtractor()); SimpleExtractionResult result(testFilePath(QStringLiteral("test.odt")), QStringLiteral("application/vnd.oasis.opendocument.text"), ExtractionResult::ExtractMetaData); plugin->extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.properties().size(), 8); QVERIFY(result.text().isEmpty()); } void OdfExtractorTest::testPresentation() { QScopedPointer plugin(new OdfExtractor()); SimpleExtractionResult result(testFilePath(QStringLiteral("test.odp")), QStringLiteral("application/vnd.oasis.opendocument.presentation")); plugin->extract(&result); QCOMPARE(result.types().size(), 2); QCOMPARE(result.types().at(0), Type::Document); QCOMPARE(result.types().at(1), Type::Presentation); QVERIFY(result.properties().value(Property::Generator).toString().contains(QStringLiteral("LibreOffice"))); QDateTime dt(QDate(2014, 07, 02), QTime(10, 59, 23, 434)); QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); QCOMPARE(result.text(), QStringLiteral("KFileMetaData Pres ")); } void OdfExtractorTest::testTextMissingMetaNoCrash() { QScopedPointer plugin(new OdfExtractor()); SimpleExtractionResult result(testFilePath(QStringLiteral("test_missing_meta.odt")), QStringLiteral("application/vnd.oasis.opendocument.text")); plugin->extract(&result); } void OdfExtractorTest::testTextMissingContentNoCrash() { QScopedPointer plugin(new OdfExtractor()); SimpleExtractionResult result(testFilePath(QStringLiteral("test_missing_content.odt")), QStringLiteral("application/vnd.oasis.opendocument.text")); plugin->extract(&result); } -QTEST_MAIN(OdfExtractorTest) +QTEST_GUILESS_MAIN(OdfExtractorTest) diff --git a/autotests/office2007extractortest.cpp b/autotests/office2007extractortest.cpp index 50a2403..a1cd778 100644 --- a/autotests/office2007extractortest.cpp +++ b/autotests/office2007extractortest.cpp @@ -1,77 +1,77 @@ /* * * Copyright (C) 2014 Vishesh Handa * * 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 "office2007extractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/office2007extractor.h" #include #include #include using namespace KFileMetaData; QString Office2007ExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void Office2007ExtractorTest::test() { QScopedPointer plugin(new Office2007Extractor(this)); SimpleExtractionResult result(testFilePath(QStringLiteral("test_libreoffice.docx")), QStringLiteral("application/vnd.openxmlformats-officedocument.wordprocessingml.document")); plugin->extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().at(0), Type::Document); QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("KFileMetaData Title"))); QCOMPARE(result.properties().value(Property::Subject), QVariant(QStringLiteral("KFileMetaData Subject"))); QCOMPARE(result.properties().value(Property::Keywords), QVariant(QStringLiteral("KFileMetaData keyword"))); QCOMPARE(result.properties().value(Property::Comment), QVariant(QStringLiteral("KFileMetaData comment"))); QCOMPARE(result.properties().value(Property::Langauge), QVariant(QStringLiteral("en-US"))); QVERIFY(result.properties().value(Property::Generator).toString().contains(QStringLiteral("LibreOffice"))); QDateTime dt(QDate(2014, 07, 01), QTime(17, 37, 40)); dt.setTimeSpec(Qt::UTC); QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); QCOMPARE(result.properties().size(), 7); QCOMPARE(result.text(), QStringLiteral("Test file for KFileMetaData. ")); } void Office2007ExtractorTest::testMetaDataOnly() { QScopedPointer plugin(new Office2007Extractor(this)); SimpleExtractionResult result(testFilePath(QStringLiteral("test_libreoffice.docx")), QStringLiteral("application/vnd.openxmlformats-officedocument.wordprocessingml.document"), ExtractionResult::ExtractMetaData); plugin->extract(&result); QVERIFY(!result.types().isEmpty()); QVERIFY(!result.properties().isEmpty()); QVERIFY(result.text().isEmpty()); } -QTEST_MAIN(Office2007ExtractorTest) +QTEST_GUILESS_MAIN(Office2007ExtractorTest) diff --git a/autotests/popplerextractortest.cpp b/autotests/popplerextractortest.cpp index e3eead1..60b57d3 100644 --- a/autotests/popplerextractortest.cpp +++ b/autotests/popplerextractortest.cpp @@ -1,73 +1,73 @@ /* * * Copyright (C) 2014 Vishesh Handa * * 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 "popplerextractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/popplerextractor.h" #include #include #include using namespace KFileMetaData; QString PopplerExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void PopplerExtractorTest::test() { QScopedPointer plugin(new PopplerExtractor(this)); SimpleExtractionResult result(testFilePath("test.pdf"), "application/pdf"); plugin->extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().first(), Type::Document); QCOMPARE(result.text(), QStringLiteral("This is a sample PDF file for KFileMetaData. ")); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Happy Man"))); QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("The Big Brown Bear"))); QCOMPARE(result.properties().value(Property::Subject), QVariant(QStringLiteral("PDF Metadata"))); QCOMPARE(result.properties().value(Property::Generator), QVariant(QStringLiteral("LibreOffice 4.2"))); QDateTime dt(QDate(2014, 07, 01), QTime(13, 38, 50)); dt.setTimeSpec(Qt::UTC); QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); QCOMPARE(result.properties().size(), 5); } void PopplerExtractorTest::testMetaDataOnly() { QScopedPointer plugin(new PopplerExtractor(this)); SimpleExtractionResult result(testFilePath("test.pdf"), "application/pdf", ExtractionResult::ExtractMetaData); plugin->extract(&result); QCOMPARE(result.types().size(), 1); QVERIFY(result.text().isEmpty()); QCOMPARE(result.properties().size(), 5); } -QTEST_MAIN(PopplerExtractorTest) +QTEST_GUILESS_MAIN(PopplerExtractorTest) diff --git a/autotests/propertyinfotest.cpp b/autotests/propertyinfotest.cpp index 4d5beeb..ae8b1b8 100644 --- a/autotests/propertyinfotest.cpp +++ b/autotests/propertyinfotest.cpp @@ -1,48 +1,48 @@ /* * This file is part of the KDE KFileMetaData project * Copyright (C) 2014 Vishesh Handa * * 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 "propertyinfotest.h" #include "propertyinfo.h" #include using namespace KFileMetaData; void PropertyInfoTest::testNameIdMapping() { // The +1 is to avoid the Empty Property int i = static_cast(Property::FirstProperty) + 1; int e = static_cast(Property::LastProperty); for (; i <= e; i++) { Property::Property p = static_cast(i); PropertyInfo pi(p); // qDebug() << pi.name(); QCOMPARE(pi.property(), p); QVERIFY(!pi.name().isEmpty()); QVERIFY(!pi.displayName().isEmpty()); PropertyInfo pi2 = PropertyInfo::fromName(pi.name()); QCOMPARE(pi2.property(), p); } } -QTEST_MAIN(PropertyInfoTest) +QTEST_GUILESS_MAIN(PropertyInfoTest) diff --git a/autotests/taglibextractortest.cpp b/autotests/taglibextractortest.cpp index 8dea7f0..4f4216a 100644 --- a/autotests/taglibextractortest.cpp +++ b/autotests/taglibextractortest.cpp @@ -1,151 +1,151 @@ /* * TagLibExtractor tests. * * Copyright (C) 2015 Juan Palacios * * 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 "taglibextractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/taglibextractor.h" #include #include #include using namespace KFileMetaData; QString TagLibExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void TagLibExtractorTest::test() { QScopedPointer plugin(new TagLibExtractor(this)); SimpleExtractionResult resultOpus(testFilePath("test.opus"), "audio/opus"); plugin->extract(&resultOpus); QCOMPARE(resultOpus.types().size(), 1); QCOMPARE(resultOpus.types().first(), Type::Audio); QCOMPARE(resultOpus.properties().value(Property::Title), QVariant(QStringLiteral("Title"))); QCOMPARE(resultOpus.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); QCOMPARE(resultOpus.properties().value(Property::Album), QVariant(QStringLiteral("Test"))); QCOMPARE(resultOpus.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(resultOpus.properties().value(Property::Genre), QVariant(QStringLiteral("Genre"))); QCOMPARE(resultOpus.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); QCOMPARE(resultOpus.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(resultOpus.properties().value(Property::TrackNumber).toInt(), 1); QCOMPARE(resultOpus.properties().value(Property::ReleaseYear).toInt(), 2015); QCOMPARE(resultOpus.properties().value(Property::Channels).toInt(), 1); QCOMPARE(resultOpus.properties().value(Property::DiscNumber).toInt(), 1); SimpleExtractionResult resultFlac(testFilePath("test.flac"), "audio/flac"); plugin->extract(&resultFlac); QCOMPARE(resultFlac.types().size(), 1); QCOMPARE(resultFlac.types().first(), Type::Audio); QCOMPARE(resultFlac.properties().value(Property::Title), QVariant(QStringLiteral("Title"))); QCOMPARE(resultFlac.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); QCOMPARE(resultFlac.properties().value(Property::Album), QVariant(QStringLiteral("Test"))); QCOMPARE(resultFlac.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(resultFlac.properties().value(Property::Genre), QVariant(QStringLiteral("Genre"))); QCOMPARE(resultFlac.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); QCOMPARE(resultFlac.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(resultFlac.properties().value(Property::TrackNumber).toInt(), 1); QCOMPARE(resultFlac.properties().value(Property::ReleaseYear).toInt(), 2015); QCOMPARE(resultFlac.properties().value(Property::Channels).toInt(), 1); QCOMPARE(resultFlac.properties().value(Property::DiscNumber).toInt(), 1); SimpleExtractionResult resultOgg(testFilePath("test.ogg"), "audio/ogg"); plugin->extract(&resultOgg); QCOMPARE(resultOgg.types().size(), 1); QCOMPARE(resultOgg.types().first(), Type::Audio); QCOMPARE(resultOgg.properties().value(Property::Title), QVariant(QStringLiteral("Title"))); QCOMPARE(resultOgg.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); QCOMPARE(resultOgg.properties().value(Property::Album), QVariant(QStringLiteral("Test"))); QCOMPARE(resultOgg.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(resultOgg.properties().value(Property::Genre), QVariant(QStringLiteral("Genre"))); QCOMPARE(resultOgg.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); QCOMPARE(resultOgg.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(resultOgg.properties().value(Property::TrackNumber).toInt(), 1); QCOMPARE(resultOgg.properties().value(Property::ReleaseYear).toInt(), 2015); QCOMPARE(resultOgg.properties().value(Property::Channels).toInt(), 1); QCOMPARE(resultOgg.properties().value(Property::DiscNumber).toInt(), 1); SimpleExtractionResult resultMp3(testFilePath("test.mp3"), "audio/mpeg"); plugin->extract(&resultMp3); QCOMPARE(resultMp3.types().size(), 1); QCOMPARE(resultMp3.types().first(), Type::Audio); QCOMPARE(resultMp3.properties().value(Property::Title), QVariant(QStringLiteral("Title"))); QCOMPARE(resultMp3.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); QCOMPARE(resultMp3.properties().value(Property::Album), QVariant(QStringLiteral("Test"))); QCOMPARE(resultMp3.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(resultMp3.properties().value(Property::Genre), QVariant(QStringLiteral("Genre"))); QCOMPARE(resultMp3.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); QCOMPARE(resultMp3.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(resultMp3.properties().value(Property::TrackNumber).toInt(), 1); QCOMPARE(resultMp3.properties().value(Property::ReleaseYear).toInt(), 2015); QCOMPARE(resultMp3.properties().value(Property::Channels).toInt(), 1); QCOMPARE(resultMp3.properties().value(Property::DiscNumber).toInt(), 1); SimpleExtractionResult resultMpc(testFilePath("test.mpc"), "audio/x-musepack"); plugin->extract(&resultMpc); QCOMPARE(resultMpc.types().size(), 1); QCOMPARE(resultMpc.types().first(), Type::Audio); QCOMPARE(resultMpc.properties().value(Property::Title), QVariant(QStringLiteral("Title"))); QCOMPARE(resultMpc.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); QCOMPARE(resultMpc.properties().value(Property::Album), QVariant(QStringLiteral("Test"))); QCOMPARE(resultMpc.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(resultMpc.properties().value(Property::Genre), QVariant(QStringLiteral("Genre"))); QCOMPARE(resultMpc.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); QCOMPARE(resultMpc.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(resultMpc.properties().value(Property::TrackNumber).toInt(), 1); QCOMPARE(resultMpc.properties().value(Property::ReleaseYear).toInt(), 2015); QCOMPARE(resultMpc.properties().value(Property::Channels).toInt(), 1); QCOMPARE(resultMpc.properties().value(Property::DiscNumber).isValid(), false); SimpleExtractionResult resultMp4(testFilePath("test.m4a"), "audio/mp4"); plugin->extract(&resultMp4); QCOMPARE(resultMp4.types().size(), 1); QCOMPARE(resultMp4.types().first(), Type::Audio); QCOMPARE(resultMp4.properties().value(Property::Title), QVariant(QStringLiteral("Title"))); QCOMPARE(resultMp4.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); QCOMPARE(resultMp4.properties().value(Property::Album), QVariant(QStringLiteral("Test"))); QCOMPARE(resultMp4.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(resultMp4.properties().value(Property::Genre), QVariant(QStringLiteral("Genre"))); QCOMPARE(resultMp4.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); QCOMPARE(resultMp4.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(resultMp4.properties().value(Property::TrackNumber).toInt(), 1); QCOMPARE(resultMp4.properties().value(Property::ReleaseYear).toInt(), 2015); QCOMPARE(resultMp4.properties().value(Property::Channels).toInt(), 2); QCOMPARE(resultMp4.properties().value(Property::DiscNumber).toInt(), 1); } -QTEST_MAIN(TagLibExtractorTest) +QTEST_GUILESS_MAIN(TagLibExtractorTest) diff --git a/autotests/taglibwritertest.cpp b/autotests/taglibwritertest.cpp index 6999d20..07e50d9 100644 --- a/autotests/taglibwritertest.cpp +++ b/autotests/taglibwritertest.cpp @@ -1,59 +1,59 @@ #include "taglibwritertest.h" #include "indexerextractortestsconfig.h" #include "writers/taglibwriter.h" #include "writedata.h" #include "taglib.h" #include "fileref.h" #include #include #include #include #define TEST_FILENAME "writertest.opus" using namespace KFileMetaData; static QString t2q(const TagLib::String& t) { return QString::fromWCharArray((const wchar_t*)t.toCWString(), t.length()); } QString TagLibWriterTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } void TagLibWriterTest::initTestCase() { QFile testFile(testFilePath("test.opus")); QFile writerTestFile(testFilePath(TEST_FILENAME)); QFile::copy(testFilePath("test.opus"), testFilePath(TEST_FILENAME)); } void TagLibWriterTest::test() { QScopedPointer writerPlugin(new TagLibWriter(this)); WriteData data(testFilePath(TEST_FILENAME), "audio/opus"); data.add(Property::Title, "Title1"); data.add(Property::Artist, "Artist1"); writerPlugin->write(data); TagLib::FileRef file(testFilePath(TEST_FILENAME).toUtf8().constData(), true); TagLib::Tag* tags = file.tag(); QString extractedTitle = t2q(tags->title()); QString extractedArtist = t2q(tags->artist()); QCOMPARE(extractedTitle, QStringLiteral("Title1")); QCOMPARE(extractedArtist, QStringLiteral("Artist1")); } void TagLibWriterTest::cleanupTestCase() { QFile::remove(testFilePath(TEST_FILENAME)); } -QTEST_MAIN(TagLibWriterTest) +QTEST_GUILESS_MAIN(TagLibWriterTest)