File indexing completed on 2024-05-12 16:46:24
0001 /*************************************************************************** 0002 Copyright (C) 2012-2019 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 "thegamesdbfetchertest.h" 0026 0027 #include "../fetch/thegamesdbfetcher.h" 0028 #include "../collectionfactory.h" 0029 #include "../entry.h" 0030 #include "../images/imagefactory.h" 0031 0032 #include <KSharedConfig> 0033 0034 #include <QTest> 0035 0036 QTEST_GUILESS_MAIN( TheGamesDBFetcherTest ) 0037 0038 TheGamesDBFetcherTest::TheGamesDBFetcherTest() : AbstractFetcherTest() { 0039 } 0040 0041 void TheGamesDBFetcherTest::initTestCase() { 0042 Tellico::ImageFactory::init(); 0043 0044 QString configFile = QFINDTESTDATA("tellicotest_private.config"); 0045 if(!configFile.isEmpty()) { 0046 m_config = KSharedConfig::openConfig(configFile, KConfig::SimpleConfig)->group(QStringLiteral("TGDB")); 0047 } 0048 0049 m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("GoldenEye 007")); 0050 m_fieldValues.insert(QStringLiteral("platform"), QStringLiteral("Nintendo 64")); 0051 m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("1997")); 0052 m_fieldValues.insert(QStringLiteral("certification"), QStringLiteral("Teen")); 0053 m_fieldValues.insert(QStringLiteral("genre"), QStringLiteral("Action; Adventure; Shooter; Stealth")); 0054 m_fieldValues.insert(QStringLiteral("publisher"), QStringLiteral("Nintendo")); 0055 m_fieldValues.insert(QStringLiteral("developer"), QStringLiteral("Rare, Ltd.")); 0056 m_fieldValues.insert(QStringLiteral("num-player"), QStringLiteral("4")); 0057 0058 // need to delete cached data 0059 QFile genreFile(Tellico::Fetch::TheGamesDBFetcher::dataFileName(Tellico::Fetch::TheGamesDBFetcher::Genre)); 0060 if(genreFile.exists()) { 0061 genreFile.remove(); 0062 } 0063 QFile publisherFile(Tellico::Fetch::TheGamesDBFetcher::dataFileName(Tellico::Fetch::TheGamesDBFetcher::Publisher)); 0064 if(publisherFile.exists()) { 0065 publisherFile.remove(); 0066 } 0067 QFile developerFile(Tellico::Fetch::TheGamesDBFetcher::dataFileName(Tellico::Fetch::TheGamesDBFetcher::Developer)); 0068 if(developerFile.exists()) { 0069 developerFile.remove(); 0070 } 0071 } 0072 0073 void TheGamesDBFetcherTest::testTitle() { 0074 if(!m_config.isValid()) { 0075 QSKIP("This test requires a config file with TGDB settings.", SkipAll); 0076 } 0077 0078 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Game, Tellico::Fetch::Title, 0079 QStringLiteral("Goldeneye")); 0080 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::TheGamesDBFetcher(this)); 0081 fetcher->readConfig(m_config); 0082 0083 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0084 0085 QCOMPARE(results.size(), 1); 0086 0087 Tellico::Data::EntryPtr entry = results.at(0); 0088 QHashIterator<QString, QString> i(m_fieldValues); 0089 while(i.hasNext()) { 0090 i.next(); 0091 QString result = entry->field(i.key()).toLower(); 0092 QCOMPARE(result, i.value().toLower()); 0093 } 0094 QVERIFY(!entry->field(QStringLiteral("description")).isEmpty()); 0095 QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty()); 0096 QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); 0097 }