From d1d900561a9a51bd44707546e691b013341e221c Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 11 Nov 2009 17:47:21 +1000 Subject: Extend repeater test ObjectList doesn't pass yet. Unsure if it should be passing, or if we should rectify the docs. --- tests/auto/declarative/repeater/data/intmodel.qml | 17 ++++++++++ tests/auto/declarative/repeater/data/objlist.qml | 21 +++++++++++++ tests/auto/declarative/repeater/tst_repeater.cpp | 38 +++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 tests/auto/declarative/repeater/data/intmodel.qml create mode 100644 tests/auto/declarative/repeater/data/objlist.qml diff --git a/tests/auto/declarative/repeater/data/intmodel.qml b/tests/auto/declarative/repeater/data/intmodel.qml new file mode 100644 index 0000000..a779079 --- /dev/null +++ b/tests/auto/declarative/repeater/data/intmodel.qml @@ -0,0 +1,17 @@ +import Qt 4.6 + +Rectangle { + id: container + objectName: "container" + width: 240 + height: 320 + color: "white" + Repeater { + id: repeater + objectName: "repeater" + model: testData + Component { + Item{} + } + } +} diff --git a/tests/auto/declarative/repeater/data/objlist.qml b/tests/auto/declarative/repeater/data/objlist.qml new file mode 100644 index 0000000..ecc6d02 --- /dev/null +++ b/tests/auto/declarative/repeater/data/objlist.qml @@ -0,0 +1,21 @@ +import Qt 4.6 + +Rectangle { + id: container + objectName: "container" + width: 240 + height: 320 + color: "white" + Repeater { + id: repeater + objectName: "repeater" + model: testData + property int errors: 0 + property int instantiated: 0 + Component { + Item{ + Component.onCompleted: {if(index!=modelData.idx) repeater.errors += 1; repeater.instantiated++} + } + } + } +} diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/repeater/tst_repeater.cpp index dc0f1be..e002ee1 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/repeater/tst_repeater.cpp @@ -52,6 +52,8 @@ public: tst_QmlGraphicsRepeater(); private slots: + void numberModel(); + void objectList(); void stringList(); private: @@ -64,6 +66,42 @@ tst_QmlGraphicsRepeater::tst_QmlGraphicsRepeater() { } +void tst_QmlGraphicsRepeater::numberModel() +{ + QmlView *canvas = createView(SRCDIR "/data/intmodel.qml"); + canvas->execute(); + qApp->processEvents(); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testData", 5); + + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QVERIFY(repeater != 0); + QCOMPARE(repeater->parentItem()->childItems().count(), 5+1); +} + +void tst_QmlGraphicsRepeater::objectList() +{ + QmlView *canvas = createView(SRCDIR "/data/objlist.qml"); + + QObjectList* data = new QObjectList; + for(int i=0; i<100; i++){ + *data << new QObject(); + data->back()->setProperty("idx", i); + } + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testData", QVariant::fromValue(data)); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); + QVERIFY(repeater != 0); + QCOMPARE(repeater->property("errors").toInt(), 0);//If this fails either they are out of order or can't find the object's data + QCOMPARE(repeater->property("instantiated").toInt(), 100); +} + /* The Repeater element creates children at its own position in its parent's stacking order. In this test we insert a repeater between two other Text -- cgit v0.12