File indexing completed on 2024-05-12 05:09:59

0001 /***************************************************************************
0002     Copyright (C) 2010-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 "gcstarfetchertest.h"
0028 
0029 #include "../fetch/gcstarpluginfetcher.h"
0030 #include "../entry.h"
0031 #include "../collections/videocollection.h"
0032 #include "../collectionfactory.h"
0033 #include "../images/imagefactory.h"
0034 #include "../images/image.h"
0035 #include "../fieldformat.h"
0036 #include "../utils/datafileregistry.h"
0037 
0038 #include <KSharedConfig>
0039 #include <KConfigGroup>
0040 
0041 #include <QTest>
0042 #include <QStandardPaths>
0043 
0044 QTEST_GUILESS_MAIN( GCstarFetcherTest )
0045 
0046 GCstarFetcherTest::GCstarFetcherTest() : AbstractFetcherTest() {
0047 }
0048 
0049 void GCstarFetcherTest::initTestCase() {
0050   const QString gcstar = QStandardPaths::findExecutable(QStringLiteral("gcstar"));
0051   if(gcstar.isEmpty()) {
0052     QSKIP("This test requires gcstar", SkipAll);
0053   }
0054 
0055   Tellico::ImageFactory::init();
0056   Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video");
0057 
0058   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/gcstar2tellico.xsl"));
0059 }
0060 
0061 void GCstarFetcherTest::testSnowyRiver() {
0062   KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("gcstar"));
0063   cg.writeEntry("CollectionType", QStringLiteral("3"));
0064   cg.writeEntry("Plugin", QStringLiteral("Amazon (US)"));
0065 
0066   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title, QStringLiteral("Superman Returns"));
0067   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::GCstarPluginFetcher(this));
0068   fetcher->readConfig(cg);
0069 
0070   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0071 
0072   QCOMPARE(results.size(), 1);
0073 
0074   // the first entry had better be the right one
0075   Tellico::Data::EntryPtr entry = results.at(0);
0076 
0077   QCOMPARE(entry->field("title"), QStringLiteral("Superman Returns"));
0078   QCOMPARE(entry->field("year"), QStringLiteral("2006"));
0079   QVERIFY(!entry->field("cover").isEmpty());
0080   QVERIFY(!Tellico::ImageFactory::imageById(entry->field("cover")).isNull());
0081 }