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 "exiv2extractortest.h" |
22 | #include "simpleextractionresult.h" |
23 | #include "indexerextractortestsconfig.h" |
24 | #include "extractors/exiv2extractor.h" |
25 | #include "mimeutils.h" |
26 | |
27 | #include <QTest> |
28 | #include <QMimeDatabase> |
29 | |
30 | using namespace KFileMetaData; |
31 | using namespace KFileMetaData::Property; |
32 | |
33 | QString Exiv2ExtractorTest::(const QString& fileName) const |
34 | { |
35 | return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; |
36 | } |
37 | |
38 | void Exiv2ExtractorTest::() |
39 | { |
40 | Exiv2Extractor plugin{this}; |
41 | |
42 | QString fileName = testFilePath(QStringLiteral("test.jpg" )); |
43 | QMimeDatabase mimeDb; |
44 | QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); |
45 | QVERIFY(plugin.mimetypes().contains(mimeType)); |
46 | |
47 | SimpleExtractionResult result(fileName, mimeType); |
48 | plugin.extract(&result); |
49 | |
50 | QCOMPARE(result.types().size(), 1); |
51 | QCOMPARE(result.types().constFirst(), Type::Image); |
52 | |
53 | QCOMPARE(result.properties().value(Artist).toString(), QStringLiteral("Artist" )); |
54 | QCOMPARE(result.properties().value(Description).toString(), QStringLiteral("Description" )); |
55 | QCOMPARE(result.properties().value(Copyright).toString(), QStringLiteral("Copyright" )); |
56 | QCOMPARE(result.properties().value(Generator).toString(), QStringLiteral("digiKam-5.9.0" )); |
57 | } |
58 | |
59 | void Exiv2ExtractorTest::() |
60 | { |
61 | Exiv2Extractor plugin{this}; |
62 | |
63 | SimpleExtractionResult result(testFilePath("test.jpg" ), "image/jpeg" ); |
64 | plugin.extract(&result); |
65 | |
66 | QCOMPARE(result.properties().value(PhotoGpsLatitude).toDouble(), 41.411); |
67 | QCOMPARE(result.properties().value(PhotoGpsLongitude).toDouble(), 2.173); |
68 | QCOMPARE(result.properties().value(PhotoGpsAltitude).toDouble(), 12.2); |
69 | |
70 | SimpleExtractionResult resultEmpty(testFilePath("test_no_gps.jpg" ), "image/jpeg" ); |
71 | plugin.extract(&resultEmpty); |
72 | QVERIFY(!resultEmpty.properties().contains(PhotoGpsLatitude)); |
73 | QVERIFY(!resultEmpty.properties().contains(PhotoGpsLongitude)); |
74 | QVERIFY(!resultEmpty.properties().contains(PhotoGpsAltitude)); |
75 | |
76 | SimpleExtractionResult resultZero(testFilePath("test_zero_gps.jpg" ), "image/jpeg" ); |
77 | plugin.extract(&resultZero); |
78 | QVERIFY(resultZero.properties().contains(PhotoGpsLatitude)); |
79 | QVERIFY(resultZero.properties().contains(PhotoGpsLongitude)); |
80 | QVERIFY(resultZero.properties().contains(PhotoGpsAltitude)); |
81 | QCOMPARE(resultZero.properties().value(PhotoGpsLatitude).toDouble(), 0.0); |
82 | QCOMPARE(resultZero.properties().value(PhotoGpsLongitude).toDouble(), 0.0); |
83 | QCOMPARE(resultZero.properties().value(PhotoGpsAltitude).toDouble(), 0.0); |
84 | } |
85 | |
86 | QTEST_GUILESS_MAIN(Exiv2ExtractorTest) |
87 | |