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