File indexing completed on 2024-05-12 05:10:05
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 "../collections/bookcollection.h" 0033 #include "../collectionfactory.h" 0034 #include "../images/imagefactory.h" 0035 #include "../utils/datafileregistry.h" 0036 0037 #include <KLocalizedString> 0038 0039 #include <QTest> 0040 #include <QStandardPaths> 0041 0042 // needs a GUI for QPixmaps 0043 QTEST_MAIN( PdfTest ) 0044 0045 void PdfTest::initTestCase() { 0046 QStandardPaths::setTestModeEnabled(true); 0047 KLocalizedString::setApplicationDomain("tellico"); 0048 Tellico::RegisterCollection<Tellico::Data::BibtexCollection> registerBibtex(Tellico::Data::Collection::Bibtex, "bibliography"); 0049 Tellico::RegisterCollection<Tellico::Data::BookCollection> registerBook(Tellico::Data::Collection::Book, "book"); 0050 // since we use the XMP importer 0051 Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/xmp2tellico.xsl")); 0052 Tellico::ImageFactory::init(); 0053 } 0054 0055 void PdfTest::testScienceDirect() { 0056 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-sciencedirect.pdf")); 0057 Tellico::Import::PDFImporter importer(url); 0058 QVERIFY(importer.canImport(Tellico::Data::Collection::Book)); 0059 QVERIFY(importer.canImport(Tellico::Data::Collection::Bibtex)); 0060 0061 Tellico::Data::CollPtr coll = importer.collection(); 0062 0063 QVERIFY(coll); 0064 QCOMPARE(coll->type(), Tellico::Data::Collection::Bibtex); 0065 QCOMPARE(coll->entryCount(), 1); 0066 0067 Tellico::Data::EntryPtr entry = coll->entryById(1); 0068 QVERIFY(entry); 0069 #ifdef HAVE_EXEMPI 0070 QCOMPARE(entry->field("title"), QStringLiteral("Parametric analysis of air-water heat recovery concept applied to HVAC systems")); 0071 QCOMPARE(entry->field("author"), QStringLiteral("Mohamad Ramadan; Mostafa Gad El Rab; Mahmoud Khaled")); 0072 QCOMPARE(entry->field("journal"), QStringLiteral("Case Studies in Thermal Engineering")); 0073 QCOMPARE(entry->field("entry-type"), QStringLiteral("article")); 0074 QCOMPARE(entry->field("publisher"), QStringLiteral("Elsevier")); 0075 QCOMPARE(entry->field("year"), QStringLiteral("2015")); 0076 QCOMPARE(entry->field("month"), QStringLiteral("09")); 0077 QCOMPARE(entry->field("keyword"), QStringLiteral("Heat recovery; HVAC; Water heating; Thermal modeling; Parametric analysis")); 0078 QCOMPARE(entry->field("volume"), QStringLiteral("6")); 0079 QCOMPARE(entry->field("pages"), QStringLiteral("61-68")); 0080 QCOMPARE(entry->field("doi"), QStringLiteral("10.1016/j.csite.2015.06.001")); 0081 // QVERIFY(!entry->field("cover").isEmpty()); 0082 #endif 0083 } 0084 0085 void PdfTest::testMultiple() { 0086 const QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-sciencedirect.pdf")); 0087 for (int i = 0; i < 5; ++i) { 0088 Tellico::Import::PDFImporter importer(url); 0089 Tellico::Data::CollPtr coll = importer.collection(); 0090 QVERIFY(coll); 0091 } 0092 } 0093 0094 void PdfTest::testMetadata() { 0095 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-metadata.pdf")); 0096 Tellico::Import::PDFImporter importer(url); 0097 0098 Tellico::Data::CollPtr coll = importer.collection(); 0099 0100 QVERIFY(coll); 0101 QCOMPARE(coll->type(), Tellico::Data::Collection::Bibtex); 0102 QCOMPARE(coll->entryCount(), 1); 0103 0104 Tellico::Data::EntryPtr entry = coll->entryById(1); 0105 QVERIFY(entry); 0106 #ifdef HAVE_POPPLER 0107 QCOMPARE(entry->field("title"), QStringLiteral("The Big Brown Bear")); 0108 QCOMPARE(entry->field("author"), QStringLiteral("Happy Man")); 0109 QCOMPARE(entry->field("entry-type"), QStringLiteral("article")); 0110 QCOMPARE(entry->field("keyword"), QStringLiteral("PDF Metadata")); 0111 #endif 0112 } 0113 0114 void PdfTest::testBookCollection() { 0115 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-metadata.pdf")); 0116 Tellico::Import::PDFImporter importer(url); 0117 0118 // PDF importer defaults to bibtex unless current collection is a book collection 0119 Tellico::Data::CollPtr tmpColl(new Tellico::Data::BookCollection(true)); 0120 importer.setCurrentCollection(tmpColl); 0121 Tellico::Data::CollPtr coll = importer.collection(); 0122 0123 QVERIFY(coll); 0124 QCOMPARE(coll->type(), Tellico::Data::Collection::Book); 0125 QCOMPARE(coll->entryCount(), 1); 0126 0127 Tellico::Data::EntryPtr entry = coll->entryById(1); 0128 QVERIFY(entry); 0129 #ifdef HAVE_POPPLER 0130 QCOMPARE(entry->field("title"), QStringLiteral("The Big Brown Bear")); 0131 QCOMPARE(entry->field("author"), QStringLiteral("Happy Man")); 0132 QCOMPARE(entry->field("keyword"), QStringLiteral("PDF Metadata")); 0133 #endif 0134 }