aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qmltest
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-12-21 10:21:41 +0100
committerMitch Curtis <mitch.curtis@qt.io>2016-12-21 17:34:33 +0000
commit42c52e6f2d9002e8191ada765d8a2509c7fae71b (patch)
treebbd40a618190eb13a726098d18034602fda8875f /tests/auto/qmltest
parent312967965fed542c77ca6f2b03400296da342bd5 (diff)
TestCase: make parent argument to createTemporaryObject optional
This matches the behavior seen from Component's createObject() function. Change-Id: I83fe73a588d04c5efd30c49059bb19e7584bef48 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/qmltest')
-rw-r--r--tests/auto/qmltest/selftests/tst_createTemporaryObject.qml36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml
index 6e76317e5f..5f1e802df2 100644
--- a/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml
+++ b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml
@@ -38,11 +38,15 @@ TestCase {
when: windowShown
property var createdObjectNames: []
+ property var createdParentlessObjects: []
function verifyNoChildren() {
for (var i = 0; i < createdObjectNames.length; ++i) {
verify(!findChild(testCase, createdObjectNames[i]));
}
+
+ compare(createdParentlessObjects.length, 0,
+ "The following parentless temporary objects were not destroyed: " + createdParentlessObjects)
}
function init() {
@@ -140,4 +144,36 @@ TestCase {
verify(!findChild(testCase, manuallyDestroyedObjectName));
}
+
+ function test_fromComponentParent_data() {
+ return [
+ { tag: "omit", expectedParent: null },
+ { tag: "undefined", parent: undefined, expectedParent: null },
+ { tag: "null", parent: null, expectedParent: null },
+ { tag: "1", parent: 1, expectedParent: null },
+ { tag: "testCase", parent: testCase, expectedParent: testCase }
+ ];
+ }
+
+ // Tests that an invalid or missing parent argument results in a parentless object.
+ // This is the same behavior as displayed by component.createObject().
+ function test_fromComponentParent(data) {
+ var object = data.hasOwnProperty("parent")
+ ? createTemporaryObject(itemComponent, data.parent)
+ : createTemporaryObject(itemComponent);
+ verify(object);
+ compare(object.parent, data.expectedParent);
+
+ object.objectName = data.tag + "FromComponentOmitParent";
+ if (object.parent) {
+ compare(findChild(testCase, object.objectName), object);
+ createdObjectNames.push(object.objectName);
+ } else {
+ object.Component.destruction.connect(function() {
+ var indexOfObject = createdParentlessObjects.indexOf(object);
+ createdParentlessObjects.splice(indexOfObject, 1);
+ });
+ createdParentlessObjects.push(object);
+ }
+ }
}