summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/client/CMakeLists.txt1
-rw-r--r--tests/auto/client/clientextension/CMakeLists.txt14
-rw-r--r--tests/auto/client/clientextension/test.xml6
-rw-r--r--tests/auto/client/clientextension/tst_clientextension.cpp152
4 files changed, 173 insertions, 0 deletions
diff --git a/tests/auto/client/CMakeLists.txt b/tests/auto/client/CMakeLists.txt
index accac45f..e187d1da 100644
--- a/tests/auto/client/CMakeLists.txt
+++ b/tests/auto/client/CMakeLists.txt
@@ -3,6 +3,7 @@
add_subdirectory(shared)
add_subdirectory(client)
+add_subdirectory(clientextension)
add_subdirectory(datadevicev1)
add_subdirectory(fullscreenshellv1)
add_subdirectory(iviapplication)
diff --git a/tests/auto/client/clientextension/CMakeLists.txt b/tests/auto/client/clientextension/CMakeLists.txt
new file mode 100644
index 00000000..efcd575d
--- /dev/null
+++ b/tests/auto/client/clientextension/CMakeLists.txt
@@ -0,0 +1,14 @@
+qt_internal_add_test(tst_clientextension
+ SOURCES
+ tst_clientextension.cpp
+ PUBLIC_LIBRARIES
+ SharedClientTest
+)
+
+qt6_generate_wayland_protocol_client_sources(tst_clientextension
+ FILES ${CMAKE_CURRENT_SOURCE_DIR}/test.xml
+)
+
+qt6_generate_wayland_protocol_server_sources(tst_clientextension
+ FILES ${CMAKE_CURRENT_SOURCE_DIR}/test.xml
+)
diff --git a/tests/auto/client/clientextension/test.xml b/tests/auto/client/clientextension/test.xml
new file mode 100644
index 00000000..f8d5b4ea
--- /dev/null
+++ b/tests/auto/client/clientextension/test.xml
@@ -0,0 +1,6 @@
+<protocol name="test">
+ <interface name="test_interface" version="1">
+ <request name="release" type="destructor" />
+ </interface>
+</protocol>
+
diff --git a/tests/auto/client/clientextension/tst_clientextension.cpp b/tests/auto/client/clientextension/tst_clientextension.cpp
new file mode 100644
index 00000000..ea7ef361
--- /dev/null
+++ b/tests/auto/client/clientextension/tst_clientextension.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 David Redondo <qt@david-redondo.de>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QSignalSpy>
+#include <QtGui/private/qguiapplication_p.h>
+#include <QtWaylandClient/private/qwayland-wayland.h>
+#include <QtWaylandClient/private/qwaylanddisplay_p.h>
+#include <QtWaylandClient/private/qwaylandintegration_p.h>
+#include <QtWaylandClient/qwaylandclientextension.h>
+#include <qwayland-server-test.h>
+#include <qwayland-test.h>
+#include "mockcompositor.h"
+#include "coreprotocol.h"
+
+using namespace MockCompositor;
+
+class TestExtension : public QWaylandClientExtensionTemplate<TestExtension>,
+ public QtWayland::test_interface
+{
+public:
+ TestExtension() : QWaylandClientExtensionTemplate<TestExtension>(1) { }
+ ~TestExtension()
+ {
+ if (object()) {
+ release();
+ }
+ }
+ void initialize() { QWaylandClientExtension::initialize(); }
+};
+
+class TestGlobal : public Global, public QtWaylandServer::test_interface
+{
+ Q_OBJECT
+public:
+ explicit TestGlobal(CoreCompositor *compositor)
+ : QtWaylandServer::test_interface(compositor->m_display, 1)
+ {
+ }
+};
+
+class tst_clientextension : public QObject, private CoreCompositor
+{
+ Q_OBJECT
+private:
+ QtWaylandClient::QWaylandDisplay *display()
+ {
+ return static_cast<QtWaylandClient::QWaylandIntegration *>(
+ QGuiApplicationPrivate::platformIntegration())
+ ->display();
+ }
+private slots:
+ void cleanup()
+ {
+ display()->flushRequests();
+ dispatch();
+ exec([this] { removeAll<TestGlobal>(); });
+ QTRY_COMPARE(display()->globals().size(), 0);
+ }
+ void createWithoutGlobal();
+ void createWithGlobalAutomatic();
+ void createWithGlobalManual();
+ void globalBecomesAvailable();
+ void globalRemoved();
+};
+
+void tst_clientextension::createWithoutGlobal()
+{
+ TestExtension extension;
+ QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged);
+ QVERIFY(spy.isValid());
+ QVERIFY(!extension.isActive());
+ QCOMPARE(spy.count(), 0);
+ extension.initialize();
+ QVERIFY(!extension.isActive());
+ QCOMPARE(spy.count(), 0);
+}
+
+void tst_clientextension::createWithGlobalAutomatic()
+{
+ exec([this] { add<TestGlobal>(); });
+ QTRY_COMPARE(display()->globals().size(), 1);
+ TestExtension extension;
+ QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged);
+ QVERIFY(spy.isValid());
+ QTRY_VERIFY(extension.isActive());
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_clientextension::createWithGlobalManual()
+{
+ exec([this] { add<TestGlobal>(); });
+ QTRY_COMPARE(display()->globals().size(), 1);
+ // Wait for the display to have the global
+ TestExtension extension;
+ QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged);
+ QVERIFY(spy.isValid());
+ extension.initialize();
+ QVERIFY(extension.isActive());
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_clientextension::globalBecomesAvailable()
+{
+ TestExtension extension;
+ QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged);
+ QVERIFY(spy.isValid());
+ exec([this] { add<TestGlobal>(); });
+ QTRY_VERIFY(extension.isActive());
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_clientextension::globalRemoved()
+{
+ exec([this] { add<TestGlobal>(); });
+ TestExtension extension;
+ QTRY_VERIFY(extension.isActive());
+ QSignalSpy spy(&extension, &QWaylandClientExtension::activeChanged);
+ QVERIFY(spy.isValid());
+ QCOMPOSITOR_TRY_COMPARE(get<TestGlobal>()->resourceMap().size(), 1);
+
+ exec([this] { removeAll<TestGlobal>(); });
+ QTRY_VERIFY(!extension.isActive());
+ QCOMPARE(spy.count(), 1);
+}
+
+QCOMPOSITOR_TEST_MAIN(tst_clientextension)
+#include "tst_clientextension.moc"