aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeecmascript
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2011-11-29 13:06:47 +0100
committerQt by Nokia <qt-info@nokia.com>2011-11-30 12:28:27 +0100
commitdcf1e555d7d2ff435098fe910262cc77dcf835db (patch)
tree294a94c138e3cebe025bd7a3f4abc0be6776cd12 /tests/auto/declarative/qdeclarativeecmascript
parent92b2a05dcae983be6f108e010114c129809b9234 (diff)
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 <christian.d.kamm@nokia.com> Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/switchStatement.6.qml13
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.1.qml13
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.2.qml11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.3.qml13
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.4.qml12
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/withStatement.1.qml14
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp71
7 files changed, 147 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/switchStatement.6.qml b/tests/auto/declarative/qdeclarativeecmascript/data/switchStatement.6.qml
new file mode 100644
index 0000000000..6fb71eb345
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/switchStatement.6.qml
@@ -0,0 +1,13 @@
+import Qt.test 1.0
+
+MyQmlObject {
+ function one(kind) { return 123 }
+ function two(kind) { return 321 }
+
+ value: switch (stringProperty) {
+ case "A": case "S": one(stringProperty); break;
+ case "D": case "F": two(stringProperty); break;
+ default: 0
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.1.qml
new file mode 100644
index 0000000000..71cc67a941
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.1.qml
@@ -0,0 +1,13 @@
+import Qt.test 1.0
+
+MyQmlObject {
+ property int defaultValue: 123
+
+ function go() {
+ undefinedObject.method() // this call will throw an exception
+ return 321
+ }
+
+ value: try { go() } catch(e) { defaultValue }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.2.qml
new file mode 100644
index 0000000000..e7fca0bff7
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.2.qml
@@ -0,0 +1,11 @@
+import Qt.test 1.0
+
+MyQmlObject {
+ property int defaultValue: 123
+
+ function go() {
+ return 321
+ }
+
+ value: try { go() } catch(e) { defaultValue }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.3.qml
new file mode 100644
index 0000000000..04b39f73d5
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.3.qml
@@ -0,0 +1,13 @@
+import Qt.test 1.0
+
+MyQmlObject {
+ property int defaultValue: 123
+
+ function go() {
+ undefinedObject.method() // this call will throw an exception
+ return 321
+ }
+
+ value: try { var p = go() } catch(e) { var p = defaultValue } finally { p == 123 }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.4.qml
new file mode 100644
index 0000000000..231aaf0683
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/tryStatement.4.qml
@@ -0,0 +1,12 @@
+import Qt.test 1.0
+
+MyQmlObject {
+ property int defaultValue: 123
+
+ function go() {
+ return 321
+ }
+
+ value: try { var p = go() } catch(e) { var p = defaultValue } finally { p == 321 }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/withStatement.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/withStatement.1.qml
new file mode 100644
index 0000000000..28f0c08451
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/withStatement.1.qml
@@ -0,0 +1,14 @@
+import Qt.test 1.0
+
+MyQmlObject {
+ property var other: MyQmlObject {
+ intProperty: 123
+
+ function go() {
+ return intProperty;
+ }
+ }
+
+ value: with(other) go()
+}
+
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<v8::Value> 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<MyQmlObject *>(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<MyQmlObject *>(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<MyQmlObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->value(), 123);
+ }
+
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("tryStatement.2.qml"));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->value(), 321);
+ }
+
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("tryStatement.3.qml"));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->value(), 1);
+ }
+
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("tryStatement.4.qml"));
+ MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->value(), 1);
+ }
}
QTEST_MAIN(tst_qdeclarativeecmascript)