File indexing completed on 2024-05-12 05:09:54
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 "arxivfetchertest.h" 0028 0029 #include "../fetch/arxivfetcher.h" 0030 #include "../entry.h" 0031 #include "../collections/bibtexcollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../utils/datafileregistry.h" 0034 0035 #include <QTest> 0036 0037 QTEST_GUILESS_MAIN( ArxivFetcherTest) 0038 0039 ArxivFetcherTest::ArxivFetcherTest() : AbstractFetcherTest() { 0040 } 0041 0042 void ArxivFetcherTest::initTestCase() { 0043 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/arxiv2tellico.xsl")); 0044 Tellico::RegisterCollection<Tellico::Data::BibtexCollection> registerBibtex(Tellico::Data::Collection::Bibtex, "bibtex"); 0045 0046 m_fieldValues.insert(QStringLiteral("arxiv"), QStringLiteral("hep-lat/0110180")); 0047 m_fieldValues.insert(QStringLiteral("entry-type"), QStringLiteral("article")); 0048 m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("Speeding up the Hybrid-Monte-Carlo algorithm for dynamical fermions")); 0049 m_fieldValues.insert(QStringLiteral("author"), QStringLiteral("M. Hasenbusch; K. Jansen")); 0050 m_fieldValues.insert(QStringLiteral("keyword"), QStringLiteral("High Energy Physics - Lattice")); 0051 m_fieldValues.insert(QStringLiteral("journal"), QStringLiteral("Nucl.Phys.Proc.Suppl. 106")); 0052 m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("2002")); 0053 m_fieldValues.insert(QStringLiteral("pages"), QStringLiteral("1076-1078")); 0054 } 0055 0056 void ArxivFetcherTest::testArxivTitle() { 0057 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::Title, 0058 QLatin1Char('"') + m_fieldValues.value(QStringLiteral("title")) + QLatin1Char('"')); 0059 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ArxivFetcher(this)); 0060 0061 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0062 0063 QEXPECT_FAIL("", "Exact title searches don't return expected results", Continue); 0064 QCOMPARE(results.size(), 1); 0065 } 0066 0067 void ArxivFetcherTest::testArxivID() { 0068 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::ArxivID, 0069 "arxiv:" + m_fieldValues.value(QStringLiteral("arxiv"))); 0070 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ArxivFetcher(this)); 0071 0072 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0073 0074 QCOMPARE(results.size(), 1); 0075 Tellico::Data::EntryPtr entry = results.at(0); 0076 0077 QHashIterator<QString, QString> i(m_fieldValues); 0078 while(i.hasNext()) { 0079 i.next(); 0080 QCOMPARE(entry->field(i.key()), i.value()); 0081 } 0082 } 0083 0084 void ArxivFetcherTest::testArxivIDVersioned() { 0085 QString arxivVersioned = m_fieldValues.value(QStringLiteral("arxiv")) + "v1"; 0086 Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::ArxivID, arxivVersioned); 0087 Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ArxivFetcher(this)); 0088 0089 Tellico::Data::EntryList results = DO_FETCH(fetcher, request); 0090 0091 QCOMPARE(results.size(), 1); 0092 Tellico::Data::EntryPtr entry = results.at(0); 0093 // id has version since original search included it 0094 QCOMPARE(entry->field("arxiv"), arxivVersioned); 0095 0096 QHashIterator<QString, QString> i(m_fieldValues); 0097 while(i.hasNext()) { 0098 i.next(); 0099 if(i.key() == QLatin1String("arxiv")) continue; 0100 QCOMPARE(entry->field(i.key()), i.value()); 0101 } 0102 }