diff --git a/autotests/epubextractortest.cpp b/autotests/epubextractortest.cpp index 064c7fa..23ec35d 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)); + EPubExtractor plugin{this}; SimpleExtractionResult result(testFilePath("test.epub"), "application/epub+zip"); - plugin->extract(&result); + plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().constFirst(), 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)); + EPubExtractor plugin{this}; SimpleExtractionResult result(testFilePath("test.epub"), "application/epub+zip", ExtractionResult::ExtractMetaData); - plugin->extract(&result); + plugin.extract(&result); QVERIFY(!result.types().isEmpty()); QVERIFY(!result.properties().isEmpty()); QVERIFY(result.text().isEmpty()); } QTEST_GUILESS_MAIN(EPubExtractorTest) diff --git a/autotests/exiv2extractortest.cpp b/autotests/exiv2extractortest.cpp index 9cec7ab..1688a42 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)); + Exiv2Extractor plugin{this}; SimpleExtractionResult result(testFilePath("test.jpg"), "image/jpeg"); - plugin->extract(&result); + plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().constFirst(), 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_GUILESS_MAIN(Exiv2ExtractorTest) diff --git a/autotests/externalextractortest.cpp b/autotests/externalextractortest.cpp index 7e8661d..9928ec0 100644 --- a/autotests/externalextractortest.cpp +++ b/autotests/externalextractortest.cpp @@ -1,55 +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 "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_CONFIGURED_FILES_PATH) + QDir::separator() + fileName; } void ExternalExtractorTest::test() { QTemporaryFile file; file.open(); file.write("Hello"); file.close(); - QScopedPointer plugin(new ExternalExtractor( - testFilePath("testexternalextractor") - )); + ExternalExtractor plugin{testFilePath("testexternalextractor")}; SimpleExtractionResult result(file.fileName(), "application/text"); - plugin->extract(&result); + plugin.extract(&result); QCOMPARE(result.text(), QStringLiteral("Hello ")); } QTEST_GUILESS_MAIN(ExternalExtractorTest) diff --git a/autotests/externalwritertest.cpp b/autotests/externalwritertest.cpp index 65f6bbf..bd68ee0 100644 --- a/autotests/externalwritertest.cpp +++ b/autotests/externalwritertest.cpp @@ -1,53 +1,50 @@ /* * * 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_CONFIGURED_FILES_PATH) + QDir::separator() + fileName; } void ExternalWriterTest::test() { QTemporaryFile file; - QScopedPointer plugin( - new ExternalWriter(testFilePath("testexternalwriter") - )); - + ExternalWriter plugin{testFilePath("testexternalwriter")}; file.open(); WriteData data(file.fileName(), "application/text"); - plugin->write(data); + plugin.write(data); QCOMPARE(QString(file.readAll()), QStringLiteral("{}")); } QTEST_GUILESS_MAIN(ExternalWriterTest) diff --git a/autotests/indexerextractortests.cpp b/autotests/indexerextractortests.cpp index 071b05a..c2ad4bb 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)); + PlainTextExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("plain_text_file.txt")), QStringLiteral("text/plain")); - plugin->extract(&result); + 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)); + PlainTextExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("plain_text_file.txt")), QStringLiteral("text/plain"), ExtractionResult::ExtractMetaData); - plugin->extract(&result); + 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_GUILESS_MAIN(IndexerExtractorTests) diff --git a/autotests/mobiextractortest.cpp b/autotests/mobiextractortest.cpp index 4115af9..6a74f0b 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())); + EPubExtractor plugin{this}; SimpleExtractionResult result(testFilePath("test.mobi"), "application/epub+zip"); - plugin->extract(&result); + 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_GUILESS_MAIN(MobiExtractorTest) diff --git a/autotests/odfextractortest.cpp b/autotests/odfextractortest.cpp index f74d110..34b29c7 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()); + OdfExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test.odt")), QStringLiteral("application/vnd.oasis.opendocument.text")); - plugin->extract(&result); + 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()); + OdfExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test.odt")), QStringLiteral("application/vnd.oasis.opendocument.text"), ExtractionResult::ExtractMetaData); - plugin->extract(&result); + plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.properties().size(), 8); QVERIFY(result.text().isEmpty()); } void OdfExtractorTest::testPresentation() { - QScopedPointer plugin(new OdfExtractor()); + OdfExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test.odp")), QStringLiteral("application/vnd.oasis.opendocument.presentation")); - plugin->extract(&result); + 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()); + OdfExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test_missing_meta.odt")), QStringLiteral("application/vnd.oasis.opendocument.text")); - plugin->extract(&result); + plugin.extract(&result); } void OdfExtractorTest::testTextMissingContentNoCrash() { - QScopedPointer plugin(new OdfExtractor()); + OdfExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test_missing_content.odt")), QStringLiteral("application/vnd.oasis.opendocument.text")); - plugin->extract(&result); + plugin.extract(&result); } QTEST_GUILESS_MAIN(OdfExtractorTest) diff --git a/autotests/office2007extractortest.cpp b/autotests/office2007extractortest.cpp index a1cd778..938e33e 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)); + Office2007Extractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test_libreoffice.docx")), QStringLiteral("application/vnd.openxmlformats-officedocument.wordprocessingml.document")); - plugin->extract(&result); + 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)); + Office2007Extractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test_libreoffice.docx")), QStringLiteral("application/vnd.openxmlformats-officedocument.wordprocessingml.document"), ExtractionResult::ExtractMetaData); - plugin->extract(&result); + plugin.extract(&result); QVERIFY(!result.types().isEmpty()); QVERIFY(!result.properties().isEmpty()); QVERIFY(result.text().isEmpty()); } QTEST_GUILESS_MAIN(Office2007ExtractorTest) diff --git a/autotests/popplerextractortest.cpp b/autotests/popplerextractortest.cpp index da29c24..d47801e 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)); + PopplerExtractor plugin{this}; SimpleExtractionResult result(testFilePath("test.pdf"), "application/pdf"); - plugin->extract(&result); + plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().constFirst(), 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)); + PopplerExtractor plugin{this}; SimpleExtractionResult result(testFilePath("test.pdf"), "application/pdf", ExtractionResult::ExtractMetaData); - plugin->extract(&result); + plugin.extract(&result); QCOMPARE(result.types().size(), 1); QVERIFY(result.text().isEmpty()); QCOMPARE(result.properties().size(), 5); } QTEST_GUILESS_MAIN(PopplerExtractorTest) diff --git a/autotests/taglibextractortest.cpp b/autotests/taglibextractortest.cpp index c4a8f55..8798cf4 100644 --- a/autotests/taglibextractortest.cpp +++ b/autotests/taglibextractortest.cpp @@ -1,316 +1,316 @@ /* * 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 "propertyinfo.h" //TODO: use QTESTFINDDATA and remove this #include "indexerextractortestsconfig.h" #include "extractors/taglibextractor.h" #include #include #include Q_DECLARE_METATYPE(KFileMetaData::Property::Property) using namespace KFileMetaData; QString TagLibExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; } const QStringList TagLibExtractorTest::propertyEnumNames(const QList& keys) const { QStringList result; for (auto key : keys) { result.append(PropertyInfo(key).name()); } return result; } void TagLibExtractorTest::test() { - QScopedPointer plugin(new TagLibExtractor(this)); + TagLibExtractor plugin{this}; SimpleExtractionResult resultOpus(testFilePath("test.opus"), "audio/opus"); - plugin->extract(&resultOpus); + plugin.extract(&resultOpus); QCOMPARE(resultOpus.types().size(), 1); QCOMPARE(resultOpus.types().constFirst(), 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("Album"))); 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::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(resultOpus.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(resultOpus.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); QCOMPARE(resultOpus.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); QCOMPARE(resultOpus.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); QCOMPARE(resultOpus.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); QCOMPARE(resultOpus.properties().value(Property::Langauge), QVariant(QStringLiteral("Language"))); QCOMPARE(resultOpus.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(resultOpus.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); QCOMPARE(resultOpus.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(resultOpus.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(resultOpus.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(resultOpus.properties().value(Property::License), QVariant(QStringLiteral("License"))); QCOMPARE(resultOpus.properties().value(Property::Opus).toInt(), 1); 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); + plugin.extract(&resultFlac); QCOMPARE(resultFlac.types().size(), 1); QCOMPARE(resultFlac.types().constFirst(), 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("Album"))); 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::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(resultFlac.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(resultFlac.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); QCOMPARE(resultFlac.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); QCOMPARE(resultFlac.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); QCOMPARE(resultFlac.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); QCOMPARE(resultFlac.properties().value(Property::Langauge), QVariant(QStringLiteral("Language"))); QCOMPARE(resultFlac.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(resultFlac.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); QCOMPARE(resultFlac.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(resultFlac.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(resultFlac.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(resultFlac.properties().value(Property::License), QVariant(QStringLiteral("License"))); QCOMPARE(resultFlac.properties().value(Property::Opus).toInt(), 1); 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); + plugin.extract(&resultOgg); QCOMPARE(resultOgg.types().size(), 1); QCOMPARE(resultOgg.types().constFirst(), 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("Album"))); 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::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(resultOgg.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(resultOgg.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); QCOMPARE(resultOgg.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); QCOMPARE(resultOgg.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); QCOMPARE(resultOgg.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); QCOMPARE(resultOgg.properties().value(Property::Langauge), QVariant(QStringLiteral("Language"))); QCOMPARE(resultOgg.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(resultOgg.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); QCOMPARE(resultOgg.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(resultOgg.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(resultOgg.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(resultOgg.properties().value(Property::License), QVariant(QStringLiteral("License"))); QCOMPARE(resultOgg.properties().value(Property::Opus).toInt(), 1); 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); + plugin.extract(&resultMp3); QCOMPARE(resultMp3.types().size(), 1); QCOMPARE(resultMp3.types().constFirst(), 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("Album"))); 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::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(resultMp3.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(resultMp3.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(resultMp3.properties().value(Property::Langauge), QVariant(QStringLiteral("Language"))); QCOMPARE(resultMp3.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); 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); + plugin.extract(&resultMpc); QCOMPARE(resultMpc.types().size(), 1); QCOMPARE(resultMpc.types().constFirst(), 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("Album"))); 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::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(resultMpc.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); QCOMPARE(resultMpc.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); QCOMPARE(resultMpc.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); QCOMPARE(resultMpc.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); QCOMPARE(resultMpc.properties().value(Property::Langauge), QVariant(QStringLiteral("Language"))); QCOMPARE(resultMpc.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(resultMpc.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); QCOMPARE(resultMpc.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(resultMpc.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(resultMpc.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(resultMpc.properties().value(Property::License), QVariant(QStringLiteral("License"))); 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); + plugin.extract(&resultMp4); QCOMPARE(resultMp4.types().size(), 1); QCOMPARE(resultMp4.types().constFirst(), 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("Album"))); 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::Copyright), QVariant(QStringLiteral("Copyright"))); 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); } void TagLibExtractorTest::testNoMetadata_data() { const auto expectedKeys = QList{ Property::BitRate, Property::Channels, Property::Duration, Property::SampleRate, }; QTest::addColumn("path"); QTest::addColumn("mimeType"); QTest::addColumn>("expectedKeys"); QTest::addColumn("failMessage"); QTest::addRow("mp3") << QFINDTESTDATA("samplefiles/no-meta/test.mp3") << QStringLiteral("audio/mp3") << expectedKeys << QString() ; QTest::addRow("m4a") << QFINDTESTDATA("samplefiles/no-meta/test.m4a") << QStringLiteral("audio/mp4") << expectedKeys << QString() ; QTest::addRow("flac") << QFINDTESTDATA("samplefiles/no-meta/test.flac") << QStringLiteral("audio/flac") << expectedKeys << QString() ; QTest::addRow("opus") << QFINDTESTDATA("samplefiles/no-meta/test.opus") << QStringLiteral("audio/opus") << expectedKeys << QString() ; QTest::addRow("ogg") << QFINDTESTDATA("samplefiles/no-meta/test.ogg") << QStringLiteral("audio/ogg") << expectedKeys << QString() ; QTest::addRow("mpc") << QFINDTESTDATA("samplefiles/no-meta/test.mpc") << QStringLiteral("audio/x-musepack") << expectedKeys << QString() ; } void TagLibExtractorTest::testNoMetadata() { QFETCH(QString, path); QFETCH(QString, mimeType); QFETCH(QList, expectedKeys); QFETCH(QString, failMessage); TagLibExtractor plugin{this}; SimpleExtractionResult extracted(path, mimeType); plugin.extract(&extracted); const auto resultList = extracted.properties(); const auto resultKeys = resultList.uniqueKeys(); const auto excessKeys = resultKeys.toSet() - expectedKeys.toSet(); const auto missingKeys = expectedKeys.toSet() - resultKeys.toSet(); if (excessKeys.size()) { const auto propNames = propertyEnumNames(excessKeys.toList()).join(QLatin1String(", ")); if (failMessage.isEmpty()) { const auto message = QStringLiteral("Excess properties: %1").arg(propNames); QWARN(qPrintable(message)); } else { QEXPECT_FAIL("", qPrintable(QStringLiteral("%1: %2").arg(failMessage).arg(propNames)), Continue); } } else if (missingKeys.size()) { const auto message = QStringLiteral("Missing properties: %1") .arg(propertyEnumNames(missingKeys.toList()).join(QLatin1String(", "))); QWARN(qPrintable(message)); } QCOMPARE(resultKeys, expectedKeys); if (!failMessage.isEmpty()) { auto excessKeys = resultKeys.toSet() - expectedKeys.toSet(); const auto message = QStringLiteral("%1: %2") .arg(failMessage) .arg(propertyEnumNames(excessKeys.toList()).join(QLatin1String(", "))); QEXPECT_FAIL("", qPrintable(message), Continue); } QCOMPARE(resultKeys, expectedKeys); } QTEST_GUILESS_MAIN(TagLibExtractorTest) diff --git a/autotests/taglibwritertest.cpp b/autotests/taglibwritertest.cpp index 07e50d9..dfe92af 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)); + TagLibWriter writerPlugin{this}; WriteData data(testFilePath(TEST_FILENAME), "audio/opus"); data.add(Property::Title, "Title1"); data.add(Property::Artist, "Artist1"); - writerPlugin->write(data); + 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_GUILESS_MAIN(TagLibWriterTest)