File indexing completed on 2024-05-12 05:09:58
0001 /*************************************************************************** 0002 Copyright (C) 2015 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 "externalfetchertest.h" 0028 0029 #include "../fetch/execexternalfetcher.h" 0030 #include "../entry.h" 0031 #include "../collections/bookcollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../utils/datafileregistry.h" 0034 0035 #include <KSharedConfig> 0036 #include <KConfigGroup> 0037 0038 #include <QTest> 0039 #include <QStandardPaths> 0040 0041 QTEST_GUILESS_MAIN( ExternalFetcherTest ) 0042 0043 ExternalFetcherTest::ExternalFetcherTest() : AbstractFetcherTest() { 0044 } 0045 0046 void ExternalFetcherTest::initTestCase() { 0047 Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book"); 0048 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/mods2tellico.xsl")); 0049 } 0050 0051 void ExternalFetcherTest::testParsing() { 0052 const QString argsList(QStringLiteral("run a test \"with 3 args\" plus \"one more\" at end")); 0053 auto args = Tellico::Fetch::ExecExternalFetcher::parseArguments(argsList); 0054 QCOMPARE(args.count(), 8); 0055 QCOMPARE(args.at(3), QLatin1String("with 3 args")); 0056 QCOMPARE(args.at(4), QLatin1String("plus")); 0057 } 0058 0059 void ExternalFetcherTest::testMods() { 0060 // fake the fetcher by 'cat'ting the MODS file 0061 // the search request is a dummy title search 0062 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Title, 0063 QString()); 0064 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ExecExternalFetcher(this)); 0065 0066 KSharedConfig::Ptr config = KSharedConfig::openConfig(QFINDTESTDATA("data/cat_mods.spec"), KConfig::SimpleConfig); 0067 KConfigGroup cg = config->group(QStringLiteral("<default>")); 0068 cg.writeEntry("ExecPath", QFINDTESTDATA("data/cat_mods.sh")); // update command path to local script 0069 cg.markAsClean(); // don't edit the file on sync() 0070 0071 fetcher->readConfig(cg); 0072 QVERIFY(fetcher->canSearch(request.key())); 0073 0074 Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); 0075 0076 QCOMPARE(results.size(), 1); 0077 0078 Tellico::Data::EntryPtr entry = results.at(0); 0079 QVERIFY(entry); 0080 QCOMPARE(entry->field("title"), QStringLiteral("Sound and fury")); 0081 QCOMPARE(entry->field("author"), QStringLiteral("Alterman, Eric")); 0082 QCOMPARE(entry->field("genre"), QStringLiteral("bibliography")); 0083 QCOMPARE(entry->field("pub_year"), QStringLiteral("1999")); 0084 QCOMPARE(entry->field("isbn"), QStringLiteral("0-8014-8639-4")); 0085 QCOMPARE(entry->field("lccn"), QStringLiteral("99042030")); 0086 }