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

0001 /***************************************************************************
0002     Copyright (C) 2020 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 "collectorztest.h"
0028 
0029 #include "../translators/collectorzimporter.h"
0030 #include "../collections/bookcollection.h"
0031 #include "../collections/videocollection.h"
0032 #include "../collections/musiccollection.h"
0033 #include "../collectionfactory.h"
0034 #include "../images/imagefactory.h"
0035 #include "../fieldformat.h"
0036 #include "../utils/datafileregistry.h"
0037 
0038 #include <KLocalizedString>
0039 
0040 #include <QTest>
0041 #include <QStandardPaths>
0042 
0043 QTEST_GUILESS_MAIN( CollectorzTest )
0044 
0045 void CollectorzTest::initTestCase() {
0046   QStandardPaths::setTestModeEnabled(true);
0047   KLocalizedString::setApplicationDomain("tellico");
0048   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/collectorz2tellico.xsl"));
0049   // need to register the collection type
0050   Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book");
0051   Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video");
0052   Tellico::RegisterCollection<Tellico::Data::MusicCollection> registerMusic(Tellico::Data::Collection::Album, "album");
0053   Tellico::ImageFactory::init();
0054 }
0055 
0056 void CollectorzTest::testBooks() {
0057   QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/collectorz_books.xml"));
0058   Tellico::Import::CollectorzImporter importer(url);
0059   QVERIFY(importer.canImport(Tellico::Data::Collection::Book));
0060   Tellico::Data::CollPtr coll = importer.collection();
0061 
0062   QVERIFY(coll);
0063   QCOMPARE(coll->type(), Tellico::Data::Collection::Book);
0064   QCOMPARE(coll->entryCount(), 33);
0065 
0066   Tellico::Data::EntryPtr entry = coll->entryById(476);
0067   QVERIFY(entry);
0068   QCOMPARE(entry->field("title"), QStringLiteral("1812: The Rivers of War"));
0069   QCOMPARE(entry->field("pub_year"), QStringLiteral("2006"));
0070   QCOMPARE(entry->field("author"), QStringLiteral("Eric Flint"));
0071   QCOMPARE(entry->field("publisher"), QStringLiteral("Del Rey Book"));
0072   QCOMPARE(entry->field("isbn"), QStringLiteral("0-345-46568-7"));
0073   QCOMPARE(entry->field("binding"), QStringLiteral("Paperback"));
0074   QCOMPARE(entry->field("series"), QStringLiteral("Trail of Glory"));
0075   QCOMPARE(entry->field("series_num"), QStringLiteral("1"));
0076   QCOMPARE(entry->field("read"), QStringLiteral("true"));
0077   QCOMPARE(entry->field("genre"), QStringLiteral("Alternate History"));
0078   QCOMPARE(entry->field("mdate"), QStringLiteral("2017-04-29"));
0079   QVERIFY(!entry->field("plot").isEmpty());
0080   QVERIFY(!entry->field("comments").isEmpty());
0081   QVERIFY(!entry->field("cover").isEmpty());
0082   QVERIFY(!entry->field("cover").contains(QLatin1Char('/')));
0083   QVERIFY(!entry->field("cover").contains(QLatin1Char('\\')));
0084 }
0085 
0086 void CollectorzTest::testMovies() {
0087   QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/collectorz_movies.xml"));
0088   Tellico::Import::CollectorzImporter importer(url);
0089   QVERIFY(importer.canImport(Tellico::Data::Collection::Video));
0090   Tellico::Data::CollPtr coll = importer.collection();
0091 
0092   QVERIFY(coll);
0093   QCOMPARE(coll->type(), Tellico::Data::Collection::Video);
0094   QCOMPARE(coll->entryCount(), 14);
0095 
0096   // first a movie
0097   Tellico::Data::EntryPtr entry = coll->entryById(234);
0098   QVERIFY(entry);
0099   QCOMPARE(entry->field("title"), QStringLiteral("Shaun Of The Dead"));
0100   QCOMPARE(entry->field("year"), QStringLiteral("2004"));
0101   QCOMPARE(entry->field("nationality"), QStringLiteral("UK"));
0102   QCOMPARE(entry->field("language"), QStringLiteral("English"));
0103   QCOMPARE(entry->field("director"), QStringLiteral("Edgar Wright"));
0104   QCOMPARE(entry->field("producer"), QStringLiteral("Tim Bevan; Eric Fellner"));
0105   QCOMPARE(entry->field("writer"), QStringLiteral("Edgar Wright; Simon Pegg"));
0106   QStringList cast = Tellico::FieldFormat::splitTable(entry->field("cast"));
0107   QCOMPARE(cast.count(), 10);
0108   QStringList cast0 = QStringList() << QStringLiteral("Kate Ashfield") << QStringLiteral("Liz");
0109   QCOMPARE(cast.at(0), cast0.join(Tellico::FieldFormat::columnDelimiterString()));
0110   QCOMPARE(entry->field("studio"), QStringLiteral("Universal Studios"));
0111   QCOMPARE(entry->field("medium"), QStringLiteral("DVD"));
0112   QCOMPARE(entry->field("color"), QStringLiteral("Color"));
0113   QCOMPARE(entry->field("aspect-ratio"), QStringLiteral("2.35:1"));
0114   QCOMPARE(entry->field("widescreen"), QStringLiteral("true"));
0115   QCOMPARE(entry->field("running-time"), QStringLiteral("100"));
0116   QCOMPARE(entry->field("certification"), QStringLiteral("R (USA)"));
0117   QCOMPARE(entry->field("genre"), QStringLiteral("Comedy; Horror; Thriller"));
0118   QCOMPARE(entry->field("subtitle"), QStringLiteral("English; French"));
0119   QCOMPARE(entry->field("audio-track"), QStringLiteral("030 Dolby Digital 5.1 [English]; 030 Dolby Digital 5.1 [French]; 030 Dolby Digital 5.1 [Spanish]"));
0120   QCOMPARE(entry->field("region"), QStringLiteral("Region 1"));
0121   QCOMPARE(entry->field("rating"), QStringLiteral("3"));
0122   QCOMPARE(entry->field("pur_price"), QStringLiteral("$44.55"));
0123   QCOMPARE(entry->field("pur_date"), QStringLiteral("2012-03-23"));
0124   QCOMPARE(entry->field("imdb"), QStringLiteral("http://www.imdb.com/title/tt0365748"));
0125   QVERIFY(!entry->field("plot").isEmpty());
0126   QCOMPARE(entry->field("mdate"), QStringLiteral("2019-08-25"));
0127 }
0128 
0129 void CollectorzTest::testMusic() {
0130   QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/collectorz_music.xml"));
0131   Tellico::Import::CollectorzImporter importer(url);
0132   QVERIFY(importer.canImport(Tellico::Data::Collection::Album));
0133   Tellico::Data::CollPtr coll = importer.collection();
0134 
0135   QVERIFY(coll);
0136   QCOMPARE(coll->type(), Tellico::Data::Collection::Album);
0137   QCOMPARE(coll->entryCount(), 16);
0138 
0139   Tellico::Data::EntryPtr entry = coll->entryById(275);
0140   QVERIFY(entry);
0141   QCOMPARE(entry->field("title"), QStringLiteral("A Quiet Normal Life: The Best Of Warren Zevon"));
0142   QCOMPARE(entry->field("artist"), QStringLiteral("Warren Zevon"));
0143   QCOMPARE(entry->field("year"), QStringLiteral("1986"));
0144   QCOMPARE(entry->field("genre"), QStringLiteral("Rock"));
0145   QCOMPARE(entry->field("medium"), QStringLiteral("Compact Disc"));
0146   QCOMPARE(entry->field("label"), QStringLiteral("Elektra"));
0147   QStringList tracks = Tellico::FieldFormat::splitTable(entry->field("track"));
0148   QCOMPARE(tracks.count(), 14);
0149   QStringList track1 = QStringList() << QStringLiteral("Werewolves Of London") << QStringLiteral("Warren Zevon") << QStringLiteral("03:28");
0150   QCOMPARE(tracks.at(0), track1.join(Tellico::FieldFormat::columnDelimiterString()));
0151   QCOMPARE(entry->field("pur_price"), QStringLiteral("$11.98"));
0152   QVERIFY(!entry->field("amazon").isEmpty());
0153   QCOMPARE(entry->field("mdate"), QStringLiteral("2017-04-29"));
0154 
0155   // test conductor
0156   entry = coll->entryById(192);
0157   QVERIFY(entry);
0158   QCOMPARE(entry->field("title"), QStringLiteral("Great Performances: Grieg/Schumann Piano Concertos"));
0159   QCOMPARE(entry->field("artist"), QStringLiteral("The Cleveland Orchestra; Leon Fleisher"));
0160   QCOMPARE(entry->field("year"), QStringLiteral("2004"));
0161   QCOMPARE(entry->field("conductor"), QStringLiteral("George Szell"));
0162 }