diff options
Diffstat (limited to 'tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index 9f22c3d51d..14dcd0babc 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -47,6 +47,8 @@ private slots: void availableTimeZoneIds(); void transitionEachZone_data(); void transitionEachZone(); + void checkOffset_data(); + void checkOffset(); void stressTest(); void windowsId(); void isValidId_data(); @@ -436,6 +438,14 @@ void tst_QTimeZone::transitionEachZone() QTimeZone named(zone); for (int i = start; i < stop; i++) { +#ifdef Q_OS_WIN + // See QTBUG-64985: MS's TZ APIs' misdescription of Europe/Samara leads + // to mis-disambiguation of its fall-back here. + if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::Windows7 + && zone == "Europe/Samara" && i == -3) { + continue; + } +#endif qint64 here = secs + i * 3600; QDateTime when = QDateTime::fromMSecsSinceEpoch(here * 1000, named); qint64 stamp = when.toMSecsSinceEpoch(); @@ -446,6 +456,51 @@ void tst_QTimeZone::transitionEachZone() } } +void tst_QTimeZone::checkOffset_data() +{ + QTest::addColumn<QByteArray>("zoneName"); + QTest::addColumn<QDateTime>("when"); + QTest::addColumn<int>("netOffset"); + QTest::addColumn<int>("stdOffset"); + QTest::addColumn<int>("dstOffset"); + + struct { + const char *zone, *nick; + int year, month, day, hour, min, sec; + int std, dst; + } table[] = { + // Kiev: regression test for QTBUG-64122 (on MS): + { "Europe/Kiev", "summer", 2017, 10, 27, 12, 0, 0, 2 * 3600, 3600 }, + { "Europe/Kiev", "winter", 2017, 10, 29, 12, 0, 0, 2 * 3600, 0 } + }; + for (const auto &entry : table) { + QTimeZone zone(entry.zone); + if (zone.isValid()) { + QTest::addRow("%s@%s", entry.zone, entry.nick) + << QByteArray(entry.zone) + << QDateTime(QDate(entry.year, entry.month, entry.day), + QTime(entry.hour, entry.min, entry.sec), zone) + << entry.dst + entry.std << entry.std << entry.dst; + } + } +} + +void tst_QTimeZone::checkOffset() +{ + QFETCH(QByteArray, zoneName); + QFETCH(QDateTime, when); + QFETCH(int, netOffset); + QFETCH(int, stdOffset); + QFETCH(int, dstOffset); + + QTimeZone zone(zoneName); + QVERIFY(zone.isValid()); // It was when _data() added the row ! + QCOMPARE(zone.offsetFromUtc(when), netOffset); + QCOMPARE(zone.standardTimeOffset(when), stdOffset); + QCOMPARE(zone.daylightTimeOffset(when), dstOffset); + QCOMPARE(zone.isDaylightTime(when), dstOffset != 0); +} + void tst_QTimeZone::availableTimeZoneIds() { if (debug) { @@ -1177,7 +1232,8 @@ void tst_QTimeZone::testEpochTranPrivate(const QTimeZonePrivate &tzp) // Pre-epoch time-zones might not be supported at all: tran = tzp.nextTransition(QDateTime(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC).toMSecsSinceEpoch()); - if (tran.atMSecsSinceEpoch != QTimeZonePrivate::invalidSeconds() + if (tran.atMSecsSinceEpoch != QTimeZonePrivate::invalidMSecs() + // Toronto *did* have a transition before 1970 (DST since 1918): && tran.atMSecsSinceEpoch < 0) { // ... but, if they are, we should be able to search back to them: tran = tzp.previousTransition(0); // i.e. last before epoch |