summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qtimezone
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/qtimezone')
-rw-r--r--tests/auto/corelib/tools/qtimezone/qtimezone.pro5
-rw-r--r--tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp79
-rw-r--r--tests/auto/corelib/tools/qtimezone/tst_qtimezone_darwin.mm68
3 files changed, 142 insertions, 10 deletions
diff --git a/tests/auto/corelib/tools/qtimezone/qtimezone.pro b/tests/auto/corelib/tools/qtimezone/qtimezone.pro
index afc4c59dfe..19ebc13306 100644
--- a/tests/auto/corelib/tools/qtimezone/qtimezone.pro
+++ b/tests/auto/corelib/tools/qtimezone/qtimezone.pro
@@ -5,3 +5,8 @@ SOURCES = tst_qtimezone.cpp
qtConfig(icu) {
DEFINES += QT_USE_ICU
}
+
+darwin {
+ OBJECTIVE_SOURCES += tst_qtimezone_darwin.mm
+ LIBS += -framework Foundation
+}
diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp
index c631b395f8..abb5b50229 100644
--- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp
@@ -45,6 +45,8 @@ private slots:
void dataStreamTest();
void isTimeZoneIdAvailable();
void availableTimeZoneIds();
+ void transitionEachZone_data();
+ void transitionEachZone();
void stressTest();
void windowsId();
void isValidId_data();
@@ -54,23 +56,24 @@ private slots:
void icuTest();
void tzTest();
void macTest();
+ void darwinTypes();
void winTest();
private:
- void printTimeZone(const QTimeZone tz);
+ void printTimeZone(const QTimeZone &tz);
#ifdef QT_BUILD_INTERNAL
void testCetPrivate(const QTimeZonePrivate &tzp);
#endif // QT_BUILD_INTERNAL
- bool debug;
+ const bool debug;
};
tst_QTimeZone::tst_QTimeZone()
-{
// Set to true to print debug output, test Display Names and run long stress tests
- debug = false;
+ : debug(false)
+{
}
-void tst_QTimeZone::printTimeZone(const QTimeZone tz)
+void tst_QTimeZone::printTimeZone(const QTimeZone &tz)
{
QDateTime now = QDateTime::currentDateTime();
QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC);
@@ -367,6 +370,56 @@ void tst_QTimeZone::isTimeZoneIdAvailable()
QCOMPARE(QTimeZonePrivate::isValidId("12345678901234/123456789012345"), false);
}
+void tst_QTimeZone::transitionEachZone_data()
+{
+ QTest::addColumn<QByteArray>("zone");
+ QTest::addColumn<qint64>("secs");
+ QTest::addColumn<int>("start");
+ QTest::addColumn<int>("stop");
+
+ struct {
+ qint64 baseSecs;
+ int start, stop;
+ int year;
+ } table[] = {
+ { 25666200, 3, 12, 1970 }, // 1970-10-25 01:30 UTC; North America
+ { 1288488600, -4, 8, 2010 } // 2010-10-31 01:30 UTC; Europe, Russia
+ };
+
+ QString name;
+ for (int k = sizeof(table) / sizeof(table[0]); k-- > 0; ) {
+ foreach (QByteArray zone, QTimeZone::availableTimeZoneIds()) {
+ name.sprintf("%s@%d", zone.constData(), table[k].year);
+ QTest::newRow(name.toUtf8().constData())
+ << zone
+ << table[k].baseSecs
+ << table[k].start
+ << table[k].stop;
+ }
+ }
+}
+
+void tst_QTimeZone::transitionEachZone()
+{
+ // Regression test: round-trip fromMsecs/toMSecs should be idempotent; but
+ // various zones failed during fall-back transitions.
+ QFETCH(QByteArray, zone);
+ QFETCH(qint64, secs);
+ QFETCH(int, start);
+ QFETCH(int, stop);
+ QTimeZone named(zone);
+
+ for (int i = start; i < stop; i++) {
+ qint64 here = secs + i * 3600;
+ QDateTime when = QDateTime::fromMSecsSinceEpoch(here * 1000, named);
+ qint64 stamp = when.toMSecsSinceEpoch();
+ if (here * 1000 != stamp) // (The +1 is due to using *1*:30 as baseSecs.)
+ qDebug() << "Failing for" << zone << "at half past" << (i + 1) << "UTC";
+ QCOMPARE(stamp % 1000, 0);
+ QCOMPARE(here - stamp / 1000, 0);
+ }
+}
+
void tst_QTimeZone::availableTimeZoneIds()
{
if (debug) {
@@ -704,9 +757,9 @@ void tst_QTimeZone::tzTest()
// Test display names by type, either ICU or abbreviation only
QLocale enUS("en_US");
-#ifdef QT_USE_ICU
// Only test names in debug mode, names used can vary by ICU version installed
if (debug) {
+#ifdef QT_USE_ICU
QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::LongName, enUS),
QString("Central European Standard Time"));
QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::ShortName, enUS),
@@ -726,9 +779,7 @@ void tst_QTimeZone::tzTest()
QString("GMT+01:00"));
QCOMPARE(tzp.displayName(QTimeZone::GenericTime, QTimeZone::OffsetName, enUS),
QString("UTC+01:00"));
- }
#else
- if (debug) {
QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::LongName, enUS),
QString("CET"));
QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::ShortName, enUS),
@@ -747,10 +798,8 @@ void tst_QTimeZone::tzTest()
QString("CET"));
QCOMPARE(tzp.displayName(QTimeZone::GenericTime, QTimeZone::OffsetName, enUS),
QString("CET"));
- }
#endif // QT_USE_ICU
- if (debug) {
// Test Abbreviations
QCOMPARE(tzp.abbreviation(std), QString("CET"));
QCOMPARE(tzp.abbreviation(dst), QString("CEST"));
@@ -907,6 +956,16 @@ void tst_QTimeZone::macTest()
#endif // Q_OS_MAC
}
+void tst_QTimeZone::darwinTypes()
+{
+#ifndef Q_OS_DARWIN
+ QSKIP("This is an Apple-only test");
+#else
+ extern void tst_QTimeZone_darwinTypes(); // in tst_qtimezone_darwin.mm
+ tst_QTimeZone_darwinTypes();
+#endif
+}
+
void tst_QTimeZone::winTest()
{
#if defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN)
diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone_darwin.mm b/tests/auto/corelib/tools/qtimezone/tst_qtimezone_darwin.mm
new file mode 100644
index 0000000000..de801e55d0
--- /dev/null
+++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone_darwin.mm
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QTimeZone>
+#include <QtTest/QtTest>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <Foundation/Foundation.h>
+
+void tst_QTimeZone_darwinTypes()
+{
+#if !defined(QT_NO_SYSTEMLOCALE)
+ // QTimeZone <-> CFTimeZone
+ {
+ QTimeZone qtTimeZone("America/Los_Angeles");
+ const CFTimeZoneRef cfTimeZone = qtTimeZone.toCFTimeZone();
+ QCOMPARE(QTimeZone::fromCFTimeZone(cfTimeZone), qtTimeZone);
+ CFRelease(cfTimeZone);
+ }
+ {
+ CFTimeZoneRef cfTimeZone = CFTimeZoneCreateWithName(kCFAllocatorDefault,
+ CFSTR("America/Los_Angeles"), false);
+ const QTimeZone qtTimeZone = QTimeZone::fromCFTimeZone(cfTimeZone);
+ QVERIFY(CFEqual(qtTimeZone.toCFTimeZone(), cfTimeZone));
+ CFRelease(cfTimeZone);
+ }
+ // QTimeZone <-> NSTimeZone
+ {
+ NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
+ QTimeZone qtTimeZone("America/Los_Angeles");
+ const NSTimeZone *nsTimeZone = qtTimeZone.toNSTimeZone();
+ QCOMPARE(QTimeZone::fromNSTimeZone(nsTimeZone), qtTimeZone);
+ [autoreleasepool release];
+ }
+ {
+ NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
+ NSTimeZone *nsTimeZone = [NSTimeZone timeZoneWithName:@"America/Los_Angeles"];
+ const QTimeZone qtTimeZone = QTimeZone::fromNSTimeZone(nsTimeZone);
+ QVERIFY([qtTimeZone.toNSTimeZone() isEqual:nsTimeZone]);
+ [autoreleasepool release];
+ }
+#endif
+}