diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 543001a..49824ba 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,246 +1,251 @@ find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test) find_package(PythonInterp) set_package_properties(PythonInterp PROPERTIES DESCRIPTION "Python Interpreter" URL "https://www.python.org" TYPE OPTIONAL PURPOSE "Python interpreter is needed to execute test for external extractors or writers") remove_definitions(-DQT_NO_CAST_FROM_ASCII) configure_file(indexerextractortestsconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/indexerextractortestsconfig.h @ONLY) set(KfileMetaDataAutotest_SRCS) ecm_qt_declare_logging_category(KfileMetaDataAutotest_SRCS HEADER kfilemetadata_debug.h IDENTIFIER KFILEMETADATA_LOG CATEGORY_NAME kf5.kfilemetadata) # # Test case coverage # set(extractorcoverage_SRCS extractorcoveragetest.cpp ) ecm_add_test(${extractorcoverage_SRCS} TEST_NAME "extractorcoveragetest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) # # Full text extraction test # set(indexerextractor_SRCS indexerextractortests.cpp ../src/extractors/plaintextextractor.cpp ) ecm_add_test(${indexerextractor_SRCS} TEST_NAME "indexextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) # # Office # if(KF5Archive_FOUND) ecm_add_test(odfextractortest.cpp ../src/extractors/odfextractor.cpp TEST_NAME "odfextractortest" LINK_LIBRARIES Qt5::Test Qt5::Xml KF5::FileMetaData KF5::Archive ) endif() if(KF5Archive_FOUND) ecm_add_test(office2007extractortest.cpp ../src/extractors/office2007extractor.cpp TEST_NAME "officeextractortest" LINK_LIBRARIES Qt5::Test Qt5::Xml KF5::FileMetaData KF5::Archive ) endif() # # Poppler # if(Poppler_Qt5_FOUND) ecm_add_test(popplerextractortest.cpp ../src/extractors/popplerextractor.cpp TEST_NAME "popplerextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData Poppler::Qt5 ) endif() # # EPub # if(EPUB_FOUND) include_directories(${EPUB_INCLUDE_DIR}) ecm_add_test(epubextractortest.cpp ../src/extractors/epubextractor.cpp TEST_NAME "epubextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${EPUB_LIBRARIES} ) endif() # # Mobi # if (QMOBIPOCKET_FOUND) include_directories(${QMOBIPOCKET_INCLUDE_DIR}) ecm_add_test(mobiextractortest.cpp ../src/extractors/mobiextractor.cpp TEST_NAME "mobiextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${QMOBIPOCKET_LIBRARIES} ) endif() # # Property Info # -ecm_add_test(propertyinfotest.cpp - TEST_NAME "propertyinfotest" - LINK_LIBRARIES Qt5::Test KF5::FileMetaData +add_executable(propertyinfotest_bin propertyinfotest.cpp) +target_link_libraries(propertyinfotest_bin + Qt5::Test + KF5::FileMetaData ) +ecm_mark_as_test(propertyinfotest_bin) +ecm_mark_nongui_executable(propertyinfotest_bin) +add_test(NAME propertyinfotest_en COMMAND propertyinfotest_bin) +add_test(NAME propertyinfotest_localized COMMAND propertyinfotest_bin "--localized") # # Exiv2 # if(LibExiv2_FOUND) kde_enable_exceptions() ecm_add_test(exiv2extractortest.cpp ../src/extractors/exiv2extractor.cpp TEST_NAME "exiv2extractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData LibExiv2::LibExiv2 ) target_include_directories(exiv2extractortest PRIVATE ${CMAKE_BINARY_DIR}/src/extractors) endif() # # FFMPEG # if(FFMPEG_FOUND) kde_enable_exceptions() ecm_add_test(ffmpegextractortest.cpp ../src/extractors/ffmpegextractor.cpp TEST_NAME "ffmpegextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${AVCODEC_LIBRARIES} ${AVFORMAT_LIBRARIES} ${AVUTIL_LIBRARIES} ) target_include_directories(ffmpegextractortest SYSTEM PRIVATE ${AVCODEC_INCLUDE_DIRS} ${AVFORMAT_INCLUDE_DIRS} ${AVUTIL_INCLUDE_DIRS}) endif() # # TagLib # if(TAGLIB_FOUND) kde_enable_exceptions() ecm_add_test(taglibextractortest.cpp ../src/extractors/taglibextractor.cpp TEST_NAME "taglibextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${TAGLIB_LIBRARIES} ) target_include_directories(taglibextractortest SYSTEM PRIVATE ${TAGLIB_INCLUDES}) ecm_add_test(embeddedimagedatatest.cpp TEST_NAME "embeddedimagedatatest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${TAGLIB_LIBRARIES} ) target_include_directories(embeddedimagedatatest SYSTEM PRIVATE ${TAGLIB_INCLUDES}) endif() if(PYTHONINTERP_FOUND) configure_file(samplefiles/testexternalextractor/main.py samplefiles/testexternalextractor/main.py) configure_file(samplefiles/testexternalextractor/manifest.json samplefiles/testexternalextractor/manifest.json COPYONLY) ecm_add_test(externalextractortest.cpp ../src/externalextractor.cpp ${KfileMetaDataAutotest_SRCS} TEST_NAME "externalextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData KF5::I18n ) endif() # # Collection # set(extractorcollection_SRCS extractorcollectiontest.cpp ) ecm_add_test(${extractorcollection_SRCS} TEST_NAME "extractorcollectiontest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) # # XML # set(xmlextractor_SRCS xmlextractortest.cpp ../src/extractors/xmlextractor.cpp ../src/extractors/dublincoreextractor.cpp ../src/kfilemetadata_debug.cpp ) ecm_add_test(${xmlextractor_SRCS} TEST_NAME "xmlextractortest" LINK_LIBRARIES Qt5::Test Qt5::Xml KF5::FileMetaData ) # # Postscript DSC # set(postscriptdscextractor_SRCS postscriptdscextractortest.cpp ../src/extractors/postscriptdscextractor.cpp ../src/kfilemetadata_debug.cpp ) ecm_add_test(${postscriptdscextractor_SRCS} TEST_NAME "postscriptdscextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) # # AppImage # if(libappimage_FOUND AND KF5Config_FOUND AND Qt5Gui_FOUND) ecm_add_test(appimageextractortest.cpp ../src/extractors/appimageextractor.cpp TEST_NAME "appimageextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData KF5::ConfigCore Qt5::Xml Qt5::Gui libappimage ) endif() ################ # Writer tests # ################ # # UserMetaData # if(CMAKE_SYSTEM_NAME MATCHES "Linux") kde_enable_exceptions() ecm_add_test(usermetadatawritertest.cpp ../src/usermetadata.cpp TEST_NAME "usermetadatawritertest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) endif() # # TagLib # if(TAGLIB_FOUND) kde_enable_exceptions() ecm_add_test(taglibwritertest.cpp ../src/writers/taglibwriter.cpp TEST_NAME "taglibwritertest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${TAGLIB_LIBRARIES} ) target_include_directories(taglibwritertest SYSTEM PRIVATE ${TAGLIB_INCLUDES}) endif() if(PYTHONINTERP_FOUND) configure_file(samplefiles/testexternalwriter/main.py samplefiles/testexternalwriter/main.py) configure_file(samplefiles/testexternalwriter/manifest.json samplefiles/testexternalwriter/manifest.json COPYONLY) ecm_add_test(externalwritertest.cpp ../src/externalwriter.cpp ${KfileMetaDataAutotest_SRCS} TEST_NAME "externalwritertest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData KF5::I18n ) endif() diff --git a/autotests/propertyinfotest.cpp b/autotests/propertyinfotest.cpp index dbb5b18..72ca9bd 100644 --- a/autotests/propertyinfotest.cpp +++ b/autotests/propertyinfotest.cpp @@ -1,105 +1,136 @@ /* * This file is part of the KDE KFileMetaData project * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "propertyinfotest.h" #include "propertyinfo.h" #include using namespace KFileMetaData; +//QTEST_GUILESS_MAIN(PropertyInfoTest) +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + PropertyInfoTest tc; + + auto arguments = app.arguments(); + if (arguments.contains(QStringLiteral("--localized"))) { + arguments.removeAll(QStringLiteral("--localized")); + tc.setLocalized(true); + } + + return QTest::qExec(&tc, arguments); +} + +void PropertyInfoTest::setLocalized(bool localized) +{ + m_useLocalization = localized; +} + +void PropertyInfoTest::init() +{ + if (!m_useLocalization) { + QLocale().setDefault(QLocale::c()); + } +} + void PropertyInfoTest::testNameIdMapping() { // The +1 is to avoid the Empty Property int i = static_cast(Property::FirstProperty) + 1; int e = static_cast(Property::LastProperty); for (; i <= e; i++) { Property::Property p = static_cast(i); PropertyInfo pi(p); // qDebug() << pi.name(); QCOMPARE(pi.property(), p); QVERIFY(!pi.name().isEmpty()); QVERIFY(!pi.displayName().isEmpty()); PropertyInfo pi2 = PropertyInfo::fromName(pi.name()); QCOMPARE(pi2.property(), p); } } void PropertyInfoTest::testFormatAsDisplayString() { QFETCH(KFileMetaData::PropertyInfo, propertyInfo); QFETCH(QVariant, value); QFETCH(QString, expected); QFETCH(bool, maybeLocalized); + if (m_useLocalization && maybeLocalized) { + qDebug() << "Expected:" << expected << ", formatted/localized:" << propertyInfo.formatAsDisplayString(value); + if (expected != propertyInfo.formatAsDisplayString(value)) { + QEXPECT_FAIL("", "Expected value not localized", Continue); + } + } QCOMPARE(propertyInfo.formatAsDisplayString(value), expected); } void PropertyInfoTest::testFormatAsDisplayString_data() { QTest::addColumn("propertyInfo"); QTest::addColumn("value"); QTest::addColumn("expected"); QTest::addColumn("maybeLocalized"); auto emptyProperty = PropertyInfo::fromName(QStringLiteral("no valid property name")); QTest::addRow("") << emptyProperty << QVariant(QStringLiteral("empty")) << QStringLiteral("empty") << true; QStringList artistList = {QStringLiteral("Artist1"), QStringLiteral("Artist2"), QStringLiteral("Artist3")}; QStringList authorList = {QStringLiteral("Author1")}; struct { KFileMetaData::Property::Property property; bool maybeLocalized; QVariant value; QString expected; } rows[] = { { Property::DiscNumber, true, 2018, QStringLiteral("2018")}, { Property::Title, false, QStringLiteral("Title"), QStringLiteral("Title")}, { Property::Artist, true, artistList, QStringLiteral("Artist1, Artist2, and Artist3")}, { Property::Author, true, authorList, QStringLiteral("Author1")}, { Property::Duration, true, 1800, QStringLiteral("0:30:00")}, { Property::SampleRate, true, 44100, QStringLiteral("44.1 kHz")}, { Property::BitRate, true, 128000, QStringLiteral("128 kbit/s")}, { Property::BitRate, true, 1350000, QStringLiteral("1.35 Mbit/s")}, { Property::BitRate, true, 14700000, QStringLiteral("14.7 Mbit/s")}, { Property::ImageOrientation, true, 5, QStringLiteral("Transposed")}, { Property::PhotoFlash, true, 0x00, QStringLiteral("No flash")}, { Property::PhotoFlash, true, 0x50, QStringLiteral("No, red-eye reduction")}, { Property::PhotoGpsAltitude, true, 1.1, QStringLiteral("1.1 m")}, // make VisualStudio compiler happy: QChar(0x00B0) = "°" { Property::PhotoGpsLatitude, true, 25, QStringLiteral("25") + QChar(0x00B0)}, { Property::PhotoGpsLongitude, true, 13.5, QStringLiteral("13.5") + QChar(0x00B0)}, { Property::FrameRate, true, 23, QStringLiteral("23 fps")}, { Property::FrameRate, true, 23.976, QStringLiteral("23.98 fps")}, { Property::AspectRatio, true, 1.77778, QStringLiteral("1.78:1")}, }; for (auto row : rows) { PropertyInfo info(row.property); QTest::addRow("%s", info.displayName().toUtf8().constData()) << info << row.value << row.expected << row.maybeLocalized; } } - -QTEST_GUILESS_MAIN(PropertyInfoTest) diff --git a/autotests/propertyinfotest.h b/autotests/propertyinfotest.h index 6c80a21..d2f86d7 100644 --- a/autotests/propertyinfotest.h +++ b/autotests/propertyinfotest.h @@ -1,39 +1,45 @@ /* * This file is part of the KDE KFileMetaData project * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef PROPERTYINFOTEST_H #define PROPERTYINFOTEST_H #include namespace KFileMetaData { class PropertyInfoTest : public QObject { Q_OBJECT +public: + void setLocalized(bool); + private Q_SLOTS: + void init(); void testNameIdMapping(); void testFormatAsDisplayString(); void testFormatAsDisplayString_data(); +private: + bool m_useLocalization = false; }; } #endif // PROPERTYINFOTEST_H