File indexing completed on 2024-05-12 05:10:03
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 "marctest.h" 0028 0029 #include "../translators/marcimporter.h" 0030 #include "../collections/bibtexcollection.h" 0031 #include "../collections/bookcollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../utils/datafileregistry.h" 0034 0035 #include <KLocalizedString> 0036 0037 #include <QTest> 0038 #include <QStandardPaths> 0039 0040 QTEST_APPLESS_MAIN( MarcTest ) 0041 0042 void MarcTest::initTestCase() { 0043 KLocalizedString::setApplicationDomain("tellico"); 0044 Tellico::RegisterCollection<Tellico::Data::BibtexCollection> registerBibtex(Tellico::Data::Collection::Bibtex, "bibtex"); 0045 Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book"); 0046 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/mods2tellico.xsl")); 0047 } 0048 0049 void MarcTest::testMarc() { 0050 const QString marcdump = QStandardPaths::findExecutable(QStringLiteral("yaz-marcdump")); 0051 if(marcdump.isEmpty()) { 0052 QSKIP("This test requires yaz-marcdump", SkipAll); 0053 } 0054 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test.mrc")); 0055 Tellico::Import::MarcImporter importer(url); 0056 importer.setCharacterSet(QStringLiteral("iso-8859-1")); 0057 0058 Tellico::Data::CollPtr coll = importer.collection(); 0059 0060 QVERIFY(coll); 0061 QCOMPARE(coll->type(), Tellico::Data::Collection::Book); 0062 QCOMPARE(coll->entryCount(), 1); 0063 // since the importer uses MODS as an intermediate format, the title reflects that 0064 QCOMPARE(coll->title(), QStringLiteral("MODS Import")); 0065 QVERIFY(importer.canImport(coll->type())); 0066 0067 Tellico::Data::EntryPtr entry = coll->entryById(1); 0068 QVERIFY(entry); 0069 QCOMPARE(entry->field("title"), QString::fromUtf8("Det osynliga barnet och andra berättelser")); 0070 QCOMPARE(entry->field("author"), QStringLiteral("Jansson, Tove")); 0071 QCOMPARE(entry->field("pub_year"), QStringLiteral("1998")); 0072 QCOMPARE(entry->field("isbn"), QStringLiteral("951-500880-8")); 0073 }