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

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 "filmasterfetchertest.h"
0028 
0029 #include "../fetch/fetcherjob.h"
0030 #include "../fetch/filmasterfetcher.h"
0031 #include "../collections/videocollection.h"
0032 #include "../entry.h"
0033 #include "../images/imagefactory.h"
0034 
0035 #include <QTest>
0036 
0037 QTEST_MAIN( FilmasterFetcherTest )
0038 
0039 FilmasterFetcherTest::FilmasterFetcherTest() : AbstractFetcherTest() {
0040 }
0041 
0042 void FilmasterFetcherTest::initTestCase() {
0043   Tellico::ImageFactory::init();
0044 
0045   m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("The Man from Snowy River"));
0046   m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("1982"));
0047   m_fieldValues.insert(QStringLiteral("genre"), QStringLiteral("western; romans; familijny; dramat"));
0048   m_fieldValues.insert(QStringLiteral("director"), QStringLiteral("George Miller"));
0049 //  m_fieldValues.insert(QStringLiteral("nationality"), QStringLiteral("Australia"));
0050 }
0051 
0052 void FilmasterFetcherTest::testTitle() {
0053   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Title,
0054                                        QStringLiteral("Man From Snowy River"));
0055   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::FilmasterFetcher(this));
0056 
0057   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 2);
0058 
0059   QCOMPARE(results.size(), 2);
0060 
0061   Tellico::Data::EntryPtr entry = results.at(1);
0062   QVERIFY(entry);
0063 
0064   QHashIterator<QString, QString> i(m_fieldValues);
0065   while(i.hasNext()) {
0066     i.next();
0067     QString result = entry->field(i.key()).toLower();
0068     QCOMPARE(result, i.value().toLower());
0069   }
0070   QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast")));
0071   QCOMPARE(castList.at(0), QStringLiteral("Tom Burlinson::Jim Craig"));
0072 // 2017-10-01: cover link is now invalid
0073 //  QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0074 //  QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0075 //   2017-05-01: plot is no longer being returned
0076 //  QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
0077 }
0078 
0079 void FilmasterFetcherTest::testPerson() {
0080   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Person,
0081                                        QStringLiteral("Tom Burlinson"));
0082   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::FilmasterFetcher(this));
0083 
0084   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0085 
0086   QVERIFY(results.size() > 0);
0087   Tellico::Data::EntryPtr entry;  //  results can be randomly ordered, loop until wee find the one we want
0088   for(int i = 0; i < results.size(); ++i) {
0089     Tellico::Data::EntryPtr test = results.at(i);
0090     if(test->field(QStringLiteral("title")).toLower() == QStringLiteral("the man from snowy river")) {
0091       entry = test;
0092       break;
0093     } else {
0094       qDebug() << "skipping" << test->title();
0095     }
0096   }
0097   QVERIFY(entry);
0098 
0099   QHashIterator<QString, QString> i(m_fieldValues);
0100   while(i.hasNext()) {
0101     i.next();
0102     QString result = entry->field(i.key()).toLower();
0103     QCOMPARE(result, i.value().toLower());
0104   }
0105   QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast")));
0106   QCOMPARE(castList.at(0), QStringLiteral("Tom Burlinson::Jim Craig"));
0107 // 2017-10-01: cover link is now invalid
0108 //  QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0109 //  QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0110 //   2017-05-01: plot is no longer being returned
0111 //  QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
0112 }
0113 
0114 void FilmasterFetcherTest::testKeyword() {
0115   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Video, Tellico::Fetch::Keyword,
0116                                        QStringLiteral("Man From Snowy River"));
0117   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::FilmasterFetcher(this));
0118 
0119   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 2);
0120 
0121   QCOMPARE(results.size(), 2);
0122 
0123   Tellico::Data::EntryPtr entry = results.at(1);
0124   QVERIFY(entry);
0125 
0126   QHashIterator<QString, QString> i(m_fieldValues);
0127   while(i.hasNext()) {
0128     i.next();
0129     QString result = entry->field(i.key()).toLower();
0130     QCOMPARE(result, i.value().toLower());
0131   }
0132   QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast")));
0133   QCOMPARE(castList.at(0), QStringLiteral("Tom Burlinson::Jim Craig"));
0134 // 2017-10-01: cover link is now invalid
0135 //  QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
0136  // QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
0137 //   2017-05-01: plot is no longer being returned
0138 //  QVERIFY(!entry->field(QStringLiteral("plot")).isEmpty());
0139 }