[PATCH 3/3 v3] tests: Add a test for global filter

Olivier Fourdan ofourdan at redhat.com
Mon Aug 8 08:10:52 UTC 2016


Test if the global filter is effectively filtering out the global when
the filter returns false.

Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
---
 v3: split out as its own commit

 tests/display-test.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/tests/display-test.c b/tests/display-test.c
index 17956db..3679772 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -125,6 +125,7 @@ struct handler_info {
 	struct wl_seat *seat;
 	uint32_t bind_version;
 	bool use_unversioned;
+	bool has_data_offer;
 };
 
 static void
@@ -145,6 +146,8 @@ registry_handle_globals(void *data, struct wl_registry *registry,
 			hi->seat = wl_registry_bind(registry, id,
 						    &wl_seat_interface, ver);
 		assert(hi->seat);
+	} else if (strcmp(intf, "wl_data_offer") == 0) {
+		hi->has_data_offer = true;
 	}
 }
 
@@ -926,3 +929,58 @@ TEST(error_on_destroyed_object)
 	display_resume(d);
 	display_destroy(d);
 }
+
+static bool
+global_filter(const struct wl_client *client,
+		      const struct wl_global *global,
+		      void *data)
+{
+	/* Hide the wl_data_offer interface */
+	if (wl_global_get_interface(global) == &wl_data_offer_interface)
+		return false;
+
+	/* Show all the others */
+	return true;
+}
+
+static void
+bind_data_offer(struct wl_client *client, void *data,
+		uint32_t vers, uint32_t id)
+{
+	struct display *d = data;
+	struct client_info *ci;
+	struct wl_resource *res;
+
+	ci = find_client_info(d, client);
+	assert(ci);
+
+	res = wl_resource_create(client, &wl_data_offer_interface, vers, id);
+	assert(res);
+}
+
+TEST(filter)
+{
+	struct handler_info hi;
+	struct display *d;
+	struct wl_global *g1, *g2;
+
+	d = display_create();
+
+	g1 = wl_global_create(d->wl_display, &wl_seat_interface,
+			      1, d, bind_seat);
+	g2 = wl_global_create(d->wl_display, &wl_data_offer_interface,
+			      1, d, bind_data_offer);
+	wl_display_set_filter_global(d->wl_display, global_filter, NULL);
+
+	hi.has_data_offer = false;
+	client_create(d, seat_version, &hi);
+	assert(hi.seat != NULL);
+	assert(hi.has_data_offer != true);
+
+	display_run(d);
+
+	wl_global_destroy(g1);
+	wl_global_destroy(g2);
+
+	display_destroy(d);
+}
-- 
2.7.4



More information about the wayland-devel mailing list