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

0001 /***************************************************************************
0002     Copyright (C) 2012 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 "ibsfetchertest.h"
0028 
0029 #include "../fetch/ibsfetcher.h"
0030 #include "../entry.h"
0031 #include "../images/imagefactory.h"
0032 
0033 #include <QTest>
0034 
0035 QTEST_GUILESS_MAIN( IBSFetcherTest )
0036 
0037 IBSFetcherTest::IBSFetcherTest() : AbstractFetcherTest() {
0038 }
0039 
0040 void IBSFetcherTest::initTestCase() {
0041   Tellico::ImageFactory::init();
0042 }
0043 
0044 void IBSFetcherTest::testTitle() {
0045   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Title,
0046                                        QStringLiteral("Vino & cucina"));
0047   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IBSFetcher(this));
0048 
0049   // the one we want should be in the first 5
0050   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 5);
0051 
0052   QVERIFY(results.size() > 0);
0053   Tellico::Data::EntryPtr entry;  //  results can be randomly ordered, loop until we find the one we want
0054   foreach(Tellico::Data::EntryPtr testEntry, results) {
0055     if(testEntry->title().startsWith(QStringLiteral("Vino & cucina"), Qt::CaseInsensitive)) {
0056       entry = testEntry;
0057       break;
0058     }
0059   }
0060   QVERIFY(entry);
0061 
0062   compareEntry(entry);
0063 }
0064 
0065 void IBSFetcherTest::testIsbn() {
0066   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN,
0067                                        QStringLiteral("8804644060"));
0068   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IBSFetcher(this));
0069 
0070   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0071 
0072   QCOMPARE(results.size(), 1);
0073   compareEntry(results.first());
0074 }
0075 
0076 void IBSFetcherTest::testTranslator() {
0077   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN,
0078                                        QStringLiteral("8842914975"));
0079   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IBSFetcher(this));
0080 
0081   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0082 
0083   QCOMPARE(results.size(), 1);
0084 
0085   Tellico::Data::EntryPtr entry = results.first();
0086   QCOMPARE(entry->field("title"), QString::fromUtf8("città sepolta"));
0087   QCOMPARE(entry->field("isbn"), QStringLiteral("8842914975"));
0088   QCOMPARE(entry->field("pages"), QStringLiteral("542"));
0089   QCOMPARE(entry->field("genre"), QStringLiteral("Avventura"));
0090   QCOMPARE(entry->field("language"), QStringLiteral("italiano"));
0091   QCOMPARE(entry->field("author"), QStringLiteral("James Rollins"));
0092   QCOMPARE(entry->field("translator"), QStringLiteral("Marco Zonetti"));
0093   QCOMPARE(entry->field("edition"), QStringLiteral("Nord"));
0094   QCOMPARE(entry->field("series"), QStringLiteral("Narrativa Nord"));
0095 }
0096 
0097 void IBSFetcherTest::testEditor() {
0098   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN,
0099                                        QStringLiteral("8873718735"));
0100   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::IBSFetcher(this));
0101 
0102   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0103 
0104   QCOMPARE(results.size(), 1);
0105 
0106   Tellico::Data::EntryPtr entry = results.first();
0107   QCOMPARE(entry->field("title"), QString::fromUtf8("centuria bianca"));
0108   QCOMPARE(entry->field("editor"), QStringLiteral("I. Armaro"));
0109   QCOMPARE(entry->field("binding"), QStringLiteral("Paperback"));
0110 }
0111 
0112 void IBSFetcherTest::compareEntry(Tellico::Data::EntryPtr entry) {
0113   QVERIFY(entry->field("title").startsWith(QStringLiteral("Vino & cucina")));
0114   QCOMPARE(entry->field("isbn"), QStringLiteral("8804644060"));
0115   QCOMPARE(entry->field("author"), QStringLiteral("Antonella Clerici"));
0116   QCOMPARE(entry->field("pub_year"), QStringLiteral("2014"));
0117   QCOMPARE(entry->field("pages"), QStringLiteral("225"));
0118   QCOMPARE(entry->field("publisher"), QStringLiteral("Mondadori"));
0119   QVERIFY(!entry->field("plot").isEmpty());
0120   QVERIFY(!entry->field("cover").isEmpty());
0121   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0122 }