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

0001 /***************************************************************************
0002     Copyright (C) 2014 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 "mrlookupfetchertest.h"
0028 
0029 #include "../fetch/mrlookupfetcher.h"
0030 #include "../entry.h"
0031 #include "../utils/datafileregistry.h"
0032 
0033 #include <QTest>
0034 
0035 QTEST_GUILESS_MAIN( MRLookupFetcherTest )
0036 
0037 MRLookupFetcherTest::MRLookupFetcherTest() : AbstractFetcherTest() {
0038 }
0039 
0040 void MRLookupFetcherTest::initTestCase() {
0041   // since we use the bibtex importer
0042   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../translators/bibtex-translation.xml"));
0043 
0044   m_fieldValues.insert(QStringLiteral("doi"), QStringLiteral("10.4169/amer.math.monthly.121.10.917"));
0045   m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("An unnoticed consequence of Szegö's distribution theorem"));
0046   m_fieldValues.insert(QStringLiteral("author"), QStringLiteral("Trench, William F."));
0047   m_fieldValues.insert(QStringLiteral("volume"), QStringLiteral("121"));
0048   m_fieldValues.insert(QStringLiteral("journal"), QStringLiteral("American Mathematical Monthly"));
0049   m_fieldValues.insert(QStringLiteral("number"), QStringLiteral("10"));
0050   m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("2014"));
0051   m_fieldValues.insert(QStringLiteral("pages"), QStringLiteral("917–921"));
0052   m_fieldValues.insert(QStringLiteral("entry-type"), QStringLiteral("article"));
0053 }
0054 
0055 void MRLookupFetcherTest::testTitle() {
0056   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title,
0057                                        QLatin1String("An unnoticed consequence of Szego's distribution theorem"));
0058   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::MRLookupFetcher(this));
0059 
0060   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0061 
0062   QVERIFY(!results.isEmpty());
0063   Tellico::Data::EntryPtr entry = results.at(0);
0064 
0065   QHashIterator<QString, QString> i(m_fieldValues);
0066   while(i.hasNext()) {
0067     i.next();
0068     QCOMPARE(entry->field(i.key()), i.value());
0069   }
0070 }
0071 
0072 void MRLookupFetcherTest::testAuthor() {
0073   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Person,
0074                                        QStringLiteral("Trench, William"));
0075   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::MRLookupFetcher(this));
0076 
0077   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0078 
0079   QVERIFY(!results.isEmpty());
0080 
0081   Tellico::Data::EntryPtr entry;
0082   foreach(Tellico::Data::EntryPtr test, results) {
0083     if(test->title().toLower() == m_fieldValues.value(QStringLiteral("title")).toLower()) {
0084       entry = test;
0085       break;
0086     } else {
0087       qDebug() << "Skipping" << test->title();
0088     }
0089   }
0090   QVERIFY(entry);
0091 
0092   QHashIterator<QString, QString> i(m_fieldValues);
0093   while(i.hasNext()) {
0094     i.next();
0095     QCOMPARE(entry->field(i.key()), i.value());
0096   }
0097 }