diff --git a/src/models/stringcomparison.cpp b/src/models/stringcomparison.cpp index 73548cd3..1ec12f02 100644 --- a/src/models/stringcomparison.cpp +++ b/src/models/stringcomparison.cpp @@ -1,231 +1,236 @@ /*************************************************************************** Copyright (C) 2007-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 . * * * ***************************************************************************/ #include "stringcomparison.h" #include "../fieldformat.h" #include "../tellico_debug.h" #include namespace { int compareFloat(const QString& s1, const QString& s2) { bool ok1, ok2; float n1 = s1.toFloat(&ok1); if(!ok1) { return 0; } float n2 = s2.toFloat(&ok2); if(!ok2) { return 0; } return n1 > n2 ? 1 : (n1 < n2 ? -1 : 0); } } Tellico::StringComparison* Tellico::StringComparison::create(Data::FieldPtr field_) { if(!field_) { myWarning() << "No field for creating a string comparison"; return nullptr; } if(field_->type() == Data::Field::Number || field_->type() == Data::Field::Rating) { return new NumberComparison(); } else if(field_->type() == Data::Field::Bool) { return new BoolComparison(); } else if(field_->type() == Data::Field::Date || field_->formatType() == FieldFormat::FormatDate) { return new ISODateComparison(); } else if(field_->formatType() == FieldFormat::FormatTitle) { return new TitleComparison(); } else if(field_->property(QStringLiteral("lcc")) == QLatin1String("true") || field_->name() == QLatin1String("lcc")) { // allow LCC comparison if LCC property is set, or if the name is lcc return new LCCComparison(); } return new StringComparison(); } Tellico::StringComparison::StringComparison() { } int Tellico::StringComparison::compare(const QString& str1_, const QString& str2_) { return str1_.localeAwareCompare(str2_); } Tellico::BoolComparison::BoolComparison() : StringComparison() { } int Tellico::BoolComparison::compare(const QString& str1_, const QString& str2_) { - return str1_.compare(str2_); + const bool b1 = str1_.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0 + || str1_ == QLatin1String("1"); + const bool b2 = str2_.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0 + || str2_ == QLatin1String("1"); + return b1 == b2 ? 0 : (b1 ? 1 : -1); } Tellico::TitleComparison::TitleComparison() : StringComparison() { } int Tellico::TitleComparison::compare(const QString& str1_, const QString& str2_) { const QString title1 = FieldFormat::sortKeyTitle(str1_).toLower(); const QString title2 = FieldFormat::sortKeyTitle(str2_).toLower(); return title1.localeAwareCompare(title2); } Tellico::NumberComparison::NumberComparison() : StringComparison() { } int Tellico::NumberComparison::compare(const QString& str1_, const QString& str2_) { bool ok1, ok2; float num1 = 0, num2 = 0; const QStringList values1 = FieldFormat::splitValue(str1_); const QStringList values2 = FieldFormat::splitValue(str2_); int index = 0; do { if((ok1 = index < values1.count())) { num1 = values1.at(index).toFloat(&ok1); } if((ok2 = index < values2.count())) { num2 = values2.at(index).toFloat(&ok2); } if(ok1 && ok2) { if(!qFuzzyCompare(num1, num2)) { const float ret = num1 - num2; // if abs(ret) < 0.5, we want to round up/down to -1 or 1 // so that comparing 0.2 to 0.4 yields 1, for example, and not 0 return ret < 0 ? qMin(-1, qRound(ret)) : qMax(1, qRound(ret)); } } ++index; } while(ok1 && ok2); if(ok1 && !ok2) { return 1; } else if(!ok1 && ok2) { return -1; } return 0; } // for details on the LCC comparison, see // http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/ // http://library.dts.edu/Pages/RM/Helps/lc_call.shtml Tellico::LCCComparison::LCCComparison() : StringComparison(), m_regexp(QLatin1String("^([A-Z]+)" "(\\d+(?:\\.\\d+)?)" "\\.?([A-Z]*)" "(\\d*)" "\\.?([A-Z]*)" "(\\d*)" "(?: (.+))?")) { } int Tellico::LCCComparison::compare(const QString& str1_, const QString& str2_) { if(str1_.isEmpty()) { return str2_.isEmpty() ? 0 : -1; } if(str2_.isEmpty()) { return 1; } // myDebug() << str1_ << " to " << str2_; int pos1 = m_regexp.indexIn(str1_); const QStringList cap1 = m_regexp.capturedTexts(); int pos2 = m_regexp.indexIn(str2_); const QStringList cap2 = m_regexp.capturedTexts(); if(pos1 > -1 && pos2 > -1) { int res = compareLCC(cap1, cap2); // myLog() << "...result = " << res; return res; } else { if(pos1 == -1) { myDebug() << "no regexp match:" << str1_; } if(pos2 == -1) { myDebug() << "no regexp match:" << str2_; } } return StringComparison::compare(str1_, str2_); } int Tellico::LCCComparison::compareLCC(const QStringList& cap1, const QStringList& cap2) const { // the first item in the list is the full match, so start array index at 1 int res = 0; return (res = cap1[1].compare(cap2[1])) != 0 ? res : (res = compareFloat(cap1[2], cap2[2])) != 0 ? res : (res = cap1[3].compare(cap2[3])) != 0 ? res : (res = compareFloat(QLatin1String("0.") + cap1[4], QLatin1String("0.") + cap2[4])) != 0 ? res : (res = cap1[5].compare(cap2[5])) != 0 ? res : (res = compareFloat(QLatin1String("0.") + cap1[6], QLatin1String("0.") + cap2[6])) != 0 ? res : (res = cap1[7].compare(cap2[7])) != 0 ? res : 0; } Tellico::ISODateComparison::ISODateComparison() : StringComparison() { } int Tellico::ISODateComparison::compare(const QString& str1, const QString& str2) { if(str1.isEmpty()) { return str2.isEmpty() ? 0 : -1; } if(str2.isEmpty()) { // str1 is not return 1; } // modelled after Field::formatDate() // so dates would sort as expected without padding month and day with zero // and accounting for "current year - 1 - 1" default scheme + const QDate now = QDate::currentDate(); QStringList dlist1 = str1.split(QLatin1Char('-'), QString::KeepEmptyParts); bool ok = true; - int y1 = dlist1.count() > 0 ? dlist1[0].toInt(&ok) : QDate::currentDate().year(); + int y1 = dlist1.count() > 0 ? dlist1[0].toInt(&ok) : now.year(); if(!ok) { - y1 = QDate::currentDate().year(); + y1 = now.year(); } int m1 = dlist1.count() > 1 ? dlist1[1].toInt(&ok) : 1; if(!ok) { m1 = 1; } int d1 = dlist1.count() > 2 ? dlist1[2].toInt(&ok) : 1; if(!ok) { d1 = 1; } QDate date1(y1, m1, d1); QStringList dlist2 = str2.split(QLatin1Char('-'), QString::KeepEmptyParts); - int y2 = dlist2.count() > 0 ? dlist2[0].toInt(&ok) : QDate::currentDate().year(); + int y2 = dlist2.count() > 0 ? dlist2[0].toInt(&ok) : now.year(); if(!ok) { - y2 = QDate::currentDate().year(); + y2 = now.year(); } int m2 = dlist2.count() > 1 ? dlist2[1].toInt(&ok) : 1; if(!ok) { m2 = 1; } int d2 = dlist2.count() > 2 ? dlist2[2].toInt(&ok) : 1; if(!ok) { d2 = 1; } QDate date2(y2, m2, d2); if(date1 < date2) { return -1; } else if(date1 > date2) { return 1; } return 0; } diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 912d8f6b..7f970915 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,866 +1,866 @@ include(ECMAddTests) include(ECMMarkNonGuiExecutable) SET( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) # formattest includes fieldformat that include core/tellico_config.h # which is generated in the build directory INCLUDE_DIRECTORIES( ${Tellico_BINARY_DIR}/src ) add_executable(entitytest entitytest.cpp ../fieldformat.cpp) ecm_mark_nongui_executable(entitytest) add_test(entitytest entitytest) ecm_mark_as_test(entitytest) TARGET_LINK_LIBRARIES(entitytest utils config Qt5::Test ) add_executable(cuecattest cuecattest.cpp) ecm_mark_nongui_executable(cuecattest) add_test(cuecattest cuecattest) ecm_mark_as_test(cuecattest) TARGET_LINK_LIBRARIES(cuecattest utils Qt5::Test) add_executable(isbntest isbntest.cpp) ecm_mark_nongui_executable(isbntest) add_test(isbntest isbntest) ecm_mark_as_test(isbntest) TARGET_LINK_LIBRARIES(isbntest utils Qt5::Test) add_executable(lccntest lccntest.cpp) ecm_mark_nongui_executable(lccntest) add_test(lccntest lccntest) ecm_mark_as_test(lccntest) TARGET_LINK_LIBRARIES(lccntest utils Qt5::Test) add_executable(lcctest lcctest.cpp ../field.cpp ../fieldformat.cpp) ecm_mark_nongui_executable(lcctest) add_test(lcctest lcctest) ecm_mark_as_test(lcctest) TARGET_LINK_LIBRARIES(lcctest tellicomodels Qt5::Test) add_executable(formattest formattest.cpp ../fieldformat.cpp) ecm_mark_nongui_executable(formattest) add_test(formattest formattest) ecm_mark_as_test(formattest) TARGET_LINK_LIBRARIES(formattest config Qt5::Test) add_executable(fieldtest fieldtest.cpp ../field.cpp ../fieldformat.cpp ../gui/urlfieldlogic.cpp) ecm_mark_nongui_executable(fieldtest) add_test(fieldtest fieldtest) ecm_mark_as_test(fieldtest) TARGET_LINK_LIBRARIES(fieldtest config utils Qt5::Test) -add_executable(comparisontest comparisontest.cpp ../field.cpp ../fieldformat.cpp) -ecm_mark_nongui_executable(comparisontest) -add_test(comparisontest comparisontest) -ecm_mark_as_test(comparisontest) -TARGET_LINK_LIBRARIES(comparisontest tellicomodels Qt5::Test) - add_executable(imagetest imagetest.cpp ../utils/tellico_utils.cpp ../utils/guiproxy.cpp ../utils/cursorsaver.cpp ../fieldformat.cpp) ecm_mark_nongui_executable(imagetest) add_test(imagetest imagetest) ecm_mark_as_test(imagetest) TARGET_LINK_LIBRARIES(imagetest images KF5::Archive Qt5::Test) add_executable(imagejobtest imagejobtest.cpp ../fieldformat.cpp) ecm_mark_nongui_executable(imagejobtest) add_test(imagejobtest imagejobtest) ecm_mark_as_test(imagejobtest) TARGET_LINK_LIBRARIES(imagejobtest images KF5::Archive Qt5::Test) add_executable(iso6937test iso6937test.cpp) ecm_mark_nongui_executable(iso6937test) add_test(iso6937test iso6937test) ecm_mark_as_test(iso6937test) TARGET_LINK_LIBRARIES(iso6937test utils Qt5::Test) add_executable(iso5426test iso5426test.cpp) ecm_mark_nongui_executable(iso5426test) add_test(iso5426test iso5426test) ecm_mark_as_test(iso5426test) TARGET_LINK_LIBRARIES(iso5426test utils Qt5::Test) SET(tellicotest_SRCS ../collection.cpp ../entry.cpp ../entrygroup.cpp ../entrycomparison.cpp ../field.cpp ../fieldformat.cpp ../filter.cpp ../borrower.cpp ../collectionfactory.cpp ../derivedvalue.cpp ../progressmanager.cpp ) add_library(tellicotest STATIC ${tellicotest_SRCS}) TARGET_LINK_LIBRARIES(tellicotest Qt5::Core Qt5::Gui KF5::I18n KF5::ConfigWidgets) ADD_DEPENDENCIES(tellicotest tellico_config) SET(translatorstest_SRCS ../translators/tellicoimporter.cpp ../translators/xsltimporter.cpp ../translators/textimporter.cpp ../translators/dataimporter.cpp ../translators/importer.cpp ../translators/tellicoxmlhandler.cpp ../translators/tellico_xml.cpp ../translators/xmlstatehandler.cpp ../translators/xslthandler.cpp ) add_library(translatorstest STATIC ${translatorstest_SRCS}) TARGET_LINK_LIBRARIES(translatorstest Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Xml KF5::I18n KF5::Archive KF5::KIOWidgets KF5::ConfigWidgets ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${LIBXSLT_EXSLT_LIBRARIES} ) set(TELLICO_TEST_LIBS tellicotest collections utils images core tellicomodels Qt5::Test KF5::KIOCore KF5::Archive ) add_executable(collectiontest collectiontest.cpp ../document.cpp ../translators/tellicoxmlexporter.cpp ../translators/tellicozipexporter.cpp ../translators/exporter.cpp ) ecm_mark_nongui_executable(collectiontest) add_test(collectiontest collectiontest) ecm_mark_as_test(collectiontest) TARGET_LINK_LIBRARIES(collectiontest translatorstest ${TELLICO_TEST_LIBS}) +add_executable(comparisontest comparisontest.cpp) +ecm_mark_nongui_executable(comparisontest) +add_test(comparisontest comparisontest) +ecm_mark_as_test(comparisontest) +TARGET_LINK_LIBRARIES(comparisontest tellicotest tellicomodels Qt5::Test) + add_executable(documenttest documenttest.cpp ../document.cpp ../translators/tellicoxmlexporter.cpp ../translators/tellicozipexporter.cpp ../translators/exporter.cpp ) ecm_mark_nongui_executable(documenttest) add_test(documenttest documenttest) ecm_mark_as_test(documenttest) TARGET_LINK_LIBRARIES(documenttest translatorstest ${TELLICO_TEST_LIBS}) add_executable(filtertest filtertest.cpp) ecm_mark_nongui_executable(filtertest) add_test(filtertest filtertest) ecm_mark_as_test(filtertest) TARGET_LINK_LIBRARIES(filtertest gui ${TELLICO_TEST_LIBS}) add_executable(tellicomodeltest tellicomodeltest.cpp modeltest.cpp ../document.cpp ../translators/tellicoimporter.cpp ../translators/dataimporter.cpp ../translators/importer.cpp ../translators/tellicoxmlexporter.cpp ../translators/tellicozipexporter.cpp ../translators/exporter.cpp ../translators/tellicoxmlhandler.cpp ../translators/tellico_xml.cpp ../translators/xmlstatehandler.cpp ) ecm_mark_nongui_executable(tellicomodeltest) add_test(tellicomodeltest tellicomodeltest) ecm_mark_as_test(tellicomodeltest) TARGET_LINK_LIBRARIES(tellicomodeltest ${TELLICO_TEST_LIBS} ${LIBXML2_LIBRARIES}) ###################################################### add_executable(adstest adstest.cpp ../translators/adsimporter.cpp ../translators/importer.cpp ) ecm_mark_nongui_executable(adstest) add_test(adstest adstest) ecm_mark_as_test(adstest) TARGET_LINK_LIBRARIES(adstest ${TELLICO_TEST_LIBS}) add_executable(alexandriatest alexandriatest.cpp ../translators/alexandriaimporter.cpp ../translators/importer.cpp ../translators/alexandriaexporter.cpp ../translators/exporter.cpp ) ecm_mark_nongui_executable(alexandriatest) add_test(alexandriatest alexandriatest) ecm_mark_as_test(alexandriatest) TARGET_LINK_LIBRARIES(alexandriatest ${TELLICO_TEST_LIBS}) add_executable(amctest amctest.cpp ../translators/amcimporter.cpp ../translators/dataimporter.cpp ../translators/importer.cpp ) ecm_mark_nongui_executable(amctest) add_test(amctest amctest) ecm_mark_as_test(amctest) TARGET_LINK_LIBRARIES(amctest ${TELLICO_TEST_LIBS}) IF( TAGLIB_FOUND ) add_executable(audiofiletest audiofiletest.cpp ../translators/audiofileimporter.cpp ../translators/dataimporter.cpp ../translators/importer.cpp ) ecm_mark_nongui_executable(audiofiletest) add_test(audiofiletest audiofiletest) ecm_mark_as_test(audiofiletest) TARGET_LINK_LIBRARIES(audiofiletest ${TELLICO_TEST_LIBS} ${TAGLIB_LIBRARIES}) ENDIF( TAGLIB_FOUND ) add_executable(bibtextest bibtextest.cpp ../translators/bibteximporter.cpp ../translators/importer.cpp ../translators/bibtexexporter.cpp ../translators/exporter.cpp ) ecm_mark_nongui_executable(bibtextest) add_test(bibtextest bibtextest) ecm_mark_as_test(bibtextest) TARGET_LINK_LIBRARIES(bibtextest ${TELLICO_BTPARSE_LIBS} ${TELLICO_TEST_LIBS}) add_executable(bibtexmltest bibtexmltest.cpp ../translators/bibtexmlimporter.cpp ../translators/bibtexmlexporter.cpp ../translators/exporter.cpp ) ecm_mark_nongui_executable(bibtexmltest) add_test(bibtexmltest bibtexmltest) ecm_mark_as_test(bibtexmltest) TARGET_LINK_LIBRARIES(bibtexmltest translatorstest core ${TELLICO_TEST_LIBS}) add_executable(citetest citetest.cpp ../collections/bibtexcollection.cpp ../core/filehandler.cpp ) ecm_mark_nongui_executable(citetest) add_test(citetest citetest) ecm_mark_as_test(citetest) TARGET_LINK_LIBRARIES(citetest cite tellicotest config images Qt5::Test) ADD_DEPENDENCIES(citetest tellico_config) add_executable(ciwtest ciwtest.cpp ../translators/ciwimporter.cpp ../translators/importer.cpp ) ecm_mark_nongui_executable(ciwtest) add_test(ciwtest ciwtest) ecm_mark_as_test(ciwtest) TARGET_LINK_LIBRARIES(ciwtest ${TELLICO_TEST_LIBS}) add_executable(csvtest csvtest.cpp ../translators/csvparser.cpp ../translators/csvexporter.cpp ../translators/exporter.cpp ) ecm_mark_nongui_executable(csvtest) add_test(csvtest csvtest) ecm_mark_as_test(csvtest) TARGET_LINK_LIBRARIES(csvtest ${TELLICO_CSV_LIBS} translatorstest ${TELLICO_TEST_LIBS}) add_executable(delicioustest delicioustest.cpp ../translators/deliciousimporter.cpp ) ecm_mark_nongui_executable(delicioustest) add_test(delicioustest delicioustest) ecm_mark_as_test(delicioustest) TARGET_LINK_LIBRARIES(delicioustest rtf2html-tellico translatorstest ${TELLICO_TEST_LIBS}) add_executable(filelistingtest filelistingtest.cpp ../translators/filelistingimporter.cpp ../translators/xmphandler.cpp ) ecm_mark_nongui_executable(filelistingtest) add_test(filelistingtest filelistingtest) ecm_mark_as_test(filelistingtest) TARGET_LINK_LIBRARIES(filelistingtest translatorstest ${TELLICO_TEST_LIBS} KF5::Solid ) IF( KF5FileMetaData_FOUND ) TARGET_LINK_LIBRARIES(filelistingtest KF5::FileMetaData) ENDIF( KF5FileMetaData_FOUND ) IF( Exempi_FOUND ) TARGET_LINK_LIBRARIES(filelistingtest ${Exempi_LIBRARIES}) ENDIF( Exempi_FOUND ) add_executable(gcstartest gcstartest.cpp ../translators/gcstarimporter.cpp ../translators/gcstarexporter.cpp ../translators/tellicoxmlexporter.cpp ../translators/tellicozipexporter.cpp ../translators/exporter.cpp ../document.cpp ) ecm_mark_nongui_executable(gcstartest) add_test(gcstartest gcstartest) ecm_mark_as_test(gcstartest) TARGET_LINK_LIBRARIES(gcstartest translatorstest ${TELLICO_TEST_LIBS}) add_executable(griffithtest griffithtest.cpp ../translators/griffithimporter.cpp ) ecm_mark_nongui_executable(griffithtest) add_test(griffithtest griffithtest) ecm_mark_as_test(griffithtest) TARGET_LINK_LIBRARIES(griffithtest translatorstest ${TELLICO_TEST_LIBS}) add_executable(htmlexportertest htmlexportertest.cpp ../translators/htmlexporter.cpp ../translators/tellicoxmlexporter.cpp ../translators/tellicozipexporter.cpp ../translators/exporter.cpp ../document.cpp ) ecm_mark_nongui_executable(htmlexportertest) add_test(htmlexportertest htmlexportertest) ecm_mark_as_test(htmlexportertest) TARGET_LINK_LIBRARIES(htmlexportertest translatorstest ${TELLICO_TEST_LIBS}) add_executable(modstest modstest.cpp) ecm_mark_nongui_executable(modstest) add_test(modstest modstest) ecm_mark_as_test(modstest) TARGET_LINK_LIBRARIES(modstest translatorstest ${TELLICO_TEST_LIBS}) add_executable(referencertest referencertest.cpp ../translators/referencerimporter.cpp ) ecm_mark_nongui_executable(referencertest) add_test(referencertest referencertest) ecm_mark_as_test(referencertest) TARGET_LINK_LIBRARIES(referencertest translatorstest ${TELLICO_TEST_LIBS}) add_executable(ristest ristest.cpp ../translators/risimporter.cpp ../translators/importer.cpp ) ecm_mark_nongui_executable(ristest) add_test(ristest ristest) ecm_mark_as_test(ristest) TARGET_LINK_LIBRARIES(ristest ${TELLICO_TEST_LIBS}) add_executable(tellicoreadtest tellicoreadtest.cpp ../translators/tellicoxmlexporter.cpp ../translators/tellicozipexporter.cpp ../translators/exporter.cpp ../document.cpp ) ecm_mark_nongui_executable(tellicoreadtest) add_test(tellicoreadtest tellicoreadtest) ecm_mark_as_test(tellicoreadtest) TARGET_LINK_LIBRARIES(tellicoreadtest translatorstest ${TELLICO_TEST_LIBS}) add_executable(vinoxmltest vinoxmltest.cpp ../translators/vinoxmlimporter.cpp ) ecm_mark_nongui_executable(vinoxmltest) add_test(vinoxmltest vinoxmltest) ecm_mark_as_test(vinoxmltest) TARGET_LINK_LIBRARIES(vinoxmltest translatorstest ${TELLICO_TEST_LIBS}) SET(fetcherstest_SRCS ../fetch/fetcher.cpp ../fetch/fetcherjob.cpp ../fetch/fetchresult.cpp ../fetch/fetchmanager.cpp ../fetch/messagehandler.cpp ../fetch/configwidget.cpp ../document.cpp ../translators/tellicoxmlexporter.cpp ../translators/tellicozipexporter.cpp ../translators/exporter.cpp ) # FetchManager links to SRUFetcher for the default sources # so have to include everything it needs SET(fetcherstest_SRCS ${fetcherstest_SRCS} ../fetch/srufetcher.cpp ../fetch/xmlfetcher.cpp ../gui/lineedit.cpp ../gui/combobox.cpp ../gui/stringmapwidget.cpp ) add_library(fetcherstest STATIC ${fetcherstest_SRCS}) TARGET_LINK_LIBRARIES(fetcherstest translatorstest Qt5::Core Qt5::Gui Qt5::DBus KF5::ConfigCore KF5::ConfigGui KF5::ConfigWidgets KF5::I18n KF5::Archive KF5::IconThemes KF5::XmlGui KF5::SonnetCore KF5::SonnetUi ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${LIBXSLT_EXSLT_LIBRARIES} ) ADD_DEPENDENCIES(fetcherstest tellico_config) IF(${KF5KIO_VERSION} VERSION_GREATER "5.18.0") TARGET_LINK_LIBRARIES(fetcherstest KF5::KIOGui ) ENDIF(${KF5KIO_VERSION} VERSION_GREATER "5.18.0") # the PDF importer uses CrossRefFetcher, so include the test in the fetchers add_executable(pdftest pdftest.cpp ../translators/pdfimporter.cpp ../translators/xmphandler.cpp ../entryupdatejob.cpp ) ecm_mark_nongui_executable(pdftest) add_test(pdftest pdftest) ecm_mark_as_test(pdftest) TARGET_LINK_LIBRARIES(pdftest translatorstest fetcherstest ${TELLICO_TEST_LIBS}) IF( Exempi_FOUND ) TARGET_LINK_LIBRARIES(pdftest ${Exempi_LIBRARIES}) ENDIF( Exempi_FOUND ) IF( Poppler_Qt5_FOUND ) TARGET_LINK_LIBRARIES(pdftest Poppler::Qt5) ENDIF( Poppler_Qt5_FOUND ) # fetcher tests from here down IF(BUILD_FETCHER_TESTS) add_executable(entryupdatejobtest entryupdatejobtest.cpp ../entryupdatejob.cpp ../fetch/arxivfetcher.cpp ) ecm_mark_nongui_executable(entryupdatejobtest) add_test(entryupdatejobtest entryupdatejobtest) ecm_mark_as_test(entryupdatejobtest) TARGET_LINK_LIBRARIES(entryupdatejobtest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(allocinefetchertest allocinefetchertest.cpp abstractfetchertest.cpp ../fetch/allocinefetcher.cpp ../fetch/execexternalfetcher.cpp ../translators/bibteximporter.cpp ../translators/risimporter.cpp ../gui/collectiontypecombo.cpp ) ecm_mark_nongui_executable(allocinefetchertest) add_test(allocinefetchertest allocinefetchertest) ecm_mark_as_test(allocinefetchertest) # SonnetCore is needed for GUI::LineEdit TARGET_LINK_LIBRARIES(allocinefetchertest fetcherstest translatorstest newstuff ${TELLICO_BTPARSE_LIBS} ${TELLICO_TEST_LIBS} ) add_executable(amazonfetchertest amazonfetchertest.cpp abstractfetchertest.cpp ../fetch/amazonfetcher.cpp ../fetch/amazonrequest.cpp ../fetch/messagelogger.cpp ) ecm_mark_nongui_executable(amazonfetchertest) add_test(amazonfetchertest amazonfetchertest) ecm_mark_as_test(amazonfetchertest) TARGET_LINK_LIBRARIES(amazonfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(animenfofetchertest animenfofetchertest.cpp abstractfetchertest.cpp ../fetch/animenfofetcher.cpp ) ecm_mark_nongui_executable(animenfofetchertest) add_test(animenfofetchertest animenfofetchertest) ecm_mark_as_test(animenfofetchertest) TARGET_LINK_LIBRARIES(animenfofetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(arxivfetchertest arxivfetchertest.cpp abstractfetchertest.cpp ../fetch/arxivfetcher.cpp ) ecm_mark_nongui_executable(arxivfetchertest) add_test(arxivfetchertest arxivfetchertest) ecm_mark_as_test(arxivfetchertest) TARGET_LINK_LIBRARIES(arxivfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(bedethequefetchertest bedethequefetchertest.cpp abstractfetchertest.cpp ../fetch/bedethequefetcher.cpp ) ecm_mark_nongui_executable(bedethequefetchertest) add_test(bedethequefetchertest bedethequefetchertest) ecm_mark_as_test(bedethequefetchertest) TARGET_LINK_LIBRARIES(bedethequefetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(bibliosharefetchertest bibliosharefetchertest.cpp abstractfetchertest.cpp ../fetch/bibliosharefetcher.cpp ) ecm_mark_nongui_executable(bibliosharefetchertest) add_test(bibliosharefetchertest bibliosharefetchertest) ecm_mark_as_test(bibliosharefetchertest) TARGET_LINK_LIBRARIES(bibliosharefetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(boardgamegeekfetchertest boardgamegeekfetchertest.cpp abstractfetchertest.cpp ../fetch/boardgamegeekfetcher.cpp ) ecm_mark_nongui_executable(boardgamegeekfetchertest) add_test(boardgamegeekfetchertest boardgamegeekfetchertest) ecm_mark_as_test(boardgamegeekfetchertest) TARGET_LINK_LIBRARIES(boardgamegeekfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(comicvinefetchertest comicvinefetchertest.cpp abstractfetchertest.cpp ../fetch/comicvinefetcher.cpp ) ecm_mark_nongui_executable(comicvinefetchertest) add_test(comicvinefetchertest comicvinefetchertest) ecm_mark_as_test(comicvinefetchertest) TARGET_LINK_LIBRARIES(comicvinefetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(colnectfetchertest colnectfetchertest.cpp abstractfetchertest.cpp ../fetch/colnectfetcher.cpp ) ecm_mark_nongui_executable(colnectfetchertest) add_test(colnectfetchertest colnectfetchertest) ecm_mark_as_test(colnectfetchertest) TARGET_LINK_LIBRARIES(colnectfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(crossreffetchertest crossreffetchertest.cpp abstractfetchertest.cpp ../fetch/crossreffetcher.cpp ) ecm_mark_nongui_executable(crossreffetchertest) add_test(crossreffetchertest crossreffetchertest) ecm_mark_as_test(crossreffetchertest) TARGET_LINK_LIBRARIES(crossreffetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(darkhorsefetchertest darkhorsefetchertest.cpp abstractfetchertest.cpp ../fetch/execexternalfetcher.cpp ../translators/bibteximporter.cpp ../translators/risimporter.cpp ../gui/collectiontypecombo.cpp ) ecm_mark_nongui_executable(darkhorsefetchertest) add_test(darkhorsefetchertest darkhorsefetchertest) ecm_mark_as_test(darkhorsefetchertest) TARGET_LINK_LIBRARIES(darkhorsefetchertest fetcherstest newstuff ${TELLICO_BTPARSE_LIBS} ${TELLICO_TEST_LIBS} ) add_executable(dbcfetchertest dbcfetchertest.cpp abstractfetchertest.cpp ../fetch/dbcfetcher.cpp ) ecm_mark_nongui_executable(dbcfetchertest) add_test(dbcfetchertest dbcfetchertest) ecm_mark_as_test(dbcfetchertest) TARGET_LINK_LIBRARIES(dbcfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(dblpfetchertest dblpfetchertest.cpp abstractfetchertest.cpp ../fetch/dblpfetcher.cpp ) ecm_mark_nongui_executable(dblpfetchertest) add_test(dblpfetchertest dblpfetchertest) ecm_mark_as_test(dblpfetchertest) TARGET_LINK_LIBRARIES(dblpfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(discogsfetchertest discogsfetchertest.cpp abstractfetchertest.cpp ../fetch/discogsfetcher.cpp ) ecm_mark_nongui_executable(discogsfetchertest) add_test(discogsfetchertest discogsfetchertest) ecm_mark_as_test(discogsfetchertest) TARGET_LINK_LIBRARIES(discogsfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(doubanfetchertest doubanfetchertest.cpp abstractfetchertest.cpp ../fetch/doubanfetcher.cpp ) ecm_mark_nongui_executable(doubanfetchertest) add_test(doubanfetchertest doubanfetchertest) ecm_mark_as_test(doubanfetchertest) TARGET_LINK_LIBRARIES(doubanfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(dvdfrfetchertest dvdfrfetchertest.cpp abstractfetchertest.cpp ../fetch/dvdfrfetcher.cpp ) ecm_mark_nongui_executable(dvdfrfetchertest) add_test(dvdfrfetchertest dvdfrfetchertest) ecm_mark_as_test(dvdfrfetchertest) TARGET_LINK_LIBRARIES(dvdfrfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(entrezfetchertest entrezfetchertest.cpp abstractfetchertest.cpp ../fetch/entrezfetcher.cpp ) ecm_mark_nongui_executable(entrezfetchertest) add_test(entrezfetchertest entrezfetchertest) ecm_mark_as_test(entrezfetchertest) TARGET_LINK_LIBRARIES(entrezfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(externalfetchertest externalfetchertest.cpp abstractfetchertest.cpp ../fetch/execexternalfetcher.cpp ../translators/bibteximporter.cpp ../translators/risimporter.cpp ../gui/collectiontypecombo.cpp ) ecm_mark_nongui_executable(externalfetchertest) add_test(externalfetchertest externalfetchertest) ecm_mark_as_test(externalfetchertest) TARGET_LINK_LIBRARIES(externalfetchertest fetcherstest newstuff ${TELLICO_BTPARSE_LIBS} ${TELLICO_TEST_LIBS} KF5::SonnetCore KF5::SonnetUi KF5::XmlGui ) add_executable(filmasterfetchertest filmasterfetchertest.cpp abstractfetchertest.cpp ../fetch/filmasterfetcher.cpp ) ecm_mark_nongui_executable(filmasterfetchertest) add_test(filmasterfetchertest filmasterfetchertest) ecm_mark_as_test(filmasterfetchertest) TARGET_LINK_LIBRARIES(filmasterfetchertest fetcherstest translatorstest ${TELLICO_TEST_LIBS}) # running gcstar in the fetcher is really unreliable add_executable(gcstarfetchertest gcstarfetchertest.cpp abstractfetchertest ../fetch/gcstarpluginfetcher.cpp ../fetch/gcstarthread.cpp ../translators/gcstarimporter.cpp ../gui/collectiontypecombo.cpp ) ecm_mark_nongui_executable(gcstarfetchertest) #add_test(gcstarfetchertest gcstarfetchertest) #ecm_mark_as_test(gcstarfetchertest) TARGET_LINK_LIBRARIES(gcstarfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(giantbombfetchertest giantbombfetchertest.cpp abstractfetchertest.cpp ../fetch/giantbombfetcher.cpp ) ecm_mark_nongui_executable(giantbombfetchertest) add_test(giantbombfetchertest giantbombfetchertest) ecm_mark_as_test(giantbombfetchertest) TARGET_LINK_LIBRARIES(giantbombfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(googlebookfetchertest googlebookfetchertest.cpp abstractfetchertest.cpp ../fetch/googlebookfetcher.cpp ) ecm_mark_nongui_executable(googlebookfetchertest) add_test(googlebookfetchertest googlebookfetchertest) ecm_mark_as_test(googlebookfetchertest) TARGET_LINK_LIBRARIES(googlebookfetchertest fetcherstest translatorstest ${TELLICO_TEST_LIBS}) add_executable(googlescholarfetchertest googlescholarfetchertest.cpp abstractfetchertest.cpp ../fetch/googlescholarfetcher.cpp ../translators/bibteximporter.cpp ) ecm_mark_nongui_executable(googlescholarfetchertest) add_test(googlescholarfetchertest googlescholarfetchertest) ecm_mark_as_test(googlescholarfetchertest) TARGET_LINK_LIBRARIES(googlescholarfetchertest fetcherstest ${TELLICO_BTPARSE_LIBS} ${TELLICO_TEST_LIBS}) add_executable(hathitrustfetchertest hathitrustfetchertest.cpp abstractfetchertest.cpp ../fetch/hathitrustfetcher.cpp ) ecm_mark_nongui_executable(hathitrustfetchertest) add_test(hathitrustfetchertest hathitrustfetchertest) ecm_mark_as_test(hathitrustfetchertest) TARGET_LINK_LIBRARIES(hathitrustfetchertest fetcherstest translatorstest ${TELLICO_TEST_LIBS}) add_executable(ibsfetchertest ibsfetchertest.cpp abstractfetchertest.cpp ../fetch/ibsfetcher.cpp ) ecm_mark_nongui_executable(ibsfetchertest) add_test(ibsfetchertest ibsfetchertest) ecm_mark_as_test(ibsfetchertest) TARGET_LINK_LIBRARIES(ibsfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(igdbfetchertest igdbfetchertest.cpp abstractfetchertest.cpp ../fetch/igdbfetcher.cpp ) ecm_mark_nongui_executable(igdbfetchertest) add_test(igdbfetchertest igdbfetchertest) ecm_mark_as_test(igdbfetchertest) TARGET_LINK_LIBRARIES(igdbfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(imdbfetchertest imdbfetchertest.cpp abstractfetchertest.cpp ../fetch/imdbfetcher.cpp ../gui/listwidgetitem.cpp ) ecm_mark_nongui_executable(imdbfetchertest) add_test(imdbfetchertest imdbfetchertest) ecm_mark_as_test(imdbfetchertest) TARGET_LINK_LIBRARIES(imdbfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(isbndbfetchertest isbndbfetchertest.cpp abstractfetchertest.cpp ../fetch/isbndbfetcher.cpp ) ecm_mark_nongui_executable(isbndbfetchertest) add_test(isbndbfetchertest isbndbfetchertest) ecm_mark_as_test(isbndbfetchertest) TARGET_LINK_LIBRARIES(isbndbfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(kinofetchertest kinofetchertest.cpp abstractfetchertest.cpp ../fetch/kinofetcher.cpp ) ecm_mark_nongui_executable(kinofetchertest) add_test(kinofetchertest kinofetchertest) ecm_mark_as_test(kinofetchertest) TARGET_LINK_LIBRARIES(kinofetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(kinopoiskfetchertest kinopoiskfetchertest.cpp abstractfetchertest.cpp ../fetch/kinopoiskfetcher.cpp ) ecm_mark_nongui_executable(kinopoiskfetchertest) add_test(kinopoiskfetchertest kinopoiskfetchertest) ecm_mark_as_test(kinopoiskfetchertest) TARGET_LINK_LIBRARIES(kinopoiskfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(kinoteatrfetchertest kinoteatrfetchertest.cpp abstractfetchertest.cpp ../fetch/kinoteatrfetcher.cpp ) ecm_mark_nongui_executable(kinoteatrfetchertest) add_test(kinoteatrfetchertest kinoteatrfetchertest) ecm_mark_as_test(kinoteatrfetchertest) TARGET_LINK_LIBRARIES(kinoteatrfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(mobygamesfetchertest mobygamesfetchertest.cpp abstractfetchertest.cpp ../fetch/mobygamesfetcher.cpp ) ecm_mark_nongui_executable(mobygamesfetchertest) add_test(mobygamesfetchertest mobygamesfetchertest) ecm_mark_as_test(mobygamesfetchertest) TARGET_LINK_LIBRARIES(mobygamesfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(moviemeterfetchertest moviemeterfetchertest.cpp abstractfetchertest.cpp ../fetch/moviemeterfetcher.cpp ) ecm_mark_nongui_executable(moviemeterfetchertest) add_test(moviemeterfetchertest moviemeterfetchertest) ecm_mark_as_test(moviemeterfetchertest) TARGET_LINK_LIBRARIES(moviemeterfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(mrlookupfetchertest mrlookupfetchertest.cpp abstractfetchertest.cpp ../fetch/mrlookupfetcher.cpp ../translators/bibteximporter.cpp ) ecm_mark_nongui_executable(mrlookupfetchertest) add_test(mrlookupfetchertest mrlookupfetchertest) ecm_mark_as_test(mrlookupfetchertest) TARGET_LINK_LIBRARIES(mrlookupfetchertest fetcherstest ${TELLICO_BTPARSE_LIBS} ${TELLICO_TEST_LIBS}) add_executable(musicbrainzfetchertest musicbrainzfetchertest.cpp abstractfetchertest.cpp ../fetch/musicbrainzfetcher.cpp ) ecm_mark_nongui_executable(musicbrainzfetchertest) add_test(musicbrainzfetchertest musicbrainzfetchertest) ecm_mark_as_test(musicbrainzfetchertest) TARGET_LINK_LIBRARIES(musicbrainzfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(openlibraryfetchertest openlibraryfetchertest.cpp abstractfetchertest.cpp ../fetch/openlibraryfetcher.cpp ) ecm_mark_nongui_executable(openlibraryfetchertest) add_test(openlibraryfetchertest openlibraryfetchertest) ecm_mark_as_test(openlibraryfetchertest) TARGET_LINK_LIBRARIES(openlibraryfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(omdbfetchertest omdbfetchertest.cpp abstractfetchertest.cpp ../fetch/omdbfetcher.cpp ) ecm_mark_nongui_executable(omdbfetchertest) add_test(omdbfetchertest omdbfetchertest) ecm_mark_as_test(omdbfetchertest) TARGET_LINK_LIBRARIES(omdbfetchertest fetcherstest translatorstest ${TELLICO_TEST_LIBS}) add_executable(springerfetchertest springerfetchertest.cpp abstractfetchertest.cpp ../fetch/springerfetcher.cpp ) ecm_mark_nongui_executable(springerfetchertest) add_test(springerfetchertest springerfetchertest) ecm_mark_as_test(springerfetchertest) TARGET_LINK_LIBRARIES(springerfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(srufetchertest srufetchertest.cpp abstractfetchertest.cpp ) ecm_mark_nongui_executable(srufetchertest) add_test(srufetchertest srufetchertest) ecm_mark_as_test(srufetchertest) # Sonnet needed for gui/lineedit TARGET_LINK_LIBRARIES(srufetchertest fetcherstest ${TELLICO_TEST_LIBS} ) add_executable(thegamesdbfetchertest thegamesdbfetchertest.cpp abstractfetchertest.cpp ../fetch/thegamesdbfetcher.cpp ) ecm_mark_nongui_executable(thegamesdbfetchertest) add_test(thegamesdbfetchertest thegamesdbfetchertest) ecm_mark_as_test(thegamesdbfetchertest) TARGET_LINK_LIBRARIES(thegamesdbfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(themoviedbfetchertest themoviedbfetchertest.cpp abstractfetchertest.cpp ../fetch/themoviedbfetcher.cpp ) ecm_mark_nongui_executable(themoviedbfetchertest) add_test(themoviedbfetchertest themoviedbfetchertest) ecm_mark_as_test(themoviedbfetchertest) TARGET_LINK_LIBRARIES(themoviedbfetchertest fetcherstest translatorstest ${TELLICO_TEST_LIBS}) add_executable(videogamegeekfetchertest videogamegeekfetchertest.cpp abstractfetchertest.cpp ../fetch/videogamegeekfetcher.cpp ) ecm_mark_nongui_executable(videogamegeekfetchertest) add_test(videogamegeekfetchertest videogamegeekfetchertest) ecm_mark_as_test(videogamegeekfetchertest) TARGET_LINK_LIBRARIES(videogamegeekfetchertest fetcherstest ${TELLICO_TEST_LIBS}) add_executable(vndbfetchertest vndbfetchertest.cpp abstractfetchertest.cpp ../fetch/vndbfetcher.cpp ) ecm_mark_nongui_executable(vndbfetchertest) add_test(vndbfetchertest vndbfetchertest) ecm_mark_as_test(vndbfetchertest) TARGET_LINK_LIBRARIES(vndbfetchertest fetcherstest ${TELLICO_TEST_LIBS}) IF( Yaz_FOUND ) add_executable(z3950fetchertest z3950fetchertest.cpp abstractfetchertest.cpp ../fetch/z3950fetcher.cpp ../fetch/z3950connection.cpp ../translators/grs1importer.cpp ../translators/adsimporter.cpp ) ecm_mark_nongui_executable(z3950fetchertest) add_test(z3950fetchertest z3950fetchertest) ecm_mark_as_test(z3950fetchertest) TARGET_LINK_LIBRARIES(z3950fetchertest fetcherstest ${Yaz_LIBRARIES} ${TELLICO_TEST_LIBS} ) ENDIF( Yaz_FOUND ) ENDIF(BUILD_FETCHER_TESTS) diff --git a/src/tests/comparisontest.cpp b/src/tests/comparisontest.cpp index b655dd10..1168efe2 100644 --- a/src/tests/comparisontest.cpp +++ b/src/tests/comparisontest.cpp @@ -1,145 +1,213 @@ /*************************************************************************** Copyright (C) 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 "comparisontest.h" #include "../models/stringcomparison.h" +#include "../models/fieldcomparison.h" #include "../config/tellico_config.h" #include QTEST_GUILESS_MAIN( ComparisonTest ) void ComparisonTest::initTestCase() { Tellico::Config::setArticlesString(QStringLiteral("the,l'")); } void ComparisonTest::testNumber() { QFETCH(QString, string1); QFETCH(QString, string2); QFETCH(int, res); Tellico::NumberComparison comp; QCOMPARE(comp.compare(string1, string2), res); } void ComparisonTest::testNumber_data() { QTest::addColumn("string1"); QTest::addColumn("string2"); QTest::addColumn("res"); QTest::newRow("null") << QString() << QString() << 0; QTest::newRow("< 0") << QString() << QStringLiteral("0") << -1; QTest::newRow("> 0") << QStringLiteral("0") << QString() << 1; QTest::newRow("=1 1") << QStringLiteral("1") << QStringLiteral("1") << 0; QTest::newRow("< 1") << QStringLiteral("0") << QStringLiteral("1") << -1; QTest::newRow("> 1") << QStringLiteral("1") << QStringLiteral("0") << 1; QTest::newRow("> -1") << QStringLiteral("0") << QStringLiteral("-1") << 1; QTest::newRow("< -1") << QStringLiteral("-1") << QStringLiteral("0") << -1; QTest::newRow("> 10") << QStringLiteral("10") << QStringLiteral("5") << 5; QTest::newRow("< 10") << QStringLiteral("5") << QStringLiteral("10") << -5; QTest::newRow("multiple1") << QStringLiteral("1; 2") << QStringLiteral("2") << -1; QTest::newRow("multiple2") << QStringLiteral("3; 2") << QStringLiteral("2") << 1; QTest::newRow("multiple3") << QStringLiteral("2") << QStringLiteral("2; 3") << -1; QTest::newRow("multiple4") << QStringLiteral("1; 2") << QStringLiteral("1; 3") << -1; QTest::newRow("float1") << QStringLiteral("5.1") << QStringLiteral("6.9") << -2; QTest::newRow("float2") << QStringLiteral("5.1") << QStringLiteral("5.2") << -1; QTest::newRow("float3") << QStringLiteral("5.2") << QStringLiteral("5.1") << 1; QTest::newRow("float4") << QStringLiteral("5.1") << QStringLiteral("5.1") << 0; } void ComparisonTest::testLCC() { QFETCH(QString, string1); QFETCH(QString, string2); QFETCH(int, res); Tellico::LCCComparison comp; QCOMPARE(comp.compare(string1, string2), res); } void ComparisonTest::testLCC_data() { QTest::addColumn("string1"); QTest::addColumn("string2"); QTest::addColumn("res"); QTest::newRow("null") << QString() << QString() << 0; QTest::newRow("null1") << QString() << QStringLiteral("B") << -1; QTest::newRow("null2") << QStringLiteral("B") << QString() << 1; QTest::newRow("test1") << QStringLiteral("BX932 .C53 1993") << QStringLiteral("BX2230.3") << -1; QTest::newRow("test2") << QStringLiteral("BX932 .C53 1993") << QStringLiteral("BX2380 .R67 2002") << -1; QTest::newRow("test3") << QStringLiteral("AE25 E3 2002") << QStringLiteral("AE5 E333 2003") << 1; } void ComparisonTest::testDate() { QFETCH(QString, string1); QFETCH(QString, string2); QFETCH(int, res); Tellico::ISODateComparison comp; QCOMPARE(comp.compare(string1, string2), res); } void ComparisonTest::testDate_data() { QTest::addColumn("string1"); QTest::addColumn("string2"); QTest::addColumn("res"); QTest::newRow("null") << QString() << QString() << 0; QTest::newRow("null1") << QString() << QStringLiteral("2001") << -1; QTest::newRow("null2") << QStringLiteral("2001") << QString() << 1; QTest::newRow("test1") << QStringLiteral("2001-9-8") << QStringLiteral("2001-10-12") << -1; QTest::newRow("test2") << QStringLiteral("1998") << QStringLiteral("2020-01-01") << -1; QTest::newRow("test3") << QStringLiteral("2008--") << QStringLiteral("2008-1-1") << 0; QTest::newRow("test5") << QStringLiteral("2008-2-2") << QStringLiteral("2008-02-02") << 0; + // non-integers get converted to current date + QTest::newRow("words") << QStringLiteral("all-by-myself") << QStringLiteral("---") << 0; + QTest::newRow("words") << QStringLiteral("2020--") << QStringLiteral("---") << 0; } void ComparisonTest::testTitle() { QFETCH(QString, string1); QFETCH(QString, string2); QFETCH(int, res); Tellico::TitleComparison comp; QCOMPARE(comp.compare(string1, string2), res); } void ComparisonTest::testTitle_data() { QTest::addColumn("string1"); QTest::addColumn("string2"); QTest::addColumn("res"); QTest::newRow("null") << QString() << QString() << 0; QTest::newRow("null1") << QString() << QStringLiteral("The One") << -1; QTest::newRow("null2") << QStringLiteral("The One") << QString() << 1; // not that they're equal, but that "The One" should be sorted under "One" QTest::newRow("test3") << QStringLiteral("The One") << QStringLiteral("One, The") << -1; QTest::newRow("test4") << QStringLiteral("The One") << QStringLiteral("one, the") << -1; QTest::newRow("test5") << QStringLiteral("l'One") << QStringLiteral("one, the") << -1; QTest::newRow("test6") << QStringLiteral("l'One") << QStringLiteral("the one") << 0; QTest::newRow("test7") << QStringLiteral("All One") << QStringLiteral("the one") << -1; } + +void ComparisonTest::testString() { + QFETCH(QString, string1); + QFETCH(QString, string2); + QFETCH(int, res); + + Tellico::StringComparison comp; + + QCOMPARE(comp.compare(string1, string2), res); +} + +void ComparisonTest::testString_data() { + QTest::addColumn("string1"); + QTest::addColumn("string2"); + QTest::addColumn("res"); + + QTest::newRow("null") << QString() << QString() << 0; + QTest::newRow("null1") << QString() << QStringLiteral("string") << -1; + QTest::newRow("null2") << QStringLiteral("string") << QString() << 1; + QTest::newRow("test1") << QStringLiteral("string1") << QStringLiteral("string1") << 0; + QTest::newRow("test2") << QStringLiteral("string1") << QStringLiteral("string2") << -1; +} + +void ComparisonTest::testBool() { + QFETCH(QString, string1); + QFETCH(QString, string2); + QFETCH(int, res); + + Tellico::BoolComparison comp; + + QCOMPARE(comp.compare(string1, string2), res); +} + +void ComparisonTest::testBool_data() { + QTest::addColumn("string1"); + QTest::addColumn("string2"); + QTest::addColumn("res"); + + QTest::newRow("null") << QString() << QString() << 0; + QTest::newRow("null1") << QString() << QStringLiteral("true") << -1; + QTest::newRow("null2") << QStringLiteral("true") << QString() << 1; + QTest::newRow("truetrue") << QStringLiteral("true") << QStringLiteral("true") << 0; + QTest::newRow("truefalse") << QStringLiteral("true") << QStringLiteral("false") << 1; + QTest::newRow("falsetrue") << QStringLiteral("false") << QStringLiteral("true") << -1; +} + +void ComparisonTest::testChoiceField() { + Tellico::Data::CollPtr coll(new Tellico::Data::Collection(true)); // add default field + + QStringList allowed; + allowed << QStringLiteral("choice2") << QStringLiteral("choice1"); + QVERIFY(allowed.size() > 1); + Tellico::Data::FieldPtr field(new Tellico::Data::Field(QStringLiteral("choice"), QStringLiteral("Choice"), allowed)); + coll->addField(field); + + Tellico::Data::EntryPtr entry1(new Tellico::Data::Entry(coll)); + entry1->setField(field->name(), allowed.at(0)); + Tellico::Data::EntryPtr entry2(new Tellico::Data::Entry(coll)); + entry2->setField(field->name(), allowed.at(1)); + + Tellico::FieldComparison* comp = Tellico::FieldComparison::create(field); + // even though the second allowed value would sort first, it comes second in the list + QCOMPARE(comp->compare(entry1, entry2), -1); +} diff --git a/src/tests/comparisontest.h b/src/tests/comparisontest.h index c5e01f6e..21ce52f5 100644 --- a/src/tests/comparisontest.h +++ b/src/tests/comparisontest.h @@ -1,45 +1,50 @@ /*************************************************************************** Copyright (C) 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 . * * * ***************************************************************************/ #ifndef COMPARISONTEST_H #define COMPARISONTEST_H #include class ComparisonTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void testNumber(); void testNumber_data(); void testLCC(); void testLCC_data(); void testDate(); void testDate_data(); void testTitle(); void testTitle_data(); + void testString(); + void testString_data(); + void testBool(); + void testBool_data(); + void testChoiceField(); }; #endif