1/*
2 * <one line to give the library's name and an idea of what it does.>
3 * Copyright (C) 2014 Vishesh Handa <me@vhanda.in>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21#include "epubextractortest.h"
22#include "simpleextractionresult.h"
23#include "indexerextractortestsconfig.h"
24#include "extractors/epubextractor.h"
25#include "mimeutils.h"
26
27#include <QTest>
28#include <QMimeDatabase>
29
30using namespace KFileMetaData;
31
32QString EPubExtractorTest::testFilePath(const QString& fileName) const
33{
34 return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName;
35}
36
37void EPubExtractorTest::test()
38{
39 EPubExtractor plugin{this};
40
41 QString fileName = testFilePath(QStringLiteral("test.epub"));
42 QMimeDatabase mimeDb;
43 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name();
44 QVERIFY(plugin.mimetypes().contains(mimeType));
45
46 SimpleExtractionResult result(fileName, mimeType);
47 plugin.extract(&result);
48
49 QCOMPARE(result.types().size(), 1);
50 QCOMPARE(result.types().constFirst(), Type::Document);
51
52 // We're doing a contains instead of an exact check cause the epub file contains
53 // a ton of css and other garbage.
54 QVERIFY(result.text().contains(QStringLiteral("This is a sample PDF file for KFileMetaData.")));
55 QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Happy Man")));
56 QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Happy Publisher")));
57 QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("The Big Brown Bear")));
58 QCOMPARE(result.properties().value(Property::Subject), QVariant(QStringLiteral("Baloo KFileMetaData")));
59 QCOMPARE(result.properties().value(Property::Description), QVariant(QStringLiteral("Honey")));
60
61 QDateTime dt(QDate(2014, 1, 1), QTime(1, 1, 1));
62 dt.setTimeSpec(Qt::UTC);
63 QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt));
64 QCOMPARE(result.properties().value(Property::ReleaseYear), QVariant(2014));
65
66 QCOMPARE(result.properties().size(), 7);
67}
68
69void EPubExtractorTest::testMetaDataOnly()
70{
71 EPubExtractor plugin{this};
72
73 SimpleExtractionResult result(testFilePath("test.epub"), "application/epub+zip", ExtractionResult::ExtractMetaData);
74 plugin.extract(&result);
75
76 QVERIFY(!result.types().isEmpty());
77 QVERIFY(!result.properties().isEmpty());
78 QVERIFY(result.text().isEmpty());
79}
80
81
82QTEST_GUILESS_MAIN(EPubExtractorTest)
83