summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-01-20 05:04:44 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-01-20 05:04:44 (GMT)
commitacc74925e989e9c6cbde66858ca04cfc053602bc (patch)
tree458c7067a453b6c8bbdac7a4467849188c8c5502 /tests/auto/declarative
parentf95956a6cc61d0c05d96e2f8027167f51ed7dbea (diff)
downloadQt-acc74925e989e9c6cbde66858ca04cfc053602bc.zip
Qt-acc74925e989e9c6cbde66858ca04cfc053602bc.tar.gz
Qt-acc74925e989e9c6cbde66858ca04cfc053602bc.tar.bz2
Keep empty lists and 1-item lists as lists instead of converting them
to null or single objects. This brings back change bc6940f with additional fixes and tests.
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp
index 0986d20..da1bf44 100644
--- a/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp
+++ b/tests/auto/declarative/qmllistmodel/tst_qmllistmodel.cpp
@@ -52,6 +52,8 @@ public:
private slots:
void static_i18n();
+ void static_nestedElements();
+ void static_nestedElements_data();
void dynamic_data();
void dynamic();
void error_data();
@@ -72,6 +74,50 @@ void tst_QmlListModel::static_i18n()
delete obj;
}
+void tst_QmlListModel::static_nestedElements()
+{
+ QFETCH(int, elementCount);
+
+ QStringList elements;
+ for (int i=0; i<elementCount; i++)
+ elements.append("ListElement { a: 1; b: 2 }");
+ QString elementsStr = elements.join(",\n") + "\n";
+
+ QString componentStr =
+ "import Qt 4.6\n"
+ "ListModel {\n"
+ " ListElement {\n"
+ " attributes: [\n";
+ componentStr += elementsStr.toUtf8().constData();
+ componentStr +=
+ " ]\n"
+ " }\n"
+ "}";
+
+ QmlEngine engine;
+ QmlComponent component(&engine);
+ component.setData(componentStr.toUtf8(), QUrl("file://"));
+
+ QmlListModel *obj = qobject_cast<QmlListModel*>(component.create());
+ QVERIFY(obj != 0);
+
+ QScriptValue prop = obj->get(0).property(QLatin1String("attributes")).property(QLatin1String("count"));
+ QVERIFY(prop.isNumber());
+ QCOMPARE(prop.toInt32(), qint32(elementCount));
+
+ delete obj;
+}
+
+void tst_QmlListModel::static_nestedElements_data()
+{
+ QTest::addColumn<int>("elementCount");
+
+ QTest::newRow("0 items") << 0;
+ QTest::newRow("1 item") << 1;
+ QTest::newRow("2 items") << 2;
+ QTest::newRow("many items") << 5;
+}
+
void tst_QmlListModel::dynamic_data()
{
QTest::addColumn<QString>("script");