1 /***************************************************************************
2 Copyright (C) 2017 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 "dbcfetchertest.h"
28
29 #include "../fetch/dbcfetcher.h"
30 #include "../collections/bookcollection.h"
31 #include "../collectionfactory.h"
32 #include "../entry.h"
33 #include "../utils/datafileregistry.h"
34
35 #include <QTest>
36
QTEST_GUILESS_MAIN(DBCFetcherTest)37 QTEST_GUILESS_MAIN( DBCFetcherTest )
38
39 DBCFetcherTest::DBCFetcherTest() : AbstractFetcherTest() {
40 }
41
initTestCase()42 void DBCFetcherTest::initTestCase() {
43 Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book");
44 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/dbc2tellico.xsl"));
45 }
46
testTitle()47 void DBCFetcherTest::testTitle() {
48 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title,
49 QStringLiteral("Min kamp"));
50 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DBCFetcher(this));
51
52 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
53
54 QCOMPARE(results.size(), 1);
55
56 Tellico::Data::EntryPtr entry = results.at(0);
57 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Min kamp"));
58 QCOMPARE(entry->field(QStringLiteral("author")), QString::fromUtf8("Karl Ove Knausgård"));
59 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Lindhardt og Ringhof"));
60 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2012"));
61 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("978-87-11-39183-9"));
62 QCOMPARE(entry->field(QStringLiteral("pages")), QStringLiteral("487"));
63 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("barndomserindringer; erindringer"));
64 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
65 }
66
testIsbn()67 void DBCFetcherTest::testIsbn() {
68 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::ISBN,
69 QStringLiteral("9788711391839"));
70 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DBCFetcher(this));
71
72 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
73
74 QCOMPARE(results.size(), 1);
75
76 Tellico::Data::EntryPtr entry = results.at(0);
77 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Min kamp. 1. bog"));
78 QCOMPARE(entry->field(QStringLiteral("author")), QString::fromUtf8("Karl Ove Knausgård"));
79 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Lindhardt og Ringhof"));
80 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2012"));
81 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("978-87-11-39183-9"));
82 QCOMPARE(entry->field(QStringLiteral("pages")), QStringLiteral("487"));
83 QCOMPARE(entry->field(QStringLiteral("language")), QStringLiteral("Dansk"));
84 QCOMPARE(entry->field(QStringLiteral("translator")), QStringLiteral("Sara Koch"));
85 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("barndomserindringer; erindringer"));
86 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
87 }
88
testKeyword()89 void DBCFetcherTest::testKeyword() {
90 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Keyword,
91 QStringLiteral("9788711391839"));
92 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DBCFetcher(this));
93
94 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
95
96 QCOMPARE(results.size(), 1);
97
98 Tellico::Data::EntryPtr entry = results.at(0);
99 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Min kamp. 1. bog"));
100 QCOMPARE(entry->field(QStringLiteral("author")), QString::fromUtf8("Karl Ove Knausgård"));
101 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Lindhardt og Ringhof"));
102 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2012"));
103 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("978-87-11-39183-9"));
104 QCOMPARE(entry->field(QStringLiteral("pages")), QStringLiteral("487"));
105 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("barndomserindringer; erindringer"));
106 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
107 }
108