Testlib: Fix qml objects not deleted in TestCase
authorCaroline Chao <caroline.chao@digia.com>
Wed, 10 Apr 2013 09:32:10 +0000 (11:32 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 11 Apr 2013 14:09:10 +0000 (16:09 +0200)
After destroy() been called in the test function.

wait(0) is used to call processEvents().

Task-number: QTBUG-30523

Change-Id: I208f213e2de6b530dd0965b301d046aee0182d9b
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
src/imports/testlib/TestCase.qml
tests/auto/qmltest/selftests/tst_destroy.qml [new file with mode: 0644]

index fbfad28..5484d5a 100644 (file)
@@ -682,6 +682,9 @@ Item {
                 qtest_runFunction(prop, null, isBenchmark)
             }
             qtest_results.finishTestFunction()
+            // wait(0) will call processEvents() so objects marked for deletion
+            // in the test function will be deleted.
+            wait(0)
             qtest_results.skipped = false
         }
 
diff --git a/tests/auto/qmltest/selftests/tst_destroy.qml b/tests/auto/qmltest/selftests/tst_destroy.qml
new file mode 100644 (file)
index 0000000..b2a473d
--- /dev/null
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.1
+import QtTest 1.0
+
+TestCase {
+    id: testCase
+    width: 100
+    height: 100
+    name: "SelfTests_Destroy"
+
+    function test_a_QTBUG_30523() {
+        compare(testCase.children.length, 0)
+        var tmp = Qt.createQmlObject('import QtQuick 2.1; Rectangle {width: 20; height: 20;}', testCase, '')
+        compare(testCase.children.length, 1)
+        tmp.destroy()
+    }
+
+    function test_b_QTBUG_30523() {
+        // The object created in test above should be deleted
+        compare(testCase.children.length, 0)
+    }
+}