From: Glenn Watson Date: Wed, 20 Jun 2012 02:57:43 +0000 (+1000) Subject: Fix locale test on Linux and skip it on Windows. X-Git-Tag: upstream/5.2.1~1620 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d27bc91f0da57c383762b96674f7a335efdbb28;p=platform%2Fupstream%2Fqtdeclarative.git 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 --- diff --git a/tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml b/tests/auto/qml/qqmllocale/data/timeZoneUpdated.qml index 92d1f5b..cc6e143 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 c394263..f9ced25 100644 --- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp +++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp @@ -43,6 +43,7 @@ #include #include +#include #include #include #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 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); }