summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPekka Paalanen <ppaalanen@gmail.com>2013-02-08 17:01:27 +0200
committerKristian Høgsberg <krh@bitplanet.net>2013-02-08 13:38:17 -0500
commitd1c426eef7f796a598bc19e9c9564167b0c4435b (patch)
treef8660d38370f617fa567c03892fc7e2415686825 /tests
parent32ac9b92457700887ee6c9ccfbff6838fb168bdd (diff)
tests: add test for buffer release event
Tests especially, that attach-attach-commit does not result in a release of the first buffer. Also tests, that the old buffer is released when a new buffer has been attached, committed, and displayed (frame callback). Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/event-test.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/event-test.c b/tests/event-test.c
index 254517dd..980dfaad 100644
--- a/tests/event-test.c
+++ b/tests/event-test.c
@@ -1,5 +1,6 @@
/*
* Copyright © 2012 Intel Corporation
+ * Copyright © 2013 Collabora, Ltd.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
@@ -347,3 +348,71 @@ TEST(test_surface_output)
check_client_move(client, x, --y);
assert(output_contains_client(client));
}
+
+static void
+buffer_release_handler(void *data, struct wl_buffer *buffer)
+{
+ int *released = data;
+
+ *released = 1;
+}
+
+static struct wl_buffer_listener buffer_listener = {
+ buffer_release_handler
+};
+
+TEST(buffer_release)
+{
+ struct client *client;
+ struct wl_surface *surface;
+ struct wl_buffer *buf1;
+ struct wl_buffer *buf2;
+ struct wl_buffer *buf3;
+ int buf1_released = 0;
+ int buf2_released = 0;
+ int buf3_released = 0;
+ int frame;
+
+ client = client_create(100, 100, 100, 100);
+ assert(client);
+ surface = client->surface->wl_surface;
+
+ buf1 = create_shm_buffer(client, 100, 100, NULL);
+ wl_buffer_add_listener(buf1, &buffer_listener, &buf1_released);
+
+ buf2 = create_shm_buffer(client, 100, 100, NULL);
+ wl_buffer_add_listener(buf2, &buffer_listener, &buf2_released);
+
+ buf3 = create_shm_buffer(client, 100, 100, NULL);
+ wl_buffer_add_listener(buf3, &buffer_listener, &buf3_released);
+
+ /*
+ * buf1 must never be released, since it is replaced before
+ * it is committed, therefore it never becomes busy.
+ */
+
+ wl_surface_attach(surface, buf1, 0, 0);
+ wl_surface_attach(surface, buf2, 0, 0);
+ frame_callback_set(surface, &frame);
+ wl_surface_commit(surface);
+ frame_callback_wait(client, &frame);
+ assert(buf1_released == 0);
+ /* buf2 may or may not be released */
+ assert(buf3_released == 0);
+
+ wl_surface_attach(surface, buf3, 0, 0);
+ frame_callback_set(surface, &frame);
+ wl_surface_commit(surface);
+ frame_callback_wait(client, &frame);
+ assert(buf1_released == 0);
+ assert(buf2_released == 1);
+ /* buf3 may or may not be released */
+
+ wl_surface_attach(surface, client->surface->wl_buffer, 0, 0);
+ frame_callback_set(surface, &frame);
+ wl_surface_commit(surface);
+ frame_callback_wait(client, &frame);
+ assert(buf1_released == 0);
+ assert(buf2_released == 1);
+ assert(buf3_released == 1);
+}