File indexing completed on 2024-05-12 05:09:56
0001 /*************************************************************************** 0002 Copyright (C) 2017 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #undef QT_NO_CAST_FROM_ASCII 0026 0027 #include "dbcfetchertest.h" 0028 0029 #include "../fetch/dbcfetcher.h" 0030 #include "../collections/bookcollection.h" 0031 #include "../collectionfactory.h" 0032 #include "../entry.h" 0033 #include "../utils/datafileregistry.h" 0034 0035 #include <QTest> 0036 0037 QTEST_GUILESS_MAIN( DBCFetcherTest ) 0038 0039 DBCFetcherTest::DBCFetcherTest() : AbstractFetcherTest() { 0040 } 0041 0042 void DBCFetcherTest::initTestCase() { 0043 Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book"); 0044 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/dbc2tellico.xsl")); 0045 } 0046 0047 void DBCFetcherTest::testTitle() { 0048 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title, 0049 QStringLiteral("Min kamp")); 0050 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DBCFetcher(this)); 0051 0052 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0053 0054 QCOMPARE(results.size(), 1); 0055 0056 Tellico::Data::EntryPtr entry = results.at(0); 0057 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Min kamp. 6")); 0058 QCOMPARE(entry->field(QStringLiteral("author")), QString::fromUtf8("Karl Ove Knausgård")); 0059 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Lindhardt og Ringhof")); 0060 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2012")); 0061 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("978-87-11-39509-7")); 0062 QCOMPARE(entry->field(QStringLiteral("binding")), QStringLiteral("E-Book")); 0063 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("biografiske romaner")); 0064 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0065 } 0066 0067 void DBCFetcherTest::testIsbn() { 0068 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::ISBN, 0069 QStringLiteral("978-87-11-39509-7")); 0070 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DBCFetcher(this)); 0071 0072 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0073 0074 QCOMPARE(results.size(), 1); 0075 0076 Tellico::Data::EntryPtr entry = results.at(0); 0077 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Min kamp. 6")); 0078 QCOMPARE(entry->field(QStringLiteral("author")), QString::fromUtf8("Karl Ove Knausgård")); 0079 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Lindhardt og Ringhof")); 0080 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2012")); 0081 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("978-87-11-39509-7")); 0082 QCOMPARE(entry->field(QStringLiteral("language")), QStringLiteral("dansk")); 0083 QCOMPARE(entry->field(QStringLiteral("translator")), QStringLiteral("Sara Koch")); 0084 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("biografiske romaner")); 0085 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0086 } 0087 0088 void DBCFetcherTest::testKeyword() { 0089 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Keyword, 0090 QStringLiteral("9788711395097")); 0091 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DBCFetcher(this)); 0092 0093 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0094 0095 QCOMPARE(results.size(), 1); 0096 0097 Tellico::Data::EntryPtr entry = results.at(0); 0098 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Min kamp. 6")); 0099 QCOMPARE(entry->field(QStringLiteral("author")), QString::fromUtf8("Karl Ove Knausgård")); 0100 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Lindhardt og Ringhof")); 0101 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2012")); 0102 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("978-87-11-39509-7")); 0103 QCOMPARE(entry->field(QStringLiteral("language")), QStringLiteral("dansk")); 0104 QCOMPARE(entry->field(QStringLiteral("translator")), QStringLiteral("Sara Koch")); 0105 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("biografiske romaner")); 0106 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0107 }