Make it easier for tests to init the platform
Only a single static method is needed now, instead of 2.
This commit is contained in:
@@ -42,9 +42,20 @@ bool Platform::hasActivePopup() const
|
||||
|
||||
#ifdef DOCKS_DEVELOPER_MODE
|
||||
|
||||
void Platform::tests_cleanupTests()
|
||||
/*static*/
|
||||
void Platform::tests_initPlatform(KDDockWidgets::FrontendType type)
|
||||
{
|
||||
delete this;
|
||||
KDDockWidgets::initFrontend(type);
|
||||
Platform::instance()->tests_initPlatform_impl();
|
||||
}
|
||||
|
||||
/*static */
|
||||
void Platform::tests_deinitPlatform()
|
||||
{
|
||||
auto plat = Platform::instance();
|
||||
|
||||
plat->tests_deinitPlatform_impl();
|
||||
delete plat;
|
||||
}
|
||||
|
||||
/**static*/
|
||||
|
||||
@@ -98,15 +98,26 @@ public:
|
||||
|
||||
virtual void tests_sendEvent(std::shared_ptr<Window> window, QEvent *ev) const = 0;
|
||||
|
||||
/// @brief Creates the platform. Called by the tests at startup.
|
||||
/// For any custom behaviour in your derived Platform override tests_initPlatform_impl()
|
||||
static void tests_initPlatform(KDDockWidgets::FrontendType);
|
||||
|
||||
/// @brief Deletes the platform. Called at end of tests.
|
||||
/// For any custom behaviour in your derived Platform override tests_deinitPlatform_impl()
|
||||
static void tests_deinitPlatform();
|
||||
|
||||
protected:
|
||||
/// @brief Implement any needed initializations before tests starting to run, if any
|
||||
/// Override in derived classes for custom behavior.
|
||||
virtual void tests_initTests()
|
||||
virtual void tests_initPlatform_impl()
|
||||
{
|
||||
}
|
||||
|
||||
/// @brief Implement any needed cleanup after the tests runs, if any
|
||||
/// Override in derived classes for custom behavior.
|
||||
virtual void tests_cleanupTests();
|
||||
virtual void tests_deinitPlatform_impl()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -175,15 +175,14 @@ void Platform_qt::tests_sendEvent(Window::Ptr window, QEvent *ev) const
|
||||
qApp->sendEvent(static_cast<Window_qt *>(window.get())->qtWindow(), ev);
|
||||
}
|
||||
|
||||
void Platform_qt::tests_initTests()
|
||||
void Platform_qt::tests_initPlatform_impl()
|
||||
{
|
||||
qApp->setOrganizationName(QStringLiteral("KDAB"));
|
||||
qApp->setApplicationName(QStringLiteral("dockwidgets-unit-tests"));
|
||||
}
|
||||
|
||||
void Platform_qt::tests_cleanupTests()
|
||||
void Platform_qt::tests_deinitPlatform_impl()
|
||||
{
|
||||
Platform::tests_cleanupTests();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -42,8 +42,8 @@ public:
|
||||
bool tests_waitForResize(Controller *, int timeout = 2000) const override;
|
||||
bool tests_waitForDeleted(View *, int timeout = 2000) const override;
|
||||
void tests_sendEvent(std::shared_ptr<Window>, QEvent *) const override;
|
||||
void tests_initTests() override;
|
||||
void tests_cleanupTests() override;
|
||||
void tests_initPlatform_impl() override;
|
||||
void tests_deinitPlatform_impl() override;
|
||||
#endif
|
||||
protected:
|
||||
int screenNumberForQWindow(QWindow *) const;
|
||||
|
||||
@@ -101,19 +101,19 @@ QSize Platform_qtquick::screenSizeFor(View *view) const
|
||||
|
||||
#ifdef DOCKS_DEVELOPER_MODE
|
||||
|
||||
void Platform_qtquick::tests_initTests()
|
||||
void Platform_qtquick::tests_initPlatform_impl()
|
||||
{
|
||||
Platform_qt::tests_initTests();
|
||||
Platform_qt::tests_initPlatform_impl();
|
||||
|
||||
QQuickStyle::setStyle("Material"); // so we don't load KDE plugins
|
||||
KDDockWidgets::Config::self().setQmlEngine(new QQmlEngine(this));
|
||||
}
|
||||
|
||||
void Platform_qtquick::tests_cleanupTests()
|
||||
void Platform_qtquick::tests_deinitPlatform_impl()
|
||||
{
|
||||
delete KDDockWidgets::Config::self().qmlEngine();
|
||||
|
||||
Platform_qt::tests_cleanupTests();
|
||||
Platform_qt::tests_deinitPlatform_impl();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,8 +33,8 @@ public:
|
||||
QSize screenSizeFor(View *) const override;
|
||||
|
||||
#ifdef DOCKS_DEVELOPER_MODE
|
||||
void tests_initTests() override;
|
||||
void tests_cleanupTests() override;
|
||||
void tests_initPlatform_impl() override;
|
||||
void tests_deinitPlatform_impl() override;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -108,16 +108,16 @@ QSize Platform_qtwidgets::screenSizeFor(View *view) const
|
||||
|
||||
#ifdef DOCKS_DEVELOPER_MODE
|
||||
|
||||
void Platform_qtwidgets::tests_initTests()
|
||||
void Platform_qtwidgets::tests_initPlatform_impl()
|
||||
{
|
||||
qputenv("KDDOCKWIDGETS_SHOW_DEBUG_WINDOW", "");
|
||||
Platform_qt::tests_initTests();
|
||||
Platform_qt::tests_initPlatform_impl();
|
||||
qApp->setStyle(QStyleFactory::create(QStringLiteral("fusion")));
|
||||
}
|
||||
|
||||
void Platform_qtwidgets::tests_cleanupTests()
|
||||
void Platform_qtwidgets::tests_deinitPlatform_impl()
|
||||
{
|
||||
Platform_qt::tests_cleanupTests();
|
||||
Platform_qt::tests_deinitPlatform_impl();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,8 +35,8 @@ public:
|
||||
QSize screenSizeFor(View *) const override;
|
||||
|
||||
#ifdef DOCKS_DEVELOPER_MODE
|
||||
void tests_initTests() override;
|
||||
void tests_cleanupTests() override;
|
||||
void tests_initPlatform_impl() override;
|
||||
void tests_deinitPlatform_impl() override;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -69,15 +69,13 @@ class TestQtWidgets : public QObject
|
||||
public Q_SLOTS:
|
||||
void initTestCase()
|
||||
{
|
||||
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtWidgets);
|
||||
|
||||
KDDockWidgets::Platform::instance()->tests_initTests();
|
||||
KDDockWidgets::Platform::tests_initPlatform(KDDockWidgets::FrontendType::QtWidgets);
|
||||
KDDockWidgets::Testing::installFatalMessageHandler();
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
KDDockWidgets::Platform::instance()->tests_cleanupTests();
|
||||
KDDockWidgets::Platform::tests_deinitPlatform();
|
||||
}
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
@@ -42,16 +42,13 @@ class TestDocks : public QObject
|
||||
public Q_SLOTS:
|
||||
void initTestCase()
|
||||
{
|
||||
// TODOv2
|
||||
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtWidgets);
|
||||
|
||||
KDDockWidgets::Platform::instance()->tests_initTests();
|
||||
KDDockWidgets::Platform::tests_initPlatform(KDDockWidgets::FrontendType::QtWidgets);
|
||||
KDDockWidgets::Testing::installFatalMessageHandler();
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
KDDockWidgets::Platform::instance()->tests_cleanupTests();
|
||||
KDDockWidgets::Platform::tests_deinitPlatform();
|
||||
}
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
Reference in New Issue
Block a user