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

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 "googlescholarfetchertest.h"
0028 
0029 #include "../fetch/googlescholarfetcher.h"
0030 #include "../entry.h"
0031 #include "../collections/bibtexcollection.h"
0032 #include "../collectionfactory.h"
0033 #include "../utils/bibtexhandler.h"
0034 #include "../utils/datafileregistry.h"
0035 
0036 #include <QTest>
0037 
0038 QTEST_GUILESS_MAIN( GoogleScholarFetcherTest )
0039 
0040 GoogleScholarFetcherTest::GoogleScholarFetcherTest() : AbstractFetcherTest() {
0041 }
0042 
0043 void GoogleScholarFetcherTest::initTestCase() {
0044   Tellico::RegisterCollection<Tellico::Data::BibtexCollection> registerBibtex(Tellico::Data::Collection::Bibtex, "bibtex");
0045   // since we use the bibtex importer
0046   Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../translators/bibtex-translation.xml"));
0047 
0048   m_fieldValues.insert(QStringLiteral("entry-type"), QStringLiteral("article"));
0049   m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("Speeding up the Hybrid Monte Carlo algorithm for dynamical fermions"));
0050   m_fieldValues.insert(QStringLiteral("author"), QStringLiteral("Hasenbusch, Martin"));
0051   m_fieldValues.insert(QStringLiteral("publisher"), QStringLiteral("Elsevier"));
0052   m_fieldValues.insert(QStringLiteral("journal"), QStringLiteral("physics letters b"));
0053   m_fieldValues.insert(QStringLiteral("volume"), QStringLiteral("519"));
0054   m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("2001"));
0055   m_fieldValues.insert(QStringLiteral("pages"), QStringLiteral("177–182"));
0056   m_fieldValues.insert(QStringLiteral("bibtex-key"), QStringLiteral("hasenbusch2001speeding"));
0057 }
0058 
0059 void GoogleScholarFetcherTest::testTitle() {
0060   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title,
0061                                        m_fieldValues.value(QStringLiteral("title")));
0062   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::GoogleScholarFetcher(this));
0063 
0064   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0065 
0066   QVERIFY(!results.isEmpty());
0067 
0068   Tellico::Data::EntryPtr entry = results.at(0);
0069 
0070   QHashIterator<QString, QString> i(m_fieldValues);
0071   while(i.hasNext()) {
0072     i.next();
0073     QString result = entry->field(i.key()).toLower();
0074     Tellico::BibtexHandler::cleanText(result);
0075     QCOMPARE(result, i.value().toLower());
0076   }
0077 }
0078 
0079 void GoogleScholarFetcherTest::testKeyword() {
0080   Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Keyword,
0081                                        m_fieldValues.value(QStringLiteral("title")));
0082   Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::GoogleScholarFetcher(this));
0083 
0084   Tellico::Data::EntryList results = DO_FETCH(fetcher, request);
0085 
0086   QVERIFY(!results.isEmpty());
0087 
0088   Tellico::Data::EntryPtr entry = results.at(0);
0089 
0090   QHashIterator<QString, QString> i(m_fieldValues);
0091   while(i.hasNext()) {
0092     i.next();
0093     QString result = entry->field(i.key()).toLower();
0094     Tellico::BibtexHandler::cleanText(result);
0095     QCOMPARE(result, i.value().toLower());
0096   }
0097 }