[PATCH weston 2/5] tests: add sub-surface protocol tests

Pekka Paalanen ppaalanen at gmail.com
Fri Dec 21 04:04:01 PST 2012


For testing the protocol behaviour only:
- linking a surface to a parent does not fail
- position and placement requests do not fail
- bad linking and arguments do fail
- passing a surface as a sibling from a different set fails
- different destruction sequences do not crash

Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
 tests/.gitignore        |    2 +
 tests/Makefile.am       |    4 +
 tests/subsurface-test.c |  306 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 312 insertions(+), 0 deletions(-)
 create mode 100644 tests/subsurface-test.c

diff --git a/tests/.gitignore b/tests/.gitignore
index d8086a9..796c4c9 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -10,3 +10,5 @@ text-test
 keyboard-test
 event-test
 button-test
+subsurface-test
+
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7d6b6e0..a0cde40 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,6 +8,7 @@ weston_tests =				\
 	keyboard-test			\
 	event-test			\
 	button-test			\
+	subsurface-test			\
 	text-test
 
 TESTS_ENVIRONMENT = $(SHELL) $(top_srcdir)/tests/weston-tests-env
@@ -74,6 +75,9 @@ text_test_SOURCES =				\
 	$(weston_test_client_src)
 text_test_LDADD = $(weston_test_client_libs)
 
+subsurface_test_SOURCES = subsurface-test.c $(weston_test_client_src)
+subsurface_test_LDADD = $(weston_test_client_libs)
+
 matrix_test_SOURCES =				\
 	matrix-test.c				\
 	$(top_srcdir)/shared/matrix.c		\
