File indexing completed on 2024-05-12 16:46:23
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 <config.h> 0028 #include "pdftest.h" 0029 0030 #include "../translators/pdfimporter.h" 0031 #include "../collections/bibtexcollection.h" 0032 #include "../collectionfactory.h" 0033 #include "../images/imagefactory.h" 0034 #include "../fieldformat.h" 0035 #include "../utils/datafileregistry.h" 0036 0037 #include <QTest> 0038 #include <QStandardPaths> 0039 0040 // needs a GUI for QPixmaps 0041 QTEST_MAIN( PdfTest ) 0042 0043 void PdfTest::initTestCase() { 0044 QStandardPaths::setTestModeEnabled(true); 0045 Tellico::RegisterCollection<Tellico::Data::BibtexCollection> registerBook(Tellico::Data::Collection::Bibtex, "bibliography"); 0046 // since we use the XMP importer 0047 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/xmp2tellico.xsl")); 0048 Tellico::ImageFactory::init(); 0049 } 0050 0051 void PdfTest::testScienceDirect() { 0052 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-sciencedirect.pdf")); 0053 Tellico::Import::PDFImporter importer(url); 0054 0055 Tellico::Data::CollPtr coll = importer.collection(); 0056 0057 QVERIFY(coll); 0058 QCOMPARE(coll->type(), Tellico::Data::Collection::Bibtex); 0059 QCOMPARE(coll->entryCount(), 1); 0060 0061 Tellico::Data::EntryPtr entry = coll->entryById(1); 0062 QVERIFY(entry); 0063 #ifdef HAVE_EXEMPI 0064 QCOMPARE(entry->field("title"), QStringLiteral("Parametric analysis of air-water heat recovery concept applied to HVAC systems")); 0065 QCOMPARE(entry->field("author"), QStringLiteral("Mohamad Ramadan; Mostafa Gad El Rab; Mahmoud Khaled")); 0066 QCOMPARE(entry->field("journal"), QStringLiteral("Case Studies in Thermal Engineering")); 0067 QCOMPARE(entry->field("entry-type"), QStringLiteral("article")); 0068 QCOMPARE(entry->field("publisher"), QStringLiteral("Elsevier")); 0069 QCOMPARE(entry->field("year"), QStringLiteral("2015")); 0070 QCOMPARE(entry->field("month"), QStringLiteral("09")); 0071 QCOMPARE(entry->field("keyword"), QStringLiteral("Heat recovery; HVAC; Water heating; Thermal modeling; Parametric analysis")); 0072 QCOMPARE(entry->field("volume"), QStringLiteral("6")); 0073 QCOMPARE(entry->field("pages"), QStringLiteral("61-68")); 0074 QCOMPARE(entry->field("doi"), QStringLiteral("10.1016/j.csite.2015.06.001")); 0075 // QVERIFY(!entry->field("cover").isEmpty()); 0076 #endif 0077 } 0078 0079 void PdfTest::testMultiple() { 0080 const QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-sciencedirect.pdf")); 0081 for (int i = 0; i < 5; ++i) { 0082 Tellico::Import::PDFImporter importer(url); 0083 Tellico::Data::CollPtr coll = importer.collection(); 0084 QVERIFY(coll); 0085 } 0086 }