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>
This commit is contained in:
Edward Welbourne 2018-10-01 15:27:06 +02:00
parent 67d6b05aac
commit 449b347644
2 changed files with 11 additions and 42 deletions

View File

@ -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

View File

@ -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
}