File indexing completed on 2024-05-12 16:46:13

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