File indexing completed on 2024-05-12 05:09:56
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 #undef QT_NO_CAST_FROM_ASCII 0026 0027 #include "delicioustest.h" 0028 0029 #include "../translators/deliciousimporter.h" 0030 #include "../collections/bookcollection.h" 0031 #include "../collections/videocollection.h" 0032 #include "../collections/musiccollection.h" 0033 #include "../collections/gamecollection.h" 0034 #include "../collectionfactory.h" 0035 #include "../filter.h" 0036 #include "../fieldformat.h" 0037 #include "../utils/datafileregistry.h" 0038 0039 #include <KLocalizedString> 0040 0041 #include <QTest> 0042 0043 #define FIELDS(entry, fieldName) Tellico::FieldFormat::splitValue(entry->field(fieldName)) 0044 #define ROWS(entry, fieldName) Tellico::FieldFormat::splitTable(entry->field(fieldName)) 0045 0046 QTEST_GUILESS_MAIN( DeliciousTest ) 0047 0048 void DeliciousTest::initTestCase() { 0049 KLocalizedString::setApplicationDomain("tellico"); 0050 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/delicious2tellico.xsl")); 0051 // need to register the collection type 0052 Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book"); 0053 Tellico::RegisterCollection<Tellico::Data::VideoCollection> registerVideo(Tellico::Data::Collection::Video, "video"); 0054 Tellico::RegisterCollection<Tellico::Data::MusicCollection> registerMusic(Tellico::Data::Collection::Album, "album"); 0055 Tellico::RegisterCollection<Tellico::Data::GameCollection> registerGame(Tellico::Data::Collection::Game, "game"); 0056 } 0057 0058 void DeliciousTest::testBooks1() { 0059 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious1_books.xml")); 0060 Tellico::Import::DeliciousImporter importer(url); 0061 QVERIFY(importer.canImport(Tellico::Data::Collection::Book)); 0062 Tellico::Data::CollPtr coll = importer.collection(); 0063 0064 QVERIFY(coll); 0065 QCOMPARE(coll->type(), Tellico::Data::Collection::Book); 0066 QCOMPARE(coll->entryCount(), 5); 0067 0068 Tellico::Data::EntryPtr entry = coll->entryById(1); 0069 QVERIFY(entry); 0070 QCOMPARE(entry->field("title"), QStringLiteral("Lost in Translation")); 0071 QCOMPARE(entry->field("pub_year"), QStringLiteral("1998")); 0072 QCOMPARE(entry->field("author"), QStringLiteral("Nicole Mones; Robby Stephenson")); 0073 QCOMPARE(entry->field("publisher"), QStringLiteral("Delacorte Press")); 0074 QCOMPARE(entry->field("isbn"), QStringLiteral("0-385-31934-7")); 0075 QCOMPARE(entry->field("binding"), QStringLiteral("Hardback")); 0076 QCOMPARE(entry->field("keyword"), QStringLiteral("United States; Contemporary & Robby")); 0077 QCOMPARE(entry->field("pages"), QStringLiteral("384")); 0078 QCOMPARE(entry->field("rating"), QStringLiteral("4")); 0079 QCOMPARE(entry->field("pur_price"), QStringLiteral("$23.95")); 0080 QCOMPARE(entry->field("pur_date"), QStringLiteral("07-08-2006")); 0081 QVERIFY(entry->field("comments").startsWith(QStringLiteral("<p><span style=\"font-size:12pt;\">Nicole Mones doesn't"))); 0082 } 0083 0084 void DeliciousTest::testBooks2() { 0085 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious2_books.xml")); 0086 Tellico::Import::DeliciousImporter importer(url); 0087 Tellico::Data::CollPtr coll = importer.collection(); 0088 0089 QVERIFY(coll); 0090 QCOMPARE(coll->type(), Tellico::Data::Collection::Book); 0091 QCOMPARE(coll->entryCount(), 7); 0092 0093 Tellico::Data::EntryPtr entry = coll->entryById(1); 0094 QVERIFY(entry); 0095 QCOMPARE(entry->field("title"), QStringLiteral("The Restaurant at the End of the Universe")); 0096 QCOMPARE(entry->field("isbn"), QStringLiteral("0-517-54535-7")); 0097 QCOMPARE(entry->field("cdate"), QStringLiteral("2007-12-19")); 0098 QCOMPARE(entry->field("mdate"), QStringLiteral("2009-06-11")); 0099 QCOMPARE(FIELDS(entry, "author").count(), 1); 0100 QCOMPARE(FIELDS(entry, "author").first(), QStringLiteral("Douglas Adams")); 0101 QCOMPARE(entry->field("binding"), QStringLiteral("Hardback")); 0102 QCOMPARE(entry->field("rating"), QStringLiteral("4.5")); // visually, this gets shown as 4 stars 0103 QCOMPARE(entry->field("pages"), QStringLiteral("250")); 0104 QCOMPARE(entry->field("pub_year"), QStringLiteral("1982")); 0105 QCOMPARE(entry->field("publisher"), QStringLiteral("Harmony")); 0106 QCOMPARE(entry->field("pur_date"), QStringLiteral("2007-12-18")); 0107 QCOMPARE(entry->field("pur_price"), QStringLiteral("$12.95")); 0108 QCOMPARE(entry->field("signed"), QStringLiteral("true")); 0109 QCOMPARE(entry->field("condition"), QStringLiteral("Used")); 0110 } 0111 0112 void DeliciousTest::testMovies1() { 0113 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious1_movies.xml")); 0114 Tellico::Import::DeliciousImporter importer(url); 0115 QVERIFY(importer.canImport(Tellico::Data::Collection::Video)); 0116 Tellico::Data::CollPtr coll = importer.collection(); 0117 0118 QVERIFY(coll); 0119 QCOMPARE(coll->type(), Tellico::Data::Collection::Video); 0120 QCOMPARE(coll->entryCount(), 4); 0121 0122 // first a movie 0123 Tellico::Data::EntryPtr entry = coll->entryById(2); 0124 QVERIFY(entry); 0125 QCOMPARE(entry->field("title"), QStringLiteral("Driving Miss Daisy")); 0126 QCOMPARE(entry->field("year"), QStringLiteral("1990")); 0127 QCOMPARE(entry->field("nationality"), QStringLiteral("USA")); 0128 QCOMPARE(entry->field("director"), QStringLiteral("Bruce Beresford")); 0129 QStringList cast = QStringList() << QStringLiteral("Morgan Freeman") << QStringLiteral("Jessica Tandy") << QStringLiteral("Dan Aykroyd") << QStringLiteral("Patti LuPone") << QStringLiteral("Esther Rolle"); 0130 QCOMPARE(entry->field("cast"), cast.join(Tellico::FieldFormat::rowDelimiterString())); 0131 QCOMPARE(entry->field("format"), QStringLiteral("NTSC")); 0132 QCOMPARE(entry->field("medium"), QStringLiteral("DVD")); 0133 QCOMPARE(entry->field("color"), QStringLiteral("Color")); 0134 QCOMPARE(entry->field("aspect-ratio"), QStringLiteral("1.85:1")); 0135 QCOMPARE(entry->field("audio-track"), QStringLiteral("Dolby")); 0136 QCOMPARE(entry->field("widescreen"), QStringLiteral("true")); 0137 QCOMPARE(entry->field("running-time"), QStringLiteral("99")); 0138 QCOMPARE(entry->field("certification"), QStringLiteral("PG (USA)")); 0139 QCOMPARE(entry->field("region"), QStringLiteral("Region 1")); 0140 QCOMPARE(entry->field("rating"), QStringLiteral("4.5")); 0141 QCOMPARE(entry->field("pur_price"), QStringLiteral("$14.98")); 0142 QCOMPARE(entry->field("pur_date"), QStringLiteral("25-03-2006")); 0143 QVERIFY(entry->field("keyword").startsWith(QStringLiteral("Period Piece; Race Relations"))); 0144 0145 // check the TV show, too 0146 entry = coll->entryById(4); 0147 QVERIFY(entry); 0148 QCOMPARE(entry->field("title"), QStringLiteral("South Park - The Complete Sixth Season")); 0149 QCOMPARE(entry->field("year"), QStringLiteral("1997")); 0150 QCOMPARE(entry->field("nationality"), QStringLiteral("USA")); 0151 QCOMPARE(entry->field("studio"), QStringLiteral("Comedy Central")); 0152 QCOMPARE(entry->field("director"), QStringLiteral("Trey Parker; Matt Stone")); 0153 // the shelf name gets added to keyword list 0154 QVERIFY(entry->field("keyword").contains(QStringLiteral("TV Shows"))); 0155 0156 Tellico::FilterList filters = coll->filters(); 0157 QCOMPARE(filters.count(), 1); 0158 0159 Tellico::FilterPtr filter = filters.first(); 0160 QVERIFY(filter); 0161 QCOMPARE(filter->name(), QStringLiteral("TV Shows")); 0162 QVERIFY(filter->matches(entry)); 0163 } 0164 0165 void DeliciousTest::testMovies2() { 0166 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious2_movies.xml")); 0167 Tellico::Import::DeliciousImporter importer(url); 0168 Tellico::Data::CollPtr coll = importer.collection(); 0169 0170 QVERIFY(coll); 0171 QCOMPARE(coll->type(), Tellico::Data::Collection::Video); 0172 QCOMPARE(coll->entryCount(), 4); 0173 0174 Tellico::Data::EntryPtr entry = coll->entryById(2); 0175 QVERIFY(entry); 0176 QCOMPARE(entry->field("title"), QStringLiteral("2001 - A Space Odyssey")); 0177 QCOMPARE(entry->field("certification"), QStringLiteral("G (USA)")); 0178 QCOMPARE(entry->field("nationality"), QStringLiteral("USA")); 0179 QCOMPARE(entry->field("aspect-ratio"), QStringLiteral("2.35:1")); 0180 QCOMPARE(entry->field("audio-track"), QStringLiteral("Dolby")); 0181 QCOMPARE(entry->field("widescreen"), QStringLiteral("true")); 0182 QCOMPARE(entry->field("director"), QStringLiteral("Stanley Kubrick")); 0183 QCOMPARE(entry->field("color"), QStringLiteral("Color")); 0184 QCOMPARE(entry->field("format"), QStringLiteral("NTSC")); 0185 QCOMPARE(entry->field("medium"), QStringLiteral("DVD")); 0186 QCOMPARE(entry->field("running-time"), QStringLiteral("148")); 0187 QCOMPARE(entry->field("rating"), QStringLiteral("4")); 0188 QCOMPARE(entry->field("year"), QStringLiteral("1968")); 0189 QCOMPARE(entry->field("pur_date"), QStringLiteral("2007-12-19")); 0190 QCOMPARE(entry->field("cdate"), QStringLiteral("2007-12-20")); 0191 QCOMPARE(entry->field("mdate"), QStringLiteral("2009-06-11")); 0192 0193 entry = coll->entryById(4); 0194 QVERIFY(entry); 0195 QCOMPARE(entry->field("region"), QStringLiteral("Region 1")); 0196 } 0197 0198 void DeliciousTest::testMusic1() { 0199 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious1_music.xml")); 0200 Tellico::Import::DeliciousImporter importer(url); 0201 QVERIFY(importer.canImport(Tellico::Data::Collection::Album)); 0202 Tellico::Data::CollPtr coll = importer.collection(); 0203 0204 QVERIFY(coll); 0205 QCOMPARE(coll->type(), Tellico::Data::Collection::Album); 0206 QCOMPARE(coll->entryCount(), 3); 0207 0208 // first a movie 0209 Tellico::Data::EntryPtr entry = coll->entryById(1); 0210 QVERIFY(entry); 0211 QCOMPARE(entry->field("title"), QStringLiteral("Are You Listening?")); 0212 QCOMPARE(entry->field("artist"), QStringLiteral("Dolores O'Riordan")); 0213 QCOMPARE(entry->field("year"), QStringLiteral("2007")); 0214 QCOMPARE(entry->field("medium"), QStringLiteral("Compact Disc")); 0215 QCOMPARE(entry->field("label"), QStringLiteral("Sanctuary Records")); 0216 QCOMPARE(ROWS(entry, "track").count(), 12); 0217 QCOMPARE(ROWS(entry, "track").first(), QStringLiteral("Ordinary Day")); 0218 QCOMPARE(entry->field("pur_price"), QStringLiteral("$15.98")); 0219 QCOMPARE(entry->field("pur_date"), QStringLiteral("27-06-2008")); 0220 QCOMPARE(entry->field("rating"), QStringLiteral("4.5")); 0221 } 0222 0223 void DeliciousTest::testMusic2() { 0224 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious2_music.xml")); 0225 Tellico::Import::DeliciousImporter importer(url); 0226 Tellico::Data::CollPtr coll = importer.collection(); 0227 0228 QVERIFY(coll); 0229 QCOMPARE(coll->type(), Tellico::Data::Collection::Album); 0230 QCOMPARE(coll->entryCount(), 3); 0231 0232 Tellico::Data::EntryPtr entry = coll->entryById(2); 0233 QVERIFY(entry); 0234 QCOMPARE(entry->field("title"), QStringLiteral("The Ultimate Sin")); 0235 QCOMPARE(entry->field("artist"), QStringLiteral("Ozzy Osbourne")); 0236 QCOMPARE(entry->field("year"), QStringLiteral("1987")); 0237 QCOMPARE(entry->field("medium"), QStringLiteral("Compact Disc")); 0238 QCOMPARE(entry->field("label"), QStringLiteral("Epic Aus/Zoom")); 0239 QCOMPARE(entry->field("pur_price"), QStringLiteral("$15.98")); 0240 QCOMPARE(entry->field("pur_date"), QStringLiteral("2009-01-17")); 0241 QCOMPARE(entry->field("rating"), QStringLiteral("3.5")); 0242 QCOMPARE(entry->field("keyword"), QStringLiteral("Hard Rock & Metal; Rock")); 0243 } 0244 0245 void DeliciousTest::testGames1() { 0246 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious1_games.xml")); 0247 Tellico::Import::DeliciousImporter importer(url); 0248 QVERIFY(importer.canImport(Tellico::Data::Collection::Game)); 0249 Tellico::Data::CollPtr coll = importer.collection(); 0250 0251 QVERIFY(coll); 0252 QCOMPARE(coll->type(), Tellico::Data::Collection::Game); 0253 QCOMPARE(coll->entryCount(), 2); 0254 0255 // first a movie 0256 Tellico::Data::EntryPtr entry = coll->entryById(1); 0257 QVERIFY(entry); 0258 QCOMPARE(entry->field("title"), QStringLiteral("Spider-Man 2: The Movie 2")); 0259 QCOMPARE(entry->field("certification"), QStringLiteral("Teen")); 0260 QCOMPARE(entry->field("platform"), QStringLiteral("GameCube")); 0261 QCOMPARE(entry->field("year"), QStringLiteral("2004")); 0262 QCOMPARE(entry->field("pur_price"), QStringLiteral("$49.99")); 0263 QCOMPARE(entry->field("pur_date"), QStringLiteral("25-03-2006")); 0264 QCOMPARE(entry->field("rating"), QStringLiteral("4.5")); 0265 QCOMPARE(entry->field("publisher"), QStringLiteral("Activision")); 0266 }