diff --git a/src/Platform.cpp b/src/Platform.cpp index c23d3d82..06f26933 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -130,4 +130,4 @@ std::vector Platform::frontendTypes() return types; } -#endif \ No newline at end of file +#endif diff --git a/src/qtcommon/Platform_qt.cpp b/src/qtcommon/Platform_qt.cpp index a66b525d..44c0bbdc 100644 --- a/src/qtcommon/Platform_qt.cpp +++ b/src/qtcommon/Platform_qt.cpp @@ -244,18 +244,27 @@ void Platform_qt::tests_sendEvent(Window::Ptr window, QEvent *ev) const qApp->sendEvent(static_cast(window.get())->qtWindow(), ev); } +void Platform_qt::installMessageHandler() +{ + Tests::s_original = qInstallMessageHandler(Tests::fatalWarningsMessageHandler); +} + +void Platform_qt::uninstallMessageHandler() +{ + if (!Tests::s_original) + qWarning() << Q_FUNC_INFO << "No message handler was installed or the fatalWarningsMessageHandler was already uninstalled!"; + qInstallMessageHandler(Tests::s_original); + Tests::s_original = nullptr; +} + void Platform_qt::tests_initPlatform_impl() { qApp->setOrganizationName(QStringLiteral("KDAB")); qApp->setApplicationName(QStringLiteral("dockwidgets-unit-tests")); - - Tests::s_original = qInstallMessageHandler(Tests::fatalWarningsMessageHandler); } void Platform_qt::tests_deinitPlatform_impl() { - qInstallMessageHandler(Tests::s_original); - Tests::s_original = nullptr; delete qApp; } diff --git a/src/qtcommon/Platform_qt.h b/src/qtcommon/Platform_qt.h index ec2e4be2..1a3698e3 100644 --- a/src/qtcommon/Platform_qt.h +++ b/src/qtcommon/Platform_qt.h @@ -48,6 +48,9 @@ public: void tests_initPlatform_impl() override; void tests_deinitPlatform_impl() override; void tests_wait(int ms) override; + + static void installMessageHandler(); + static void uninstallMessageHandler(); #endif protected: int screenNumberForQWindow(QWindow *) const; diff --git a/tests/tst_docks.cpp b/tests/tst_docks.cpp index 5923fa71..288e212a 100644 --- a/tests/tst_docks.cpp +++ b/tests/tst_docks.cpp @@ -20,6 +20,7 @@ #include "Platform.h" #include "multisplitter/Item_p.h" #include "ViewFactory.h" +#include "qtcommon/Platform_qt.h" #include "controllers/MDILayout.h" #include "controllers/DropArea.h" @@ -100,6 +101,16 @@ static std::unique_ptr createSimpleNestedMainWindow(Controllers::Doc return window; } +void TestDocks::initTestCase() +{ + KDDockWidgets::Platform_qt::installMessageHandler(); +} + +void TestDocks::cleanupTestCase() +{ + KDDockWidgets::Platform_qt::uninstallMessageHandler(); +} + void TestDocks::tst_simple1() { // Simply create a MainWindow diff --git a/tests/tst_docks.h b/tests/tst_docks.h index cda38516..a9ce3954 100644 --- a/tests/tst_docks.h +++ b/tests/tst_docks.h @@ -26,9 +26,8 @@ class TestDocks : public QObject { Q_OBJECT public Q_SLOTS: - void initTestCase() - { - } + void initTestCase(); + void cleanupTestCase(); private Q_SLOTS: void tst_simple1();