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