File indexing completed on 2024-05-12 05:09:57
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 "doubanfetchertest.h" 0028 0029 #include "../fetch/doubanfetcher.h" 0030 #include "../collections/bookcollection.h" 0031 #include "../collections/videocollection.h" 0032 #include "../collections/musiccollection.h" 0033 #include "../collectionfactory.h" 0034 #include "../entry.h" 0035 #include "../images/imagefactory.h" 0036 0037 #include <KSharedConfig> 0038 0039 #include <QTest> 0040 0041 QTEST_GUILESS_MAIN( DoubanFetcherTest ) 0042 0043 DoubanFetcherTest::DoubanFetcherTest() : AbstractFetcherTest() { 0044 } 0045 0046 void DoubanFetcherTest::initTestCase() { 0047 Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book"); 0048 Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video"); 0049 Tellico::RegisterCollection<Tellico::Data::MusicCollection> registerMusic(Tellico::Data::Collection::Album, "album"); 0050 Tellico::ImageFactory::init(); 0051 0052 m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("douban")); 0053 m_config.writeEntry("Custom Fields", QStringLiteral("douban,origtitle")); 0054 } 0055 0056 void DoubanFetcherTest::testBookTitle() { 0057 QUrl testUrl1 = QUrl::fromLocalFile(QFINDTESTDATA("data/douban_book_search.json")); 0058 QUrl testUrl2 = QUrl::fromLocalFile(QFINDTESTDATA("data/douban_book_details.json")); 0059 auto f = new Tellico::Fetch::DoubanFetcher(this); 0060 f->setTestUrl1(testUrl1); 0061 f->setTestUrl2(testUrl2); 0062 Tellico::Fetch::Fetcher::Ptr fetcher(f); 0063 0064 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Keyword, 0065 QStringLiteral("大设计 列纳德·蒙洛迪诺")); 0066 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0067 0068 QCOMPARE(results.size(), 1); 0069 0070 Tellico::Data::EntryPtr entry = results.at(0); 0071 QVERIFY(entry); 0072 0073 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::Book); 0074 0075 QCOMPARE(entry->field("title"), QString::fromUtf8("大设计")); 0076 QCOMPARE(entry->field("author"), QString::fromUtf8("[英] 斯蒂芬·霍金; 列纳德·蒙洛迪诺")); 0077 QCOMPARE(entry->field("translator"), QString::fromUtf8("吴忠超")); 0078 QCOMPARE(entry->field("publisher"), QString::fromUtf8("湖南科学技术出版社")); 0079 QCOMPARE(entry->field("binding"), QStringLiteral("Hardback")); 0080 QCOMPARE(entry->field("pub_year"), QStringLiteral("2011")); 0081 QCOMPARE(entry->field("isbn"), QStringLiteral("7-53576544-0")); 0082 QCOMPARE(entry->field("pages"), QStringLiteral("176")); 0083 QVERIFY(!entry->field(QStringLiteral("keyword")).isEmpty()); 0084 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0085 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0086 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0087 } 0088 0089 void DoubanFetcherTest::testISBN() { 0090 QUrl testUrl = QUrl::fromLocalFile(QFINDTESTDATA("data/douban_book_isbn.json")); 0091 auto f = new Tellico::Fetch::DoubanFetcher(this); 0092 f->setTestUrl1(testUrl); 0093 Tellico::Fetch::Fetcher::Ptr fetcher(f); 0094 0095 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN, 0096 QStringLiteral("9787535765444")); 0097 fetcher->readConfig(m_config); 0098 0099 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0100 0101 QCOMPARE(results.size(), 1); 0102 0103 Tellico::Data::EntryPtr entry = results.at(0); 0104 QVERIFY(entry); 0105 0106 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::Book); 0107 0108 QCOMPARE(entry->field("title"), QString::fromUtf8("大设计")); 0109 QCOMPARE(entry->field("author"), QString::fromUtf8("[英] 斯蒂芬·霍金; 列纳德·蒙洛迪诺")); 0110 QCOMPARE(entry->field("translator"), QString::fromUtf8("吴忠超")); 0111 QCOMPARE(entry->field("publisher"), QString::fromUtf8("湖南科学技术出版社")); 0112 QCOMPARE(entry->field("binding"), QStringLiteral("Hardback")); 0113 QCOMPARE(entry->field("pub_year"), QStringLiteral("2011")); 0114 QCOMPARE(entry->field("isbn"), QStringLiteral("7-53576544-0")); 0115 QCOMPARE(entry->field("pages"), QStringLiteral("176")); 0116 QCOMPARE(entry->field("origtitle"), QStringLiteral("The Grand Design")); 0117 QCOMPARE(entry->field("douban"), QStringLiteral("https://book.douban.com/subject/5422665/")); 0118 QVERIFY(!entry->field(QStringLiteral("keyword")).isEmpty()); 0119 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0120 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0121 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0122 } 0123 0124 void DoubanFetcherTest::testVideo() { 0125 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword, 0126 QStringLiteral("钢铁侠2")); 0127 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DoubanFetcher(this)); 0128 fetcher->readConfig(m_config); 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->collection()->type(), Tellico::Data::Collection::Video); 0138 0139 QCOMPARE(entry->field("title"), QString::fromUtf8("钢铁侠2")); 0140 QCOMPARE(entry->field("origtitle"), QStringLiteral("Iron Man 2")); 0141 QCOMPARE(entry->field("year"), QStringLiteral("2010")); 0142 QCOMPARE(entry->field("director"), QString::fromUtf8("乔恩·费儒")); 0143 QCOMPARE(entry->field("writer"), QString::fromUtf8("贾斯汀·塞洛克斯")); 0144 QCOMPARE(entry->field("running-time"), QStringLiteral("124")); 0145 QVERIFY(!entry->field(QStringLiteral("genre")).isEmpty()); 0146 QVERIFY(!entry->field(QStringLiteral("cast")).isEmpty()); 0147 // QVERIFY(!entry->field(QStringLiteral("nationality")).isEmpty()); 0148 // QVERIFY(!entry->field(QStringLiteral("language")).isEmpty()); 0149 // QVERIFY(!entry->field(QStringLiteral("keyword")).isEmpty()); 0150 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0151 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0152 QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty()); 0153 } 0154 0155 void DoubanFetcherTest::testMusic() { 0156 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::Keyword, 0157 QLatin1String("Top Gun Original Motion Picture")); 0158 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DoubanFetcher(this)); 0159 0160 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0161 0162 QCOMPARE(results.size(), 1); 0163 0164 Tellico::Data::EntryPtr entry = results.at(0); 0165 QVERIFY(entry); 0166 0167 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::Album); 0168 0169 QCOMPARE(entry->field("title"), QStringLiteral("TOP GUN/SOUNDTRACK")); 0170 QCOMPARE(entry->field("year"), QStringLiteral("2013")); 0171 QCOMPARE(entry->field("artist"), QStringLiteral("Original Motion Picture Soundtrack")); 0172 QCOMPARE(entry->field("label"), QString::fromUtf8("索尼音乐")); 0173 // QCOMPARE(entry->field("medium"), QStringLiteral("Compact Disc")); 0174 QStringList trackList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("track"))); 0175 QCOMPARE(trackList.count(), 10); 0176 QCOMPARE(trackList.front(), QStringLiteral("Danger Zone::Kenny Loggins")); 0177 // QVERIFY(!entry->field(QStringLiteral("keyword")).isEmpty()); 0178 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0179 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0180 } 0181 0182 void DoubanFetcherTest::testMusicAdele() { 0183 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::Keyword, 0184 QLatin1String("Adele 21")); 0185 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DoubanFetcher(this)); 0186 0187 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0188 0189 QCOMPARE(results.size(), 1); 0190 0191 Tellico::Data::EntryPtr entry = results.at(0); 0192 QVERIFY(entry); 0193 0194 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::Album); 0195 0196 QCOMPARE(entry->field("title"), QStringLiteral("21")); 0197 QCOMPARE(entry->field("year"), QStringLiteral("2011")); 0198 QCOMPARE(entry->field("artist"), QStringLiteral("Adele")); 0199 QCOMPARE(entry->field("medium"), QStringLiteral("Compact Disc")); 0200 QStringList trackList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("track"))); 0201 QCOMPARE(trackList.count(), 12); 0202 QCOMPARE(trackList.front(), QStringLiteral("Rolling In the Deep::Adele::3:48")); 0203 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0204 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0205 } 0206 0207 void DoubanFetcherTest::testMusicArtPepper() { 0208 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Album, Tellico::Fetch::Keyword, 0209 QLatin1String("Art Pepper Meets the Rhythm Section")); 0210 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::DoubanFetcher(this)); 0211 0212 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0213 0214 QCOMPARE(results.size(), 1); 0215 0216 Tellico::Data::EntryPtr entry = results.at(0); 0217 QVERIFY(entry); 0218 0219 QCOMPARE(entry->collection()->type(), Tellico::Data::Collection::Album); 0220 0221 QCOMPARE(entry->field("title"), QStringLiteral("Art Pepper Meets The Rhythm Section")); 0222 QCOMPARE(entry->field("year"), QStringLiteral("1991")); 0223 QCOMPARE(entry->field("label"), QStringLiteral("Ojc")); 0224 QCOMPARE(entry->field("artist"), QStringLiteral("Art Pepper")); 0225 QCOMPARE(entry->field("medium"), QStringLiteral("Compact Disc")); 0226 QStringList trackList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("track"))); 0227 QCOMPARE(trackList.count(), 9); 0228 // doesn't seem to have the duration 0229 QVERIFY(trackList.front().startsWith(QStringLiteral("You'd Be So Nice To Come Home To::Art Pepper"))); 0230 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0231 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0232 }