diff --git a/src/tests/alexandriatest.cpp b/src/tests/alexandriatest.cpp index f3639e4f..d5dbc6a0 100644 --- a/src/tests/alexandriatest.cpp +++ b/src/tests/alexandriatest.cpp @@ -1,104 +1,102 @@ /*************************************************************************** Copyright (C) 2009 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * ***************************************************************************/ -#undef QT_NO_CAST_FROM_ASCII - #include "alexandriatest.h" #include "../translators/alexandriaimporter.h" #include "../translators/alexandriaexporter.h" #include "../collections/bookcollection.h" #include "../images/imagefactory.h" #include #include QTEST_GUILESS_MAIN( AlexandriaTest ) -#define QL1(x) QStringLiteral(x) +#define QSL(x) QStringLiteral(x) void AlexandriaTest::initTestCase() { Tellico::ImageFactory::init(); } void AlexandriaTest::testImport() { Tellico::Import::AlexandriaImporter importer; importer.setLibraryPath(QFINDTESTDATA("/data/alexandria/")); // shut the importer up about current collection Tellico::Data::CollPtr tmpColl(new Tellico::Data::BookCollection(true)); importer.setCurrentCollection(tmpColl); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Book); QCOMPARE(coll->entryCount(), 2); // should be translated somehow - QCOMPARE(coll->title(), QL1("My Books")); + QCOMPARE(coll->title(), QSL("My Books")); Tellico::Data::EntryPtr entry = coll->entryById(1); - QCOMPARE(entry->field("title"), QL1("The Hallowed Hunt")); - QCOMPARE(entry->field("comments"), QL1("first line
second line")); + QCOMPARE(entry->field(QSL("title")), QSL("The Hallowed Hunt")); + QCOMPARE(entry->field(QSL("comments")), QSL("first line
second line")); entry = coll->entryById(2); - QCOMPARE(entry->field("title"), QL1("Life Together")); - QCOMPARE(entry->field("author"), QL1("Dietrich Bonhoeffer; My Other Author")); + QCOMPARE(entry->field(QSL("title")), QSL("Life Together")); + QCOMPARE(entry->field(QSL("author")), QSL("Dietrich Bonhoeffer; My Other Author")); // translated - QCOMPARE(entry->field("binding"), QL1("Hardback")); - QCOMPARE(entry->field("isbn"), QL1("0-06-060853-6")); - QCOMPARE(entry->field("pub_year"), QL1("1993")); - QCOMPARE(entry->field("publisher"), QL1("Harper Collins")); - QCOMPARE(entry->field("rating"), QL1("3")); - QCOMPARE(entry->field("read"), QL1("true")); - QCOMPARE(entry->field("loaned"), QL1("")); - QVERIFY(!entry->field("comments").isEmpty()); + QCOMPARE(entry->field(QSL("binding")), QSL("Hardback")); + QCOMPARE(entry->field(QSL("isbn")), QSL("0-06-060853-6")); + QCOMPARE(entry->field(QSL("pub_year")), QSL("1993")); + QCOMPARE(entry->field(QSL("publisher")), QSL("Harper Collins")); + QCOMPARE(entry->field(QSL("rating")), QSL("3")); + QCOMPARE(entry->field(QSL("read")), QSL("true")); + QCOMPARE(entry->field(QSL("loaned")), QString()); + QVERIFY(!entry->field(QSL("comments")).isEmpty()); QTemporaryDir outputDir; Tellico::Export::AlexandriaExporter exporter(coll); exporter.setEntries(coll->entries()); exporter.setURL(QUrl::fromLocalFile(outputDir.path())); QVERIFY(exporter.exec()); - importer.setLibraryPath(outputDir.path() + "/.alexandria/" + coll->title()); + importer.setLibraryPath(outputDir.path() + QSL("/.alexandria/") + coll->title()); Tellico::Data::CollPtr coll2 = importer.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->title(), coll->title()); QCOMPARE(coll2->entryCount(), coll->entryCount()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { // assume IDs stay the same Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images if(f->type() != Tellico::Data::Field::Image) { QCOMPARE(f->name() + e1->field(f), f->name() + e2->field(f)); } } } } diff --git a/src/tests/ciwtest.cpp b/src/tests/ciwtest.cpp index 1eb242ad..f876ab19 100644 --- a/src/tests/ciwtest.cpp +++ b/src/tests/ciwtest.cpp @@ -1,77 +1,77 @@ /*************************************************************************** Copyright (C) 2012 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * ***************************************************************************/ -#undef QT_NO_CAST_FROM_ASCII - #include "ciwtest.h" #include "../translators/ciwimporter.h" #include "../collections/bibtexcollection.h" #include "../fieldformat.h" #include QTEST_APPLESS_MAIN( CiwTest ) +#define QSL(x) QStringLiteral(x) + void CiwTest::testImport() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("/data/test.ciw")); QList urls; urls << url; Tellico::Import::CIWImporter importer(urls); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Bibtex); QCOMPARE(coll->entryCount(), 6); - QCOMPARE(coll->title(), QStringLiteral("Bibliography")); + QCOMPARE(coll->title(), QSL("Bibliography")); Tellico::Data::EntryPtr entry = coll->entryById(3); QVERIFY(entry); - QCOMPARE(entry->field("entry-type"), QStringLiteral("article")); - QCOMPARE(entry->field("title"), QStringLiteral("Key Process Conditions for Production of C(4) Dicarboxylic Acids in " + QCOMPARE(entry->field(QSL("entry-type")), QSL("article")); + QCOMPARE(entry->field(QSL("title")), QSL("Key Process Conditions for Production of C(4) Dicarboxylic Acids in " "Bioreactor Batch Cultures of an Engineered Saccharomyces cerevisiae Strain")); - QCOMPARE(entry->field("year"), QStringLiteral("2010")); - QCOMPARE(entry->field("pages"), QStringLiteral("744-750")); - QCOMPARE(entry->field("volume"), QStringLiteral("76")); - QCOMPARE(entry->field("journal"), QStringLiteral("APPLIED AND ENVIRONMENTAL MICROBIOLOGY")); - QCOMPARE(entry->field("doi"), QStringLiteral("10.1128/AEM.02396-09")); - QCOMPARE(Tellico::FieldFormat::splitValue(entry->field("author")).count(), 5); - QCOMPARE(Tellico::FieldFormat::splitValue(entry->field("author")).first(), QStringLiteral("Zelle, Rintze M.")); - QVERIFY(!entry->field("abstract").isEmpty()); + QCOMPARE(entry->field(QSL("year")), QSL("2010")); + QCOMPARE(entry->field(QSL("pages")), QSL("744-750")); + QCOMPARE(entry->field(QSL("volume")), QSL("76")); + QCOMPARE(entry->field(QSL("journal")), QSL("APPLIED AND ENVIRONMENTAL MICROBIOLOGY")); + QCOMPARE(entry->field(QSL("doi")), QSL("10.1128/AEM.02396-09")); + QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("author"))).count(), 5); + QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("author"))).first(), QSL("Zelle, Rintze M.")); + QVERIFY(!entry->field(QSL("abstract")).isEmpty()); entry = coll->entryById(6); QVERIFY(entry); - QCOMPARE(entry->field("entry-type"), QStringLiteral("article")); - QCOMPARE(entry->field("title"), QStringLiteral("Prematurity: An Overview and Public Health Implications")); - QCOMPARE(entry->field("booktitle"), QStringLiteral("ANNUAL REVIEW OF PUBLIC HEALTH, VOL 32")); - QCOMPARE(entry->field("isbn"), QStringLiteral("978-0-8243-2732-3")); - QCOMPARE(Tellico::FieldFormat::splitValue(entry->field("author")).count(), 4); - QCOMPARE(Tellico::FieldFormat::splitValue(entry->field("author")).first(), QStringLiteral("McCormick, Marie C.")); - QCOMPARE(Tellico::FieldFormat::splitValue(entry->field("editor")).count(), 3); - QCOMPARE(Tellico::FieldFormat::splitValue(entry->field("editor")).first(), QStringLiteral("Fielding, JE")); + QCOMPARE(entry->field(QSL("entry-type")), QSL("article")); + QCOMPARE(entry->field(QSL("title")), QSL("Prematurity: An Overview and Public Health Implications")); + QCOMPARE(entry->field(QSL("booktitle")), QSL("ANNUAL REVIEW OF PUBLIC HEALTH, VOL 32")); + QCOMPARE(entry->field(QSL("isbn")), QSL("978-0-8243-2732-3")); + QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("author"))).count(), 4); + QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("author"))).first(), QSL("McCormick, Marie C.")); + QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("editor"))).count(), 3); + QCOMPARE(Tellico::FieldFormat::splitValue(entry->field(QSL("editor"))).first(), QSL("Fielding, JE")); Tellico::Data::BibtexCollection* bColl = dynamic_cast(coll.data()); QVERIFY(bColl); - QCOMPARE(bColl->fieldByBibtexName("entry-type")->name(), QStringLiteral("entry-type")); + QCOMPARE(bColl->fieldByBibtexName(QSL("entry-type"))->name(), QSL("entry-type")); } diff --git a/src/tests/darkhorsefetchertest.cpp b/src/tests/darkhorsefetchertest.cpp index 2ec29c23..bcc59905 100644 --- a/src/tests/darkhorsefetchertest.cpp +++ b/src/tests/darkhorsefetchertest.cpp @@ -1,87 +1,87 @@ /*************************************************************************** Copyright (C) 2011 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * ***************************************************************************/ -#undef QT_NO_CAST_FROM_ASCII - #include "darkhorsefetchertest.h" #include "../fetch/execexternalfetcher.h" #include "../entry.h" #include "../collections/comicbookcollection.h" #include "../collectionfactory.h" #include "../images/imagefactory.h" #include "../images/image.h" #include "../fieldformat.h" #include #include #include #include QTEST_GUILESS_MAIN( DarkHorseFetcherTest ) +#define QSL(x) QStringLiteral(x) + DarkHorseFetcherTest::DarkHorseFetcherTest() : AbstractFetcherTest() { } void DarkHorseFetcherTest::initTestCase() { - const QString python = QStandardPaths::findExecutable(QStringLiteral("python")); + const QString python = QStandardPaths::findExecutable(QSL("python")); if(python.isEmpty()) { QSKIP("This test requires python", SkipAll); } Tellico::ImageFactory::init(); Tellico::RegisterCollection registerComic(Tellico::Data::Collection::ComicBook, "comicbook"); } void DarkHorseFetcherTest::testComic() { Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook, Tellico::Fetch::Title, - QStringLiteral("axe cop: bad guy earth #1")); + QSL("axe cop: bad guy earth #1")); Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ExecExternalFetcher(this)); KConfig config(QFINDTESTDATA("../fetch/scripts/dark_horse_comics.py.spec"), KConfig::SimpleConfig); - KConfigGroup cg = config.group(QStringLiteral("")); + KConfigGroup cg = config.group(QSL("")); cg.writeEntry("ExecPath", QFINDTESTDATA("../fetch/scripts/dark_horse_comics.py")); // don't sync() and save the new path cg.markAsClean(); fetcher->readConfig(cg, cg.name()); Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); QCOMPARE(results.size(), 1); // the first entry had better be the right one Tellico::Data::EntryPtr entry = results.at(0); - QCOMPARE(entry->field("title"), QStringLiteral("Axe Cop: Bad Guy Earth #1")); - QCOMPARE(entry->field("pub_year"), QStringLiteral("2011")); - QCOMPARE(entry->field("genre"), QStringLiteral("Humor")); - QCOMPARE(entry->field("pages"), QStringLiteral("32")); - QCOMPARE(entry->field("publisher"), QStringLiteral("Dark Horse Comics")); - QCOMPARE(entry->field("writer"), QStringLiteral("Malachai Nicolle")); - QCOMPARE(entry->field("artist"), QStringLiteral("Ethan Nicolle")); - QVERIFY(!entry->field("comments").isEmpty()); - QVERIFY(!entry->field("cover").isEmpty()); - QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/'))); - QVERIFY(!Tellico::ImageFactory::imageById(entry->field("cover")).isNull()); + QCOMPARE(entry->field(QSL("title")), QSL("Axe Cop: Bad Guy Earth #1")); + QCOMPARE(entry->field(QSL("pub_year")), QSL("2011")); + QCOMPARE(entry->field(QSL("genre")), QSL("Humor")); + QCOMPARE(entry->field(QSL("pages")), QSL("32")); + QCOMPARE(entry->field(QSL("publisher")), QSL("Dark Horse Comics")); + QCOMPARE(entry->field(QSL("writer")), QSL("Malachai Nicolle")); + QCOMPARE(entry->field(QSL("artist")), QSL("Ethan Nicolle")); + QVERIFY(!entry->field(QSL("comments")).isEmpty()); + QVERIFY(!entry->field(QSL("cover")).isEmpty()); + QVERIFY(!entry->field(QSL("cover")).contains(QLatin1Char('/'))); + QVERIFY(!Tellico::ImageFactory::imageById(entry->field(QSL("cover"))).isNull()); } diff --git a/src/tests/filtertest.cpp b/src/tests/filtertest.cpp index 762d0f6f..da5faf80 100644 --- a/src/tests/filtertest.cpp +++ b/src/tests/filtertest.cpp @@ -1,252 +1,252 @@ /*************************************************************************** Copyright (C) 2011 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * ***************************************************************************/ #undef QT_NO_CAST_FROM_ASCII #include "filtertest.h" #include "../filter.h" #include "../entry.h" #include "../collections/bookcollection.h" #include QTEST_GUILESS_MAIN( FilterTest ) void FilterTest::initTestCase() { } void FilterTest::testFilter() { Tellico::Data::CollPtr coll(new Tellico::Data::Collection(true, QStringLiteral("TestCollection"))); Tellico::Data::EntryPtr entry(new Tellico::Data::Entry(coll)); entry->setField(QStringLiteral("title"), QStringLiteral("Star Wars")); Tellico::FilterRule* rule1 = new Tellico::FilterRule(QStringLiteral("title"), QStringLiteral("Star Wars"), Tellico::FilterRule::FuncEquals); QCOMPARE(rule1->fieldName(), QStringLiteral("title")); QCOMPARE(rule1->pattern(), QStringLiteral("Star Wars")); QCOMPARE(rule1->function(), Tellico::FilterRule::FuncEquals); Tellico::Filter filter(Tellico::Filter::MatchAny); filter.append(rule1); QVERIFY(filter.matches(entry)); rule1->setFunction(Tellico::FilterRule::FuncNotEquals); QVERIFY(!filter.matches(entry)); rule1->setFunction(Tellico::FilterRule::FuncContains); QVERIFY(filter.matches(entry)); rule1->setFieldName(QStringLiteral("author")); QVERIFY(!filter.matches(entry)); rule1->setFunction(Tellico::FilterRule::FuncNotContains); QVERIFY(filter.matches(entry)); rule1->setFieldName(QString()); rule1->setFunction(Tellico::FilterRule::FuncEquals); QVERIFY(filter.matches(entry)); Tellico::FilterRule* rule2 = new Tellico::FilterRule(QStringLiteral("title"), QStringLiteral("Star"), Tellico::FilterRule::FuncEquals); filter.clear(); filter.append(rule2); QVERIFY(!filter.matches(entry)); rule2->setFunction(Tellico::FilterRule::FuncContains); QVERIFY(filter.matches(entry)); rule2->setFunction(Tellico::FilterRule::FuncNotContains); QVERIFY(!filter.matches(entry)); rule2->setFieldName(QStringLiteral("author")); rule2->setFunction(Tellico::FilterRule::FuncContains); QVERIFY(!filter.matches(entry)); rule2->setFieldName(QString()); QVERIFY(filter.matches(entry)); Tellico::FilterRule* rule3 = new Tellico::FilterRule(QStringLiteral("title"), QStringLiteral("Sta[rt]"), Tellico::FilterRule::FuncRegExp); QCOMPARE(rule3->pattern(), QStringLiteral("Sta[rt]")); filter.clear(); filter.append(rule3); QVERIFY(filter.matches(entry)); rule3->setFunction(Tellico::FilterRule::FuncNotRegExp); QVERIFY(!filter.matches(entry)); rule3->setFieldName(QStringLiteral("author")); QVERIFY(filter.matches(entry)); rule3->setFieldName(QString()); rule3->setFunction(Tellico::FilterRule::FuncRegExp); QVERIFY(filter.matches(entry)); entry->setField(QStringLiteral("title"), QStringLiteral("Tmavomodrý Svět")); Tellico::FilterRule* rule4 = new Tellico::FilterRule(QStringLiteral("title"), QStringLiteral("Tmavomodrý Svět"), Tellico::FilterRule::FuncEquals); filter.clear(); filter.append(rule4); QVERIFY(filter.matches(entry)); rule4->setFunction(Tellico::FilterRule::FuncContains); QVERIFY(filter.matches(entry)); rule4->setFunction(Tellico::FilterRule::FuncRegExp); QVERIFY(filter.matches(entry)); Tellico::FilterRule* rule5 = new Tellico::FilterRule(QStringLiteral("title"), - QLatin1String("Tmavomodry Svet"), + QStringLiteral("Tmavomodry Svet"), Tellico::FilterRule::FuncEquals); filter.clear(); filter.append(rule5); QVERIFY(!filter.matches(entry)); rule5->setFunction(Tellico::FilterRule::FuncContains); QVERIFY(filter.matches(entry)); rule5->setFunction(Tellico::FilterRule::FuncRegExp); QVERIFY(!filter.matches(entry)); Tellico::Data::FieldPtr date(new Tellico::Data::Field(QStringLiteral("date"), QStringLiteral("Date"), Tellico::Data::Field::Date)); coll->addField(date); Tellico::FilterRule* rule6 = new Tellico::FilterRule(QStringLiteral("date"), QStringLiteral("2011-01-24"), Tellico::FilterRule::FuncAfter); QCOMPARE(rule6->pattern(), QStringLiteral("2011-01-24")); filter.clear(); filter.append(rule6); // test Bug 361625 entry->setField(QStringLiteral("date"), QStringLiteral("2011-1-25")); QVERIFY(filter.matches(entry)); entry->setField(QStringLiteral("date"), QStringLiteral("2011-01-25")); QVERIFY(filter.matches(entry)); rule6->setFunction(Tellico::FilterRule::FuncBefore); QVERIFY(!filter.matches(entry)); // check that a date match is neither before or after entry->setField(QStringLiteral("date"), rule6->pattern()); rule6->setFunction(Tellico::FilterRule::FuncAfter); QVERIFY(!filter.matches(entry)); rule6->setFunction(Tellico::FilterRule::FuncBefore); QVERIFY(!filter.matches(entry)); // check that an invalid date never matches entry->setField(QStringLiteral("date"), QStringLiteral("test")); rule6->setFunction(Tellico::FilterRule::FuncAfter); QVERIFY(!filter.matches(entry)); rule6->setFunction(Tellico::FilterRule::FuncBefore); QVERIFY(!filter.matches(entry)); Tellico::Data::FieldPtr number(new Tellico::Data::Field(QStringLiteral("number"), QStringLiteral("Number"), Tellico::Data::Field::Number)); coll->addField(number); entry->setField(QStringLiteral("number"), QStringLiteral("3")); Tellico::FilterRule* rule7 = new Tellico::FilterRule(QStringLiteral("number"), QStringLiteral("5.0"), Tellico::FilterRule::FuncLess); QCOMPARE(rule7->pattern(), QStringLiteral("5.0")); filter.clear(); filter.append(rule7); QVERIFY(filter.matches(entry)); rule7->setFunction(Tellico::FilterRule::FuncGreater); QVERIFY(!filter.matches(entry)); entry->setField(QStringLiteral("number"), QStringLiteral("6")); QVERIFY(filter.matches(entry)); // check that a rating can use greater than Tellico::Data::FieldPtr rating(new Tellico::Data::Field(QStringLiteral("rating"), QStringLiteral("Rating"), Tellico::Data::Field::Rating)); coll->addField(rating); entry->setField(QStringLiteral("rating"), QStringLiteral("3")); Tellico::FilterRule* rule8 = new Tellico::FilterRule(QStringLiteral("rating"), QStringLiteral("2.0"), Tellico::FilterRule::FuncGreater); QCOMPARE(rule8->pattern(), QStringLiteral("2.0")); filter.clear(); filter.append(rule8); QVERIFY(filter.matches(entry)); rule8->setFunction(Tellico::FilterRule::FuncLess); QVERIFY(!filter.matches(entry)); entry->setField(QStringLiteral("rating"), QStringLiteral("1")); QVERIFY(filter.matches(entry)); } void FilterTest::testGroupViewFilter() { // ideally, I'd instantiate a GroupView object and test that, but it's tough with all the dependencies // so this code is identical to what is in Tellico::GroupView::slotFilterGroup() Tellico::Data::CollPtr coll(new Tellico::Data::BookCollection(true, QStringLiteral("TestCollection"))); Tellico::Data::EntryPtr entry1(new Tellico::Data::Entry(coll)); entry1->setField(QStringLiteral("author"), QStringLiteral("John Author")); Tellico::Data::EntryPtr entry2(new Tellico::Data::Entry(coll)); entry2->setField(QStringLiteral("author"), QStringLiteral("John Q. Author")); Tellico::Data::EntryPtr entry3(new Tellico::Data::Entry(coll)); entry3->setField(QStringLiteral("author"), QStringLiteral("John Author") + Tellico::FieldFormat::delimiterString() + QStringLiteral("James Author")); Tellico::Data::EntryPtr entry4(new Tellico::Data::Entry(coll)); entry4->setField(QStringLiteral("author"), QStringLiteral("James Author") + Tellico::FieldFormat::delimiterString() + QStringLiteral("John Author")); Tellico::Data::EntryPtr entry5(new Tellico::Data::Entry(coll)); entry5->setField(QStringLiteral("author"), QStringLiteral("James Author") + Tellico::FieldFormat::delimiterString() + QStringLiteral("John Q. Author")); QString pattern(entry1->formattedField(QStringLiteral("author"))); // the filter should match all since it was the initial way the group view filter was constructed Tellico::Filter filter1(Tellico::Filter::MatchAny); filter1.append(new Tellico::FilterRule(QStringLiteral("author"), pattern, Tellico::FilterRule::FuncContains)); QVERIFY(filter1.matches(entry1)); QVERIFY(filter1.matches(entry2)); QVERIFY(filter1.matches(entry3)); QVERIFY(filter1.matches(entry4)); QVERIFY(filter1.matches(entry5)); QString rxPattern(QStringLiteral("(^|;\\s)") + pattern + QStringLiteral("($|;)")); // the filter should match entry1, entry3, and entry 4 but not entry2 or entry5 Tellico::Filter filter2(Tellico::Filter::MatchAny); filter2.append(new Tellico::FilterRule(QStringLiteral("author"), rxPattern, Tellico::FilterRule::FuncRegExp)); QVERIFY(filter2.matches(entry1)); QVERIFY(!filter2.matches(entry2)); // does not match QVERIFY(filter2.matches(entry3)); QVERIFY(filter2.matches(entry4)); QVERIFY(!filter2.matches(entry5)); } diff --git a/src/tests/gcstartest.cpp b/src/tests/gcstartest.cpp index 47ef934a..1065c0b9 100644 --- a/src/tests/gcstartest.cpp +++ b/src/tests/gcstartest.cpp @@ -1,592 +1,592 @@ /*************************************************************************** Copyright (C) 2009-2010 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * ***************************************************************************/ #undef QT_NO_CAST_FROM_ASCII #include "gcstartest.h" #include "../translators/gcstarimporter.h" #include "../translators/gcstarexporter.h" #include "../collections/collectioninitializer.h" #include "../collectionfactory.h" #include "../images/imagefactory.h" #include "../utils/datafileregistry.h" #include "../fieldformat.h" #include -#define FIELDS(entry, fieldName) Tellico::FieldFormat::splitValue(entry->field(fieldName)) -#define TABLES(entry, fieldName) Tellico::FieldFormat::splitTable(entry->field(fieldName)) +#define FIELDS(entry, fieldName) Tellico::FieldFormat::splitValue(entry->field(QStringLiteral(fieldName))) +#define TABLES(entry, fieldName) Tellico::FieldFormat::splitTable(entry->field(QStringLiteral(fieldName))) QTEST_GUILESS_MAIN( GCstarTest ) void GCstarTest::initTestCase() { Tellico::ImageFactory::init(); Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/gcstar2tellico.xsl")); // need to register the collection types Tellico::CollectionInitializer ci; } void GCstarTest::testBook() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-book.gcs")); Tellico::Import::GCstarImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Book); QCOMPARE(coll->entryCount(), 2); // should be translated somehow QCOMPARE(coll->title(), QStringLiteral("GCstar Import")); Tellico::Data::EntryPtr entry = coll->entryById(1); QVERIFY(entry); QCOMPARE(entry->field("title"), QStringLiteral("The Reason for God")); QCOMPARE(entry->field("pub_year"), QStringLiteral("2008")); QCOMPARE(FIELDS(entry, "author").count(), 2); QCOMPARE(FIELDS(entry, "author").first(), QStringLiteral("Timothy Keller")); QCOMPARE(entry->field("isbn"), QStringLiteral("978-0-525-95049-3")); QCOMPARE(entry->field("publisher"), QStringLiteral("Dutton Adult")); QCOMPARE(FIELDS(entry, "genre").count(), 2); QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("non-fiction")); QCOMPARE(FIELDS(entry, "keyword").count(), 2); QCOMPARE(FIELDS(entry, "keyword").at(0), QStringLiteral("tag1")); QCOMPARE(FIELDS(entry, "keyword").at(1), QStringLiteral("tag2")); // file has rating of 4, Tellico uses half the rating of GCstar, so it should be 2 QCOMPARE(entry->field("rating"), QStringLiteral("2")); QCOMPARE(FIELDS(entry, "language").count(), 1); QCOMPARE(FIELDS(entry, "language").at(0), QStringLiteral("English")); Tellico::Export::GCstarExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::GCstarImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->entryCount(), coll->entryCount()); QCOMPARE(coll2->title(), coll->title()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images if(f->type() != Tellico::Data::Field::Image) { QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); } } } } void GCstarTest::testComicBook() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-comicbook.gcs")); Tellico::Import::GCstarImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::ComicBook); QCOMPARE(coll->entryCount(), 1); // should be translated somehow QCOMPARE(coll->title(), QStringLiteral("GCstar Import")); Tellico::Data::EntryPtr entry = coll->entryById(1); QVERIFY(entry); QCOMPARE(entry->field("title"), QStringLiteral("title")); QCOMPARE(entry->field("pub_year"), QStringLiteral("2010")); QCOMPARE(entry->field("series"), QStringLiteral("series")); QCOMPARE(entry->field("issue"), QStringLiteral("1")); QCOMPARE(FIELDS(entry, "writer").count(), 2); QCOMPARE(FIELDS(entry, "writer").first(), QStringLiteral("writer1")); QCOMPARE(entry->field("isbn"), QStringLiteral("1234567890")); QCOMPARE(entry->field("artist"), QStringLiteral("illustrator")); QCOMPARE(entry->field("publisher"), QStringLiteral("publisher")); QCOMPARE(entry->field("colorist"), QStringLiteral("colourist")); QCOMPARE(entry->field("category"), QStringLiteral("category")); QCOMPARE(entry->field("format"), QStringLiteral("format")); QCOMPARE(entry->field("collection"), QStringLiteral("collection")); QCOMPARE(entry->field("pur_date"), QStringLiteral("29/08/2010")); QCOMPARE(entry->field("pur_price"), QStringLiteral("12.99")); QCOMPARE(entry->field("numberboards"), QStringLiteral("1")); QCOMPARE(entry->field("signed"), QStringLiteral("true")); // file has rating of 4, Tellico uses half the rating of GCstar, so it should be 2 QCOMPARE(entry->field("rating"), QStringLiteral("2")); QVERIFY(!entry->field("plot").isEmpty()); QVERIFY(!entry->field("comments").isEmpty()); Tellico::Export::GCstarExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::GCstarImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->entryCount(), coll->entryCount()); QCOMPARE(coll2->title(), coll->title()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images if(f->type() != Tellico::Data::Field::Image) { QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); } } } } void GCstarTest::testVideo() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-video.gcs")); Tellico::Import::GCstarImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Video); QCOMPARE(coll->entryCount(), 3); Tellico::Data::EntryPtr entry = coll->entryById(2); QVERIFY(entry); QCOMPARE(entry->field("title"), QStringLiteral("The Man from Snowy River")); QCOMPARE(entry->field("year"), QStringLiteral("1982")); QCOMPARE(FIELDS(entry, "director").count(), 1); QCOMPARE(FIELDS(entry, "director").first(), QStringLiteral("George Miller")); QCOMPARE(FIELDS(entry, "nationality").count(), 1); QCOMPARE(FIELDS(entry, "nationality").first(), QStringLiteral("Australia")); QCOMPARE(entry->field("medium"), QStringLiteral("DVD")); QCOMPARE(entry->field("running-time"), QStringLiteral("102")); QCOMPARE(FIELDS(entry, "genre").count(), 4); QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("Drama")); QStringList castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); QCOMPARE(castList.count(), 10); QCOMPARE(castList.at(0), QStringLiteral("Tom Burlinson::Jim Craig")); QCOMPARE(castList.at(2), QStringLiteral("Kirk Douglas::Harrison / Spur")); QCOMPARE(FIELDS(entry, "keyword").count(), 2); QCOMPARE(FIELDS(entry, "keyword").at(0), QStringLiteral("tag2")); QCOMPARE(FIELDS(entry, "keyword").at(1), QStringLiteral("tag1")); QCOMPARE(entry->field("rating"), QStringLiteral("3")); QVERIFY(!entry->field("plot").isEmpty()); QVERIFY(!entry->field("comments").isEmpty()); entry = coll->entryById(4); QVERIFY(entry); castList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("cast"))); QCOMPARE(castList.count(), 11); QCOMPARE(castList.at(0), QStringLiteral("Famke Janssen::Marnie Watson")); QCOMPARE(entry->field("location"), QStringLiteral("On Hard Drive")); Tellico::Export::GCstarExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::GCstarImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->entryCount(), coll->entryCount()); QCOMPARE(coll2->title(), coll->title()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images and tables if(f->type() != Tellico::Data::Field::Image && f->type() != Tellico::Data::Field::Table) { QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); } else if(f->type() == Tellico::Data::Field::Table) { QStringList rows1 = Tellico::FieldFormat::splitTable(e1->field(f)); QStringList rows2 = Tellico::FieldFormat::splitTable(e2->field(f)); QCOMPARE(rows1.count(), rows2.count()); for(int i = 0; i < rows1.count(); ++i) { QCOMPARE(f->name() + rows2.at(i), f->name() + rows1.at(i)); } } } } } void GCstarTest::testMusic() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-music.gcs")); Tellico::Import::GCstarImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Album); QCOMPARE(coll->entryCount(), 1); Tellico::Data::EntryPtr entry = coll->entryById(1); QVERIFY(entry); QCOMPARE(entry->field("title"), QStringLiteral("Lifesong")); QCOMPARE(entry->field("year"), QStringLiteral("2005")); QCOMPARE(FIELDS(entry, "artist").count(), 1); QCOMPARE(FIELDS(entry, "artist").first(), QStringLiteral("Casting Crowns")); QCOMPARE(FIELDS(entry, "label").count(), 1); QCOMPARE(FIELDS(entry, "label").first(), QStringLiteral("Beach Street Records")); QCOMPARE(entry->field("medium"), QStringLiteral("Compact Disc")); QCOMPARE(FIELDS(entry, "genre").count(), 2); QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("Electronic")); QStringList trackList = Tellico::FieldFormat::splitTable(entry->field(QStringLiteral("track"))); QCOMPARE(trackList.count(), 11); QCOMPARE(trackList.at(1), QStringLiteral("Praise You In This Storm::Casting Crowns::4:59")); QCOMPARE(FIELDS(entry, "producer").count(), 1); QCOMPARE(FIELDS(entry, "producer").at(0), QStringLiteral("Mark A. Miller")); QCOMPARE(FIELDS(entry, "composer").count(), 4); QCOMPARE(FIELDS(entry, "composer").at(1), QStringLiteral("David Hunt")); QCOMPARE(entry->field("cdate"), QStringLiteral("2009-09-22")); Tellico::Export::GCstarExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::GCstarImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->entryCount(), coll->entryCount()); QCOMPARE(coll2->title(), coll->title()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images if(f->type() != Tellico::Data::Field::Image) { QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); } } } } void GCstarTest::testVideoGame() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-videogame.gcs")); Tellico::Import::GCstarImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Game); QCOMPARE(coll->entryCount(), 2); Tellico::Data::EntryPtr entry = coll->entryById(2); QVERIFY(entry); QCOMPARE(entry->field("title"), QStringLiteral("Halo 3")); QCOMPARE(entry->field("year"), QStringLiteral("2007")); QCOMPARE(entry->field("platform"), QStringLiteral("Xbox 360")); QCOMPARE(FIELDS(entry, "developer").count(), 1); QCOMPARE(FIELDS(entry, "developer").first(), QStringLiteral("Bungie Studios")); QCOMPARE(FIELDS(entry, "publisher").count(), 1); QCOMPARE(FIELDS(entry, "publisher").first(), QStringLiteral("Microsoft Games Studios")); QCOMPARE(FIELDS(entry, "genre").count(), 3); QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("Action")); QCOMPARE(entry->field("cdate"), QStringLiteral("2009-09-24")); QVERIFY(!entry->field("description").isEmpty()); Tellico::Export::GCstarExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::GCstarImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->entryCount(), coll->entryCount()); QCOMPARE(coll2->title(), coll->title()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images if(f->type() != Tellico::Data::Field::Image) { QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); } } } } void GCstarTest::testBoardGame() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-boardgame.gcs")); Tellico::Import::GCstarImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::BoardGame); QCOMPARE(coll->entryCount(), 2); Tellico::Data::EntryPtr entry = coll->entryById(1); QVERIFY(entry); QCOMPARE(entry->field("title"), QStringLiteral("Risk")); QCOMPARE(entry->field("year"), QStringLiteral("1959")); QCOMPARE(FIELDS(entry, "designer").count(), 2); QCOMPARE(FIELDS(entry, "designer").at(1), QStringLiteral("Michael I. Levin")); QCOMPARE(FIELDS(entry, "publisher").count(), 11); QCOMPARE(FIELDS(entry, "publisher").at(1), QStringLiteral("Borras Plana S.A.")); QCOMPARE(FIELDS(entry, "mechanism").count(), 3); QCOMPARE(FIELDS(entry, "mechanism").at(1), QStringLiteral("Dice Rolling")); QCOMPARE(FIELDS(entry, "genre").count(), 1); QCOMPARE(FIELDS(entry, "genre").at(0), QStringLiteral("Wargame")); QVERIFY(!entry->field("description").isEmpty()); QVERIFY(!entry->field("comments").isEmpty()); Tellico::Export::GCstarExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::GCstarImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->entryCount(), coll->entryCount()); QCOMPARE(coll2->title(), coll->title()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images if(f->type() != Tellico::Data::Field::Image) { QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); } } } } void GCstarTest::testWine() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-wine.gcs")); Tellico::Import::GCstarImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Wine); QCOMPARE(coll->entryCount(), 1); Tellico::Data::EntryPtr entry = coll->entryById(1); QVERIFY(entry); QCOMPARE(entry->field("vintage"), QStringLiteral("1990")); QCOMPARE(entry->field("producer"), QStringLiteral("producer")); QCOMPARE(entry->field("type"), QStringLiteral("Red Wine")); QCOMPARE(entry->field("country"), QStringLiteral("australia")); QCOMPARE(entry->field("quantity"), QStringLiteral("1")); QCOMPARE(FIELDS(entry, "varietal").count(), 2); QCOMPARE(FIELDS(entry, "varietal").at(1), QStringLiteral("grape2")); QCOMPARE(entry->field("pur_date"), QStringLiteral("28/08/2010")); QCOMPARE(entry->field("pur_price"), QStringLiteral("12.99")); QCOMPARE(entry->field("appellation"), QStringLiteral("designation")); QCOMPARE(entry->field("distinction"), QStringLiteral("distinction")); QCOMPARE(entry->field("soil"), QStringLiteral("soil")); QCOMPARE(entry->field("alcohol"), QStringLiteral("12")); QCOMPARE(entry->field("volume"), QStringLiteral("750")); QCOMPARE(entry->field("rating"), QStringLiteral("3")); QCOMPARE(entry->field("gift"), QStringLiteral("true")); QCOMPARE(entry->field("tasted"), QStringLiteral("true")); QVERIFY(!entry->field("description").isEmpty()); QVERIFY(!entry->field("comments").isEmpty()); Tellico::Export::GCstarExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::GCstarImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->entryCount(), coll->entryCount()); QCOMPARE(coll2->title(), coll->title()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images if(f->type() != Tellico::Data::Field::Image) { QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); } } } } void GCstarTest::testCoin() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-coin.gcs")); Tellico::Import::GCstarImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Coin); QCOMPARE(coll->entryCount(), 1); Tellico::Data::EntryPtr entry = coll->entryById(1); QVERIFY(entry); QCOMPARE(entry->field("denomination"), QStringLiteral("0.05")); QCOMPARE(entry->field("year"), QStringLiteral("1974")); QCOMPARE(entry->field("currency"), QStringLiteral("USD")); QCOMPARE(entry->field("diameter"), QStringLiteral("12.7")); QCOMPARE(entry->field("estimate"), QStringLiteral("5")); QCOMPARE(entry->field("grade"), QStringLiteral("Mint State-65")); QCOMPARE(entry->field("country"), QStringLiteral("australia")); QCOMPARE(entry->field("location"), QStringLiteral("current")); QCOMPARE(entry->field("service"), QStringLiteral("PCGS")); QCOMPARE(TABLES(entry, "metal").count(), 2); QCOMPARE(TABLES(entry, "metal").at(1), QStringLiteral("metal2")); QVERIFY(!entry->field("comments").isEmpty()); Tellico::Export::GCstarExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::GCstarImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->entryCount(), coll->entryCount()); QCOMPARE(coll2->title(), coll->title()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images if(f->type() != Tellico::Data::Field::Image) { QCOMPARE(f->name() + e2->field(f), f->name() + e1->field(f)); } } } } void GCstarTest::testCustomFields() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/test-book.gcs")); Tellico::Import::GCstarImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Book); QCOMPARE(coll->entryCount(), 2); // should be translated somehow QCOMPARE(coll->title(), QStringLiteral("GCstar Import")); // test custom fields Tellico::Data::FieldPtr field = coll->fieldByName(QStringLiteral("gcsfield1")); QVERIFY(field); QCOMPARE(field->name(), QStringLiteral("gcsfield1")); QCOMPARE(field->title(), QStringLiteral("New boolean")); QCOMPARE(field->category(), QStringLiteral("User fields")); QCOMPARE(field->type(), Tellico::Data::Field::Bool); field = coll->fieldByName(QStringLiteral("gcsfield2")); QVERIFY(field); QCOMPARE(field->title(), QStringLiteral("New choice")); QCOMPARE(field->type(), Tellico::Data::Field::Choice); QCOMPARE(field->allowed(), QStringList() << QStringLiteral("yes") << QStringLiteral("no") << QStringLiteral("maybe")); field = coll->fieldByName(QStringLiteral("gcsfield3")); QVERIFY(field); QCOMPARE(field->title(), QStringLiteral("New rating")); QCOMPARE(field->type(), Tellico::Data::Field::Rating); QCOMPARE(field->property(QStringLiteral("minimum")), QStringLiteral("1")); QCOMPARE(field->property(QStringLiteral("maximum")), QStringLiteral("5")); field = coll->fieldByName(QStringLiteral("gcsfield4")); QVERIFY(field); QCOMPARE(field->title(), QStringLiteral("New field")); QCOMPARE(field->type(), Tellico::Data::Field::Line); field = coll->fieldByName(QStringLiteral("gcsfield5")); QVERIFY(field); QCOMPARE(field->title(), QStringLiteral("New image")); QCOMPARE(field->type(), Tellico::Data::Field::Image); field = coll->fieldByName(QStringLiteral("gcsfield6")); QVERIFY(field); QCOMPARE(field->title(), QStringLiteral("New long field")); QCOMPARE(field->type(), Tellico::Data::Field::Para); field = coll->fieldByName(QStringLiteral("gcsfield7")); QVERIFY(field); QCOMPARE(field->title(), QStringLiteral("New date")); QCOMPARE(field->type(), Tellico::Data::Field::Date); field = coll->fieldByName(QStringLiteral("gcsfield8")); QVERIFY(field); QCOMPARE(field->title(), QStringLiteral("New number")); QCOMPARE(field->type(), Tellico::Data::Field::Number); QCOMPARE(field->defaultValue(), QStringLiteral("2")); field = coll->fieldByName(QStringLiteral("gcsfield9")); QVERIFY(field); QCOMPARE(field->title(), QStringLiteral("dependency")); QCOMPARE(field->type(), Tellico::Data::Field::Line); QCOMPARE(field->property(QStringLiteral("template")), QStringLiteral("%{gcsfield1},%{gcsfield2}")); field = coll->fieldByName(QStringLiteral("gcsfield10")); QVERIFY(field); QCOMPARE(field->title(), QStringLiteral("list")); QCOMPARE(field->type(), Tellico::Data::Field::Table); QCOMPARE(field->property(QStringLiteral("columns")), QStringLiteral("1")); Tellico::Data::EntryPtr entry = coll->entryById(2); QVERIFY(entry); QCOMPARE(entry->field("gcsfield1"), QStringLiteral("true")); QCOMPARE(entry->field("gcsfield2"), QStringLiteral("maybe")); QCOMPARE(entry->field("gcsfield3"), QStringLiteral("3")); QCOMPARE(entry->field("gcsfield4"), QStringLiteral("random value")); QCOMPARE(entry->field("gcsfield6"), QStringLiteral("all\nthe best \nstuff")); QCOMPARE(entry->field("gcsfield7"), QStringLiteral("2013-03-31")); QCOMPARE(entry->field("gcsfield9"), QStringLiteral("true,maybe")); QCOMPARE(TABLES(entry, "gcsfield10").count(), 2); QCOMPARE(TABLES(entry, "gcsfield10").at(1), QStringLiteral("list2")); Tellico::Export::GCstarExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::GCstarImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); foreach(Tellico::Data::FieldPtr f1, coll->fields()) { Tellico::Data::FieldPtr f2 = coll2->fieldByName(f1->name()); QVERIFY2(f2, qPrintable(f1->name())); QCOMPARE(f1->name(), f2->name()); QCOMPARE(f1->title(), f2->title()); QCOMPARE(f1->category(), f2->category()); QCOMPARE(f1->allowed(), f2->allowed()); QCOMPARE(f1->type(), f2->type()); QCOMPARE(f1->flags(), f2->flags()); QCOMPARE(f1->formatType(), f2->formatType()); QCOMPARE(f1->description(), f2->description()); QCOMPARE(f1->defaultValue(), f2->defaultValue()); QCOMPARE(f1->property(QStringLiteral("minimum")), f2->property(QStringLiteral("minimum"))); QCOMPARE(f1->property(QStringLiteral("maximum")), f2->property(QStringLiteral("maximum"))); QCOMPARE(f1->property(QStringLiteral("columns")), f2->property(QStringLiteral("columns"))); QCOMPARE(f1->property(QStringLiteral("template")), f2->property(QStringLiteral("template"))); } foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); QCOMPARE(TABLES(e2, "gcsfield10").count(), 2); QCOMPARE(TABLES(e2, "gcsfield10").at(1), QStringLiteral("list2")); foreach(Tellico::Data::FieldPtr f, coll->fields()) { // skip images if(f->type() != Tellico::Data::Field::Image) { QCOMPARE(f->name() + e1->field(f), f->name() + e2->field(f)); } } } } diff --git a/src/tests/griffithtest.cpp b/src/tests/griffithtest.cpp index 0d0325da..c1dfb503 100644 --- a/src/tests/griffithtest.cpp +++ b/src/tests/griffithtest.cpp @@ -1,78 +1,76 @@ /*************************************************************************** Copyright (C) 2012 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * ***************************************************************************/ -#undef QT_NO_CAST_FROM_ASCII - #include "griffithtest.h" #include "../translators/griffithimporter.h" #include "../collections/videocollection.h" #include "../collectionfactory.h" #include "../fieldformat.h" #include "../images/imagefactory.h" #include "../utils/datafileregistry.h" #include -#define FIELDS(entry, fieldName) Tellico::FieldFormat::splitValue(entry->field(fieldName)) -#define ROWS(entry, fieldName) Tellico::FieldFormat::splitTable(entry->field(fieldName)) +#define QSL(x) QStringLiteral(x) +#define ROWS(entry, fieldName) Tellico::FieldFormat::splitTable(entry->field(QStringLiteral(fieldName))) QTEST_GUILESS_MAIN( GriffithTest ) void GriffithTest::initTestCase() { Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/griffith2tellico.xsl")); Tellico::ImageFactory::init(); // need to register the collection type Tellico::RegisterCollection registerVideo(Tellico::Data::Collection::Video, "video"); } void GriffithTest::testMovies() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/griffith.xml")); Tellico::Import::GriffithImporter importer(url); // can't import images for local test importer.setOptions(importer.options() & ~Tellico::Import::ImportShowImageErrors); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Video); QCOMPARE(coll->entryCount(), 5); Tellico::Data::EntryPtr entry = coll->entryById(1); QVERIFY(entry); - QCOMPARE(entry->field("title"), QStringLiteral("Serendipity")); - QCOMPARE(entry->field("origtitle"), QStringLiteral("Serendipity")); - QCOMPARE(entry->field("director"), QStringLiteral("Peter Chelsom")); - QCOMPARE(entry->field("year"), QStringLiteral("2001")); - QCOMPARE(entry->field("certification"), QStringLiteral("PG-13 (USA)")); - QCOMPARE(entry->field("nationality"), QStringLiteral("USA")); - QCOMPARE(entry->field("genre"), QStringLiteral("Comedy; Romance; Fantasy")); - QCOMPARE(entry->field("rating"), QStringLiteral("6")); - QCOMPARE(entry->field("running-time"), QStringLiteral("90")); - QCOMPARE(entry->field("studio"), QStringLiteral("studio")); - QCOMPARE(entry->field("seen"), QStringLiteral("true")); - QCOMPARE(entry->field("medium"), QStringLiteral("DVD")); - QCOMPARE(ROWS(entry, "cast").first(), QStringLiteral("John Cusack::Jonathan Trager")); - QVERIFY(!entry->field("plot").isEmpty()); + QCOMPARE(entry->field(QSL("title")), QSL("Serendipity")); + QCOMPARE(entry->field(QSL("origtitle")), QSL("Serendipity")); + QCOMPARE(entry->field(QSL("director")), QSL("Peter Chelsom")); + QCOMPARE(entry->field(QSL("year")), QSL("2001")); + QCOMPARE(entry->field(QSL("certification")), QSL("PG-13 (USA)")); + QCOMPARE(entry->field(QSL("nationality")), QSL("USA")); + QCOMPARE(entry->field(QSL("genre")), QSL("Comedy; Romance; Fantasy")); + QCOMPARE(entry->field(QSL("rating")), QSL("6")); + QCOMPARE(entry->field(QSL("running-time")), QSL("90")); + QCOMPARE(entry->field(QSL("studio")), QSL("studio")); + QCOMPARE(entry->field(QSL("seen")), QSL("true")); + QCOMPARE(entry->field(QSL("medium")), QSL("DVD")); + QCOMPARE(ROWS(entry, "cast").first(), QSL("John Cusack::Jonathan Trager")); + QVERIFY(!entry->field(QSL("plot")).isEmpty()); // cover will be empty since local images don't exist } diff --git a/src/tests/tellicoreadtest.cpp b/src/tests/tellicoreadtest.cpp index 7f0d53f2..425150c7 100644 --- a/src/tests/tellicoreadtest.cpp +++ b/src/tests/tellicoreadtest.cpp @@ -1,341 +1,339 @@ /*************************************************************************** Copyright (C) 2009 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * ***************************************************************************/ -#undef QT_NO_CAST_FROM_ASCII - #include "tellicoreadtest.h" #include "../translators/tellicoimporter.h" #include "../collections/bookcollection.h" #include "../collections/coincollection.h" #include "../collectionfactory.h" #include "../translators/tellicoxmlexporter.h" #include "../translators/tellico_xml.h" #include "../images/imagefactory.h" #include "../images/image.h" #include "../fieldformat.h" #include "../entry.h" #include "../utils/xmlhandler.h" #include QTEST_GUILESS_MAIN( TellicoReadTest ) #define QSL(x) QStringLiteral(x) #define TELLICOREAD_NUMBER_OF_CASES 10 void TellicoReadTest::initTestCase() { // need to register this first Tellico::RegisterCollection registerBook(Tellico::Data::Collection::Book, "book"); Tellico::RegisterCollection registerCoin(Tellico::Data::Collection::Coin, "coin"); Tellico::RegisterCollection registerBase(Tellico::Data::Collection::Base, "entry"); for(int i = 1; i < TELLICOREAD_NUMBER_OF_CASES; ++i) { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA(QSL("data/books-format%1.bc").arg(i))); Tellico::Import::TellicoImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); m_collections.append(coll); } Tellico::ImageFactory::init(); } void TellicoReadTest::init() { Tellico::ImageFactory::clean(true); } void TellicoReadTest::testBookCollection() { Tellico::Data::CollPtr coll1 = m_collections[0]; // skip the first one for(int i = 1; i < m_collections.count(); ++i) { Tellico::Data::CollPtr coll2 = m_collections[i]; QVERIFY(coll2); QCOMPARE(coll1->type(), coll2->type()); QCOMPARE(coll1->title(), coll2->title()); QCOMPARE(coll1->entryCount(), coll2->entryCount()); } } void TellicoReadTest::testEntries() { QFETCH(QString, fieldName); Tellico::Data::FieldPtr field1 = m_collections[0]->fieldByName(fieldName); // skip the first one for(int i = 1; i < m_collections.count(); ++i) { Tellico::Data::FieldPtr field2 = m_collections[i]->fieldByName(fieldName); if(field1 && field2) { QCOMPARE(field1->name(), field2->name()); QCOMPARE(field1->title(), field2->title()); QCOMPARE(field1->category(), field2->category()); QCOMPARE(field1->type(), field2->type()); QCOMPARE(field1->flags(), field2->flags()); QCOMPARE(field1->propertyList(), field2->propertyList()); } for(int j = 0; j < m_collections[0]->entryCount(); ++j) { // don't test id values since the initial value has changed from 0 to 1 Tellico::Data::EntryPtr entry1 = m_collections[0]->entries().at(j); Tellico::Data::EntryPtr entry2 = m_collections[i]->entries().at(j); QVERIFY(entry1); QVERIFY(entry2); QCOMPARE(entry1->field(fieldName), entry2->field(fieldName)); } } } void TellicoReadTest::testEntries_data() { QTest::addColumn("fieldName"); QTest::newRow("title") << QSL("title"); QTest::newRow("author") << QSL("author"); QTest::newRow("publisher") << QSL("publisher"); QTest::newRow("keywords") << QSL("keywords"); QTest::newRow("keyword") << QSL("keyword"); QTest::newRow("genre") << QSL("genre"); QTest::newRow("isbn") << QSL("isbn"); QTest::newRow("pub_year") << QSL("pub_year"); QTest::newRow("rating") << QSL("rating"); QTest::newRow("comments") << QSL("comments"); } void TellicoReadTest::testCoinCollection() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/coins-format9.tc")); Tellico::Import::TellicoImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Coin); Tellico::Data::FieldPtr field = coll->fieldByName(QStringLiteral("title")); // old field has Dependent value, now is Line QVERIFY(field); QCOMPARE(field->type(), Tellico::Data::Field::Line); QCOMPARE(field->title(), QSL("Title")); QVERIFY(field->hasFlag(Tellico::Data::Field::Derived)); Tellico::Data::EntryPtr entry = coll->entries().at(0); // test creating the derived title QCOMPARE(entry->title(), QSL("1974D Jefferson Nickel 0.05")); } void TellicoReadTest::testTableData() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("/data/tabletest.tc")); Tellico::Import::TellicoImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->entryCount(), 3); Tellico::Export::TellicoXMLExporter exporter(coll); exporter.setEntries(coll->entries()); Tellico::Import::TellicoImporter importer2(exporter.text()); Tellico::Data::CollPtr coll2 = importer2.collection(); QVERIFY(coll2); QCOMPARE(coll2->type(), coll->type()); QCOMPARE(coll2->entryCount(), coll->entryCount()); foreach(Tellico::Data::EntryPtr e1, coll->entries()) { Tellico::Data::EntryPtr e2 = coll2->entryById(e1->id()); QVERIFY(e2); foreach(Tellico::Data::FieldPtr f, coll->fields()) { QCOMPARE(f->name() + e1->field(f), f->name() + e2->field(f)); } } // test table value concatenation Tellico::Data::EntryPtr e3(new Tellico::Data::Entry(coll)); coll->addEntries(e3); - QString value = "11a" + Tellico::FieldFormat::delimiterString() + "11b" - + Tellico::FieldFormat::columnDelimiterString() + "12" - + Tellico::FieldFormat::columnDelimiterString() + "13" - + Tellico::FieldFormat::rowDelimiterString() + "21" - + Tellico::FieldFormat::columnDelimiterString() + "22" - + Tellico::FieldFormat::columnDelimiterString() + "23"; + QString value = QSL("11a") + Tellico::FieldFormat::delimiterString() + QSL("11b") + + Tellico::FieldFormat::columnDelimiterString() + QSL("12") + + Tellico::FieldFormat::columnDelimiterString() + QSL("13") + + Tellico::FieldFormat::rowDelimiterString() + QSL("21") + + Tellico::FieldFormat::columnDelimiterString() + QSL("22") + + Tellico::FieldFormat::columnDelimiterString() + QSL("23"); e3->setField(QSL("table"), value); QStringList groups = e3->groupNamesByFieldName(QStringLiteral("table")); QCOMPARE(groups.count(), 3); // the order of the group names is not stable (it uses QSet::toList) QCOMPARE(groups.toSet(), QSet() << QSL("11a") << QSL("11b") << QSL("21")); // test having empty value in table Tellico::Data::EntryPtr e = coll2->entryById(2); QVERIFY(e); - const QStringList rows = Tellico::FieldFormat::splitTable(e->field(QStringLiteral("table"))); + const QStringList rows = Tellico::FieldFormat::splitTable(e->field(QSL("table"))); QCOMPARE(rows.count(), 1); const QStringList cols = Tellico::FieldFormat::splitRow(rows.at(0)); QCOMPARE(cols.count(), 3); } void TellicoReadTest::testDuplicateLoans() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("/data/duplicate_loan.xml")); Tellico::Import::TellicoImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->borrowers().count(), 1); Tellico::Data::BorrowerPtr bor = coll->borrowers().first(); QVERIFY(bor); QCOMPARE(bor->loans().count(), 1); } void TellicoReadTest::testDuplicateBorrowers() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("/data/duplicate_borrower.xml")); Tellico::Import::TellicoImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->borrowers().count(), 1); Tellico::Data::BorrowerPtr bor = coll->borrowers().first(); QVERIFY(bor); QCOMPARE(bor->loans().count(), 2); } void TellicoReadTest::testLocalImage() { // this is the md5 hash of the tellico.png icon, used as an image id const QString imageId(QSL("dde5bf2cbd90fad8635a26dfb362e0ff.png")); // not yet loaded QVERIFY(!Tellico::ImageFactory::self()->hasImageInMemory(imageId)); QVERIFY(!Tellico::ImageFactory::self()->hasImageInfo(imageId)); QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("/data/local_image.xml")); QFile f(url.toLocalFile()); QVERIFY(f.exists()); QVERIFY(f.open(QIODevice::ReadOnly | QIODevice::Text)); QTextStream in(&f); QString fileText = in.readAll(); // replace %COVER% with image file location fileText.replace(QSL("%COVER%"), QFINDTESTDATA("../../icons/tellico.png")); Tellico::Import::TellicoImporter importer(fileText); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->entries().count(), 1); Tellico::Data::EntryPtr entry = coll->entries().at(0); QVERIFY(entry); QCOMPARE(entry->field(QStringLiteral("cover")), imageId); // the image should be in local memory now QVERIFY(Tellico::ImageFactory::self()->hasImageInMemory(imageId)); QVERIFY(Tellico::ImageFactory::self()->hasImageInfo(imageId)); const Tellico::Data::Image& img = Tellico::ImageFactory::imageById(imageId); QVERIFY(!img.isNull()); } void TellicoReadTest::testRemoteImage() { // this is the md5 hash of the logo.png icon, used as an image id const QString imageId(QSL("757322046f4aa54290a3d92b05b71ca1.png")); // not yet loaded QVERIFY(!Tellico::ImageFactory::self()->hasImageInMemory(imageId)); QVERIFY(!Tellico::ImageFactory::self()->hasImageInfo(imageId)); QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("/data/local_image.xml")); QFile f(url.toLocalFile()); QVERIFY(f.exists()); QVERIFY(f.open(QIODevice::ReadOnly | QIODevice::Text)); QTextStream in(&f); QString fileText = in.readAll(); // replace %COVER% with image file location fileText.replace(QSL("%COVER%"), QSL("http://tellico-project.org/sites/default/files/logo.png")); Tellico::Import::TellicoImporter importer(fileText); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->entries().count(), 1); Tellico::Data::EntryPtr entry = coll->entries().at(0); QVERIFY(entry); QCOMPARE(entry->field(QStringLiteral("cover")), imageId); // the image should be in local memory now QVERIFY(Tellico::ImageFactory::self()->hasImageInMemory(imageId)); QVERIFY(Tellico::ImageFactory::self()->hasImageInfo(imageId)); const Tellico::Data::Image& img = Tellico::ImageFactory::imageById(imageId); QVERIFY(!img.isNull()); } void TellicoReadTest::testXMLHandler() { QFETCH(QByteArray, data); QFETCH(QString, expectedString); QFETCH(bool, changeEncoding); QString origString = QString::fromUtf8(data); QCOMPARE(Tellico::XMLHandler::readXMLData(data), expectedString); QCOMPARE(Tellico::XMLHandler::setUtf8XmlEncoding(origString), changeEncoding); } void TellicoReadTest::testXMLHandler_data() { QTest::addColumn("data"); QTest::addColumn("expectedString"); QTest::addColumn("changeEncoding"); QTest::newRow("basic") << QByteArray("value") << QStringLiteral("value") << false; QTest::newRow("utf8") << QByteArray("\nvalue") << QStringLiteral("\nvalue") << false; QTest::newRow("latin1") << QByteArray("\nvalue") << QStringLiteral("\nvalue") << true; } void TellicoReadTest::testXmlName() { QFETCH(bool, valid); QFETCH(QString, input); QFETCH(QString, modified); QCOMPARE(Tellico::XML::validXMLElementName(input), valid); QCOMPARE(Tellico::XML::elementName(input), modified); } void TellicoReadTest::testXmlName_data() { QTest::addColumn("valid"); QTest::addColumn("input"); QTest::addColumn("modified"); QTest::newRow("start") << true << QSL("start") << QSL("start"); QTest::newRow("_start") << true << QSL("_start") << QSL("_start"); QTest::newRow("n42") << true << QSL("n42") << QSL("n42"); // an empty string is handled in CollectionFieldsDialog when creating the field name - QTest::newRow("42") << false << QSL("42") << QString(""); + QTest::newRow("42") << false << QSL("42") << QString(); QTest::newRow("she is") << false << QSL("she is") << QSL("she-is"); QTest::newRow("colon:") << true << QSL("colon:") << QSL("colon:"); QTest::newRow("Svět") << true << QSL("Svět") << QSL("Svět"); QTest::newRow("") << false << QSL("") << QSL("test"); }