diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-30 06:26:12 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-30 06:26:12 (GMT) |
commit | c8cb256644c143f9d85eed0a8d295ffd05a2017d (patch) | |
tree | 4dc1b8794b7de842a91372576a81b76f07f67156 /tests | |
parent | 1c8cf1b080c81c40bedc9d7c342555585fc394b0 (diff) | |
parent | c4cd2138ea46f9e7990bd732b63d7322f21a2f38 (diff) | |
download | Qt-c8cb256644c143f9d85eed0a8d295ffd05a2017d.zip Qt-c8cb256644c143f9d85eed0a8d295ffd05a2017d.tar.gz Qt-c8cb256644c143f9d85eed0a8d295ffd05a2017d.tar.bz2 |
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests')
3 files changed, 133 insertions, 0 deletions
diff --git a/tests/auto/declarative/behaviors/data/disabled.qml b/tests/auto/declarative/behaviors/data/disabled.qml new file mode 100644 index 0000000..e7b8d51 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/disabled.qml @@ -0,0 +1,27 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior"; + enabled: false + NumberAnimation { duration: 200; } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 6343968..e1376ce 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -64,6 +64,7 @@ private slots: void emptyBehavior(); void nonSelectingBehavior(); void reassignedAnimation(); + void disabled(); }; void tst_behaviors::simpleBehavior() @@ -243,6 +244,20 @@ void tst_behaviors::reassignedAnimation() rect->findChild<QmlBehavior*>("MyBehavior"))->animation())->duration(), 200); } +void tst_behaviors::disabled() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/disabled.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); + QVERIFY(rect); + QCOMPARE(rect->findChild<QmlBehavior*>("MyBehavior")->enabled(), false); + + rect->setState("moved"); + qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately + +} + QTEST_MAIN(tst_behaviors) #include "tst_behaviors.moc" diff --git a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp index f31ea49..96a164b 100644 --- a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp +++ b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp @@ -65,6 +65,7 @@ private slots: void currentIndex(); void defaultValues(); void properties(); + void positionViewAtIndex(); private: QmlView *createView(const QString &filename); @@ -809,6 +810,96 @@ void tst_QmlGraphicsGridView::properties() delete obj; } +void tst_QmlGraphicsGridView::positionViewAtIndex() +{ + QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + + TestModel model; + for (int i = 0; i < 40; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + ctxt->setContextProperty("testTopToBottom", QVariant(false)); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsGridView *gridview = findItem<QmlGraphicsGridView>(canvas->root(), "grid"); + QVERIFY(gridview != 0); + + QmlGraphicsItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + // Confirm items positioned correctly + int itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount-1; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->x(), (i%3)*80.); + QCOMPARE(item->y(), (i/3)*60.); + } + + // Position on a currently visible item + gridview->positionViewAtIndex(4); + QCOMPARE(gridview->viewportY(), 60.); + + // Confirm items positioned correctly + itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->x(), (i%3)*80.); + QCOMPARE(item->y(), (i/3)*60.); + } + + // Position on an item beyond the visible items + gridview->positionViewAtIndex(21); + QCOMPARE(gridview->viewportY(), 420.); + + // Confirm items positioned correctly + itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->x(), (i%3)*80.); + QCOMPARE(item->y(), (i/3)*60.); + } + + // Position on an item that would leave empty space if positioned at the top + gridview->positionViewAtIndex(31); + QCOMPARE(gridview->viewportY(), 520.); + + // Confirm items positioned correctly + itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->x(), (i%3)*80.); + QCOMPARE(item->y(), (i/3)*60.); + } + + // Position at the beginning again + gridview->positionViewAtIndex(0); + QCOMPARE(gridview->viewportY(), 0.); + + // Confirm items positioned correctly + itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount-1; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->x(), (i%3)*80.); + QCOMPARE(item->y(), (i/3)*60.); + } + + delete canvas; +} + QmlView *tst_QmlGraphicsGridView::createView(const QString &filename) { QmlView *canvas = new QmlView(0); |