File indexing completed on 2024-05-12 05:10:00
0001 /*************************************************************************** 0002 Copyright (C) 2009-2010 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 "gcstartest.h" 0028 0029 #include "../translators/gcstarimporter.h" 0030 #include "../translators/gcstarexporter.h" 0031 #include "../collections/collectioninitializer.h" 0032 #include "../collectionfactory.h" 0033 #include "../images/imagefactory.h" 0034 #include "../utils/datafileregistry.h" 0035 #include "../fieldformat.h" 0036 0037 #include <KLocalizedString> 0038 0039 #include <QTest> 0040 #include <QStandardPaths> 0041 0042 #define FIELDS(entry, fieldName) Tellico::FieldFormat::splitValue(entry->field(QStringLiteral(fieldName))) 0043 #define TABLES(entry, fieldName) Tellico::FieldFormat::splitTable(entry->field(QStringLiteral(fieldName))) 0044 0045 QTEST_GUILESS_MAIN( GCstarTest ) 0046 0047 void GCstarTest::initTestCase() { 0048 QStandardPaths::setTestModeEnabled(true); 0049 KLocalizedString::setApplicationDomain("tellico"); 0050 // remove the test image directory 0051 QDir gcstarImageDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/gcstar/")); 0052 gcstarImageDir.removeRecursively(); 0053 Tellico::ImageFactory::init(); 0054 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/gcstar2tellico.xsl")); 0055 // need to register the collection types 0056 Tellico::CollectionInitializer ci; 0057 } 0058 0059 void GCstarTest::testBook() { 0060 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-book.gcs")); 0061 Tellico::Import::GCstarImporter importer(url); 0062 Tellico::Data::CollPtr coll = importer.collection(); 0063 0064 QVERIFY(coll); 0065 QCOMPARE(coll->type(), Tellico::Data::Collection::Book); 0066 QCOMPARE(coll->entryCount(), 2); 0067 // should be translated somehow 0068 QCOMPARE(coll->title(), QStringLiteral("GCstar Import")); 0069 QVERIFY(importer.canImport(coll->type())); 0070 0071 Tellico::Data::EntryPtr entry = coll->entryById(1); 0072 QVERIFY(entry); 0073 QCOMPARE(entry->field("title"), QStringLiteral("The Reason for God")); 0074 QCOMPARE(entry->field("pub_year"), QStringLiteral("2008")); 0075 QCOMPARE(FIELDS(entry, "author").count(), 2); 0076 QCOMPARE(FIELDS(entry, "author").first(), QStringLiteral("Timothy Keller")); 0077 QCOMPARE(entry->field("isbn"), QStringLiteral("978-0-525-95049-3")); 0078 QCOMPARE(entry->field("publisher"), QStringLiteral("Dutton Adult")); 0079 QCOMPARE(FIELDS(entry, "genre").count(), 2); 0080 QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("non-fiction")); 0081 QCOMPARE(FIELDS(entry, "keyword").count(), 2); 0082 QCOMPARE(FIELDS(entry, "keyword").at(0), QStringLiteral("tag1")); 0083 QCOMPARE(FIELDS(entry, "keyword").at(1), QStringLiteral("tag2")); 0084 // file has rating of 4, Tellico uses half the rating of GCstar, so it should be 2 0085 QCOMPARE(entry->field("rating"), QStringLiteral("2")); 0086 QCOMPARE(FIELDS(entry, "language").count(), 1); 0087 QCOMPARE(FIELDS(entry, "language").at(0), QStringLiteral("English")); 0088 0089 Tellico::Export::GCstarExporter exporter(coll); 0090 exporter.setEntries(coll->entries()); 0091 0092 Tellico::Import::GCstarImporter importer2(exporter.text()); 0093 Tellico::Data::CollPtr coll2 = importer2.collection(); 0094 0095 QVERIFY(coll2); 0096 QCOMPARE(coll2->type(), coll->type()); 0097 QCOMPARE(coll2->entryCount(), coll->entryCount()); 0098 QCOMPARE(coll2->title(), coll->title()); 0099 0100 foreach(Tellico::Data::EntryPtr e1, coll->entries()) { 0101 Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); 0102 QVERIFY(e2); 0103 foreach(Tellico::Data::FieldPtr f, coll->fields()) { 0104 // skip images 0105 if(f->type() != Tellico::Data::Field::Image) { 0106 QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); 0107 } 0108 } 0109 } 0110 } 0111 0112 void GCstarTest::testComicBook() { 0113 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-comicbook.gcs")); 0114 Tellico::Import::GCstarImporter importer(url); 0115 Tellico::Data::CollPtr coll = importer.collection(); 0116 0117 QVERIFY(coll); 0118 QCOMPARE(coll->type(), Tellico::Data::Collection::ComicBook); 0119 QCOMPARE(coll->entryCount(), 1); 0120 // should be translated somehow 0121 QCOMPARE(coll->title(), QStringLiteral("GCstar Import")); 0122 QVERIFY(importer.canImport(coll->type())); 0123 0124 Tellico::Data::EntryPtr entry = coll->entryById(1); 0125 QVERIFY(entry); 0126 QCOMPARE(entry->field("title"), QStringLiteral("title")); 0127 QCOMPARE(entry->field("pub_year"), QStringLiteral("2010")); 0128 QCOMPARE(entry->field("series"), QStringLiteral("series")); 0129 QCOMPARE(entry->field("issue"), QStringLiteral("1")); 0130 QCOMPARE(FIELDS(entry, "writer").count(), 2); 0131 QCOMPARE(FIELDS(entry, "writer").first(), QStringLiteral("writer1")); 0132 QCOMPARE(entry->field("isbn"), QStringLiteral("1-23456-789-X")); 0133 QCOMPARE(entry->field("artist"), QStringLiteral("illustrator")); 0134 QCOMPARE(entry->field("publisher"), QStringLiteral("publisher")); 0135 QCOMPARE(entry->field("colorist"), QStringLiteral("colourist")); 0136 QCOMPARE(entry->field("category"), QStringLiteral("category")); 0137 QCOMPARE(entry->field("format"), QStringLiteral("format")); 0138 QCOMPARE(entry->field("collection"), QStringLiteral("collection")); 0139 QCOMPARE(entry->field("pur_date"), QStringLiteral("29/08/2010")); 0140 QCOMPARE(entry->field("pur_price"), QStringLiteral("12.99")); 0141 QCOMPARE(entry->field("numberboards"), QStringLiteral("1")); 0142 QCOMPARE(entry->field("signed"), QStringLiteral("true")); 0143 // file has rating of 4, Tellico uses half the rating of GCstar, so it should be 2 0144 QCOMPARE(entry->field("rating"), QStringLiteral("2")); 0145 QVERIFY(!entry->field("plot").isEmpty()); 0146 QVERIFY(!entry->field("comments").isEmpty()); 0147 0148 Tellico::Export::GCstarExporter exporter(coll); 0149 exporter.setEntries(coll->entries()); 0150 0151 Tellico::Import::GCstarImporter importer2(exporter.text()); 0152 Tellico::Data::CollPtr coll2 = importer2.collection(); 0153 0154 QVERIFY(coll2); 0155 QCOMPARE(coll2->type(), coll->type()); 0156 QCOMPARE(coll2->entryCount(), coll->entryCount()); 0157 QCOMPARE(coll2->title(), coll->title()); 0158 0159 foreach(Tellico::Data::EntryPtr e1, coll->entries()) { 0160 Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); 0161 QVERIFY(e2); 0162 foreach(Tellico::Data::FieldPtr f, coll->fields()) { 0163 // skip images 0164 if(f->type() != Tellico::Data::Field::Image) { 0165 QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); 0166 } 0167 } 0168 } 0169 } 0170 0171 void GCstarTest::testVideo() { 0172 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-video.gcs")); 0173 Tellico::Import::GCstarImporter importer(url); 0174 Tellico::Data::CollPtr coll = importer.collection(); 0175 0176 QVERIFY(coll); 0177 QCOMPARE(coll->type(), Tellico::Data::Collection::Video); 0178 QCOMPARE(coll->entryCount(), 3); 0179 QVERIFY(importer.canImport(coll->type())); 0180 0181 Tellico::Data::EntryPtr entry = coll->entryById(2); 0182 QVERIFY(entry); 0183 QCOMPARE(entry->field("title"), QStringLiteral("The Man from Snowy River")); 0184 QCOMPARE(entry->field("year"), QStringLiteral("1982")); 0185 QCOMPARE(FIELDS(entry, "director").count(), 1); 0186 QCOMPARE(FIELDS(entry, "director").first(), QStringLiteral("George Miller")); 0187 QCOMPARE(FIELDS(entry, "nationality").count(), 1); 0188 QCOMPARE(FIELDS(entry, "nationality").first(), QStringLiteral("Australia")); 0189 QCOMPARE(entry->field("medium"), QStringLiteral("DVD")); 0190 QCOMPARE(entry->field("running-time"), QStringLiteral("102")); 0191 QCOMPARE(FIELDS(entry, "genre").count(), 4); 0192 QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("Drama")); 0193 QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0194 QCOMPARE(castList.count(), 10); 0195 QCOMPARE(castList.at(0), QStringLiteral("Tom Burlinson::Jim Craig")); 0196 QCOMPARE(castList.at(2), QStringLiteral("Kirk Douglas::Harrison / Spur")); 0197 QCOMPARE(FIELDS(entry, "keyword").count(), 2); 0198 QCOMPARE(FIELDS(entry, "keyword").at(0), QStringLiteral("tag2")); 0199 QCOMPARE(FIELDS(entry, "keyword").at(1), QStringLiteral("tag1")); 0200 QCOMPARE(entry->field("rating"), QStringLiteral("3")); 0201 QVERIFY(!entry->field("plot").isEmpty()); 0202 QVERIFY(!entry->field("comments").isEmpty()); 0203 0204 entry = coll->entryById(4); 0205 QVERIFY(entry); 0206 castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); 0207 QCOMPARE(castList.count(), 11); 0208 QCOMPARE(castList.at(0), QStringLiteral("Famke Janssen::Marnie Watson")); 0209 QCOMPARE(entry->field("location"), QStringLiteral("On Hard Drive")); 0210 0211 Tellico::Export::GCstarExporter exporter(coll); 0212 exporter.setEntries(coll->entries()); 0213 Tellico::Import::GCstarImporter importer2(exporter.text()); 0214 Tellico::Data::CollPtr coll2 = importer2.collection(); 0215 0216 QVERIFY(coll2); 0217 QCOMPARE(coll2->type(), coll->type()); 0218 QCOMPARE(coll2->entryCount(), coll->entryCount()); 0219 QCOMPARE(coll2->title(), coll->title()); 0220 0221 foreach(Tellico::Data::EntryPtr e1, coll->entries()) { 0222 Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); 0223 QVERIFY(e2); 0224 foreach(Tellico::Data::FieldPtr f, coll->fields()) { 0225 // skip images and tables 0226 if(f->type() != Tellico::Data::Field::Image && 0227 f->type() != Tellico::Data::Field::Table) { 0228 QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); 0229 } else if(f->type() == Tellico::Data::Field::Table) { 0230 QStringList rows1 = Tellico::FieldFormat::splitTable(e1->field(f)); 0231 QStringList rows2 = Tellico::FieldFormat::splitTable(e2->field(f)); 0232 QCOMPARE(rows1.count(), rows2.count()); 0233 for(int i = 0; i < rows1.count(); ++i) { 0234 QCOMPARE(f->name() + rows2.at(i), f->name() + rows1.at(i)); 0235 } 0236 } 0237 } 0238 } 0239 } 0240 0241 void GCstarTest::testMusic() { 0242 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-music.gcs")); 0243 Tellico::Import::GCstarImporter importer(url); 0244 Tellico::Data::CollPtr coll = importer.collection(); 0245 0246 QVERIFY(coll); 0247 QCOMPARE(coll->type(), Tellico::Data::Collection::Album); 0248 QCOMPARE(coll->entryCount(), 1); 0249 QVERIFY(importer.canImport(coll->type())); 0250 0251 Tellico::Data::EntryPtr entry = coll->entryById(1); 0252 QVERIFY(entry); 0253 QCOMPARE(entry->field("title"), QStringLiteral("Lifesong")); 0254 QCOMPARE(entry->field("year"), QStringLiteral("2005")); 0255 QCOMPARE(FIELDS(entry, "artist").count(), 1); 0256 QCOMPARE(FIELDS(entry, "artist").first(), QStringLiteral("Casting Crowns")); 0257 QCOMPARE(FIELDS(entry, "label").count(), 1); 0258 QCOMPARE(FIELDS(entry, "label").first(), QStringLiteral("Beach Street Records")); 0259 QCOMPARE(entry->field("medium"), QStringLiteral("Compact Disc")); 0260 QCOMPARE(FIELDS(entry, "genre").count(), 2); 0261 QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("Electronic")); 0262 QStringList trackList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("track"))); 0263 QCOMPARE(trackList.count(), 11); 0264 QCOMPARE(trackList.at(1), QStringLiteral("Praise You In This Storm::Casting Crowns::4:59")); 0265 QCOMPARE(FIELDS(entry, "producer").count(), 1); 0266 QCOMPARE(FIELDS(entry, "producer").at(0), QStringLiteral("Mark A. Miller")); 0267 QCOMPARE(FIELDS(entry, "composer").count(), 4); 0268 QCOMPARE(FIELDS(entry, "composer").at(1), QStringLiteral("David Hunt")); 0269 QCOMPARE(entry->field("cdate"), QStringLiteral("2009-09-22")); 0270 0271 Tellico::Export::GCstarExporter exporter(coll); 0272 exporter.setEntries(coll->entries()); 0273 Tellico::Import::GCstarImporter importer2(exporter.text()); 0274 Tellico::Data::CollPtr coll2 = importer2.collection(); 0275 0276 QVERIFY(coll2); 0277 QCOMPARE(coll2->type(), coll->type()); 0278 QCOMPARE(coll2->entryCount(), coll->entryCount()); 0279 QCOMPARE(coll2->title(), coll->title()); 0280 0281 foreach(Tellico::Data::EntryPtr e1, coll->entries()) { 0282 Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); 0283 QVERIFY(e2); 0284 foreach(Tellico::Data::FieldPtr f, coll->fields()) { 0285 // skip images 0286 if(f->type() != Tellico::Data::Field::Image) { 0287 QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); 0288 } 0289 } 0290 } 0291 } 0292 0293 void GCstarTest::testVideoGame() { 0294 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-videogame.gcs")); 0295 Tellico::Import::GCstarImporter importer(url); 0296 Tellico::Data::CollPtr coll = importer.collection(); 0297 0298 QVERIFY(coll); 0299 QCOMPARE(coll->type(), Tellico::Data::Collection::Game); 0300 QCOMPARE(coll->entryCount(), 2); 0301 QVERIFY(importer.canImport(coll->type())); 0302 0303 Tellico::Data::EntryPtr entry = coll->entryById(2); 0304 QVERIFY(entry); 0305 QCOMPARE(entry->field("title"), QStringLiteral("Halo 3")); 0306 QCOMPARE(entry->field("year"), QStringLiteral("2007")); 0307 QCOMPARE(entry->field("platform"), QStringLiteral("Xbox 360")); 0308 QCOMPARE(FIELDS(entry, "developer").count(), 1); 0309 QCOMPARE(FIELDS(entry, "developer").first(), QStringLiteral("Bungie Studios")); 0310 QCOMPARE(FIELDS(entry, "publisher").count(), 1); 0311 QCOMPARE(FIELDS(entry, "publisher").first(), QStringLiteral("Microsoft Games Studios")); 0312 QCOMPARE(FIELDS(entry, "genre").count(), 3); 0313 QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("Action")); 0314 QCOMPARE(entry->field("cdate"), QStringLiteral("2009-09-24")); 0315 QVERIFY(!entry->field("description").isEmpty()); 0316 0317 Tellico::Export::GCstarExporter exporter(coll); 0318 exporter.setEntries(coll->entries()); 0319 Tellico::Import::GCstarImporter importer2(exporter.text()); 0320 Tellico::Data::CollPtr coll2 = importer2.collection(); 0321 0322 QVERIFY(coll2); 0323 QCOMPARE(coll2->type(), coll->type()); 0324 QCOMPARE(coll2->entryCount(), coll->entryCount()); 0325 QCOMPARE(coll2->title(), coll->title()); 0326 0327 foreach(Tellico::Data::EntryPtr e1, coll->entries()) { 0328 Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); 0329 QVERIFY(e2); 0330 foreach(Tellico::Data::FieldPtr f, coll->fields()) { 0331 // skip images 0332 if(f->type() != Tellico::Data::Field::Image) { 0333 QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); 0334 } 0335 } 0336 } 0337 } 0338 0339 void GCstarTest::testBoardGame() { 0340 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-boardgame.gcs")); 0341 Tellico::Import::GCstarImporter importer(url); 0342 Tellico::Data::CollPtr coll = importer.collection(); 0343 0344 QVERIFY(coll); 0345 QCOMPARE(coll->type(), Tellico::Data::Collection::BoardGame); 0346 QCOMPARE(coll->entryCount(), 2); 0347 QVERIFY(importer.canImport(coll->type())); 0348 0349 Tellico::Data::EntryPtr entry = coll->entryById(1); 0350 QVERIFY(entry); 0351 QCOMPARE(entry->field("title"), QStringLiteral("Risk")); 0352 QCOMPARE(entry->field("year"), QStringLiteral("1959")); 0353 QCOMPARE(FIELDS(entry, "designer").count(), 2); 0354 QCOMPARE(FIELDS(entry, "designer").at(1), QStringLiteral("Michael I. Levin")); 0355 QCOMPARE(FIELDS(entry, "publisher").count(), 11); 0356 QCOMPARE(FIELDS(entry, "publisher").at(1), QStringLiteral("Borras Plana S.A.")); 0357 QCOMPARE(FIELDS(entry, "mechanism").count(), 3); 0358 QCOMPARE(FIELDS(entry, "mechanism").at(1), QStringLiteral("Dice Rolling")); 0359 QCOMPARE(FIELDS(entry, "genre").count(), 1); 0360 QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("Wargame")); 0361 QVERIFY(!entry->field("description").isEmpty()); 0362 QVERIFY(!entry->field("comments").isEmpty()); 0363 0364 Tellico::Export::GCstarExporter exporter(coll); 0365 exporter.setEntries(coll->entries()); 0366 Tellico::Import::GCstarImporter importer2(exporter.text()); 0367 Tellico::Data::CollPtr coll2 = importer2.collection(); 0368 0369 QVERIFY(coll2); 0370 QCOMPARE(coll2->type(), coll->type()); 0371 QCOMPARE(coll2->entryCount(), coll->entryCount()); 0372 QCOMPARE(coll2->title(), coll->title()); 0373 0374 foreach(Tellico::Data::EntryPtr e1, coll->entries()) { 0375 Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); 0376 QVERIFY(e2); 0377 foreach(Tellico::Data::FieldPtr f, coll->fields()) { 0378 // skip images 0379 if(f->type() != Tellico::Data::Field::Image) { 0380 QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); 0381 } 0382 } 0383 } 0384 } 0385 0386 void GCstarTest::testWine() { 0387 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-wine.gcs")); 0388 Tellico::Import::GCstarImporter importer(url); 0389 importer.setHasRelativeImageLinks(true); 0390 Tellico::Data::CollPtr coll = importer.collection(); 0391 0392 QVERIFY(coll); 0393 QCOMPARE(coll->type(), Tellico::Data::Collection::Wine); 0394 QCOMPARE(coll->entryCount(), 1); 0395 QVERIFY(importer.canImport(coll->type())); 0396 0397 Tellico::Data::EntryPtr entry = coll->entryById(1); 0398 QVERIFY(entry); 0399 QCOMPARE(entry->field("vintage"), QStringLiteral("1990")); 0400 QCOMPARE(entry->field("producer"), QStringLiteral("producer")); 0401 QCOMPARE(entry->field("type"), QStringLiteral("Red Wine")); 0402 QCOMPARE(entry->field("country"), QStringLiteral("australia")); 0403 QCOMPARE(entry->field("quantity"), QStringLiteral("1")); 0404 QCOMPARE(FIELDS(entry, "varietal").count(), 2); 0405 QCOMPARE(FIELDS(entry, "varietal").at(1), QStringLiteral("grape2")); 0406 QCOMPARE(entry->field("pur_date"), QStringLiteral("28/08/2010")); 0407 QCOMPARE(entry->field("pur_price"), QStringLiteral("12.99")); 0408 QCOMPARE(entry->field("appellation"), QStringLiteral("designation")); 0409 QCOMPARE(entry->field("distinction"), QStringLiteral("distinction")); 0410 QCOMPARE(entry->field("soil"), QStringLiteral("soil")); 0411 QCOMPARE(entry->field("alcohol"), QStringLiteral("12")); 0412 QCOMPARE(entry->field("volume"), QStringLiteral("750")); 0413 QCOMPARE(entry->field("rating"), QStringLiteral("3")); 0414 QCOMPARE(entry->field("gift"), QStringLiteral("true")); 0415 QCOMPARE(entry->field("tasted"), QStringLiteral("true")); 0416 QVERIFY(!entry->field("description").isEmpty()); 0417 QVERIFY(!entry->field("comments").isEmpty()); 0418 QVERIFY(!entry->field("label").isEmpty()); 0419 0420 Tellico::Export::GCstarExporter exporter(coll); 0421 exporter.setOptions(exporter.options() | Tellico::Export::ExportImages); 0422 exporter.setEntries(coll->entries()); 0423 0424 Tellico::Import::GCstarImporter importer2(exporter.text()); 0425 Tellico::Data::CollPtr coll2 = importer2.collection(); 0426 0427 QVERIFY(coll2); 0428 QCOMPARE(coll2->type(), coll->type()); 0429 QCOMPARE(coll2->entryCount(), coll->entryCount()); 0430 QCOMPARE(coll2->title(), coll->title()); 0431 0432 foreach(Tellico::Data::EntryPtr e1, coll->entries()) { 0433 Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); 0434 QVERIFY(e2); 0435 foreach(Tellico::Data::FieldPtr f, coll->fields()) { 0436 QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); 0437 } 0438 } 0439 } 0440 0441 void GCstarTest::testCoin() { 0442 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-coin.gcs")); 0443 Tellico::Import::GCstarImporter importer(url); 0444 Tellico::Data::CollPtr coll = importer.collection(); 0445 0446 QVERIFY(coll); 0447 QCOMPARE(coll->type(), Tellico::Data::Collection::Coin); 0448 QCOMPARE(coll->entryCount(), 1); 0449 QVERIFY(importer.canImport(coll->type())); 0450 0451 Tellico::Data::EntryPtr entry = coll->entryById(1); 0452 QVERIFY(entry); 0453 QCOMPARE(entry->field("denomination"), QStringLiteral("0.05")); 0454 QCOMPARE(entry->field("year"), QStringLiteral("1974")); 0455 QCOMPARE(entry->field("currency"), QStringLiteral("USD")); 0456 QCOMPARE(entry->field("diameter"), QStringLiteral("12.7")); 0457 QCOMPARE(entry->field("estimate"), QStringLiteral("5")); 0458 QCOMPARE(entry->field("grade"), QStringLiteral("Mint State-65")); 0459 QCOMPARE(entry->field("country"), QStringLiteral("australia")); 0460 QCOMPARE(entry->field("location"), QStringLiteral("current")); 0461 QCOMPARE(entry->field("service"), QStringLiteral("PCGS")); 0462 QCOMPARE(TABLES(entry, "metal").count(), 2); 0463 QCOMPARE(TABLES(entry, "metal").at(1), QStringLiteral("metal2")); 0464 QVERIFY(!entry->field("comments").isEmpty()); 0465 0466 Tellico::Export::GCstarExporter exporter(coll); 0467 exporter.setEntries(coll->entries()); 0468 Tellico::Import::GCstarImporter importer2(exporter.text()); 0469 Tellico::Data::CollPtr coll2 = importer2.collection(); 0470 0471 QVERIFY(coll2); 0472 QCOMPARE(coll2->type(), coll->type()); 0473 QCOMPARE(coll2->entryCount(), coll->entryCount()); 0474 QCOMPARE(coll2->title(), coll->title()); 0475 0476 foreach(Tellico::Data::EntryPtr e1, coll->entries()) { 0477 Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); 0478 QVERIFY(e2); 0479 foreach(Tellico::Data::FieldPtr f, coll->fields()) { 0480 // skip images 0481 if(f->type() != Tellico::Data::Field::Image) { 0482 QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); 0483 } 0484 } 0485 } 0486 } 0487 0488 void GCstarTest::testCustomFields() { 0489 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-book.gcs")); 0490 Tellico::Import::GCstarImporter importer(url); 0491 Tellico::Data::CollPtr coll = importer.collection(); 0492 0493 QVERIFY(coll); 0494 QCOMPARE(coll->type(), Tellico::Data::Collection::Book); 0495 QCOMPARE(coll->entryCount(), 2); 0496 // should be translated somehow 0497 QCOMPARE(coll->title(), QStringLiteral("GCstar Import")); 0498 QVERIFY(importer.canImport(coll->type())); 0499 0500 // test custom fields 0501 Tellico::Data::FieldPtr field = coll->fieldByName(QStringLiteral("gcsfield1")); 0502 QVERIFY(field); 0503 QCOMPARE(field->name(), QStringLiteral("gcsfield1")); 0504 QCOMPARE(field->title(), QStringLiteral("New boolean")); 0505 QCOMPARE(field->category(), QStringLiteral("User fields")); 0506 QCOMPARE(field->type(), Tellico::Data::Field::Bool); 0507 0508 field = coll->fieldByName(QStringLiteral("gcsfield2")); 0509 QVERIFY(field); 0510 QCOMPARE(field->title(), QStringLiteral("New choice")); 0511 QCOMPARE(field->type(), Tellico::Data::Field::Choice); 0512 QCOMPARE(field->allowed(), QStringList() << QStringLiteral("yes") 0513 << QStringLiteral("no") 0514 << QStringLiteral("maybe")); 0515 0516 field = coll->fieldByName(QStringLiteral("gcsfield3")); 0517 QVERIFY(field); 0518 QCOMPARE(field->title(), QStringLiteral("New rating")); 0519 QCOMPARE(field->type(), Tellico::Data::Field::Rating); 0520 QCOMPARE(field->property(QStringLiteral("minimum")), QStringLiteral("1")); 0521 QCOMPARE(field->property(QStringLiteral("maximum")), QStringLiteral("5")); 0522 0523 field = coll->fieldByName(QStringLiteral("gcsfield4")); 0524 QVERIFY(field); 0525 QCOMPARE(field->title(), QStringLiteral("New field")); 0526 QCOMPARE(field->type(), Tellico::Data::Field::Line); 0527 0528 field = coll->fieldByName(QStringLiteral("gcsfield5")); 0529 QVERIFY(field); 0530 QCOMPARE(field->title(), QStringLiteral("New image")); 0531 QCOMPARE(field->type(), Tellico::Data::Field::Image); 0532 0533 field = coll->fieldByName(QStringLiteral("gcsfield6")); 0534 QVERIFY(field); 0535 QCOMPARE(field->title(), QStringLiteral("New long field")); 0536 QCOMPARE(field->type(), Tellico::Data::Field::Para); 0537 0538 field = coll->fieldByName(QStringLiteral("gcsfield7")); 0539 QVERIFY(field); 0540 QCOMPARE(field->title(), QStringLiteral("New date")); 0541 QCOMPARE(field->type(), Tellico::Data::Field::Date); 0542 0543 field = coll->fieldByName(QStringLiteral("gcsfield8")); 0544 QVERIFY(field); 0545 QCOMPARE(field->title(), QStringLiteral("New number")); 0546 QCOMPARE(field->type(), Tellico::Data::Field::Number); 0547 QCOMPARE(field->defaultValue(), QStringLiteral("2")); 0548 0549 field = coll->fieldByName(QStringLiteral("gcsfield9")); 0550 QVERIFY(field); 0551 QCOMPARE(field->title(), QStringLiteral("dependency")); 0552 QCOMPARE(field->type(), Tellico::Data::Field::Line); 0553 QCOMPARE(field->property(QStringLiteral("template")), QStringLiteral("%{gcsfield1},%{gcsfield2}")); 0554 0555 field = coll->fieldByName(QStringLiteral("gcsfield10")); 0556 QVERIFY(field); 0557 QCOMPARE(field->title(), QStringLiteral("list")); 0558 QCOMPARE(field->type(), Tellico::Data::Field::Table); 0559 QCOMPARE(field->property(QStringLiteral("columns")), QStringLiteral("1")); 0560 0561 Tellico::Data::EntryPtr entry = coll->entryById(2); 0562 QVERIFY(entry); 0563 QCOMPARE(entry->field("gcsfield1"), QStringLiteral("true")); 0564 QCOMPARE(entry->field("gcsfield2"), QStringLiteral("maybe")); 0565 QCOMPARE(entry->field("gcsfield3"), QStringLiteral("3")); 0566 QCOMPARE(entry->field("gcsfield4"), QStringLiteral("random value")); 0567 QCOMPARE(entry->field("gcsfield6"), QStringLiteral("all\nthe best \nstuff")); 0568 QCOMPARE(entry->field("gcsfield7"), QStringLiteral("2013-03-31")); 0569 QCOMPARE(entry->field("gcsfield9"), QStringLiteral("true,maybe")); 0570 QCOMPARE(TABLES(entry, "gcsfield10").count(), 2); 0571 QCOMPARE(TABLES(entry, "gcsfield10").at(1), QStringLiteral("list2")); 0572 0573 Tellico::Export::GCstarExporter exporter(coll); 0574 exporter.setEntries(coll->entries()); 0575 0576 Tellico::Import::GCstarImporter importer2(exporter.text()); 0577 Tellico::Data::CollPtr coll2 = importer2.collection(); 0578 QVERIFY(coll2); 0579 0580 foreach(Tellico::Data::FieldPtr f1, coll->fields()) { 0581 Tellico::Data::FieldPtr f2 = coll2->fieldByName(f1->name()); 0582 QVERIFY2(f2, qPrintable(f1->name())); 0583 QCOMPARE(f1->name(), f2->name()); 0584 QCOMPARE(f1->title(), f2->title()); 0585 QCOMPARE(f1->category(), f2->category()); 0586 QCOMPARE(f1->allowed(), f2->allowed()); 0587 QCOMPARE(f1->type(), f2->type()); 0588 QCOMPARE(f1->flags(), f2->flags()); 0589 QCOMPARE(f1->formatType(), f2->formatType()); 0590 QCOMPARE(f1->description(), f2->description()); 0591 QCOMPARE(f1->defaultValue(), f2->defaultValue()); 0592 QCOMPARE(f1->property(QStringLiteral("minimum")), f2->property(QStringLiteral("minimum"))); 0593 QCOMPARE(f1->property(QStringLiteral("maximum")), f2->property(QStringLiteral("maximum"))); 0594 QCOMPARE(f1->property(QStringLiteral("columns")), f2->property(QStringLiteral("columns"))); 0595 QCOMPARE(f1->property(QStringLiteral("template")), f2->property(QStringLiteral("template"))); 0596 } 0597 0598 foreach(Tellico::Data::EntryPtr e1, coll->entries()) { 0599 Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); 0600 QVERIFY(e2); 0601 QCOMPARE(TABLES(e2, "gcsfield10").count(), 2); 0602 QCOMPARE(TABLES(e2, "gcsfield10").at(1), QStringLiteral("list2")); 0603 foreach(Tellico::Data::FieldPtr f, coll->fields()) { 0604 // skip images 0605 if(f->type() != Tellico::Data::Field::Image) { 0606 QCOMPARE(f->name() + e1->field(f), f->name() + e2->field(f)); 0607 } 0608 } 0609 } 0610 }