tests: Port away from a few Qt specific waitForEvent
Removes a bunch of asQWidget() from the tests
This commit is contained in:
@@ -15,10 +15,39 @@
|
||||
#include <QWindow>
|
||||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include <QtTest/QTest>
|
||||
|
||||
using namespace KDDockWidgets;
|
||||
|
||||
namespace KDDockWidgets::Tests {
|
||||
|
||||
/// @brief Helper class to help us with tests
|
||||
class EventFilter : public QObject
|
||||
{
|
||||
public:
|
||||
EventFilter(QEvent::Type type)
|
||||
: m_type(type)
|
||||
{
|
||||
}
|
||||
~EventFilter() override;
|
||||
bool eventFilter(QObject *, QEvent *e) override
|
||||
{
|
||||
if (e->type() == m_type)
|
||||
m_got = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const QEvent::Type m_type;
|
||||
bool m_got = false;
|
||||
};
|
||||
|
||||
EventFilter::~EventFilter() = default;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Platform_qt::Platform_qt()
|
||||
{
|
||||
@@ -62,4 +91,34 @@ bool Platform_qt::tests_waitForWindowActive(Window::Ptr window, int timeout) con
|
||||
return QTest::qWaitForWindowActive(windowqt->qtWindow(), timeout);
|
||||
}
|
||||
|
||||
bool Platform_qt::tests_waitForEvent(QObject *w, QEvent::Type type, int timeout) const
|
||||
{
|
||||
Tests::EventFilter filter(type);
|
||||
w->installEventFilter(&filter);
|
||||
QElapsedTimer time;
|
||||
time.start();
|
||||
|
||||
while (!filter.m_got && time.elapsed() < timeout) {
|
||||
qApp->processEvents();
|
||||
QTest::qWait(50);
|
||||
}
|
||||
|
||||
return filter.m_got;
|
||||
}
|
||||
|
||||
bool Platform_qt::tests_waitForEvent(View *view, QEvent::Type type, int timeout) const
|
||||
{
|
||||
return tests_waitForEvent(view->asQObject(), type, timeout);
|
||||
}
|
||||
|
||||
bool Platform_qt::tests_waitForResize(View *view, int timeout) const
|
||||
{
|
||||
return tests_waitForEvent(view->asQObject(), QEvent::Resize, timeout);
|
||||
}
|
||||
|
||||
bool Platform_qt::tests_waitForResize(Controller *c, int timeout) const
|
||||
{
|
||||
return tests_waitForResize(c->view(), timeout);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user