aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--src/imports/testlib/TestCase.qml8
-rw-r--r--tests/auto/qmltest/selftests/tst_createTemporaryObject.qml36
2 files changed, 37 insertions, 7 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 1ead2f21b7..18c70e1169 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -567,7 +567,7 @@ Item {
\qmlmethod object TestCase::createTemporaryObject(Component component, object parent, object properties)
This function dynamically creates a QML object from the given
- \a component with the specified \a parent and \a properties.
+ \a component with the specified optional \a parent and \a properties.
The returned object will be destroyed (if it was not already) after
\l cleanup() has finished executing, meaning that objects created with
this function are guaranteed to be destroyed after each test,
@@ -589,12 +589,6 @@ Item {
throw new Error("QtQuickTest::fail");
}
- if (!parent && parent !== null) {
- qtest_results.fail("Second argument must be a parent object or null; actual type is " + typeof parent,
- util.callerFile(), util.callerLine());
- throw new Error("QtQuickTest::fail");
- }
-
if (properties && typeof properties !== "object") {
qtest_results.fail("Third argument must be an object; actual type is " + typeof properties,
util.callerFile(), util.callerLine());
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);
+ }
+ }
}