File indexing completed on 2024-05-12 16:46:13
0001 /*************************************************************************** 0002 Copyright (C) 2011 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 "animenfofetchertest.h" 0028 0029 #include "../fetch/animenfofetcher.h" 0030 #include "../entry.h" 0031 #include "../collections/videocollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../images/imagefactory.h" 0034 #include "../fieldformat.h" 0035 0036 #include <KSharedConfig> 0037 0038 #include <QTest> 0039 0040 QTEST_GUILESS_MAIN( AnimenfoFetcherTest ) 0041 0042 AnimenfoFetcherTest::AnimenfoFetcherTest() : AbstractFetcherTest() { 0043 } 0044 0045 void AnimenfoFetcherTest::initTestCase() { 0046 Tellico::ImageFactory::init(); 0047 // Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video"); 0048 0049 m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("animenfo")); 0050 m_config.writeEntry("Custom Fields", QStringLiteral("alttitle,episodes,origtitle,distributor,animenfo,animenfo-rating")); 0051 } 0052 0053 void AnimenfoFetcherTest::testMegami() { 0054 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword, QStringLiteral("Aa! Megami-sama!")); 0055 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::AnimeNfoFetcher(this)); 0056 fetcher->readConfig(m_config); 0057 0058 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0059 0060 QCOMPARE(results.size(), 1); 0061 0062 // the first entry had better be the right one 0063 Tellico::Data::EntryPtr entry = results.at(0); 0064 QVERIFY(entry); 0065 0066 QCOMPARE(entry->field("title"), QStringLiteral("Aa! Megami-sama!: Together Forever")); 0067 QCOMPARE(entry->field("year"), QStringLiteral("2011")); 0068 QCOMPARE(entry->field("episodes"), QStringLiteral("2")); 0069 QCOMPARE(entry->field("studio"), QStringLiteral("AIC (Anime International Company)")); 0070 QCOMPARE(entry->field("origtitle"), QString::fromUtf8("ああっ女神さまっ ~ いつも二人で")); 0071 QVERIFY(entry->field("plot").startsWith(QStringLiteral("Keiichi finds out"))); 0072 QVERIFY(!entry->field("cover").isEmpty()); 0073 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0074 } 0075 0076 void AnimenfoFetcherTest::testHachimitsu() { 0077 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword, QStringLiteral("Hachimitsu to Clover")); 0078 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::AnimeNfoFetcher(this)); 0079 fetcher->readConfig(m_config); 0080 0081 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0082 0083 QCOMPARE(results.size(), 1); 0084 0085 // the first entry had better be the right one 0086 Tellico::Data::EntryPtr entry = results.at(0); 0087 QVERIFY(entry); 0088 0089 QCOMPARE(entry->field("title"), QStringLiteral("Hachimitsu to Clover")); 0090 QCOMPARE(entry->field("year"), QStringLiteral("2005")); 0091 QCOMPARE(entry->field("episodes"), QStringLiteral("26")); 0092 QCOMPARE(entry->field("keyword"), QStringLiteral("TV")); 0093 QCOMPARE(entry->field("genre"), QStringLiteral("Comedy; Drama; Romance")); 0094 QCOMPARE(entry->field("studio"), QStringLiteral("J.C.STAFF")); 0095 QCOMPARE(entry->field("origtitle"), QString::fromUtf8("ハチミツとクローバー")); 0096 QCOMPARE(entry->field("director"), QString::fromUtf8("Kasai Kenichi (カサヰ ケンイチ)")); 0097 QCOMPARE(entry->field("writer"), QString::fromUtf8("Kuroda Yosuke (黒田洋介)")); 0098 QCOMPARE(entry->field("alttitle"), QStringLiteral("Honey and Clover")); 0099 QCOMPARE(entry->field("animenfo-rating"), QStringLiteral("9")); 0100 QVERIFY(entry->field("plot").startsWith(QStringLiteral("Takemoto, Mayama, and Morita are students"))); 0101 QVERIFY(!entry->field("cover").isEmpty()); 0102 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0103 QVERIFY(!entry->field("animenfo").isEmpty()); 0104 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0105 QCOMPARE(castList.count(), 7); 0106 QCOMPARE(castList.at(0), QString::fromUtf8("Kudo Haruka (工藤晴香)::Hanamoto Hagumi")); 0107 } 0108 0109 void AnimenfoFetcherTest::testGhost() { 0110 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Keyword, QStringLiteral("Ghost in the Shell")); 0111 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::AnimeNfoFetcher(this)); 0112 fetcher->readConfig(m_config); 0113 0114 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0115 0116 QCOMPARE(results.size(), 1); 0117 0118 // the first entry had better be the right one 0119 Tellico::Data::EntryPtr entry = results.at(0); 0120 QVERIFY(entry); 0121 0122 QCOMPARE(entry->field("title"), QStringLiteral("Kokaku Kido Tai")); 0123 QCOMPARE(entry->field("pub_year"), QStringLiteral("1991")); 0124 QCOMPARE(entry->field("genre"), QStringLiteral("Action; Science-Fiction")); 0125 QCOMPARE(entry->field("publisher"), QStringLiteral("Kodansha")); 0126 QCOMPARE(entry->field("origtitle"), QString::fromUtf8("攻殻機動隊")); 0127 QCOMPARE(entry->field("author"), QString::fromUtf8("Shiro Masamune (士郎 正宗)")); 0128 QCOMPARE(entry->field("alttitle"), QStringLiteral("Ghost in the Shell")); 0129 QVERIFY(!entry->field("cover").isEmpty()); 0130 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0131 QVERIFY(!entry->field("animenfo").isEmpty()); 0132 }