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

0001 /***************************************************************************
0002     Copyright (C) 2022 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 "datacrowtest.h"
0028 
0029 #include "../translators/datacrowimporter.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( DataCrowTest )
0044 
0045 void DataCrowTest::initTestCase() {
0046   QStandardPaths::setTestModeEnabled(true);
0047   KLocalizedString::setApplicationDomain("tellico");
0048   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/datacrow2tellico.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 DataCrowTest::testBooks() {
0057   QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/datacrow_books.xml"));
0058   Tellico::Import::DataCrowImporter 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(), 1);
0065 
0066   Tellico::Data::EntryPtr entry = coll->entryById(1);
0067   QVERIFY(entry);
0068   QCOMPARE(entry->field("title"), QStringLiteral("1632"));
0069   QCOMPARE(entry->field("pub_year"), QStringLiteral("2013"));
0070   QCOMPARE(entry->field("language"), QStringLiteral("English"));
0071   QCOMPARE(entry->field("edition"), QStringLiteral("First Edition"));
0072   QCOMPARE(entry->field("author"), QStringLiteral("Eric Flint"));
0073   QCOMPARE(entry->field("pages"), QStringLiteral("329"));
0074   QCOMPARE(entry->field("isbn"), QStringLiteral("1-62579-070-8"));
0075   QCOMPARE(entry->field("binding"), QStringLiteral("Hardback"));
0076   QCOMPARE(entry->field("publisher"), QStringLiteral("Baen Publishing"));
0077   QCOMPARE(entry->field("series"), QStringLiteral("Ring of Fire"));
0078   QCOMPARE(entry->field("rating"), QStringLiteral("3"));
0079   QCOMPARE(entry->field("keyword"), QStringLiteral("favorite"));
0080   QCOMPARE(entry->field("read"), QStringLiteral("true"));
0081   QVERIFY(!entry->field("cover").isEmpty());
0082   QVERIFY(!entry->field("cover").contains(QLatin1Char('/')));
0083   QVERIFY(!entry->field("plot").isEmpty());
0084   QCOMPARE(entry->field("cdate"), QStringLiteral("2022-03-10"));
0085   QCOMPARE(entry->field("mdate"), QStringLiteral("2022-03-10"));
0086 }
0087 
0088 void DataCrowTest::testMovies() {
0089   QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/datacrow_movies.xml"));
0090   Tellico::Import::DataCrowImporter importer(url);
0091   QVERIFY(importer.canImport(Tellico::Data::Collection::Video));
0092   Tellico::Data::CollPtr coll = importer.collection();
0093 
0094   QVERIFY(coll);
0095   QCOMPARE(coll->type(), Tellico::Data::Collection::Video);
0096   QCOMPARE(coll->entryCount(), 1);
0097 
0098   Tellico::Data::EntryPtr entry = coll->entryById(1);
0099   QVERIFY(entry);
0100   QCOMPARE(entry->field("title"), QStringLiteral("Spider-Man: Homecoming"));
0101   QCOMPARE(entry->field("year"), QStringLiteral("2017"));
0102   QCOMPARE(entry->field("nationality"), QStringLiteral("United States"));
0103   QCOMPARE(entry->field("language"), QStringLiteral("English"));
0104   QCOMPARE(entry->field("subtitle"), QStringLiteral("English"));
0105   QCOMPARE(entry->field("director"), QStringLiteral("Jon Watts"));
0106   QStringList cast = Tellico::FieldFormat::splitTable(entry->field("cast"));
0107   QCOMPARE(cast.count(), 78);
0108   QCOMPARE(cast.at(0), QStringLiteral("Abraham Attah"));
0109   QCOMPARE(entry->field("color"), QStringLiteral("Color"));
0110   QCOMPARE(entry->field("medium"), QStringLiteral("DVD"));
0111   QCOMPARE(entry->field("aspect-ratio"), QStringLiteral("16:9"));
0112   QCOMPARE(entry->field("widescreen"), QStringLiteral("true"));
0113   QCOMPARE(entry->field("running-time"), QStringLiteral("133"));
0114   QCOMPARE(entry->field("genre"), QStringLiteral("Action; Adventure; Drama; Science Fiction"));
0115   QCOMPARE(entry->field("rating"), QStringLiteral("5"));
0116   QCOMPARE(entry->field("keyword"), QStringLiteral("favorite"));
0117   QCOMPARE(entry->field("seen"), QStringLiteral("true"));
0118   QCOMPARE(entry->field("url"), QStringLiteral("http://www.spidermanhomecoming.com"));
0119   QVERIFY(!entry->field("cover").isEmpty());
0120   QVERIFY(!entry->field("cover").contains(QLatin1Char('/')));
0121   QVERIFY(!entry->field("plot").isEmpty());
0122   QCOMPARE(entry->field("cdate"), QStringLiteral("2022-03-10"));
0123   QCOMPARE(entry->field("mdate"), QStringLiteral("2022-03-10"));
0124 }
0125 
0126 void DataCrowTest::testMusic() {
0127   QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/datacrow_music.xml"));
0128   Tellico::Import::DataCrowImporter importer(url);
0129   QVERIFY(importer.canImport(Tellico::Data::Collection::Album));
0130   Tellico::Data::CollPtr coll = importer.collection();
0131 
0132   QVERIFY(coll);
0133   QCOMPARE(coll->type(), Tellico::Data::Collection::Album);
0134   QCOMPARE(coll->entryCount(), 1);
0135 
0136   Tellico::Data::EntryPtr entry = coll->entryById(1);
0137   QVERIFY(entry);
0138   QCOMPARE(entry->field("title"), QStringLiteral("Love and Thunder"));
0139   QCOMPARE(entry->field("year"), QStringLiteral("2003"));
0140   QCOMPARE(entry->field("location"), QStringLiteral("container1"));
0141   QCOMPARE(entry->field("label"), QStringLiteral("Essential"));
0142   QCOMPARE(entry->field("artist"), QStringLiteral("Andrew Peterson"));
0143   QCOMPARE(entry->field("genre"), QStringLiteral("Christian"));
0144   QCOMPARE(entry->field("rating"), QStringLiteral("4"));
0145   QStringList tracks = Tellico::FieldFormat::splitTable(entry->field("track"));
0146   QCOMPARE(tracks.count(), 2);
0147   QStringList track2 = QStringList() << QStringLiteral("Let There Be Light") << QStringLiteral("Andrew Peterson") << QStringLiteral("03:56");
0148   QCOMPARE(tracks.at(1), track2.join(Tellico::FieldFormat::columnDelimiterString()));
0149   QVERIFY(!entry->field("cover").isEmpty());
0150   QVERIFY(!entry->field("cover").contains(QLatin1Char('/')));
0151   QCOMPARE(entry->field("cdate"), QStringLiteral("2022-03-11"));
0152   QCOMPARE(entry->field("mdate"), QStringLiteral("2022-03-11"));
0153 }