| 1 |
// Copyright (C) 2021 David Redondo <[email protected]> |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#include <QSignalSpy> |
| 5 |
#include <QtGui/private/qguiapplication_p.h> |
| 6 |
#include <QtWaylandClient/private/qwayland-wayland.h> |
| 7 |
#include <QtWaylandClient/private/qwaylanddisplay_p.h> |
| 8 |
#include <QtWaylandClient/private/qwaylandintegration_p.h> |
| 9 |
#include <QtWaylandClient/qwaylandclientextension.h> |
| 10 |
#include <qwayland-server-test.h> |
| 11 |
#include <qwayland-test.h> |
| 12 |
#include "mockcompositor.h" |
| 13 |
#include "coreprotocol.h" |
| 14 |
|
| 15 |
using namespace MockCompositor; |
| 16 |
|
| 17 |
class TestExtension |
| 18 |
: public QWaylandClientExtensionTemplate<TestExtension, &QtWayland::test_interface::release>, |
| 19 |
public QtWayland::test_interface |
| 20 |
{ |
| 21 |
public: |
| 22 |
TestExtension() : QWaylandClientExtensionTemplate(1){}; |
| 23 |
void initialize() { QWaylandClientExtension::initialize(); } |
| 24 |
}; |
| 25 |
|
| 26 |
class TestGlobal : public Global, public QtWaylandServer::test_interface |
| 27 |
{ |
| 28 |
Q_OBJECT |
| 29 |
public: |
| 30 |
explicit TestGlobal(CoreCompositor *compositor) |
| 31 |
: QtWaylandServer::test_interface(compositor->m_display, 1) |
| 32 |
{ |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
class tst_clientextension : public QObject, private CoreCompositor |
| 37 |
{ |
| 38 |
Q_OBJECT |
| 39 |
private: |
| 40 |
QtWaylandClient::QWaylandDisplay *display() |
| 41 |
{ |
| 42 |
return static_cast<QtWaylandClient::QWaylandIntegration *>( |
| 43 |
QGuiApplicationPrivate::platformIntegration()) |
| 44 |
->display(); |
| 45 |
} |
| 46 |
private slots: |
| 47 |
void cleanup() |
| 48 |
{ |
| 49 |
display()->flushRequests(); |
| 50 |
dispatch(); |
| 51 |
exec([this] { removeAll<TestGlobal>(); }); |
| 52 |
QTRY_COMPARE(display()->globals().size(), 0); |
| 53 |
} |
| 54 |
void createWithoutGlobal(); |
| 55 |
void createWithGlobalAutomatic(); |
| 56 |
void createWithGlobalManual(); |
| 57 |
void globalBecomesAvailable(); |
| 58 |
void globalRemoved(); |
| 59 |
}; |
| 60 |
|
| 61 |
void tst_clientextension::createWithoutGlobal() |
| 62 |
{ |
| 63 |
TestExtension extension; |
| 64 |
QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged); |
| 65 |
QVERIFY(spy.isValid()); |
| 66 |
QVERIFY(!extension.isActive()); |
| 67 |
QCOMPARE(spy.size(), 0); |
| 68 |
extension.initialize(); |
| 69 |
QVERIFY(!extension.isActive()); |
| 70 |
QCOMPARE(spy.size(), 0); |
| 71 |
} |
| 72 |
|
| 73 |
void tst_clientextension::createWithGlobalAutomatic() |
| 74 |
{ |
| 75 |
exec([this] { add<TestGlobal>(); }); |
| 76 |
QTRY_COMPARE(display()->globals().size(), 1); |
| 77 |
TestExtension extension; |
| 78 |
QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged); |
| 79 |
QVERIFY(spy.isValid()); |
| 80 |
QTRY_VERIFY(extension.isActive()); |
| 81 |
QCOMPARE(spy.size(), 1); |
| 82 |
} |
| 83 |
|
| 84 |
void tst_clientextension::createWithGlobalManual() |
| 85 |
{ |
| 86 |
exec([this] { add<TestGlobal>(); }); |
| 87 |
QTRY_COMPARE(display()->globals().size(), 1); |
| 88 |
// Wait for the display to have the global |
| 89 |
TestExtension extension; |
| 90 |
QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged); |
| 91 |
QVERIFY(spy.isValid()); |
| 92 |
extension.initialize(); |
| 93 |
QVERIFY(extension.isActive()); |
| 94 |
QCOMPARE(spy.size(), 1); |
| 95 |
} |
| 96 |
|
| 97 |
void tst_clientextension::globalBecomesAvailable() |
| 98 |
{ |
| 99 |
TestExtension extension; |
| 100 |
QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged); |
| 101 |
QVERIFY(spy.isValid()); |
| 102 |
exec([this] { add<TestGlobal>(); }); |
| 103 |
QTRY_VERIFY(extension.isActive()); |
| 104 |
QCOMPARE(spy.size(), 1); |
| 105 |
} |
| 106 |
|
| 107 |
void tst_clientextension::globalRemoved() |
| 108 |
{ |
| 109 |
exec([this] { add<TestGlobal>(); }); |
| 110 |
TestExtension extension; |
| 111 |
QTRY_VERIFY(extension.isActive()); |
| 112 |
QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged); |
| 113 |
QVERIFY(spy.isValid()); |
| 114 |
QCOMPOSITOR_TRY_COMPARE(get<TestGlobal>()->resourceMap().size(), 1); |
| 115 |
|
| 116 |
exec([this] { removeAll<TestGlobal>(); }); |
| 117 |
QTRY_VERIFY(!extension.isActive()); |
| 118 |
QCOMPARE(spy.size(), 1); |
| 119 |
} |
| 120 |
|
| 121 |
int main(int argc, char **argv) |
| 122 |
{ |
| 123 |
QTemporaryDir tmpRuntimeDir; |
| 124 |
qputenv("XDG_RUNTIME_DIR", tmpRuntimeDir.path().toLocal8Bit()); |
| 125 |
qputenv("QT_QPA_PLATFORM", "wayland"); |
| 126 |
qputenv("QT_WAYLAND_DONT_CHECK_SHELL_INTEGRATION", "1"); |
| 127 |
|
| 128 |
tst_clientextension tc; |
| 129 |
QGuiApplication app(argc, argv); |
| 130 |
QTEST_SET_MAIN_SOURCE_PATH |
| 131 |
return QTest::qExec(&tc, argc, argv); |
| 132 |
} |
| 133 |
|
| 134 |
#include "tst_clientextension.moc" |