File indexing completed on 2024-05-12 05:10:07

0001 /***************************************************************************
0002     Copyright (C) 2009-2011 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 "z3950fetchertest.h"
0028 
0029 #include "../fetch/z3950fetcher.h"
0030 #include "../collections/bookcollection.h"
0031 #include "../collectionfactory.h"
0032 #include "../entry.h"
0033 #include "../utils/datafileregistry.h"
0034 
0035 #include <QTest>
0036 
0037 QTEST_GUILESS_MAIN( Z3950FetcherTest )
0038 
0039 Z3950FetcherTest::Z3950FetcherTest() : AbstractFetcherTest() {
0040 }
0041 
0042 void Z3950FetcherTest::initTestCase() {
0043   Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBibtex(Tellico::Data::Collection::Book, "book");
0044   // since we use the MODS importer
0045   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/mods2tellico.xsl"));
0046   // also use the z3950-servers.cfg file
0047   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../fetch/z3950-servers.cfg"));
0048 }
0049 
0050 void Z3950FetcherTest::testTitle() {
0051   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::Title,
0052                                        QStringLiteral("Foundations of Qt Development"));
0053   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::Z3950Fetcher(this, QStringLiteral("loc")));
0054 
0055   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0056 
0057   QCOMPARE(results.size(), 1);
0058 
0059   Tellico::Data::EntryPtr entry = results.at(0);
0060   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Foundations of Qt development"));
0061   QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Thelin, Johan."));
0062   QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("1-59059-831-8"));
0063 }
0064 
0065 void Z3950FetcherTest::testIsbn() {
0066   // also testing multiple values
0067   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN,
0068                                        QStringLiteral("978-1-59059-831-3; 0-201-88954-4"));
0069   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::Z3950Fetcher(this, QStringLiteral("loc")));
0070 
0071   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0072 
0073   QCOMPARE(results.size(), 2);
0074 
0075   Tellico::Data::EntryPtr entry = results.at(1);
0076   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Foundations of Qt development"));
0077   QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Thelin, Johan."));
0078   QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("1-59059-831-8"));
0079 }
0080 
0081 void Z3950FetcherTest::testADS() {
0082   // 2014: ADS has disappeared with no warning
0083   return;
0084   // also testing multiple values
0085   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Raw,
0086                                        QStringLiteral("@and @attr 1=4 \"Particle creation by black holes\" "
0087                                                       "@and @attr 1=1003 Hawking @attr 1=62 Generalized"));
0088   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::Z3950Fetcher(this,
0089                                                                         QStringLiteral("z3950.adsabs.harvard.edu"),
0090                                                                         210,
0091                                                                         QStringLiteral("AST"),
0092                                                                         QStringLiteral("ads")));
0093 
0094   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0095 
0096   QCOMPARE(results.size(), 1);
0097 
0098   Tellico::Data::EntryPtr entry = results.at(0);
0099   QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Particle creation by black holes"));
0100   QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Hawking, S. W."));
0101   QCOMPARE(entry->field(QStringLiteral("year")), QStringLiteral("1975"));
0102   QCOMPARE(entry->field(QStringLiteral("doi")), QStringLiteral("10.1007/BF02345020"));
0103   QCOMPARE(entry->field(QStringLiteral("pages")), QStringLiteral("199-220"));
0104   QCOMPARE(entry->field(QStringLiteral("volume")), QStringLiteral("43"));
0105   QCOMPARE(entry->field(QStringLiteral("journal")), QStringLiteral("Communications In Mathematical Physics"));
0106   QVERIFY(!entry->field(QStringLiteral("url")).isEmpty());
0107 }
0108 
0109 void Z3950FetcherTest::testBibsysIsbn() {
0110   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Book, Tellico::Fetch::ISBN,
0111                                        QStringLiteral("8242407665"));
0112   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::Z3950Fetcher(this, QStringLiteral("bibsys")));
0113 
0114   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0115 
0116   QCOMPARE(results.size(), 1);
0117 
0118   Tellico::Data::EntryPtr entry = results.at(0);
0119   QCOMPARE(entry->field(QStringLiteral("title")), QString::fromUtf8("Grønn"));
0120   QCOMPARE(entry->field(QStringLiteral("isbn")), QStringLiteral("82-42-40477-1"));
0121 }
0122 
0123 // https://bugs.kde.org/show_bug.cgi?id=419670
0124 void Z3950FetcherTest::testPortugal() {
0125 //  Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::ISBN,
0126 //                                       QString::fromUtf8("972-706-024-2"));
0127   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title,
0128                                        QString::fromUtf8("Memórias póstumas de Brás Cubas"));
0129   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::Z3950Fetcher(this,
0130                                                                         QStringLiteral("z3950.porbase.bnportugal.gov.pt"),
0131                                                                         210,
0132                                                                         QStringLiteral("bn"),
0133                                                                         QStringLiteral("unimarc")));
0134   Tellico::Fetch::Z3950Fetcher* f = static_cast<Tellico::Fetch::Z3950Fetcher*>(fetcher.data());
0135   f->setCharacterSet(QStringLiteral("ISO-8859-1"), QStringLiteral("iso5426"));
0136 
0137   Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
0138 
0139   QCOMPARE(results.size(), 1);
0140 
0141   Tellico::Data::EntryPtr entry = results.at(0);
0142   QCOMPARE(entry->field(QStringLiteral("title")).toUtf8(), QString::fromUtf8("Memórias póstumas de Brás Cubas").toUtf8());
0143   QCOMPARE(entry->field(QStringLiteral("author")), QStringLiteral("Assis, Machado de"));
0144 }