diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-12-15 15:38:29 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2016-12-21 14:09:32 +0000 |
commit | fd0c4fb24a58b4acaba613dc83634f28dfdbfeda (patch) | |
tree | 7e61fac4a79b5bee223bb6d9efc8ca3d5fc07840 /tests/auto | |
parent | c4eefa4a8d6d3e95062deb78229940460a7ef605 (diff) |
TestCase: don't try to access destroyed temporary objects
Objects created with createTemporaryObject() and
createTemporaryQmlObject() can be destroyed manually before the test
ends. Before this patch, there would be a type error when trying to
check if the object still exists in qtest_destroyTemporaryObjects().
The error seems to stem from the fact that objects that are stored in
an array and later destroy()'d are not nullified, but rather left in
a corrupt state. See the linked bug for more information about this.
We work around this issue by checking for the existence of the
destroy() function on the object before attempting to call it.
Task-number: QTBUG-57749
Change-Id: I0f6ddd47d86af6fb87392c2992f9f6143af6aab8
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qmltest/selftests/tst_createTemporaryObject.qml | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml index c4912c7388..6e76317e5f 100644 --- a/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml +++ b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml @@ -70,6 +70,21 @@ TestCase { compare(findChild(testCase, object.objectName), object); createdObjectNames.push(object.objectName); + + // Create an object and destroy it early. It should be + // removed from TestCase's list of temporary objects + // as soon as it's destroyed. + var manuallyDestroyedObject = createTemporaryQmlObject(data.qml, testCase); + verify(manuallyDestroyedObject); + + var manuallyDestroyedObjectName = data.tag + "FromQmlShortLived"; + manuallyDestroyedObject.objectName = manuallyDestroyedObjectName; + compare(findChild(testCase, manuallyDestroyedObjectName), manuallyDestroyedObject); + + manuallyDestroyedObject.destroy(); + wait(0); + + verify(!findChild(testCase, manuallyDestroyedObjectName)); } Component { @@ -109,5 +124,20 @@ TestCase { object.contentItem.objectName = "WindowContentItemFromComponent"; createdObjectNames.push(object.objectName); + + // Create an object and destroy it early. It should be + // removed from TestCase's list of temporary objects + // as soon as it's destroyed. + var manuallyDestroyedObject = createTemporaryObject(data.component, testCase); + verify(manuallyDestroyedObject); + + var manuallyDestroyedObjectName = data.tag + "FromComponentShortLived"; + manuallyDestroyedObject.objectName = manuallyDestroyedObjectName; + compare(findChild(testCase, manuallyDestroyedObjectName), manuallyDestroyedObject); + + manuallyDestroyedObject.destroy(); + wait(0); + + verify(!findChild(testCase, manuallyDestroyedObjectName)); } } |