2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2017 David Edmundson <davidedmundson@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2017-12-18 21:50:31 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2017-12-18 21:50:31 +00:00
|
|
|
// Qt
|
2018-11-06 06:22:36 +00:00
|
|
|
#include <QtTest>
|
2017-12-18 21:50:31 +00:00
|
|
|
// KWin
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/compositor.h"
|
|
|
|
#include "KWayland/Client/connection_thread.h"
|
|
|
|
#include "KWayland/Client/event_queue.h"
|
|
|
|
#include "KWayland/Client/region.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/surface.h"
|
|
|
|
#include "KWayland/Client/appmenu.h"
|
2017-12-18 21:50:31 +00:00
|
|
|
#include "../../src/server/display.h"
|
|
|
|
#include "../../src/server/compositor_interface.h"
|
|
|
|
#include "../../src/server/region_interface.h"
|
|
|
|
#include "../../src/server/appmenu_interface.h"
|
|
|
|
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
Q_DECLARE_METATYPE(KWaylandServer::AppMenuInterface::InterfaceAddress)
|
2017-12-18 21:50:31 +00:00
|
|
|
|
|
|
|
class TestAppmenu : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TestAppmenu(QObject *parent = nullptr);
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testCreateAndSet();
|
|
|
|
|
|
|
|
private:
|
2020-04-29 14:56:38 +00:00
|
|
|
KWaylandServer::Display *m_display;
|
|
|
|
KWaylandServer::CompositorInterface *m_compositorInterface;
|
|
|
|
KWaylandServer::AppMenuManagerInterface *m_appmenuManagerInterface;
|
2017-12-18 21:50:31 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::Compositor *m_compositor;
|
|
|
|
KWayland::Client::AppMenuManager *m_appmenuManager;
|
|
|
|
KWayland::Client::EventQueue *m_queue;
|
|
|
|
QThread *m_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwayland-test-wayland-appmenu-0");
|
|
|
|
|
|
|
|
TestAppmenu::TestAppmenu(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_display(nullptr)
|
|
|
|
, m_compositorInterface(nullptr)
|
|
|
|
, m_connection(nullptr)
|
|
|
|
, m_compositor(nullptr)
|
|
|
|
, m_queue(nullptr)
|
|
|
|
, m_thread(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestAppmenu::init()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
2017-12-18 21:50:31 +00:00
|
|
|
qRegisterMetaType<AppMenuInterface::InterfaceAddress>();
|
|
|
|
delete m_display;
|
|
|
|
m_display = new Display(this);
|
|
|
|
m_display->setSocketName(s_socketName);
|
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
|
|
|
QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected);
|
|
|
|
QVERIFY(connectedSpy.isValid());
|
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
m_connection->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
|
|
|
QVERIFY(!m_queue->isValid());
|
|
|
|
m_queue->setup(m_connection);
|
|
|
|
QVERIFY(m_queue->isValid());
|
|
|
|
|
|
|
|
Registry registry;
|
|
|
|
QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced);
|
|
|
|
QVERIFY(compositorSpy.isValid());
|
|
|
|
|
|
|
|
QSignalSpy appmenuSpy(®istry, &Registry::appMenuAnnounced);
|
|
|
|
QVERIFY(appmenuSpy.isValid());
|
|
|
|
|
|
|
|
QVERIFY(!registry.eventQueue());
|
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
QCOMPARE(registry.eventQueue(), m_queue);
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
|
|
|
|
m_compositorInterface = m_display->createCompositor(m_display);
|
|
|
|
QVERIFY(compositorSpy.wait());
|
|
|
|
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
|
|
|
|
|
|
|
|
m_appmenuManagerInterface = m_display->createAppMenuManagerInterface(m_display);
|
|
|
|
|
|
|
|
QVERIFY(appmenuSpy.wait());
|
|
|
|
m_appmenuManager = registry.createAppMenuManager(appmenuSpy.first().first().value<quint32>(), appmenuSpy.first().last().value<quint32>(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestAppmenu::cleanup()
|
|
|
|
{
|
|
|
|
#define CLEANUP(variable) \
|
|
|
|
if (variable) { \
|
|
|
|
delete variable; \
|
|
|
|
variable = nullptr; \
|
|
|
|
}
|
|
|
|
CLEANUP(m_compositor)
|
|
|
|
CLEANUP(m_appmenuManager)
|
|
|
|
CLEANUP(m_queue)
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
|
|
|
}
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
CLEANUP(m_compositorInterface)
|
|
|
|
CLEANUP(m_appmenuManagerInterface)
|
|
|
|
CLEANUP(m_display)
|
|
|
|
#undef CLEANUP
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestAppmenu::testCreateAndSet()
|
|
|
|
{
|
2020-04-29 14:56:38 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWaylandServer::SurfaceInterface*)));
|
2017-12-18 21:50:31 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.isValid());
|
|
|
|
|
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
auto serverSurface = serverSurfaceCreated.first().first().value<KWaylandServer::SurfaceInterface*>();
|
|
|
|
QSignalSpy appMenuCreated(m_appmenuManagerInterface, &KWaylandServer::AppMenuManagerInterface::appMenuCreated);
|
2017-12-18 21:50:31 +00:00
|
|
|
|
2017-12-19 08:10:09 +00:00
|
|
|
QVERIFY(!m_appmenuManagerInterface->appMenuForSurface(serverSurface));
|
2017-12-18 21:50:31 +00:00
|
|
|
|
|
|
|
auto appmenu = m_appmenuManager->create(surface.data(), surface.data());
|
|
|
|
QVERIFY(appMenuCreated.wait());
|
2020-04-29 14:56:38 +00:00
|
|
|
auto appMenuInterface = appMenuCreated.first().first().value<KWaylandServer::AppMenuInterface*>();
|
2017-12-18 21:50:31 +00:00
|
|
|
QCOMPARE(m_appmenuManagerInterface->appMenuForSurface(serverSurface), appMenuInterface);
|
|
|
|
|
|
|
|
QCOMPARE(appMenuInterface->address().serviceName, QString());
|
|
|
|
QCOMPARE(appMenuInterface->address().objectPath, QString());
|
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
QSignalSpy appMenuChangedSpy(appMenuInterface, &KWaylandServer::AppMenuInterface::addressChanged);
|
2017-12-18 21:50:31 +00:00
|
|
|
|
|
|
|
appmenu->setAddress("net.somename", "/test/path");
|
|
|
|
|
|
|
|
QVERIFY(appMenuChangedSpy.wait());
|
2017-12-19 07:28:20 +00:00
|
|
|
QCOMPARE(appMenuInterface->address().serviceName, QString("net.somename"));
|
|
|
|
QCOMPARE(appMenuInterface->address().objectPath, QString("/test/path"));
|
2017-12-18 21:50:31 +00:00
|
|
|
|
|
|
|
// and destroy
|
|
|
|
QSignalSpy destroyedSpy(appMenuInterface, &QObject::destroyed);
|
|
|
|
QVERIFY(destroyedSpy.isValid());
|
|
|
|
delete appmenu;
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
2017-12-19 08:10:09 +00:00
|
|
|
QVERIFY(!m_appmenuManagerInterface->appMenuForSurface(serverSurface));
|
2017-12-18 21:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TestAppmenu)
|
|
|
|
#include "test_wayland_appmenu.moc"
|