tests: remove static data from presentation
authorPekka Paalanen <pekka.paalanen@collabora.com>
Wed, 13 Nov 2019 13:50:51 +0000 (15:50 +0200)
committerDaniel Stone <daniel@fooishbar.org>
Thu, 21 Nov 2019 16:24:01 +0000 (16:24 +0000)
While get_presentation() will only ever be called once (making the caching of
the return value moot), it is good to stop using the static variable as it
would cause surprising problems if anyone adds more tests here and runs it
under the new test harness.

It was leaked before and continues to be so.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
tests/presentation-test.c

index f6ffe4805dca8ccf71f370b914f1b7710eb3e8a1..a4f8c87fc501642e62e9c2aed5c56a8fd99331a7 100644 (file)
@@ -43,10 +43,7 @@ get_presentation(struct client *client)
 {
        struct global *g;
        struct global *global_pres = NULL;
-       static struct wp_presentation *pres;
-
-       if (pres)
-               return pres;
+       struct wp_presentation *pres;
 
        wl_list_for_each(g, &client->global_list, link) {
                if (strcmp(g->interface, wp_presentation_interface.name))
@@ -137,13 +134,15 @@ static const struct wp_presentation_feedback_listener feedback_listener = {
 };
 
 static struct feedback *
-feedback_create(struct client *client, struct wl_surface *surface)
+feedback_create(struct client *client,
+               struct wl_surface *surface,
+               struct wp_presentation *pres)
 {
        struct feedback *fb;
 
        fb = xzalloc(sizeof *fb);
        fb->client = client;
-       fb->obj = wp_presentation_feedback(get_presentation(client), surface);
+       fb->obj = wp_presentation_feedback(pres, surface);
        wp_presentation_feedback_add_listener(fb->obj, &feedback_listener, fb);
 
        return fb;
@@ -215,13 +214,15 @@ TEST(test_presentation_feedback_simple)
 {
        struct client *client;
        struct feedback *fb;
+       struct wp_presentation *pres;
 
        client = create_client_and_test_surface(100, 50, 123, 77);
        assert(client);
+       pres = get_presentation(client);
 
        wl_surface_attach(client->surface->wl_surface,
                          client->surface->buffer->proxy, 0, 0);
-       fb = feedback_create(client, client->surface->wl_surface);
+       fb = feedback_create(client, client->surface->wl_surface, pres);
        wl_surface_damage(client->surface->wl_surface, 0, 0, 100, 100);
        wl_surface_commit(client->surface->wl_surface);