File indexing completed on 2024-05-12 05:09:54
0001 /*************************************************************************** 0002 Copyright (C) 2012 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 #include "ciwtest.h" 0026 0027 #include "../translators/ciwimporter.h" 0028 #include "../collections/bibtexcollection.h" 0029 #include "../fieldformat.h" 0030 0031 #include <KLocalizedString> 0032 0033 #include <QTest> 0034 0035 QTEST_APPLESS_MAIN( CiwTest ) 0036 0037 #define QSL(x) QStringLiteral(x) 0038 0039 void CiwTest::initTestCase() { 0040 KLocalizedString::setApplicationDomain("tellico"); 0041 } 0042 0043 void CiwTest::testImport() { 0044 QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("/data/test.ciw")); 0045 QList<QUrl> urls; 0046 urls << url; 0047 Tellico::Import::CIWImporter importer(urls); 0048 Tellico::Data::CollPtr coll = importer.collection(); 0049 0050 QVERIFY(coll); 0051 QCOMPARE(coll->type(), Tellico::Data::Collection::Bibtex); 0052 QCOMPARE(coll->entryCount(), 6); 0053 QCOMPARE(coll->title(), QSL("Bibliography")); 0054 0055 Tellico::Data::EntryPtr entry = coll->entryById(3); 0056 QVERIFY(entry); 0057 QCOMPARE(entry->field(QSL("entry-type")), QSL("article")); 0058 QCOMPARE(entry->field(QSL("title")), QSL("Key Process Conditions for Production of C(4) Dicarboxylic Acids in " 0059 "Bioreactor Batch Cultures of an Engineered Saccharomyces cerevisiae Strain")); 0060 QCOMPARE(entry->field(QSL("year")), QSL("2010")); 0061 QCOMPARE(entry->field(QSL("pages")), QSL("744-750")); 0062 QCOMPARE(entry->field(QSL("volume")), QSL("76")); 0063 QCOMPARE(entry->field(QSL("journal")), QSL("APPLIED AND ENVIRONMENTAL MICROBIOLOGY")); 0064 QCOMPARE(entry->field(QSL("doi")), QSL("10.1128/AEM.02396-09")); 0065 QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("author"))).count(), 5); 0066 QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("author"))).first(), QSL("Zelle, Rintze M.")); 0067 QVERIFY(!entry->field(QSL("abstract")).isEmpty()); 0068 0069 entry = coll->entryById(6); 0070 QVERIFY(entry); 0071 QCOMPARE(entry->field(QSL("entry-type")), QSL("article")); 0072 QCOMPARE(entry->field(QSL("title")), QSL("Prematurity: An Overview and Public Health Implications")); 0073 QCOMPARE(entry->field(QSL("booktitle")), QSL("ANNUAL REVIEW OF PUBLIC HEALTH, VOL 32")); 0074 QCOMPARE(entry->field(QSL("isbn")), QSL("978-0-8243-2732-3")); 0075 QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("author"))).count(), 4); 0076 QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("author"))).first(), QSL("McCormick, Marie C.")); 0077 QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("editor"))).count(), 3); 0078 QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("editor"))).first(), QSL("Fielding, JE")); 0079 0080 Tellico::Data::BibtexCollection* bColl = dynamic_cast<Tellico::Data::BibtexCollection*>(coll.data()); 0081 QVERIFY(bColl); 0082 QCOMPARE(bColl->fieldByBibtexName(QSL("entry-type"))->name(), QSL("entry-type")); 0083 QVERIFY(Tellico::Import::CIWImporter::maybeCIW(url)); 0084 }