summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-04-05 10:53:06 +0200
committerIvan Solovev <ivan.solovev@qt.io>2022-04-08 00:13:01 +0200
commit44f3fe1cf4e2319e012207eba3afe7adfe09cad6 (patch)
tree1e68ce60de8d7914f55d45f7d7082f637eefa9eb /tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
parent9fee35a2eda68b5968d911d5e14d298b91418d2c (diff)
Android: use BCP 47 tag to create a correct Locale for QTimeZone::displayName()
Before the patch we tried to create a java Locale object by passing the human-readable language, territory and variant strings. However, the Locale constructor accepts ISO-defined codes. Fix it by using a factory method Locale.forLanguageTag() [0] that constructs a Java Locale object based on BCP 47 tag. [0]: https://developer.android.com/reference/java/util/Locale#forLanguageTag(java.lang.String) Fixes: QTBUG-101460 Pick-to: 6.3 6.2 5.15 Change-Id: If414c66cf0e5b7e8299ffc3a6038b6f9eb79d5ec Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp')
-rw-r--r--tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
index f6d4f65346..0a18958fb6 100644
--- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
@@ -75,6 +75,8 @@ private Q_SLOTS:
void macTest();
void darwinTypes();
void winTest();
+ void localeSpecificDisplayName_data();
+ void localeSpecificDisplayName();
private:
void printTimeZone(const QTimeZone &tz);
@@ -1416,8 +1418,58 @@ void tst_QTimeZone::winTest()
testEpochTranPrivate(QWinTimeZonePrivate("America/Toronto"));
#endif // QT_BUILD_INTERNAL && USING_WIN_TZ
}
+
#undef ZONE_DNAME_CHECK
+void tst_QTimeZone::localeSpecificDisplayName_data()
+{
+#ifdef USING_WIN_TZ
+ QSKIP("MS backend does not use locale parameter");
+#endif
+ QTest::addColumn<QByteArray>("zoneName");
+ QTest::addColumn<QLocale>("locale");
+ QTest::addColumn<QTimeZone::TimeType>("timeType");
+ QTest::addColumn<QString>("expectedName");
+
+ QStringList names;
+ QLocale locale;
+ // Pick a non-system locale; German or French
+ if (QLocale::system().language() != QLocale::German) {
+ locale = QLocale(QLocale::German);
+ names << QString("Mitteleurop\u00e4ische Normalzeit")
+ << QString("Mitteleurop\u00e4ische Sommerzeit");
+ } else {
+ locale = QLocale(QLocale::French);
+ names << QString("heure normale d\u2019Europe centrale")
+ << QString("heure d\u2019\u00E9t\u00E9 d\u2019Europe centrale");
+ }
+
+ qsizetype index = 0;
+ QTest::newRow("Berlin, standard time")
+ << QByteArray("Europe/Berlin") << locale << QTimeZone::StandardTime
+ << names.at(index++);
+
+ QTest::newRow("Berlin, summer time")
+ << QByteArray("Europe/Berlin") << locale << QTimeZone::DaylightTime
+ << names.at(index++);
+}
+
+void tst_QTimeZone::localeSpecificDisplayName()
+{
+ // This test checks that QTimeZone::displayName() correctly uses the
+ // specified locale, NOT the system locale (see QTBUG-101460).
+ QFETCH(QByteArray, zoneName);
+ QFETCH(QLocale, locale);
+ QFETCH(QTimeZone::TimeType, timeType);
+ QFETCH(QString, expectedName);
+
+ QTimeZone zone(zoneName);
+ QVERIFY(zone.isValid());
+
+ const QString localeName = zone.displayName(timeType, QTimeZone::LongName, locale);
+ QCOMPARE(localeName, expectedName);
+}
+
#ifdef QT_BUILD_INTERNAL
// Test each private produces the same basic results for CET
void tst_QTimeZone::testCetPrivate(const QTimeZonePrivate &tzp)