File indexing completed on 2024-05-12 05:10:00

0001 /***************************************************************************
0002     Copyright (C) 2011-2020 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 "googlebookfetchertest.h"
0028 
0029 #include "../fetch/googlebookfetcher.h"
0030 #include "../entry.h"
0031 #include "../images/imagefactory.h"
0032 
0033 #include <QTest>
0034 
0035 QTEST_GUILESS_MAIN( GoogleBookFetcherTest )
0036 
0037 GoogleBookFetcherTest::GoogleBookFetcherTest() : AbstractFetcherTest() {
0038 }
0039 
0040 void GoogleBookFetcherTest::initTestCase() {
0041   Tellico::ImageFactory::init();
0042 }
0043 
0044 void GoogleBookFetcherTest::testTitle() {
0045   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Title,
0046                                        QStringLiteral("Practical Rdf"));
0047   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::GoogleBookFetcher(this));
0048 
0049   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0050 
0051   QCOMPARE(results.size(), 1);
0052   compareEntry(results.at(0));
0053 }
0054 
0055 void GoogleBookFetcherTest::testIsbn() {
0056   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN,
0057                                        QStringLiteral("0-596-55051-0"));
0058   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::GoogleBookFetcher(this));
0059 
0060   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0061 
0062   QCOMPARE(results.size(), 1);
0063   compareEntry(results.at(0));
0064 }
0065 
0066 void GoogleBookFetcherTest::testAuthor() {
0067   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Person,
0068                                        QStringLiteral("Shelley Powers"));
0069   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::GoogleBookFetcher(this));
0070 
0071   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0072 
0073   Tellico::Data::EntryPtr entry;
0074   foreach(Tellico::Data::EntryPtr testEntry, results) {
0075     if(testEntry->title() == QStringLiteral("Practical RDF")) {
0076       entry = testEntry;
0077       break;
0078     }
0079   }
0080   QVERIFY(entry);
0081   compareEntry(entry);
0082 }
0083 
0084 void GoogleBookFetcherTest::testKeyword() {
0085   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Keyword,
0086                                        QStringLiteral("Practical Rdf"));
0087   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::GoogleBookFetcher(this));
0088 
0089   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0090 
0091   QCOMPARE(results.size(), 1);
0092   compareEntry(results.at(0));
0093 }
0094 
0095 void GoogleBookFetcherTest::compareEntry(Tellico::Data::EntryPtr entry) {
0096   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Practical RDF"));
0097   if(entry->field(QStringLiteral("isbn")) == QStringLiteral("0-596-55051-0")) {
0098     QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("0-596-55051-0"));
0099     QCOMPARE(entry->field(QStringLiteral("pages")), QStringLiteral("352"));
0100   } else {
0101     QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("0-596-51561-8"));
0102     QCOMPARE(entry->field(QStringLiteral("pages")), QStringLiteral("336"));
0103   }
0104   QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Shelley Powers"));
0105   QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("O'Reilly Media, Inc."));
0106   QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2003"));
0107   QVERIFY(entry->field(QStringLiteral("keyword")).contains(QStringLiteral("Computers")));
0108   QVERIFY(entry->field(QStringLiteral("keyword")).contains(QStringLiteral("XML")));
0109   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0110   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0111   QVERIFY(!entry->field(QStringLiteral("comments")).isEmpty());
0112 }