diff --git a/autotests/server/CMakeLists.txt b/autotests/server/CMakeLists.txt --- a/autotests/server/CMakeLists.txt +++ b/autotests/server/CMakeLists.txt @@ -20,3 +20,21 @@ target_link_libraries( testWaylandServerSeat Qt5::Test Qt5::Gui KF5::WaylandServer Wayland::Server) add_test(kwayland-testWaylandServerSeat testWaylandServerSeat) ecm_mark_as_test(testWaylandServerSeat) + +######################################################## +# QtSurfaceExtenstion Helper +######################################################## +add_executable(surfaceExtensionHelper surfaceextension_helper.cpp) +target_link_libraries( surfaceExtensionHelper Qt5::Gui) +ecm_mark_as_test(surfaceExtensionHelper) + +######################################################## +# Test QtSurfaceExtenstion +######################################################## +set( testQtSurfaceExtension_SRCS + test_qt_surface_extension.cpp + ) +add_executable(testQtSurfaceExtension ${testQtSurfaceExtension_SRCS}) +target_link_libraries( testQtSurfaceExtension Qt5::Test Qt5::Gui KF5::WaylandServer) +add_test(kwayland-testQtSurfaceExtension testQtSurfaceExtension) +ecm_mark_as_test(testQtSurfaceExtension) diff --git a/autotests/server/surfaceextension_helper.cpp b/autotests/server/surfaceextension_helper.cpp new file mode 100644 --- /dev/null +++ b/autotests/server/surfaceextension_helper.cpp @@ -0,0 +1,61 @@ +/******************************************************************** +Copyright 2016 Martin Gräßlin + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) version 3, or any +later version accepted by the membership of KDE e.V. (or its +successor approved by the membership of KDE e.V.), which shall +act as a proxy defined in Section 6 of version 3 of the license. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library. If not, see . +*********************************************************************/ +#include +#include +#include + +class Window : public QRasterWindow +{ + Q_OBJECT +public: + explicit Window(); + virtual ~Window(); + +protected: + void paintEvent(QPaintEvent *event) override; +}; + +Window::Window() + : QRasterWindow() +{ + setGeometry(QRect(0, 0, 200, 200)); +} + +Window::~Window() = default; + +void Window::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + QPainter p(this); + p.fillRect(QRect(QPoint(0, 0), size()), Qt::black); +} + +int main(int argc, char **argv) +{ + qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("wayland")); + QGuiApplication app(argc, argv); + + QScopedPointer w(new Window); + w->show(); + + return app.exec(); +} + +#include "surfaceextension_helper.moc" diff --git a/autotests/server/test_qt_surface_extension.cpp b/autotests/server/test_qt_surface_extension.cpp new file mode 100644 --- /dev/null +++ b/autotests/server/test_qt_surface_extension.cpp @@ -0,0 +1,97 @@ +/******************************************************************** +Copyright 2016 Martin Gräßlin + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) version 3, or any +later version accepted by the membership of KDE e.V. (or its +successor approved by the membership of KDE e.V.), which shall +act as a proxy defined in Section 6 of version 3 of the license. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library. If not, see . +*********************************************************************/ +// Qt +#include +#include +// WaylandServer +#include "../../src/server/compositor_interface.h" +#include "../../src/server/display.h" +#include "../../src/server/output_interface.h" +#include "../../src/server/qtsurfaceextension_interface.h" +#include "../../src/server/seat_interface.h" +#include "../../src/server/shell_interface.h" + +using namespace KWayland::Server; + + +class TestQtSurfaceExtension : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void testCloseWindow(); +}; + +static const QString s_socketName = QStringLiteral("kwin-wayland-server-qt-surface-extension-0"); + +void TestQtSurfaceExtension::testCloseWindow() +{ + // this test verifies that we can close windows through the Qt surface extension interface + // for this we start a dummy server, launch a QtWayland powered application, wait for the + // window it opens, close it and verify that the process terminates + Display display; + display.setSocketName(s_socketName); + display.start(); + display.createShm(); + SeatInterface *seat = display.createSeat(); + seat->setHasKeyboard(true); + seat->setHasPointer(true); + seat->setHasTouch(true); + seat->create(); + CompositorInterface *compositor = display.createCompositor(); + compositor->create(); + ShellInterface *shell = display.createShell(); + shell->create(); + OutputInterface *output = display.createOutput(); + output->setManufacturer(QStringLiteral("org.kde")); + output->setModel(QStringLiteral("QtSurfaceExtensionTestCase")); + output->addMode(QSize(1280, 1024), OutputInterface::ModeFlag::Preferred | OutputInterface::ModeFlag::Current); + output->setPhysicalSize(QSize(1280, 1024) / 3.8); + output->create(); + // surface extension + QtSurfaceExtensionInterface *surfaceExtension = display.createQtSurfaceExtension(); + surfaceExtension->create(); + // create a signalspy for surfaceCreated + QSignalSpy surfaceExtensionSpy(surfaceExtension, &QtSurfaceExtensionInterface::surfaceCreated); + QVERIFY(surfaceExtensionSpy.isValid()); + + // now start our application + QString binary = QFINDTESTDATA("surfaceExtensionHelper"); + QVERIFY(!binary.isEmpty()); + + QProcess process; + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert(QStringLiteral("WAYLAND_DISPLAY"), s_socketName); + process.setProcessEnvironment(env); + process.start(binary); + QVERIFY(surfaceExtensionSpy.wait()); + QCOMPARE(surfaceExtensionSpy.count(), 1); + auto *extension = surfaceExtensionSpy.first().first().value(); + QVERIFY(extension); + QSignalSpy processStateChangedSpy(&process, &QProcess::stateChanged); + QVERIFY(processStateChangedSpy.isValid()); + extension->close(); + extension->client()->flush(); + + QVERIFY(processStateChangedSpy.wait()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); +} + +QTEST_GUILESS_MAIN(TestQtSurfaceExtension) +#include "test_qt_surface_extension.moc"