[PATCH 3/3 v4] tests: Add a test for global filter
Olivier Fourdan
ofourdan at redhat.com
Tue Aug 16 08:38:19 UTC 2016
Oops, before anyone waste dome time on this, the latest iteration of this patch is wrong, if the global is hidden it won;t be listed so the last test does nothing...
I'll come up with something better shortly, hopefully...
Sorry
Olivier
----- Original Message -----
> 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
> v4: Follow up on Jonas' comments:
> assert(hi.has_data_offer == false) instead of assert(hi.has_data_offer
> != true)
> Add a test for an illegal bind (bind on hidden global)
>
> tests/display-test.c | 110
> +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 110 insertions(+)
>
> diff --git a/tests/display-test.c b/tests/display-test.c
> index 0c4df16..07f63e4 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,110 @@ 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(filtered_global_is_hidden)
> +{
> + 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_global_filter(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 == false);
> +
> + display_run(d);
> +
> + wl_global_destroy(g1);
> + wl_global_destroy(g2);
> +
> + display_destroy(d);
> +}
> +
> +static void
> +registry_handle_globals2(void *data, struct wl_registry *registry,
> + uint32_t id, const char *intf, uint32_t ver)
> +{
> + void *ptr;
> +
> + /* Try to bind to the hidden wl_data_offer interface, if should fail */
> + if (strcmp (intf, "wl_data_offer") == 0) {
> + ptr = wl_registry_bind(registry, id, &wl_data_offer_interface, ver);
> + assert(ptr == NULL);
> + }
> +}
> +
> +static const struct wl_registry_listener registry_listener2 = {
> + registry_handle_globals2,
> + NULL
> +};
> +
> +static void
> +get_data_offer(void *data)
> +{
> + struct client *c = client_connect();
> + struct wl_registry *registry;
> +
> + registry = wl_display_get_registry(c->wl_display);
> + wl_registry_add_listener(registry, ®istry_listener2, data);
> + wl_display_roundtrip(c->wl_display);
> +
> + wl_registry_destroy(registry);
> + client_disconnect_nocheck(c);
> +}
> +
> +TEST(bind_fails_on_filtered_global)
> +{
> + struct display *d;
> + struct wl_global *g;
> +
> + d = display_create();
> +
> + g = wl_global_create(d->wl_display, &wl_data_offer_interface,
> + 1, d, bind_data_offer);
> + wl_display_set_global_filter(d->wl_display, global_filter, NULL);
> +
> + client_create_noarg(d, get_data_offer);
> +
> + display_run(d);
> +
> + wl_global_destroy(g);
> +
> + display_destroy(d);
> +}
> --
> 2.7.4
>
>
More information about the wayland-devel
mailing list