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

0001 /***************************************************************************
0002     Copyright (C) 2021 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 #include "upcitemdbfetchertest.h"
0026 
0027 #include "../fetch/upcitemdbfetcher.h"
0028 #include "../collectionfactory.h"
0029 #include "../collections/bookcollection.h"
0030 #include "../collections/videocollection.h"
0031 #include "../collections/boardgamecollection.h"
0032 #include "../collections/musiccollection.h"
0033 #include "../collections/gamecollection.h"
0034 #include "../entry.h"
0035 #include "../images/imagefactory.h"
0036 
0037 #include <KSharedConfig>
0038 #include <KConfigGroup>
0039 
0040 #include <QTest>
0041 
0042 QTEST_GUILESS_MAIN( UPCItemDbFetcherTest )
0043 
0044 UPCItemDbFetcherTest::UPCItemDbFetcherTest() : AbstractFetcherTest() {
0045 }
0046 
0047 void UPCItemDbFetcherTest::initTestCase() {
0048   Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book");
0049   Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video");
0050   Tellico::RegisterCollection<Tellico::Data::BoardGameCollection> registerBoardGame(Tellico::Data::Collection::BoardGame, "boardgame");
0051   Tellico::RegisterCollection<Tellico::Data::MusicCollection> registerMusic(Tellico::Data::Collection::Album, "album");
0052   Tellico::RegisterCollection<Tellico::Data::GameCollection> registerGame(Tellico::Data::Collection::Game, "game");
0053   Tellico::ImageFactory::init();
0054 }
0055 
0056 void UPCItemDbFetcherTest::testFightClub() {
0057   KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("upcitemdb"));
0058   cg.writeEntry("Custom Fields", QStringLiteral("barcode"));
0059 
0060   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::UPC,
0061                                        QStringLiteral("024543617907"));
0062   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::UPCItemDbFetcher(this));
0063   fetcher->readConfig(cg);
0064 
0065   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0066 
0067   QCOMPARE(results.size(), 1);
0068 
0069   Tellico::Data::EntryPtr entry = results.at(0);
0070   QVERIFY(entry);
0071 
0072   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Fight Club"));
0073   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1999"));
0074   QCOMPARE(entry->field(QStringLiteral("barcode")), QStringLiteral("024543617907"));
0075   QCOMPARE(entry->field(QStringLiteral("medium")), QStringLiteral("Blu-ray"));
0076   QCOMPARE(entry->field(QStringLiteral("studio")), QStringLiteral("20TH CENTURY FOX"));
0077   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0078   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0079   QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
0080 }
0081 
0082 void UPCItemDbFetcherTest::testCatan() {
0083   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::BoardGame, Tellico::Fetch::UPC,
0084                                        QStringLiteral("029877030712"));
0085   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::UPCItemDbFetcher(this));
0086 
0087   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0088 
0089   QCOMPARE(results.size(), 1);
0090 
0091   Tellico::Data::EntryPtr entry = results.at(0);
0092   QVERIFY(entry);
0093 
0094   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Settlers of Catan Board Game"));
0095   QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Mayfair Games"));
0096   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0097   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0098   QVERIFY(!entry->field(QStringLiteral("description")).isEmpty());
0099 }
0100 
0101 void UPCItemDbFetcherTest::test1632() {
0102   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN,
0103                                        QStringLiteral("0671319728"));
0104   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::UPCItemDbFetcher(this));
0105 
0106   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0107 
0108   QCOMPARE(results.size(), 1);
0109 
0110   Tellico::Data::EntryPtr entry = results.at(0);
0111   QVERIFY(entry);
0112 
0113   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Ring of Fire: 1632"));
0114   QEXPECT_FAIL("", "Author data is in publisher field", Continue);
0115   QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Eric Flint"));
0116   QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("9780671319724"));
0117   QEXPECT_FAIL("", "Author data is in publisher field", Continue);
0118   QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Baen"));
0119   QCOMPARE(entry->field(QStringLiteral("binding")), QStringLiteral("Paperback"));
0120   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0121   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0122 //  QVERIFY(!entry->field(QStringLiteral("description")).isEmpty());
0123 }
0124 
0125 void UPCItemDbFetcherTest::testBurningEdge() {
0126   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::UPC,
0127                                        QStringLiteral("829619128628"));
0128   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::UPCItemDbFetcher(this));
0129 
0130   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0131 
0132   QCOMPARE(results.size(), 1);
0133 
0134   Tellico::Data::EntryPtr entry = results.at(0);
0135   QVERIFY(entry);
0136 
0137   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("The Burning Edge of Dawn"));
0138   QEXPECT_FAIL("", "Artist data is in brand field", Continue);
0139   QCOMPARE(entry->field(QStringLiteral("artist")), QStringLiteral("Andrew Peterson"));
0140   QEXPECT_FAIL("", "Artist data is in brand field", Continue);
0141   QCOMPARE(entry->field(QStringLiteral("label")), QStringLiteral("UMGD"));
0142   QCOMPARE(entry->field(QStringLiteral("medium")), QStringLiteral("Compact Disc"));
0143   QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0144   QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0145 }
0146 
0147 void UPCItemDbFetcherTest::testGTA4() {
0148   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Game, Tellico::Fetch::UPC,
0149                                        QStringLiteral("710425392320"));
0150   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::UPCItemDbFetcher(this));
0151 
0152   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0153 
0154   QCOMPARE(results.size(), 1);
0155 
0156   Tellico::Data::EntryPtr entry = results.at(0);
0157   QVERIFY(entry);
0158 
0159   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Grand Theft Auto IV"));
0160   QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Take Two Interactive"));
0161   QCOMPARE(entry->field(QStringLiteral("platform")), QStringLiteral("Xbox 360"));
0162   // cover image is timing out for some reason
0163 //  QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0164 //  QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0165   QVERIFY(!entry->field(QStringLiteral("description")).isEmpty());
0166 }