diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -94,10 +94,15 @@ # # 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 diff --git a/autotests/propertyinfotest.h b/autotests/propertyinfotest.h --- a/autotests/propertyinfotest.h +++ b/autotests/propertyinfotest.h @@ -28,10 +28,16 @@ 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; }; } diff --git a/autotests/propertyinfotest.cpp b/autotests/propertyinfotest.cpp --- a/autotests/propertyinfotest.cpp +++ b/autotests/propertyinfotest.cpp @@ -25,6 +25,33 @@ 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 @@ -51,6 +78,12 @@ 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); } @@ -101,5 +134,3 @@ << info << row.value << row.expected << row.maybeLocalized; } } - -QTEST_GUILESS_MAIN(PropertyInfoTest)