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:
parent
67d6b05aac
commit
449b347644
@ -1775,29 +1775,13 @@ void tst_QLocale::formatTimeZone()
|
|||||||
qDebug("(Skipped some CET-only tests)");
|
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)
|
#if QT_CONFIG(timezone)
|
||||||
QDateTime dt6(QDate(2013, 1, 1), QTime(0, 0, 0), QTimeZone("Europe/Berlin"));
|
const QTimeZone berlin("Europe/Berlin");
|
||||||
#ifdef Q_OS_WIN
|
const QDateTime jan(QDate(2010, 1, 1).startOfDay(berlin));
|
||||||
QEXPECT_FAIL("", "QTimeZone windows backend only returns long name", Continue);
|
const QDateTime jul(QDate(2010, 7, 1).startOfDay(berlin));
|
||||||
#endif
|
|
||||||
QCOMPARE(enUS.toString(dt6, "t"), cet);
|
|
||||||
|
|
||||||
QDateTime dt7(QDate(2013, 6, 1), QTime(0, 0, 0), QTimeZone("Europe/Berlin"));
|
QCOMPARE(enUS.toString(jan, "t"), berlin.abbreviation(jan));
|
||||||
#ifdef Q_OS_WIN
|
QCOMPARE(enUS.toString(jul, "t"), berlin.abbreviation(jul));
|
||||||
QEXPECT_FAIL("", "QTimeZone windows backend only returns long name", Continue);
|
|
||||||
#endif
|
|
||||||
QCOMPARE(enUS.toString(dt7, "t"), cest);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Current datetime should return current abbreviation
|
// Current datetime should return current abbreviation
|
||||||
|
@ -3021,28 +3021,13 @@ void tst_QDateTime::timeZoneAbbreviation()
|
|||||||
qDebug("(Skipped some CET-only tests)");
|
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)
|
#if QT_CONFIG(timezone)
|
||||||
QDateTime dt5(QDate(2013, 1, 1), QTime(0, 0, 0), QTimeZone("Europe/Berlin"));
|
const QTimeZone berlin("Europe/Berlin");
|
||||||
#ifdef Q_OS_WIN
|
const QDateTime jan(QDate(2013, 1, 1).startOfDay(berlin));
|
||||||
QEXPECT_FAIL("", "Windows only reports long names (QTBUG-32759)", Continue);
|
const QDateTime jul(QDate(2013, 7, 1).startOfDay(berlin));
|
||||||
#endif
|
|
||||||
QCOMPARE(dt5.timeZoneAbbreviation(), cet);
|
QCOMPARE(jan.timeZoneAbbreviation(), berlin.abbreviation(jan));
|
||||||
QDateTime dt6(QDate(2013, 6, 1), QTime(0, 0, 0), QTimeZone("Europe/Berlin"));
|
QCOMPARE(jul.timeZoneAbbreviation(), berlin.abbreviation(jul));
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
QEXPECT_FAIL("", "Windows only reports long names (QTBUG-32759)", Continue);
|
|
||||||
#endif
|
|
||||||
QCOMPARE(dt6.timeZoneAbbreviation(), cest);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user