diff --git a/tests/subsurface-test.c b/tests/subsurface-test.c
new file mode 100644
index 0000000..18d4e8c
--- /dev/null
+++ b/tests/subsurface-test.c
@@ -0,0 +1,306 @@
+/*
+ * Copyright © 2012 Collabora, Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <string.h>
+
+#include "weston-test-client-helper.h"
+
+#define NUM_SUBSURFACES 3
+
+struct compound_surface {
+	struct wl_subcompositor *subco;
+	struct wl_surface *parent;
+	struct wl_surface *child[NUM_SUBSURFACES];
+	struct wl_subsurface *sub[NUM_SUBSURFACES];
+};
+
+static struct wl_subcompositor *
+get_subcompositor(struct client *client)
+{
+	struct global *g;
+	struct global *global_sub = NULL;
+	struct wl_subcompositor *sub;
+
+	wl_list_for_each(g, &client->global_list, link) {
+		if (strcmp(g->interface, "wl_subcompositor"))
+			continue;
+
+		if (global_sub)
+			assert(0 && "multiple wl_subcompositor objects");
+
+		global_sub = g;
+	}
+
+	assert(global_sub && "no wl_subcompositor found");
+
+	assert(global_sub->version == 1);
+
+	sub = wl_registry_bind(client->wl_registry, global_sub->name,
+			       &wl_subcompositor_interface, 1);
+	assert(sub);
+
+	return sub;
+}
+
+static void
+populate_compound_surface(struct compound_surface *com, struct client *client)
+{
+	int i;
+
+	com->subco = get_subcompositor(client);
+
+	com->parent = wl_compositor_create_surface(client->wl_compositor);
+
+	for (i = 0; i < NUM_SUBSURFACES; i++) {
+		com->child[i] =
+			wl_compositor_create_surface(client->wl_compositor);
+		com->sub[i] =
+			wl_subcompositor_get_subsurface(com->subco,
+							com->child[i],
+							com->parent);
+	}
+}
+
+TEST(test_subsurface_basic_protocol)
+{
+	struct client *client;
+	struct compound_surface com1;
+	struct compound_surface com2;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	populate_compound_surface(&com1, client);
+	populate_compound_surface(&com2, client);
+
+	client_roundtrip(client);
+}
+
+TEST(test_subsurface_position_protocol)
+{
+	struct client *client;
+	struct compound_surface com;
+	int i;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	populate_compound_surface(&com, client);
+	for (i = 0; i < NUM_SUBSURFACES; i++)
+		wl_subsurface_set_position(com.sub[i],
+					   (i + 2) * 20, (i + 2) * 10);
+
+	client_roundtrip(client);
+}
+
+TEST(test_subsurface_placement_protocol)
+{
+	struct client *client;
+	struct compound_surface com;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	populate_compound_surface(&com, client);
+
+	wl_subsurface_place_above(com.sub[0], com.child[1]);
+	wl_subsurface_place_above(com.sub[1], com.parent);
+	wl_subsurface_place_below(com.sub[2], com.child[0]);
+	wl_subsurface_place_below(com.sub[1], com.parent);
+
+	client_roundtrip(client);
+}
+
+FAIL_TEST(test_subsurface_identical_link)
+{
+	struct client *client;
+	struct compound_surface com;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	populate_compound_surface(&com, client);
+
+	/* surface is already a subsurface */
+	wl_subcompositor_get_subsurface(com.subco, com.child[0], com.parent);
+
+	client_roundtrip(client);
+}
+
+FAIL_TEST(test_subsurface_change_link)
+{
+	struct client *client;
+	struct compound_surface com;
+	struct wl_surface *stranger;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	stranger = wl_compositor_create_surface(client->wl_compositor);
+	populate_compound_surface(&com, client);
+
+	/* surface is already a subsurface */
+	wl_subcompositor_get_subsurface(com.subco, com.child[0], stranger);
+
+	client_roundtrip(client);
+}
+
+FAIL_TEST(test_subsurface_nesting)
+{
+	struct client *client;
+	struct compound_surface com;
+	struct wl_surface *stranger;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	stranger = wl_compositor_create_surface(client->wl_compositor);
+	populate_compound_surface(&com, client);
+
+	/* parent is a sub-surface */
+	wl_subcompositor_get_subsurface(com.subco, stranger, com.child[0]);
+
+	client_roundtrip(client);
+}
+
+FAIL_TEST(test_subsurface_nesting_parent)
+{
+	struct client *client;
+	struct compound_surface com;
+	struct wl_surface *stranger;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	stranger = wl_compositor_create_surface(client->wl_compositor);
+	populate_compound_surface(&com, client);
+
+	/* surface is already a parent */
+	wl_subcompositor_get_subsurface(com.subco, com.parent, stranger);
+
+	client_roundtrip(client);
+}
+
+FAIL_TEST(test_subsurface_place_above_stranger)
+{
+	struct client *client;
+	struct compound_surface com;
+	struct wl_surface *stranger;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	stranger = wl_compositor_create_surface(client->wl_compositor);
+	populate_compound_surface(&com, client);
+
+	/* bad sibling */
+	wl_subsurface_place_above(com.sub[0], stranger);
+
+	client_roundtrip(client);
+}
+
+FAIL_TEST(test_subsurface_place_below_stranger)
+{
+	struct client *client;
+	struct compound_surface com;
+	struct wl_surface *stranger;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	stranger = wl_compositor_create_surface(client->wl_compositor);
+	populate_compound_surface(&com, client);
+
+	/* bad sibling */
+	wl_subsurface_place_below(com.sub[0], stranger);
+
+	client_roundtrip(client);
+}
+
+FAIL_TEST(test_subsurface_place_above_foreign)
+{
+	struct client *client;
+	struct compound_surface com1;
+	struct compound_surface com2;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	populate_compound_surface(&com1, client);
+	populate_compound_surface(&com2, client);
+
+	/* bad sibling */
+	wl_subsurface_place_above(com1.sub[0], com2.child[0]);
+
+	client_roundtrip(client);
+}
+
+FAIL_TEST(test_subsurface_place_below_foreign)
+{
+	struct client *client;
+	struct compound_surface com1;
+	struct compound_surface com2;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	populate_compound_surface(&com1, client);
+	populate_compound_surface(&com2, client);
+
+	/* bad sibling */
+	wl_subsurface_place_below(com1.sub[0], com2.child[0]);
+
+	client_roundtrip(client);
+}
+
+TEST(test_subsurface_destroy_protocol)
+{
+	struct client *client;
+	struct compound_surface com;
+
+	client = client_create(100, 50, 123, 77);
+	assert(client);
+
+	populate_compound_surface(&com, client);
+
+	/* not needed */
+	wl_subcompositor_destroy(com.subco);
+
+	/* no protocol involved */
+	wl_subsurface_destroy(com.sub[0]);
+
+	/* destroy: child, parent */
+	wl_surface_destroy(com.child[1]);
+	wl_surface_destroy(com.parent);
+
+	/* destroy: parent, child */
+	wl_surface_destroy(com.child[2]);
+
+	/* destroy: sub, child */
+	wl_surface_destroy(com.child[0]);
+
+	/* 2x destroy: child, sub */
+	wl_subsurface_destroy(com.sub[2]);
+	wl_subsurface_destroy(com.sub[1]);
+
+	client_roundtrip(client);
+}
-- 
1.7.8.6



More information about the wayland-devel mailing list