diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-02-24 02:42:00 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-02-24 02:42:00 (GMT) |
commit | 7c76abb0dc4204043bec9b6fa315f9753a7986ae (patch) | |
tree | cee303672cfd138790645e731f2d69472564d4b7 /tests/auto/declarative/qmlecmascript | |
parent | 4066e60e859853cfe3240245ba05271e79839506 (diff) | |
download | Qt-7c76abb0dc4204043bec9b6fa315f9753a7986ae.zip Qt-7c76abb0dc4204043bec9b6fa315f9753a7986ae.tar.gz Qt-7c76abb0dc4204043bec9b6fa315f9753a7986ae.tar.bz2 |
Change class prefix to from QmlXXX to QDeclarativeXXX, QmlGraphicsXXX to QDeclarativeXXX.
Diffstat (limited to 'tests/auto/declarative/qmlecmascript')
72 files changed, 0 insertions, 3178 deletions
diff --git a/tests/auto/declarative/qmlecmascript/data/ConstantsOverrideBindings.qml b/tests/auto/declarative/qmlecmascript/data/ConstantsOverrideBindings.qml deleted file mode 100644 index b4a702b..0000000 --- a/tests/auto/declarative/qmlecmascript/data/ConstantsOverrideBindings.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - property int c1: 0 - property int c2: c1 -} diff --git a/tests/auto/declarative/qmlecmascript/data/CustomObject.qml b/tests/auto/declarative/qmlecmascript/data/CustomObject.qml deleted file mode 100644 index 691d9ec..0000000 --- a/tests/auto/declarative/qmlecmascript/data/CustomObject.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt 4.6 - -QtObject { - property string greeting: "hello world" -} diff --git a/tests/auto/declarative/qmlecmascript/data/MethodsObject.qml b/tests/auto/declarative/qmlecmascript/data/MethodsObject.qml deleted file mode 100644 index f51ca86..0000000 --- a/tests/auto/declarative/qmlecmascript/data/MethodsObject.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt 4.6 - -QtObject { - function testFunction() { return 19; } - function testFunction2() { return 18; } -} diff --git a/tests/auto/declarative/qmlecmascript/data/NestedTypeTransientErrors.qml b/tests/auto/declarative/qmlecmascript/data/NestedTypeTransientErrors.qml deleted file mode 100644 index 7c32e56..0000000 --- a/tests/auto/declarative/qmlecmascript/data/NestedTypeTransientErrors.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt 4.6 - -QtObject { - property int b: obj.prop.a - - property var prop; - prop: QtObject { - property int a: 10 - } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/ScopeObject.qml b/tests/auto/declarative/qmlecmascript/data/ScopeObject.qml deleted file mode 100644 index b7bec63..0000000 --- a/tests/auto/declarative/qmlecmascript/data/ScopeObject.qml +++ /dev/null @@ -1,14 +0,0 @@ -import Qt 4.6 - -Item { - property int a: 3 - property int binding: myFunction(); - property int binding2: myCompFunction(); - - Script { - function myCompFunction() { - return a; - } - } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml b/tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml deleted file mode 100644 index 56e0625..0000000 --- a/tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml +++ /dev/null @@ -1,2 +0,0 @@ -import Qt.test 1.0 -MyQmlObject{objectName:"objectThree"} diff --git a/tests/auto/declarative/qmlecmascript/data/aliasPropertyAndBinding.qml b/tests/auto/declarative/qmlecmascript/data/aliasPropertyAndBinding.qml deleted file mode 100644 index 5c3ea1f..0000000 --- a/tests/auto/declarative/qmlecmascript/data/aliasPropertyAndBinding.qml +++ /dev/null @@ -1,14 +0,0 @@ -import Qt 4.6 -import Qt.test 1.0 - -MyQmlObject { - property alias c1: myObject.c1 - property int c2: 3 - property int c3: c2 - objectProperty: QtObject { - id: myObject - property int c1 - } -} - - diff --git a/tests/auto/declarative/qmlecmascript/data/assignBasicTypes.2.qml b/tests/auto/declarative/qmlecmascript/data/assignBasicTypes.2.qml deleted file mode 100644 index db7f2b5..0000000 --- a/tests/auto/declarative/qmlecmascript/data/assignBasicTypes.2.qml +++ /dev/null @@ -1,26 +0,0 @@ -import Qt.test 1.0 - -MyTypeObject { - flagProperty: if(1) "FlagVal1 | FlagVal3" - enumProperty: if(1) "EnumVal2" - stringProperty: if(1) "Hello World!" - uintProperty: if(1) 10 - intProperty: if(1) -19 - realProperty: if(1) 23.2 - doubleProperty: if(1) -19.7 - floatProperty: if(1) 8.5 - colorProperty: if(1) "red" - dateProperty: if(1) "1982-11-25" - timeProperty: if(1) "11:11:32" - dateTimeProperty: if(1) "2009-05-12T13:22:01" - pointProperty: if(1) "99,13" - pointFProperty: if(1) "-10.1,12.3" - sizeProperty: if(1) "99x13" - sizeFProperty: if(1) "0.1x0.2" - rectProperty: if(1) "9,7,100x200" - rectFProperty: if(1) "1000.1,-10.9,400x90.99" - boolProperty: if(1) true - variantProperty: if(1) "Hello World!" - vectorProperty: if(1) "10,1,2.2" - urlProperty: if(1) "main.qml" -} diff --git a/tests/auto/declarative/qmlecmascript/data/assignBasicTypes.qml b/tests/auto/declarative/qmlecmascript/data/assignBasicTypes.qml deleted file mode 100644 index 128db69..0000000 --- a/tests/auto/declarative/qmlecmascript/data/assignBasicTypes.qml +++ /dev/null @@ -1,29 +0,0 @@ -import Qt.test 1.0 -import Qt 4.6 - -MyTypeObject { - Component.onCompleted: { - flagProperty = "FlagVal1 | FlagVal3" - enumProperty = "EnumVal2" - stringProperty = "Hello World!" - uintProperty = 10 - intProperty = -19 - realProperty = 23.2 - doubleProperty = -19.7 - floatProperty = 8.5 - colorProperty = "red" - dateProperty = "1982-11-25" - timeProperty = "11:11:32" - dateTimeProperty = "2009-05-12T13:22:01" - pointProperty = "99,13" - pointFProperty = "-10.1,12.3" - sizeProperty = "99x13" - sizeFProperty = "0.1x0.2" - rectProperty = "9,7,100x200" - rectFProperty = "1000.1,-10.9,400x90.99" - boolProperty = true - variantProperty = "Hello World!" - vectorProperty = "10,1,2.2" - urlProperty = "main.qml" - } -} diff --git a/tests/auto/declarative/qmlecmascript/data/attachedProperty.qml b/tests/auto/declarative/qmlecmascript/data/attachedProperty.qml deleted file mode 100644 index 061eda0..0000000 --- a/tests/auto/declarative/qmlecmascript/data/attachedProperty.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt.test 1.0 -import Qt.test 1.0 as Namespace - -MyQmlObject { - id: me - property int a: MyQmlObject.value - property int b: Namespace.MyQmlObject.value - property int c: me.Namespace.MyQmlObject.value - property int d: me.Namespace.MyQmlObject.value -} - diff --git a/tests/auto/declarative/qmlecmascript/data/bindingLoop.qml b/tests/auto/declarative/qmlecmascript/data/bindingLoop.qml deleted file mode 100644 index 80545cf..0000000 --- a/tests/auto/declarative/qmlecmascript/data/bindingLoop.qml +++ /dev/null @@ -1,14 +0,0 @@ -import Qt.test 1.0 - -MyQmlContainer { - children : [ - MyQmlObject { - id: object1 - stringProperty: "hello" + object2.stringProperty - }, - MyQmlObject { - id: object2 - stringProperty: "hello" + object1.stringProperty - } - ] -} diff --git a/tests/auto/declarative/qmlecmascript/data/boolPropertiesEvaluateAsBool.1.qml b/tests/auto/declarative/qmlecmascript/data/boolPropertiesEvaluateAsBool.1.qml deleted file mode 100644 index 3147f63..0000000 --- a/tests/auto/declarative/qmlecmascript/data/boolPropertiesEvaluateAsBool.1.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - stringProperty: trueProperty?'pass':'fail' -} diff --git a/tests/auto/declarative/qmlecmascript/data/boolPropertiesEvaluateAsBool.2.qml b/tests/auto/declarative/qmlecmascript/data/boolPropertiesEvaluateAsBool.2.qml deleted file mode 100644 index c89bb49..0000000 --- a/tests/auto/declarative/qmlecmascript/data/boolPropertiesEvaluateAsBool.2.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - stringProperty: falseProperty?'fail':'pass' -} diff --git a/tests/auto/declarative/qmlecmascript/data/bug.1.qml b/tests/auto/declarative/qmlecmascript/data/bug.1.qml deleted file mode 100644 index 266de76..0000000 --- a/tests/auto/declarative/qmlecmascript/data/bug.1.qml +++ /dev/null @@ -1,10 +0,0 @@ -import Qt 4.6 - -QtObject { - property int a: 10 - property bool b: false - - property int test - - test: ((a == 10)?(a + 1):0) + ((b == true)?9:3) -} diff --git a/tests/auto/declarative/qmlecmascript/data/compositePropertyType.qml b/tests/auto/declarative/qmlecmascript/data/compositePropertyType.qml deleted file mode 100644 index 80a2814..0000000 --- a/tests/auto/declarative/qmlecmascript/data/compositePropertyType.qml +++ /dev/null @@ -1,8 +0,0 @@ -import Qt 4.6 - -QtObject { - property CustomObject myObject - myObject: CustomObject { } - - Component.onCompleted: console.log(myObject.greeting) -} diff --git a/tests/auto/declarative/qmlecmascript/data/constantsOverrideBindings.1.qml b/tests/auto/declarative/qmlecmascript/data/constantsOverrideBindings.1.qml deleted file mode 100644 index 13c5ae5..0000000 --- a/tests/auto/declarative/qmlecmascript/data/constantsOverrideBindings.1.qml +++ /dev/null @@ -1,8 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - property int c1: 0 - property int c2: c1 - - onBasicSignal: c2 = 13 -} diff --git a/tests/auto/declarative/qmlecmascript/data/constantsOverrideBindings.2.qml b/tests/auto/declarative/qmlecmascript/data/constantsOverrideBindings.2.qml deleted file mode 100644 index 207a06b..0000000 --- a/tests/auto/declarative/qmlecmascript/data/constantsOverrideBindings.2.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - property alias c1: myConstants.c1 - property alias c2: myConstants.c2 - - objectProperty: ConstantsOverrideBindings { - id: myConstants - c2: 10 - } -} diff --git a/tests/auto/declarative/qmlecmascript/data/constantsOverrideBindings.3.qml b/tests/auto/declarative/qmlecmascript/data/constantsOverrideBindings.3.qml deleted file mode 100644 index ca9d1d8..0000000 --- a/tests/auto/declarative/qmlecmascript/data/constantsOverrideBindings.3.qml +++ /dev/null @@ -1,7 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - property int c1: 0 - property int c2: c1 -} - diff --git a/tests/auto/declarative/qmlecmascript/data/deferredProperties.qml b/tests/auto/declarative/qmlecmascript/data/deferredProperties.qml deleted file mode 100644 index e01f708..0000000 --- a/tests/auto/declarative/qmlecmascript/data/deferredProperties.qml +++ /dev/null @@ -1,10 +0,0 @@ -import Qt.test 1.0 - -MyDeferredObject { - id: root - value: 10 - objectProperty: MyQmlObject { - value: root.value - } - objectProperty2: MyQmlObject { id: blah } -} diff --git a/tests/auto/declarative/qmlecmascript/data/deletedObject.qml b/tests/auto/declarative/qmlecmascript/data/deletedObject.qml deleted file mode 100644 index 6bc3a17..0000000 --- a/tests/auto/declarative/qmlecmascript/data/deletedObject.qml +++ /dev/null @@ -1,25 +0,0 @@ -import Qt 4.6 -import Qt.test 1.0 - -QtObject { - property var obj - obj: MyQmlObject { - id: myObject - value: 92 - } - - property bool test1: false - property bool test2: false - property bool test3: false - property bool test4: false - - Component.onCompleted: { - test1 = myObject.value == 92; - test2 = obj.value == 92; - - myObject.deleteOnSet = 1; - - test3 = myObject.value == undefined; - // test4 = obj.value == undefined; - } -} diff --git a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.helper.qml b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.helper.qml deleted file mode 100644 index d790d63..0000000 --- a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.helper.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject{ - objectName: "objectTwo" -} - diff --git a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml deleted file mode 100644 index ed5e571..0000000 --- a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml +++ /dev/null @@ -1,21 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject{ - id: obj - objectName: "obj" - function createOne() - { - obj.objectProperty = createQmlObject('import Qt.test 1.0; MyQmlObject{objectName:"objectOne"}', obj); - } - - function createTwo() - { - var component = createComponent('dynamicCreation.helper.qml'); - obj.objectProperty = component.createObject(); - } - - function createThree() - { - obj.objectProperty = createQmlObject('TypeForDynamicCreation{}', obj); - } -} diff --git a/tests/auto/declarative/qmlecmascript/data/dynamicDeletion.qml b/tests/auto/declarative/qmlecmascript/data/dynamicDeletion.qml deleted file mode 100644 index 0855b29..0000000 --- a/tests/auto/declarative/qmlecmascript/data/dynamicDeletion.qml +++ /dev/null @@ -1,20 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject{ - id: obj - objectName: "obj" - function create() - { - obj.objectProperty = createQmlObject('import Qt.test 1.0; MyQmlObject{objectName:"emptyObject"}', obj); - } - - function killOther() - { - obj.objectProperty.destroy(500); - } - - function killMe() - { - obj.destroy();//Must not segfault - } -} diff --git a/tests/auto/declarative/qmlecmascript/data/enums.1.qml b/tests/auto/declarative/qmlecmascript/data/enums.1.qml deleted file mode 100644 index 6351823..0000000 --- a/tests/auto/declarative/qmlecmascript/data/enums.1.qml +++ /dev/null @@ -1,20 +0,0 @@ -import Qt.test 1.0 -import Qt.test 1.0 as Namespace - -MyQmlObject { - // Enums from non-namespaced type - property int a: MyQmlObject.EnumValue1 - property int b: MyQmlObject.EnumValue2 - property int c: MyQmlObject.EnumValue3 - property int d: MyQmlObject.EnumValue4 - - // Enums from namespaced type - property int e: Namespace.MyQmlObject.EnumValue1 - property int f: Namespace.MyQmlObject.EnumValue2 - property int g: Namespace.MyQmlObject.EnumValue3 - property int h: Namespace.MyQmlObject.EnumValue4 - - // Test that enums don't mask attached properties - property int i: MyQmlObject.value - property int j: Namespace.MyQmlObject.value -} diff --git a/tests/auto/declarative/qmlecmascript/data/enums.2.qml b/tests/auto/declarative/qmlecmascript/data/enums.2.qml deleted file mode 100644 index bdc672f..0000000 --- a/tests/auto/declarative/qmlecmascript/data/enums.2.qml +++ /dev/null @@ -1,8 +0,0 @@ -import Qt.test 1.0 -import Qt.test 1.0 as Namespace - -MyQmlObject { - property int a: MyQmlObject.EnumValue10 - property int b: Namespace.MyQmlObject.EnumValue10 -} - diff --git a/tests/auto/declarative/qmlecmascript/data/exceptionClearsOnReeval.qml b/tests/auto/declarative/qmlecmascript/data/exceptionClearsOnReeval.qml deleted file mode 100644 index a2f0d1a..0000000 --- a/tests/auto/declarative/qmlecmascript/data/exceptionClearsOnReeval.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - property bool test: objectProperty.objectProperty.trueProperty -} - diff --git a/tests/auto/declarative/qmlecmascript/data/exceptionProducesWarning.qml b/tests/auto/declarative/qmlecmascript/data/exceptionProducesWarning.qml deleted file mode 100644 index acc3163..0000000 --- a/tests/auto/declarative/qmlecmascript/data/exceptionProducesWarning.qml +++ /dev/null @@ -1,8 +0,0 @@ -import Qt 4.6 -import Qt.test 1.0 - -MyQmlObject { - Component.onCompleted: - { throw(new Error("JS exception")) } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/exceptionProducesWarning2.qml b/tests/auto/declarative/qmlecmascript/data/exceptionProducesWarning2.qml deleted file mode 100644 index 44e10c1..0000000 --- a/tests/auto/declarative/qmlecmascript/data/exceptionProducesWarning2.qml +++ /dev/null @@ -1,7 +0,0 @@ -import Qt 4.6 -import Qt.test 1.0 - -MyQmlObject { - value: { throw(new Error("JS exception")) } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/extendedObjectPropertyLookup.qml b/tests/auto/declarative/qmlecmascript/data/extendedObjectPropertyLookup.qml deleted file mode 100644 index 9a82ad1..0000000 --- a/tests/auto/declarative/qmlecmascript/data/extendedObjectPropertyLookup.qml +++ /dev/null @@ -1,8 +0,0 @@ -import Qt.test 1.0 -import Qt 4.6 - -QtObject { - property MyExtendedObject a; - a: MyExtendedObject { id: root } - property int b: Math.max(root.extendedProperty, 0) -} diff --git a/tests/auto/declarative/qmlecmascript/data/extensionObjects.qml b/tests/auto/declarative/qmlecmascript/data/extensionObjects.qml deleted file mode 100644 index a902312..0000000 --- a/tests/auto/declarative/qmlecmascript/data/extensionObjects.qml +++ /dev/null @@ -1,10 +0,0 @@ -import Qt.test 1.0 - -MyExtendedObject -{ - baseProperty: baseExtendedProperty - baseExtendedProperty: 13 - - coreProperty: extendedProperty - extendedProperty: 9 -} diff --git a/tests/auto/declarative/qmlecmascript/data/externalScript.1.qml b/tests/auto/declarative/qmlecmascript/data/externalScript.1.qml deleted file mode 100644 index 2ac7b6e..0000000 --- a/tests/auto/declarative/qmlecmascript/data/externalScript.1.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt 4.6 - -QtObject { - property int test: external_script_func(); - - Script { - // Single source as non-array literal - source: "externalScript.js" - } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/externalScript.2.js b/tests/auto/declarative/qmlecmascript/data/externalScript.2.js deleted file mode 100644 index 78c3a86..0000000 --- a/tests/auto/declarative/qmlecmascript/data/externalScript.2.js +++ /dev/null @@ -1,8 +0,0 @@ -function external_script_func2() { - return a; -} - -function is_a_undefined() { - return a == undefined; -} - diff --git a/tests/auto/declarative/qmlecmascript/data/externalScript.2.qml b/tests/auto/declarative/qmlecmascript/data/externalScript.2.qml deleted file mode 100644 index dec657c..0000000 --- a/tests/auto/declarative/qmlecmascript/data/externalScript.2.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt 4.6 - -QtObject { - property int test: external_script_func(); - - Script { - // Single source as array - source: [ "externalScript.js" ] - } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/externalScript.3.qml b/tests/auto/declarative/qmlecmascript/data/externalScript.3.qml deleted file mode 100644 index d7acf38..0000000 --- a/tests/auto/declarative/qmlecmascript/data/externalScript.3.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.6 - -QtObject { - property int test: external_script_func(); - property int test2: external_script_func2(); - property bool test3: is_a_undefined(); - - Script { - // Multiple script - source: [ "externalScript.js", "externalScript.2.js" ] - } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/externalScript.4.qml b/tests/auto/declarative/qmlecmascript/data/externalScript.4.qml deleted file mode 100644 index 16211aa..0000000 --- a/tests/auto/declarative/qmlecmascript/data/externalScript.4.qml +++ /dev/null @@ -1,15 +0,0 @@ -import Qt 4.6 - -QtObject { - property int test: external_script_func(); - property bool test2: is_a_undefined(); - - // Disconnected scripts - Script { - source: "externalScript.js" - } - - Script { - source: "externalScript.2.js" - } -} diff --git a/tests/auto/declarative/qmlecmascript/data/externalScript.js b/tests/auto/declarative/qmlecmascript/data/externalScript.js deleted file mode 100644 index 8928652..0000000 --- a/tests/auto/declarative/qmlecmascript/data/externalScript.js +++ /dev/null @@ -1,6 +0,0 @@ -var a = 92; - -function external_script_func() { - return a; -} - diff --git a/tests/auto/declarative/qmlecmascript/data/idShortcutInvalidates.1.qml b/tests/auto/declarative/qmlecmascript/data/idShortcutInvalidates.1.qml deleted file mode 100644 index 2db0fc6..0000000 --- a/tests/auto/declarative/qmlecmascript/data/idShortcutInvalidates.1.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt.test 1.0 -import Qt 4.6 - -MyQmlObject { - objectProperty: if(1) otherObject - - property var obj - - obj: QtObject { - id: otherObject - } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/idShortcutInvalidates.qml b/tests/auto/declarative/qmlecmascript/data/idShortcutInvalidates.qml deleted file mode 100644 index f66428d..0000000 --- a/tests/auto/declarative/qmlecmascript/data/idShortcutInvalidates.qml +++ /dev/null @@ -1,12 +0,0 @@ -import Qt.test 1.0 -import Qt 4.6 - -MyQmlObject { - objectProperty: otherObject - - property var obj - - obj: QtObject { - id: otherObject - } -} diff --git a/tests/auto/declarative/qmlecmascript/data/jsObject.qml b/tests/auto/declarative/qmlecmascript/data/jsObject.qml deleted file mode 100644 index 4128c92..0000000 --- a/tests/auto/declarative/qmlecmascript/data/jsObject.qml +++ /dev/null @@ -1,12 +0,0 @@ -import Qt 4.6 - -QtObject { - property int test - - Component.onCompleted: { - var o = new Object; - o.test = 92; - test = o.test; - } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/listProperties.qml b/tests/auto/declarative/qmlecmascript/data/listProperties.qml deleted file mode 100644 index 810f9b6..0000000 --- a/tests/auto/declarative/qmlecmascript/data/listProperties.qml +++ /dev/null @@ -1,27 +0,0 @@ -import Qt.test 1.0 -import Qt 4.6 - -MyQmlObject { - id: root - - objectListProperty: [ - QtObject { property int a: 10 }, - QtObject { property int a: 11 } - ] - - Script { - function calcTest1() { - var rv = 0; - for (var ii = 0; ii < root.objectListProperty.length; ++ii) { - rv += root.objectListProperty[ii].a; - } - return rv; - } - - } - - property int test1: calcTest1(); - property int test2: root.objectListProperty.length - property bool test3: root.objectListProperty[1] != undefined - property bool test4: root.objectListProperty[100] == undefined -} diff --git a/tests/auto/declarative/qmlecmascript/data/listToVariant.qml b/tests/auto/declarative/qmlecmascript/data/listToVariant.qml deleted file mode 100644 index 47f4e50..0000000 --- a/tests/auto/declarative/qmlecmascript/data/listToVariant.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt 4.6 - -QtObject { - property var test: children -} diff --git a/tests/auto/declarative/qmlecmascript/data/methods.1.qml b/tests/auto/declarative/qmlecmascript/data/methods.1.qml deleted file mode 100644 index 0bbee16..0000000 --- a/tests/auto/declarative/qmlecmascript/data/methods.1.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - id: myObject - onBasicSignal: myObject.methodNoArgs() -} diff --git a/tests/auto/declarative/qmlecmascript/data/methods.2.qml b/tests/auto/declarative/qmlecmascript/data/methods.2.qml deleted file mode 100644 index 9f0c6b1..0000000 --- a/tests/auto/declarative/qmlecmascript/data/methods.2.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - id: myObject - onBasicSignal: myObject.method(163) -} diff --git a/tests/auto/declarative/qmlecmascript/data/methods.3.qml b/tests/auto/declarative/qmlecmascript/data/methods.3.qml deleted file mode 100644 index 79efc50..0000000 --- a/tests/auto/declarative/qmlecmascript/data/methods.3.qml +++ /dev/null @@ -1,7 +0,0 @@ -import Qt 4.6 - -QtObject { - function testFunction() { return 19; } - - property int test: testFunction() -} diff --git a/tests/auto/declarative/qmlecmascript/data/methods.4.qml b/tests/auto/declarative/qmlecmascript/data/methods.4.qml deleted file mode 100644 index aac711c..0000000 --- a/tests/auto/declarative/qmlecmascript/data/methods.4.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt 4.6 - -MethodsObject { - function testFunction2() { return 17; } - function testFunction3() { return 16; } - - property int test: testFunction() - property int test2: testFunction2() - property int test3: testFunction3() -} - diff --git a/tests/auto/declarative/qmlecmascript/data/methods.5.qml b/tests/auto/declarative/qmlecmascript/data/methods.5.qml deleted file mode 100644 index 3d45b15..0000000 --- a/tests/auto/declarative/qmlecmascript/data/methods.5.qml +++ /dev/null @@ -1,9 +0,0 @@ -import Qt 4.6 - -Item { - property alias x: item.x - Item { id: item } - - function testFunction() { return 9; } - property int test: testFunction(); -} diff --git a/tests/auto/declarative/qmlecmascript/data/multiEngineObject.qml b/tests/auto/declarative/qmlecmascript/data/multiEngineObject.qml deleted file mode 100644 index 7da09e4..0000000 --- a/tests/auto/declarative/qmlecmascript/data/multiEngineObject.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt 4.6 - -QtObject { - property string test: thing.stringProperty -} diff --git a/tests/auto/declarative/qmlecmascript/data/nonExistantAttachedObject.qml b/tests/auto/declarative/qmlecmascript/data/nonExistantAttachedObject.qml deleted file mode 100644 index f9585db..0000000 --- a/tests/auto/declarative/qmlecmascript/data/nonExistantAttachedObject.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - stringProperty: MyQmlContainer.prop -} diff --git a/tests/auto/declarative/qmlecmascript/data/objectsCompareAsEqual.qml b/tests/auto/declarative/qmlecmascript/data/objectsCompareAsEqual.qml deleted file mode 100644 index 18e488a..0000000 --- a/tests/auto/declarative/qmlecmascript/data/objectsCompareAsEqual.qml +++ /dev/null @@ -1,15 +0,0 @@ -import Qt 4.6 - -Item { - id: root - - property var item: child - Item { id: child } - - property bool test1: child == child - property bool test2: child.parent == root - property bool test3: root != child - property bool test4: item == child - property bool test5: item != root -} - diff --git a/tests/auto/declarative/qmlecmascript/data/outerBindingOverridesInnerBinding.qml b/tests/auto/declarative/qmlecmascript/data/outerBindingOverridesInnerBinding.qml deleted file mode 100644 index 0a933e8..0000000 --- a/tests/auto/declarative/qmlecmascript/data/outerBindingOverridesInnerBinding.qml +++ /dev/null @@ -1,14 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - property alias c1: myConstants.c1 - property alias c2: myConstants.c2 - property int c3: 0 - - objectProperty: ConstantsOverrideBindings { - id: myConstants - c2: c3 - } - -} - diff --git a/tests/auto/declarative/qmlecmascript/data/qmlToString.qml b/tests/auto/declarative/qmlecmascript/data/qmlToString.qml deleted file mode 100644 index ac296ce..0000000 --- a/tests/auto/declarative/qmlecmascript/data/qmlToString.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject{ - id: obj - objectName: "objName" - function testToString() - { - obj.stringProperty = obj.toString(); - } - -} diff --git a/tests/auto/declarative/qmlecmascript/data/scope.2.qml b/tests/auto/declarative/qmlecmascript/data/scope.2.qml deleted file mode 100644 index 8e5aa0b..0000000 --- a/tests/auto/declarative/qmlecmascript/data/scope.2.qml +++ /dev/null @@ -1,42 +0,0 @@ -import Qt 4.6 - -Item { - property int a: 0 - property int b: 0 - - Script { - function b() { return 11; } - function c() { return 33; } - } - - QtObject { - id: a - property int value: 19 - } - - QtObject { - id: c - property int value: 24 - } - - QtObject { - id: nested - property int a: 1 - property int test: a.value - property int test2: b() - property int test3: c.value - } - - - // id takes precedence over local, and root properties - property int test1: a.value - property alias test2: nested.test - - // methods takes precedence over local, and root properties - property int test3: b() - property alias test4: nested.test2 - - // id takes precedence over methods - property int test5: c.value - property alias test6: nested.test3 -} diff --git a/tests/auto/declarative/qmlecmascript/data/scope.qml b/tests/auto/declarative/qmlecmascript/data/scope.qml deleted file mode 100644 index cccd3d3..0000000 --- a/tests/auto/declarative/qmlecmascript/data/scope.qml +++ /dev/null @@ -1,48 +0,0 @@ -import Qt 4.6 - -Item { - id: root - - property int a: 1 - property int binding: a - property string binding2: a + "Test" - property int binding3: myFunction() - property int binding4: myNestedFunction() - - Script { - function myFunction() { - return a; - } - } - - Item { - id: nestedObject - - Script { - function myNestedFunction() { - return a; - } - } - - property int a: 2 - property int binding: a - property string binding2: a + "Test" - property int binding3: myFunction() - property int binding4: myNestedFunction() - } - - ScopeObject { - id: compObject - } - - property alias test1: root.binding - property alias test2: nestedObject.binding - property alias test3: root.binding2 - property alias test4: nestedObject.binding2 - property alias test5: root.binding3 - property alias test6: nestedObject.binding3 - property alias test7: root.binding4 - property alias test8: nestedObject.binding4 - property alias test9: compObject.binding - property alias test10: compObject.binding2 -} diff --git a/tests/auto/declarative/qmlecmascript/data/scriptAccess.js b/tests/auto/declarative/qmlecmascript/data/scriptAccess.js deleted file mode 100644 index c00d285..0000000 --- a/tests/auto/declarative/qmlecmascript/data/scriptAccess.js +++ /dev/null @@ -1,7 +0,0 @@ -var extVariable = 19; - -function extMethod() -{ - return extVariable; -} - diff --git a/tests/auto/declarative/qmlecmascript/data/scriptAccess.qml b/tests/auto/declarative/qmlecmascript/data/scriptAccess.qml deleted file mode 100644 index feb6d16..0000000 --- a/tests/auto/declarative/qmlecmascript/data/scriptAccess.qml +++ /dev/null @@ -1,17 +0,0 @@ -import Qt 4.6 - -Item { - Script { - function method() { - return 10; - } - } - - Script { - source: "scriptAccess.js" - } - - property int test1: method() - property int test2: extMethod() - property int test3: extVariable -} diff --git a/tests/auto/declarative/qmlecmascript/data/scriptErrors.js b/tests/auto/declarative/qmlecmascript/data/scriptErrors.js deleted file mode 100644 index 1d7b357..0000000 --- a/tests/auto/declarative/qmlecmascript/data/scriptErrors.js +++ /dev/null @@ -1,2 +0,0 @@ -// Comment -a = 10 diff --git a/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml b/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml deleted file mode 100644 index c2edb41..0000000 --- a/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml +++ /dev/null @@ -1,17 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - Script { source: "scriptErrors.js" } - Script { function getValue() { a = 10; return 0; } } - - property int t: a.value - property int w: getValue(); - property int x: undefinedObject - property int y: (a.value, undefinedObject) - - onBasicSignal: { console.log(a.value); } - id: myObj - onAnotherBasicSignal: myObj.trueProperty = false; - onThirdBasicSignal: myObj.fakeProperty = ""; -} - diff --git a/tests/auto/declarative/qmlecmascript/data/selfDeletingBinding.2.qml b/tests/auto/declarative/qmlecmascript/data/selfDeletingBinding.2.qml deleted file mode 100644 index 58cf805..0000000 --- a/tests/auto/declarative/qmlecmascript/data/selfDeletingBinding.2.qml +++ /dev/null @@ -1,17 +0,0 @@ -import Qt.test 1.0 - -MyQmlContainer { - property bool triggerDelete: false - - children: [ - MyQmlObject { - // Will trigger deletion on binding assignment - deleteOnSet: Math.max(0, 1) - }, - - MyQmlObject { - // Will trigger deletion on binding assignment, but after component creation - deleteOnSet: if (triggerDelete) 1; else 0; - } - ] -} diff --git a/tests/auto/declarative/qmlecmascript/data/selfDeletingBinding.qml b/tests/auto/declarative/qmlecmascript/data/selfDeletingBinding.qml deleted file mode 100644 index 074851a..0000000 --- a/tests/auto/declarative/qmlecmascript/data/selfDeletingBinding.qml +++ /dev/null @@ -1,18 +0,0 @@ -import Qt.test 1.0 - -MyQmlContainer { - property bool triggerDelete: false - - children: [ - MyQmlObject { - // Will trigger deletion during binding evaluation - stringProperty: {deleteMe(), "Hello"} - }, - - MyQmlObject { - // Will trigger deletion during binding evaluation, but after component creation - stringProperty: if (triggerDelete) { deleteMe(), "Hello" } else { "World" } - } - - ] -} diff --git a/tests/auto/declarative/qmlecmascript/data/shutdownErrors.qml b/tests/auto/declarative/qmlecmascript/data/shutdownErrors.qml deleted file mode 100644 index 5a19639..0000000 --- a/tests/auto/declarative/qmlecmascript/data/shutdownErrors.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.6 - -Item { - property int test: myObject.object.a - - Item { - id: myObject - property QtObject object; - object: QtObject { - property int a: 10 - } - } -} diff --git a/tests/auto/declarative/qmlecmascript/data/signalAssignment.1.qml b/tests/auto/declarative/qmlecmascript/data/signalAssignment.1.qml deleted file mode 100644 index fbd0914..0000000 --- a/tests/auto/declarative/qmlecmascript/data/signalAssignment.1.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - onBasicSignal: setString('pass') -} diff --git a/tests/auto/declarative/qmlecmascript/data/signalAssignment.2.qml b/tests/auto/declarative/qmlecmascript/data/signalAssignment.2.qml deleted file mode 100644 index 8addcb9..0000000 --- a/tests/auto/declarative/qmlecmascript/data/signalAssignment.2.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - onArgumentSignal: setString('pass ' + a + ' ' + b + ' ' + c) -} diff --git a/tests/auto/declarative/qmlecmascript/data/signalParameterTypes.qml b/tests/auto/declarative/qmlecmascript/data/signalParameterTypes.qml deleted file mode 100644 index 6fc8b02..0000000 --- a/tests/auto/declarative/qmlecmascript/data/signalParameterTypes.qml +++ /dev/null @@ -1,16 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject -{ - id: root - property int intProperty - property real realProperty - property color colorProperty - property var variantProperty - - signal mySignal(int a, real b, color c, var d) - - onMySignal: { intProperty = a; realProperty = b; colorProperty = c; variantProperty = d; } - - onBasicSignal: root.mySignal(10, 19.2, Qt.rgba(1, 1, 0, 1), Qt.rgba(1, 0, 1, 1)) -} diff --git a/tests/auto/declarative/qmlecmascript/data/signalTriggeredBindings.qml b/tests/auto/declarative/qmlecmascript/data/signalTriggeredBindings.qml deleted file mode 100644 index 7d419cd..0000000 --- a/tests/auto/declarative/qmlecmascript/data/signalTriggeredBindings.qml +++ /dev/null @@ -1,20 +0,0 @@ -import Qt.test 1.0 -import Qt 4.6 - -MyQmlObject { - property real base: 50 - property alias test1: myObject.test1 - property alias test2: myObject.test2 - - objectProperty: QtObject { - id: myObject - property real test1: base - property real test2: Math.max(0, base) - } - - // Signal with no args - onBasicSignal: base = 200 - // Signal with args - onArgumentSignal: base = 400 -} - diff --git a/tests/auto/declarative/qmlecmascript/data/transientErrors.qml b/tests/auto/declarative/qmlecmascript/data/transientErrors.qml deleted file mode 100644 index fa7e01c..0000000 --- a/tests/auto/declarative/qmlecmascript/data/transientErrors.qml +++ /dev/null @@ -1,10 +0,0 @@ -import Qt 4.6 - -QtObject { - property var obj: nested - - property var obj2 - obj2: NestedTypeTransientErrors { - id: nested - } -} diff --git a/tests/auto/declarative/qmlecmascript/data/undefinedResetsProperty.2.qml b/tests/auto/declarative/qmlecmascript/data/undefinedResetsProperty.2.qml deleted file mode 100644 index e73d38e2..0000000 --- a/tests/auto/declarative/qmlecmascript/data/undefinedResetsProperty.2.qml +++ /dev/null @@ -1,10 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - resettableProperty: 19 - - function doReset() { - resettableProperty = undefined; - } -} - diff --git a/tests/auto/declarative/qmlecmascript/data/undefinedResetsProperty.qml b/tests/auto/declarative/qmlecmascript/data/undefinedResetsProperty.qml deleted file mode 100644 index eceff60..0000000 --- a/tests/auto/declarative/qmlecmascript/data/undefinedResetsProperty.qml +++ /dev/null @@ -1,7 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject { - property bool setUndefined: false - - resettableProperty: setUndefined?undefined:92 -} diff --git a/tests/auto/declarative/qmlecmascript/data/valueTypeFunctions.qml b/tests/auto/declarative/qmlecmascript/data/valueTypeFunctions.qml deleted file mode 100644 index 33b4a68..0000000 --- a/tests/auto/declarative/qmlecmascript/data/valueTypeFunctions.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt.test 1.0 - -MyTypeObject { - rectProperty: Qt.rect(0,0,100,100) - rectFProperty: Qt.rect(0,0.5,100,99.5) -} diff --git a/tests/auto/declarative/qmlecmascript/qmlecmascript.pro b/tests/auto/declarative/qmlecmascript/qmlecmascript.pro deleted file mode 100644 index 9f592e8..0000000 --- a/tests/auto/declarative/qmlecmascript/qmlecmascript.pro +++ /dev/null @@ -1,10 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative script -macx:CONFIG -= app_bundle - -SOURCES += tst_qmlecmascript.cpp \ - testtypes.cpp -HEADERS += testtypes.h - -# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -# LIBS += -lgcov diff --git a/tests/auto/declarative/qmlecmascript/testtypes.cpp b/tests/auto/declarative/qmlecmascript/testtypes.cpp deleted file mode 100644 index 6a04704..0000000 --- a/tests/auto/declarative/qmlecmascript/testtypes.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "testtypes.h" - -class BaseExtensionObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(int baseExtendedProperty READ extendedProperty WRITE setExtendedProperty NOTIFY extendedPropertyChanged); -public: - BaseExtensionObject(QObject *parent) : QObject(parent), m_value(0) {} - - int extendedProperty() const { return m_value; } - void setExtendedProperty(int v) { m_value = v; emit extendedPropertyChanged(); } - -signals: - void extendedPropertyChanged(); -private: - int m_value; -}; - -class ExtensionObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(int extendedProperty READ extendedProperty WRITE setExtendedProperty NOTIFY extendedPropertyChanged); -public: - ExtensionObject(QObject *parent) : QObject(parent), m_value(0) {} - - int extendedProperty() const { return m_value; } - void setExtendedProperty(int v) { m_value = v; emit extendedPropertyChanged(); } - -signals: - void extendedPropertyChanged(); -private: - int m_value; -}; - -void registerTypes() -{ - QML_REGISTER_TYPE(Qt.test, 1,0, MyQmlObject,MyQmlObject); - QML_REGISTER_TYPE(Qt.test, 1,0, MyDeferredObject,MyDeferredObject); - QML_REGISTER_TYPE(Qt.test, 1,0, MyQmlContainer,MyQmlContainer); - QML_REGISTER_EXTENDED_TYPE(Qt.test, 1,0, MyBaseExtendedObject,MyBaseExtendedObject,BaseExtensionObject); - QML_REGISTER_EXTENDED_TYPE(Qt.test, 1,0, MyExtendedObject,MyExtendedObject,ExtensionObject); - QML_REGISTER_TYPE(Qt.test, 1,0, MyTypeObject, MyTypeObject); -} - -#include "testtypes.moc" diff --git a/tests/auto/declarative/qmlecmascript/testtypes.h b/tests/auto/declarative/qmlecmascript/testtypes.h deleted file mode 100644 index 9d7d0a7..0000000 --- a/tests/auto/declarative/qmlecmascript/testtypes.h +++ /dev/null @@ -1,598 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef TESTTYPES_H -#define TESTTYPES_H - -#include <QtCore/qobject.h> -#include <QtDeclarative/qml.h> -#include <QtDeclarative/qmlexpression.h> -#include <QtCore/qpoint.h> -#include <QtCore/qsize.h> -#include <QtDeclarative/qmllist.h> -#include <QtCore/qrect.h> -#include <QtGui/qmatrix.h> -#include <QtGui/qcolor.h> -#include <QtGui/qvector3d.h> -#include <QtCore/qdatetime.h> -#include <QtScript/qscriptvalue.h> -#include <QtDeclarative/qmlscriptstring.h> -#include <QtDeclarative/qmlcomponent.h> - -class MyQmlAttachedObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(int value READ value CONSTANT) -public: - MyQmlAttachedObject(QObject *parent) : QObject(parent) {} - - int value() const { return 19; } -}; - -class MyQmlObject : public QObject -{ - Q_OBJECT - Q_ENUMS(MyEnum) - Q_ENUMS(MyEnum2) - Q_PROPERTY(int deleteOnSet READ deleteOnSet WRITE setDeleteOnSet) - Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT) - Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT) - Q_PROPERTY(int value READ value WRITE setValue) - Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged) - Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged) - Q_PROPERTY(QmlListProperty<QObject> objectListProperty READ objectListProperty CONSTANT) - Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty) - -public: - MyQmlObject(): m_methodCalled(false), m_methodIntCalled(false), m_object(0), m_value(0), m_resetProperty(13) {} - - enum MyEnum { EnumValue1 = 0, EnumValue2 = 1 }; - enum MyEnum2 { EnumValue3 = 2, EnumValue4 = 3 }; - - bool trueProperty() const { return true; } - bool falseProperty() const { return false; } - - QString stringProperty() const { return m_string; } - void setStringProperty(const QString &s) - { - if (s == m_string) - return; - m_string = s; - emit stringChanged(); - } - - QObject *objectProperty() const { return m_object; } - void setObjectProperty(QObject *obj) { - if (obj == m_object) - return; - m_object = obj; - emit objectChanged(); - } - - QmlListProperty<QObject> objectListProperty() { return QmlListProperty<QObject>(this, m_objectQList); } - - bool methodCalled() const { return m_methodCalled; } - bool methodIntCalled() const { return m_methodIntCalled; } - - QString string() const { return m_string; } - - static MyQmlAttachedObject *qmlAttachedProperties(QObject *o) { - return new MyQmlAttachedObject(o); - } - - int deleteOnSet() const { return 1; } - void setDeleteOnSet(int v) { if(v) delete this; } - - int value() const { return m_value; } - void setValue(int v) { m_value = v; } - - int resettableProperty() const { return m_resetProperty; } - void setResettableProperty(int v) { m_resetProperty = v; } - void resetProperty() { m_resetProperty = 13; } - -signals: - void basicSignal(); - void argumentSignal(int a, QString b, qreal c); - void stringChanged(); - void objectChanged(); - void anotherBasicSignal(); - void thirdBasicSignal(); - -public slots: - void deleteMe() { delete this; } - void methodNoArgs() { m_methodCalled = true; } - void method(int a) { if(a == 163) m_methodIntCalled = true; } - void setString(const QString &s) { m_string = s; } - -private: - friend class tst_qmlecmascript; - bool m_methodCalled; - bool m_methodIntCalled; - - QObject *m_object; - QString m_string; - QList<QObject *> m_objectQList; - int m_value; - int m_resetProperty; -}; - -QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(MyQmlObject); - -class MyQmlContainer : public QObject -{ - Q_OBJECT - Q_PROPERTY(QmlListProperty<MyQmlObject> children READ children CONSTANT) -public: - MyQmlContainer() {} - - QmlListProperty<MyQmlObject> children() { return QmlListProperty<MyQmlObject>(this, m_children); } - -private: - QList<MyQmlObject*> m_children; -}; - -QML_DECLARE_TYPE(MyQmlContainer); - -class MyExpression : public QmlExpression -{ - Q_OBJECT -public: - MyExpression(QmlContext *ctxt, const QString &expr) - : QmlExpression(ctxt, expr, 0), changed(false) - { - QObject::connect(this, SIGNAL(valueChanged()), this, SLOT(expressionValueChanged())); - setNotifyOnValueChanged(true); - } - - bool changed; - -public slots: - void expressionValueChanged() { - changed = true; - } -}; - - -class MyDefaultObject1 : public QObject -{ - Q_OBJECT - Q_PROPERTY(int horseLegs READ horseLegs CONSTANT); - Q_PROPERTY(int antLegs READ antLegs CONSTANT); -public: - int horseLegs() const { return 4; } - int antLegs() const { return 6; } -}; - -class MyDefaultObject2 : public QObject -{ - Q_OBJECT - Q_PROPERTY(int antLegs READ antLegs CONSTANT); - Q_PROPERTY(int emuLegs READ emuLegs CONSTANT); -public: - int antLegs() const { return 5; } // Had an accident - int emuLegs() const { return 2; } -}; - -class MyDefaultObject3 : public QObject -{ - Q_OBJECT - Q_PROPERTY(int antLegs READ antLegs CONSTANT); - Q_PROPERTY(int humanLegs READ humanLegs CONSTANT); -public: - int antLegs() const { return 7; } // Mutant - int humanLegs() const { return 2; } - int millipedeLegs() const { return 1000; } -}; - -class MyDeferredObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged) - Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty); - Q_PROPERTY(QObject *objectProperty2 READ objectProperty2 WRITE setObjectProperty2); - Q_CLASSINFO("DeferredPropertyNames", "value,objectProperty,objectProperty2"); - -public: - MyDeferredObject() : m_value(0), m_object(0), m_object2(0) {} - - int value() const { return m_value; } - void setValue(int v) { m_value = v; emit valueChanged(); } - - QObject *objectProperty() const { return m_object; } - void setObjectProperty(QObject *obj) { m_object = obj; } - - QObject *objectProperty2() const { return m_object2; } - void setObjectProperty2(QObject *obj) { m_object2 = obj; } - -signals: - void valueChanged(); - -private: - int m_value; - QObject *m_object; - QObject *m_object2; -}; -QML_DECLARE_TYPE(MyDeferredObject); - -class MyBaseExtendedObject : public QObject -{ -Q_OBJECT -Q_PROPERTY(int baseProperty READ baseProperty WRITE setBaseProperty); -public: - MyBaseExtendedObject() : m_value(0) {} - - int baseProperty() const { return m_value; } - void setBaseProperty(int v) { m_value = v; } - -private: - int m_value; -}; -QML_DECLARE_TYPE(MyBaseExtendedObject); - -class MyExtendedObject : public MyBaseExtendedObject -{ -Q_OBJECT -Q_PROPERTY(int coreProperty READ coreProperty WRITE setCoreProperty); -public: - MyExtendedObject() : m_value(0) {} - - int coreProperty() const { return m_value; } - void setCoreProperty(int v) { m_value = v; } - -private: - int m_value; -}; -QML_DECLARE_TYPE(MyExtendedObject); - -class MyTypeObject : public QObject -{ - Q_OBJECT - Q_ENUMS(MyEnum) - Q_FLAGS(MyFlags) - - Q_PROPERTY(QString id READ id WRITE setId); - Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty); - Q_PROPERTY(QmlComponent *componentProperty READ componentProperty WRITE setComponentProperty); - Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty); - Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty); - Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty); - Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty); - Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty); - Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty); - Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty); - Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty); - Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty); - Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty); - Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty); - Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty); - Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty); - Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty); - Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty); - Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty); - Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged); - Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2); - Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty); - Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty); - Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty); - Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty); - Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty); - - Q_PROPERTY(QmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty); - -public: - MyTypeObject() - : objectPropertyValue(0), componentPropertyValue(0) {} - - QString idValue; - QString id() const { - return idValue; - } - void setId(const QString &v) { - idValue = v; - } - - QObject *objectPropertyValue; - QObject *objectProperty() const { - return objectPropertyValue; - } - void setObjectProperty(QObject *v) { - objectPropertyValue = v; - } - - QmlComponent *componentPropertyValue; - QmlComponent *componentProperty() const { - return componentPropertyValue; - } - void setComponentProperty(QmlComponent *v) { - componentPropertyValue = v; - } - - enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 }; - Q_DECLARE_FLAGS(MyFlags, MyFlag) - MyFlags flagPropertyValue; - MyFlags flagProperty() const { - return flagPropertyValue; - } - void setFlagProperty(MyFlags v) { - flagPropertyValue = v; - } - - enum MyEnum { EnumVal1, EnumVal2 }; - MyEnum enumPropertyValue; - MyEnum enumProperty() const { - return enumPropertyValue; - } - void setEnumProperty(MyEnum v) { - enumPropertyValue = v; - } - - QString stringPropertyValue; - QString stringProperty() const { - return stringPropertyValue; - } - void setStringProperty(const QString &v) { - stringPropertyValue = v; - } - - uint uintPropertyValue; - uint uintProperty() const { - return uintPropertyValue; - } - void setUintProperty(const uint &v) { - uintPropertyValue = v; - } - - int intPropertyValue; - int intProperty() const { - return intPropertyValue; - } - void setIntProperty(const int &v) { - intPropertyValue = v; - } - - qreal realPropertyValue; - qreal realProperty() const { - return realPropertyValue; - } - void setRealProperty(const qreal &v) { - realPropertyValue = v; - } - - double doublePropertyValue; - double doubleProperty() const { - return doublePropertyValue; - } - void setDoubleProperty(const double &v) { - doublePropertyValue = v; - } - - float floatPropertyValue; - float floatProperty() const { - return floatPropertyValue; - } - void setFloatProperty(const float &v) { - floatPropertyValue = v; - } - - QColor colorPropertyValue; - QColor colorProperty() const { - return colorPropertyValue; - } - void setColorProperty(const QColor &v) { - colorPropertyValue = v; - } - - QDate datePropertyValue; - QDate dateProperty() const { - return datePropertyValue; - } - void setDateProperty(const QDate &v) { - datePropertyValue = v; - } - - QTime timePropertyValue; - QTime timeProperty() const { - return timePropertyValue; - } - void setTimeProperty(const QTime &v) { - timePropertyValue = v; - } - - QDateTime dateTimePropertyValue; - QDateTime dateTimeProperty() const { - return dateTimePropertyValue; - } - void setDateTimeProperty(const QDateTime &v) { - dateTimePropertyValue = v; - } - - QPoint pointPropertyValue; - QPoint pointProperty() const { - return pointPropertyValue; - } - void setPointProperty(const QPoint &v) { - pointPropertyValue = v; - } - - QPointF pointFPropertyValue; - QPointF pointFProperty() const { - return pointFPropertyValue; - } - void setPointFProperty(const QPointF &v) { - pointFPropertyValue = v; - } - - QSize sizePropertyValue; - QSize sizeProperty() const { - return sizePropertyValue; - } - void setSizeProperty(const QSize &v) { - sizePropertyValue = v; - } - - QSizeF sizeFPropertyValue; - QSizeF sizeFProperty() const { - return sizeFPropertyValue; - } - void setSizeFProperty(const QSizeF &v) { - sizeFPropertyValue = v; - } - - QRect rectPropertyValue; - QRect rectProperty() const { - return rectPropertyValue; - } - void setRectProperty(const QRect &v) { - rectPropertyValue = v; - emit rectPropertyChanged(); - } - - QRect rectPropertyValue2; - QRect rectProperty2() const { - return rectPropertyValue2; - } - void setRectProperty2(const QRect &v) { - rectPropertyValue2 = v; - } - - QRectF rectFPropertyValue; - QRectF rectFProperty() const { - return rectFPropertyValue; - } - void setRectFProperty(const QRectF &v) { - rectFPropertyValue = v; - } - - bool boolPropertyValue; - bool boolProperty() const { - return boolPropertyValue; - } - void setBoolProperty(const bool &v) { - boolPropertyValue = v; - } - - QVariant variantPropertyValue; - QVariant variantProperty() const { - return variantPropertyValue; - } - void setVariantProperty(const QVariant &v) { - variantPropertyValue = v; - } - - QVector3D vectorPropertyValue; - QVector3D vectorProperty() const { - return vectorPropertyValue; - } - void setVectorProperty(const QVector3D &v) { - vectorPropertyValue = v; - } - - QUrl urlPropertyValue; - QUrl urlProperty() const { - return urlPropertyValue; - } - void setUrlProperty(const QUrl &v) { - urlPropertyValue = v; - } - - QmlScriptString scriptPropertyValue; - QmlScriptString scriptProperty() const { - return scriptPropertyValue; - } - void setScriptProperty(const QmlScriptString &v) { - scriptPropertyValue = v; - } - - void doAction() { emit action(); } -signals: - void action(); - void rectPropertyChanged(); -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags) -QML_DECLARE_TYPE(MyTypeObject); - -Q_DECLARE_METATYPE(QScriptValue); -class MyInvokableObject : public QObject -{ - Q_OBJECT -public: - MyInvokableObject() { reset(); } - - int invoked() const { return m_invoked; } - bool error() const { return m_invokedError; } - const QVariantList &actuals() const { return m_actuals; } - void reset() { m_invoked = -1; m_invokedError = false; m_actuals.clear(); } - - Q_INVOKABLE QPointF method_get_QPointF() { return QPointF(99.3, -10.2); } - Q_INVOKABLE QPoint method_get_QPoint() { return QPoint(9, 12); } - - Q_INVOKABLE void method_NoArgs() { invoke(0); } - Q_INVOKABLE int method_NoArgs_int() { invoke(1); return 6; } - Q_INVOKABLE qreal method_NoArgs_real() { invoke(2); return 19.7; } - Q_INVOKABLE QPointF method_NoArgs_QPointF() { invoke(3); return QPointF(123, 4.5); } - Q_INVOKABLE QObject *method_NoArgs_QObject() { invoke(4); return this; } - Q_INVOKABLE MyInvokableObject *method_NoArgs_unknown() { invoke(5); return this; } - Q_INVOKABLE QScriptValue method_NoArgs_QScriptValue() { invoke(6); return QScriptValue("Hello world"); } - Q_INVOKABLE QVariant method_NoArgs_QVariant() { invoke(7); return QVariant("QML rocks"); } - - Q_INVOKABLE void method_int(int a) { invoke(8); m_actuals << a; } - Q_INVOKABLE void method_intint(int a, int b) { invoke(9); m_actuals << a << b; } - Q_INVOKABLE void method_real(qreal a) { invoke(10); m_actuals << a; } - Q_INVOKABLE void method_QString(QString a) { invoke(11); m_actuals << a; } - Q_INVOKABLE void method_QPointF(QPointF a) { invoke(12); m_actuals << a; } - Q_INVOKABLE void method_QObject(QObject *a) { invoke(13); m_actuals << qVariantFromValue(a); } - Q_INVOKABLE void method_QScriptValue(QScriptValue a) { invoke(14); m_actuals << qVariantFromValue(a); } - Q_INVOKABLE void method_intQScriptValue(int a, QScriptValue b) { invoke(15); m_actuals << a << qVariantFromValue(b); } - - Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; } - Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; } - -private: - void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;} - int m_invoked; - bool m_invokedError; - QVariantList m_actuals; -}; - -void registerTypes(); - -#endif // TESTTYPES_H - diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp deleted file mode 100644 index 88f06ad..0000000 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ /dev/null @@ -1,1662 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <qtest.h> -#include <QtDeclarative/qmlcomponent.h> -#include <QtDeclarative/qmlengine.h> -#include <QtDeclarative/qmlexpression.h> -#include <QtDeclarative/qmlcontext.h> -#include <QtCore/qfileinfo.h> -#include <QtCore/qdebug.h> -#include <QtDeclarative/private/qmlguard_p.h> -#include <QtCore/qdir.h> -#include <QtCore/qnumeric.h> -#include <private/qmlengine_p.h> -#include <private/qmlglobalscriptclass_p.h> -#include "testtypes.h" - -/* -This test covers evaluation of ECMAScript expressions and bindings from within -QML. This does not include static QML language issues. - -Static QML language issues are covered in qmllanguage -*/ -inline QUrl TEST_FILE(const QString &filename) -{ - QFileInfo fileInfo(__FILE__); - return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath("data/" + filename)); -} - -inline QUrl TEST_FILE(const char *filename) -{ - return TEST_FILE(QLatin1String(filename)); -} - -class tst_qmlecmascript : public QObject -{ - Q_OBJECT -public: - tst_qmlecmascript() {} - -private slots: - void initTestCase(); - void assignBasicTypes(); - void idShortcutInvalidates(); - void boolPropertiesEvaluateAsBool(); - void methods(); - void signalAssignment(); - void bindingLoop(); - void basicExpressions(); - void basicExpressions_data(); - void arrayExpressions(); - void contextPropertiesTriggerReeval(); - void objectPropertiesTriggerReeval(); - void deferredProperties(); - void extensionObjects(); - void attachedProperties(); - void enums(); - void valueTypeFunctions(); - void constantsOverrideBindings(); - void outerBindingOverridesInnerBinding(); - void aliasPropertyAndBinding(); - void nonExistantAttachedObject(); - void scope(); - void signalParameterTypes(); - void objectsCompareAsEqual(); - void scriptAccess(); - void dynamicCreation_data(); - void dynamicCreation(); - void dynamicDestruction(); - void objectToString(); - void selfDeletingBinding(); - void extendedObjectPropertyLookup(); - void scriptErrors(); - void signalTriggeredBindings(); - void listProperties(); - void exceptionClearsOnReeval(); - void exceptionSlotProducesWarning(); - void exceptionBindingProducesWarning(); - void transientErrors(); - void shutdownErrors(); - void externalScript(); - void compositePropertyType(); - void jsObject(); - void undefinedResetsProperty(); - void listToVariant(); - void multiEngineObject(); - void deletedObject(); - - void bug1(); - - void callQtInvokables(); -private: - QmlEngine engine; -}; - -void tst_qmlecmascript::initTestCase() { registerTypes(); } - -void tst_qmlecmascript::assignBasicTypes() -{ - { - QmlComponent component(&engine, TEST_FILE("assignBasicTypes.qml")); - MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3); - QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2); - QCOMPARE(object->stringProperty(), QString("Hello World!")); - QCOMPARE(object->uintProperty(), uint(10)); - QCOMPARE(object->intProperty(), -19); - QCOMPARE((float)object->realProperty(), float(23.2)); - QCOMPARE((float)object->doubleProperty(), float(-19.7)); - QCOMPARE((float)object->floatProperty(), float(8.5)); - QCOMPARE(object->colorProperty(), QColor("red")); - QCOMPARE(object->dateProperty(), QDate(1982, 11, 25)); - QCOMPARE(object->timeProperty(), QTime(11, 11, 32)); - QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1))); - QCOMPARE(object->pointProperty(), QPoint(99,13)); - QCOMPARE(object->pointFProperty(), QPointF(-10.1, 12.3)); - QCOMPARE(object->sizeProperty(), QSize(99, 13)); - QCOMPARE(object->sizeFProperty(), QSizeF(0.1, 0.2)); - QCOMPARE(object->rectProperty(), QRect(9, 7, 100, 200)); - QCOMPARE(object->rectFProperty(), QRectF(1000.1, -10.9, 400, 90.99)); - QCOMPARE(object->boolProperty(), true); - QCOMPARE(object->variantProperty(), QVariant("Hello World!")); - QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2)); - QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml"))); - delete object; - } - { - QmlComponent component(&engine, TEST_FILE("assignBasicTypes.2.qml")); - MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3); - QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2); - QCOMPARE(object->stringProperty(), QString("Hello World!")); - QCOMPARE(object->uintProperty(), uint(10)); - QCOMPARE(object->intProperty(), -19); - QCOMPARE((float)object->realProperty(), float(23.2)); - QCOMPARE((float)object->doubleProperty(), float(-19.7)); - QCOMPARE((float)object->floatProperty(), float(8.5)); - QCOMPARE(object->colorProperty(), QColor("red")); - QCOMPARE(object->dateProperty(), QDate(1982, 11, 25)); - QCOMPARE(object->timeProperty(), QTime(11, 11, 32)); - QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1))); - QCOMPARE(object->pointProperty(), QPoint(99,13)); - QCOMPARE(object->pointFProperty(), QPointF(-10.1, 12.3)); - QCOMPARE(object->sizeProperty(), QSize(99, 13)); - QCOMPARE(object->sizeFProperty(), QSizeF(0.1, 0.2)); - QCOMPARE(object->rectProperty(), QRect(9, 7, 100, 200)); - QCOMPARE(object->rectFProperty(), QRectF(1000.1, -10.9, 400, 90.99)); - QCOMPARE(object->boolProperty(), true); - QCOMPARE(object->variantProperty(), QVariant("Hello World!")); - QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2)); - QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml"))); - delete object; - } -} - -void tst_qmlecmascript::idShortcutInvalidates() -{ - { - QmlComponent component(&engine, TEST_FILE("idShortcutInvalidates.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - QVERIFY(object->objectProperty() != 0); - delete object->objectProperty(); - QVERIFY(object->objectProperty() == 0); - } - - { - QmlComponent component(&engine, TEST_FILE("idShortcutInvalidates.1.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - QVERIFY(object->objectProperty() != 0); - delete object->objectProperty(); - QVERIFY(object->objectProperty() == 0); - } -} - -void tst_qmlecmascript::boolPropertiesEvaluateAsBool() -{ - { - QmlComponent component(&engine, TEST_FILE("boolPropertiesEvaluateAsBool.1.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->stringProperty(), QLatin1String("pass")); - } - { - QmlComponent component(&engine, TEST_FILE("boolPropertiesEvaluateAsBool.2.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->stringProperty(), QLatin1String("pass")); - } -} - -void tst_qmlecmascript::signalAssignment() -{ - { - QmlComponent component(&engine, TEST_FILE("signalAssignment.1.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->string(), QString()); - emit object->basicSignal(); - QCOMPARE(object->string(), QString("pass")); - } - - { - QmlComponent component(&engine, TEST_FILE("signalAssignment.2.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->string(), QString()); - emit object->argumentSignal(19, "Hello world!", 10.3); - QCOMPARE(object->string(), QString("pass 19 Hello world! 10.3")); - } -} - -void tst_qmlecmascript::methods() -{ - { - QmlComponent component(&engine, TEST_FILE("methods.1.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->methodCalled(), false); - QCOMPARE(object->methodIntCalled(), false); - emit object->basicSignal(); - QCOMPARE(object->methodCalled(), true); - QCOMPARE(object->methodIntCalled(), false); - } - - { - QmlComponent component(&engine, TEST_FILE("methods.2.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->methodCalled(), false); - QCOMPARE(object->methodIntCalled(), false); - emit object->basicSignal(); - QCOMPARE(object->methodCalled(), false); - QCOMPARE(object->methodIntCalled(), true); - } - - { - QmlComponent component(&engine, TEST_FILE("methods.3.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - QCOMPARE(object->property("test").toInt(), 19); - } - - { - QmlComponent component(&engine, TEST_FILE("methods.4.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - QCOMPARE(object->property("test").toInt(), 19); - QCOMPARE(object->property("test2").toInt(), 17); - QCOMPARE(object->property("test3").toInt(), 16); - } - - { - QmlComponent component(&engine, TEST_FILE("methods.5.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - QCOMPARE(object->property("test").toInt(), 9); - } -} - -void tst_qmlecmascript::bindingLoop() -{ - QmlComponent component(&engine, TEST_FILE("bindingLoop.qml")); - QString warning = "QML MyQmlObject (" + component.url().toString() + ":9:9) Binding loop detected for property \"stringProperty\""; - QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); - QObject *object = component.create(); - QVERIFY(object != 0); -} - -void tst_qmlecmascript::basicExpressions_data() -{ - QTest::addColumn<QString>("expression"); - QTest::addColumn<QVariant>("result"); - QTest::addColumn<bool>("nest"); - - QTest::newRow("Syntax error (self test)") << "{console.log({'a':1'}.a)}" << QVariant() << false; - QTest::newRow("Context property") << "a" << QVariant(1944) << false; - QTest::newRow("Context property") << "a" << QVariant(1944) << true; - QTest::newRow("Context property expression") << "a * 2" << QVariant(3888) << false; - QTest::newRow("Context property expression") << "a * 2" << QVariant(3888) << true; - QTest::newRow("Overridden context property") << "b" << QVariant("Milk") << false; - QTest::newRow("Overridden context property") << "b" << QVariant("Cow") << true; - QTest::newRow("Object property") << "object.stringProperty" << QVariant("Object1") << false; - QTest::newRow("Object property") << "object.stringProperty" << QVariant("Object1") << true; - QTest::newRow("Overridden object property") << "objectOverride.stringProperty" << QVariant("Object2") << false; - QTest::newRow("Overridden object property") << "objectOverride.stringProperty" << QVariant("Object3") << true; - QTest::newRow("Default object property") << "horseLegs" << QVariant(4) << false; - QTest::newRow("Default object property") << "antLegs" << QVariant(6) << false; - QTest::newRow("Default object property") << "emuLegs" << QVariant(2) << false; - QTest::newRow("Nested default object property") << "horseLegs" << QVariant(4) << true; - QTest::newRow("Nested default object property") << "antLegs" << QVariant(7) << true; - QTest::newRow("Nested default object property") << "emuLegs" << QVariant(2) << true; - QTest::newRow("Nested default object property") << "humanLegs" << QVariant(2) << true; - QTest::newRow("Context property override default object property") << "millipedeLegs" << QVariant(100) << true; -} - -void tst_qmlecmascript::basicExpressions() -{ - QFETCH(QString, expression); - QFETCH(QVariant, result); - QFETCH(bool, nest); - - MyQmlObject object1; - MyQmlObject object2; - MyQmlObject object3; - MyDefaultObject1 default1; - MyDefaultObject2 default2; - MyDefaultObject3 default3; - object1.setStringProperty("Object1"); - object2.setStringProperty("Object2"); - object3.setStringProperty("Object3"); - - QmlContext context(engine.rootContext()); - QmlContext nestedContext(&context); - - context.addDefaultObject(&default1); - context.addDefaultObject(&default2); - context.setContextProperty("a", QVariant(1944)); - context.setContextProperty("b", QVariant("Milk")); - context.setContextProperty("object", &object1); - context.setContextProperty("objectOverride", &object2); - nestedContext.addDefaultObject(&default3); - nestedContext.setContextProperty("b", QVariant("Cow")); - nestedContext.setContextProperty("objectOverride", &object3); - nestedContext.setContextProperty("millipedeLegs", QVariant(100)); - - MyExpression expr(nest?&nestedContext:&context, expression); - QCOMPARE(expr.value(), result); -} - -void tst_qmlecmascript::arrayExpressions() -{ - QObject obj1; - QObject obj2; - QObject obj3; - - QmlContext context(engine.rootContext()); - context.setContextProperty("a", &obj1); - context.setContextProperty("b", &obj2); - context.setContextProperty("c", &obj3); - - MyExpression expr(&context, "[a, b, c, 10]"); - QVariant result = expr.value(); - QCOMPARE(result.userType(), qMetaTypeId<QList<QObject *> >()); - QList<QObject *> list = qvariant_cast<QList<QObject *> >(result); - QCOMPARE(list.count(), 4); - QCOMPARE(list.at(0), &obj1); - QCOMPARE(list.at(1), &obj2); - QCOMPARE(list.at(2), &obj3); - QCOMPARE(list.at(3), (QObject *)0); -} - -// Tests that modifying a context property will reevaluate expressions -void tst_qmlecmascript::contextPropertiesTriggerReeval() -{ - QmlContext context(engine.rootContext()); - MyQmlObject object1; - MyQmlObject object2; - MyQmlObject *object3 = new MyQmlObject; - - object1.setStringProperty("Hello"); - object2.setStringProperty("World"); - - context.setContextProperty("testProp", QVariant(1)); - context.setContextProperty("testObj", &object1); - context.setContextProperty("testObj2", object3); - - { - MyExpression expr(&context, "testProp + 1"); - QCOMPARE(expr.changed, false); - QCOMPARE(expr.value(), QVariant(2)); - - context.setContextProperty("testProp", QVariant(2)); - QCOMPARE(expr.changed, true); - QCOMPARE(expr.value(), QVariant(3)); - } - - { - MyExpression expr(&context, "testProp + testProp + testProp"); - QCOMPARE(expr.changed, false); - QCOMPARE(expr.value(), QVariant(6)); - - context.setContextProperty("testProp", QVariant(4)); - QCOMPARE(expr.changed, true); - QCOMPARE(expr.value(), QVariant(12)); - } - - { - MyExpression expr(&context, "testObj.stringProperty"); - QCOMPARE(expr.changed, false); - QCOMPARE(expr.value(), QVariant("Hello")); - - context.setContextProperty("testObj", &object2); - QCOMPARE(expr.changed, true); - QCOMPARE(expr.value(), QVariant("World")); - } - - { - MyExpression expr(&context, "testObj.stringProperty /**/"); - QCOMPARE(expr.changed, false); - QCOMPARE(expr.value(), QVariant("World")); - - context.setContextProperty("testObj", &object1); - QCOMPARE(expr.changed, true); - QCOMPARE(expr.value(), QVariant("Hello")); - } - - { - MyExpression expr(&context, "testObj2"); - QCOMPARE(expr.changed, false); - QCOMPARE(expr.value(), QVariant::fromValue((QObject *)object3)); - } - -} - -void tst_qmlecmascript::objectPropertiesTriggerReeval() -{ - QmlContext context(engine.rootContext()); - MyQmlObject object1; - MyQmlObject object2; - MyQmlObject object3; - context.setContextProperty("testObj", &object1); - - object1.setStringProperty(QLatin1String("Hello")); - object2.setStringProperty(QLatin1String("Dog")); - object3.setStringProperty(QLatin1String("Cat")); - - { - MyExpression expr(&context, "testObj.stringProperty"); - QCOMPARE(expr.changed, false); - QCOMPARE(expr.value(), QVariant("Hello")); - - object1.setStringProperty(QLatin1String("World")); - QCOMPARE(expr.changed, true); - QCOMPARE(expr.value(), QVariant("World")); - } - - { - MyExpression expr(&context, "testObj.objectProperty.stringProperty"); - QCOMPARE(expr.changed, false); - QCOMPARE(expr.value(), QVariant()); - - object1.setObjectProperty(&object2); - QCOMPARE(expr.changed, true); - expr.changed = false; - QCOMPARE(expr.value(), QVariant("Dog")); - - object1.setObjectProperty(&object3); - QCOMPARE(expr.changed, true); - expr.changed = false; - QCOMPARE(expr.value(), QVariant("Cat")); - - object1.setObjectProperty(0); - QCOMPARE(expr.changed, true); - expr.changed = false; - QCOMPARE(expr.value(), QVariant()); - - object1.setObjectProperty(&object3); - QCOMPARE(expr.changed, true); - expr.changed = false; - QCOMPARE(expr.value(), QVariant("Cat")); - - object3.setStringProperty("Donkey"); - QCOMPARE(expr.changed, true); - expr.changed = false; - QCOMPARE(expr.value(), QVariant("Donkey")); - } -} - -void tst_qmlecmascript::deferredProperties() -{ - QmlComponent component(&engine, TEST_FILE("deferredProperties.qml")); - MyDeferredObject *object = - qobject_cast<MyDeferredObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->value(), 0); - QVERIFY(object->objectProperty() == 0); - QVERIFY(object->objectProperty2() != 0); - qmlExecuteDeferred(object); - QCOMPARE(object->value(), 10); - QVERIFY(object->objectProperty() != 0); - MyQmlObject *qmlObject = - qobject_cast<MyQmlObject *>(object->objectProperty()); - QVERIFY(qmlObject != 0); - QCOMPARE(qmlObject->value(), 10); - object->setValue(19); - QCOMPARE(qmlObject->value(), 19); -} - -void tst_qmlecmascript::extensionObjects() -{ - QmlComponent component(&engine, TEST_FILE("extensionObjects.qml")); - MyExtendedObject *object = - qobject_cast<MyExtendedObject *>(component.create()); - QVERIFY(object != 0); - QCOMPARE(object->baseProperty(), 13); - QCOMPARE(object->coreProperty(), 9); - - object->setProperty("extendedProperty", QVariant(11)); - object->setProperty("baseExtendedProperty", QVariant(92)); - QCOMPARE(object->coreProperty(), 11); - QCOMPARE(object->baseProperty(), 92); -} - -void tst_qmlecmascript::attachedProperties() -{ - QmlComponent component(&engine, TEST_FILE("attachedProperty.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - QCOMPARE(object->property("a").toInt(), 19); - QCOMPARE(object->property("b").toInt(), 19); - QCOMPARE(object->property("c").toInt(), 19); - QCOMPARE(object->property("d").toInt(), 19); - - // ### Need to test attached property assignment -} - -void tst_qmlecmascript::enums() -{ - // Existant enums - { - QmlComponent component(&engine, TEST_FILE("enums.1.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("a").toInt(), 0); - QCOMPARE(object->property("b").toInt(), 1); - QCOMPARE(object->property("c").toInt(), 2); - QCOMPARE(object->property("d").toInt(), 3); - QCOMPARE(object->property("e").toInt(), 0); - QCOMPARE(object->property("f").toInt(), 1); - QCOMPARE(object->property("g").toInt(), 2); - QCOMPARE(object->property("h").toInt(), 3); - QCOMPARE(object->property("i").toInt(), 19); - QCOMPARE(object->property("j").toInt(), 19); - } - // Non-existent enums - { - QmlComponent component(&engine, TEST_FILE("enums.2.qml")); - - QString warning1 = component.url().toString() + ":5: Unable to assign [undefined] to int"; - QString warning2 = component.url().toString() + ":6: Unable to assign [undefined] to int"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); - QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); - - QObject *object = component.create(); - QVERIFY(object != 0); - QCOMPARE(object->property("a").toInt(), 0); - QCOMPARE(object->property("b").toInt(), 0); - } -} - -void tst_qmlecmascript::valueTypeFunctions() -{ - QmlComponent component(&engine, TEST_FILE("valueTypeFunctions.qml")); - MyTypeObject *obj = qobject_cast<MyTypeObject*>(component.create()); - QVERIFY(obj != 0); - QCOMPARE(obj->rectProperty(), QRect(0,0,100,100)); - QCOMPARE(obj->rectFProperty(), QRectF(0,0.5,100,99.5)); -} - -/* -Tests that writing a constant to a property with a binding on it disables the -binding. -*/ -void tst_qmlecmascript::constantsOverrideBindings() -{ - // From ECMAScript - { - QmlComponent component(&engine, TEST_FILE("constantsOverrideBindings.1.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - - QCOMPARE(object->property("c2").toInt(), 0); - object->setProperty("c1", QVariant(9)); - QCOMPARE(object->property("c2").toInt(), 9); - - emit object->basicSignal(); - - QCOMPARE(object->property("c2").toInt(), 13); - object->setProperty("c1", QVariant(8)); - QCOMPARE(object->property("c2").toInt(), 13); - } - - // During construction - { - QmlComponent component(&engine, TEST_FILE("constantsOverrideBindings.2.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - - QCOMPARE(object->property("c1").toInt(), 0); - QCOMPARE(object->property("c2").toInt(), 10); - object->setProperty("c1", QVariant(9)); - QCOMPARE(object->property("c1").toInt(), 9); - QCOMPARE(object->property("c2").toInt(), 10); - } - -#if 0 - // From C++ - { - QmlComponent component(&engine, TEST_FILE("constantsOverrideBindings.3.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - - QCOMPARE(object->property("c2").toInt(), 0); - object->setProperty("c1", QVariant(9)); - QCOMPARE(object->property("c2").toInt(), 9); - - object->setProperty("c2", QVariant(13)); - QCOMPARE(object->property("c2").toInt(), 13); - object->setProperty("c1", QVariant(7)); - QCOMPARE(object->property("c1").toInt(), 7); - QCOMPARE(object->property("c2").toInt(), 13); - } -#endif -} - -/* -Tests that assigning a binding to a property that already has a binding causes -the original binding to be disabled. -*/ -void tst_qmlecmascript::outerBindingOverridesInnerBinding() -{ - QmlComponent component(&engine, - TEST_FILE("outerBindingOverridesInnerBinding.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - - QCOMPARE(object->property("c1").toInt(), 0); - QCOMPARE(object->property("c2").toInt(), 0); - QCOMPARE(object->property("c3").toInt(), 0); - - object->setProperty("c1", QVariant(9)); - QCOMPARE(object->property("c1").toInt(), 9); - QCOMPARE(object->property("c2").toInt(), 0); - QCOMPARE(object->property("c3").toInt(), 0); - - object->setProperty("c3", QVariant(8)); - QCOMPARE(object->property("c1").toInt(), 9); - QCOMPARE(object->property("c2").toInt(), 8); - QCOMPARE(object->property("c3").toInt(), 8); -} - -/* -Access a non-existent attached object. - -Tests for a regression where this used to crash. -*/ -void tst_qmlecmascript::nonExistantAttachedObject() -{ - QmlComponent component(&engine, TEST_FILE("nonExistantAttachedObject.qml")); - - QString warning = component.url().toString() + ":4: Unable to assign [undefined] to QString"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - - QObject *object = component.create(); - QVERIFY(object != 0); -} - -void tst_qmlecmascript::scope() -{ - { - QmlComponent component(&engine, TEST_FILE("scope.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test1").toInt(), 1); - QCOMPARE(object->property("test2").toInt(), 2); - QCOMPARE(object->property("test3").toString(), QString("1Test")); - QCOMPARE(object->property("test4").toString(), QString("2Test")); - QCOMPARE(object->property("test5").toInt(), 1); - QCOMPARE(object->property("test6").toInt(), 1); - QCOMPARE(object->property("test7").toInt(), 2); - QCOMPARE(object->property("test8").toInt(), 2); - QCOMPARE(object->property("test9").toInt(), 1); - QCOMPARE(object->property("test10").toInt(), 3); - } - - { - QmlComponent component(&engine, TEST_FILE("scope.2.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test1").toInt(), 19); - QCOMPARE(object->property("test2").toInt(), 19); - QCOMPARE(object->property("test3").toInt(), 11); - QCOMPARE(object->property("test4").toInt(), 11); - QCOMPARE(object->property("test5").toInt(), 24); - QCOMPARE(object->property("test6").toInt(), 24); - } -} - -/* -Tests that "any" type passes through a synthesized signal parameter. This -is essentially a test of QmlMetaType::copy() -*/ -void tst_qmlecmascript::signalParameterTypes() -{ - QmlComponent component(&engine, TEST_FILE("signalParameterTypes.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - - emit object->basicSignal(); - - QCOMPARE(object->property("intProperty").toInt(), 10); - QCOMPARE(object->property("realProperty").toReal(), 19.2); - QVERIFY(object->property("colorProperty").value<QColor>() == QColor(255, 255, 0, 255)); - QVERIFY(object->property("variantProperty") == QVariant::fromValue(QColor(255, 0, 255, 255))); -} - -/* -Test that two JS objects for the same QObject compare as equal. -*/ -void tst_qmlecmascript::objectsCompareAsEqual() -{ - QmlComponent component(&engine, TEST_FILE("objectsCompareAsEqual.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test1").toBool(), true); - QCOMPARE(object->property("test2").toBool(), true); - QCOMPARE(object->property("test3").toBool(), true); - QCOMPARE(object->property("test4").toBool(), true); - QCOMPARE(object->property("test5").toBool(), true); -} - -/* -Confirm bindings and alias properties can coexist. - -Tests for a regression where the binding would not reevaluate. -*/ -void tst_qmlecmascript::aliasPropertyAndBinding() -{ - QmlComponent component(&engine, TEST_FILE("aliasPropertyAndBinding.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("c2").toInt(), 3); - QCOMPARE(object->property("c3").toInt(), 3); - - object->setProperty("c2", QVariant(19)); - - QCOMPARE(object->property("c2").toInt(), 19); - QCOMPARE(object->property("c3").toInt(), 19); -} - -/* -Tests that only methods of Script {} blocks are exposed. -*/ -void tst_qmlecmascript::scriptAccess() -{ - QmlComponent component(&engine, TEST_FILE("scriptAccess.qml")); - - QString warning = component.url().toString() + ":16: Unable to assign [undefined] to int"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test1").toInt(), 10); - QCOMPARE(object->property("test2").toInt(), 19); - QCOMPARE(object->property("test3").toInt(), 0); -} - -void tst_qmlecmascript::dynamicCreation_data() -{ - QTest::addColumn<QString>("method"); - QTest::addColumn<QString>("createdName"); - - QTest::newRow("One") << "createOne" << "objectOne"; - QTest::newRow("Two") << "createTwo" << "objectTwo"; - QTest::newRow("Three") << "createThree" << "objectThree"; -} - -/* -Test using createQmlObject to dynamically generate an item -Also using createComponent is tested. -*/ -void tst_qmlecmascript::dynamicCreation() -{ - QFETCH(QString, method); - QFETCH(QString, createdName); - - QmlComponent component(&engine, TEST_FILE("dynamicCreation.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(object != 0); - - QMetaObject::invokeMethod(object, method.toUtf8()); - QObject *created = object->objectProperty(); - QVERIFY(created); - QCOMPARE(created->objectName(), createdName); -} - -/* - Tests the destroy function -*/ -void tst_qmlecmascript::dynamicDestruction() -{ - QmlComponent component(&engine, TEST_FILE("dynamicDeletion.qml")); - QmlGuard<MyQmlObject> object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(object != 0); - QmlGuard<QObject> createdQmlObject = 0; - - QMetaObject::invokeMethod(object, "create"); - createdQmlObject = object->objectProperty(); - QVERIFY(createdQmlObject); - QCOMPARE(createdQmlObject->objectName(), QString("emptyObject")); - - QMetaObject::invokeMethod(object, "killOther"); - QVERIFY(createdQmlObject); - QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion); - QVERIFY(createdQmlObject); - for (int ii = 0; createdQmlObject && ii < 50; ++ii) { // After 5 seconds we should give up - if (createdQmlObject) { - QTest::qWait(100); - QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion); - } - } - QVERIFY(!createdQmlObject); - - QMetaObject::invokeMethod(object, "killMe"); - QVERIFY(object); - QTest::qWait(0); - QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion); - QVERIFY(!object); -} - -/* - tests that id.toString() works -*/ -void tst_qmlecmascript::objectToString() -{ - QmlComponent component(&engine, TEST_FILE("qmlToString.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(object != 0); - QMetaObject::invokeMethod(object, "testToString"); - QVERIFY(object->stringProperty().startsWith("MyQmlObject_QML_")); - QVERIFY(object->stringProperty().endsWith(", \"objName\")")); -} - -/* -Tests bindings that indirectly cause their own deletion work. - -This test is best run under valgrind to ensure no invalid memory access occur. -*/ -void tst_qmlecmascript::selfDeletingBinding() -{ - { - QmlComponent component(&engine, TEST_FILE("selfDeletingBinding.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - object->setProperty("triggerDelete", true); - } - - { - QmlComponent component(&engine, TEST_FILE("selfDeletingBinding.2.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - object->setProperty("triggerDelete", true); - } -} - -/* -Test that extended object properties can be accessed. - -This test a regression where this used to crash. The issue was specificially -for extended objects that did not include a synthesized meta object (so non-root -and no synthesiszed properties). -*/ -void tst_qmlecmascript::extendedObjectPropertyLookup() -{ - QmlComponent component(&engine, TEST_FILE("extendedObjectPropertyLookup.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); -} - -/* -Test file/lineNumbers for binding/Script errors. -*/ -void tst_qmlecmascript::scriptErrors() -{ - QmlComponent component(&engine, TEST_FILE("scriptErrors.qml")); - QString url = component.url().toString(); - - QString warning1 = url.left(url.length() - 3) + "js:2: Error: Invalid write to global property \"a\""; - QString warning2 = url + ":7: TypeError: Result of expression 'a' [undefined] is not an object."; - QString warning3 = url + ":5: Error: Invalid write to global property \"a\""; - QString warning4 = url + ":12: TypeError: Result of expression 'a' [undefined] is not an object."; - QString warning5 = url + ":10: TypeError: Result of expression 'a' [undefined] is not an object."; - QString warning6 = url + ":9: Unable to assign [undefined] to int"; - QString warning7 = url + ":14: Error: Cannot assign to read-only property \"trueProperty\""; - QString warning8 = url + ":15: Error: Cannot assign to non-existent property \"fakeProperty\""; - - QTest::ignoreMessage(QtWarningMsg, warning1.toLatin1().constData()); - QTest::ignoreMessage(QtWarningMsg, warning2.toLatin1().constData()); - QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData()); - QTest::ignoreMessage(QtWarningMsg, warning5.toLatin1().constData()); - QTest::ignoreMessage(QtWarningMsg, warning6.toLatin1().constData()); - MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); - QVERIFY(object != 0); - - QTest::ignoreMessage(QtWarningMsg, warning4.toLatin1().constData()); - emit object->basicSignal(); - - QTest::ignoreMessage(QtWarningMsg, warning7.toLatin1().constData()); - emit object->anotherBasicSignal(); - - QTest::ignoreMessage(QtWarningMsg, warning8.toLatin1().constData()); - emit object->thirdBasicSignal(); -} - -/* -Test bindings still work when the reeval is triggered from within -a signal script. -*/ -void tst_qmlecmascript::signalTriggeredBindings() -{ - QmlComponent component(&engine, TEST_FILE("signalTriggeredBindings.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(object != 0); - - QCOMPARE(object->property("base").toReal(), 50.); - QCOMPARE(object->property("test1").toReal(), 50.); - QCOMPARE(object->property("test2").toReal(), 50.); - - object->basicSignal(); - - QCOMPARE(object->property("base").toReal(), 200.); - QCOMPARE(object->property("test1").toReal(), 200.); - QCOMPARE(object->property("test2").toReal(), 200.); - - object->argumentSignal(10, QString(), 10); - - QCOMPARE(object->property("base").toReal(), 400.); - QCOMPARE(object->property("test1").toReal(), 400.); - QCOMPARE(object->property("test2").toReal(), 400.); -} - -/* -Test that list properties can be iterated from ECMAScript -*/ -void tst_qmlecmascript::listProperties() -{ - QmlComponent component(&engine, TEST_FILE("listProperties.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(object != 0); - - QCOMPARE(object->property("test1").toInt(), 21); - QCOMPARE(object->property("test2").toInt(), 2); - QCOMPARE(object->property("test3").toBool(), true); - QCOMPARE(object->property("test4").toBool(), true); -} - -void tst_qmlecmascript::exceptionClearsOnReeval() -{ - QmlComponent component(&engine, TEST_FILE("exceptionClearsOnReeval.qml")); - QString url = component.url().toString(); - - QString warning = url + ":4: TypeError: Result of expression 'objectProperty.objectProperty' [undefined] is not an object."; - - QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); - MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toBool(), false); - - MyQmlObject object2; - MyQmlObject object3; - object2.setObjectProperty(&object3); - object->setObjectProperty(&object2); - - QCOMPARE(object->property("test").toBool(), true); -} - -void tst_qmlecmascript::exceptionSlotProducesWarning() -{ - QmlComponent component(&engine, TEST_FILE("exceptionProducesWarning.qml")); - QString url = component.url().toString(); - - QString warning = component.url().toString() + ":6: Error: JS exception"; - - QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); - MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(object != 0); -} - -void tst_qmlecmascript::exceptionBindingProducesWarning() -{ - QmlComponent component(&engine, TEST_FILE("exceptionProducesWarning2.qml")); - QString url = component.url().toString(); - - QString warning = component.url().toString() + ":5: Error: JS exception"; - - QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); - MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(object != 0); -} - -static int transientErrorsMsgCount = 0; -static void transientErrorsMsgHandler(QtMsgType, const char *) -{ - ++transientErrorsMsgCount; -} - -// Check that transient binding errors are not displayed -void tst_qmlecmascript::transientErrors() -{ - QmlComponent component(&engine, TEST_FILE("transientErrors.qml")); - - transientErrorsMsgCount = 0; - QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); - - QObject *object = component.create(); - QVERIFY(object != 0); - - qInstallMsgHandler(old); - - QCOMPARE(transientErrorsMsgCount, 0); -} - -// Check that errors during shutdown are minimized -void tst_qmlecmascript::shutdownErrors() -{ - QmlComponent component(&engine, TEST_FILE("shutdownErrors.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - transientErrorsMsgCount = 0; - QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); - - delete object; - - qInstallMsgHandler(old); - QCOMPARE(transientErrorsMsgCount, 0); -} - -// Check that Script::source property works as expected -void tst_qmlecmascript::externalScript() -{ - { - QmlComponent component(&engine, TEST_FILE("externalScript.1.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 92); - - delete object; - } - - { - QmlComponent component(&engine, TEST_FILE("externalScript.2.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 92); - - delete object; - } - - { - QmlComponent component(&engine, TEST_FILE("externalScript.3.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 92); - QCOMPARE(object->property("test2").toInt(), 92); - QCOMPARE(object->property("test3").toBool(), false); - - delete object; - } - - { - QmlComponent component(&engine, TEST_FILE("externalScript.4.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 92); - QCOMPARE(object->property("test2").toBool(), true); - - delete object; - } -} - -void tst_qmlecmascript::compositePropertyType() -{ - QmlComponent component(&engine, TEST_FILE("compositePropertyType.qml")); - QTest::ignoreMessage(QtDebugMsg, "hello world"); - QObject *object = qobject_cast<QObject *>(component.create()); - delete object; -} - -// QTBUG-5759 -void tst_qmlecmascript::jsObject() -{ - QmlComponent component(&engine, TEST_FILE("jsObject.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 92); - - delete object; -} - -void tst_qmlecmascript::undefinedResetsProperty() -{ - { - QmlComponent component(&engine, TEST_FILE("undefinedResetsProperty.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("resettableProperty").toInt(), 92); - - object->setProperty("setUndefined", true); - - QCOMPARE(object->property("resettableProperty").toInt(), 13); - - object->setProperty("setUndefined", false); - - QCOMPARE(object->property("resettableProperty").toInt(), 92); - - delete object; - } - { - QmlComponent component(&engine, TEST_FILE("undefinedResetsProperty.2.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("resettableProperty").toInt(), 19); - - QMetaObject::invokeMethod(object, "doReset"); - - QCOMPARE(object->property("resettableProperty").toInt(), 13); - - delete object; - } -} - -// QTBUG-6781 -void tst_qmlecmascript::bug1() -{ - QmlComponent component(&engine, TEST_FILE("bug.1.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); - - QCOMPARE(object->property("test").toInt(), 14); - - object->setProperty("a", 11); - - QCOMPARE(object->property("test").toInt(), 3); - - object->setProperty("b", true); - - QCOMPARE(object->property("test").toInt(), 9); - - delete object; -} - -void tst_qmlecmascript::callQtInvokables() -{ - MyInvokableObject o; - - QmlEngine qmlengine; - QmlEnginePrivate *ep = QmlEnginePrivate::get(&qmlengine); - QScriptEngine *engine = &ep->scriptEngine; - ep->globalClass->explicitSetProperty("object", ep->objectClass->newQObject(&o)); - - // Non-existent methods - o.reset(); - QCOMPARE(engine->evaluate("object.method_nonexistent()").isError(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), -1); - QCOMPARE(o.actuals().count(), 0); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_nonexistent(10, 11)").isError(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), -1); - QCOMPARE(o.actuals().count(), 0); - - // Insufficient arguments - o.reset(); - QCOMPARE(engine->evaluate("object.method_int()").isError(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), -1); - QCOMPARE(o.actuals().count(), 0); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_intint(10)").isError(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), -1); - QCOMPARE(o.actuals().count(), 0); - - // Excessive arguments - o.reset(); - QCOMPARE(engine->evaluate("object.method_int(10, 11)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 8); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(10)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_intint(10, 11, 12)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 9); - QCOMPARE(o.actuals().count(), 2); - QCOMPARE(o.actuals().at(0), QVariant(10)); - QCOMPARE(o.actuals().at(1), QVariant(11)); - - // Test return types - o.reset(); - QCOMPARE(engine->evaluate("object.method_NoArgs()").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 0); - QCOMPARE(o.actuals().count(), 0); - - o.reset(); - QVERIFY(engine->evaluate("object.method_NoArgs_int()").strictlyEquals(QScriptValue(engine, 6))); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 1); - QCOMPARE(o.actuals().count(), 0); - - o.reset(); - QVERIFY(engine->evaluate("object.method_NoArgs_real()").strictlyEquals(QScriptValue(engine, 19.7))); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 2); - QCOMPARE(o.actuals().count(), 0); - - o.reset(); - { - QScriptValue ret = engine->evaluate("object.method_NoArgs_QPointF()"); - QVERIFY(ret.isVariant()); - QCOMPARE(ret.toVariant(), QVariant(QPointF(123, 4.5))); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 3); - QCOMPARE(o.actuals().count(), 0); - } - - o.reset(); - { - QScriptValue ret = engine->evaluate("object.method_NoArgs_QObject()"); - QVERIFY(ret.isQObject()); - QCOMPARE(ret.toQObject(), (QObject *)&o); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 4); - QCOMPARE(o.actuals().count(), 0); - } - - o.reset(); - QCOMPARE(engine->evaluate("object.method_NoArgs_unknown()").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 5); - QCOMPARE(o.actuals().count(), 0); - - o.reset(); - { - QScriptValue ret = engine->evaluate("object.method_NoArgs_QScriptValue()"); - QVERIFY(ret.isString()); - QCOMPARE(ret.toString(), QString("Hello world")); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 6); - QCOMPARE(o.actuals().count(), 0); - } - - o.reset(); - QVERIFY(engine->evaluate("object.method_NoArgs_QVariant()").strictlyEquals(QScriptValue(engine, "QML rocks"))); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 7); - QCOMPARE(o.actuals().count(), 0); - - // Test arg types - o.reset(); - QCOMPARE(engine->evaluate("object.method_int(94)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 8); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(94)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_int(\"94\")").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 8); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(94)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_int(\"not a number\")").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 8); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(0)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_int(null)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 8); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(0)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_int(undefined)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 8); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(0)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_int(object)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 8); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(0)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_intint(122, 9)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 9); - QCOMPARE(o.actuals().count(), 2); - QCOMPARE(o.actuals().at(0), QVariant(122)); - QCOMPARE(o.actuals().at(1), QVariant(9)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_real(94.3)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 10); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(94.3)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_real(\"94.3\")").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 10); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(94.3)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_real(\"not a number\")").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 10); - QCOMPARE(o.actuals().count(), 1); - QVERIFY(qIsNaN(o.actuals().at(0).toDouble())); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_real(null)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 10); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(0)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_real(undefined)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 10); - QCOMPARE(o.actuals().count(), 1); - QVERIFY(qIsNaN(o.actuals().at(0).toDouble())); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_real(object)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 10); - QCOMPARE(o.actuals().count(), 1); - QVERIFY(qIsNaN(o.actuals().at(0).toDouble())); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QString(\"Hello world\")").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 11); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant("Hello world")); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QString(19)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 11); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant("19")); - - o.reset(); - { - QString expected = "MyInvokableObject(0x" + QString::number((intptr_t)&o, 16) + ")"; - QCOMPARE(engine->evaluate("object.method_QString(object)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 11); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(expected)); - } - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QString(null)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 11); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(QString())); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QString(undefined)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 11); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(QString())); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(0)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 12); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(QPointF())); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(null)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 12); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(QPointF())); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(undefined)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 12); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(QPointF())); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(object)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 12); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(QPointF())); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(object.method_get_QPointF())").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 12); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(QPointF(99.3, -10.2))); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QPointF(object.method_get_QPoint())").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 12); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), QVariant(QPointF(9, 12))); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(0)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 13); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(\"Hello world\")").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 13); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(null)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 13); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(undefined)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 13); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)0)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QObject(object)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 13); - QCOMPARE(o.actuals().count(), 1); - QCOMPARE(o.actuals().at(0), qVariantFromValue((QObject *)&o)); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QScriptValue(null)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 14); - QCOMPARE(o.actuals().count(), 1); - QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).isNull()); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QScriptValue(undefined)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 14); - QCOMPARE(o.actuals().count(), 1); - QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).isUndefined()); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QScriptValue(19)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 14); - QCOMPARE(o.actuals().count(), 1); - QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).strictlyEquals(QScriptValue(engine, 19))); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_QScriptValue([19, 20])").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 14); - QCOMPARE(o.actuals().count(), 1); - QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(0)).isArray()); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_intQScriptValue(4, null)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 15); - QCOMPARE(o.actuals().count(), 2); - QCOMPARE(o.actuals().at(0), QVariant(4)); - QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isNull()); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_intQScriptValue(8, undefined)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 15); - QCOMPARE(o.actuals().count(), 2); - QCOMPARE(o.actuals().at(0), QVariant(8)); - QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isUndefined()); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_intQScriptValue(3, 19)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 15); - QCOMPARE(o.actuals().count(), 2); - QCOMPARE(o.actuals().at(0), QVariant(3)); - QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).strictlyEquals(QScriptValue(engine, 19))); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_intQScriptValue(44, [19, 20])").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 15); - QCOMPARE(o.actuals().count(), 2); - QCOMPARE(o.actuals().at(0), QVariant(44)); - QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isArray()); - - // Test overloads - QML will always invoke the *last* method - o.reset(); - QCOMPARE(engine->evaluate("object.method_overload()").isError(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), -1); - QCOMPARE(o.actuals().count(), 0); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_overload(10)").isError(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), -1); - QCOMPARE(o.actuals().count(), 0); - - o.reset(); - QCOMPARE(engine->evaluate("object.method_overload(10, 11)").isUndefined(), true); - QCOMPARE(o.error(), false); - QCOMPARE(o.invoked(), 17); - QCOMPARE(o.actuals().count(), 2); - QCOMPARE(o.actuals().at(0), QVariant(10)); - QCOMPARE(o.actuals().at(1), QVariant(11)); -} - -// QTBUG-5675 -void tst_qmlecmascript::listToVariant() -{ - QmlComponent component(&engine, TEST_FILE("listToVariant.qml")); - - MyQmlContainer container; - - QmlContext context(engine.rootContext()); - context.addDefaultObject(&container); - - QObject *object = component.create(&context); - QVERIFY(object != 0); - - QVariant v = object->property("test"); - QCOMPARE(v.userType(), qMetaTypeId<QmlListReference>()); - QVERIFY(qvariant_cast<QmlListReference>(v).object() == &container); - - delete object; -} - -// QTBUG-7957 -void tst_qmlecmascript::multiEngineObject() -{ - MyQmlObject obj; - obj.setStringProperty("Howdy planet"); - - QmlEngine e1; - e1.rootContext()->setContextProperty("thing", &obj); - QmlComponent c1(&e1, TEST_FILE("multiEngineObject.qml")); - - QmlEngine e2; - e2.rootContext()->setContextProperty("thing", &obj); - QmlComponent c2(&e2, TEST_FILE("multiEngineObject.qml")); - - QObject *o1 = c1.create(); - QObject *o2 = c2.create(); - - QCOMPARE(o1->property("test").toString(), QString("Howdy planet")); - QCOMPARE(o2->property("test").toString(), QString("Howdy planet")); - - delete o2; - delete o1; -} - -// Test that references to QObjects are cleanup when the object is destroyed -void tst_qmlecmascript::deletedObject() -{ - QmlComponent component(&engine, TEST_FILE("deletedObject.qml")); - - QObject *object = component.create(); - - QCOMPARE(object->property("test1").toBool(), true); - QCOMPARE(object->property("test2").toBool(), true); - QCOMPARE(object->property("test3").toBool(), true); - QEXPECT_FAIL("", "QTBUG-8077", Continue); - QCOMPARE(object->property("test4").toBool(), true); - - delete object; -} - -QTEST_MAIN(tst_qmlecmascript) - -#include "tst_qmlecmascript.moc" |