From dcf1e555d7d2ff435098fe910262cc77dcf835db Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 29 Nov 2011 13:06:47 +0100 Subject: Extend the grammar of QML binding declarations. This allows the use of non-iterative statements on the right hand side of a binding declaration. Change-Id: I60fac880766ba99a410b3647e41b1252677a372f Reviewed-by: Christian Kamm Reviewed-by: Kent Hansen --- .../tst_qdeclarativeecmascript.cpp | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp') diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 5565aaf137..3fdf1e905c 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -233,6 +233,8 @@ private slots: void automaticSemicolon(); void unaryExpression(); void switchStatement(); + void withStatement(); + void tryStatement(); private: static void propertyVarWeakRefCallback(v8::Persistent object, void* parameter); @@ -5339,6 +5341,75 @@ void tst_qdeclarativeecmascript::switchStatement() object->setStringProperty("something else"); QCOMPARE(object->value(), 1); } + + { + QDeclarativeComponent component(&engine, TEST_FILE("switchStatement.6.qml")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + // `object->value()' is the number of executed statements + + object->setStringProperty("A"); + QCOMPARE(object->value(), 123); + + object->setStringProperty("S"); + QCOMPARE(object->value(), 123); + + object->setStringProperty("D"); + QCOMPARE(object->value(), 321); + + object->setStringProperty("F"); + QCOMPARE(object->value(), 321); + + object->setStringProperty("something else"); + QCOMPARE(object->value(), 0); + } +} + +void tst_qdeclarativeecmascript::withStatement() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("withStatement.1.qml")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->value(), 123); + } +} + +void tst_qdeclarativeecmascript::tryStatement() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("tryStatement.1.qml")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->value(), 123); + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("tryStatement.2.qml")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->value(), 321); + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("tryStatement.3.qml")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->value(), 1); + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("tryStatement.4.qml")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->value(), 1); + } } QTEST_MAIN(tst_qdeclarativeecmascript) -- cgit v1.2.3