[autotest] Add a test case for QtSurfaceExtensionInterface
Summary: KWayland does not have a client implementation of the QtSurfaceExtension protocol. Thus the test is different: it starts a helper binary which creates a QWindow. The test closes that one which should terminate the started applications. Reviewers: #plasma Subscribers: plasma-devel Projects: #plasma Differential Revision: https://phabricator.kde.org/D1388
This commit is contained in:
parent
9e3cd3bf7b
commit
c5a16a535d
3 changed files with 176 additions and 0 deletions
|
@ -20,3 +20,21 @@ add_executable(testWaylandServerSeat ${testWaylandServerSeat_SRCS})
|
|||
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)
|
||||
|
|
61
src/wayland/autotests/server/surfaceextension_helper.cpp
Normal file
61
src/wayland/autotests/server/surfaceextension_helper.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
/********************************************************************
|
||||
Copyright 2016 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#include <QGuiApplication>
|
||||
#include <QPainter>
|
||||
#include <QRasterWindow>
|
||||
|
||||
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<Window> w(new Window);
|
||||
w->show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "surfaceextension_helper.moc"
|
97
src/wayland/autotests/server/test_qt_surface_extension.cpp
Normal file
97
src/wayland/autotests/server/test_qt_surface_extension.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
/********************************************************************
|
||||
Copyright 2016 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
// Qt
|
||||
#include <QtTest/QtTest>
|
||||
#include <QProcess>
|
||||
// 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<QtExtendedSurfaceInterface*>();
|
||||
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"
|
Loading…
Reference in a new issue