aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-04-23 15:14:42 +1000
committerQt by Nokia <qt-info@nokia.com>2012-04-24 00:33:25 +0200
commit5dac3d9f846d0a9cffb95608219fefd4079a7bc2 (patch)
treeaf71dea03eb2fd7c46e3e584380e7007d2a78eea /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
parenta8e017fbc22d8ec445fc9202479a775bdac4d5b0 (diff)
Verify that QML can reliably receive datetime info from C++
Since a JavaScript Date object does not contain any information about the timezone in which it is specified, a C++ module that exports datetime information to QML must also provide the relevant timezone data so that clients can correctly interpret the datetime value. Provide an example of exporting datetime information to QML, verifying that the data can be correctly interpreted in JS. Task-number: QTBUG-25262 Change-Id: I732797da225861470e6b034f2e3d89a43df36cf7 Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 4e7da76d5e..b66427ef89 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -73,6 +73,8 @@ private slots:
void assignBasicTypes();
void assignDate_data();
void assignDate();
+ void exportDate_data();
+ void exportDate();
void idShortcutInvalidates();
void boolPropertiesEvaluateAsBool();
void methods();
@@ -362,6 +364,62 @@ void tst_qqmlecmascript::assignDate()
QCOMPARE(object->boolProperty(), true);
}
+void tst_qqmlecmascript::exportDate_data()
+{
+ QTest::addColumn<QUrl>("source");
+ QTest::addColumn<QDateTime>("datetime");
+
+ // Verify that we can export datetime information to QML and that consumers can access
+ // the data correctly provided they know the TZ info associated with the value
+
+ const QDate date(2009, 5, 12);
+ const QTime early(0, 0, 1);
+ const QTime late(23, 59, 59);
+ const int offset(((11 * 60) + 30) * 60);
+
+ QTest::newRow("Localtime early") << testFileUrl("exportDate.qml") << QDateTime(date, early, Qt::LocalTime);
+ QTest::newRow("Localtime late") << testFileUrl("exportDate.2.qml") << QDateTime(date, late, Qt::LocalTime);
+ QTest::newRow("UTC early") << testFileUrl("exportDate.3.qml") << QDateTime(date, early, Qt::UTC);
+ QTest::newRow("UTC late") << testFileUrl("exportDate.4.qml") << QDateTime(date, late, Qt::UTC);
+ {
+ QDateTime dt(date, early, Qt::OffsetFromUTC);
+ dt.setUtcOffset(offset);
+ QTest::newRow("+11:30 early") << testFileUrl("exportDate.5.qml") << dt;
+ }
+ {
+ QDateTime dt(date, late, Qt::OffsetFromUTC);
+ dt.setUtcOffset(offset);
+ QTest::newRow("+11:30 late") << testFileUrl("exportDate.6.qml") << dt;
+ }
+ {
+ QDateTime dt(date, early, Qt::OffsetFromUTC);
+ dt.setUtcOffset(-offset);
+ QTest::newRow("-11:30 early") << testFileUrl("exportDate.7.qml") << dt;
+ }
+ {
+ QDateTime dt(date, late, Qt::OffsetFromUTC);
+ dt.setUtcOffset(-offset);
+ QTest::newRow("-11:30 late") << testFileUrl("exportDate.8.qml") << dt;
+ }
+}
+
+void tst_qqmlecmascript::exportDate()
+{
+ QFETCH(QUrl, source);
+ QFETCH(QDateTime, datetime);
+
+ DateTimeExporter exporter(datetime);
+
+ QQmlEngine e;
+ e.rootContext()->setContextProperty("datetimeExporter", &exporter);
+
+ QQmlComponent component(&e, source);
+ QScopedPointer<QObject> obj(component.create());
+ MyTypeObject *object = qobject_cast<MyTypeObject *>(obj.data());
+ QVERIFY(object != 0);
+ QCOMPARE(object->boolProperty(), true);
+}
+
void tst_qqmlecmascript::idShortcutInvalidates()
{
{