summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-10-01 15:27:06 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2020-05-28 15:15:17 +0200
commit449b347644a34ab37720874bf9f8bcffe2ea425e (patch)
treec4e63ba91c6afe8827d411bc9bc25f057725e9bc /tests
parent67d6b05aac162a197ed7e26ac8ec634dbe51ed03 (diff)
Rework QLocale and QDateTime tests that expect CET abbreviation
The name CET is locale-dependent; but QLocale doesn't know about localization of time zone names. Such abbreviated zone names are, in any case, potentially ambiguous - various zones around the world have collisions - so they can't be relied on. QTimeZone's various backends have differing handlings of how to abbreviate zone names (MS's provides no abbreviated names at all); and it appears macOS actually follows the relevant localizations. So it is hopeless to hard-code the expected zone abbreviations. Changed the tests to consult QTimeZone for the abbreviation and compare what it gets with the results of checks which should match this. This is less stringent, but it is at least robustly correct, thereby getting rid of assorted kludges and #if-ery. Pick-to: 5.15 Task-number: QTBUG-70149 Change-Id: I0c565de3fd8b5987c8f5a3f785ebd8f6e941e055 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp26
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp27
2 files changed, 11 insertions, 42 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
index b9e14663ed..b46f9aa567 100644
--- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
@@ -1775,29 +1775,13 @@ void tst_QLocale::formatTimeZone()
qDebug("(Skipped some CET-only tests)");
}
-#ifdef Q_OS_ANDROID // Only reports (general) zones as offsets (QTBUG-68837)
- const QString cet(QStringLiteral("GMT+01:00"));
- const QString cest(QStringLiteral("GMT+02:00"));
-#elif defined Q_OS_DARWIN
- const QString cet(QStringLiteral("GMT+1"));
- const QString cest(QStringLiteral("GMT+2"));
-#else
- const QString cet(QStringLiteral("CET"));
- const QString cest(QStringLiteral("CEST"));
-#endif
-
#if QT_CONFIG(timezone)
- QDateTime dt6(QDate(2013, 1, 1), QTime(0, 0, 0), QTimeZone("Europe/Berlin"));
-#ifdef Q_OS_WIN
- QEXPECT_FAIL("", "QTimeZone windows backend only returns long name", Continue);
-#endif
- QCOMPARE(enUS.toString(dt6, "t"), cet);
+ const QTimeZone berlin("Europe/Berlin");
+ const QDateTime jan(QDate(2010, 1, 1).startOfDay(berlin));
+ const QDateTime jul(QDate(2010, 7, 1).startOfDay(berlin));
- QDateTime dt7(QDate(2013, 6, 1), QTime(0, 0, 0), QTimeZone("Europe/Berlin"));
-#ifdef Q_OS_WIN
- QEXPECT_FAIL("", "QTimeZone windows backend only returns long name", Continue);
-#endif
- QCOMPARE(enUS.toString(dt7, "t"), cest);
+ QCOMPARE(enUS.toString(jan, "t"), berlin.abbreviation(jan));
+ QCOMPARE(enUS.toString(jul, "t"), berlin.abbreviation(jul));
#endif
// Current datetime should return current abbreviation
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 23a99e2f47..b3deaf7bfe 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -3021,28 +3021,13 @@ void tst_QDateTime::timeZoneAbbreviation()
qDebug("(Skipped some CET-only tests)");
}
-#ifdef Q_OS_ANDROID // Only reports (general) zones as offsets (QTBUG-68837)
- const QString cet(QStringLiteral("GMT+01:00"));
- const QString cest(QStringLiteral("GMT+02:00"));
-#elif defined Q_OS_DARWIN
- const QString cet(QStringLiteral("GMT+1"));
- const QString cest(QStringLiteral("GMT+2"));
-#else
- const QString cet(QStringLiteral("CET"));
- const QString cest(QStringLiteral("CEST"));
-#endif
-
#if QT_CONFIG(timezone)
- QDateTime dt5(QDate(2013, 1, 1), QTime(0, 0, 0), QTimeZone("Europe/Berlin"));
-#ifdef Q_OS_WIN
- QEXPECT_FAIL("", "Windows only reports long names (QTBUG-32759)", Continue);
-#endif
- QCOMPARE(dt5.timeZoneAbbreviation(), cet);
- QDateTime dt6(QDate(2013, 6, 1), QTime(0, 0, 0), QTimeZone("Europe/Berlin"));
-#ifdef Q_OS_WIN
- QEXPECT_FAIL("", "Windows only reports long names (QTBUG-32759)", Continue);
-#endif
- QCOMPARE(dt6.timeZoneAbbreviation(), cest);
+ const QTimeZone berlin("Europe/Berlin");
+ const QDateTime jan(QDate(2013, 1, 1).startOfDay(berlin));
+ const QDateTime jul(QDate(2013, 7, 1).startOfDay(berlin));
+
+ QCOMPARE(jan.timeZoneAbbreviation(), berlin.abbreviation(jan));
+ QCOMPARE(jul.timeZoneAbbreviation(), berlin.abbreviation(jul));
#endif
}