From 281ff52c266e54030ca48326e79eab2d452c2e83 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 27 Jan 2011 18:22:15 +1000 Subject: Test for passing functions to createObject() for property bindings --- .../data/createObjectWithScript.qml | 17 ++++++++++++++++ .../tst_qdeclarativecomponent.cpp | 23 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml b/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml index 60d4c44..6f9ddc1 100644 --- a/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml +++ b/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml @@ -4,6 +4,10 @@ Item{ id: root property QtObject declarativerectangle : null property QtObject declarativeitem : null + + property QtObject bindingTestObject : null + property QtObject bindingThisTestObject : null + Component{id: a; Rectangle{} } Component{ id: b @@ -14,8 +18,21 @@ Item{ } } + // test passing in bindings + width: 100 + Component { + id: c + Item { + property int testValue + width: 300 + } + } + Component.onCompleted: { root.declarativerectangle = a.createObject(root, {"x":17,"y":17, "color":"white"}); root.declarativeitem = b.createObject(root, {"x":17,"y":17,"testBool":true,"testInt":17,"testObject":root}); + + root.bindingTestObject = c.createObject(root, {'testValue': (function(){return width * 3}) }) // use root.width + root.bindingThisTestObject = c.createObject(root, {'testValue': (function(){return this.width * 3}) }) // use width of Item within 'c' } } diff --git a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp index 829b762..62c6bb5 100644 --- a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp +++ b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp @@ -62,7 +62,7 @@ private slots: void null(); void loadEmptyUrl(); void qmlCreateObject(); - void qmlCreatObjectWithScript(); + void qmlCreateObjectWithProperties(); private: QDeclarativeEngine engine; @@ -121,10 +121,11 @@ void tst_qdeclarativecomponent::qmlCreateObject() QCOMPARE(testObject3->metaObject()->className(), "QDeclarativeGraphicsWidget"); } -void tst_qdeclarativecomponent::qmlCreatObjectWithScript() +void tst_qdeclarativecomponent::qmlCreateObjectWithProperties() { QDeclarativeEngine engine; QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/createObjectWithScript.qml")); + QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8()); QObject *object = component.create(); QVERIFY(object != 0); @@ -134,6 +135,7 @@ void tst_qdeclarativecomponent::qmlCreatObjectWithScript() QCOMPARE(testObject1->property("x").value(), 17); QCOMPARE(testObject1->property("y").value(), 17); QCOMPARE(testObject1->property("color").value(), QColor(255,255,255)); + delete testObject1; QObject *testObject2 = object->property("declarativeitem").value(); QVERIFY(testObject2); @@ -144,6 +146,23 @@ void tst_qdeclarativecomponent::qmlCreatObjectWithScript() QCOMPARE(testObject2->property("testBool").value(), true); QCOMPARE(testObject2->property("testInt").value(), 17); QCOMPARE(testObject2->property("testObject").value(), object); + delete testObject2; + + QObject *testBindingObj = object->property("bindingTestObject").value(); + QVERIFY(testBindingObj); + QCOMPARE(testBindingObj->parent(), object); + QCOMPARE(testBindingObj->property("testValue").value(), 300); + object->setProperty("width", 150); + QCOMPARE(testBindingObj->property("testValue").value(), 150 * 3); + delete testBindingObj; + + QObject *testBindingThisObj = object->property("bindingThisTestObject").value(); + QVERIFY(testBindingThisObj); + QCOMPARE(testBindingThisObj->parent(), object); + QCOMPARE(testBindingThisObj->property("testValue").value(), 900); + testBindingThisObj->setProperty("width", 200); + QCOMPARE(testBindingThisObj->property("testValue").value(), 200 * 3); + delete testBindingThisObj; } QTEST_MAIN(tst_qdeclarativecomponent) -- cgit v0.12