diff --git a/autotests/epubextractortest.cpp b/autotests/epubextractortest.cpp index 3ed52ec..01a47cb 100644 --- a/autotests/epubextractortest.cpp +++ b/autotests/epubextractortest.cpp @@ -1,77 +1,84 @@ /* * * 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 "mimeutils.h" #include #include #include +#include using namespace KFileMetaData; QString EPubExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; } void EPubExtractorTest::test() { EPubExtractor plugin{this}; - SimpleExtractionResult result(testFilePath("test.epub"), "application/epub+zip"); + QString fileName = testFilePath(QStringLiteral("test.epub")); + QMimeDatabase mimeDb; + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); + QVERIFY(plugin.mimetypes().contains(mimeType)); + + SimpleExtractionResult result(fileName, mimeType); 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"))); QCOMPARE(result.properties().value(Property::Description), QVariant(QStringLiteral("Honey"))); 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().value(Property::ReleaseYear), QVariant(2014)); QCOMPARE(result.properties().size(), 7); } void EPubExtractorTest::testMetaDataOnly() { EPubExtractor plugin{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_GUILESS_MAIN(EPubExtractorTest) diff --git a/autotests/exiv2extractortest.cpp b/autotests/exiv2extractortest.cpp index 58efce8..5a344f8 100644 --- a/autotests/exiv2extractortest.cpp +++ b/autotests/exiv2extractortest.cpp @@ -1,81 +1,88 @@ /* * * 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 "mimeutils.h" #include #include #include +#include using namespace KFileMetaData; using namespace KFileMetaData::Property; QString Exiv2ExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; } void Exiv2ExtractorTest::test() { Exiv2Extractor plugin{this}; - SimpleExtractionResult result(testFilePath("test.jpg"), "image/jpeg"); + QString fileName = testFilePath(QStringLiteral("test.jpg")); + QMimeDatabase mimeDb; + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); + QVERIFY(plugin.mimetypes().contains(mimeType)); + + SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().constFirst(), Type::Image); QCOMPARE(result.properties().value(Artist).toString(), QStringLiteral("Artist")); QCOMPARE(result.properties().value(Description).toString(), QStringLiteral("Description")); QCOMPARE(result.properties().value(Copyright).toString(), QStringLiteral("Copyright")); QCOMPARE(result.properties().value(Generator).toString(), QStringLiteral("digiKam-5.9.0")); } void Exiv2ExtractorTest::testGPS() { Exiv2Extractor plugin{this}; SimpleExtractionResult result(testFilePath("test.jpg"), "image/jpeg"); plugin.extract(&result); QCOMPARE(result.properties().value(PhotoGpsLatitude).toDouble(), 41.411); QCOMPARE(result.properties().value(PhotoGpsLongitude).toDouble(), 2.173); QCOMPARE(result.properties().value(PhotoGpsAltitude).toDouble(), 12.2); SimpleExtractionResult resultEmpty(testFilePath("test_no_gps.jpg"), "image/jpeg"); plugin.extract(&resultEmpty); QVERIFY(!resultEmpty.properties().contains(PhotoGpsLatitude)); QVERIFY(!resultEmpty.properties().contains(PhotoGpsLongitude)); QVERIFY(!resultEmpty.properties().contains(PhotoGpsAltitude)); SimpleExtractionResult resultZero(testFilePath("test_zero_gps.jpg"), "image/jpeg"); plugin.extract(&resultZero); QVERIFY(resultZero.properties().contains(PhotoGpsLatitude)); QVERIFY(resultZero.properties().contains(PhotoGpsLongitude)); QVERIFY(resultZero.properties().contains(PhotoGpsAltitude)); QCOMPARE(resultZero.properties().value(PhotoGpsLatitude).toDouble(), 0.0); QCOMPARE(resultZero.properties().value(PhotoGpsLongitude).toDouble(), 0.0); QCOMPARE(resultZero.properties().value(PhotoGpsAltitude).toDouble(), 0.0); } QTEST_GUILESS_MAIN(Exiv2ExtractorTest) diff --git a/autotests/odfextractortest.cpp b/autotests/odfextractortest.cpp index c5c8335..ce5b066 100644 --- a/autotests/odfextractortest.cpp +++ b/autotests/odfextractortest.cpp @@ -1,110 +1,119 @@ /* * * 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" +#include "mimeutils.h" using namespace KFileMetaData; QString OdfExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; } void OdfExtractorTest::testText() { OdfExtractor plugin{this}; - SimpleExtractionResult result(testFilePath(QStringLiteral("test.odt")), QStringLiteral("application/vnd.oasis.opendocument.text")); + QString fileName = testFilePath(QStringLiteral("test.odt")); + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); + QVERIFY(plugin.mimetypes().contains(mimeType)); + + SimpleExtractionResult result(fileName, mimeType); 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::Description), QVariant(QStringLiteral("KFileMetaData description"))); 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() { OdfExtractor plugin{this}; 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() { OdfExtractor plugin{this}; - SimpleExtractionResult result(testFilePath(QStringLiteral("test.odp")), QStringLiteral("application/vnd.oasis.opendocument.presentation")); + QString fileName = testFilePath(QStringLiteral("test.odp")); + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); + QVERIFY(plugin.mimetypes().contains(mimeType)); + + SimpleExtractionResult result(fileName, mimeType); 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() { OdfExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test_missing_meta.odt")), QStringLiteral("application/vnd.oasis.opendocument.text")); plugin.extract(&result); } void OdfExtractorTest::testTextMissingContentNoCrash() { OdfExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test_missing_content.odt")), QStringLiteral("application/vnd.oasis.opendocument.text")); plugin.extract(&result); } QTEST_GUILESS_MAIN(OdfExtractorTest) diff --git a/autotests/odfextractortest.h b/autotests/odfextractortest.h index 89642ce..1177b1e 100644 --- a/autotests/odfextractortest.h +++ b/autotests/odfextractortest.h @@ -1,43 +1,47 @@ /* * * 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 * */ #ifndef ODFEXTRACTORTEST_H #define ODFEXTRACTORTEST_H #include +#include class OdfExtractorTest : public QObject { Q_OBJECT private: QString testFilePath(const QString& fileName) const; private Q_SLOTS: void testText(); void testTextMetaDataOnly(); void testPresentation(); void testTextMissingMetaNoCrash(); void testTextMissingContentNoCrash(); + +private: + QMimeDatabase mimeDb; }; #endif // ODFEXTRACTORTEST_H diff --git a/autotests/office2007extractortest.cpp b/autotests/office2007extractortest.cpp index aed28b9..9cc3526 100644 --- a/autotests/office2007extractortest.cpp +++ b/autotests/office2007extractortest.cpp @@ -1,77 +1,84 @@ /* * * 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 "mimeutils.h" #include #include #include +#include using namespace KFileMetaData; QString Office2007ExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; } void Office2007ExtractorTest::test() { Office2007Extractor plugin{this}; - SimpleExtractionResult result(testFilePath(QStringLiteral("test_libreoffice.docx")), QStringLiteral("application/vnd.openxmlformats-officedocument.wordprocessingml.document")); + QString fileName = testFilePath(QStringLiteral("test_libreoffice.docx")); + QMimeDatabase mimeDb; + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); + QVERIFY(plugin.mimetypes().contains(mimeType)); + + SimpleExtractionResult result(fileName, mimeType); 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::Description), QVariant(QStringLiteral("KFileMetaData comment"))); QCOMPARE(result.properties().value(Property::Language), 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() { Office2007Extractor plugin{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_GUILESS_MAIN(Office2007ExtractorTest) diff --git a/autotests/popplerextractortest.cpp b/autotests/popplerextractortest.cpp index 85c0bed..2ad8fd7 100644 --- a/autotests/popplerextractortest.cpp +++ b/autotests/popplerextractortest.cpp @@ -1,73 +1,80 @@ /* * * 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 "mimeutils.h" #include #include #include +#include using namespace KFileMetaData; QString PopplerExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; } void PopplerExtractorTest::test() { PopplerExtractor plugin{this}; - SimpleExtractionResult result(testFilePath("test.pdf"), "application/pdf"); + QString fileName = testFilePath(QStringLiteral("test.pdf")); + QMimeDatabase mimeDb; + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); + QVERIFY(plugin.mimetypes().contains(mimeType)); + + SimpleExtractionResult result(fileName, mimeType); 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() { PopplerExtractor plugin{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_GUILESS_MAIN(PopplerExtractorTest) diff --git a/autotests/postscriptdscextractortest.cpp b/autotests/postscriptdscextractortest.cpp index d6a2cf7..bee076a 100644 --- a/autotests/postscriptdscextractortest.cpp +++ b/autotests/postscriptdscextractortest.cpp @@ -1,73 +1,82 @@ /* * Copyright (C) 2018 Stefan Brüns * * 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 "postscriptdscextractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/postscriptdscextractor.h" +#include "mimeutils.h" #include using namespace KFileMetaData; QString PostscriptDscExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; } void PostscriptDscExtractorTest::testPS() { DscExtractor plugin{this}; - SimpleExtractionResult result(testFilePath("test.ps"), "application/postscript"); + QString fileName = testFilePath(QStringLiteral("test.ps")); + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); + QVERIFY(plugin.mimetypes().contains(mimeType)); + + SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().constFirst(), Type::Document); QCOMPARE(result.properties().value(Property::Title).toString(), QStringLiteral("The Big Brown Bear")); QCOMPARE(result.properties().value(Property::PageCount).toInt(), 2); QDateTime dt(QDate(2018, 10, 28), QTime(21, 13, 39)); dt.setOffsetFromUtc(+3600); QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); QCOMPARE(result.properties().size(), 3); } void PostscriptDscExtractorTest::testEPS() { DscExtractor plugin{this}; - SimpleExtractionResult result(testFilePath("test.eps"), "image/x-eps"); + QString fileName = testFilePath(QStringLiteral("test.eps")); + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); + QVERIFY(plugin.mimetypes().contains(mimeType)); + + SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().constFirst(), Type::Image); QCOMPARE(result.properties().value(Property::Title).toString(), QStringLiteral("The Big Brown Bear")); QCOMPARE(result.properties().value(Property::PageCount).toInt(), 1); QDateTime dt(QDate(2018, 10, 28), QTime(21, 13, 39)); dt.setOffsetFromUtc(-5400); QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); QCOMPARE(result.properties().size(), 3); } QTEST_GUILESS_MAIN(PostscriptDscExtractorTest) diff --git a/autotests/postscriptdscextractortest.h b/autotests/postscriptdscextractortest.h index 8472f4c..e55b41d 100644 --- a/autotests/postscriptdscextractortest.h +++ b/autotests/postscriptdscextractortest.h @@ -1,36 +1,39 @@ /* * Copyright (C) 2018 Stefan Brüns * * 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 * */ #ifndef POSTSCRIPTDSCEXTRACTORTEST_H #define POSTSCRIPTDSCEXTRACTORTEST_H #include +#include class PostscriptDscExtractorTest : public QObject { Q_OBJECT private: QString testFilePath(const QString& fileName) const; private Q_SLOTS: void testPS(); void testEPS(); +private: + QMimeDatabase mimeDb; }; #endif // POSTSCRIPTDSCEXTRACTORTEST_H diff --git a/autotests/xmlextractortest.cpp b/autotests/xmlextractortest.cpp index 84c9ba4..4a1f43c 100644 --- a/autotests/xmlextractortest.cpp +++ b/autotests/xmlextractortest.cpp @@ -1,158 +1,164 @@ /* Copyright (C) 2018 Stefan Brüns 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 "xmlextractortest.h" #include +#include #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/xmlextractor.h" +#include "mimeutils.h" using namespace KFileMetaData; XmlExtractorTests::XmlExtractorTests(QObject* parent) : QObject(parent) { } QString XmlExtractorTests::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; } void XmlExtractorTests::benchMarkXmlExtractor() { XmlExtractor plugin(this); // generate a test file with varying number of words per line QTemporaryFile file(QStringLiteral("XXXXXX.xml")); QVERIFY(file.open()); int count = 0; file.write("\n"); QByteArray chunk("foo bar "); for (int line = 0; line < 10000; ++line) { // staircase pattern, 0, 1, 2, ... 98, 0, 0, 1 ... chunks per line for (int i = 0; i < line % 100; ++i) { count++; file.write(chunk); } file.write("\n"); } file.write("\n"); file.close(); SimpleExtractionResult result(file.fileName(), QStringLiteral("application/xml")); plugin.extract(&result); QString content = QStringLiteral("foo bar\n"); content.replace(QLatin1Char('\n'), QLatin1Char(' ')); QCOMPARE(result.text().leftRef(8), content.leftRef(8)); QCOMPARE(result.text().size(), 8 * count); QBENCHMARK { plugin.extract(&result); } } void XmlExtractorTests::testXmlExtractor() { XmlExtractor plugin{this}; - SimpleExtractionResult result(testFilePath(QStringLiteral("test_with_metadata.svg")), - QStringLiteral("image/svg"), + QString fileName = testFilePath(QStringLiteral("test_with_metadata.svg")); + QMimeDatabase mimeDb; + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); + QVERIFY(plugin.mimetypes().contains(mimeType)); + + SimpleExtractionResult result(fileName, mimeType, ExtractionResult::ExtractEverything); plugin.extract(&result); QString content = QStringLiteral("Some text\n"); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().at(0), Type::Image); QCOMPARE(result.properties().size(), 1); QCOMPARE(result.properties().value(Property::Title).toString(), QStringLiteral("Document Title")); content.replace(QLatin1Char('\n'), QLatin1Char(' ')); QCOMPARE(result.text(), content); } void XmlExtractorTests::testXmlExtractorNoContent() { XmlExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test_with_metadata.svg")), QStringLiteral("image/svg"), ExtractionResult::ExtractMetaData); plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().at(0), Type::Image); QCOMPARE(result.properties().size(), 1); QCOMPARE(result.properties().value(Property::Title).toString(), QStringLiteral("Document Title")); QVERIFY(result.text().isEmpty()); } void XmlExtractorTests::testXmlExtractorContainer() { XmlExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test_with_container.svg")), QStringLiteral("image/svg"), ExtractionResult::ExtractEverything); plugin.extract(&result); QString content = QStringLiteral("Some text below \n"); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().at(0), Type::Image); QCOMPARE(result.properties().size(), 0); content.replace(QLatin1Char('\n'), QLatin1Char(' ')); QCOMPARE(result.text(), content); } void XmlExtractorTests::testXmlExtractorMathML() { XmlExtractor plugin{this}; SimpleExtractionResult result(testFilePath(QStringLiteral("test.mml")), QStringLiteral("application/mathml+xml"), ExtractionResult::ExtractEverything); plugin.extract(&result); QString content = QStringLiteral("1 + 1 = 2\n"); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().at(0), Type::Text); QCOMPARE(result.properties().size(), 0); content.replace(QLatin1Char('\n'), QLatin1Char(' ')); QCOMPARE(result.text(), content); } QTEST_GUILESS_MAIN(XmlExtractorTests)