Client tests for xdg-output unstable v1 version 3

Change-Id: If6d7547c14dfaf06532a83ab2fbda4d0198837dc
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
This commit is contained in:
Johan Klokkhammer Helsing 2020-01-09 12:20:23 +01:00
parent d4027bc3fe
commit a23d0f4587
5 changed files with 83 additions and 14 deletions

View File

@ -158,6 +158,14 @@ void Output::sendScale(Resource *resource)
wl_output::send_scale(resource->handle, m_data.scale);
}
void Output::sendDone(wl_client *client)
{
Q_ASSERT(m_version >= WL_OUTPUT_DONE_SINCE_VERSION);
auto resources = resourceMap().values(client);
for (auto *r : resources)
wl_output::send_done(r->handle);
}
void Output::sendDone()
{
Q_ASSERT(m_version >= WL_OUTPUT_DONE_SINCE_VERSION);

View File

@ -245,6 +245,7 @@ public:
void sendScale(int factor);
void sendScale(Resource *resource); // Sends current scale to only one client
void sendDone(wl_client *client);
void sendDone();
int scale() const { return m_data.scale; }

View File

@ -32,4 +32,28 @@ namespace MockCompositor {
int XdgOutputV1::s_nextId = 1;
void XdgOutputV1::sendLogicalSize(const QSize &size)
{
m_logicalGeometry.setSize(size);
for (auto *resource : resourceMap())
zxdg_output_v1::send_logical_size(resource->handle, size.width(), size.height());
}
void XdgOutputV1::addResource(wl_client *client, int id, int version)
{
auto *resource = add(client, id, version)->handle;
zxdg_output_v1::send_logical_size(resource, m_logicalGeometry.width(), m_logicalGeometry.height());
send_logical_position(resource, m_logicalGeometry.x(), m_logicalGeometry.y());
if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)
send_name(resource, m_name);
if (version >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION)
send_description(resource, m_description);
if (version < 3) // zxdg_output_v1.done has been deprecated
zxdg_output_v1::send_done(resource);
else {
m_output->sendDone(client);
}
}
} // namespace MockCompositor

View File

@ -44,17 +44,12 @@ public:
, m_name(QString("WL-%1").arg(s_nextId++))
{}
void addResource(wl_client *client, int id, int version)
{
auto *resource = add(client, id, version)->handle;
send_logical_size(resource, m_logicalGeometry.width(), m_logicalGeometry.height());
send_logical_position(resource, m_logicalGeometry.x(), m_logicalGeometry.y());
if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)
send_name(resource, m_name);
if (version >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION)
send_description(resource, m_description);
send_done(resource);
}
void send_logical_size(int32_t width, int32_t height) = delete;
void sendLogicalSize(const QSize &size);
void send_done() = delete; // zxdg_output_v1.done has been deprecated (in protocol version 3)
void addResource(wl_client *client, int id, int version);
Output *m_output = nullptr;
QRect m_logicalGeometry;
QString m_name;
@ -66,7 +61,7 @@ class XdgOutputManagerV1 : public Global, public QtWaylandServer::zxdg_output_ma
{
Q_OBJECT
public:
explicit XdgOutputManagerV1(CoreCompositor *compositor, int version = 2)
explicit XdgOutputManagerV1(CoreCompositor *compositor, int version = 3)
: QtWaylandServer::zxdg_output_manager_v1(compositor->m_display, version)
, m_version(version)
{}

View File

@ -40,7 +40,7 @@ public:
explicit XdgOutputV1Compositor()
{
exec([this] {
int version = 2; // version 2 of of unstable-v1
int version = 3; // version 3 of of unstable-v1
add<XdgOutputManagerV1>(version);
});
}
@ -54,11 +54,13 @@ private slots:
void cleanup();
void primaryScreen();
void overrideGeometry();
void changeGeometry();
};
void tst_xdgoutput::cleanup()
{
QCOMPOSITOR_COMPARE(getAll<Output>().size(), 1); // Only the default output should be left
QTRY_COMPARE(QGuiApplication::screens().size(), 1);
QTRY_VERIFY2(isClean(), qPrintable(dirtyMessage()));
}
@ -68,7 +70,8 @@ void tst_xdgoutput::primaryScreen()
QCOMPOSITOR_TRY_COMPARE(get<XdgOutputManagerV1>()->resourceMap().size(), 1);
exec([=] {
auto *resource = xdgOutput()->resourceMap().value(client());
QCOMPARE(resource->version(), 2);
QCOMPARE(resource->version(), 3);
QCOMPARE(xdgOutput()->m_logicalGeometry.size(), QSize(1920, 1080));
});
auto *s = QGuiApplication::primaryScreen();
QTRY_COMPARE(s->size(), QSize(1920, 1080));
@ -93,5 +96,43 @@ void tst_xdgoutput::overrideGeometry()
exec([=] { remove(output(1)); });
}
void tst_xdgoutput::changeGeometry()
{
auto *xdgOutput = exec([=] {
auto *output = add<Output>();
auto *xdgOutput = get<XdgOutputManagerV1>()->getXdgOutput(output);
xdgOutput->m_logicalGeometry = QRect(10, 20, 800, 1200);
return xdgOutput;
});
QTRY_COMPARE(QGuiApplication::screens().size(), 2);
auto *screen = QGuiApplication::screens()[1];
QTRY_COMPARE(screen->size(), QSize(800, 1200));
exec([=] {
xdgOutput->sendLogicalSize(QSize(1024, 768));
});
// Now we want to check that the client doesn't apply the size immediately, but waits for the
// done event. If we TRY_COMPARE immediately, we risk that the client just hasn't handled the
// logical_size request yet, so we add a screen and verify it on the client side just to give
// the client a chance to mess up.
exec([=] { add<Output>(); });
QTRY_COMPARE(QGuiApplication::screens().size(), 3);
exec([=] { remove(output(2)); });
// The logical_size event should have been handled by now, but state should not have been applied yet.
QTRY_COMPARE(screen->size(), QSize(800, 1200));
exec([=] {
xdgOutput->m_output->sendDone();
});
// Finally, the size should change
QTRY_COMPARE(screen->size(), QSize(1024, 768));
exec([=] { remove(output(1)); });
}
QCOMPOSITOR_TEST_MAIN(tst_xdgoutput)
#include "tst_xdgoutput.moc"