From 7bf8d4d3772959f06d4dd0168af7774adde29d76 Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Thu, 20 Sep 2018 10:51:18 +0200 Subject: Add test cleanup function for C++ parts This allows to do cleanup in C++ before other parts being destructed. It QtOpcUa we need to destruct a subprocess. Until now it was done in the destructor of the setup class. When the destructor is called the eventloop already died but the process is still sending output when being terminated. In the windows event handling a nullptr is being dereferenced in this case, see QTBUG-70641. When terminating this process somewhat earlier, when the eventloop is still available, the event dispatcher is able to handle those events without crashing. Another reason to have this function is because there is applicationAvailable() being called to initialize C++ code and there should be an equivalent function for cleaning up. [ChangeLog][QtQml][QtTest] Add cleanupTestCase() to be called before starting destruction Change-Id: I24f7a51ec5276a449892609f5b2cfe7957c27668 Reviewed-by: Mitch Curtis --- src/qmltest/doc/src/qtquicktest-index.qdoc | 3 +++ src/qmltest/quicktest.cpp | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'src/qmltest') diff --git a/src/qmltest/doc/src/qtquicktest-index.qdoc b/src/qmltest/doc/src/qtquicktest-index.qdoc index f641d8248f..700bddc8d5 100644 --- a/src/qmltest/doc/src/qtquicktest-index.qdoc +++ b/src/qmltest/doc/src/qtquicktest-index.qdoc @@ -157,6 +157,9 @@ \l {QQmlEngine::addPluginPath}{plugin paths}, and \l {QQmlFileSelector::setExtraSelectors}{extra file selectors} will have been set on the engine by this point. + \li void cleanupTestCase() + \li Called right after the test execution has finished. + Use this function to clean up before everything will start to be destructed. \endtable Each function will be called once for each \c tst_*.qml file, so any diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp index f2d5848d54..f666bc2284 100644 --- a/src/qmltest/quicktest.cpp +++ b/src/qmltest/quicktest.cpp @@ -588,6 +588,11 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch } } + if (setup) { + // Don't check the return value; it's OK if it doesn't exist. + QMetaObject::invokeMethod(setup, "cleanupTestCase"); + } + // Flush the current logging stream. QuickTestResult::setProgramName(nullptr); delete app; -- cgit v1.2.3