diff options
author | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-03-09 10:22:45 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-03-09 10:23:15 +0100 |
commit | 6cef72d0b4f6cd676203688a2562f0a9a620c7fb (patch) | |
tree | d45d59493e942e4489c6428e40ea979eb373eec5 /tests/auto/corelib/tools | |
parent | f7118e7f1b495fc0a0b8d83dff1a207dfddb09aa (diff) | |
parent | 1cd8d67d5f9bb0cd17147481544db8fb9342354d (diff) |
Merge remote-tracking branch 'origin/5.5' into dev
Change-Id: I9d10911c51700965f2cf0e3173b88fd9116bd3ee
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 53 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qstring/tst_qstring.cpp | 9 |
2 files changed, 62 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index c6806086d3..446e56e936 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -142,6 +142,9 @@ private slots: void isDaylightTime() const; void daylightTransitions() const; void timeZones() const; +#if defined(Q_OS_UNIX) + void systemTimeZoneChange() const; +#endif void invalid() const; @@ -2984,6 +2987,56 @@ void tst_QDateTime::timeZones() const QCOMPARE(future.offsetFromUtc(), 28800); } +#if defined(Q_OS_UNIX) +// Currently disabled on Windows as adjusting the timezone +// requires additional privileges that aren't normally +// enabled for a process. This can be achieved by calling +// AdjustTokenPrivileges() and then SetTimeZoneInformation(), +// which will require linking to a different library to access that API. +static void setTimeZone(const QByteArray &tz) +{ + qputenv("TZ", tz); + ::tzset(); + +// following left for future reference, see comment above +// #if defined(Q_OS_WIN32) +// ::_tzset(); +// #endif +} + +void tst_QDateTime::systemTimeZoneChange() const +{ + struct ResetTZ { + QByteArray original; + ResetTZ() : original(qgetenv("TZ")) {} + ~ResetTZ() { setTimeZone(original); } + } scopedReset; + + // Set the timezone to Brisbane time + setTimeZone(QByteArray("AEST-10:00")); + + QDateTime localDate = QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::LocalTime); + QDateTime utcDate = QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::UTC); + QDateTime tzDate = QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), QTimeZone("Australia/Brisbane")); + qint64 localMsecs = localDate.toMSecsSinceEpoch(); + qint64 utcMsecs = utcDate.toMSecsSinceEpoch(); + qint64 tzMsecs = tzDate.toMSecsSinceEpoch(); + + // check that Australia/Brisbane is known + QVERIFY(tzDate.timeZone().isValid()); + + // Change to Indian time + setTimeZone(QByteArray("IST-05:30")); + + QCOMPARE(localDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::LocalTime)); + QVERIFY(localMsecs != localDate.toMSecsSinceEpoch()); + QCOMPARE(utcDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::UTC)); + QCOMPARE(utcDate.toMSecsSinceEpoch(), utcMsecs); + QCOMPARE(tzDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), QTimeZone("Australia/Brisbane"))); + QCOMPARE(tzDate.toMSecsSinceEpoch(), tzMsecs); +} +#endif + void tst_QDateTime::invalid() const { QDateTime invalidDate = QDateTime(QDate(0, 0, 0), QTime(-1, -1, -1)); diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 52c3e65a24..8cd9610542 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -2040,6 +2040,9 @@ void tst_QString::simplified() QFETCH(QString, full); QFETCH(QString, simple); + QString orig_full = full; + orig_full.data(); // forces a detach + QString result = full.simplified(); if (simple.isNull()) { QVERIFY2(result.isNull(), qPrintable("'" + full + "' did not yield null: " + result)); @@ -2048,6 +2051,12 @@ void tst_QString::simplified() } else { QCOMPARE(result, simple); } + QCOMPARE(full, orig_full); + + // without detaching: + QString copy1 = full; + QCOMPARE(qMove(full).simplified(), simple); + QCOMPARE(full, orig_full); // force a detach if (!full.isEmpty()) |