From fd0c4fb24a58b4acaba613dc83634f28dfdbfeda Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 15 Dec 2016 15:38:29 +0100 Subject: 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 --- .../selftests/tst_createTemporaryObject.qml | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/auto') 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)); } } -- cgit v1.2.3