summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGiulio Camuffo <giulio.camuffo@jollamobile.com>2014-08-19 16:19:12 +0300
committerGiulio Camuffo <giulio.camuffo@jollamobile.com>2014-08-19 15:49:04 +0200
commit58bc9a98d4c1e8b40be41b31833e535ddbf9f12a (patch)
tree5fe327aaf934d705dac1d95bcceec3af0937ad1b /tests
parent7be658e8998b748a4acfe540bd6361ad95fe5fd7 (diff)
downloadqtwayland-58bc9a98d4c1e8b40be41b31833e535ddbf9f12a.tar.gz
Make the test client more robust and make valgrind happy
Change-Id: I39ce667123391b946711cc2d16d12799e8b7dd2d Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/client/mockcompositor.cpp19
-rw-r--r--tests/auto/client/mockcompositor.h2
-rw-r--r--tests/auto/client/mockinput.cpp4
-rw-r--r--tests/auto/client/mockshell.cpp3
-rw-r--r--tests/auto/client/mocksurface.cpp75
-rw-r--r--tests/auto/client/mocksurface.h7
-rw-r--r--tests/auto/client/tst_client.cpp4
7 files changed, 63 insertions, 51 deletions
diff --git a/tests/auto/client/mockcompositor.cpp b/tests/auto/client/mockcompositor.cpp
index bb4f10fd..70fa5f23 100644
--- a/tests/auto/client/mockcompositor.cpp
+++ b/tests/auto/client/mockcompositor.cpp
@@ -135,8 +135,13 @@ QSharedPointer<MockSurface> MockCompositor::surface()
QSharedPointer<MockSurface> result;
lock();
QVector<Impl::Surface *> surfaces = m_compositor->surfaces();
- if (!surfaces.isEmpty())
- result = surfaces.first()->mockSurface();
+ foreach (Impl::Surface *surface, surfaces) {
+ // we don't want to mistake the cursor surface for a window surface
+ if (surface->isMapped()) {
+ result = surface->mockSurface();
+ break;
+ }
+ }
unlock();
return result;
}
@@ -189,11 +194,6 @@ void *MockCompositor::run(void *data)
return 0;
}
-void MockCompositor::discardSurfaces()
-{
- m_compositor->discardSurfaces();
-}
-
namespace Impl {
Compositor::Compositor()
@@ -298,10 +298,5 @@ void Compositor::removeSurface(Surface *surface)
m_pointer->setFocus(0, QPoint());
}
-void Compositor::discardSurfaces()
-{
- m_surfaces.clear();
-}
-
}
diff --git a/tests/auto/client/mockcompositor.h b/tests/auto/client/mockcompositor.h
index 68e55d35..7f3e2268 100644
--- a/tests/auto/client/mockcompositor.h
+++ b/tests/auto/client/mockcompositor.h
@@ -81,7 +81,6 @@ public:
void addSurface(Surface *surface);
void removeSurface(Surface *surface);
- void discardSurfaces();
static void setKeyboardFocus(void *data, const QList<QVariant> &parameters);
static void sendMousePress(void *data, const QList<QVariant> &parameters);
@@ -155,7 +154,6 @@ public:
void sendKeyRelease(const QSharedPointer<MockSurface> &surface, uint code);
QSharedPointer<MockSurface> surface();
- void discardSurfaces();
void lock();
void unlock();
diff --git a/tests/auto/client/mockinput.cpp b/tests/auto/client/mockinput.cpp
index 7dbb735e..bd85ad6c 100644
--- a/tests/auto/client/mockinput.cpp
+++ b/tests/auto/client/mockinput.cpp
@@ -130,6 +130,8 @@ void Seat::seat_get_pointer(Resource *resource, uint32_t id)
Keyboard::Keyboard(Compositor *compositor)
: wl_keyboard()
, m_compositor(compositor)
+ , m_focusResource(Q_NULLPTR)
+ , m_focus(Q_NULLPTR)
{
}
@@ -174,6 +176,8 @@ void Keyboard::keyboard_destroy_resource(wl_keyboard::Resource *resource)
Pointer::Pointer(Compositor *compositor)
: wl_pointer()
, m_compositor(compositor)
+ , m_focusResource(Q_NULLPTR)
+ , m_focus(Q_NULLPTR)
{
}
diff --git a/tests/auto/client/mockshell.cpp b/tests/auto/client/mockshell.cpp
index 0d841f64..2a5969f7 100644
--- a/tests/auto/client/mockshell.cpp
+++ b/tests/auto/client/mockshell.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "mockcompositor.h"
+#include "mocksurface.h"
namespace Impl {
@@ -173,6 +174,8 @@ static void get_shell_surface(wl_client *client, wl_resource *compositorResource
Q_UNUSED(compositorResource);
wl_client_add_object(client, &wl_shell_surface_interface, &shellSurfaceInterface, id, surfaceResource->data);
+ Surface *surf = Surface::fromResource(surfaceResource);
+ surf->map();
}
void Compositor::bindShell(wl_client *client, void *compositorData, uint32_t version, uint32_t id)
diff --git a/tests/auto/client/mocksurface.cpp b/tests/auto/client/mocksurface.cpp
index d5e0367a..2e4c2bc7 100644
--- a/tests/auto/client/mocksurface.cpp
+++ b/tests/auto/client/mocksurface.cpp
@@ -46,10 +46,11 @@ namespace Impl {
Surface::Surface(wl_client *client, uint32_t id, Compositor *compositor)
: QtWaylandServer::wl_surface(client, id)
+ , m_buffer(Q_NULLPTR)
, m_compositor(compositor)
, m_mockSurface(new MockSurface(this))
+ , m_mapped(false)
{
- wl_list_init(&m_frameCallbackList);
}
Surface::~Surface()
@@ -57,6 +58,21 @@ Surface::~Surface()
m_mockSurface->m_surface = 0;
}
+void Surface::map()
+{
+ m_mapped = true;
+}
+
+bool Surface::isMapped() const
+{
+ return m_mapped;
+}
+
+Surface *Surface::fromResource(struct ::wl_resource *resource)
+{
+ return static_cast<Surface *>(Resource::fromResource(resource)->surface_object);
+}
+
void Surface::surface_destroy_resource(Resource *)
{
compositor()->removeSurface(this);
@@ -88,47 +104,44 @@ void Surface::surface_damage(Resource *resource,
Q_UNUSED(y);
Q_UNUSED(width);
Q_UNUSED(height);
-
- if (!m_buffer)
- return;
-
-#if WAYLAND_VERSION_CHECK(1, 2, 0)
- struct ::wl_shm_buffer *shm_buffer = wl_shm_buffer_get(m_buffer);
-#else
- struct ::wl_buffer *shm_buffer = 0;
- if (wl_buffer_is_shm(static_cast<struct ::wl_buffer*>(m_buffer->data)))
- shm_buffer = static_cast<struct ::wl_buffer*>(m_buffer->data);
-#endif
-
- if (shm_buffer) {
- int stride = wl_shm_buffer_get_stride(shm_buffer);
- uint format = wl_shm_buffer_get_format(shm_buffer);
- Q_UNUSED(format);
- void *data = wl_shm_buffer_get_data(shm_buffer);
- const uchar *char_data = static_cast<const uchar *>(data);
- QImage img(char_data, wl_shm_buffer_get_width(shm_buffer), wl_shm_buffer_get_height(shm_buffer), stride, QImage::Format_ARGB32_Premultiplied);
- m_mockSurface->image = img;
- }
-
- wl_resource *frameCallback;
- wl_list_for_each(frameCallback, &m_frameCallbackList, link) {
- wl_callback_send_done(frameCallback, m_compositor->time());
- wl_resource_destroy(frameCallback);
- }
-
- wl_list_init(&m_frameCallbackList);
}
void Surface::surface_frame(Resource *resource,
uint32_t callback)
{
wl_resource *frameCallback = wl_client_add_object(resource->client(), &wl_callback_interface, 0, callback, this);
- wl_list_insert(&m_frameCallbackList, &frameCallback->link);
+ m_frameCallbackList << frameCallback;
}
void Surface::surface_commit(Resource *resource)
{
Q_UNUSED(resource);
+
+ if (m_buffer) {
+#if WAYLAND_VERSION_CHECK(1, 2, 0)
+ struct ::wl_shm_buffer *shm_buffer = wl_shm_buffer_get(m_buffer);
+#else
+ struct ::wl_buffer *shm_buffer = 0;
+ if (wl_buffer_is_shm(static_cast<struct ::wl_buffer*>(m_buffer->data)))
+ shm_buffer = static_cast<struct ::wl_buffer*>(m_buffer->data);
+#endif
+
+ if (shm_buffer) {
+ int stride = wl_shm_buffer_get_stride(shm_buffer);
+ uint format = wl_shm_buffer_get_format(shm_buffer);
+ Q_UNUSED(format);
+ void *data = wl_shm_buffer_get_data(shm_buffer);
+ const uchar *char_data = static_cast<const uchar *>(data);
+ QImage img(char_data, wl_shm_buffer_get_width(shm_buffer), wl_shm_buffer_get_height(shm_buffer), stride, QImage::Format_ARGB32_Premultiplied);
+ m_mockSurface->image = img;
+ }
+ }
+
+ foreach (wl_resource *frameCallback, m_frameCallbackList) {
+ wl_callback_send_done(frameCallback, m_compositor->time());
+ wl_resource_destroy(frameCallback);
+ }
+ m_frameCallbackList.clear();
}
}
diff --git a/tests/auto/client/mocksurface.h b/tests/auto/client/mocksurface.h
index 49260f51..f2a2f4eb 100644
--- a/tests/auto/client/mocksurface.h
+++ b/tests/auto/client/mocksurface.h
@@ -54,6 +54,9 @@ public:
~Surface();
Compositor *compositor() const { return m_compositor; }
+ static Surface *fromResource(struct ::wl_resource *resource);
+ void map();
+ bool isMapped() const;
QSharedPointer<MockSurface> mockSurface() const { return m_mockSurface; }
@@ -74,8 +77,8 @@ private:
Compositor *m_compositor;
QSharedPointer<MockSurface> m_mockSurface;
-
- wl_list m_frameCallbackList;
+ QList<wl_resource *> m_frameCallbackList;
+ bool m_mapped;
};
}
diff --git a/tests/auto/client/tst_client.cpp b/tests/auto/client/tst_client.cpp
index 9c3138bc..e13d738d 100644
--- a/tests/auto/client/tst_client.cpp
+++ b/tests/auto/client/tst_client.cpp
@@ -149,11 +149,7 @@ private:
void tst_WaylandClient::screen()
{
- QCoreApplication::processEvents(QEventLoop::AllEvents);
-
QTRY_COMPARE(QGuiApplication::primaryScreen()->size(), screenSize);
- // discard the cursor surface created by the QWaylandInputDevice
- compositor->discardSurfaces();
}
void tst_WaylandClient::createDestroyWindow()