File indexing completed on 2024-05-12 05:10:03
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 "itunesfetchertest.h" 0026 0027 #include "../fetch/itunesfetcher.h" 0028 #include "../entry.h" 0029 #include "../images/imagefactory.h" 0030 0031 #include <KSharedConfig> 0032 #include <KConfigGroup> 0033 #include <KLocalizedString> 0034 0035 #include <QTest> 0036 0037 QTEST_GUILESS_MAIN( ItunesFetcherTest ) 0038 0039 ItunesFetcherTest::ItunesFetcherTest() : AbstractFetcherTest() { 0040 } 0041 0042 void ItunesFetcherTest::initTestCase() { 0043 Tellico::ImageFactory::init(); 0044 } 0045 0046 void ItunesFetcherTest::testBurningEdge() { 0047 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("itunes")); 0048 cg.writeEntry("Custom Fields", QStringLiteral("itunes")); 0049 0050 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::Keyword, 0051 QStringLiteral("Burning Edge Of Dawn")); 0052 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ItunesFetcher(this)); 0053 fetcher->readConfig(cg); 0054 0055 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0056 0057 QCOMPARE(results.size(), 1); 0058 0059 Tellico::Data::EntryPtr entry = results.at(0); 0060 QVERIFY(entry); 0061 0062 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("The Burning Edge of Dawn")); 0063 QCOMPARE(entry->field(QStringLiteral("artist")), QStringLiteral("Andrew Peterson")); 0064 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Christian")); 0065 QCOMPARE(entry->field(QStringLiteral("itunes")), QStringLiteral("https://music.apple.com/us/album/the-burning-edge-of-dawn/1560397363?uo=4")); 0066 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0067 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0068 0069 QStringList trackList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("track"))); 0070 QCOMPARE(trackList.count(), 10); 0071 QCOMPARE(trackList.at(0), QStringLiteral("The Dark Before the Dawn::Andrew Peterson::4:09")); 0072 } 0073 0074 void ItunesFetcherTest::testUpc() { 0075 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::UPC, 0076 QStringLiteral("829619128628")); 0077 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ItunesFetcher(this)); 0078 QVERIFY(fetcher->canSearch(request.key())); 0079 0080 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0081 0082 QCOMPARE(results.size(), 1); 0083 0084 Tellico::Data::EntryPtr entry = results.at(0); 0085 QVERIFY(entry); 0086 0087 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("The Burning Edge of Dawn")); 0088 QCOMPARE(entry->field(QStringLiteral("artist")), QStringLiteral("Andrew Peterson")); 0089 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0090 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0091 0092 QStringList trackList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("track"))); 0093 QCOMPARE(trackList.count(), 10); 0094 QCOMPARE(trackList.at(0), QStringLiteral("The Dark Before the Dawn::Andrew Peterson::4:09")); 0095 } 0096 0097 void ItunesFetcherTest::testTopGun() { 0098 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword, 0099 QStringLiteral("Top Gun")); 0100 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ItunesFetcher(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.at(0); 0107 QVERIFY(entry); 0108 0109 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Top Gun")); 0110 QCOMPARE(entry->field(QStringLiteral("director")), QStringLiteral("Tony Scott")); 0111 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1986")); 0112 QCOMPARE(entry->field(QStringLiteral("nationality")), QStringLiteral("USA")); 0113 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Action & Adventure")); 0114 QCOMPARE(entry->field(QStringLiteral("certification")), QStringLiteral("PG (USA)")); 0115 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0116 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0117 QVERIFY(entry->field(QStringLiteral("plot")).startsWith(QLatin1String("A hip, heart-pounding combination of action"))); 0118 } 0119 0120 void ItunesFetcherTest::testFirefly() { 0121 KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("itunes")); 0122 cg.writeEntry("Custom Fields", QStringLiteral("itunes,episode")); 0123 0124 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword, 0125 QStringLiteral("Firefly")); 0126 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ItunesFetcher(this)); 0127 fetcher->readConfig(cg); 0128 0129 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0130 0131 QCOMPARE(results.size(), 1); 0132 0133 Tellico::Data::EntryPtr entry = results.at(0); 0134 QVERIFY(entry); 0135 0136 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Firefly, The Complete Series")); 0137 QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("2002")); 0138 QCOMPARE(entry->field(QStringLiteral("nationality")), QStringLiteral("USA")); 0139 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Sci-Fi & Fantasy")); 0140 QVERIFY(entry->field(QStringLiteral("certification")).isEmpty()); 0141 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0142 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0143 QVERIFY(entry->field(QStringLiteral("plot")).startsWith(QLatin1String("Five hundred years"))); 0144 QStringList episodeList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("episode"))); 0145 QCOMPARE(episodeList.size(), 14); 0146 QCOMPARE(episodeList.at(0), QStringLiteral("Serenity::1::1")); 0147 } 0148 0149 void ItunesFetcherTest::testEscapingGravity() { 0150 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Keyword, 0151 QStringLiteral("Escaping Gravity")); 0152 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ItunesFetcher(this)); 0153 QVERIFY(fetcher->canSearch(request.key())); 0154 0155 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0156 0157 QCOMPARE(results.size(), 1); 0158 0159 Tellico::Data::EntryPtr entry = results.at(0); 0160 QVERIFY(entry); 0161 0162 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Escaping Gravity: My Quest to Transform NASA and Launch a New Space Age (Unabridged)")); 0163 QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Lori Garver")); 0164 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2022")); 0165 QCOMPARE(entry->field(QStringLiteral("binding")), QStringLiteral("E-Book")); 0166 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Science & Nature")); 0167 QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("Blackstone Publishing")); 0168 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0169 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0170 QVERIFY(entry->field(QStringLiteral("plot")).startsWith(QLatin1String("The inside look"))); 0171 } 0172 0173 void ItunesFetcherTest::testIsbn() { 0174 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN, 0175 QStringLiteral("9780316069359")); 0176 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ItunesFetcher(this)); 0177 QVERIFY(fetcher->canSearch(request.key())); 0178 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0179 0180 QCOMPARE(results.size(), 1); 0181 0182 Tellico::Data::EntryPtr entry = results.at(0); 0183 QVERIFY(entry); 0184 0185 QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("The Fifth Witness")); 0186 QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Michael Connelly")); 0187 QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("2011")); 0188 QCOMPARE(entry->field(QStringLiteral("binding")), QStringLiteral("E-Book")); 0189 QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Mysteries & Thrillers; Police Procedural")); 0190 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0191 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0192 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0193 } 0194 0195 // bug 479503, https://bugs.kde.org/show_bug.cgi?id=479503 0196 void ItunesFetcherTest::testMultiDisc() { 0197 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::Keyword, 0198 QStringLiteral("Hamilton: An American Musical")); 0199 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ItunesFetcher(this)); 0200 0201 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0202 0203 QVERIFY(!results.isEmpty()); 0204 0205 Tellico::Data::EntryPtr entry = results.at(0); 0206 auto trackField = entry->collection()->fieldByName(QStringLiteral("track")); 0207 QVERIFY(trackField); 0208 // verify the title was updated to include the disc number 0209 QVERIFY(trackField->title() != i18n("Tracks")); 0210 QStringList tracks1 = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("track"))); 0211 QCOMPARE(tracks1.count(), 23); 0212 // new field with Disc 2 tracks 0213 QStringList tracks2 = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("track2"))); 0214 QCOMPARE(tracks2.count(), 23); 0215 QVERIFY(!tracks2.first().isEmpty()); 0216 }