diff options
author | Glenn Watson <glenn.watson@nokia.com> | 2012-06-20 12:57:43 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-22 01:26:29 +0200 |
commit | 4d27bc91f0da57c383762b96674f7a335efdbb28 (patch) | |
tree | 8ea17d0e9f5c6d51095855513e545be134bb593a | |
parent | fa457e593deca9fcffe2d6ec6ca0aa40d9fa7b76 (diff) |
Fix locale test on Linux and skip it on Windows.
The timezone that V8 internally uses was not being updated at the
end of one test, causing failures in subsequent tests. This was
only showing up on Windows because the test was being skipped on
Linux due to a typo. Skip the test on Windows due to complexity
of changing the timezone (added comments in code with details).
Change-Id: I47c8542111e8ddfbdeff39815c50d98570b0c6c2
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
-rw-r--r-- | tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml | 16 | ||||
-rw-r--r-- | tests/auto/qml/qqmllocale/tst_qqmllocale.cpp | 29 |
2 files changed, 38 insertions, 7 deletions
diff --git a/tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml b/tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml index 92d1f5bc40..cc6e1437ab 100644 --- a/tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml +++ b/tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml @@ -13,11 +13,11 @@ Item { if (localDate.getTimezoneOffset() != -600) return - if (localDate.toLocaleString() != "Friday, June 1, 2012 2:15:30 AM AEST") return + if (localDate.toLocaleString() != getLocalizedForm('2012-06-01T02:15:30+10:00')) return if (localDate.toISOString() != "2012-05-31T16:15:30.000Z") return if (utcDate.toISOString() != "2012-06-01T02:15:30.000Z") return - if (utcDate.toLocaleString() != "Friday, June 1, 2012 12:15:30 PM AEST") return + if (utcDate.toLocaleString() != getLocalizedForm('2012-06-01T12:15:30+10:00')) return success = true } @@ -30,22 +30,26 @@ Item { if (localDate.getTimezoneOffset() != -330) return - if (localDate.toLocaleString() != "Friday, June 1, 2012 2:15:30 AM IST") return + if (localDate.toLocaleString() != getLocalizedForm('2012-06-01T02:15:30+05:30')) return if (localDate.toISOString() != "2012-05-31T20:45:30.000Z") return if (utcDate.toISOString() != "2012-06-01T06:45:30.000Z") return - if (utcDate.toLocaleString() != "Friday, June 1, 2012 12:15:30 PM IST") return + if (utcDate.toLocaleString() != getLocalizedForm("2012-06-01T12:15:30+05:30")) return // Create new dates in this timezone localDate = new Date(2012, 6-1, 1, 2, 15, 30) utcDate = new Date(Date.UTC(2012, 6-1, 1, 2, 15, 30)) - if (localDate.toLocaleString() != "Friday, June 1, 2012 2:15:30 AM IST") return + if (localDate.toLocaleString() != getLocalizedForm("2012-06-01T02:15:30+05:30")) return if (localDate.toISOString() != "2012-05-31T20:45:30.000Z") return if (utcDate.toISOString() != "2012-06-01T02:15:30.000Z") return - if (utcDate.toLocaleString() != "Friday, June 1, 2012 7:45:30 AM IST") return + if (utcDate.toLocaleString() != getLocalizedForm("2012-06-01T07:45:30+05:30")) return success = true } + + function resetTimeZone() { + Date.timeZoneUpdated() + } } diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp index c39426375f..f9ced254da 100644 --- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp +++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp @@ -43,6 +43,7 @@ #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> +#include <QtQml/qqmlcontext.h> #include <QtCore/QDateTime> #include <qcolor.h> #include "../../shared/util.h" @@ -1227,9 +1228,30 @@ static void setTimeZone(const QByteArray &tz) #endif } +class DateFormatter : public QObject +{ + Q_OBJECT +public: + DateFormatter() : QObject() {} + + Q_INVOKABLE QString getLocalizedForm(const QString &isoTimestamp); +}; + +QString DateFormatter::getLocalizedForm(const QString &isoTimestamp) +{ + QDateTime input = QDateTime::fromString(isoTimestamp, Qt::ISODate); + QLocale locale; + return locale.toString(input); +} + void tst_qqmllocale::timeZoneUpdated() { -#if !defined(Q_OS_WIN32) && !defined(Q_OS_UINX) +#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. QSKIP("Timezone manipulation not available for this platform"); #endif @@ -1238,7 +1260,11 @@ void tst_qqmllocale::timeZoneUpdated() // Set the timezone to Brisbane time setTimeZone(QByteArray("AEST-10:00")); + DateFormatter formatter; + QQmlEngine e; + e.rootContext()->setContextObject(&formatter); + QQmlComponent c(&e, testFileUrl("timeZoneUpdated.qml")); QScopedPointer<QObject> obj(c.create()); QVERIFY(obj); @@ -1251,6 +1277,7 @@ void tst_qqmllocale::timeZoneUpdated() // Reset to original time setTimeZone(original); + QMetaObject::invokeMethod(obj.data(), "resetTimeZone"); QCOMPARE(obj->property("success").toBool(), true); } |