aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGlenn Watson <glenn.watson@nokia.com>2012-06-26 14:52:27 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-26 23:28:55 +0200
commitfb5c74a07dac7deedb9ab3b8b4390941e5dd0762 (patch)
tree191f686acfa82176cda48207909b9643e11a36a7 /tests
parentfe73fabad96f443247c6334b2c1b6ef59401c2c8 (diff)
Support JS Date object in ListModel with static roles.
ListModel uses static roles by default for performance reasons. Add JS Date object to list of supported types in this mode, via implicit conversion to QDateTime. Task-number: QTBUG-24456 Change-Id: Ifaa1a8d16290e87b61239ed351a949d66a02990c Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp b/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
index e94fe81024..e4045ebe88 100644
--- a/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
+++ b/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
@@ -125,6 +125,8 @@ private slots:
void string_to_list_crash();
void empty_element_warning();
void empty_element_warning_data();
+ void datetime();
+ void datetime_data();
};
bool tst_qquicklistmodel::compareVariantList(const QVariantList &testList, QVariant object)
@@ -1226,6 +1228,40 @@ void tst_qquicklistmodel::empty_element_warning()
delete obj;
}
+void tst_qquicklistmodel::datetime_data()
+{
+ QTest::addColumn<QString>("qml");
+ QTest::addColumn<QDateTime>("expected");
+
+ QDateTime dt;
+ QDateTime dt0(QDate(1900, 1, 2), QTime( 8, 14));
+ QDateTime dt1(QDate(2000, 11, 22), QTime(10, 45));
+
+ QTest::newRow("dt0") << "{append({'date':dt0});get(0).date}" << dt0;
+ QTest::newRow("dt1") << "{append({'date':dt0});get(0).date=dt1;get(0).date}" << dt1;
+ QTest::newRow("dt2") << "{append({'date':dt0});set(0,{'date':dt1});get(0).date}" << dt1;
+ QTest::newRow("dt3") << "{append({'date':dt0});get(0).date=undefined;get(0).date}" << dt;
+}
+
+void tst_qquicklistmodel::datetime()
+{
+ QFETCH(QString, qml);
+ QFETCH(QDateTime, expected);
+
+ QQmlEngine engine;
+ QQuickListModel model;
+ QQmlEngine::setContextForObject(&model,engine.rootContext());
+ QDateTime dt0(QDate(1900, 1, 2), QTime( 8, 14));
+ QDateTime dt1(QDate(2000, 11, 22), QTime(10, 45));
+ engine.rootContext()->setContextProperty("dt0", dt0);
+ engine.rootContext()->setContextProperty("dt1", dt1);
+ engine.rootContext()->setContextObject(&model);
+ QQmlExpression e(engine.rootContext(), &model, qml);
+ QVariant result = e.evaluate();
+ QDateTime dtResult = result.toDateTime();
+ QVERIFY(expected == dtResult);
+}
+
QTEST_MAIN(tst_qquicklistmodel)
#include "tst_qquicklistmodel.moc"