From 449b347644a34ab37720874bf9f8bcffe2ea425e Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 1 Oct 2018 15:27:06 +0200 Subject: Rework QLocale and QDateTime tests that expect CET abbreviation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 26 ++++----------------- .../auto/corelib/time/qdatetime/tst_qdatetime.cpp | 27 +++++----------------- 2 files changed, 11 insertions(+), 42 deletions(-) (limited to 'tests') 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 } -- cgit v1.2.3