diff --git a/src/Platform.h b/src/Platform.h index a05f42eb..1c7f113d 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -72,6 +72,9 @@ public: virtual bool tests_waitForEvent(View *, QEvent::Type type, int timeout = 5000) const = 0; virtual bool tests_waitForEvent(std::shared_ptr, QEvent::Type type, int timeout = 5000) const = 0; + /// @brief Waits for the specified view to be deleted + virtual bool tests_waitForDeleted(View *, int timeout = 2000) const = 0; + virtual void tests_sendEvent(View *, QEvent *) const = 0; virtual void tests_sendEvent(std::shared_ptr window, QEvent *ev) const = 0; diff --git a/src/qtcommon/Platform_qt.cpp b/src/qtcommon/Platform_qt.cpp index 71f0e0d9..84565699 100644 --- a/src/qtcommon/Platform_qt.cpp +++ b/src/qtcommon/Platform_qt.cpp @@ -127,6 +127,25 @@ bool Platform_qt::tests_waitForEvent(std::shared_ptr window, QEvent::Typ return tests_waitForEvent(windowqt->qtWindow(), type, timeout); } +bool Platform_qt::tests_waitForDeleted(View *view, int timeout) const +{ + QObject *o = view ? view->asQObject() : nullptr; + if (!o) + return true; + + QPointer ptr = o; + QElapsedTimer time; + time.start(); + + while (ptr && time.elapsed() < timeout) { + qApp->processEvents(); + QTest::qWait(50); + } + + const bool wasDeleted = !ptr; + return wasDeleted; +} + void Platform_qt::tests_sendEvent(View *view, QEvent *ev) const { qApp->sendEvent(view->asQObject(), ev); diff --git a/src/qtcommon/Platform_qt.h b/src/qtcommon/Platform_qt.h index 759943fa..ed1faa16 100644 --- a/src/qtcommon/Platform_qt.h +++ b/src/qtcommon/Platform_qt.h @@ -37,6 +37,7 @@ public: bool tests_waitForEvent(std::shared_ptr, QEvent::Type type, int timeout = 5000) const override; bool tests_waitForResize(View *, int timeout = 2000) const override; bool tests_waitForResize(Controller *, int timeout = 2000) const override; + bool tests_waitForDeleted(View *, int timeout = 2000) const override; void tests_sendEvent(std::shared_ptr, QEvent *) const override; void tests_sendEvent(View *, QEvent *) const override; #endif diff --git a/tests/tst_docks.cpp b/tests/tst_docks.cpp index d79488ea..5c3b4d4c 100644 --- a/tests/tst_docks.cpp +++ b/tests/tst_docks.cpp @@ -5763,12 +5763,11 @@ void TestDocks::tst_maximumSizePolicy() auto dock1 = createDockWidget("dock1", widget); dock1->show(); dock1->window()->resize(QSize(500, 500)); - auto oldFw = Tests::make_qpointer(dock1->window()->asQWidget()); + auto window1 = dock1->window(); dock1->close(); dock1->show(); auto oldFw2 = dock1->window(); - const int tolerance = 50; QVERIFY(dock1->window()->height() <= maxHeight + tolerance); // +tolerance as the floating window is a bit bigger, due to margins etc. QVERIFY(dock1->height() <= maxHeight); @@ -5790,8 +5789,6 @@ void TestDocks::tst_maximumSizePolicy() // Now drop it, and check too m1->addDockWidget(dock1, Location_OnBottom); QVERIFY(dock1->height() <= maxHeight); - - delete oldFw.data(); } void TestDocks::tst_minSizeChanges() @@ -6300,7 +6297,7 @@ void TestDocks::tst_raise() auto dock1 = createDockWidget("1"); auto dock2 = createDockWidget("2"); - auto fw2 = Tests::make_qpointer(dock2->window()->asQWidget()); + dock1->addDockWidgetAsTab(dock2); dock1->setAsCurrentTab(); QVERIFY(dock1->isCurrentTab()); @@ -6778,7 +6775,7 @@ void TestDocks::tst_addDockWidgetAsTabToDockWidget() dock1->dptr()->morphIntoFloatingWindow(); auto dock2 = createDockWidget("dock2", new QPushButton("two")); dock2->dptr()->morphIntoFloatingWindow(); - auto originalWindow2 = Tests::make_qpointer(dock2->window()->asQWidget()); + auto originalWindow2 = dock2->window(); dock1->addDockWidgetAsTab(dock2); @@ -6787,8 +6784,8 @@ void TestDocks::tst_addDockWidgetAsTabToDockWidget() QCOMPARE(window1->windowHandle(), window2->windowHandle()); QCOMPARE(dock1->dptr()->frame(), dock2->dptr()->frame()); QCOMPARE(dock1->dptr()->frame()->dockWidgetCount(), 2); - Testing::waitForDeleted(originalWindow2); - QVERIFY(!originalWindow2); + Platform::instance()->tests_waitForDeleted(originalWindow2.get()); + dock1->deleteLater(); dock2->deleteLater(); Testing::waitForDeleted(dock2); diff --git a/tests/utils.h b/tests/utils.h index a170384b..bcd807b0 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -58,13 +58,6 @@ namespace KDDockWidgets { namespace Tests { -template -inline QPointer make_qpointer(T *t) -{ - // To support both QWidget and QtQuick we need QPointer, so use a function instead. - return QPointer(t); -} - enum ButtonAction { ButtonAction_None, ButtonAction_Press = 1,