File indexing completed on 2024-05-12 16:46:23
0001 /*************************************************************************** 0002 Copyright (C) 2009-2011 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 "openlibraryfetchertest.h" 0028 0029 #include "../fetch/openlibraryfetcher.h" 0030 #include "../entry.h" 0031 #include "../collections/bookcollection.h" 0032 #include "../images/imagefactory.h" 0033 0034 #include <QTest> 0035 0036 QTEST_GUILESS_MAIN( OpenLibraryFetcherTest ) 0037 0038 OpenLibraryFetcherTest::OpenLibraryFetcherTest() : AbstractFetcherTest() { 0039 } 0040 0041 void OpenLibraryFetcherTest::initTestCase() { 0042 Tellico::ImageFactory::init(); 0043 } 0044 0045 void OpenLibraryFetcherTest::testTitle() { 0046 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Title, 0047 QStringLiteral("Barrayar")); 0048 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::OpenLibraryFetcher(this)); 0049 0050 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0051 0052 QCOMPARE(results.size(), 1); 0053 0054 Tellico::Data::EntryPtr entry = results.at(0); 0055 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Barrayar")); 0056 } 0057 0058 void OpenLibraryFetcherTest::testIsbn() { 0059 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN, 0060 QStringLiteral("0789312239")); 0061 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::OpenLibraryFetcher(this)); 0062 0063 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0064 0065 QCOMPARE(results.size(), 1); 0066 0067 Tellico::Data::EntryPtr entry = results.at(0); 0068 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("This is Venice")); 0069 QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("M. Sasek")); 0070 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("0-7893-1223-9")); 0071 QCOMPARE(entry->field(QStringLiteral("lccn")), QStringLiteral("2004110229")); 0072 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2005")); 0073 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Juvenile literature.")); 0074 QCOMPARE(entry->field(QStringLiteral("keyword")), QStringLiteral("Venice (Italy) -- Description and travel -- Juvenile literature")); 0075 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Universe")); 0076 QCOMPARE(entry->field(QStringLiteral("language")), QStringLiteral("English")); 0077 QCOMPARE(entry->field(QStringLiteral("pages")), QStringLiteral("56")); 0078 QVERIFY(!entry->field(QStringLiteral("comments")).isEmpty()); 0079 } 0080 0081 void OpenLibraryFetcherTest::testIsbn13() { 0082 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN, 0083 QStringLiteral("9780596004361")); 0084 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::OpenLibraryFetcher(this)); 0085 0086 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0087 0088 // sometimes OpenLibrary has multiple works defined, so just verify one or more 0089 QVERIFY(results.size() >= 1); 0090 0091 Tellico::Data::EntryPtr entry = results.at(0); 0092 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("C Pocket Reference")); 0093 QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("978-0-596-00436-1")); 0094 } 0095 0096 void OpenLibraryFetcherTest::testMultipleIsbn() { 0097 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN, 0098 QStringLiteral("0789312239; 9780596000486")); 0099 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::OpenLibraryFetcher(this)); 0100 0101 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0102 0103 QCOMPARE(results.size(), 2); 0104 } 0105 0106 void OpenLibraryFetcherTest::testUpdate() { 0107 Tellico::Data::CollPtr coll(new Tellico::Data::BookCollection(true)); 0108 Tellico::Data::EntryPtr oldEntry(new Tellico::Data::Entry(coll)); 0109 coll->addEntries(oldEntry); 0110 0111 oldEntry->setField(QStringLiteral("title"), QStringLiteral("The Great Hunt")); 0112 oldEntry->setField(QStringLiteral("publisher"), QStringLiteral("Orbit")); 0113 0114 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::OpenLibraryFetcher(this)); 0115 auto f = static_cast<Tellico::Fetch::OpenLibraryFetcher*>(fetcher.data()); 0116 0117 auto request = f->updateRequest(oldEntry); 0118 QCOMPARE(request.key(), Tellico::Fetch::Raw); 0119 request.setCollectionType(coll->type()); 0120 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0121 0122 QCOMPARE(results.size(), 1); 0123 0124 Tellico::Data::EntryPtr entry = results.at(0); 0125 QVERIFY(entry); 0126 0127 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("The Great Hunt")); 0128 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2014")); 0129 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Orbit")); 0130 }