[PATCH wayland v3] tests: Test proxy versions

Derek Foreman derekf at osg.samsung.com
Fri Jan 15 11:11:24 PST 2016


Add a test that confirms that proxy versions are always 0 for display
and correct otherwise.

Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
---
Changes from previous version:
Test now attemps to mimic behaviour of clients built with old headers

 tests/display-test.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 120 insertions(+), 13 deletions(-)

diff --git a/tests/display-test.c b/tests/display-test.c
index 161a402..4948d57 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -35,6 +35,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <pthread.h>
+#include <stdbool.h>
 
 #include "wayland-private.h"
 #include "wayland-server.h"
@@ -100,16 +101,49 @@ TEST(tc_leaks_tests)
 	display_destroy(d);
 }
 
+/* This is how pre proxy-version registry binds worked,
+ * this should create a proxy that shares the display's
+ * version number: 0 */
+static void *
+old_registry_bind(struct wl_registry *wl_registry,
+		  uint32_t name,
+		  const struct wl_interface *interface,
+		  uint32_t version)
+{
+	struct wl_proxy *id;
+
+	id = wl_proxy_marshal_constructor(
+		(struct wl_proxy *) wl_registry, WL_REGISTRY_BIND,
+		interface, name, interface->name, version, NULL);
+
+	return (void *) id;
+}
+
+static uint32_t expected_version;
+
+struct handler_info {
+	struct wl_seat *seat;
+	bool use_unversioned;
+};
+
 static void
 registry_handle_globals(void *data, struct wl_registry *registry,
 			uint32_t id, const char *intf, uint32_t ver)
 {
-	struct wl_seat **seat = data;
+	struct handler_info *hi = data;
+
+	/* This is only for the proxy version test */
+	if (expected_version)
+		ver = expected_version;
 
 	if (strcmp(intf, "wl_seat") == 0) {
-		*seat = wl_registry_bind(registry, id,
-					 &wl_seat_interface, ver);
-		assert(*seat);
+		if (hi->use_unversioned)
+			hi->seat = old_registry_bind(registry, id,
+						     &wl_seat_interface, ver);
+		else
+			hi->seat = wl_registry_bind(registry, id,
+						    &wl_seat_interface, ver);
+		assert(hi->seat);
 	}
 }
 
@@ -119,19 +153,21 @@ static const struct wl_registry_listener registry_listener = {
 };
 
 static struct wl_seat *
-client_get_seat(struct client *c)
+client_get_seat(struct client *c, bool use_unversioned_bind)
 {
-	struct wl_seat *seat;
+	struct handler_info hi;
 	struct wl_registry *reg = wl_display_get_registry(c->wl_display);
 	assert(reg);
 
-	wl_registry_add_listener(reg, &registry_listener, &seat);
+	hi.seat = NULL;
+	hi.use_unversioned = use_unversioned_bind;
+	wl_registry_add_listener(reg, &registry_listener, &hi);
 	wl_display_roundtrip(c->wl_display);
-	assert(seat);
+	assert(hi.seat);
 
 	wl_registry_destroy(reg);
 
-	return seat;
+	return hi.seat;
 }
 
 static void
@@ -186,7 +222,7 @@ static void
 post_error_main(void)
 {
 	struct client *c = client_connect();
-	struct wl_seat *seat = client_get_seat(c);
+	struct wl_seat *seat = client_get_seat(c, false);
 
 	/* stop display so that it can post the error.
 	 * The function should return -1, because of the posted error */
@@ -230,7 +266,7 @@ static void
 post_error_main2(void)
 {
 	struct client *c = client_connect();
-	struct wl_seat *seat = client_get_seat(c);
+	struct wl_seat *seat = client_get_seat(c, false);
 
 	/* the error should not be posted for this client */
 	assert(stop_display(c, 2) >= 0);
@@ -243,7 +279,7 @@ static void
 post_error_main3(void)
 {
 	struct client *c = client_connect();
-	struct wl_seat *seat = client_get_seat(c);
+	struct wl_seat *seat = client_get_seat(c, false);
 
 	assert(stop_display(c, 2) == -1);
 	check_for_error(c, (struct wl_proxy *) seat);
@@ -314,7 +350,7 @@ static void
 post_nomem_main(void)
 {
 	struct client *c = client_connect();
-	struct wl_seat *seat = client_get_seat(c);
+	struct wl_seat *seat = client_get_seat(c, false);
 
 	assert(stop_display(c, 1) == -1);
 	assert(wl_display_get_error(c->wl_display) == ENOMEM);
@@ -609,3 +645,74 @@ TEST(threading_read_after_error_tst)
 
 	display_destroy(d);
 }
+
+static void
+check_seat_versions(struct wl_seat *seat, uint32_t ev)
+{
+	struct wl_pointer *pointer;
+
+	assert(wl_proxy_get_version((struct wl_proxy *) seat) == ev);
+	assert(wl_seat_get_version(seat) == ev);
+
+	pointer = wl_seat_get_pointer(seat);
+	assert(wl_pointer_get_version(pointer) == ev);
+	assert(wl_proxy_get_version((struct wl_proxy *) pointer) == ev);
+	wl_proxy_destroy((struct wl_proxy *) pointer);
+}
+
+/* Normal client with proxy versions available. */
+static void
+seat_version_1(void)
+{
+	struct client *c = client_connect();
+	struct wl_seat *seat;
+
+	/* display proxy should always be version 0 */
+	assert(wl_proxy_get_version((struct wl_proxy *) c->wl_display) == 0);
+
+	seat = client_get_seat(c, false);
+	check_seat_versions(seat, expected_version);
+	wl_proxy_destroy((struct wl_proxy *) seat);
+
+	client_disconnect_nocheck(c);
+}
+
+/* Mimic an old client compiled with pre-proxy version headers */
+static void
+seat_version_2(void)
+{
+	struct client *c = client_connect();
+	struct wl_seat *seat;
+
+	/* display proxy should always be version 0 */
+	assert(wl_proxy_get_version((struct wl_proxy *) c->wl_display) == 0);
+
+	seat = client_get_seat(c, true);
+	check_seat_versions(seat, 0);
+	wl_proxy_destroy((struct wl_proxy *) seat);
+
+	client_disconnect_nocheck(c);
+}
+
+TEST(versions)
+{
+	struct display *d = display_create();
+	struct wl_global *global;
+	int i;
+
+	global = wl_global_create(d->wl_display, &wl_seat_interface,
+				  5, d, bind_seat);
+
+	for (i = 1; i <= 5; i++) {
+		expected_version = i;
+
+		client_create(d, seat_version_1);
+		client_create(d, seat_version_2);
+	}
+
+	display_run(d);
+
+	wl_global_destroy(global);
+
+	display_destroy(d);
+}
-- 
2.7.0.rc3



More information about the wayland-devel mailing list