diff options
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/data')
370 files changed, 6369 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/AliasBindingsAssignCorrectlyType.qml b/tests/auto/qml/qqmlecmascript/data/AliasBindingsAssignCorrectlyType.qml new file mode 100644 index 0000000000..e8e108fa44 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/AliasBindingsAssignCorrectlyType.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +QtObject { + id: root + + property real realProperty + property alias aliasProperty: root.realProperty +} + diff --git a/tests/auto/qml/qqmlecmascript/data/AliasBindingsOverrideTargetType.qml b/tests/auto/qml/qqmlecmascript/data/AliasBindingsOverrideTargetType.qml new file mode 100644 index 0000000000..062772106b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/AliasBindingsOverrideTargetType.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyTypeObject { + id: root + + property int data: 7 + + property int targetProperty: root.data * 43 - root.data + property alias aliasProperty: root.targetProperty + + pointProperty: Qt.point(data, data); + property alias pointAliasProperty: root.pointProperty +} diff --git a/tests/auto/qml/qqmlecmascript/data/AliasBindingsOverrideTargetType3.qml b/tests/auto/qml/qqmlecmascript/data/AliasBindingsOverrideTargetType3.qml new file mode 100644 index 0000000000..823c0ef367 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/AliasBindingsOverrideTargetType3.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +QtObject { + id: root + + property int testProperty + property alias aliasProperty: root.testProperty +} + diff --git a/tests/auto/qml/qqmlecmascript/data/AliasToCompositeElementType1.qml b/tests/auto/qml/qqmlecmascript/data/AliasToCompositeElementType1.qml new file mode 100644 index 0000000000..cef8ae09ea --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/AliasToCompositeElementType1.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +QtObject { + property alias group: obj + property variant foo: AliasToCompositeElementType2 { id: obj } +} diff --git a/tests/auto/qml/qqmlecmascript/data/AliasToCompositeElementType2.qml b/tests/auto/qml/qqmlecmascript/data/AliasToCompositeElementType2.qml new file mode 100644 index 0000000000..4a45535a50 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/AliasToCompositeElementType2.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + property int value +} diff --git a/tests/auto/qml/qqmlecmascript/data/ConstantsOverrideBindings.qml b/tests/auto/qml/qqmlecmascript/data/ConstantsOverrideBindings.qml new file mode 100644 index 0000000000..07bb16b0d8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/ConstantsOverrideBindings.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 + +MyQmlObject { + property int c1: 0 + property int c2: c1 + property alias c3: inner.ic1 + + objectProperty: MyQmlObject { + id: inner + property int ic1: c1 + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/CustomObject.qml b/tests/auto/qml/qqmlecmascript/data/CustomObject.qml new file mode 100644 index 0000000000..aa1a1d6061 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/CustomObject.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + property string greeting: "hello world" +} diff --git a/tests/auto/qml/qqmlecmascript/data/ElementAssignType.qml b/tests/auto/qml/qqmlecmascript/data/ElementAssignType.qml new file mode 100644 index 0000000000..4a45535a50 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/ElementAssignType.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + property int value +} diff --git a/tests/auto/qml/qqmlecmascript/data/MethodsObject.qml b/tests/auto/qml/qqmlecmascript/data/MethodsObject.qml new file mode 100644 index 0000000000..eaca0a7f92 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/MethodsObject.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +QtObject { + function testFunction() { return 19; } + function testFunction2() { return 18; } +} diff --git a/tests/auto/qml/qqmlecmascript/data/NestedTypeTransientErrors.qml b/tests/auto/qml/qqmlecmascript/data/NestedTypeTransientErrors.qml new file mode 100644 index 0000000000..3b3e84a900 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/NestedTypeTransientErrors.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +QtObject { + property int b: obj.prop.a + + property variant prop; + prop: QtObject { + property int a: 10 + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/PropertyVarBaseItem.qml b/tests/auto/qml/qqmlecmascript/data/PropertyVarBaseItem.qml new file mode 100644 index 0000000000..5f28833fe7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/PropertyVarBaseItem.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + property var random: null +} diff --git a/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent.qml b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent.qml new file mode 100644 index 0000000000..36c025401f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: first + property var vp: Item { + id: second + property var vp: Item { + id: third + property var vp: Item { + id: fourth + property var vp: Item { + id: fifth + property int fifthCanary: 5 + property var circ: third.vp + property MyScarceResourceObject srp; + srp: MyScarceResourceObject { id: scarceResourceProvider } + property variant memoryHog: scarceResourceProvider.newScarceResource() + } + } + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent2.qml b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent2.qml new file mode 100644 index 0000000000..6a49cb9317 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent2.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// Similar to PVCC.qml except that it has another var property +// It will have a different metaobject. +Item { + id: first + property var anotherVp: 6 + property var vp: Item { + id: second + property var vp: Item { + id: third + property var vp: Item { + id: fourth + property var vp: Item { + id: fifth + property int fifthCanary: 5 + property var circ: third.vp + property MyScarceResourceObject srp; + srp: MyScarceResourceObject { id: scarceResourceProvider } + property variant memoryHog2: scarceResourceProvider.newScarceResource() + } + } + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent3.qml b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent3.qml new file mode 100644 index 0000000000..a90725016e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent3.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +Rectangle { + id: rectangle // will have JS ownership + objectName: "rectangle" + width: 10 + height: 10 + property var rectCanary: 5 + + Text { + id: text // will have Eventual-JS ownership + objectName: "text" + property var vp: rectangle + property var textCanary: 10 + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent4.qml b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent4.qml new file mode 100644 index 0000000000..9273a52f54 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent4.qml @@ -0,0 +1,28 @@ +import QtQuick 2.0 + +Rectangle { + id: rectangle // will have JS ownership + objectName: "rectangle" + width: 10 + height: 10 + property var rectCanary: 5 + + Text { + id: text // will have Eventual-JS ownership + objectName: "text" + property var vp + property var textCanary: 10 + + // The varProperties array of "text" is weak + // (due to eventual JS ownership since parent is JS owned) + // but nonetheless, the reference to the created QObject + // should cause that QObject to NOT be collected. + function constructQObject() { + var component = Qt.createComponent("PropertyVarCircularComponent5.qml"); + if (component.status == Component.Ready) { + text.vp = component.createObject(null); // has JavaScript ownership + } + gc(); + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent5.qml b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent5.qml new file mode 100644 index 0000000000..94ef338792 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/PropertyVarCircularComponent5.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +Image { + id: image + objectName: "image" + property var imageCanary: 13 +} diff --git a/tests/auto/qml/qqmlecmascript/data/PropertyVarInheritanceComponent.qml b/tests/auto/qml/qqmlecmascript/data/PropertyVarInheritanceComponent.qml new file mode 100644 index 0000000000..b01cf6ed84 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/PropertyVarInheritanceComponent.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +PropertyVarCircularComponent { + id: inheritanceComponent + property int inheritanceIntProperty: 6 + property var inheritanceVarProperty + + function constructGarbage() { + var retn = 1; + var component = Qt.createComponent("PropertyVarCircularComponent2.qml"); + if (component.status == Component.Ready) { + retn = component.createObject(null); // has JavaScript ownership + } + return retn; + } + + Component.onCompleted: { + inheritanceVarProperty = constructGarbage(); + gc(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/PropertyVarOwnershipComponent.qml b/tests/auto/qml/qqmlecmascript/data/PropertyVarOwnershipComponent.qml new file mode 100644 index 0000000000..c1f73d3bac --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/PropertyVarOwnershipComponent.qml @@ -0,0 +1,37 @@ +import QtQuick 2.0 + +Rectangle { + id: rectangle // will have JS ownership + objectName: "rectangle" + width: 10 + height: 10 + property var rectCanary: 5 + + Text { + id: textOne // will have Eventual-JS ownership + objectName: "textOne" + property var textCanary: 11 + property var vp + } + + Text { + id: textTwo + objectName: "textTwo" + property var textCanary: 12 + property var vp + + function constructQObject() { + var component = Qt.createComponent("PropertyVarCircularComponent5.qml"); + if (component.status == Component.Ready) { + textTwo.vp = component.createObject(null); // has JavaScript ownership + } + gc(); + } + + function deassignVp() { + textTwo.textCanary = 22; + textTwo.vp = textTwo.textCanary; + gc(); + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/ScarceResourceSignalComponentVar.qml b/tests/auto/qml/qqmlecmascript/data/ScarceResourceSignalComponentVar.qml new file mode 100644 index 0000000000..d56bd41a99 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/ScarceResourceSignalComponentVar.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +QtObject { + property var scarceResourceCopy + property int width: 5 + signal testSignal + signal testSignal2 +} + diff --git a/tests/auto/qml/qqmlecmascript/data/ScarceResourceSignalComponentVariant.qml b/tests/auto/qml/qqmlecmascript/data/ScarceResourceSignalComponentVariant.qml new file mode 100644 index 0000000000..e10fcfe36a --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/ScarceResourceSignalComponentVariant.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +QtObject { + property variant scarceResourceCopy + property int width: 5 + signal testSignal + signal testSignal2 +} + diff --git a/tests/auto/qml/qqmlecmascript/data/ScarceResourceVarComponent.qml b/tests/auto/qml/qqmlecmascript/data/ScarceResourceVarComponent.qml new file mode 100644 index 0000000000..2cf6b4223b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/ScarceResourceVarComponent.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: first + property var vp: Item { + id: second + property MyScarceResourceObject srp; + srp: MyScarceResourceObject { id: scarceResourceProvider } + property var sr: scarceResourceProvider.scarceResource + property var canary: 5 + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/Scope6Nested.qml b/tests/auto/qml/qqmlecmascript/data/Scope6Nested.qml new file mode 100644 index 0000000000..a3794df22b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/Scope6Nested.qml @@ -0,0 +1,7 @@ +import Qt.test 1.0 + +MyQmlObject { + function runtest(obj) { + return obj.MyQmlObject.value == 19; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/ScopeObject.qml b/tests/auto/qml/qqmlecmascript/data/ScopeObject.qml new file mode 100644 index 0000000000..f341cce3c9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/ScopeObject.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Item { + property int a: 3 + property int binding: myFunction(); + property int binding2: myCompFunction(); + + function myCompFunction() { + return a; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/SequenceConversionComponent.qml b/tests/auto/qml/qqmlecmascript/data/SequenceConversionComponent.qml new file mode 100644 index 0000000000..0c7f60b062 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/SequenceConversionComponent.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MySequenceConversionObject { + id: sccmsco + objectName: "sccmsco" +} diff --git a/tests/auto/qml/qqmlecmascript/data/SpuriousWarning.qml b/tests/auto/qml/qqmlecmascript/data/SpuriousWarning.qml new file mode 100644 index 0000000000..f6398d254d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/SpuriousWarning.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + property int children: root.children.length +} diff --git a/tests/auto/qml/qqmlecmascript/data/TypeForDynamicCreation.qml b/tests/auto/qml/qqmlecmascript/data/TypeForDynamicCreation.qml new file mode 100644 index 0000000000..56e06252c4 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/TypeForDynamicCreation.qml @@ -0,0 +1,2 @@ +import Qt.test 1.0 +MyQmlObject{objectName:"objectThree"} diff --git a/tests/auto/qml/qqmlecmascript/data/aliasBindingsAssignCorrectly.qml b/tests/auto/qml/qqmlecmascript/data/aliasBindingsAssignCorrectly.qml new file mode 100644 index 0000000000..ff6c553c31 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasBindingsAssignCorrectly.qml @@ -0,0 +1,59 @@ +import QtQuick 2.0 + +Item { + id: root + + property bool test: false + + property real testData: 9 + property real testData2: 9 + + states: State { + name: "change" + PropertyChanges { + target: myType + realProperty: if (testData2 > 3) 9; else 11; + } + } + + AliasBindingsAssignCorrectlyType { + id: myType + + aliasProperty: if (testData > 3) 14; else 12; + } + + Component.onCompleted: { + // Check original binding works + if (myType.aliasProperty != 14) return; + + testData = 2; + if (myType.aliasProperty != 12) return; + + // Change binding indirectly by modifying the "realProperty" + root.state = "change"; + if (myType.aliasProperty != 9) return; + + // Check the new binding works + testData2 = 1; + if (myType.aliasProperty != 11) return; + + // Try and trigger the old binding (that should have been removed) + testData = 6; + if (myType.aliasProperty != 11) return; + + // Restore the original binding + root.state = ""; + if (myType.aliasProperty != 14) return; + + // Test the restored binding works + testData = 0; + if (myType.aliasProperty != 12) return; + + // Test the old binding isn't somehow hanging around and still in effect + testData2 = 13; + if (myType.aliasProperty != 12) return; + + test = true; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/aliasBindingsOverrideTarget.2.qml b/tests/auto/qml/qqmlecmascript/data/aliasBindingsOverrideTarget.2.qml new file mode 100644 index 0000000000..bba9033235 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasBindingsOverrideTarget.2.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 + +Item { + id: me + property bool test: false + + property int value: 9 + + AliasBindingsOverrideTargetType { + id: aliasType + pointAliasProperty.x: me.value + } + + Component.onCompleted: { + if (aliasType.pointAliasProperty.x != 9) return; + + me.value = 11; + if (aliasType.pointAliasProperty.x != 11) return; + + aliasType.data = 8; + if (aliasType.pointAliasProperty.x != 11) return; + + me.value = 4; + if (aliasType.pointAliasProperty.x != 4) return; + + test = true; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/aliasBindingsOverrideTarget.3.qml b/tests/auto/qml/qqmlecmascript/data/aliasBindingsOverrideTarget.3.qml new file mode 100644 index 0000000000..3e4cda6ba3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasBindingsOverrideTarget.3.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 + +Item { + id: root + property bool test: false; + + property int value1: 10 + property int value2: 11 + + AliasBindingsOverrideTargetType3 { + id: obj + + testProperty: root.value1 * 9 + aliasProperty: root.value2 * 10 + } + + Component.onCompleted: { + if (obj.testProperty != 110) return; + if (obj.aliasProperty != 110) return; + + test = true; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/aliasBindingsOverrideTarget.qml b/tests/auto/qml/qqmlecmascript/data/aliasBindingsOverrideTarget.qml new file mode 100644 index 0000000000..de5f49ffc5 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasBindingsOverrideTarget.qml @@ -0,0 +1,28 @@ +import QtQuick 2.0 + +Item { + id: me + property bool test: false + + property int value: 9 + + AliasBindingsOverrideTargetType { + id: aliasType + aliasProperty: me.value + } + + Component.onCompleted: { + if (aliasType.aliasProperty != 9) return; + + me.value = 11; + if (aliasType.aliasProperty != 11) return; + + aliasType.data = 8; + if (aliasType.aliasProperty != 11) return; + + me.value = 4; + if (aliasType.aliasProperty != 4) return; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/aliasPropertyAndBinding.qml b/tests/auto/qml/qqmlecmascript/data/aliasPropertyAndBinding.qml new file mode 100644 index 0000000000..f228b2c19f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasPropertyAndBinding.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +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/qml/qqmlecmascript/data/aliasToCompositeElement.qml b/tests/auto/qml/qqmlecmascript/data/aliasToCompositeElement.qml new file mode 100644 index 0000000000..79d6e6887c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasToCompositeElement.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +AliasToCompositeElementType1 { + group.value: 13 +} + diff --git a/tests/auto/qml/qqmlecmascript/data/aliasWritesOverrideBindings.2.qml b/tests/auto/qml/qqmlecmascript/data/aliasWritesOverrideBindings.2.qml new file mode 100644 index 0000000000..b5bc280d11 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasWritesOverrideBindings.2.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 + +Item { + id: me + property bool test: false + + property int value: 9 + + AliasBindingsOverrideTargetType { + id: aliasType + } + + Component.onCompleted: { + if (aliasType.aliasProperty != 294) return; + + aliasType.data = 8; + if (aliasType.aliasProperty != 336) return; + + aliasType.aliasProperty = 4; + if (aliasType.aliasProperty != 4) return; + + aliasType.data = 7; + if (aliasType.aliasProperty != 4) return; + + test = true; + } +} + + diff --git a/tests/auto/qml/qqmlecmascript/data/aliasWritesOverrideBindings.3.qml b/tests/auto/qml/qqmlecmascript/data/aliasWritesOverrideBindings.3.qml new file mode 100644 index 0000000000..6c16ff5604 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasWritesOverrideBindings.3.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 + +Item { + id: me + property bool test: false + + property int value: 9 + + AliasBindingsOverrideTargetType { + id: aliasType + pointAliasProperty.x: 9 + } + + Component.onCompleted: { + if (aliasType.pointAliasProperty.x != 9) return; + + aliasType.data = 8; + if (aliasType.pointAliasProperty.x != 9) return; + + test = true; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/aliasWritesOverrideBindings.qml b/tests/auto/qml/qqmlecmascript/data/aliasWritesOverrideBindings.qml new file mode 100644 index 0000000000..441098bd39 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasWritesOverrideBindings.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 + +Item { + id: me + property bool test: false + + property int value: 9 + + AliasBindingsOverrideTargetType { + id: aliasType + aliasProperty: 11 + } + + Component.onCompleted: { + if (aliasType.aliasProperty != 11) return; + + aliasType.data = 8; + if (aliasType.aliasProperty != 11) return; + + test = true; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/aliasreset/AliasPropertyComponent.qml b/tests/auto/qml/qqmlecmascript/data/aliasreset/AliasPropertyComponent.qml new file mode 100644 index 0000000000..9135e79469 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasreset/AliasPropertyComponent.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +Item { + id: apc + property alias sourceComponent: loader.sourceComponent + + Component { + id: redSquare + Rectangle { color: "red"; width: 10; height: 10 } + } + + Loader { + id: loader + objectName: "loader" + sourceComponent: redSquare + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.1.qml b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.1.qml new file mode 100644 index 0000000000..b855a183ee --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.1.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: first + property bool aliasIsUndefined: false + property alias sourceComponentAlias: loader.sourceComponent + + Component { + id: redSquare + Rectangle { color: "red"; width: 10; height: 10 } + } + + Loader { + id: loader + sourceComponent: redSquare + } + + function resetAliased() { + loader.sourceComponent = undefined; + aliasIsUndefined = (sourceComponentAlias == undefined); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.2.qml b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.2.qml new file mode 100644 index 0000000000..b0bb3681cf --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.2.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: first + property bool loaderSourceComponentIsUndefined: false + property alias sourceComponentAlias: loader.sourceComponent + + Component { + id: redSquare + Rectangle { color: "red"; width: 10; height: 10 } + } + + Loader { + id: loader + sourceComponent: redSquare + } + + function resetAlias() { + sourceComponentAlias = undefined; + loaderSourceComponentIsUndefined = (loader.sourceComponent == undefined); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.3.qml b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.3.qml new file mode 100644 index 0000000000..b318af0138 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.3.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: first + property bool loaderTwoSourceComponentIsUndefined: false + property bool loaderOneSourceComponentIsUndefined: false + property alias sourceComponentAlias: loaderOne.sourceComponent + + Component { + id: redSquare + Rectangle { color: "red"; width: 10; height: 10 } + } + + Loader { + id: loaderOne + sourceComponent: loaderTwo.sourceComponent + } + + Loader { + id: loaderTwo + sourceComponent: redSquare + x: 15 + } + + function resetAlias() { + sourceComponentAlias = undefined; // loaderOne.sourceComponent should be set to undefined instead of l2.sc + loaderOneSourceComponentIsUndefined = (loaderOne.sourceComponent == undefined); // should be true + loaderTwoSourceComponentIsUndefined = (loaderTwo.sourceComponent == undefined); // should be false + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.4.qml b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.4.qml new file mode 100644 index 0000000000..c5f56a8798 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.4.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: first + property alias sourceComponentAlias: loader.sourceComponent + + Component { + id: redSquare + Rectangle { color: "red"; width: 10; height: 10 } + } + + Loader { + id: loader + objectName: "loader" + sourceComponent: redSquare + } + + function resetAlias() { + sourceComponentAlias = undefined; // ensure we don't crash after deletion of loader. + } + + function setAlias() { + sourceComponentAlias = redSquare; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.5.qml b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.5.qml new file mode 100644 index 0000000000..b07db8ba40 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.5.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + + AliasPropertyComponent { + sourceComponent: returnsUndefined() + } + + function returnsUndefined() { + return undefined; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.error.1.qml b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.error.1.qml new file mode 100644 index 0000000000..35c9d6fd5d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasreset/aliasPropertyReset.error.1.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + id: first + property bool aliasedIntIsUndefined: false + property alias intAlias: objprop.intp + + objectProperty: QtObject { + id: objprop + property int intp: 12 + } + + function resetAlias() { + intAlias = undefined; // should error + aliasedIntIsUndefined = (objprop.intp == undefined); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.2.qml b/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.2.qml new file mode 100644 index 0000000000..2c79729651 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.2.qml @@ -0,0 +1,26 @@ +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.75 + 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/qml/qqmlecmascript/data/assignBasicTypes.qml b/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.qml new file mode 100644 index 0000000000..86ff6b6bb3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignBasicTypes.qml @@ -0,0 +1,29 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + Component.onCompleted: { + flagProperty = "FlagVal1 | FlagVal3" + enumProperty = "EnumVal2" + stringProperty = "Hello World!" + uintProperty = 10 + intProperty = -19 + realProperty = 23.2 + doubleProperty = -19.75 + 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/qml/qqmlecmascript/data/assignSequenceTypes.1.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.1.qml new file mode 100644 index 0000000000..be283fdda1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.1.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MySequenceConversionObject { + intListProperty: [1, 2] + qrealListProperty: [1.1, 2.2] + boolListProperty: [false, true] + urlListProperty: [ "http://www.example1.com", "http://www.example2.com" ] + stringListProperty: [ "one", "two" ] + qstringListProperty: [ "one", "two" ] +} diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.2.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.2.qml new file mode 100644 index 0000000000..c8fb28b04e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.2.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MySequenceConversionObject { + intListProperty: 1 + qrealListProperty: 1.1 + boolListProperty: false + urlListProperty: "http://www.example1.com" + stringListProperty: "one" + qstringListProperty: "two" +} diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.3.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.3.qml new file mode 100644 index 0000000000..ad8a92e317 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.3.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MySequenceConversionObject { + intListProperty: 1 + qrealListProperty: 1.1 + boolListProperty: false + urlListProperty: Qt.resolvedUrl("example.html") +} diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.4.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.4.qml new file mode 100644 index 0000000000..a9f2e642d1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.4.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MySequenceConversionObject { + Component.onCompleted: { + intListProperty = [1, 2] + qrealListProperty = [1.1, 2.2] + boolListProperty = [false, true] + urlListProperty = [ "http://www.example1.com", "http://www.example2.com" ] + stringListProperty = [ "one", "two" ] + qstringListProperty = [ "one", "two" ] + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.5.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.5.qml new file mode 100644 index 0000000000..b8697e4290 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.5.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MySequenceConversionObject { + Component.onCompleted: { + intListProperty = 1; + qrealListProperty = 1.1; + boolListProperty = false; + urlListProperty = "http://www.example1.com"; + stringListProperty = "one"; + qstringListProperty = "two"; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.6.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.6.qml new file mode 100644 index 0000000000..7a794eb694 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.6.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MySequenceConversionObject { + Component.onCompleted: { + intListProperty = 1; + qrealListProperty = 1.1; + boolListProperty = false; + urlListProperty = Qt.resolvedUrl("example.html"); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.7.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.7.qml new file mode 100644 index 0000000000..96c0684939 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.7.qml @@ -0,0 +1,42 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + // single url assignment to url list property + MySequenceConversionObject { + id: msco1 + objectName: "msco1" + } + + // single url binding to url list property + MySequenceConversionObject { + id: msco2 + objectName: "msco2" + urlListProperty: "example.html" + } + + // multiple url assignment to url list property + MySequenceConversionObject { + id: msco3 + objectName: "msco3" + } + + // multiple url binding to url list property + MySequenceConversionObject { + id: msco4 + objectName: "msco4" + urlListProperty: [ "example.html", "example2.html" ] + } + + // multiple url binding to url list property - already resolved + MySequenceConversionObject { + id: msco5 + objectName: "msco5" + urlListProperty: [ Qt.resolvedUrl("example.html"), Qt.resolvedUrl("example2.html") ] + } + + Component.onCompleted: { + msco1.urlListProperty = "example.html"; + msco3.urlListProperty = [ "example.html", "example2.html" ]; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/attachedProperty.2.qml b/tests/auto/qml/qqmlecmascript/data/attachedProperty.2.qml new file mode 100644 index 0000000000..a7184c9200 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/attachedProperty.2.qml @@ -0,0 +1,22 @@ +import Qt.test 1.0 +import Qt.test 1.0 as Namespace + +MyQmlObject { + property alias a: me.a + property alias b: me.a + property alias c: me.a + property alias d: me.a + + property MyQmlObject obj + obj: MyQmlObject { + MyQmlObject.value2: 13 + + id: me + property int a: MyQmlObject.value2 * 2 + property int b: Namespace.MyQmlObject.value2 * 2 + property int c: me.Namespace.MyQmlObject.value * 2 + property int d: me.Namespace.MyQmlObject.value * 2 + } +} + + diff --git a/tests/auto/qml/qqmlecmascript/data/attachedProperty.qml b/tests/auto/qml/qqmlecmascript/data/attachedProperty.qml new file mode 100644 index 0000000000..061eda0e54 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/attachedProperty.qml @@ -0,0 +1,11 @@ +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/qml/qqmlecmascript/data/attachedPropertyScope.qml b/tests/auto/qml/qqmlecmascript/data/attachedPropertyScope.qml new file mode 100644 index 0000000000..11fb7ccad2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/attachedPropertyScope.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +QtObject { + property int value: 9 + property int value2 + + MyQmlObject.onMySignal: value2 = value +} diff --git a/tests/auto/qml/qqmlecmascript/data/automaticSemicolon.qml b/tests/auto/qml/qqmlecmascript/data/automaticSemicolon.qml new file mode 100644 index 0000000000..6db68f2328 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/automaticSemicolon.qml @@ -0,0 +1,11 @@ + +import QtQuick 2.0 + +QtObject { + function code() { + if (1) { + var a; + function f1(){}a=1; + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/bindingLoop.qml b/tests/auto/qml/qqmlecmascript/data/bindingLoop.qml new file mode 100644 index 0000000000..80545cf72b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/bindingLoop.qml @@ -0,0 +1,14 @@ +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/qml/qqmlecmascript/data/blank.js b/tests/auto/qml/qqmlecmascript/data/blank.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/blank.js diff --git a/tests/auto/qml/qqmlecmascript/data/boolPropertiesEvaluateAsBool.1.qml b/tests/auto/qml/qqmlecmascript/data/boolPropertiesEvaluateAsBool.1.qml new file mode 100644 index 0000000000..3147f63989 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/boolPropertiesEvaluateAsBool.1.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + stringProperty: trueProperty?'pass':'fail' +} diff --git a/tests/auto/qml/qqmlecmascript/data/boolPropertiesEvaluateAsBool.2.qml b/tests/auto/qml/qqmlecmascript/data/boolPropertiesEvaluateAsBool.2.qml new file mode 100644 index 0000000000..c89bb49b45 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/boolPropertiesEvaluateAsBool.2.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + stringProperty: falseProperty?'fail':'pass' +} diff --git a/tests/auto/qml/qqmlecmascript/data/booleanConversion.qml b/tests/auto/qml/qqmlecmascript/data/booleanConversion.qml new file mode 100644 index 0000000000..a363cf4dd1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/booleanConversion.qml @@ -0,0 +1,28 @@ +import QtQuick 2.0 + +QtObject { + id: root + + property bool test_true1: false + property bool test_true2: false + property bool test_true3: false + property bool test_true4: false + property bool test_true5: false + + property bool test_false1: true + property bool test_false2: true + property bool test_false3: true + + + Component.onCompleted: { + test_true1 = 11 + test_true2 = "Hello" + test_true3 = root + test_true4 = { a: 10, b: 11 } + test_true5 = true + + test_false1 = 0 + test_false2 = null + test_false3 = false + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/bug.1.qml b/tests/auto/qml/qqmlecmascript/data/bug.1.qml new file mode 100644 index 0000000000..31f7c44fcc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/bug.1.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +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/qml/qqmlecmascript/data/canAssignNullToQObject.1.qml b/tests/auto/qml/qqmlecmascript/data/canAssignNullToQObject.1.qml new file mode 100644 index 0000000000..3fd9131b2f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/canAssignNullToQObject.1.qml @@ -0,0 +1,9 @@ +import Qt.test 1.0 + +MyQmlObject { + property bool runTest: false + + property variant a: MyQmlObject {} + + objectProperty: (runTest == false)?a:null +} diff --git a/tests/auto/qml/qqmlecmascript/data/canAssignNullToQObject.2.qml b/tests/auto/qml/qqmlecmascript/data/canAssignNullToQObject.2.qml new file mode 100644 index 0000000000..3fbf931fca --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/canAssignNullToQObject.2.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + objectProperty: MyQmlObject {} + + Component.onCompleted: { + objectProperty = null; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.1.qml b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.1.qml new file mode 100644 index 0000000000..1e92aca825 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.1.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Item { + property int changeCount: 0 + + property bool _nameWithUnderscore: false + + // this should error, since the first alpha isn't capitalised. + on_nameWithUnderscoreChanged: { + changeCount = changeCount + 2; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.2.qml b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.2.qml new file mode 100644 index 0000000000..3549d8c556 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.2.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Item { + property int changeCount: 0 + + property bool ____nameWithUnderscores: false + + // this should error, since the first alpha isn't capitalised + on____nameWithUnderscoresChanged: { + changeCount = changeCount + 3; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.3.qml b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.3.qml new file mode 100644 index 0000000000..d611e0fe30 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.3.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Item { + property int changeCount: 0 + + // invalid property name - we don't allow $ + property bool $nameWithDollarsign: false + + on$NameWithDollarsignChanged: { + changeCount = changeCount + 4; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.4.qml b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.4.qml new file mode 100644 index 0000000000..a6862517c6 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlotErrors.4.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Item { + property int changeCount: 0 + + property bool _6nameWithUnderscoreNumber: false + + // invalid property name - the first character after an underscore must be a letter + on_6NameWithUnderscoreNumberChanged: { + changeCount = changeCount + 3; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlots.qml b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlots.qml new file mode 100644 index 0000000000..f91fb71f1f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/changeslots/propertyChangeSlots.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 + +Item { + property int changeCount: 0 + + property bool normalName: false + property bool _nameWithUnderscore: false + property bool ____nameWithUnderscores: false + + onNormalNameChanged: { + changeCount = changeCount + 1; + } + + on_NameWithUnderscoreChanged: { + changeCount = changeCount + 2; + } + + on____NameWithUnderscoresChanged: { + changeCount = changeCount + 3; + } + + Component.onCompleted: { + normalName = true; + _nameWithUnderscore = true; + ____nameWithUnderscores = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/compiled.qml b/tests/auto/qml/qqmlecmascript/data/compiled.qml new file mode 100644 index 0000000000..7c46306772 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/compiled.qml @@ -0,0 +1,48 @@ +import QtQuick 2.0 + +QtObject { + //real + property real test1: a + b + property real test2: a - b + property bool test3: (a < b) + property bool test4: (a > b) + property bool test5: (a == b) + property bool test6: (a != b) + + //int + property int test7: c + d + property int test8: d - c + property bool test9: (c < d) + property bool test10: (c > d) + property bool test11: (c == d) + property bool test12: (c != d) + + //string + property string test13: e + f + property string test14: e + " " + f + property bool test15: (e == f) + property bool test16: (e != f) + + //type conversion + property int test17: a + property real test18: d + property int test19: g + property real test20: g + property string test21: g + property string test22: h + property bool test23: i + property color test24: j + property color test25: k + + property real a: 4.5 + property real b: 11.2 + property int c: 9 + property int d: 176 + property string e: "Hello" + property string f: "World" + property variant g: 6.7 + property variant h: "!" + property variant i: true + property string j: "#112233" + property string k: "#aa112233" +} diff --git a/tests/auto/qml/qqmlecmascript/data/compositePropertyType.qml b/tests/auto/qml/qqmlecmascript/data/compositePropertyType.qml new file mode 100644 index 0000000000..e97b75c8d0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/compositePropertyType.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +QtObject { + property CustomObject myObject + myObject: CustomObject { } + + Component.onCompleted: console.log(myObject.greeting) +} diff --git a/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.1.qml b/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.1.qml new file mode 100644 index 0000000000..13c5ae5fff --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.1.qml @@ -0,0 +1,8 @@ +import Qt.test 1.0 + +MyQmlObject { + property int c1: 0 + property int c2: c1 + + onBasicSignal: c2 = 13 +} diff --git a/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.2.qml b/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.2.qml new file mode 100644 index 0000000000..207a06b700 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.2.qml @@ -0,0 +1,11 @@ +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/qml/qqmlecmascript/data/constantsOverrideBindings.3.qml b/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.3.qml new file mode 100644 index 0000000000..ca9d1d8ab9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.3.qml @@ -0,0 +1,7 @@ +import Qt.test 1.0 + +MyQmlObject { + property int c1: 0 + property int c2: c1 +} + diff --git a/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.4.qml b/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.4.qml new file mode 100644 index 0000000000..5a2091f71c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/constantsOverrideBindings.4.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 + +MyQmlObject { + property alias c1: myConstants.c1 + property alias c3: myConstants.c3 + + objectProperty: ConstantsOverrideBindings { + id: myConstants + c3: 10 + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/deferredProperties.qml b/tests/auto/qml/qqmlecmascript/data/deferredProperties.qml new file mode 100644 index 0000000000..e01f708a07 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/deferredProperties.qml @@ -0,0 +1,10 @@ +import Qt.test 1.0 + +MyDeferredObject { + id: root + value: 10 + objectProperty: MyQmlObject { + value: root.value + } + objectProperty2: MyQmlObject { id: blah } +} diff --git a/tests/auto/qml/qqmlecmascript/data/deferredPropertiesErrors.qml b/tests/auto/qml/qqmlecmascript/data/deferredPropertiesErrors.qml new file mode 100644 index 0000000000..308a01ce6f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/deferredPropertiesErrors.qml @@ -0,0 +1,10 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyDeferredObject { + value: undefined // error is resolved before complete + objectProperty: undefined // immediate error + objectProperty2: QtObject { + Component.onCompleted: value = 10 + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/deleteLater.qml b/tests/auto/qml/qqmlecmascript/data/deleteLater.qml new file mode 100644 index 0000000000..2a9ce44b20 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/deleteLater.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +QtObject { + id: root + property bool test: false + + Component.onCompleted: { + try { + root.deleteLater() + } catch(e) { + test = true; + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/deleteWhileBindingRunning.qml b/tests/auto/qml/qqmlecmascript/data/deleteWhileBindingRunning.qml new file mode 100644 index 0000000000..b5cc59e2c0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/deleteWhileBindingRunning.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyDeleteObject { + property int result: nestedObject.intProperty + deleteNestedObject +} diff --git a/tests/auto/qml/qqmlecmascript/data/deletedEngine.qml b/tests/auto/qml/qqmlecmascript/data/deletedEngine.qml new file mode 100644 index 0000000000..97acddf5fc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/deletedEngine.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +QtObject { + function calculate() { + return b * 13; + } + + property int a: calculate() + property int b: 3 +} + diff --git a/tests/auto/qml/qqmlecmascript/data/deletedObject.qml b/tests/auto/qml/qqmlecmascript/data/deletedObject.qml new file mode 100644 index 0000000000..24c12bf694 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/deletedObject.qml @@ -0,0 +1,25 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +QtObject { + property variant 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 == null + test4 = obj == null + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/doubleEvaluate.qml b/tests/auto/qml/qqmlecmascript/data/doubleEvaluate.qml new file mode 100644 index 0000000000..0532715432 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/doubleEvaluate.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 + +WriteCounter { + property int x: 0 + value: if (1) x + x +} diff --git a/tests/auto/qml/qqmlecmascript/data/dynamicCreation.helper.qml b/tests/auto/qml/qqmlecmascript/data/dynamicCreation.helper.qml new file mode 100644 index 0000000000..d790d634e9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/dynamicCreation.helper.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 + +MyQmlObject{ + objectName: "objectTwo" +} + diff --git a/tests/auto/qml/qqmlecmascript/data/dynamicCreation.qml b/tests/auto/qml/qqmlecmascript/data/dynamicCreation.qml new file mode 100644 index 0000000000..7b132e1edf --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/dynamicCreation.qml @@ -0,0 +1,27 @@ +import Qt.test 1.0 + +MyQmlObject{ + id: obj + objectName: "obj" + function createOne() + { + obj.objectProperty = Qt.createQmlObject('import Qt.test 1.0; MyQmlObject{objectName:"objectOne"}', obj); + } + + function createTwo() + { + var component = Qt.createComponent('dynamicCreation.helper.qml'); + obj.objectProperty = component.createObject(obj); + } + + function createThree() + { + obj.objectProperty = Qt.createQmlObject('TypeForDynamicCreation{}', obj); + } + + function dontCrash() + { + var component = Qt.createComponent('file-doesnt-exist.qml'); + obj.objectProperty = component.createObject(obj); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/dynamicCreationOwnership.qml b/tests/auto/qml/qqmlecmascript/data/dynamicCreationOwnership.qml new file mode 100644 index 0000000000..ed396d49b0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/dynamicCreationOwnership.qml @@ -0,0 +1,20 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: obj + objectName: "obj" + + MyDynamicCreationDestructionObject { + id: mdcdo + objectName: "mdcdo" + } + + function dynamicallyCreateJsOwnedObject() { + mdcdo.createNew(); + } + + function performGc() { + gc(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/dynamicDeletion.2.qml b/tests/auto/qml/qqmlecmascript/data/dynamicDeletion.2.qml new file mode 100644 index 0000000000..9a5732c194 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/dynamicDeletion.2.qml @@ -0,0 +1,21 @@ +import QtQuick 2.0 + +QtObject { + id: root + + property QtObject objectProperty + + property Component c: Component { + id: componentObject + QtObject { + } + } + + function create() { + objectProperty = c.createObject(root); + } + + function destroy() { + objectProperty.destroy(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/dynamicDeletion.qml b/tests/auto/qml/qqmlecmascript/data/dynamicDeletion.qml new file mode 100644 index 0000000000..f41e5262fd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/dynamicDeletion.qml @@ -0,0 +1,20 @@ +import Qt.test 1.0 + +MyQmlObject{ + id: obj + objectName: "obj" + function create() + { + obj.objectProperty = Qt.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/qml/qqmlecmascript/data/dynamicString.qml b/tests/auto/qml/qqmlecmascript/data/dynamicString.qml new file mode 100644 index 0000000000..5693794c71 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/dynamicString.qml @@ -0,0 +1,16 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyTypeObject { + stringProperty:"string:%0 false:%1 true:%2 uint32:%3 int32:%4 double:%5 date:%6!" + Component.onCompleted: { + var date = new Date(); + date.setDate(11); + date.setMonth(1); + date.setFullYear(2011); + date.setHours(5); + date.setMinutes(30); + date.setSeconds(50); + stringProperty = stringProperty.arg("Hello World").arg(false).arg(true).arg(100).arg(-100).arg(3.1415926).arg(Qt.formatDateTime(date, "yyyy-MM-dd hh::mm:ss")); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/elementAssign.qml b/tests/auto/qml/qqmlecmascript/data/elementAssign.qml new file mode 100644 index 0000000000..0d75cbf6fc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/elementAssign.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +QtObject { + id: root + + property bool test: bound.value == 1923 + + property ElementAssignType element: ElementAssignType { value: 1923 } + property ElementAssignType bound: root.element +} diff --git a/tests/auto/qml/qqmlecmascript/data/enums.1.qml b/tests/auto/qml/qqmlecmascript/data/enums.1.qml new file mode 100644 index 0000000000..6351823230 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/enums.1.qml @@ -0,0 +1,20 @@ +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/qml/qqmlecmascript/data/enums.2.qml b/tests/auto/qml/qqmlecmascript/data/enums.2.qml new file mode 100644 index 0000000000..bdc672fadc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/enums.2.qml @@ -0,0 +1,8 @@ +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/qml/qqmlecmascript/data/eval.qml b/tests/auto/qml/qqmlecmascript/data/eval.qml new file mode 100644 index 0000000000..a752b8c0d3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/eval.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 + +QtObject { + property bool test1: false; + property bool test2: false; + property bool test3: false; + property bool test4: false; + property bool test5: false; + + + property int a: 7 + property int b: 8 + + Component.onCompleted: { + var b = 9; + + test1 = (eval("a") == 7); + test2 = (eval("b") == 9); + try { + eval("c"); + } catch(e) { + test3 = true; + } + test4 = (eval("console") == console); + test5 = (eval("Qt") == Qt); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/exception.js b/tests/auto/qml/qqmlecmascript/data/exception.js new file mode 100644 index 0000000000..160bbfa5b6 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/exception.js @@ -0,0 +1 @@ +throw("Whoops!"); diff --git a/tests/auto/qml/qqmlecmascript/data/exceptionClearsOnReeval.qml b/tests/auto/qml/qqmlecmascript/data/exceptionClearsOnReeval.qml new file mode 100644 index 0000000000..a2f0d1a8b7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/exceptionClearsOnReeval.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 + +MyQmlObject { + property bool test: objectProperty.objectProperty.trueProperty +} + diff --git a/tests/auto/qml/qqmlecmascript/data/exceptionProducesWarning.qml b/tests/auto/qml/qqmlecmascript/data/exceptionProducesWarning.qml new file mode 100644 index 0000000000..b8d5e5e60f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/exceptionProducesWarning.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + Component.onCompleted: + { throw(new Error("JS exception")) } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/exceptionProducesWarning2.qml b/tests/auto/qml/qqmlecmascript/data/exceptionProducesWarning2.qml new file mode 100644 index 0000000000..a4ce55e245 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/exceptionProducesWarning2.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + value: { throw(new Error("JS exception")) } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/extendedObjectPropertyLookup.qml b/tests/auto/qml/qqmlecmascript/data/extendedObjectPropertyLookup.qml new file mode 100644 index 0000000000..2c382e871a --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/extendedObjectPropertyLookup.qml @@ -0,0 +1,8 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +QtObject { + property MyExtendedObject a; + a: MyExtendedObject { id: root } + property int b: Math.max(root.extendedProperty, 0) +} diff --git a/tests/auto/qml/qqmlecmascript/data/extendedObjectPropertyLookup2.qml b/tests/auto/qml/qqmlecmascript/data/extendedObjectPropertyLookup2.qml new file mode 100644 index 0000000000..e4af3359d0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/extendedObjectPropertyLookup2.qml @@ -0,0 +1,14 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +QtObject { + id: root + property MyExtendedObject a; + a: MyExtendedObject { + id: obj + extendedProperty: 42; + } + function getValue() { + return obj.extendedProperty; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/extensionObjects.qml b/tests/auto/qml/qqmlecmascript/data/extensionObjects.qml new file mode 100644 index 0000000000..7734a11dd8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/extensionObjects.qml @@ -0,0 +1,19 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyExtendedObject +{ + baseProperty: baseExtendedProperty + baseExtendedProperty: 13 + + coreProperty: extendedProperty + extendedProperty: 9 + + property QtObject nested: MyExtendedObject { + baseProperty: baseExtendedProperty + baseExtendedProperty: 13 + + coreProperty: extendedProperty + extendedProperty: 9 + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/extensionObjectsPropertyOverride.qml b/tests/auto/qml/qqmlecmascript/data/extensionObjectsPropertyOverride.qml new file mode 100644 index 0000000000..3c443cb975 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/extensionObjectsPropertyOverride.qml @@ -0,0 +1,7 @@ +import Qt.test 1.0 + +OverrideDefaultPropertyObject +{ + MyBaseExtendedObject { + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/forInLoop.qml b/tests/auto/qml/qqmlecmascript/data/forInLoop.qml new file mode 100644 index 0000000000..f14367f177 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/forInLoop.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +QtObject { + property list<QtObject> objects + objects: [QtObject { objectName: "obj1" }, QtObject { objectName: "obj2" }, QtObject { objectName: "obj3" }] + property string listResult + + function listProperty() { + for (var i in objects) + listResult += i + "=" + objects[i].objectName + "|" + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/function.qml b/tests/auto/qml/qqmlecmascript/data/function.qml new file mode 100644 index 0000000000..af2da7023c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/function.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 + +QtObject { + property bool test1: false; + property bool test2: false; + property bool test3: false; + + Component.onCompleted: { + var a = 10; + + var func1 = new Function("a", "return a + 7"); + var func2 = new Function("a", "return Qt.atob(a)"); + var func3 = new Function("return a"); + + test1 = (func1(4) == 11); + test2 = (func2("Hello World!") == Qt.atob("Hello World!")); + try { + func3(); + } catch(e) { + test3 = true; + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/functionAssignment.1.qml b/tests/auto/qml/qqmlecmascript/data/functionAssignment.1.qml new file mode 100644 index 0000000000..09540f1f6e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/functionAssignment.1.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + property variant a: function myFunction() { return 2; } +} diff --git a/tests/auto/qml/qqmlecmascript/data/functionAssignment.2.qml b/tests/auto/qml/qqmlecmascript/data/functionAssignment.2.qml new file mode 100644 index 0000000000..0f78eaf1dc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/functionAssignment.2.qml @@ -0,0 +1,73 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +import "functionAssignment.js" as Script + +MyQmlObject { + property variant a + property int aNumber: 10 + + property bool assignToProperty: false + property bool assignToPropertyFromJsFile: false + + property bool assignWithThis: false + property bool assignWithThisFromJsFile: false + + property bool assignToValueType: false + + property bool assignFuncWithoutReturn: false + property bool assignWrongType: false + property bool assignWrongTypeToValueType: false + + + onAssignToPropertyChanged: { + function myFunction() { + return aNumber * 10; + } + a = myFunction; + } + + property QtObject obj: QtObject { + property int aNumber: 4212 + function myFunction() { + return this.aNumber * 10; // should use the aNumber from root, not this object + } + } + onAssignWithThisChanged: { + a = obj.myFunction; + } + + onAssignToPropertyFromJsFileChanged: { + Script.bindPropertyWithThis() + } + + onAssignWithThisFromJsFileChanged: { + Script.bindProperty() + } + + property Text text: Text { } + onAssignToValueTypeChanged: { + text.font.pixelSize = (function() { return aNumber * 10; }) + a = (function() { return text.font.pixelSize; }) + } + + + // detecting errors: + + onAssignFuncWithoutReturnChanged: { + function myFunction() { + } + a = myFunction; + } + + onAssignWrongTypeChanged: { + function myFunction() { + return 'a string'; + } + aNumber = myFunction; + } + + onAssignWrongTypeToValueTypeChanged: { + text.font.pixelSize = (function() { return 'a string'; }) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/functionAssignment.js b/tests/auto/qml/qqmlecmascript/data/functionAssignment.js new file mode 100644 index 0000000000..14daa7629f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/functionAssignment.js @@ -0,0 +1,17 @@ +function bindProperty() +{ + a = (function(){ return aNumber * 10 }) +} + + +function TestObject() { } +TestObject.prototype.aNumber = 928349 +TestObject.prototype.bindFunction = function() { + return this.aNumber * 10 // this should not use the TestObject's aNumber +} +var testObj = new TestObject() + +function bindPropertyWithThis() +{ + a = testObj.bindFunction +} diff --git a/tests/auto/qml/qqmlecmascript/data/functionErrors.qml b/tests/auto/qml/qqmlecmascript/data/functionErrors.qml new file mode 100644 index 0000000000..230a626600 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/functionErrors.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +QtObject { + function myFunction() { + a = 10; + } + + Component.onCompleted: myFunction(); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.handle.1.qml b/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.handle.1.qml new file mode 100644 index 0000000000..8a06c30d8c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.handle.1.qml @@ -0,0 +1,21 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: obj + objectName: "obj" + property CircularReferenceHandle first + property CircularReferenceHandle second + + CircularReferenceHandle { + id: crh + objectName: "crh" + } + + function createReference() { + first = crh.generate(crh); + second = crh.generate(crh); + // NOTE: manually add reference from first to second + // in unit test prior reparenting and gc. + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.handle.2.qml b/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.handle.2.qml new file mode 100644 index 0000000000..91edc447e2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.handle.2.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: obj + objectName: "obj" + property CircularReferenceHandle first + property CircularReferenceHandle second + + CircularReferenceHandle { + id: crh + objectName: "crh" + } + + function circularReference() { + // generate the circularly referential pair + first = crh.generate(crh); + second = crh.generate(crh); + // note: must manually reparent in unit test + // after setting the handle references. + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.object.1.qml b/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.object.1.qml new file mode 100644 index 0000000000..70e8390677 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.object.1.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: obj + objectName: "obj" + + property CircularReferenceObject first + property CircularReferenceObject second + + + CircularReferenceObject { + id: cro + objectName: "cro" + } + + function createReference() { + // generate the objects + first = cro.generate(cro); // has parent, so won't be collected + second = cro.generate(); // no parent, but will be kept alive by first's reference + first.addReference(second); + + // remove top level references + first = cro; + second = cro; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.object.2.qml b/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.object.2.qml new file mode 100644 index 0000000000..2ddb9253eb --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/handleReferenceManagement.object.2.qml @@ -0,0 +1,28 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: obj + objectName: "obj" + + property CircularReferenceObject first + property CircularReferenceObject second + + + CircularReferenceObject { + id: cro + objectName: "cro" + } + + function circularReference() { + // generate the circularly referential pair - they should still be collected + first = cro.generate(); // no parent, so should be collected + second = cro.generate(); // no parent, so should be collected + first.addReference(second); + second.addReference(first); + + // remove top level references + first = cro; + second = cro; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/idShortcutInvalidates.1.qml b/tests/auto/qml/qqmlecmascript/data/idShortcutInvalidates.1.qml new file mode 100644 index 0000000000..ece23269f1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/idShortcutInvalidates.1.qml @@ -0,0 +1,13 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + objectProperty: if(1) otherObject + + property variant obj + + obj: QtObject { + id: otherObject + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/idShortcutInvalidates.qml b/tests/auto/qml/qqmlecmascript/data/idShortcutInvalidates.qml new file mode 100644 index 0000000000..650ed7c73e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/idShortcutInvalidates.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + objectProperty: otherObject + + property variant obj + + obj: QtObject { + id: otherObject + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/importScope.1.js b/tests/auto/qml/qqmlecmascript/data/importScope.1.js new file mode 100644 index 0000000000..4c556f9e96 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/importScope.1.js @@ -0,0 +1 @@ +var value = 240 diff --git a/tests/auto/qml/qqmlecmascript/data/importScope.2.js b/tests/auto/qml/qqmlecmascript/data/importScope.2.js new file mode 100644 index 0000000000..291fb9d2cc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/importScope.2.js @@ -0,0 +1,3 @@ +function getValue() { + return ImportScope1.value +} diff --git a/tests/auto/qml/qqmlecmascript/data/importScope.qml b/tests/auto/qml/qqmlecmascript/data/importScope.qml new file mode 100644 index 0000000000..9b907f11f9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/importScope.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 +import "importScope.1.js" as ImportScope1 +import "importScope.2.js" as ImportScope2 + +QtObject { + property int test: ImportScope2.getValue() +} diff --git a/tests/auto/qml/qqmlecmascript/data/in.qml b/tests/auto/qml/qqmlecmascript/data/in.qml new file mode 100644 index 0000000000..f84c9a1481 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/in.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +Item { + id: root + property bool test1: "x" in root + property bool test2: !("foo" in root) +} diff --git a/tests/auto/qml/qqmlecmascript/data/include.js b/tests/auto/qml/qqmlecmascript/data/include.js new file mode 100644 index 0000000000..232fd808f8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include.js @@ -0,0 +1,8 @@ +var test1 = true +var test2 = false +var test3 = false + +function go() { + Qt.include("js/include2.js"); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/include.qml b/tests/auto/qml/qqmlecmascript/data/include.qml new file mode 100644 index 0000000000..5ce2ed78ec --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 +import "include.js" as IncludeTest + +QtObject { + property int test0: 0 + property bool test1: false + property bool test2: false + property bool test2_1: false + property bool test3: false + property bool test3_1: false + + property int testValue: 99 + + Component.onCompleted: { + IncludeTest.go(); + test0 = IncludeTest.value + test1 = IncludeTest.test1 + test2 = IncludeTest.test2 + test2_1 = IncludeTest.test2_1 + test3 = IncludeTest.test3 + test3_1 = IncludeTest.test3_1 + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/include_callback.js b/tests/auto/qml/qqmlecmascript/data/include_callback.js new file mode 100644 index 0000000000..ea19eba300 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_callback.js @@ -0,0 +1,11 @@ +function go() { + var a = Qt.include("missing.js", function(o) { test2 = o.status == o.NETWORK_ERROR }); + test1 = a.status == a.NETWORK_ERROR + + var b = Qt.include("blank.js", function(o) { test4 = o.status == o.OK }); + test3 = b.status == b.OK + + var c = Qt.include("exception.js", function(o) { test6 = o.status == o.EXCEPTION }); + test5 = c.status == c.EXCEPTION +} + diff --git a/tests/auto/qml/qqmlecmascript/data/include_callback.qml b/tests/auto/qml/qqmlecmascript/data/include_callback.qml new file mode 100644 index 0000000000..fbebcdcd58 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_callback.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 +import "include_callback.js" as IncludeTest + +QtObject { + property bool test1: false + property bool test2: false + property bool test3: false + property bool test4: false + property bool test5: false + property bool test6: false + + Component.onCompleted: { + IncludeTest.go(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/include_pragma.qml b/tests/auto/qml/qqmlecmascript/data/include_pragma.qml new file mode 100644 index 0000000000..7b23c76baa --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_pragma.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 +import "include_pragma_outer.js" as Script + +Item { + property int test1 + + Component.onCompleted: { + test1 = Script.callFunction() + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/include_pragma_inner.js b/tests/auto/qml/qqmlecmascript/data/include_pragma_inner.js new file mode 100644 index 0000000000..a0380a25df --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_pragma_inner.js @@ -0,0 +1,5 @@ +.pragma library + +function getValue() { + return 100; +} diff --git a/tests/auto/qml/qqmlecmascript/data/include_pragma_outer.js b/tests/auto/qml/qqmlecmascript/data/include_pragma_outer.js new file mode 100644 index 0000000000..d87bafc816 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_pragma_outer.js @@ -0,0 +1,6 @@ +Qt.include("include_pragma_inner.js") + +function callFunction() { + return getValue(); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/include_remote.js b/tests/auto/qml/qqmlecmascript/data/include_remote.js new file mode 100644 index 0000000000..e6a4676819 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_remote.js @@ -0,0 +1,26 @@ +var myvar = 10; + +function go() +{ + var a = Qt.include("http://127.0.0.1:8111/remote_file.js", + function(o) { + test2 = o.status == o.OK + test3 = a.status == a.OK + test4 = myvar == 13 + + done = true; + }); + test1 = a.status == a.LOADING + + + var b = Qt.include("http://127.0.0.1:8111/exception.js", + function(o) { + test7 = o.status == o.EXCEPTION + test8 = b.status == a.EXCEPTION + test9 = b.exception.toString() == "Whoops!"; + test10 = o.exception.toString() == "Whoops!"; + + done2 = true; + }); + test6 = b.status == b.LOADING +} diff --git a/tests/auto/qml/qqmlecmascript/data/include_remote.qml b/tests/auto/qml/qqmlecmascript/data/include_remote.qml new file mode 100644 index 0000000000..fe020a55df --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_remote.qml @@ -0,0 +1,21 @@ +import QtQuick 2.0 +import "include_remote.js" as IncludeTest + +QtObject { + property bool done: false + property bool done2: false + + property bool test1: false + property bool test2: false + property bool test3: false + property bool test4: false + property bool test5: false + + property bool test6: false + property bool test7: false + property bool test8: false + property bool test9: false + property bool test10: false + + Component.onCompleted: IncludeTest.go(); +} diff --git a/tests/auto/qml/qqmlecmascript/data/include_remote_missing.js b/tests/auto/qml/qqmlecmascript/data/include_remote_missing.js new file mode 100644 index 0000000000..cc90860cc9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_remote_missing.js @@ -0,0 +1,13 @@ +function go() +{ + var a = Qt.include("http://127.0.0.1:8111/missing.js", + function(o) { + test2 = o.status == o.NETWORK_ERROR + test3 = a.status == a.NETWORK_ERROR + + done = true; + }); + + test1 = a.status == a.LOADING +} + diff --git a/tests/auto/qml/qqmlecmascript/data/include_remote_missing.qml b/tests/auto/qml/qqmlecmascript/data/include_remote_missing.qml new file mode 100644 index 0000000000..e8ef609fed --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_remote_missing.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 +import "include_remote_missing.js" as IncludeTest + +QtObject { + property bool done: false + + property bool test1: false + property bool test2: false + property bool test3: false + + Component.onCompleted: IncludeTest.go(); +} diff --git a/tests/auto/qml/qqmlecmascript/data/include_shared.js b/tests/auto/qml/qqmlecmascript/data/include_shared.js new file mode 100644 index 0000000000..a49c07bbfc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_shared.js @@ -0,0 +1,12 @@ +.pragma library + +var test1 = true +var test2 = false +var test3 = false + +var testValue = 99; + +function go() { + Qt.include("js/include2.js"); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/include_shared.qml b/tests/auto/qml/qqmlecmascript/data/include_shared.qml new file mode 100644 index 0000000000..28b1003fd4 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/include_shared.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 +import "include_shared.js" as IncludeTest + +QtObject { + property int test0: 0 + property bool test1: false + property bool test2: false + property bool test2_1: false + property bool test3: false + property bool test3_1: false + + Component.onCompleted: { + IncludeTest.go(); + test0 = IncludeTest.value + test1 = IncludeTest.test1 + test2 = IncludeTest.test2 + test2_1 = IncludeTest.test2_1 + test3 = IncludeTest.test3 + test3_1 = IncludeTest.test3_1 + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/invokableObjectArg.qml b/tests/auto/qml/qqmlecmascript/data/invokableObjectArg.qml new file mode 100644 index 0000000000..160a90b574 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/invokableObjectArg.qml @@ -0,0 +1,9 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + id: root + Component.onCompleted: { + root.myinvokable(root); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/invokableObjectRet.qml b/tests/auto/qml/qqmlecmascript/data/invokableObjectRet.qml new file mode 100644 index 0000000000..4612273727 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/invokableObjectRet.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + id: root + property bool test: false + Component.onCompleted: { + test = (root.returnme() == root) + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/js/include2.js b/tests/auto/qml/qqmlecmascript/data/js/include2.js new file mode 100644 index 0000000000..2a0c039dfa --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/js/include2.js @@ -0,0 +1,4 @@ +test2 = true +var test2_1 = true + +Qt.include("include3.js"); diff --git a/tests/auto/qml/qqmlecmascript/data/js/include3.js b/tests/auto/qml/qqmlecmascript/data/js/include3.js new file mode 100644 index 0000000000..84b2770b6f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/js/include3.js @@ -0,0 +1,3 @@ +test3 = true +var test3_1 = true +var value = testValue diff --git a/tests/auto/qml/qqmlecmascript/data/jsObject.qml b/tests/auto/qml/qqmlecmascript/data/jsObject.qml new file mode 100644 index 0000000000..4223c25f31 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsObject.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +QtObject { + property int test + + Component.onCompleted: { + var o = new Object; + o.test = 92; + test = o.test; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/SpecialRectangleOne.qml b/tests/auto/qml/qqmlecmascript/data/jsimport/SpecialRectangleOne.qml new file mode 100644 index 0000000000..97c72bd9a6 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/SpecialRectangleOne.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +import "importPragmaLibrary.js" as TestPragmaLibraryImport + +Rectangle { + width: TestPragmaLibraryImport.importIncrementedValue() + height: width + 15 + color: "red" +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/SpecialRectangleTwo.qml b/tests/auto/qml/qqmlecmascript/data/jsimport/SpecialRectangleTwo.qml new file mode 100644 index 0000000000..d006343782 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/SpecialRectangleTwo.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +import "importPragmaLibrary.js" as TestPragmaLibraryImport + +Rectangle { + width: TestPragmaLibraryImport.importIncrementedValue() + height: width + 5 + color: "blue" +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/importFive.js b/tests/auto/qml/qqmlecmascript/data/jsimport/importFive.js new file mode 100644 index 0000000000..e458094552 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/importFive.js @@ -0,0 +1,3 @@ +function importFiveFunction() { + return '5'; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/importFour.js b/tests/auto/qml/qqmlecmascript/data/jsimport/importFour.js new file mode 100644 index 0000000000..faddc15c9d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/importFour.js @@ -0,0 +1,9 @@ +.pragma library + +function importFourFunction() { + return '4'; +} + +function greetingString() { + return 'Hello, World!'; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/importOne.js b/tests/auto/qml/qqmlecmascript/data/jsimport/importOne.js new file mode 100644 index 0000000000..338c4e042f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/importOne.js @@ -0,0 +1,13 @@ +.import "importTwo.js" as ImportTwoJs +.import "importThree.js" as ImportThreeJs + +function greetingString() { + if (ImportTwoJs.greetingString().length > 0) { + return ImportTwoJs.greetingString(); + } + return ImportThreeJs.greetingString(); +} + +function importOneFunction() { + return '1'; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/importPragmaLibrary.js b/tests/auto/qml/qqmlecmascript/data/jsimport/importPragmaLibrary.js new file mode 100644 index 0000000000..c746fef14b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/importPragmaLibrary.js @@ -0,0 +1,9 @@ +.pragma library + +var i = 4; + +// .pragma library, so should be callable from multiple .qml with shared i. +function importIncrementedValue() { + i = i + 1; + return i; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/importPragmaLibraryWithImports.js b/tests/auto/qml/qqmlecmascript/data/jsimport/importPragmaLibraryWithImports.js new file mode 100644 index 0000000000..3f2e6589dd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/importPragmaLibraryWithImports.js @@ -0,0 +1,9 @@ +.pragma library +.import "importFive.js" as ImportFive + +var i = 4; + +function importIncrementedValue() { + i = i + 1; + return (i + ImportFive.importFiveFunction()); // i + '5' (not i+5) +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/importPragmaLibraryWithPragmaLibraryImports.js b/tests/auto/qml/qqmlecmascript/data/jsimport/importPragmaLibraryWithPragmaLibraryImports.js new file mode 100644 index 0000000000..fa6497d99b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/importPragmaLibraryWithPragmaLibraryImports.js @@ -0,0 +1,11 @@ +.pragma library +.import "importPragmaLibrary.js" as LibraryImport + +var i = 10; + +function importIncrementedValue() { + i = i + 1; + // because LibraryImport is shared, and used in previous tests, + // the value will be large (already incremented a bunch of times). + return (i + LibraryImport.importIncrementedValue()); +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/importThree.js b/tests/auto/qml/qqmlecmascript/data/jsimport/importThree.js new file mode 100644 index 0000000000..3917134ee2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/importThree.js @@ -0,0 +1,9 @@ +.import "importFour.js" as ImportFourJs + +function greetingString() { + return ImportFourJs.greetingString(); +} + +function importThreeFunction() { + return '3'; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/importTwo.js b/tests/auto/qml/qqmlecmascript/data/jsimport/importTwo.js new file mode 100644 index 0000000000..45b3c9a74d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/importTwo.js @@ -0,0 +1,10 @@ +.import "importFour.js" as ImportFourJs +.import "importFive.js" as ImportFiveJs + +function greetingString() { + return ImportFourJs.greetingString(); +} + +function importTwoFunction() { + return '2'; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/importWithNoImports.js b/tests/auto/qml/qqmlecmascript/data/jsimport/importWithNoImports.js new file mode 100644 index 0000000000..83426c425c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/importWithNoImports.js @@ -0,0 +1,11 @@ +// This js file has no imports, and so should inherit +// scope from the QML file which includes it. + +function componentError() { + var i = 5; + var errorIsOne = Component.error == 1; + if (errorIsOne == true) { + i = i + 7; + } + return i; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/testImport.qml b/tests/auto/qml/qqmlecmascript/data/jsimport/testImport.qml new file mode 100644 index 0000000000..456a10c7f0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/testImport.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +import "testScriptImport.js" as TestScriptImport +import "testModuleImport.js" as TestModuleImport + +QtObject { + id: testQtObject + + property string importedScriptStringValue: TestScriptImport.greetingText + property int importedScriptFunctionValue: TestScriptImport.randomInteger(1, 20) + + property int importedModuleAttachedPropertyValue: TestModuleImport.importedAttachedPropertyValue(testQtObject) + property int importedModuleEnumValue: TestModuleImport.importedEnumValue +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/testImportPragmaLibrary.qml b/tests/auto/qml/qqmlecmascript/data/jsimport/testImportPragmaLibrary.qml new file mode 100644 index 0000000000..29de15c197 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/testImportPragmaLibrary.qml @@ -0,0 +1,20 @@ +import QtQuick 2.0 + +// We use the components specified in SpecialRectangleOne.qml and SpecialRectangleTwo.qml + +QtObject { + id: testQtObject + + property SpecialRectangleOne a; + property SpecialRectangleTwo b; + + a: SpecialRectangleOne { + id: rectangleOne + } + b: SpecialRectangleTwo { + id: rectangleTwo + } + + // this should be: (5 + 15) + (6 + 5) == 31 + property int testValue: rectangleOne.height + rectangleTwo.height +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/testImportPragmaLibraryWithImports.qml b/tests/auto/qml/qqmlecmascript/data/jsimport/testImportPragmaLibraryWithImports.qml new file mode 100644 index 0000000000..6a7459d3bb --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/testImportPragmaLibraryWithImports.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 +import "importPragmaLibraryWithImports.js" as LibraryImport + +QtObject { + id: root + property int testValue: LibraryImport.importIncrementedValue(); // valueOf(4 + 1 + '5') = valueOf('55') = 55 +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/testImportPragmaLibraryWithPragmaLibraryImports.qml b/tests/auto/qml/qqmlecmascript/data/jsimport/testImportPragmaLibraryWithPragmaLibraryImports.qml new file mode 100644 index 0000000000..01f08dbdc3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/testImportPragmaLibraryWithPragmaLibraryImports.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 +import "importPragmaLibraryWithPragmaLibraryImports.js" as LibraryImport + +QtObject { + id: root + property int testValue: LibraryImport.importIncrementedValue(); // 10 + 1 + (7 due to previous tests) = 18 +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/testImportScoping.qml b/tests/auto/qml/qqmlecmascript/data/jsimport/testImportScoping.qml new file mode 100644 index 0000000000..aff61cc436 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/testImportScoping.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +// For backward compatibility, importing a script which has no imports, +// should run the script in the parent context. See QTBUG-17518. + +import "importWithNoImports.js" as TestNoImportScoping + +QtObject { + id: testQtObject + property int componentError: TestNoImportScoping.componentError() +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/testModuleImport.js b/tests/auto/qml/qqmlecmascript/data/jsimport/testModuleImport.js new file mode 100644 index 0000000000..69bc1c9887 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/testModuleImport.js @@ -0,0 +1,8 @@ +.import Qt.test 1.0 as JsQtTest // test that we can import elements from .js files + +function importedAttachedPropertyValue(obj) { + return obj.JsQtTest.MyQmlObject.value; // attached property, value = 19. +} + +var importedEnumValue = JsQtTest.MyQmlObject.EnumValue3 // the actual value of this enum value is "2" + diff --git a/tests/auto/qml/qqmlecmascript/data/jsimport/testScriptImport.js b/tests/auto/qml/qqmlecmascript/data/jsimport/testScriptImport.js new file mode 100644 index 0000000000..2ecccd8816 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimport/testScriptImport.js @@ -0,0 +1,11 @@ +.import "importOne.js" as ImportOneJs // test that we can import scripts from .js files + +var greetingText = ImportOneJs.greetingString() + +function randomInteger(min, max) { + if (max > min) { + if (min > 10) return min; + return max; + } + return min; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/failFive.qml b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failFive.qml new file mode 100644 index 0000000000..73193a35a5 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failFive.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +// This should fail, since if the script does have imports +// of its own, it should run in its own context. + +import "importWithImports.js" as TestImportScoping + +QtObject { + id: testQtObject + property int componentError: TestImportScoping.componentError() +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/failFour.qml b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failFour.qml new file mode 100644 index 0000000000..ef2fc591b3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failFour.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +import "testModuleImport.js" as TestModuleImport + +QtObject { + property int importedModuleEnumValue: JsQtTest.MyQmlObject.EnumValue3 // should fail - the typenames available in TestModuleImport should not be available in this scope +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/failOne.qml b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failOne.qml new file mode 100644 index 0000000000..d0c37ad9ba --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failOne.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +import "testScriptImport.js" as TestScriptImport + +QtObject { + property string importScriptFunctionValue: TestScriptImport.ImportOneJs.greetingString() // should fail - the context of TestScriptImport is private to TestScriptImport. +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/failThree.qml b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failThree.qml new file mode 100644 index 0000000000..edd103bd82 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failThree.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +import "testModuleImport.js" as TestModuleImport + +QtObject { + id: testQtObject + property int importedModuleAttachedPropertyValue: testQtObject.TestModuleImport.JsQtTest.MyQmlObject.value // should fail - the context of TestScriptImport is private to TestScriptImport. +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/failTwo.qml b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failTwo.qml new file mode 100644 index 0000000000..28e2026f8d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/failTwo.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +import "testScriptImport.js" as TestScriptImport + +QtObject { + property string importScriptFunctionValue: ImportOneJs.greetingString() // should fail - the typenames in TestScriptImport should not be visible from this scope +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/importOne.js b/tests/auto/qml/qqmlecmascript/data/jsimportfail/importOne.js new file mode 100644 index 0000000000..45fd9c75dd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/importOne.js @@ -0,0 +1,7 @@ +function greetingString() { + return 'Hello, World!'; +} + +function importOneFunction() { + return '1'; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/importPragmaLibrary.js b/tests/auto/qml/qqmlecmascript/data/jsimportfail/importPragmaLibrary.js new file mode 100644 index 0000000000..ad0e6946a2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/importPragmaLibrary.js @@ -0,0 +1,11 @@ +.pragma library + +// .pragma library, so shouldn't inherit imports from any .qml file. +function importValue() { + var i = 3; + var errorIsOne = Component.error == 1; // this line should fail. + if (errorIsOne == true) { + i = i + 4; + } + return i; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/importWithImports.js b/tests/auto/qml/qqmlecmascript/data/jsimportfail/importWithImports.js new file mode 100644 index 0000000000..6d77ceccb1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/importWithImports.js @@ -0,0 +1,13 @@ +.import "importOne.js" as ImportOne + +// This js file has imports, so should not inherit +// scope from the QML file which includes it. + +function componentError() { + var i = 3; + var errorIsOne = Component.error == 1; // this line should fail. + if (errorIsOne == true) { + i = i + 4; + } + return i; +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/testImportPragmaLibrary.qml b/tests/auto/qml/qqmlecmascript/data/jsimportfail/testImportPragmaLibrary.qml new file mode 100644 index 0000000000..f04ce007d8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/testImportPragmaLibrary.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +import "importPragmaLibrary.js" as ImportPragmaLibrary + +QtObject { + id: testQtObject + property int testValue: ImportPragmaLibrary.importValue() +} diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/testModuleImport.js b/tests/auto/qml/qqmlecmascript/data/jsimportfail/testModuleImport.js new file mode 100644 index 0000000000..69bc1c9887 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/testModuleImport.js @@ -0,0 +1,8 @@ +.import Qt.test 1.0 as JsQtTest // test that we can import elements from .js files + +function importedAttachedPropertyValue(obj) { + return obj.JsQtTest.MyQmlObject.value; // attached property, value = 19. +} + +var importedEnumValue = JsQtTest.MyQmlObject.EnumValue3 // the actual value of this enum value is "2" + diff --git a/tests/auto/qml/qqmlecmascript/data/jsimportfail/testScriptImport.js b/tests/auto/qml/qqmlecmascript/data/jsimportfail/testScriptImport.js new file mode 100644 index 0000000000..2ecccd8816 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/jsimportfail/testScriptImport.js @@ -0,0 +1,11 @@ +.import "importOne.js" as ImportOneJs // test that we can import scripts from .js files + +var greetingText = ImportOneJs.greetingString() + +function randomInteger(min, max) { + if (max > min) { + if (min > 10) return min; + return max; + } + return min; +} diff --git a/tests/auto/qml/qqmlecmascript/data/libraryScriptAssert.js b/tests/auto/qml/qqmlecmascript/data/libraryScriptAssert.js new file mode 100644 index 0000000000..3ffdb339ad --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/libraryScriptAssert.js @@ -0,0 +1,6 @@ +.pragma library + +function test(target) +{ + var a = target.a; +} diff --git a/tests/auto/qml/qqmlecmascript/data/libraryScriptAssert.qml b/tests/auto/qml/qqmlecmascript/data/libraryScriptAssert.qml new file mode 100644 index 0000000000..5884e2719b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/libraryScriptAssert.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 +import "libraryScriptAssert.js" as Test + +QtObject { + id: root + Component.onCompleted: Test.test(root); +} diff --git a/tests/auto/qml/qqmlecmascript/data/listAssignment.qml b/tests/auto/qml/qqmlecmascript/data/listAssignment.qml new file mode 100644 index 0000000000..6e6039715b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/listAssignment.qml @@ -0,0 +1,20 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + width: 640 + height: 480 + + property int list1length: list1.length + + property list<MyQmlObject> list1 + property list<MyQmlObject> list2: [ + MyQmlObject { id: one; value: 100 }, + MyQmlObject { id: two; value: 300 } + ] + + Component.onCompleted: { + root.list1 = root.list2; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/listProperties.qml b/tests/auto/qml/qqmlecmascript/data/listProperties.qml new file mode 100644 index 0000000000..bdb1265a21 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/listProperties.qml @@ -0,0 +1,24 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + id: root + + objectListProperty: [ + QtObject { property int a: 10 }, + QtObject { property int a: 11 } + ] + + 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/qml/qqmlecmascript/data/listToVariant.qml b/tests/auto/qml/qqmlecmascript/data/listToVariant.qml new file mode 100644 index 0000000000..690024b928 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/listToVariant.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + property variant test: children +} diff --git a/tests/auto/qml/qqmlecmascript/data/metaobjectRevision.qml b/tests/auto/qml/qqmlecmascript/data/metaobjectRevision.qml new file mode 100644 index 0000000000..77accd80de --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/metaobjectRevision.qml @@ -0,0 +1,7 @@ +import Qt.test 1.1 + +MyRevisionedClass +{ + prop1: prop2 + onSignal1: method2() +} diff --git a/tests/auto/qml/qqmlecmascript/data/metaobjectRevision2.qml b/tests/auto/qml/qqmlecmascript/data/metaobjectRevision2.qml new file mode 100644 index 0000000000..36057cb902 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/metaobjectRevision2.qml @@ -0,0 +1,9 @@ +import Qt.test 1.1 + +MyRevisionedSubclass +{ + prop1: prop3 + onSignal1: method2() + prop3: prop4 + onSignal3: method4() +} diff --git a/tests/auto/qml/qqmlecmascript/data/metaobjectRevision3.qml b/tests/auto/qml/qqmlecmascript/data/metaobjectRevision3.qml new file mode 100644 index 0000000000..81769e98f7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/metaobjectRevision3.qml @@ -0,0 +1,8 @@ +import Qt.test 1.0 + +MyRevisionedSubclass +{ + prop1: prop3 + onSignal1: method1() + onSignal3: method3() +} diff --git a/tests/auto/qml/qqmlecmascript/data/metaobjectRevision4.qml b/tests/auto/qml/qqmlecmascript/data/metaobjectRevision4.qml new file mode 100644 index 0000000000..6ebe4790bb --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/metaobjectRevision4.qml @@ -0,0 +1,14 @@ +import Qt.test 1.1 +import QtQuick 2.0 + +QtObject { + property variant a + property real test + + a: MyRevisionedClass { + prop2: 11 + + Component.onCompleted: test = prop2 + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/metaobjectRevisionErrors.qml b/tests/auto/qml/qqmlecmascript/data/metaobjectRevisionErrors.qml new file mode 100644 index 0000000000..8a7e24d788 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/metaobjectRevisionErrors.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyRevisionedClass +{ + // Will not hit optimizer + property real p1: prop1 % 3 + property real p2: prop2 % 3 + + // Should hit optimizer + property real p3: prop2 + + Component.onCompleted: method2() +} diff --git a/tests/auto/qml/qqmlecmascript/data/metaobjectRevisionErrors2.qml b/tests/auto/qml/qqmlecmascript/data/metaobjectRevisionErrors2.qml new file mode 100644 index 0000000000..43e87948cd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/metaobjectRevisionErrors2.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyRevisionedSubclass +{ + // Will not hit optimizer + property real p1: prop1 % 3 + property real p2: prop2 % 3 + property real p3: prop3 % 3 + property real p4: prop4 % 3 + + // Should hit optimizer + property real p5: prop1 + property real p6: prop2 + property real p7: prop3 + property real p8: prop4 + + Component.onCompleted: { + method1() + method2() + method3() + method4() + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/metaobjectRevisionErrors3.qml b/tests/auto/qml/qqmlecmascript/data/metaobjectRevisionErrors3.qml new file mode 100644 index 0000000000..2f82d685fa --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/metaobjectRevisionErrors3.qml @@ -0,0 +1,36 @@ +import QtQuick 2.0 +import Qt.test 1.1 + +MyRevisionedSubclass +{ + // Will not hit optimizer + property real pA: propA % 3 + property real pB: propB % 3 + property real pC: propC % 3 + property real pD: propD % 3 + property real p1: prop1 % 3 + property real p2: prop2 % 3 + property real p3: prop3 % 3 + property real p4: prop4 % 3 + + // Should hit optimizer + property real pE: propA + property real pF: propB + property real pG: propC + property real pH: propD + property real p5: prop1 + property real p6: prop2 + property real p7: prop3 + property real p8: prop4 + + Component.onCompleted: { + methodA() + methodB() + methodC() + methodD() + method1() + method2() + method3() + method4() + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/methods.1.qml b/tests/auto/qml/qqmlecmascript/data/methods.1.qml new file mode 100644 index 0000000000..0bbee16df8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/methods.1.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 + +MyQmlObject { + id: myObject + onBasicSignal: myObject.methodNoArgs() +} diff --git a/tests/auto/qml/qqmlecmascript/data/methods.2.qml b/tests/auto/qml/qqmlecmascript/data/methods.2.qml new file mode 100644 index 0000000000..9f0c6b15fe --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/methods.2.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 + +MyQmlObject { + id: myObject + onBasicSignal: myObject.method(163) +} diff --git a/tests/auto/qml/qqmlecmascript/data/methods.3.qml b/tests/auto/qml/qqmlecmascript/data/methods.3.qml new file mode 100644 index 0000000000..365780a560 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/methods.3.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +QtObject { + function testFunction() { return 19; } + + property int test: testFunction() +} diff --git a/tests/auto/qml/qqmlecmascript/data/methods.4.qml b/tests/auto/qml/qqmlecmascript/data/methods.4.qml new file mode 100644 index 0000000000..a3bd7bebf8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/methods.4.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +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/qml/qqmlecmascript/data/methods.5.qml b/tests/auto/qml/qqmlecmascript/data/methods.5.qml new file mode 100644 index 0000000000..ede2759e2e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/methods.5.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + property alias blah: item.x + Item { id: item } + + function testFunction() { return 9; } + property int test: testFunction(); +} diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/moduleApiMajorVersionFail.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/moduleApiMajorVersionFail.qml new file mode 100644 index 0000000000..fb050f65bc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/moduleApiMajorVersionFail.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +// this qml file attempts to import an invalid version of a qobject module API. + +import Qt.test.qobjectApi 4.0 as QtTestMajorVersionQObjectApi // qobject module API installed into existing uri with nonexistent major version + +QtObject { + property int qobjectMajorVersionTest: QtTestMajorVersionQObjectApi.qobjectTestProperty +} + diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/moduleApiMinorVersionFail.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/moduleApiMinorVersionFail.qml new file mode 100644 index 0000000000..e06be667f7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/moduleApiMinorVersionFail.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +// this qml file attempts to import an invalid version of a qobject module API. + +import Qt.test.qobjectApi 1.2 as QtTestMinorVersionQObjectApi // qobject module API installed into existing uri with nonexistent minor version + +QtObject { + property int qobjectMinorVersionTest: QtTestMinorVersionedQObjectApi.qobjectTestProperty +} + diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApi.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApi.qml new file mode 100644 index 0000000000..718a64652d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApi.qml @@ -0,0 +1,21 @@ +import QtQuick 2.0 + +import Qt.test 1.0 as QtTest // module API installed into existing uri +import Qt.test.qobjectApi 1.0 as QtTestQObjectApi // qobject module API installed into new uri +import Qt.test.qobjectApi 1.3 as QtTestMinorVersionQObjectApi // qobject module API installed into existing uri with new minor version +import Qt.test.qobjectApi 2.0 as QtTestMajorVersionQObjectApi // qobject module API installed into existing uri with new major version +import Qt.test.qobjectApiParented 1.0 as QtTestParentedQObjectApi // qobject (with parent) module API installed into a new uri + +QtObject { + property int existingUriTest: QtTest.qobjectTestProperty + property int qobjectTest: QtTestQObjectApi.qobjectTestProperty + property int qobjectMethodTest: 2 + property int qobjectMinorVersionTest: QtTestMinorVersionQObjectApi.qobjectTestProperty + property int qobjectMajorVersionTest: QtTestMajorVersionQObjectApi.qobjectTestProperty + property int qobjectParentedTest: QtTestParentedQObjectApi.qobjectTestProperty + + Component.onCompleted: { + qobjectMethodTest = QtTestQObjectApi.qobjectTestMethod(); + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiCaching.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiCaching.qml new file mode 100644 index 0000000000..56a55e4e9b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiCaching.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +import Qt.test 1.0 as QtTest // module API installed into existing uri +import Qt.test.qobjectApiParented 1.0 as QtTestParentedQObjectApi // qobject (with parent) module API installed into a new uri + +QtObject { + property int existingUriTest: QtTest.qobjectTestProperty + property int qobjectParentedTest: QtTestParentedQObjectApi.qobjectTestProperty +} + diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiEnums.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiEnums.qml new file mode 100644 index 0000000000..da5ffd5e76 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiEnums.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import Qt.test.qobjectApi 1.0 as QtTestQObjectApi // qobject module API installed into new uri + +QtObject { + property int enumValue: QtTestQObjectApi.EnumValue2; + property int enumMethod: QtTestQObjectApi.qobjectEnumTestMethod(QtTestQObjectApi.EnumValue1); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiWriting.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiWriting.qml new file mode 100644 index 0000000000..be647ca57f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/qobjectModuleApiWriting.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 +import Qt.test 1.0 as QtTest // qobject module API installed into existing uri + +QtObject { + property int firstProperty: 1 + property int secondProperty: 2 + property int readOnlyProperty: QtTest.qobjectTestProperty + property int writableProperty: QtTest.qobjectTestWritableProperty + + onFirstPropertyChanged: { + // In this case, we want to attempt to set the module API property. + // This should fail, as the module API property is read only. + if (firstProperty != QtTest.qobjectTestProperty) { + QtTest.qobjectTestProperty = firstProperty; // should silently fail. + } + } + + onSecondPropertyChanged: { + // In this case, we want to attempt to set the module API property. + // This should succeed, as the module API property is writable. + if (secondProperty != QtTest.qobjectTestWritableProperty) { + QtTest.qobjectTestWritableProperty = secondProperty; // should succeed. + } + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/scriptModuleApi.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/scriptModuleApi.qml new file mode 100644 index 0000000000..7c4e20489d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/scriptModuleApi.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 +import Qt.test.scriptApi 1.0 as QtTestScriptApi // script module API installed into new uri + +QtObject { + property int scriptTest: QtTestScriptApi.scriptTestProperty // script module api's only provide properties. +} diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/scriptModuleApiCaching.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/scriptModuleApiCaching.qml new file mode 100644 index 0000000000..90974b5969 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/scriptModuleApiCaching.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 +import Qt.test.scriptApi 1.0 as QtTestScriptApi // script module API installed into new uri + +QtObject { + property int scriptTest: QtTestScriptApi.scriptTestProperty +} diff --git a/tests/auto/qml/qqmlecmascript/data/moduleapi/scriptModuleApiWriting.qml b/tests/auto/qml/qqmlecmascript/data/moduleapi/scriptModuleApiWriting.qml new file mode 100644 index 0000000000..02461d59ed --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/moduleapi/scriptModuleApiWriting.qml @@ -0,0 +1,32 @@ +import QtQuick 2.0 +import Qt.test.scriptApi 1.0 as QtTestScriptApi +import Qt.test.scriptApi 2.0 as QtTestScriptApi2 + +QtObject { + property int firstProperty + property int readBack + + property int secondProperty + property int unchanged + + onFirstPropertyChanged: { + if (QtTestScriptApi.scriptTestProperty != firstProperty) { + QtTestScriptApi.scriptTestProperty = firstProperty; + readBack = QtTestScriptApi.scriptTestProperty; + } + } + + onSecondPropertyChanged: { + if (QtTestScriptApi2.scriptTestProperty != secondProperty) { + QtTestScriptApi2.scriptTestProperty = secondProperty; + unchanged = QtTestScriptApi2.scriptTestProperty; + } + } + + Component.onCompleted: { + firstProperty = QtTestScriptApi.scriptTestProperty; + readBack = QtTestScriptApi.scriptTestProperty; + secondProperty = QtTestScriptApi2.scriptTestProperty; + unchanged = QtTestScriptApi2.scriptTestProperty; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/multiEngineObject.qml b/tests/auto/qml/qqmlecmascript/data/multiEngineObject.qml new file mode 100644 index 0000000000..e349ced98f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/multiEngineObject.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + property string test: thing.stringProperty +} diff --git a/tests/auto/qml/qqmlecmascript/data/noSpuriousWarningsAtShutdown.2.qml b/tests/auto/qml/qqmlecmascript/data/noSpuriousWarningsAtShutdown.2.qml new file mode 100644 index 0000000000..23276f778d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/noSpuriousWarningsAtShutdown.2.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +Item { + id: root + + Item {} + + SpuriousWarning {} +} + diff --git a/tests/auto/qml/qqmlecmascript/data/noSpuriousWarningsAtShutdown.qml b/tests/auto/qml/qqmlecmascript/data/noSpuriousWarningsAtShutdown.qml new file mode 100644 index 0000000000..b4a417e04e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/noSpuriousWarningsAtShutdown.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + id: root + + property int childrenCount: root.children.length + + Item {} +} diff --git a/tests/auto/qml/qqmlecmascript/data/nonExistentAttachedObject.qml b/tests/auto/qml/qqmlecmascript/data/nonExistentAttachedObject.qml new file mode 100644 index 0000000000..f9585db009 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/nonExistentAttachedObject.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + stringProperty: MyQmlContainer.prop +} diff --git a/tests/auto/qml/qqmlecmascript/data/nonNotifyable.qml b/tests/auto/qml/qqmlecmascript/data/nonNotifyable.qml new file mode 100644 index 0000000000..2b8b113c34 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/nonNotifyable.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 + +MyQmlObject { + id: root + property int test: root.value +} diff --git a/tests/auto/qml/qqmlecmascript/data/nonscriptable.qml b/tests/auto/qml/qqmlecmascript/data/nonscriptable.qml new file mode 100644 index 0000000000..e96df6b40e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/nonscriptable.qml @@ -0,0 +1,19 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + id: root + + property bool readOk: false; + property bool writeOk: false + + Component.onCompleted: { + readOk = (root.nonscriptable == undefined); + + try { + root.nonscriptable = 10 + } catch (e) { + writeOk = true; + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/nullObjectBinding.qml b/tests/auto/qml/qqmlecmascript/data/nullObjectBinding.qml new file mode 100644 index 0000000000..1aee7a1670 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/nullObjectBinding.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +QtObject { + property QtObject test + test: if (1) model + property ListModel model +} + diff --git a/tests/auto/qml/qqmlecmascript/data/numberAssignment.qml b/tests/auto/qml/qqmlecmascript/data/numberAssignment.qml new file mode 100644 index 0000000000..30a77e8aed --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/numberAssignment.qml @@ -0,0 +1,18 @@ +import Qt.test 1.0 + +NumberAssignment { + test1: if (1) 6.7 + test2: if (1) "6.7" + test3: if (1) 6 + test4: if (1) "6" + + test5: if (1) 6.7 + test6: if (1) "6.7" + test7: if (1) 6 + test8: if (1) "6" + + test9: if (1) 6.7 + test10: if (1) "6.7" + test11: if (1) 6 + test12: if (1) "6" +} diff --git a/tests/auto/qml/qqmlecmascript/data/objectConversion.qml b/tests/auto/qml/qqmlecmascript/data/objectConversion.qml new file mode 100644 index 0000000000..67fc342db3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/objectConversion.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +Rectangle { + width: 360 + height: 360 + + function circularObject() { + var a = {} + var b = {} + + a.test = 100; + a.c = b; + b.c = a; + return a; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/objectName.qml b/tests/auto/qml/qqmlecmascript/data/objectName.qml new file mode 100644 index 0000000000..20b9ec2935 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/objectName.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +QtObject { + objectName: "hello" + + property string test1: objectName + property string test2: objectName.substr(1, 3) +} diff --git a/tests/auto/qml/qqmlecmascript/data/objectsCompareAsEqual.qml b/tests/auto/qml/qqmlecmascript/data/objectsCompareAsEqual.qml new file mode 100644 index 0000000000..845f74b1aa --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/objectsCompareAsEqual.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +Item { + id: root + + property variant 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/qml/qqmlecmascript/data/objectsPassThroughSignals.qml b/tests/auto/qml/qqmlecmascript/data/objectsPassThroughSignals.qml new file mode 100644 index 0000000000..98f9e05bdf --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/objectsPassThroughSignals.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +QtObject { + id: root + + property bool test: false + + signal mysignal(variant object); + function myslot(object) + { + test = (object == root); + } + + Component.onCompleted: { + mysignal.connect(this, myslot); + mysignal(root); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/outerBindingOverridesInnerBinding.qml b/tests/auto/qml/qqmlecmascript/data/outerBindingOverridesInnerBinding.qml new file mode 100644 index 0000000000..090c948f26 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/outerBindingOverridesInnerBinding.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 + +MyQmlObject { + id: obj + property alias c1: myConstants.c1 + property alias c2: myConstants.c2 + property int c3: 0 + + objectProperty: ConstantsOverrideBindings { + id: myConstants + c2: obj.c3 + } + +} + diff --git a/tests/auto/qml/qqmlecmascript/data/ownership.qml b/tests/auto/qml/qqmlecmascript/data/ownership.qml new file mode 100644 index 0000000000..855a264995 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/ownership.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + Component.onCompleted: { var a = getObject(); a = null; } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyAssignmentErrors.qml b/tests/auto/qml/qqmlecmascript/data/propertyAssignmentErrors.qml new file mode 100644 index 0000000000..34523ec1c7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyAssignmentErrors.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 + +QtObject { + id: root + + property int a + property variant b + + property bool test1: false; + property bool test2: false; + + Component.onCompleted: { + try { + root.a = undefined; + } catch(e) { + if (e.message == "Cannot assign [undefined] to int" && + e.stack.indexOf("propertyAssignmentErrors.qml:14") != -1) + root.test1 = true; + } + + try { + root.a = "Hello"; + } catch(e) { + if (e.message == "Cannot assign QString to int" && + e.stack.indexOf("propertyAssignmentErrors.qml:22") != -1) + root.test2 = true; + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertySplicing.qml b/tests/auto/qml/qqmlecmascript/data/propertySplicing.qml new file mode 100644 index 0000000000..53711db3f4 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertySplicing.qml @@ -0,0 +1,10 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyDerivedObject { + property bool test: false + + Component.onCompleted: { + test = intProperty() + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.1.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.1.qml new file mode 100644 index 0000000000..219e61bf91 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.1.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 + +Item { + id: root + property bool test: false + + property var car: new vehicle(4); + property int wheelCount: car.wheels + + function vehicle(wheels) { + this.wheels = wheels; + } + + Component.onCompleted: { + car.wheels = 6; // not bindable, wheelCount shouldn't update + + if (car.wheels != 6) return; + if (wheelCount != 4) return; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.10.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.10.qml new file mode 100644 index 0000000000..ac7f2bed57 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.10.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +PropertyVarBaseItem { + property bool test: false + Component.onCompleted: { + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.2.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.2.qml new file mode 100644 index 0000000000..2ac4807ec5 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.2.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 + +Item { + id: root + property bool test: false + + property var truck: new vehicle(8); + property int wheelCount: truck.wheels + + function vehicle(wheels) { + this.wheels = wheels; + } + + Component.onCompleted: { + if (wheelCount != 8) return; + + // not bindable, but wheelCount will update because truck itself changed. + truck = new vehicle(12); + + if (wheelCount != 12) return; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.3.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.3.qml new file mode 100644 index 0000000000..cf6a651639 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.3.qml @@ -0,0 +1,19 @@ +import QtQuick 2.0 + +Item { + id: root + property bool test: false + + property var jsint: 4 + property int bound: jsint + 5 + + Component.onCompleted: { + if (bound != 9) return; + + jsint = jsint + 1; + + if (bound != 10) return; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.4.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.4.qml new file mode 100644 index 0000000000..82fc225e71 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.4.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +Item { + property bool test: false + + property var items: [1, 2, 3, "four", "five"] + property int bound: items[0] + + Component.onCompleted: { + if (bound != 1) return; + + items[0] = 10 // bound should remain 1 + + if (bound != 1) return; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.5.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.5.qml new file mode 100644 index 0000000000..a5c7812289 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.5.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +Item { + property bool test: false + + property var attributes: { 'color': 'red', 'width': 100 } + property int bound: attributes.width + + Component.onCompleted: { + if (bound != 100) return; + + attributes.width = 200 // bound should remain 100 + + if (bound != 100) return; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.6.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.6.qml new file mode 100644 index 0000000000..060d24e7bc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.6.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 + +Item { + property bool test: false + + property var items: [1, 2, 3, "four", "five"] + property int bound: items[0] + property var funcs: [(function() { return 6; })] + property int bound2: funcs[0]() + + function returnTwenty() { + return 20; + } + + Component.onCompleted: { + if (bound != 1) return false; + if (bound2 != 6) return false; + + items = [10, 2, 3, "four", "five"] // bound should now be 10 + funcs = [returnTwenty] // bound2 should now be 20 + + if (bound != 10) return false; + if (bound2 != 20) return false; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.7.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.7.qml new file mode 100644 index 0000000000..1d6c8c0a37 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.7.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +Item { + property bool test: false + + property var attributes: { 'color': 'red', 'width': 100 } + property int bound: attributes.width + + Component.onCompleted: { + if (bound != 100) return; + + attributes = { 'color': 'blue', 'width': 200 } // bound should now be 200 + + if (bound != 200) return; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.8.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.8.qml new file mode 100644 index 0000000000..a9f73db402 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.8.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Item { + property bool test: false + + property var literalValue: 6 + + Component.onCompleted: { + if (literalValue != 6) return; + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.9.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.9.qml new file mode 100644 index 0000000000..f5aca28417 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.9.qml @@ -0,0 +1,19 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + property bool test: false + + MyQmlObject { + id: qmlobject + intProperty: 5 + } + property var qobjectVar: qmlobject + property int bound: qobjectVar.intProperty + + Component.onCompleted: { + if (bound != 5) return; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.circular.2.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.circular.2.qml new file mode 100644 index 0000000000..93c44afcc9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.circular.2.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 + +Item { + id: root + objectName: "separateRootObject" + property var vp + + function constructGarbage() { + var retn = 1; + var component = Qt.createComponent("PropertyVarCircularComponent3.qml"); + if (component.status == Component.Ready) { + retn = component.createObject(null); // has JavaScript ownership + } + return retn; + } + + function assignCircular() { + vp = constructGarbage(); + gc(); + } + + function deassignCircular() { + vp = 2; + gc(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.circular.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.circular.qml new file mode 100644 index 0000000000..171d7747cd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.circular.qml @@ -0,0 +1,44 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: testCircular + + property var varProperty + property variant canaryResource + property int canaryInt + + function constructGarbage() { + var retn = 1; + var component = Qt.createComponent("PropertyVarCircularComponent.qml"); + if (component.status == Component.Ready) { + retn = component.createObject(null); // has JavaScript ownership + } + return retn; + } + + function deassignCanaryResource() { + canaryResource = 1; + gc(); + } + + function assignCircular() { + varProperty = constructGarbage(); + canaryResource = varProperty.vp.vp.vp.vp.memoryHog; + canaryInt = varProperty.vp.vp.vp.vp.fifthCanary; // == 5 + gc(); + } + + function deassignCircular() { + canaryInt = 2; + varProperty = 2; + gc(); + } + + function assignThenDeassign() { + varProperty = constructGarbage(); + varProperty = 2; + gc(); + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.inherit.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.inherit.qml new file mode 100644 index 0000000000..abd0dd7c04 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.inherit.qml @@ -0,0 +1,34 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: testInheritance + + property var varProperty + + function constructGarbage() { + var retn = 1; + var component = Qt.createComponent("PropertyVarInheritanceComponent.qml"); + if (component.status == Component.Ready) { + retn = component.createObject(null); // has JavaScript ownership + } + return retn; + } + + function assignCircular() { + varProperty = constructGarbage(); + gc(); + } + + function deassignCircular() { + varProperty = 2; + gc(); + } + + function assignThenDeassign() { + varProperty = constructGarbage(); + varProperty = 2; + gc(); + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.reparent.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.reparent.qml new file mode 100644 index 0000000000..7b3df674f1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.reparent.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 + +Item { + id: root + objectName: "separateRootObject" + property var vp + + function constructGarbage() { + var retn = 1; + var component = Qt.createComponent("PropertyVarOwnershipComponent.qml"); + if (component.status == Component.Ready) { + retn = component.createObject(null); // has JavaScript ownership + } + return retn; + } + + function assignVarProp() { + vp = constructGarbage(); + gc(); + } + + function deassignVarProp() { + vp = 2; + gc(); + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVarCpp.qml b/tests/auto/qml/qqmlecmascript/data/propertyVarCpp.qml new file mode 100644 index 0000000000..cd3147f565 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVarCpp.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: testOwnership + property int intProperty: 10 + property var varProperty: intProperty + property var varProperty2: false + property var varBound: varProperty + 5 + property int intBound: varProperty + 5 + property var jsobject: new vehicle(4) + + function vehicle(wheels) { + this.wheels = wheels; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVarImplicitOwnership.qml b/tests/auto/qml/qqmlecmascript/data/propertyVarImplicitOwnership.qml new file mode 100644 index 0000000000..9cebded932 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVarImplicitOwnership.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 + +Item { + id: root + objectName: "separateRootObject" + property var vp + + function constructGarbage() { + var retn = 1; + var component = Qt.createComponent("PropertyVarCircularComponent4.qml"); + if (component.status == Component.Ready) { + retn = component.createObject(null); // has JavaScript ownership + } + return retn; + } + + function assignCircular() { + vp = constructGarbage(); + gc(); + } + + function deassignCircular() { + vp = 2; + gc(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.2.qml b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.2.qml new file mode 100644 index 0000000000..14d4f9fd27 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.2.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: testOwnership + property bool test: false + + property int dummyProperty // Tests for non-interference of other properties + property var varProperty + + function runTest() { + if (varProperty != undefined) return; + varProperty = { a: 10, b: 11 } + if (varProperty.a != 10) return; + + gc(); // Shouldn't collect + + if (varProperty.a != 10) return; + + test = true; + } +} + + diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.3.qml b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.3.qml new file mode 100644 index 0000000000..d5b449c938 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.3.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 + +Item { + property var object + + property bool test1: false + property bool test2: false + + // Test methods are executed in sequential order + + function runTest() { + var c = Qt.createComponent("propertyVarOwnership.3.type.qml"); + object = c.createObject(); + + if (object.dummy != 10) return; + test1 = true; + } + + // Run gc() from C++ + + function runTest2() { + if (object.dummy != 10) return; + + object = undefined; + if (object != undefined) return; + + test2 = true; + } + + // Run gc() from C++ - QObject should be collected +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.3.type.qml b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.3.type.qml new file mode 100644 index 0000000000..3406553b91 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.3.type.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + property int dummy: 10 +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.4.qml b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.4.qml new file mode 100644 index 0000000000..1eba36ce81 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.4.qml @@ -0,0 +1,25 @@ +import QtQuick 2.0 + +Item { + id: root + + property var object + + property bool test: false + + Component.onCompleted: { + var c = Qt.createComponent("propertyVarOwnership.4.type1.qml"); + object = c.createObject(); + + if (object.dummy != 10) return; + if (object.test != true) return; + + object.creatorRef = root; + + test = true; + } + + function runTest() { + object = null; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.4.type1.qml b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.4.type1.qml new file mode 100644 index 0000000000..9a29b6e17f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.4.type1.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 + +// Has a self reference in selfRef, and a reference to propertyVarOwnership.4.qml in creatorRef +Item { + id: root + + property var creatorRef + property var selfRef + property var object + + property int dummy: 10 + property bool test: false + + Component.onCompleted: { + selfRef = root; + + var c = Qt.createComponent("propertyVarOwnership.4.type2.qml"); + object = c.createObject(); + object.creatorRef = root; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.4.type2.qml b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.4.type2.qml new file mode 100644 index 0000000000..f82b8a1c1e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.4.type2.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +// Has a reference to propertyVarOwnership.4.type1.qml in creatorRef +Item { + property var creatorRef +} diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.qml b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.qml new file mode 100644 index 0000000000..7b99c4b6ad --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: testOwnership + property bool test: false + + property var varProperty + + function runTest() { + if (varProperty != undefined) return; + varProperty = { a: 10, b: 11 } + if (varProperty.a != 10) return; + + gc(); // Shouldn't collect + + if (varProperty.a != 10) return; + + test = true; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/qlistqobjectMethods.qml b/tests/auto/qml/qqmlecmascript/data/qlistqobjectMethods.qml new file mode 100644 index 0000000000..3c1986d721 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qlistqobjectMethods.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +QtObject { + property int test: getObjects().length + property bool test2: getObjects()[0].trueProperty +} diff --git a/tests/auto/qml/qqmlecmascript/data/qmlHasOwnProperty.qml b/tests/auto/qml/qqmlecmascript/data/qmlHasOwnProperty.qml new file mode 100644 index 0000000000..12598b3b9f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qmlHasOwnProperty.qml @@ -0,0 +1,72 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import Qt.test.qobjectApi 1.0 as QtTestQObjectApi + +Item { + id: obj + objectName: "objName" + property int someIntProperty: 10 + property bool result: false + + function testHasOwnPropertySuccess() + { + obj.result = obj.hasOwnProperty("someIntProperty"); + } + + function testHasOwnPropertyFailure() + { + obj.result = obj.hasOwnProperty("someNonexistentProperty"); + } + + MyTypeObject { + id: typeObj + objectName: "typeObj" + pointProperty: Qt.point(34, 29) + variantProperty: Qt.vector3d(1, 2, 3) + stringProperty: "test string" + property list<Rectangle> listProperty: [ Rectangle { width: 10; height: 10 } ] + property list<Rectangle> emptyListProperty + + property bool valueTypeHasOwnProperty + property bool valueTypeHasOwnProperty2 + property bool variantTypeHasOwnProperty + property bool stringTypeHasOwnProperty + property bool listTypeHasOwnProperty + property bool listAtValidHasOwnProperty + property bool emptyListTypeHasOwnProperty + property bool enumTypeHasOwnProperty + property bool typenameHasOwnProperty + property bool typenameHasOwnProperty2 + property bool moduleApiTypeHasOwnProperty + property bool moduleApiPropertyTypeHasOwnProperty + function testHasOwnPropertySuccess() { + valueTypeHasOwnProperty = !typeObj.pointProperty.hasOwnProperty("nonexistentpropertyname"); + valueTypeHasOwnProperty2 = typeObj.pointProperty.hasOwnProperty("x"); // should be true + variantTypeHasOwnProperty = !typeObj.variantProperty.hasOwnProperty("nonexistentpropertyname"); + stringTypeHasOwnProperty = !typeObj.stringProperty.hasOwnProperty("nonexistentpropertyname"); + listTypeHasOwnProperty = !typeObj.listProperty.hasOwnProperty("nonexistentpropertyname"); + listAtValidHasOwnProperty = !typeObj.listProperty[0].hasOwnProperty("nonexistentpropertyname"); + emptyListTypeHasOwnProperty = !typeObj.emptyListProperty.hasOwnProperty("nonexistentpropertyname"); + enumTypeHasOwnProperty = !MyTypeObject.EnumVal1.hasOwnProperty("nonexistentpropertyname"); + typenameHasOwnProperty = !MyTypeObject.hasOwnProperty("nonexistentpropertyname"); + typenameHasOwnProperty2 = MyTypeObject.hasOwnProperty("EnumVal1"); // should be true. + moduleApiTypeHasOwnProperty = !QtTestQObjectApi.hasOwnProperty("nonexistentpropertyname"); + moduleApiPropertyTypeHasOwnProperty = !QtTestQObjectApi.qobjectTestProperty.hasOwnProperty("nonexistentpropertyname"); + } + + property bool enumNonValueHasOwnProperty + function testHasOwnPropertyFailureOne() { + enumNonValueHasOwnProperty = !MyTypeObject.NonexistentEnumVal.hasOwnProperty("nonexistentpropertyname"); + } + + property bool moduleApiNonPropertyHasOwnProperty + function testHasOwnPropertyFailureTwo() { + moduleApiNonPropertyHasOwnProperty = !QtTestQObjectApi.someNonexistentProperty.hasOwnProperty("nonexistentpropertyname"); + } + + property bool listAtInvalidHasOwnProperty + function testHasOwnPropertyFailureThree() { + listAtInvalidHasOwnProperty = !typeObj.listProperty[5].hasOwnProperty("nonexistentpropertyname"); + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/qmlToString.qml b/tests/auto/qml/qqmlecmascript/data/qmlToString.qml new file mode 100644 index 0000000000..ac296ce293 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qmlToString.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 + +MyQmlObject{ + id: obj + objectName: "objName" + function testToString() + { + obj.stringProperty = obj.toString(); + } + +} diff --git a/tests/auto/qml/qqmlecmascript/data/qobjectConnectionListExceptionHandling.qml b/tests/auto/qml/qqmlecmascript/data/qobjectConnectionListExceptionHandling.qml new file mode 100644 index 0000000000..acd512a2be --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qobjectConnectionListExceptionHandling.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 + +Item { + id: root + property int first: 5 + property bool test: false + + Item { + id: exceptional + function exceptionalFunction() { + var obj = undefined; + var prop = undefined; + return obj[prop]; + } + } + + Component.onCompleted: { + root["firstChanged"].connect(exceptional.exceptionalFunction); + root["firstChanged"].connect(exceptional.exceptionalFunction); + root["firstChanged"].connect(exceptional.exceptionalFunction); + first = 6; + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/qobjectDerivedArgument.qml b/tests/auto/qml/qqmlecmascript/data/qobjectDerivedArgument.qml new file mode 100644 index 0000000000..bf4ab6fd7a --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qobjectDerivedArgument.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + id: root + stringProperty: 'hello' + property var child + + property bool result: false + + Component.onCompleted: { + child = invokable.createMyQmlObject('goodbye'); + + result = (invokable.getStringProperty(root) == 'hello') && + (invokable.getStringProperty(child) == 'goodbye'); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_10696.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_10696.qml new file mode 100644 index 0000000000..90263e5124 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_10696.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 + +QtObject { + property string test: "aaaa" + + "bbbb" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc" + + "cccc"; +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_11600.js b/tests/auto/qml/qqmlecmascript/data/qtbug_11600.js new file mode 100644 index 0000000000..092bc2b041 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_11600.js @@ -0,0 +1 @@ +; diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_11600.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_11600.qml new file mode 100644 index 0000000000..6c7e8806e6 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_11600.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import "qtbug_11600.js" as Test + +QtObject { + id: goo + + property bool test: undefined == goo.Test +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_11606.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_11606.qml new file mode 100644 index 0000000000..b1b062ed35 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_11606.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +QtObject { + property bool test: false + Component.onCompleted: { + try { + console.log(sorryNoSuchProperty); + } catch (e) { + test = true; + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_20344.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_20344.qml new file mode 100644 index 0000000000..f490848caf --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_20344.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + Component.onCompleted: v8function() +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_21580.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_21580.qml new file mode 100644 index 0000000000..dc0066ba3f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_21580.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 + +QtObject { + property bool test: false + + property list<QtObject> objects: [ + QtObject { + id: first + property alias myAlias: other.myProperty + onMyAliasChanged: if (myAlias == 20) test = true + }, + QtObject { + id: other + property real myProperty + } + ] + + Component.onCompleted: { + other.myProperty = 20; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_21864.js b/tests/auto/qml/qqmlecmascript/data/qtbug_21864.js new file mode 100644 index 0000000000..e1a688ebbe --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_21864.js @@ -0,0 +1,2 @@ +var a = { b: 10 } +var test = (typeof a) == "object" diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_21864.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_21864.qml new file mode 100644 index 0000000000..0f972d5459 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_21864.qml @@ -0,0 +1,6 @@ +import "qtbug_21864.js" as Test +import QtQuick 2.0 + +QtObject { + property bool test: Test.test +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_22464.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_22464.qml new file mode 100644 index 0000000000..19f26736f1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_22464.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +QtObject { + property alias value: inner.value + property bool test: false + + property variant dummy: QtObject { + id: inner + property variant value: Qt.rgba(1, 1, 0, 1); + } + + Component.onCompleted: { + test = (value == Qt.rgba(1, 1, 0, 1)); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_22679.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_22679.qml new file mode 100644 index 0000000000..b38a84b4c0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_22679.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +QtObject { + function accessContextProperty() { + for (var i = 0; i < contextProp.stringProperty.length; ++i) ; + } + + Component.onCompleted: { + for (var i = 0; i < 1000; ++i) + accessContextProperty(); + // Shouldn't cause "Illegal invocation" error. + gc(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_22843.js b/tests/auto/qml/qqmlecmascript/data/qtbug_22843.js new file mode 100644 index 0000000000..6d19fe0571 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_22843.js @@ -0,0 +1,5 @@ + +function func() +{ + isFinite() ) +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_22843.library.js b/tests/auto/qml/qqmlecmascript/data/qtbug_22843.library.js new file mode 100644 index 0000000000..1a7c8a2e6e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_22843.library.js @@ -0,0 +1,5 @@ +.pragma library +function func() +{ + isFinite() ) +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_22843.library.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_22843.library.qml new file mode 100644 index 0000000000..281765bff6 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_22843.library.qml @@ -0,0 +1,6 @@ +import "qtbug_22843.library.js" as MyScript +import QtQuick 2.0 + +QtObject { + Component.onCompleted: MyScript.func() +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_22843.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_22843.qml new file mode 100644 index 0000000000..90a47c0f4b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_22843.qml @@ -0,0 +1,6 @@ +import "qtbug_22843.js" as MyScript +import QtQuick 2.0 + +QtObject { + Component.onCompleted: MyScript.func() +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtbug_9792.qml b/tests/auto/qml/qqmlecmascript/data/qtbug_9792.qml new file mode 100644 index 0000000000..9ac44308c6 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtbug_9792.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + onBasicSignal: print("Hello world!"); +} diff --git a/tests/auto/qml/qqmlecmascript/data/qtcreatorbug_1289.qml b/tests/auto/qml/qqmlecmascript/data/qtcreatorbug_1289.qml new file mode 100644 index 0000000000..90711c8d09 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qtcreatorbug_1289.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +QtObject { + id: root + property QtObject object: QtObject { + id: nested + property QtObject nestedObject + } + + Component.onCompleted: { + nested.nestedObject = root; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/readonlyDeclaration.qml b/tests/auto/qml/qqmlecmascript/data/readonlyDeclaration.qml new file mode 100644 index 0000000000..5377d2dcbf --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/readonlyDeclaration.qml @@ -0,0 +1,45 @@ +import QtQuick 2.0 + +QtObject { + property int dummy: 13 + + readonly property int test1: 19 + readonly property int test2: dummy * 49 + readonly property alias test3: other.test + + property bool test: false + + property var dummyObj: QtObject { + id: other + property int test: 9 + } + + Component.onCompleted: { + if (test1 != 19) return; + if (test2 != 637) return; + if (test3 != 9) return; + + var caught = false; + + caught = false; + try { test1 = 13 } catch (e) { caught = true; } + if (!caught) return; + + caught = false; + try { test2 = 13 } catch (e) { caught = true; } + if (!caught) return; + + caught = false; + try { test3 = 13 } catch (e) { caught = true; } + if (!caught) return; + + other.test = 13; + dummy = 9; + + if (test1 != 19) return; + if (test2 != 441) return; + if (test3 != 13) return; + + test = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/realToInt.qml b/tests/auto/qml/qqmlecmascript/data/realToInt.qml new file mode 100644 index 0000000000..a9e7dd2a95 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/realToInt.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + function test1() { + value = 4.2 + } + function test2() { + value = 7.9 + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/regExp.2.qml b/tests/auto/qml/qqmlecmascript/data/regExp.2.qml new file mode 100644 index 0000000000..68cca5733b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/regExp.2.qml @@ -0,0 +1,7 @@ +import Qt.test 1.0 + +MyQmlObject{ + id: obj + objectName: "obj" + regExp: "[a-zA-z]" +} diff --git a/tests/auto/qml/qqmlecmascript/data/regExp.qml b/tests/auto/qml/qqmlecmascript/data/regExp.qml new file mode 100644 index 0000000000..0dc404b5db --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/regExp.qml @@ -0,0 +1,7 @@ +import Qt.test 1.0 + +MyQmlObject{ + id: obj + objectName: "obj" + regExp: /[a-zA-z]/ +} diff --git a/tests/auto/qml/qqmlecmascript/data/remote_file.js b/tests/auto/qml/qqmlecmascript/data/remote_file.js new file mode 100644 index 0000000000..1b123aee61 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/remote_file.js @@ -0,0 +1,2 @@ +myvar = 13; +test5 = true; diff --git a/tests/auto/qml/qqmlecmascript/data/rewriteMultiLineStrings.qml b/tests/auto/qml/qqmlecmascript/data/rewriteMultiLineStrings.qml new file mode 100644 index 0000000000..1ae1b162b2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/rewriteMultiLineStrings.qml @@ -0,0 +1,35 @@ +import QtQuick 2.0 + +Item { + id: root; + property bool test: str == str2 && (txt != null && txt.str == root.str) + property Text txt: null + //Constant doesn't hit rewriter + property string str: 'same +multiline +string 5 !' + property string str2: ''; + Component { + id: comp + Text { + property var value: 1 + property string str: 'same +multiline +string ' + value + " !" + Component.onCompleted: { //Separate codepath for signal handers in rewriter + root.str2 = 'same +multiline +string ' + value + " !" + } + } + } + Component.onCompleted: txt = comp.createObject(root,{"value" : 5}) + /* + Timer { + interval: 1000 + running: true + repeat: true + onTriggered: console.debug( "Test: " + test + '\n' + str + '\n:\n' + str2 + "\n:\n" + txt.str) + } + */ +} diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopy.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopy.var.qml new file mode 100644 index 0000000000..805655fc17 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopy.var.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// Here we import a scarce resource directly. +// The instance has a property which is a copy +// of the scarce resource, so it should not be +// detached (but we should automatically release +// the resource from our engine internal list). + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property var scarceResourceCopy: scarceResourceProvider.scarceResource +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopy.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopy.variant.qml new file mode 100644 index 0000000000..ee5b05b28a --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopy.variant.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// Here we import a scarce resource directly. +// The instance has a property which is a copy +// of the scarce resource, so it should not be +// detached (but we should automatically release +// the resource from our engine internal list). + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property variant scarceResourceCopy: scarceResourceProvider.scarceResource +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyFromJs.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyFromJs.var.qml new file mode 100644 index 0000000000..09868e5e7c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyFromJs.var.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceTest.var.js" as ScarceResourceProviderJs + +// Here we import a scarce resource directly, from JS module. +// It is not preserved or released manually, so it should be +// automatically released once evaluation of the binding +// is complete. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property var scarceResourceCopy: ScarceResourceProviderJs.importScarceResource(scarceResourceProvider) +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyFromJs.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyFromJs.variant.qml new file mode 100644 index 0000000000..a1ebeb4073 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyFromJs.variant.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceTest.variant.js" as ScarceResourceProviderJs + +// Here we import a scarce resource directly, from JS module. +// It is not preserved or released manually, so it should be +// automatically released once evaluation of the binding +// is complete. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property variant scarceResourceCopy: ScarceResourceProviderJs.importScarceResource(scarceResourceProvider) +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.var.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.var.js new file mode 100644 index 0000000000..468a6b4f2e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.var.js @@ -0,0 +1,25 @@ +.import Qt.test 1.0 as JsQtTest + +// In this case, the "retn" variable will be evaluated during import. +// Since the "importScarceResource()" function depends on this variable, +// we must explicitly preserve the "retn" variable or the scarce +// resource would automatically be released after import completes +// but before the binding is evaluated. + +var component = Qt.createComponent("scarceResourceCopy.var.qml"); +var scarceResourceElement = component.createObject(null); +var scarceResourceProvider = scarceResourceElement.a; +var retn = scarceResourceProvider.scarceResource; +retn.preserve(); // must preserve manually or it will be released! + +function importScarceResource() { + // if called prior to calling destroyScarceResource(), + // this function should return the preserved scarce resource. + // otherwise, it should return an invalid variant. + return retn; +} + +function destroyScarceResource() { + retn.destroy(); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.var.qml new file mode 100644 index 0000000000..9321481f45 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.var.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceCopyImport.var.js" as ScarceResourceCopyImportJs + +QtObject { + // this binding is evaluated once, prior to the resource being released + property var scarceResourceImportedCopy: ScarceResourceCopyImportJs.importScarceResource() + + property bool arePropertiesEqual + property var scarceResourceAssignedCopyOne; + property var scarceResourceAssignedCopyTwo; + Component.onCompleted: { + scarceResourceAssignedCopyOne = ScarceResourceCopyImportJs.importScarceResource(); + arePropertiesEqual = (scarceResourceAssignedCopyOne == scarceResourceImportedCopy); + ScarceResourceCopyImportJs.destroyScarceResource(); // makes all properties invalid. + scarceResourceAssignedCopyTwo = ScarceResourceCopyImportJs.importScarceResource(); + } +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.variant.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.variant.js new file mode 100644 index 0000000000..9aeb507487 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.variant.js @@ -0,0 +1,25 @@ +.import Qt.test 1.0 as JsQtTest + +// In this case, the "retn" variable will be evaluated during import. +// Since the "importScarceResource()" function depends on this variable, +// we must explicitly preserve the "retn" variable or the scarce +// resource would automatically be released after import completes +// but before the binding is evaluated. + +var component = Qt.createComponent("scarceResourceCopy.variant.qml"); +var scarceResourceElement = component.createObject(null); +var scarceResourceProvider = scarceResourceElement.a; +var retn = scarceResourceProvider.scarceResource; +retn.preserve(); // must preserve manually or it will be released! + +function importScarceResource() { + // if called prior to calling destroyScarceResource(), + // this function should return the preserved scarce resource. + // otherwise, it should return an invalid variant. + return retn; +} + +function destroyScarceResource() { + retn.destroy(); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.variant.qml new file mode 100644 index 0000000000..e8b53979dd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImport.variant.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceCopyImport.variant.js" as ScarceResourceCopyImportJs + +QtObject { + // this binding is evaluated once, prior to the resource being released + property variant scarceResourceImportedCopy: ScarceResourceCopyImportJs.importScarceResource() + + // this code is evaluated on completion, and so copy one should be valid, copy two invalid. + property variant scarceResourceAssignedCopyOne; + property variant scarceResourceAssignedCopyTwo; + Component.onCompleted: { + scarceResourceAssignedCopyOne = ScarceResourceCopyImportJs.importScarceResource(); + ScarceResourceCopyImportJs.destroyScarceResource(); + scarceResourceAssignedCopyTwo = ScarceResourceCopyImportJs.importScarceResource(); + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportDifferent.var.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportDifferent.var.js new file mode 100644 index 0000000000..000eeddb34 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportDifferent.var.js @@ -0,0 +1,19 @@ +.import Qt.test 1.0 as JsQtTest + +// In this case, we create the returned scarce resource each call, +// so the object will be different every time it is returned. + +var mostRecent + +function importScarceResource() { + var component = Qt.createComponent("scarceResourceCopy.var.qml"); + var scarceResourceElement = component.createObject(null); + var scarceResourceProvider = scarceResourceElement.a; + var retn = scarceResourceProvider.scarceResource; + mostRecent = retn; + return retn; +} + +function destroyScarceResource() { + mostRecent.destroy(); +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportDifferent.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportDifferent.var.qml new file mode 100644 index 0000000000..082d132c24 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportDifferent.var.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceCopyImportDifferent.var.js" as ScarceResourceCopyImportJs + +// in this case, the ScarceResourceCopyImportJs returns a _new_, different +// scarce resource each time. Invalidating one will not invalidate the others. + +QtObject { + // this binding is evaluated once, prior to the resource being released + property var scarceResourceImportedCopy: ScarceResourceCopyImportJs.importScarceResource() + + // the following properties are assigned on component completion. + property bool arePropertiesEqual + property var scarceResourceAssignedCopyOne; + property var scarceResourceAssignedCopyTwo; + Component.onCompleted: { + scarceResourceAssignedCopyOne = ScarceResourceCopyImportJs.importScarceResource(); + arePropertiesEqual = (scarceResourceAssignedCopyOne != scarceResourceImportedCopy); // they're not the same object. + ScarceResourceCopyImportJs.destroyScarceResource(); // makes the MOST RECENT resource invalid (ie, assignedCopyOne). + scarceResourceAssignedCopyTwo = ScarceResourceCopyImportJs.importScarceResource(); + } +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.var.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.var.js new file mode 100644 index 0000000000..ba52b323f0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.var.js @@ -0,0 +1,19 @@ +.import Qt.test 1.0 as JsQtTest + +// In this case, the "retn" variable will be evaluated during import. +// Since the importScarceResource() function depends on this variable, +// because we DO NOT call "retn.preserve()", the scarce resource will +// be released after the import completes but prior to evaluation of +// any binding which calls "importScarceResource()". +// Thus, "importScarceResource()" will return a released (invalid) +// scarce resource. + +var component = Qt.createComponent("scarceResourceCopy.var.qml"); +var scarceResourceElement = component.createObject(null); +var scarceResourceProvider = scarceResourceElement.a; +var retn = scarceResourceProvider.scarceResource; + +function importScarceResource() { + return retn; // should return a released (invalid) scarce resource +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.var.qml new file mode 100644 index 0000000000..a1a3c1d66f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.var.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceCopyImportFail.var.js" as ScarceResourceCopyImportFailJs + +QtObject { + property var scarceResourceCopy: ScarceResourceCopyImportFailJs.importScarceResource() +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.variant.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.variant.js new file mode 100644 index 0000000000..b59b5b1fa9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.variant.js @@ -0,0 +1,19 @@ +.import Qt.test 1.0 as JsQtTest + +// In this case, the "retn" variable will be evaluated during import. +// Since the importScarceResource() function depends on this variable, +// because we DO NOT call "retn.preserve()", the scarce resource will +// be released after the import completes but prior to evaluation of +// any binding which calls "importScarceResource()". +// Thus, "importScarceResource()" will return a released (invalid) +// scarce resource. + +var component = Qt.createComponent("scarceResourceCopy.variant.qml"); +var scarceResourceElement = component.createObject(null); +var scarceResourceProvider = scarceResourceElement.a; +var retn = scarceResourceProvider.scarceResource; + +function importScarceResource() { + return retn; // should return a released (invalid) scarce resource +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.variant.qml new file mode 100644 index 0000000000..8f6dcd6603 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportFail.variant.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceCopyImportFail.variant.js" as ScarceResourceCopyImportFailJs + +QtObject { + property variant scarceResourceCopy: ScarceResourceCopyImportFailJs.importScarceResource() +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.var.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.var.js new file mode 100644 index 0000000000..130199f78a --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.var.js @@ -0,0 +1,15 @@ +.import Qt.test 1.0 as JsQtTest + +// In this case, the "retn" variable will be evaluated during import. +// Since the importScarceResource() function depends on this variable, +// because we DO NOT call "retn.preserve()", the scarce resource will +// be released after the import completes but prior to evaluation of +// any binding which calls "importScarceResource()". +// Thus, "importScarceResource()" will return a released (invalid) +// scarce resource. + +var component = Qt.createComponent("scarceResourceCopyNoBinding.var.qml"); +var scarceResourceElement = component.createObject(null); +var scarceResourceProvider = scarceResourceElement.a; +var retn = scarceResourceProvider.scarceResource; + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.var.qml new file mode 100644 index 0000000000..5284b40cc8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.var.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// the following js import doesn't manually preserve or destroy any resources +import "scarceResourceCopyImportNoBinding.var.js" as ScarceResourceCopyImportNoBindingJs + +QtObject { + // in this case, there is an import but no binding evaluated. + // nonetheless, any resources which are not preserved, should + // be automatically released by the engine. +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.variant.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.variant.js new file mode 100644 index 0000000000..14a36a19ea --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.variant.js @@ -0,0 +1,15 @@ +.import Qt.test 1.0 as JsQtTest + +// In this case, the "retn" variable will be evaluated during import. +// Since the importScarceResource() function depends on this variable, +// because we DO NOT call "retn.preserve()", the scarce resource will +// be released after the import completes but prior to evaluation of +// any binding which calls "importScarceResource()". +// Thus, "importScarceResource()" will return a released (invalid) +// scarce resource. + +var component = Qt.createComponent("scarceResourceCopyNoBinding.variant.qml"); +var scarceResourceElement = component.createObject(null); +var scarceResourceProvider = scarceResourceElement.a; +var retn = scarceResourceProvider.scarceResource; + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.variant.qml new file mode 100644 index 0000000000..826cbe49fc --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyImportNoBinding.variant.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// the following js import doesn't manually preserve or destroy any resources +import "scarceResourceCopyImportNoBinding.variant.js" as ScarceResourceCopyImportNoBindingJs + +QtObject { + // in this case, there is an import but no binding evaluated. + // nonetheless, any resources which are not preserved, should + // be automatically released by the engine. +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyNoBinding.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyNoBinding.var.qml new file mode 100644 index 0000000000..4adef39980 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyNoBinding.var.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +QtObject { + // this component doesn't bind any property to a scarce + // resource from the scarce resource provider, + // so the binding evaluation resource cleanup + // codepath shouldn't be activated; so if the resources + // are released, it will be due to the import evaluation + // resource cleanup codepath being activated correctly. + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyNoBinding.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyNoBinding.variant.qml new file mode 100644 index 0000000000..4adef39980 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceCopyNoBinding.variant.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +QtObject { + // this component doesn't bind any property to a scarce + // resource from the scarce resource provider, + // so the binding evaluation resource cleanup + // codepath shouldn't be activated; so if the resources + // are released, it will be due to the import evaluation + // resource cleanup codepath being activated correctly. + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceDestroyedCopy.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceDestroyedCopy.var.qml new file mode 100644 index 0000000000..500f5d5bd7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceDestroyedCopy.var.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceTest.var.js" as ScarceResourceProviderJs + +// In this case, following the evaluation of the binding, +// the scarceResourceTest value should be an invalid variant, +// since the scarce resource will have been released. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property var scarceResourceCopy: ScarceResourceProviderJs.importReleasedScarceResource(scarceResourceProvider); +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceDestroyedCopy.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceDestroyedCopy.variant.qml new file mode 100644 index 0000000000..7a3b845247 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceDestroyedCopy.variant.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceTest.variant.js" as ScarceResourceProviderJs + +// In this case, following the evaluation of the binding, +// the scarceResourceTest value should be an invalid variant, +// since the scarce resource will have been released. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property variant scarceResourceCopy: ScarceResourceProviderJs.importReleasedScarceResource(scarceResourceProvider); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceFunction.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceFunction.var.qml new file mode 100644 index 0000000000..23e4c8d15e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceFunction.var.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// Here we import a scarce resource directly. +// The copy is only assigned when retrieveScarceResource() +// is called, and so should be detached prior to that. +// The copy should be released when releaseScarceResource() +// is called, and so should be detached after that. + +QtObject { + id: root + property MyScarceResourceObject a: MyScarceResourceObject { id: scarceResourceProvider } + property var scarceResourceCopy; + + function retrieveScarceResource() { + root.scarceResourceCopy = scarceResourceProvider.scarceResource; + } + + function releaseScarceResource() { + root.scarceResourceCopy = null; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceFunction.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceFunction.variant.qml new file mode 100644 index 0000000000..fe3707b5d3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceFunction.variant.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// Here we import a scarce resource directly. +// The copy is only assigned when retrieveScarceResource() +// is called, and so should be detached prior to that. +// The copy should be released when releaseScarceResource() +// is called, and so should be detached after that. + +QtObject { + id: root + property MyScarceResourceObject a: MyScarceResourceObject { id: scarceResourceProvider } + property variant scarceResourceCopy; + + function retrieveScarceResource() { + root.scarceResourceCopy = scarceResourceProvider.scarceResource; + } + + function releaseScarceResource() { + root.scarceResourceCopy = null; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceFunctionFail.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceFunctionFail.var.qml new file mode 100644 index 0000000000..9b4b1e6fd9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceFunctionFail.var.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// In this example, a common syntax error will only be "caught" +// when the function is called via: +// QQmlVMEMetaObject::metaCall->invokeMetaMethod() +// We would like to ensure that a useful error message is printed. + +QtObject { + id: root + property MyScarceResourceObject a: MyScarceResourceObject { id: scarceResourceProvider } + property var scarceResourceCopy; + property string srp_name: a.toString(); + + function retrieveScarceResource() { + root.scarceResourceCopy = scarceResourceProvider.scarceResource(); // common syntax error, should throw exception + } + + function releaseScarceResource() { + root.scarceResourceCopy = null; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceFunctionFail.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceFunctionFail.variant.qml new file mode 100644 index 0000000000..57673de3f3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceFunctionFail.variant.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// In this example, a common syntax error will only be "caught" +// when the function is called via: +// QQmlVMEMetaObject::metaCall->invokeMetaMethod() +// We would like to ensure that a useful error message is printed. + +QtObject { + id: root + property MyScarceResourceObject a: MyScarceResourceObject { id: scarceResourceProvider } + property variant scarceResourceCopy; + property string srp_name: a.toString(); + + function retrieveScarceResource() { + root.scarceResourceCopy = scarceResourceProvider.scarceResource(); // common syntax error, should throw exception + } + + function releaseScarceResource() { + root.scarceResourceCopy = null; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleDifferentNoBinding.var.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleDifferentNoBinding.var.js new file mode 100644 index 0000000000..217f693456 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleDifferentNoBinding.var.js @@ -0,0 +1,14 @@ +.import Qt.test 1.0 as JsQtTest + +function importScarceResource() { + var component = Qt.createComponent("scarceResourceCopy.var.qml"); + var scarceResourceElement = component.createObject(null); + var scarceResourceProvider = scarceResourceElement.a; + var retn = scarceResourceProvider.scarceResource; + retn.preserve(); + return retn; +} + +function releaseScarceResource(resource) { + resource.destroy(); +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleDifferentNoBinding.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleDifferentNoBinding.var.qml new file mode 100644 index 0000000000..205131661f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleDifferentNoBinding.var.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceMultipleDifferentNoBinding.var.js" as ScarceResourcesMultipleDifferentNoBinding + +QtObject { + property var resourceOne + property var resourceTwo + + Component.onCompleted: { + resourceOne = ScarceResourcesMultipleDifferentNoBinding.importScarceResource(); + resourceTwo = ScarceResourcesMultipleDifferentNoBinding.importScarceResource(); + ScarceResourcesMultipleDifferentNoBinding.releaseScarceResource(resourceTwo); + } +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleSameNoBinding.var.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleSameNoBinding.var.js new file mode 100644 index 0000000000..5b2494c8e6 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleSameNoBinding.var.js @@ -0,0 +1,15 @@ +.import Qt.test 1.0 as JsQtTest + +var component = Qt.createComponent("scarceResourceCopy.var.qml"); +var scarceResourceElement = component.createObject(null); +var scarceResourceProvider = scarceResourceElement.a; +var retn = scarceResourceProvider.scarceResource; +retn.preserve(); + +function importScarceResource() { + return retn; +} + +function releaseScarceResource(resource) { + resource.destroy(); +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleSameNoBinding.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleSameNoBinding.var.qml new file mode 100644 index 0000000000..e7f6d7868f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleSameNoBinding.var.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceMultipleSameNoBinding.var.js" as ScarceResourcesMultipleSameNoBinding + +QtObject { + property var resourceOne + property var resourceTwo + + Component.onCompleted: { + resourceOne = ScarceResourcesMultipleSameNoBinding.importScarceResource(); + resourceTwo = ScarceResourcesMultipleSameNoBinding.importScarceResource(); + ScarceResourcesMultipleSameNoBinding.releaseScarceResource(resourceTwo); + } +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleSameWithBinding.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleSameWithBinding.var.qml new file mode 100644 index 0000000000..34cb97f39c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceMultipleSameWithBinding.var.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceMultipleDifferentNoBinding.var.js" as ScarceResourcesMultipleDifferentNoBinding + +QtObject { + property var resourceOne: ScarceResourcesMultipleDifferentNoBinding.importScarceResource() + property var resourceTwo: resourceOne + + Component.onCompleted: { + ScarceResourcesMultipleDifferentNoBinding.releaseScarceResource(resourceTwo); + } +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceObjectGc.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceObjectGc.var.qml new file mode 100644 index 0000000000..7ec98e6619 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceObjectGc.var.qml @@ -0,0 +1,30 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: testScarce + + property var varProperty + + property var canary: 4 + + // constructs an Item which contains a scarce resource. + function constructScarceObject() { + var retn = 1; + var component = Qt.createComponent("ScarceResourceVarComponent.qml"); + if (component.status == Component.Ready) { + retn = component.createObject(null); // has JavaScript ownership + } + return retn; + } + + function assignVarProperty() { + varProperty = constructScarceObject(); + gc(); + } + + function deassignVarProperty() { + varProperty = 2; // causes the original object to be garbage collected. + gc(); // image should be detached; ep->sr should be empty! + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceSignal.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceSignal.var.qml new file mode 100644 index 0000000000..0b30e88fa8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceSignal.var.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +QtObject { + id: root + + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + + property ScarceResourceSignalComponentVar b; + b: ScarceResourceSignalComponentVar { + objectName: "srsc" + + onTestSignal: { + // this signal will be invoked manually in the test. + // the scarce resource should be released automatically after evaluation + // and since we don't keep a copy of it, the pixmap will be detached. + width = (scarceResourceProvider.scarceResource,10) + } + + onTestSignal2: { + // this signal will be invoked manually in the test. + // the scarce resource should be released automatically after evaluation + // but since we assign it to a property, the pixmap won't be detached. + scarceResourceCopy = scarceResourceProvider.scarceResource + } + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceSignal.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceSignal.variant.qml new file mode 100644 index 0000000000..1011c7e240 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceSignal.variant.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +QtObject { + id: root + + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + + property ScarceResourceSignalComponentVariant b; + b: ScarceResourceSignalComponentVariant { + objectName: "srsc" + + onTestSignal: { + // this signal will be invoked manually in the test. + // the scarce resource should be released automatically after evaluation + // and since we don't keep a copy of it, the pixmap will be detached. + width = (scarceResourceProvider.scarceResource,10) + } + + onTestSignal2: { + // this signal will be invoked manually in the test. + // the scarce resource should be released automatically after evaluation + // but since we assign it to a property, the pixmap won't be detached. + scarceResourceCopy = scarceResourceProvider.scarceResource + } + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.var.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.var.js new file mode 100644 index 0000000000..c904eb3564 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.var.js @@ -0,0 +1,48 @@ +.import Qt.test 1.0 as JsQtTest + +function importScarceResource(scarceResourceProvider) { + // the scarce resource should be automatically released + // after the binding is evaluated if preserve is not + // called. + return scarceResourceProvider.scarceResource; +} + +function importPreservedScarceResource(scarceResourceProvider) { + // the scarce resource is manually preserved + // during the evaluation of the binding. + // it should not be released. + var scarceResource = scarceResourceProvider.scarceResource; + scarceResource.preserve(); + return scarceResource; +} + +function importReleasedScarceResource(scarceResourceProvider) { + // release the scarce resource during the + // evaluation of the binding. The returned + // variant will therefore be invalid. + var scarceResource = scarceResourceProvider.scarceResource; + scarceResource.destroy(); + return scarceResource; +} + +function importPreservedScarceResourceFromMultiple(scarceResourceProvider) { + // some scarce resources are manually preserved, + // some of them are manually destroyed, + // and some are automatically managed. + // We return a preserved resource + var sr1 = scarceResourceProvider.scarceResource; // preserved/destroyed. + sr1.preserve(); + var sr2 = scarceResourceProvider.scarceResource; // preserved/destroyed + sr2.preserve(); + var sr3 = scarceResourceProvider.scarceResource; // automatic. + var sr4 = scarceResourceProvider.scarceResource; // automatic and returned. + var sr5 = scarceResourceProvider.scarceResource; // destroyed + sr5.destroy(); + sr2.destroy(); + var sr6 = scarceResourceProvider.scarceResource; // destroyed + var sr7 = scarceResourceProvider.scarceResource; // automatic + sr1.destroy(); + sr6.destroy(); + return sr4; +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.var.qml new file mode 100644 index 0000000000..1d4e67055e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.var.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// Here we import a scarce resource directly, and use it in a binding. +// It is not preserved or released manually, so it should be +// automatically released once evaluation of the binding +// is complete. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property int scarceResourceTest: scarceResourceProvider.scarceResource,100 // return 100, but include the scarceResource in the binding to be evaluated. +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.variant.js b/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.variant.js new file mode 100644 index 0000000000..c904eb3564 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.variant.js @@ -0,0 +1,48 @@ +.import Qt.test 1.0 as JsQtTest + +function importScarceResource(scarceResourceProvider) { + // the scarce resource should be automatically released + // after the binding is evaluated if preserve is not + // called. + return scarceResourceProvider.scarceResource; +} + +function importPreservedScarceResource(scarceResourceProvider) { + // the scarce resource is manually preserved + // during the evaluation of the binding. + // it should not be released. + var scarceResource = scarceResourceProvider.scarceResource; + scarceResource.preserve(); + return scarceResource; +} + +function importReleasedScarceResource(scarceResourceProvider) { + // release the scarce resource during the + // evaluation of the binding. The returned + // variant will therefore be invalid. + var scarceResource = scarceResourceProvider.scarceResource; + scarceResource.destroy(); + return scarceResource; +} + +function importPreservedScarceResourceFromMultiple(scarceResourceProvider) { + // some scarce resources are manually preserved, + // some of them are manually destroyed, + // and some are automatically managed. + // We return a preserved resource + var sr1 = scarceResourceProvider.scarceResource; // preserved/destroyed. + sr1.preserve(); + var sr2 = scarceResourceProvider.scarceResource; // preserved/destroyed + sr2.preserve(); + var sr3 = scarceResourceProvider.scarceResource; // automatic. + var sr4 = scarceResourceProvider.scarceResource; // automatic and returned. + var sr5 = scarceResourceProvider.scarceResource; // destroyed + sr5.destroy(); + sr2.destroy(); + var sr6 = scarceResourceProvider.scarceResource; // destroyed + var sr7 = scarceResourceProvider.scarceResource; // automatic + sr1.destroy(); + sr6.destroy(); + return sr4; +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.variant.qml new file mode 100644 index 0000000000..1d4e67055e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceTest.variant.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +// Here we import a scarce resource directly, and use it in a binding. +// It is not preserved or released manually, so it should be +// automatically released once evaluation of the binding +// is complete. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property int scarceResourceTest: scarceResourceProvider.scarceResource,100 // return 100, but include the scarceResource in the binding to be evaluated. +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceTestMultiple.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceTestMultiple.var.qml new file mode 100644 index 0000000000..5e6c2d97f9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceTestMultiple.var.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceTest.var.js" as ScarceResourceProviderJs + +// In this case, multiple scarce resource are explicity preserved +// and then explicitly destroyed, while others are automatically +// managed. Since none are manually preserved without subsequently +// being destroyed, after the evaluation of the binding the +// scarce resource should be detached. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property int scarceResourceTest: ScarceResourceProviderJs.importPreservedScarceResourceFromMultiple(scarceResourceProvider), 100 +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceTestMultiple.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceTestMultiple.variant.qml new file mode 100644 index 0000000000..2970bcb26c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceTestMultiple.variant.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceTest.variant.js" as ScarceResourceProviderJs + +// In this case, multiple scarce resource are explicity preserved +// and then explicitly destroyed, while others are automatically +// managed. Since none are manually preserved without subsequently +// being destroyed, after the evaluation of the binding the +// scarce resource should be detached. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property int scarceResourceTest: ScarceResourceProviderJs.importPreservedScarceResourceFromMultiple(scarceResourceProvider), 100 +} diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceTestPreserve.var.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceTestPreserve.var.qml new file mode 100644 index 0000000000..9e9495c0fa --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceTestPreserve.var.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceTest.var.js" as ScarceResourceProviderJs + +// In this case, the scarce resource is explicity preserved. +// It should not be automatically released after the evaluation +// of the binding is complete, but instead will be kept in +// memory until the JS garbage collector runs. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property int scarceResourceTest: ScarceResourceProviderJs.importPreservedScarceResource(scarceResourceProvider),100 // return 100, but the resource should be preserved. +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scarceResourceTestPreserve.variant.qml b/tests/auto/qml/qqmlecmascript/data/scarceResourceTestPreserve.variant.qml new file mode 100644 index 0000000000..022067beca --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scarceResourceTestPreserve.variant.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 +import Qt.test 1.0 +import "scarceResourceTest.variant.js" as ScarceResourceProviderJs + +// In this case, the scarce resource is explicity preserved. +// It should not be automatically released after the evaluation +// of the binding is complete, but instead will be kept in +// memory until the JS garbage collector runs. + +QtObject { + property MyScarceResourceObject a; + a: MyScarceResourceObject { id: scarceResourceProvider } + property int scarceResourceTest: ScarceResourceProviderJs.importPreservedScarceResource(scarceResourceProvider),100 // return 100, but the resource should be preserved. +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scope.2.qml b/tests/auto/qml/qqmlecmascript/data/scope.2.qml new file mode 100644 index 0000000000..fe1c4c7931 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scope.2.qml @@ -0,0 +1,40 @@ +import QtQuick 2.0 + +Item { + property int a: 0 + property int b: 14 + + 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 + + // properties takes precedence over local, and root methods + 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/qml/qqmlecmascript/data/scope.3.qml b/tests/auto/qml/qqmlecmascript/data/scope.3.qml new file mode 100644 index 0000000000..9add81809c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scope.3.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + id: root + + property int foo: 12 + + property bool test1: foo == 12 + property bool test2: console != 11 + property bool test3: root.console == 11 +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scope.4.qml b/tests/auto/qml/qqmlecmascript/data/scope.4.qml new file mode 100644 index 0000000000..d65b6e7c7c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scope.4.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 + +MyQmlObject { + id: a + property int b: 9 + + property int test + property string test2 + + // Should resolve to signal arguments, not to other elements in the file + onArgumentSignal: { test = a; test2 = b; } +} diff --git a/tests/auto/qml/qqmlecmascript/data/scope.5.qml b/tests/auto/qml/qqmlecmascript/data/scope.5.qml new file mode 100644 index 0000000000..6dbcbe2a40 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scope.5.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 + +Item { + property bool test1: false; + property bool test2: false; + + property int a: 10 + + Item { + id: nested + property int a: 11 + + function mynestedfunction() { + return a; + } + } + + function myouterfunction() { + return a; + } + + Component.onCompleted: { + test1 = (myouterfunction() == 10); + test2 = (nested.mynestedfunction() == 11); + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scope.6.qml b/tests/auto/qml/qqmlecmascript/data/scope.6.qml new file mode 100644 index 0000000000..5897b533d7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scope.6.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +Item { + id: me + property bool test: nested.runtest(me); + + Scope6Nested { + id: nested + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/scope.qml b/tests/auto/qml/qqmlecmascript/data/scope.qml new file mode 100644 index 0000000000..a00352b684 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scope.qml @@ -0,0 +1,44 @@ +import QtQuick 2.0 + +Item { + id: root + + property int a: 1 + property int binding: a + property string binding2: a + "Test" + property int binding3: myFunction() + property int binding4: nestedObject.myNestedFunction() + + function myFunction() { + return a; + } + + Item { + id: nestedObject + + 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/qml/qqmlecmascript/data/scriptConnect.1.js b/tests/auto/qml/qqmlecmascript/data/scriptConnect.1.js new file mode 100644 index 0000000000..54284fea47 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.1.js @@ -0,0 +1,4 @@ +function testFunction() { + test = true; +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.1.qml b/tests/auto/qml/qqmlecmascript/data/scriptConnect.1.qml new file mode 100644 index 0000000000..ace473756e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.1.qml @@ -0,0 +1,10 @@ +import Qt.test 1.0 +import QtQuick 2.0 +import "scriptConnect.1.js" as Script +MyQmlObject { + property bool test: false + + id: root + + Component.onCompleted: root.argumentSignal.connect(Script.testFunction); +} diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.2.js b/tests/auto/qml/qqmlecmascript/data/scriptConnect.2.js new file mode 100644 index 0000000000..595c778aa7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.2.js @@ -0,0 +1,5 @@ +function testFunction() { + if (this.b == 12) + test = true; +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.2.qml b/tests/auto/qml/qqmlecmascript/data/scriptConnect.2.qml new file mode 100644 index 0000000000..cdf2d6ad98 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.2.qml @@ -0,0 +1,16 @@ +import Qt.test 1.0 +import QtQuick 2.0 +import "scriptConnect.2.js" as Script + +MyQmlObject { + property bool test: false + + id: root + + Component.onCompleted: { + var a = new Object; + a.b = 12; + root.argumentSignal.connect(a, Script.testFunction); + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.3.qml b/tests/auto/qml/qqmlecmascript/data/scriptConnect.3.qml new file mode 100644 index 0000000000..b0e40565c0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.3.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + property bool test: false + + id: root + + function testFunction() { + test = true; + } + + Component.onCompleted: root.argumentSignal.connect(testFunction); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.4.qml b/tests/auto/qml/qqmlecmascript/data/scriptConnect.4.qml new file mode 100644 index 0000000000..ef5331c94a --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.4.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + property bool test: false + + id: root + + Component.onCompleted: root.argumentSignal.connect(methodNoArgs); +} + + diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.5.qml b/tests/auto/qml/qqmlecmascript/data/scriptConnect.5.qml new file mode 100644 index 0000000000..8dcacbcbb7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.5.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + property bool test: false + + id: root + + Component.onCompleted: root.argumentSignal.connect(root, methodNoArgs); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.6.js b/tests/auto/qml/qqmlecmascript/data/scriptConnect.6.js new file mode 100644 index 0000000000..71bdd088a2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.6.js @@ -0,0 +1,3 @@ +function testFunction() { + test++; +} diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.6.qml b/tests/auto/qml/qqmlecmascript/data/scriptConnect.6.qml new file mode 100644 index 0000000000..06b6f0fa62 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.6.qml @@ -0,0 +1,15 @@ +import Qt.test 1.0 +import QtQuick 2.0 +import "scriptConnect.6.js" as Script + +MyQmlObject { + property int test: 0 + + id: root + + Component.onCompleted: { + root.argumentSignal.connect(Script.testFunction); + root.argumentSignal.connect(Script.testFunction); + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.1.js b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.1.js new file mode 100644 index 0000000000..407426fcd1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.1.js @@ -0,0 +1,6 @@ +function testFunction() { + test++; +} + +function otherFunction() { +} diff --git a/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.1.qml b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.1.qml new file mode 100644 index 0000000000..e546ee44d8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.1.qml @@ -0,0 +1,13 @@ +import Qt.test 1.0 +import QtQuick 2.0 +import "scriptDisconnect.1.js" as Script + +MyQmlObject { + property int test: 0 + + id: root + + Component.onCompleted: root.argumentSignal.connect(Script.testFunction); + + onBasicSignal: root.argumentSignal.disconnect(Script.testFunction); +} diff --git a/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.2.qml b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.2.qml new file mode 100644 index 0000000000..e70cd8b900 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.2.qml @@ -0,0 +1,14 @@ +import Qt.test 1.0 +import QtQuick 2.0 +import "scriptDisconnect.1.js" as Script + +MyQmlObject { + property int test: 0 + + id: root + + Component.onCompleted: root.argumentSignal.connect(root, Script.testFunction); + + onBasicSignal: root.argumentSignal.disconnect(root, Script.testFunction); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.3.qml b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.3.qml new file mode 100644 index 0000000000..6f47776ea5 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.3.qml @@ -0,0 +1,14 @@ +import Qt.test 1.0 +import QtQuick 2.0 +import "scriptDisconnect.1.js" as Script + +MyQmlObject { + property int test: 0 + + id: root + + Component.onCompleted: root.argumentSignal.connect(root, Script.testFunction); + + onBasicSignal: root.argumentSignal.disconnect(Script.testFunction); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.4.qml b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.4.qml new file mode 100644 index 0000000000..b3887545fb --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.4.qml @@ -0,0 +1,13 @@ +import Qt.test 1.0 +import QtQuick 2.0 +import "scriptDisconnect.1.js" as Script + +MyQmlObject { + property int test: 0 + + id: root + + Component.onCompleted: root.argumentSignal.connect(Script.testFunction); + + onBasicSignal: root.argumentSignal.disconnect(Script.otherFunction); +} diff --git a/tests/auto/qml/qqmlecmascript/data/scriptErrors.js b/tests/auto/qml/qqmlecmascript/data/scriptErrors.js new file mode 100644 index 0000000000..d22f623edb --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptErrors.js @@ -0,0 +1,4 @@ +// Comment +a = 10 + +function getValue() { a = 10; return 0; } diff --git a/tests/auto/qml/qqmlecmascript/data/scriptErrors.qml b/tests/auto/qml/qqmlecmascript/data/scriptErrors.qml new file mode 100644 index 0000000000..4998f63929 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptErrors.qml @@ -0,0 +1,18 @@ +import Qt.test 1.0 +import "scriptErrors.js" as Script + +MyQmlObject { + property int t: a.value + property int w: Script.getValue(); + property int d: undefined + ? 0 // multi-line binding + : 1 + property int x: undefined + 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/qml/qqmlecmascript/data/selfDeletingBinding.2.qml b/tests/auto/qml/qqmlecmascript/data/selfDeletingBinding.2.qml new file mode 100644 index 0000000000..58cf8051f0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/selfDeletingBinding.2.qml @@ -0,0 +1,17 @@ +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/qml/qqmlecmascript/data/selfDeletingBinding.qml b/tests/auto/qml/qqmlecmascript/data/selfDeletingBinding.qml new file mode 100644 index 0000000000..074851a67b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/selfDeletingBinding.qml @@ -0,0 +1,18 @@ +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/qml/qqmlecmascript/data/sequenceConversion.array.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml new file mode 100644 index 0000000000..52abda1e55 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml @@ -0,0 +1,193 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + } + + property bool success: false + + property variant intList + property variant qrealList + property variant boolList + property variant stringList + + function indexedAccess() { + intList = msco.intListProperty; + var jsIntList = msco.intListProperty; + qrealList = msco.qrealListProperty; + var jsQrealList = msco.qrealListProperty; + boolList = msco.boolListProperty; + var jsBoolList = msco.boolListProperty; + stringList = msco.stringListProperty; + var jsStringList = msco.stringListProperty; + + // Three cases: direct property modification, variant copy modification, js var reference modification. + // Only the first and third should "write back" to the original QObject Q_PROPERTY; the second one + // should have no effect whatsoever to maintain "property variant" semantics (see e.g., valuetype). + success = true; + + msco.intListProperty[1] = 33; + if (msco.intListProperty[1] != 33) success = false; // ensure write back + intList[1] = 44; + if (intList[1] == 44) success = false; // ensure no effect + jsIntList[1] = 55; + if (jsIntList[1] != 55 + || jsIntList[1] != msco.intListProperty[1]) success = false; // ensure write back + + msco.qrealListProperty[1] = 33.3; + if (msco.qrealListProperty[1] != 33.3) success = false; // ensure write back + qrealList[1] = 44.4; + if (qrealList[1] == 44.4) success = false; // ensure no effect + jsQrealList[1] = 55.5; + if (jsQrealList[1] != 55.5 + || jsQrealList[1] != msco.qrealListProperty[1]) success = false; // ensure write back + + msco.boolListProperty[1] = true; + if (msco.boolListProperty[1] != true) success = false; // ensure write back + boolList[1] = true; + if (boolList[1] != false) success = false; // ensure no effect + jsBoolList[1] = false; + if (jsBoolList[1] != false + || jsBoolList[1] != msco.boolListProperty[1]) success = false; // ensure write back + + msco.stringListProperty[1] = "changed"; + if (msco.stringListProperty[1] != "changed") success = false; // ensure write back + stringList[1] = "changed"; + if (stringList[1] != "second") success = false; // ensure no effect + jsStringList[1] = "different"; + if (jsStringList[1] != "different" + || jsStringList[1] != msco.stringListProperty[1]) success = false; // ensure write back + } + + function arrayOperations() { + success = true; + var expected = 0; + var expectedStr = ""; + + // ecma262r3 defines array as implementing Length and Put. Test put here. + msco.intListProperty.asdf = 5; // shouldn't work, only indexes are valid names. + if (msco.intListProperty.asdf == 5) success = false; + msco.intListProperty[3] = 38; // should work. + if (msco.intListProperty[3] != 38) success = false; + msco.intListProperty[199] = 200; // should work, and should set length to 200. + if (msco.intListProperty[199] != 200) success = false; + if (msco.intListProperty.length != 200) success = false; + + // test indexed deleter + msco.intListProperty = [ 1, 2, 3, 4, 5 ]; + delete msco.intListProperty[-1]; + expected = [ 1, 2, 3, 4, 5 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + delete msco.intListProperty[0]; + expected = [ 0, 2, 3, 4, 5 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + delete msco.intListProperty[2]; + expected = [ 0, 2, 0, 4, 5 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + delete msco.intListProperty[7]; + expected = [ 0, 2, 0, 4, 5 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + + // other operations are defined on the array prototype; see if they work. + + // splice + msco.intListProperty = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; + msco.intListProperty.splice(1,3, 33, 44, 55, 66); + expected = [ 0, 33, 44, 55, 66, 4, 5, 6, 7 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + msco.intListProperty = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; + msco.intListProperty.splice(1, 3); + expected = [ 0, 4, 5, 6, 7 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + + msco.qrealListProperty = [ 0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1 ]; + msco.qrealListProperty.splice(1,3, 33.33, 44.44, 55.55, 66.66); + expected = [ 0.1, 33.33, 44.44, 55.55, 66.66, 4.1, 5.1, 6.1, 7.1 ]; + if (msco.qrealListProperty.toString() != expected.toString()) success = false; + msco.qrealListProperty = [ 0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1 ]; + msco.qrealListProperty.splice(1,3); + expected = [ 0.1, 4.1, 5.1, 6.1, 7.1 ]; + if (msco.qrealListProperty.toString() != expected.toString()) success = false; + + msco.boolListProperty = [ false, true, true, false, false, true, false, true ]; + msco.boolListProperty.splice(1,3, false, true, false, false); + expected = [ false, false, true, false, false, false, true, false, true ]; + if (msco.boolListProperty.toString() != expected.toString()) success = false; + msco.boolListProperty = [ false, true, true, false, false, true, false, true ]; + msco.boolListProperty.splice(1,3); + expected = [ false, false, true, false, true ]; + if (msco.boolListProperty.toString() != expected.toString()) success = false; + + msco.stringListProperty = [ "one", "two", "three", "four", "five", "six", "seven", "eight" ]; + msco.stringListProperty.splice(1,3, "nine", "ten", "eleven", "twelve"); + expected = [ "one", "nine", "ten", "eleven", "twelve", "five", "six", "seven", "eight" ]; + if (msco.stringListProperty.toString() != expected.toString()) success = false; + msco.stringListProperty = [ "one", "two", "three", "four", "five", "six", "seven", "eight" ]; + msco.stringListProperty.splice(0,3); + expected = [ "four", "five", "six", "seven", "eight" ]; + if (msco.stringListProperty.toString() != expected.toString()) success = false; + + // pop + msco.intListProperty = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; + var poppedVal = msco.intListProperty.pop(); + expected = [ 0, 1, 2, 3, 4, 5, 6 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + expected = 7; + if (poppedVal != expected) success = false; + } + + property variant variantList: [ 1, 2, 3, 4, 5 ]; + property variant variantList2: [ 1, 2, 3, 4, 5 ]; + function testEqualitySemantics() { + // ensure equality semantics match JS array equality semantics + success = true; + + msco.intListProperty = [ 1, 2, 3, 4, 5 ]; + msco.intListProperty2 = [ 1, 2, 3, 4, 5 ]; + var jsIntList = [ 1, 2, 3, 4, 5 ]; + var jsIntList2 = [ 1, 2, 3, 4, 5 ]; + + if (jsIntList != jsIntList) success = false; + if (jsIntList == jsIntList2) success = false; + if (jsIntList == msco.intListProperty) success = false; + if (jsIntList == variantList) success = false; + + if (msco.intListProperty != msco.intListProperty) success = false; + if (msco.intListProperty == msco.intListProperty2) success = false; + if (msco.intListProperty == jsIntList) success = false; + if (msco.intListProperty == variantList) success = false; + + if (variantList == variantList) return false; + if (variantList == variantList2) return false; + if (variantList == msco.intListProperty) return false; + if (variantList == jsIntList) return false; + + if ((jsIntList == jsIntList2) != (jsIntList == msco.intListProperty)) success = false; + if ((jsIntList == jsIntList2) != (msco.intListProperty == msco.intListProperty2)) success = false; + if ((jsIntList == jsIntList) != (msco.intListProperty == msco.intListProperty)) success = false; + if ((jsIntList == variantList) != (msco.intListProperty == variantList)) success = false; + if ((variantList == jsIntList) != (variantList == msco.intListProperty)) success = false; + if ((msco.intListProperty == variantList) != (variantList == msco.intListProperty)) success = false; + } + + property bool referenceDeletion: false + function testReferenceDeletion() { + referenceDeletion = true; + var testObj = msco.generateTestObject(); + testObj.intListProperty = [1, 2, 3, 4, 5]; + var testSequence = testObj.intListProperty; + var prevString = testSequence.toString(); + var prevValueOf = testSequence.valueOf(); + var prevLength = testSequence.length; + msco.deleteTestObject(testObj); // delete referenced object. + if (testSequence.toString() == prevString) referenceDeletion = false; + if (testSequence.valueOf() == prevValueOf) referenceDeletion = false; + if (testSequence.length == prevLength) referenceDeletion = false; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.bindings.error.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.bindings.error.qml new file mode 100644 index 0000000000..9c87dd293e --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.bindings.error.qml @@ -0,0 +1,19 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + intListProperty: [ 1, 2, 3, 6, 7 ] + } + + MySequenceConversionObject { + id: mscoTwo + objectName: "mscoTwo" + boolListProperty: msco.intListProperty + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.bindings.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.bindings.qml new file mode 100644 index 0000000000..8d83e9f9f5 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.bindings.qml @@ -0,0 +1,28 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + intListProperty: [ 1, 2, 3, 6, 7 ] + } + + MySequenceConversionObject { + id: mscoTwo + objectName: "mscoTwo" + intListProperty: msco.intListProperty + } + + property variant boundSequence: msco.intListProperty + property int boundElement: msco.intListProperty[3] + property variant boundSequenceTwo: mscoTwo.intListProperty + + Component.onCompleted: { + msco.intListProperty[3] = 12; + mscoTwo.intListProperty[4] = 14; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.copy.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.copy.qml new file mode 100644 index 0000000000..f6614dad0c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.copy.qml @@ -0,0 +1,160 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + } + + property bool success: true + + property variant intList + property variant qrealList + property variant boolList + property variant stringList + property variant urlList + property variant qstringList + + // this test ensures that the "copy resource" codepaths work + function testCopySequences() { + success = true; + + // create "copy resource" sequences + var jsIntList = msco.generateIntSequence(); + var jsQrealList = msco.generateQrealSequence(); + var jsBoolList = msco.generateBoolSequence(); + var jsStringList = msco.generateStringSequence(); + var jsUrlList = msco.generateUrlSequence(); + var jsQStringList = msco.generateQStringSequence(); + + if (jsIntList.toString() != [1, 2, 3].toString()) + success = false; + if (jsQrealList.toString() != [1.1, 2.2, 3.3].toString()) + success = false; + if (jsBoolList.toString() != [true, false, true].toString()) + success = false; + if (jsStringList.toString() != ["one", "two", "three"].toString()) + success = false; + if (jsUrlList.toString() != ["http://www.example1.com", "http://www.example2.com", "http://www.example3.com"].toString()) + success = false; + if (jsQStringList.toString() != ["one", "two", "three"].toString()) + success = false; + + // copy the sequence; should result in a new copy + intList = jsIntList; + qrealList = jsQrealList; + boolList = jsBoolList; + stringList = jsStringList; + urlList = jsUrlList; + qstringList = jsQStringList; + + // these operations shouldn't modify either variables - because + // we don't handle writing to the intermediate variant at list[index] + // for variant properties. + intList[1] = 8; + qrealList[1] = 8.8; + boolList[1] = true; + stringList[1] = "eight"; + urlList[1] = "http://www.example8.com"; + qstringList[1] = "eight"; + + if (jsIntList[1] == 8) + success = false; + if (jsQrealList[1] == 8.8) + success = false; + if (jsBoolList[1] == true) + success = false; + if (jsStringList[1] == "eight") + success = false; + if (jsUrlList[1] == "http://www.example8.com") + success = false; + if (jsQStringList[1] == "eight") + success = false; + + // assign a "copy resource" sequence to a QObject Q_PROPERTY + msco.intListProperty = intList; + msco.qrealListProperty = qrealList; + msco.boolListProperty = boolList; + msco.stringListProperty = stringList; + msco.urlListProperty = urlList; + msco.qstringListProperty = qstringList; + + if (msco.intListProperty.toString() != [1, 2, 3].toString()) + success = false; + if (msco.qrealListProperty.toString() != [1.1, 2.2, 3.3].toString()) + success = false; + if (msco.boolListProperty.toString() != [true, false, true].toString()) + success = false; + if (msco.stringListProperty.toString() != ["one", "two", "three"].toString()) + success = false; + if (msco.urlListProperty.toString() != ["http://www.example1.com", "http://www.example2.com", "http://www.example3.com"].toString()) + success = false; + if (msco.qstringListProperty.toString() != ["one", "two", "three"].toString()) + success = false; + + // now modify the QObject Q_PROPERTY (reference resource) sequences - shouldn't modify the copy resource sequences. + msco.intListProperty[2] = 9; + msco.qrealListProperty[2] = 9.9; + msco.boolListProperty[2] = false; + msco.stringListProperty[2] = "nine"; + msco.urlListProperty[2] = "http://www.example9.com"; + msco.qstringListProperty[2] = "nine"; + + if (intList[2] == 9) + success = false; + if (qrealList[2] == 9.9) + success = false; + if (boolList[2] == false) + success = false; + if (stringList[2] == "nine") + success = false; + if (urlList[2] == "http://www.example9.com") + success = false; + if (qstringList[2] == "nine") + success = false; + } + + property int intVal + property real qrealVal + property bool boolVal + property string stringVal + + // this test ensures that indexed access works for copy resource sequences. + function readSequenceCopyElements() { + success = true; + + var jsIntList = msco.generateIntSequence(); + var jsQrealList = msco.generateQrealSequence(); + var jsBoolList = msco.generateBoolSequence(); + var jsStringList = msco.generateStringSequence(); + + intVal = jsIntList[1]; + qrealVal = jsQrealList[1]; + boolVal = jsBoolList[1]; + stringVal = jsStringList[1]; + + if (intVal != 2) + success = false; + if (qrealVal != 2.2) + success = false; + if (boolVal != false) + success = false; + if (stringVal != "two") + success = false; + } + + // this test ensures that equality works for copy resource sequences. + function testEqualitySemantics() { + success = true; + + var jsIntList = msco.generateIntSequence(); + var jsIntList2 = msco.generateIntSequence(); + + if (jsIntList == jsIntList2) success = false; + if (jsIntList != jsIntList) success = false; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml new file mode 100644 index 0000000000..23f1e90417 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml @@ -0,0 +1,89 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + } + + property bool success: false + + function verifyExpected(array, idx) { + for (var i = 0; i < idx; ++i) { + if (array[i] != i) { + return false; + } + } + return true; + } + + function indexedAccess() { + success = true; + + msco.intListProperty = [ 0, 1, 2, 3, 4 ]; + var expectedLength = msco.intListProperty.length; + var maxIndex = msco.maxIndex; + var tooBigIndex = msco.tooBigIndex; + var negativeIndex = msco.negativeIndex; + + // shouldn't be able to set the length > maxIndex. + msco.intListProperty.length = tooBigIndex; + if (msco.intListProperty.length != expectedLength) + success = false; + if (!verifyExpected(msco.intListProperty, 4)) + success = false; + + // shouldn't be able to set any index > maxIndex. + msco.intListProperty[tooBigIndex] = 12; + if (msco.intListProperty.length != expectedLength) + success = false; + if (!verifyExpected(msco.intListProperty, 4)) + success = false; + + // shouldn't be able to access any index > maxIndex. + var valueAtTBI = msco.intListProperty[tooBigIndex]; + if (valueAtTBI != undefined) + success = false; + if (!verifyExpected(msco.intListProperty, 4)) + success = false; + + // shouldn't be able to set the length to < 0 + msco.intListProperty.length = negativeIndex; + if (msco.intListProperty.length != expectedLength) + success = false; // shouldn't have changed. + if (!verifyExpected(msco.intListProperty, 4)) + success = false; + + // shouldn't be able to set any index < 0. + msco.intListProperty[negativeIndex] = 12; + if (msco.intListProperty.length != expectedLength) + success = false; + if (!verifyExpected(msco.intListProperty, 4)) + success = false; + + // shouldn't be able to access any index < 0. + var valueAtNI = msco.intListProperty[negativeIndex]; + if (valueAtNI != undefined) + success = false; + if (!verifyExpected(msco.intListProperty, 4)) + success = false; + + // NOTE: while these two operations are technically + // fine, we expect std::bad_alloc exceptions here + // which we handle in the sequence wrapper. + msco.intListProperty.length = maxIndex; + if (msco.intListProperty.length != expectedLength) + success = false; + if (!verifyExpected(msco.intListProperty, 4)) + success = false; + msco.intListProperty[maxIndex] = 15; + if (msco.intListProperty.length != expectedLength) + success = false; + if (!verifyExpected(msco.intListProperty, 4)) + success = false; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.error.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.error.qml new file mode 100644 index 0000000000..12a76d7e7d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.error.qml @@ -0,0 +1,21 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + } + + property int pointListLength: 0 + property variant pointList + + function performTest() { + // we have NOT registered QList<QPoint> as a type + pointListLength = msco.pointListProperty.length; + pointList = msco.pointListProperty; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.qml new file mode 100644 index 0000000000..4a8a4a17b2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.read.qml @@ -0,0 +1,105 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + } + + property int intListLength: 0 + property variant intList + property int qrealListLength: 0 + property variant qrealList + property int boolListLength: 0 + property variant boolList + property int stringListLength: 0 + property variant stringList + property int urlListLength: 0 + property variant urlList + property int qstringListLength: 0 + property variant qstringList + + function readSequences() { + intListLength = msco.intListProperty.length; + intList = msco.intListProperty; + qrealListLength = msco.qrealListProperty.length; + qrealList = msco.qrealListProperty; + boolListLength = msco.boolListProperty.length; + boolList = msco.boolListProperty; + stringListLength = msco.stringListProperty.length; + stringList = msco.stringListProperty; + urlListLength = msco.urlListProperty.length; + urlList = msco.urlListProperty; + qstringListLength = msco.qstringListProperty.length; + qstringList = msco.qstringListProperty; + } + + property int intVal + property real qrealVal + property bool boolVal + property string stringVal + property url urlVal + property string qstringVal + + function readSequenceElements() { + intVal = msco.intListProperty[1]; + qrealVal = msco.qrealListProperty[1]; + boolVal = msco.boolListProperty[1]; + stringVal = msco.stringListProperty[1]; + urlVal = msco.urlListProperty[1]; + qstringVal = msco.qstringListProperty[1]; + } + + property bool enumerationMatches + function enumerateSequenceElements() { + var jsIntList = [1, 2, 3, 4, 5]; + msco.intListProperty = [1, 2, 3, 4, 5]; + + var jsIntListProps = [] + var seqIntListProps = [] + + enumerationMatches = true; + for (var i in jsIntList) { + jsIntListProps.push(i); + if (jsIntList[i] != msco.intListProperty[i]) { + enumerationMatches = false; + } + } + for (var j in msco.intListProperty) { + seqIntListProps.push(j); + if (jsIntList[j] != msco.intListProperty[j]) { + enumerationMatches = false; + } + } + + if (jsIntListProps.length != seqIntListProps.length) { + enumerationMatches = false; + } + + var emptyList = []; + msco.stringListProperty = [] + if (emptyList.toString() != msco.stringListProperty.toString()) { + enumerationMatches = false; + } + if (emptyList.valueOf() != msco.stringListProperty.valueOf()) { + enumerationMatches = false; + } + } + + property bool referenceDeletion: false + function testReferenceDeletion() { + referenceDeletion = true; + var testObj = msco.generateTestObject(); + testObj.intListProperty = [1, 2, 3, 4, 5]; + var testSequence = testObj.intListProperty; + if (testSequence[4] != 5) + referenceDeletion = false; + msco.deleteTestObject(testObj); // delete referenced object. + if (testSequence[4] == 5) + referenceDeletion = false; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.threads.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.threads.qml new file mode 100644 index 0000000000..aefad89ca4 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.threads.qml @@ -0,0 +1,74 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + } + + property bool success: false + property bool finished: false + + function testIntSequence() { + msco.intListProperty = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; + worker.sendSequence(msco.intListProperty); + } + + function testQrealSequence() { + msco.qrealListProperty = [ 0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1 ]; + worker.sendSequence(msco.qrealListProperty); + } + + function testBoolSequence() { + msco.boolListProperty = [ false, true, true, false, false, true, false, true ]; + worker.sendSequence(msco.boolListProperty); + } + + function testStringSequence() { + msco.stringListProperty = [ "one", "two", "three", "four" ]; + worker.sendSequence(msco.stringListProperty); + } + + function testQStringSequence() { + msco.qstringListProperty = [ "one", "two", "three", "four" ]; + worker.sendSequence(msco.qstringListProperty); + } + + function testUrlSequence() { + msco.urlListProperty = [ "www.example1.com", "www.example2.com", "www.example3.com", "www.example4.com" ]; + worker.sendSequence(msco.urlListProperty); + } + + function testVariantSequence() { + msco.variantListProperty = [ "one", true, 3, "four" ]; + worker.sendSequence(msco.variantListProperty); + } + + WorkerScript { + id: worker + source: "threadScript.js" + + property variant expected + property variant response + + function sendSequence(seq) { + root.success = false; + root.finished = false; + worker.expected = seq; + worker.sendMessage(seq); + } + + onMessage: { + worker.response = messageObject; + if (worker.response.toString() == worker.expected.toString()) + root.success = true; + else + root.success = false; + root.finished = true; + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.write.error.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.write.error.qml new file mode 100644 index 0000000000..75beafd1ee --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.write.error.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + } + + function performTest() { + // we have NOT registered QList<QPoint> as a type + var pointList = [ Qt.point(7,7), Qt.point(8,8), Qt.point(9,9) ]; + msco.pointListProperty = pointList; // error. + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.write.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.write.qml new file mode 100644 index 0000000000..812de043b7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.write.qml @@ -0,0 +1,109 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + objectName: "root" + + MySequenceConversionObject { + id: msco + objectName: "msco" + } + + property bool success + + function writeSequences() { + success = true; + + var intList = [ 9, 8, 7, 6 ]; + msco.intListProperty = intList; + var qrealList = [ 9.9, 8.8, 7.7, 6.6 ]; + msco.qrealListProperty = qrealList; + var boolList = [ false, false, false, true ]; + msco.boolListProperty = boolList; + var stringList = [ "nine", "eight", "seven", "six" ] + msco.stringListProperty = stringList; + var urlList = [ "http://www.example9.com", "http://www.example8.com", "http://www.example7.com", "http://www.example6.com" ] + msco.urlListProperty = urlList; + var qstringList = [ "nine", "eight", "seven", "six" ] + msco.qstringListProperty = qstringList; + + if (msco.intListProperty[0] != 9 || msco.intListProperty[1] != 8 || msco.intListProperty[2] != 7 || msco.intListProperty[3] != 6) + success = false; + if (msco.qrealListProperty[0] != 9.9 || msco.qrealListProperty[1] != 8.8 || msco.qrealListProperty[2] != 7.7 || msco.qrealListProperty[3] != 6.6) + success = false; + if (msco.boolListProperty[0] != false || msco.boolListProperty[1] != false || msco.boolListProperty[2] != false || msco.boolListProperty[3] != true) + success = false; + if (msco.stringListProperty[0] != "nine" || msco.stringListProperty[1] != "eight" || msco.stringListProperty[2] != "seven" || msco.stringListProperty[3] != "six") + success = false; + if (msco.urlListProperty[0] != "http://www.example9.com" || msco.urlListProperty[1] != "http://www.example8.com" || msco.urlListProperty[2] != "http://www.example7.com" || msco.urlListProperty[3] != "http://www.example6.com") + success = false; + if (msco.qstringListProperty[0] != "nine" || msco.qstringListProperty[1] != "eight" || msco.qstringListProperty[2] != "seven" || msco.qstringListProperty[3] != "six") + success = false; + } + + function writeSequenceElements() { + // set up initial conditions. + writeSequences(); + success = true; + + // element set. + msco.intListProperty[3] = 2; + msco.qrealListProperty[3] = 2.2; + msco.boolListProperty[3] = false; + msco.stringListProperty[3] = "changed"; + msco.urlListProperty[3] = "http://www.examplechanged.com"; + msco.qstringListProperty[3] = "changed"; + + if (msco.intListProperty[0] != 9 || msco.intListProperty[1] != 8 || msco.intListProperty[2] != 7 || msco.intListProperty[3] != 2) + success = false; + if (msco.qrealListProperty[0] != 9.9 || msco.qrealListProperty[1] != 8.8 || msco.qrealListProperty[2] != 7.7 || msco.qrealListProperty[3] != 2.2) + success = false; + if (msco.boolListProperty[0] != false || msco.boolListProperty[1] != false || msco.boolListProperty[2] != false || msco.boolListProperty[3] != false) + success = false; + if (msco.stringListProperty[0] != "nine" || msco.stringListProperty[1] != "eight" || msco.stringListProperty[2] != "seven" || msco.stringListProperty[3] != "changed") + success = false; + if (msco.urlListProperty[0] != "http://www.example9.com" || msco.urlListProperty[1] != "http://www.example8.com" || msco.urlListProperty[2] != "http://www.example7.com" || msco.urlListProperty[3] != "http://www.examplechanged.com") + success = false; + if (msco.qstringListProperty[0] != "nine" || msco.qstringListProperty[1] != "eight" || msco.qstringListProperty[2] != "seven" || msco.qstringListProperty[3] != "changed") + success = false; + } + + function writeOtherElements() { + success = true; + var jsIntList = [1, 2, 3, 4, 5]; + msco.intListProperty = [1, 2, 3, 4, 5]; + + jsIntList[8] = 8; + msco.intListProperty[8] = 8; + if (jsIntList[8] != msco.intListProperty[8]) + success = false; + if (jsIntList.length != msco.intListProperty.length) + success = false; + + // NOTE: we can't exactly match the spec here -- we fill the sequence with a default (rather than empty) value + if (msco.intListProperty[5] != 0 || msco.intListProperty[6] != 0 || msco.intListProperty[7] != 0) + success = false; + + // should have no effect + var currLength = jsIntList.length; + jsIntList.someThing = 9; + msco.intListProperty.someThing = 9; + if (msco.intListProperty.length != currLength) + success = false; + } + + property bool referenceDeletion: false + function testReferenceDeletion() { + referenceDeletion = true; + var testObj = msco.generateTestObject(); + testObj.intListProperty = [1, 2, 3, 4, 5]; + var testSequence = testObj.intListProperty; + if (testSequence[4] != 5) + referenceDeletion = false; + msco.deleteTestObject(testObj); // delete referenced object. + testSequence[4] = 5; // shouldn't work, since referenced object no longer exists. + if (testSequence[4] == 5) + referenceDeletion = false; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/sharedAttachedObject.qml b/tests/auto/qml/qqmlecmascript/data/sharedAttachedObject.qml new file mode 100644 index 0000000000..b967f0984c --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/sharedAttachedObject.qml @@ -0,0 +1,16 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyQmlObject { + id: root + property bool test1: false + property bool test2: false + + MyQmlObject.value2: 7 + + Component.onCompleted: { + test1 = root.MyQmlObject.value2 == 7; + test2 = root.MyQmlObjectAlias.value2 == 7; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/shutdownErrors.qml b/tests/auto/qml/qqmlecmascript/data/shutdownErrors.qml new file mode 100644 index 0000000000..b30aa8b4cd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/shutdownErrors.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +Item { + property int test: myObject.object.a + + Item { + id: myObject + property QtObject object; + object: QtObject { + property int a: 10 + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/signalAssignment.1.qml b/tests/auto/qml/qqmlecmascript/data/signalAssignment.1.qml new file mode 100644 index 0000000000..fbd09142f7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/signalAssignment.1.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + onBasicSignal: setString('pass') +} diff --git a/tests/auto/qml/qqmlecmascript/data/signalAssignment.2.qml b/tests/auto/qml/qqmlecmascript/data/signalAssignment.2.qml new file mode 100644 index 0000000000..6467c42bb9 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/signalAssignment.2.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + onArgumentSignal: setString('pass ' + a + ' ' + b + ' ' + c + ' ' + d + ' ' + e) +} diff --git a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml new file mode 100644 index 0000000000..975be1b2ad --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml @@ -0,0 +1,60 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +QtObject { + id: root + + property int count: 0 + signal testSignal + onTestSignal: count++ + + property int funcCount: 0 + function testFunction() { + funcCount++; + } + + //should increment count + function testSignalCall() { + testSignal() + } + + //should NOT increment count, and should throw an exception + property string errorString + function testSignalHandlerCall() { + try { + onTestSignal() + } catch (error) { + errorString = error.toString(); + } + } + + //should increment funcCount once + function testSignalConnection() { + testSignal.connect(testFunction) + testSignal(); + testSignal.disconnect(testFunction) + testSignal(); + } + + //should increment funcCount once + function testSignalHandlerConnection() { + onTestSignal.connect(testFunction) + testSignal(); + onTestSignal.disconnect(testFunction) + testSignal(); + } + + //should be defined + property bool definedResult: false + function testSignalDefined() { + if (testSignal !== undefined) + definedResult = true; + } + + //should be defined + property bool definedHandlerResult: false + function testSignalHandlerDefined() { + if (onTestSignal !== undefined) + definedHandlerResult = true; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml new file mode 100644 index 0000000000..4fc2dab943 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml @@ -0,0 +1,18 @@ +import Qt.test 1.0 + +MyQmlObject +{ + id: root + property int intProperty + property real realProperty + property color colorProperty + property variant variantProperty + property int enumProperty + property int qtEnumProperty + + signal mySignal(int a, real b, color c, variant d, int e, int f) + + onMySignal: { intProperty = a; realProperty = b; colorProperty = c; variantProperty = d; enumProperty = e; qtEnumProperty = f; } + + onBasicSignal: root.mySignal(10, 19.2, Qt.rgba(1, 1, 0, 1), Qt.rgba(1, 0, 1, 1), MyQmlObject.EnumValue3, Qt.LeftButton) +} diff --git a/tests/auto/qml/qqmlecmascript/data/signalTriggeredBindings.qml b/tests/auto/qml/qqmlecmascript/data/signalTriggeredBindings.qml new file mode 100644 index 0000000000..d98d7e9c81 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/signalTriggeredBindings.qml @@ -0,0 +1,20 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +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/qml/qqmlecmascript/data/signalWithJSValueInVariant.qml b/tests/auto/qml/qqmlecmascript/data/signalWithJSValueInVariant.qml new file mode 100644 index 0000000000..a6f1aa381a --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/signalWithJSValueInVariant.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 + +MyQmlObject { + property string expression + property string compare + property bool pass: false + onSignalWithVariant: + { + var expected = eval(expression); + pass = eval(compare)(arg, expected); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/signalWithQJSValue.qml b/tests/auto/qml/qqmlecmascript/data/signalWithQJSValue.qml new file mode 100644 index 0000000000..36f481d533 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/signalWithQJSValue.qml @@ -0,0 +1,14 @@ +import Qt.test 1.0 + +MyQmlObject { + property string expression + property string compare + property bool pass: false + + onSignalWithQJSValue: + { + qjsvalueMethod(arg); + var expected = eval(expression); + pass = eval(compare)(arg, expected); + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/signalWithUnknownTypes.qml b/tests/auto/qml/qqmlecmascript/data/signalWithUnknownTypes.qml new file mode 100644 index 0000000000..49293edfb3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/signalWithUnknownTypes.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject { + onSignalWithUnknownType: variantMethod(arg); +} diff --git a/tests/auto/qml/qqmlecmascript/data/strictlyEquals.qml b/tests/auto/qml/qqmlecmascript/data/strictlyEquals.qml new file mode 100644 index 0000000000..e709e3a8bd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/strictlyEquals.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +QtObject { + property bool test1: (a === true) + property bool test2: !(a === false) + property bool test3: (b === 11.2) + property bool test4: !(b === 9) + property bool test5: (c === 9) + property bool test6: !(c === 13) + property bool test7: (d === "Hello world") + property bool test8: !(d === "Hi") + + property bool a: true + property real b: 11.2 + property int c: 9 + property string d: "Hello world" +} diff --git a/tests/auto/qml/qqmlecmascript/data/stringArg.qml b/tests/auto/qml/qqmlecmascript/data/stringArg.qml new file mode 100644 index 0000000000..7019af9da5 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/stringArg.qml @@ -0,0 +1,49 @@ +import QtQuick 2.0 + +Item { + id: root + property bool returnValue: false + + property string first + property string second + property string third + property string fourth + property string fifth + property string sixth + property string seventh + property string eighth + property string ninth + + function success() { + var a = "Value is %1"; + for (var ii = 0; ii < 10; ++ii) { + first = a.arg("string"); + second = a.arg(1); + third = a.arg(true); + fourth = a.arg(3.345); + fifth = a.arg(undefined); + sixth = a.arg(null); + seventh = a.arg({"test":5}); + eighth = a.arg({"test":5, "again":6}); + } + + if (first != "Value is string") returnValue = false; + if (second != "Value is 1") returnValue = false; + if (third != "Value is true") returnValue = false; + if (fourth != "Value is 3.345") returnValue = false; + if (fifth != "Value is undefined") returnValue = false; + if (sixth != "Value is null") returnValue = false; + if (seventh != "Value is [Object object]") returnValue = false; + if (eighth != "Value is [Object object]") returnValue = false; + returnValue = true; + } + + function failure() { + returnValue = true; + var a = "Value is %1"; + for (var ii = 0; ii < 10; ++ii) { + ninth = a.arg(1,2,3,4); + } + returnValue = false; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/switchStatement.1.qml b/tests/auto/qml/qqmlecmascript/data/switchStatement.1.qml new file mode 100644 index 0000000000..3c7870839d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/switchStatement.1.qml @@ -0,0 +1,33 @@ +import Qt.test 1.0 + +MyQmlObject { + value: { + var value = 0 + switch (stringProperty) { + case "A": + value = value + 1 + value = value + 1 + /* should fall through */ + case "S": + value = value + 1 + value = value + 1 + value = value + 1 + break; + case "D": { // with curly braces + value = value + 1 + value = value + 1 + value = value + 1 + break; + } + case "F": { + value = value + 1 + value = value + 1 + value = value + 1 + } + /* should fall through */ + default: + value = value + 1 + } + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/switchStatement.2.qml b/tests/auto/qml/qqmlecmascript/data/switchStatement.2.qml new file mode 100644 index 0000000000..928d36be1f --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/switchStatement.2.qml @@ -0,0 +1,33 @@ +import Qt.test 1.0 + +MyQmlObject { + value: { + var value = 0 + switch (stringProperty) { + case "A": + value = value + 1 + value = value + 1 + /* should fall through */ + case "S": + value = value + 1 + value = value + 1 + value = value + 1 + break; + default: + value = value + 1 + case "D": { // with curly braces + value = value + 1 + value = value + 1 + value = value + 1 + break; + } + case "F": { + value = value + 1 + value = value + 1 + value = value + 1 + } + /* should fall through */ + } + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/switchStatement.3.qml b/tests/auto/qml/qqmlecmascript/data/switchStatement.3.qml new file mode 100644 index 0000000000..5b05d88767 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/switchStatement.3.qml @@ -0,0 +1,33 @@ +import Qt.test 1.0 + +MyQmlObject { + value: { + var value = 0 + switch (stringProperty) { + default: + value = value + 1 + case "A": + value = value + 1 + value = value + 1 + /* should fall through */ + case "S": + value = value + 1 + value = value + 1 + value = value + 1 + break; + case "D": { // with curly braces + value = value + 1 + value = value + 1 + value = value + 1 + break; + } + case "F": { + value = value + 1 + value = value + 1 + value = value + 1 + } + /* should fall through */ + } + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/switchStatement.4.qml b/tests/auto/qml/qqmlecmascript/data/switchStatement.4.qml new file mode 100644 index 0000000000..43ba199a04 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/switchStatement.4.qml @@ -0,0 +1,31 @@ +import Qt.test 1.0 + +MyQmlObject { + value: { + var value = 0 + switch (stringProperty) { + case "A": + value = value + 1 + value = value + 1 + /* should fall through */ + case "S": + value = value + 1 + value = value + 1 + value = value + 1 + break; + case "D": { // with curly braces + value = value + 1 + value = value + 1 + value = value + 1 + break; + } + case "F": { + value = value + 1 + value = value + 1 + value = value + 1 + } + /* should fall through */ + } + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/switchStatement.5.qml b/tests/auto/qml/qqmlecmascript/data/switchStatement.5.qml new file mode 100644 index 0000000000..e0fc62e392 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/switchStatement.5.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 + +MyQmlObject { + value: { + var value = 0 + switch (stringProperty) { + default: + value = value + 1 + } + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/switchStatement.6.qml b/tests/auto/qml/qqmlecmascript/data/switchStatement.6.qml new file mode 100644 index 0000000000..6fb71eb345 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/switchStatement.6.qml @@ -0,0 +1,13 @@ +import Qt.test 1.0 + +MyQmlObject { + function one(kind) { return 123 } + function two(kind) { return 321 } + + value: switch (stringProperty) { + case "A": case "S": one(stringProperty); break; + case "D": case "F": two(stringProperty); break; + default: 0 + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/threadScript.js b/tests/auto/qml/qqmlecmascript/data/threadScript.js new file mode 100644 index 0000000000..9f94de1bc1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/threadScript.js @@ -0,0 +1,4 @@ +WorkerScript.onMessage = function(msg) { + WorkerScript.sendMessage(msg); +} + diff --git a/tests/auto/qml/qqmlecmascript/data/transientErrors.2.qml b/tests/auto/qml/qqmlecmascript/data/transientErrors.2.qml new file mode 100644 index 0000000000..c44acf4fd1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/transientErrors.2.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +QtObject { + id: root + + property variant a: 10 + property int x: 10 + property int test: a.x + + Component.onCompleted: { + a = 11; + a = root; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/transientErrors.qml b/tests/auto/qml/qqmlecmascript/data/transientErrors.qml new file mode 100644 index 0000000000..451bb51996 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/transientErrors.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +QtObject { + property variant obj: nested + + property variant obj2 + obj2: NestedTypeTransientErrors { + id: nested + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/tryStatement.1.qml b/tests/auto/qml/qqmlecmascript/data/tryStatement.1.qml new file mode 100644 index 0000000000..71cc67a941 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/tryStatement.1.qml @@ -0,0 +1,13 @@ +import Qt.test 1.0 + +MyQmlObject { + property int defaultValue: 123 + + function go() { + undefinedObject.method() // this call will throw an exception + return 321 + } + + value: try { go() } catch(e) { defaultValue } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/tryStatement.2.qml b/tests/auto/qml/qqmlecmascript/data/tryStatement.2.qml new file mode 100644 index 0000000000..e7fca0bff7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/tryStatement.2.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 + +MyQmlObject { + property int defaultValue: 123 + + function go() { + return 321 + } + + value: try { go() } catch(e) { defaultValue } +} diff --git a/tests/auto/qml/qqmlecmascript/data/tryStatement.3.qml b/tests/auto/qml/qqmlecmascript/data/tryStatement.3.qml new file mode 100644 index 0000000000..04b39f73d5 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/tryStatement.3.qml @@ -0,0 +1,13 @@ +import Qt.test 1.0 + +MyQmlObject { + property int defaultValue: 123 + + function go() { + undefinedObject.method() // this call will throw an exception + return 321 + } + + value: try { var p = go() } catch(e) { var p = defaultValue } finally { p == 123 } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/tryStatement.4.qml b/tests/auto/qml/qqmlecmascript/data/tryStatement.4.qml new file mode 100644 index 0000000000..231aaf0683 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/tryStatement.4.qml @@ -0,0 +1,12 @@ +import Qt.test 1.0 + +MyQmlObject { + property int defaultValue: 123 + + function go() { + return 321 + } + + value: try { var p = go() } catch(e) { var p = defaultValue } finally { p == 321 } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/typeOf.js b/tests/auto/qml/qqmlecmascript/data/typeOf.js new file mode 100644 index 0000000000..16a34234c0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/typeOf.js @@ -0,0 +1,25 @@ +var test1 = typeof a + +var b = {} +var test2 = typeof b + +var c = 5 +var test3 = typeof c + +var d = "hello world" +var test4 = typeof d + +var e = function() {} +var test5 = typeof e + +var f = null +var test6 = typeof f + +var g = undefined +var test7 = typeof g + +var h = true +var test8 = typeof h + +var i = [] +var test9 = typeof i diff --git a/tests/auto/qml/qqmlecmascript/data/typeOf.qml b/tests/auto/qml/qqmlecmascript/data/typeOf.qml new file mode 100644 index 0000000000..28f7debed5 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/typeOf.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 +import "typeOf.js" as TypeOf + +QtObject { + property string test1 + property string test2 + property string test3 + property string test4 + property string test5 + property string test6 + property string test7 + property string test8 + property string test9 + + Component.onCompleted: { + test1 = TypeOf.test1 + test2 = TypeOf.test2 + test3 = TypeOf.test3 + test4 = TypeOf.test4 + test5 = TypeOf.test5 + test6 = TypeOf.test6 + test7 = TypeOf.test7 + test8 = TypeOf.test8 + test9 = TypeOf.test9 + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/unaryExpression.qml b/tests/auto/qml/qqmlecmascript/data/unaryExpression.qml new file mode 100644 index 0000000000..0d40bec710 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/unaryExpression.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + + Component.onCompleted: +++bar + + property int bar: 0 +} diff --git a/tests/auto/qml/qqmlecmascript/data/undefinedResetsProperty.2.qml b/tests/auto/qml/qqmlecmascript/data/undefinedResetsProperty.2.qml new file mode 100644 index 0000000000..e73d38e2ce --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/undefinedResetsProperty.2.qml @@ -0,0 +1,10 @@ +import Qt.test 1.0 + +MyQmlObject { + resettableProperty: 19 + + function doReset() { + resettableProperty = undefined; + } +} + diff --git a/tests/auto/qml/qqmlecmascript/data/undefinedResetsProperty.qml b/tests/auto/qml/qqmlecmascript/data/undefinedResetsProperty.qml new file mode 100644 index 0000000000..eceff60aa1 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/undefinedResetsProperty.qml @@ -0,0 +1,7 @@ +import Qt.test 1.0 + +MyQmlObject { + property bool setUndefined: false + + resettableProperty: setUndefined?undefined:92 +} diff --git a/tests/auto/qml/qqmlecmascript/data/urlListProperty.qml b/tests/auto/qml/qqmlecmascript/data/urlListProperty.qml new file mode 100644 index 0000000000..eeb0815f09 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/urlListProperty.qml @@ -0,0 +1,41 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + // single url assignment to url list property + MySequenceConversionObject { + id: msco1 + objectName: "msco1" + } + + // single url binding to url list property + MySequenceConversionObject { + id: msco2 + objectName: "msco2" + urlListProperty: "http://qt-project.org/?get%3cDATA%3e"; + } + + // multiple url assignment to url list property + MySequenceConversionObject { + id: msco3 + objectName: "msco3" + } + + // multiple url binding to url list property + MySequenceConversionObject { + id: msco4 + objectName: "msco4" + urlListProperty: [ + "http://qt-project.org/?get%3cDATA%3e", + "http://qt-project.org/?get%3cDATA%3e" + ]; + } + + Component.onCompleted: { + msco1.urlListProperty = "http://qt-project.org/?get%3cDATA%3e"; + msco3.urlListProperty = [ + "http://qt-project.org/?get%3cDATA%3e", + "http://qt-project.org/?get%3cDATA%3e" + ]; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/urlProperty.1.qml b/tests/auto/qml/qqmlecmascript/data/urlProperty.1.qml new file mode 100644 index 0000000000..451cb03206 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/urlProperty.1.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + property bool result + urlProperty: stringProperty + "/index.html" + intProperty: if (urlProperty) 123; else 321 + value: urlProperty == stringProperty + "/index.html" + result: urlProperty == urlProperty +} diff --git a/tests/auto/qml/qqmlecmascript/data/urlProperty.2.qml b/tests/auto/qml/qqmlecmascript/data/urlProperty.2.qml new file mode 100644 index 0000000000..0e8bdaec96 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/urlProperty.2.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +MyQmlObject { + property bool result + stringProperty: "http://example.org" + urlProperty: stringProperty + "/?get%3cDATA%3e" + value: urlProperty == stringProperty + "/?get%3cDATA%3e" + result: urlProperty == urlProperty +} diff --git a/tests/auto/qml/qqmlecmascript/data/v8bindingException.qml b/tests/auto/qml/qqmlecmascript/data/v8bindingException.qml new file mode 100644 index 0000000000..ff203e23e3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/v8bindingException.qml @@ -0,0 +1,21 @@ +import QtQuick 2.0 + +// This test uses a multi-line string which has \r-terminated +// string fragments. The expression rewriter deliberately doesn't +// handle \r-terminated string fragments (see QTBUG-24064) and thus +// this test ensures that we don't crash when we encounter a +// non-compilable binding such as this one. + +Item { + id: root + + Component { + id: comp + Text { + property var value: "," + text: 'multi
line ' + value + 'str
ings' + } + } + + Component.onCompleted: comp.createObject(root, { "value": undefined }) +} diff --git a/tests/auto/qml/qqmlecmascript/data/v8functionException.qml b/tests/auto/qml/qqmlecmascript/data/v8functionException.qml new file mode 100644 index 0000000000..51df1c65d8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/v8functionException.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +// This test uses a multi-line string which has \r-terminated +// string fragments. The expression rewriter deliberately doesn't +// handle \r-terminated string fragments (see QTBUG-24064) and thus +// this test ensures that we don't crash when the client attempts +// to invoke a non-compiled dynamic slot. + +Item { + id: root + + function dynamicSlot() { + var someString = "Hello,
this is a
multiline string"; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/valueTypeFunctions.qml b/tests/auto/qml/qqmlecmascript/data/valueTypeFunctions.qml new file mode 100644 index 0000000000..33b4a68c40 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/valueTypeFunctions.qml @@ -0,0 +1,6 @@ +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/qml/qqmlecmascript/data/variantsAssignedUndefined.qml b/tests/auto/qml/qqmlecmascript/data/variantsAssignedUndefined.qml new file mode 100644 index 0000000000..6aa8480365 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/variantsAssignedUndefined.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +QtObject { + property bool runTest: false + onRunTestChanged: test1 = undefined + + property variant test1: 10 + property variant test2: (runTest == false)?11:undefined +} diff --git a/tests/auto/qml/qqmlecmascript/data/withStatement.1.qml b/tests/auto/qml/qqmlecmascript/data/withStatement.1.qml new file mode 100644 index 0000000000..28f0c08451 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/withStatement.1.qml @@ -0,0 +1,14 @@ +import Qt.test 1.0 + +MyQmlObject { + property var other: MyQmlObject { + intProperty: 123 + + function go() { + return intProperty; + } + } + + value: with(other) go() +} + diff --git a/tests/auto/qml/qqmlecmascript/data/writeAttachedProperty.qml b/tests/auto/qml/qqmlecmascript/data/writeAttachedProperty.qml new file mode 100644 index 0000000000..3854b069a0 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/writeAttachedProperty.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +QtObject { + function writeValue2() { MyQmlObject.value2 = 9 } +} diff --git a/tests/auto/qml/qqmlecmascript/data/writeRemovesBinding.qml b/tests/auto/qml/qqmlecmascript/data/writeRemovesBinding.qml new file mode 100644 index 0000000000..a1ba5df071 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/writeRemovesBinding.qml @@ -0,0 +1,46 @@ +import QtQuick 2.0 + +QtObject { + id: root + + property bool test: false + + property real data: 9 + property real binding: data + + property alias aliasProperty: root.aliasBinding + property real aliasBinding: data + + Component.onCompleted: { + // Non-aliased properties + if (binding != 9) return; + + data = 11; + if (binding != 11) return; + + binding = 6; + if (binding != 6) return; + + data = 3; + if (binding != 6) return; + + + // Writing through an aliased property + if (aliasProperty != 3) return; + if (aliasBinding != 3) return; + + data = 4; + if (aliasProperty != 4) return; + if (aliasBinding != 4) return; + + aliasProperty = 19; + if (aliasProperty != 19) return; + if (aliasBinding != 19) return; + + data = 5; + if (aliasProperty != 19) return; + if (aliasBinding != 19) return; + + test = true; + } +} |