File indexing completed on 2024-05-12 05:10:00

0001 /***************************************************************************
0002     Copyright (C) 2012 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 "griffithtest.h"
0026 
0027 #include "../translators/griffithimporter.h"
0028 #include "../collections/videocollection.h"
0029 #include "../collectionfactory.h"
0030 #include "../fieldformat.h"
0031 #include "../images/imagefactory.h"
0032 #include "../utils/datafileregistry.h"
0033 
0034 #include <KLocalizedString>
0035 
0036 #include <QTest>
0037 #include <QStandardPaths>
0038 
0039 #define QSL(x) QStringLiteral(x)
0040 #define ROWS(entry, fieldName) Tellico::FieldFormat::splitTable(entry->field(QStringLiteral(fieldName)))
0041 
0042 QTEST_GUILESS_MAIN( GriffithTest )
0043 
0044 void GriffithTest::initTestCase() {
0045   QStandardPaths::setTestModeEnabled(true);
0046   KLocalizedString::setApplicationDomain("tellico");
0047   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/griffith2tellico.xsl"));
0048   Tellico::ImageFactory::init();
0049   // need to register the collection type
0050   Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video");
0051 }
0052 
0053 void GriffithTest::testMovies() {
0054   QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/griffith.xml"));
0055   Tellico::Import::GriffithImporter importer(url);
0056   // can't import images for local test
0057   importer.setOptions(importer.options() & ~Tellico::Import::ImportShowImageErrors);
0058   Tellico::Data::CollPtr coll = importer.collection();
0059 
0060   QVERIFY(coll);
0061   QCOMPARE(coll->type(), Tellico::Data::Collection::Video);
0062   QCOMPARE(coll->entryCount(), 5);
0063   QVERIFY(importer.canImport(coll->type()));
0064 
0065   Tellico::Data::EntryPtr entry = coll->entryById(1);
0066   QVERIFY(entry);
0067   QCOMPARE(entry->field(QSL("title")), QSL("Serendipity"));
0068   QCOMPARE(entry->field(QSL("origtitle")), QSL("Serendipity"));
0069   QCOMPARE(entry->field(QSL("director")), QSL("Peter Chelsom"));
0070   QCOMPARE(entry->field(QSL("year")), QSL("2001"));
0071   QCOMPARE(entry->field(QSL("certification")), QSL("PG-13 (USA)"));
0072   QCOMPARE(entry->field(QSL("nationality")), QSL("USA"));
0073   QCOMPARE(entry->field(QSL("genre")), QSL("Comedy; Romance; Fantasy"));
0074   QCOMPARE(entry->field(QSL("rating")), QSL("6"));
0075   QCOMPARE(entry->field(QSL("running-time")), QSL("90"));
0076   QCOMPARE(entry->field(QSL("studio")), QSL("studio"));
0077   QCOMPARE(entry->field(QSL("seen")), QSL("true"));
0078   QCOMPARE(entry->field(QSL("medium")), QSL("DVD"));
0079   QCOMPARE(ROWS(entry, "cast").first(), QSL("John Cusack::Jonathan Trager"));
0080   QVERIFY(!entry->field(QSL("plot")).isEmpty());
0081   // cover will be empty since local images don't exist
0082 }