1 /***************************************************************************
2     Copyright (C) 2015 Robby Stephenson <robby@periapsis.org>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or         *
8  *   modify it under the terms of the GNU General Public License as        *
9  *   published by the Free Software Foundation; either version 2 of        *
10  *   the License or (at your option) version 3 or any later version        *
11  *   accepted by the membership of KDE e.V. (or its successor approved     *
12  *   by the membership of KDE e.V.), which shall act as a proxy            *
13  *   defined in Section 14 of version 3 of the license.                    *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
22  *                                                                         *
23  ***************************************************************************/
24 
25 #undef QT_NO_CAST_FROM_ASCII
26 
27 #include <config.h>
28 #include "filelistingtest.h"
29 
30 #include "../translators/filelistingimporter.h"
31 #include "../translators/xmphandler.h"
32 #include "../images/imagefactory.h"
33 
34 #include <QTest>
35 #include <QStandardPaths>
36 
37 // KIO::listDir in FileListingImporter seems to require a GUI Application
QTEST_MAIN(FileListingTest)38 QTEST_MAIN( FileListingTest )
39 
40 void FileListingTest::initTestCase() {
41   QStandardPaths::setTestModeEnabled(true);
42   Tellico::ImageFactory::init();
43 }
44 
testCpp()45 void FileListingTest::testCpp() {
46   QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("filelistingtest.cpp"));
47   Tellico::Import::FileListingImporter importer(url.adjusted(QUrl::RemoveFilename));
48   // can't import images for local test
49 //  importer.setOptions(importer.options() & ~Tellico::Import::ImportShowImageErrors);
50   Tellico::Data::CollPtr coll = importer.collection();
51 
52   QVERIFY(coll);
53   QCOMPARE(coll->type(), Tellico::Data::Collection::File);
54   QVERIFY(coll->entryCount() > 0);
55 
56   Tellico::Data::EntryPtr entry;
57   foreach(Tellico::Data::EntryPtr tmpEntry, coll->entries()) {
58     if(tmpEntry->field(QStringLiteral("title")) == QStringLiteral("filelistingtest.cpp")) {
59       entry = tmpEntry;
60     }
61   }
62   QVERIFY(entry);
63   QCOMPARE(entry->field("title"), QStringLiteral("filelistingtest.cpp"));
64   QCOMPARE(entry->field("url"), url.url());
65   QVERIFY(entry->field("description").contains("C++"));
66   QCOMPARE(entry->field("folder"), QString()); // empty relative folder location
67   QCOMPARE(entry->field("mimetype"), QStringLiteral("text/x-c++src"));
68   QVERIFY(!entry->field("size").isEmpty());
69   QVERIFY(!entry->field("permissions").isEmpty());
70   QVERIFY(!entry->field("owner").isEmpty());
71   QVERIFY(!entry->field("group").isEmpty());
72   // for some reason, the Creation time isn't populated for this test
73 //  QVERIFY(!entry->field("created").isEmpty());
74   QVERIFY(!entry->field("modified").isEmpty());
75 #ifdef HAVE_KFILEMETADATA
76   QCOMPARE(entry->field("metainfo"), QString());
77 #endif
78   // icon name does not get set for the jenkins build service
79 //  QVERIFY(!entry->field("icon").isEmpty());
80 }
81 
testXMPData()82 void FileListingTest::testXMPData() {
83   {
84     Tellico::XMPHandler xmp;
85 #ifdef HAVE_EXEMPI
86     QVERIFY(xmp.isXMPEnabled());
87     QVERIFY(!xmp.extractXMP(QFINDTESTDATA("data/BlueSquare.jpg")).isEmpty());
88 #endif
89   }
90   // initializing exempi can cause a crash in Exiv for files with XMP data
91   // see https://bugs.kde.org/show_bug.cgi?id=390744
92   QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/BlueSquare.jpg"));
93   Tellico::Import::FileListingImporter importer(url.adjusted(QUrl::RemoveFilename));
94   Tellico::Data::CollPtr coll = importer.collection();
95 
96   QVERIFY(coll);
97   QCOMPARE(coll->type(), Tellico::Data::Collection::File);
98   QVERIFY(coll->entryCount() > 0);
99 
100   Tellico::Data::EntryPtr entry;
101   foreach(Tellico::Data::EntryPtr tmpEntry, coll->entries()) {
102     if(tmpEntry->field(QStringLiteral("title")) == QStringLiteral("BlueSquare.jpg")) {
103       entry = tmpEntry;
104     }
105   }
106   QVERIFY(entry);
107   QCOMPARE(entry->field("title"), QStringLiteral("BlueSquare.jpg"));
108   QCOMPARE(entry->field("mimetype"), QStringLiteral("image/jpeg"));
109   QCOMPARE(entry->field("size"), QStringLiteral("23.6 KiB"));
110 #ifdef HAVE_KFILEMETADATA
111 #ifdef HAVE_EXEMPI
112   QEXPECT_FAIL("", "Because of a crash related to exempi and kfilemetadata linking, no metadata is read", Continue);
113 #endif
114   QVERIFY(!entry->field("metainfo").isEmpty());
115 #endif
116 }
117