[mutter] tests/wayland/subsurfaces: Use helper to manage display



commit d58bd948a830ca8b14c248f00616bb5d3cf60cda
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Wed May 11 22:50:58 2022 +0200

    tests/wayland/subsurfaces: Use helper to manage display
    
    Adds a _free() function since the display is reopened multiple times and
    cleaned up in between.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2416>

 .../wayland-test-clients/invalid-subsurfaces.c     | 75 +++++-----------------
 .../wayland-test-client-utils.c                    |  7 ++
 .../wayland-test-client-utils.h                    |  3 +
 3 files changed, 25 insertions(+), 60 deletions(-)
---
diff --git a/src/tests/wayland-test-clients/invalid-subsurfaces.c 
b/src/tests/wayland-test-clients/invalid-subsurfaces.c
index f186dfbc96..843bef1fa1 100644
--- a/src/tests/wayland-test-clients/invalid-subsurfaces.c
+++ b/src/tests/wayland-test-clients/invalid-subsurfaces.c
@@ -26,66 +26,21 @@
 
 #include "xdg-shell-client-protocol.h"
 
-static struct wl_display *display;
-static struct wl_registry *registry;
-static struct wl_compositor *compositor;
-static struct wl_subcompositor *subcompositor;
-
-static void
-handle_registry_global (void               *data,
-                        struct wl_registry *registry,
-                        uint32_t            id,
-                        const char         *interface,
-                        uint32_t            version)
-{
-  if (strcmp (interface, "wl_compositor") == 0)
-    {
-      compositor = wl_registry_bind (registry, id, &wl_compositor_interface, 1);
-    }
-  else if (strcmp (interface, "wl_subcompositor") == 0)
-    {
-      subcompositor = wl_registry_bind (registry,
-                                        id, &wl_subcompositor_interface, 1);
-    }
-}
-
-static void
-handle_registry_global_remove (void               *data,
-                               struct wl_registry *registry,
-                               uint32_t            name)
-{
-}
-
-static const struct wl_registry_listener registry_listener = {
-  handle_registry_global,
-  handle_registry_global_remove
-};
+static WaylandDisplay *display;
 
 static void
 connect_to_display (void)
 {
   g_assert_null (display);
-  g_assert_null (registry);
-  g_assert_null (subcompositor);
 
-  display = wl_display_connect (NULL);
+  display = wayland_display_new (WAYLAND_DISPLAY_CAPABILITY_NONE);
   g_assert_nonnull (display);
-  registry = wl_display_get_registry (display);
-  g_assert_nonnull (registry);
-  wl_registry_add_listener (registry, &registry_listener, NULL);
-
-  g_assert_cmpint (wl_display_roundtrip (display), !=, -1);
-
-  g_assert_nonnull (subcompositor);
 }
 
 static void
 clean_up_display (void)
 {
-  wl_display_disconnect (display);
-  display = NULL;
-  registry = NULL;
-  subcompositor = NULL;
+  g_clear_pointer (&display, wayland_display_free);
 }
 
 static void
@@ -98,21 +53,21 @@ test_circular_subsurfaces1 (void)
 
   connect_to_display ();
 
-  surface1 = wl_compositor_create_surface (compositor);
-  surface2 = wl_compositor_create_surface (compositor);
+  surface1 = wl_compositor_create_surface (display->compositor);
+  surface2 = wl_compositor_create_surface (display->compositor);
   g_assert_nonnull (surface1);
   g_assert_nonnull (surface2);
 
-  subsurface1 = wl_subcompositor_get_subsurface (subcompositor,
+  subsurface1 = wl_subcompositor_get_subsurface (display->subcompositor,
                                                  surface1,
                                                  surface2);
-  subsurface2 = wl_subcompositor_get_subsurface (subcompositor,
+  subsurface2 = wl_subcompositor_get_subsurface (display->subcompositor,
                                                  surface2,
                                                  surface1);
   g_assert_nonnull (subsurface1);
   g_assert_nonnull (subsurface2);
 
-  g_assert_cmpint (wl_display_roundtrip (display), ==, -1);
+  g_assert_cmpint (wl_display_roundtrip (display->display), ==, -1);
 
   clean_up_display ();
 }
@@ -129,27 +84,27 @@ test_circular_subsurfaces2 (void)
 
   connect_to_display ();
 
-  surface1 = wl_compositor_create_surface (compositor);
-  surface2 = wl_compositor_create_surface (compositor);
-  surface3 = wl_compositor_create_surface (compositor);
+  surface1 = wl_compositor_create_surface (display->compositor);
+  surface2 = wl_compositor_create_surface (display->compositor);
+  surface3 = wl_compositor_create_surface (display->compositor);
   g_assert_nonnull (surface1);
   g_assert_nonnull (surface2);
   g_assert_nonnull (surface3);
 
-  subsurface1 = wl_subcompositor_get_subsurface (subcompositor,
+  subsurface1 = wl_subcompositor_get_subsurface (display->subcompositor,
                                                  surface1,
                                                  surface2);
-  subsurface2 = wl_subcompositor_get_subsurface (subcompositor,
+  subsurface2 = wl_subcompositor_get_subsurface (display->subcompositor,
                                                  surface2,
                                                  surface3);
-  subsurface3 = wl_subcompositor_get_subsurface (subcompositor,
+  subsurface3 = wl_subcompositor_get_subsurface (display->subcompositor,
                                                  surface3,
                                                  surface1);
   g_assert_nonnull (subsurface1);
   g_assert_nonnull (subsurface2);
   g_assert_nonnull (subsurface3);
 
-  g_assert_cmpint (wl_display_roundtrip (display), ==, -1);
+  g_assert_cmpint (wl_display_roundtrip (display->display), ==, -1);
 
   clean_up_display ();
 }
diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.c 
b/src/tests/wayland-test-clients/wayland-test-client-utils.c
index 408f957b81..7485e5868e 100644
--- a/src/tests/wayland-test-clients/wayland-test-client-utils.c
+++ b/src/tests/wayland-test-clients/wayland-test-client-utils.c
@@ -181,3 +181,10 @@ wayland_display_new (WaylandDisplayCapabilities capabilities)
 
   return display;
 }
+
+void
+wayland_display_free (WaylandDisplay *display)
+{
+  wl_display_disconnect (display->display);
+  g_free (display);
+}
diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.h 
b/src/tests/wayland-test-clients/wayland-test-client-utils.h
index b7dfe4da79..f7f213f718 100644
--- a/src/tests/wayland-test-clients/wayland-test-client-utils.h
+++ b/src/tests/wayland-test-clients/wayland-test-client-utils.h
@@ -9,6 +9,7 @@
 
 typedef enum _WaylandDisplayCapabilities
 {
+  WAYLAND_DISPLAY_CAPABILITY_NONE = 0,
   WAYLAND_DISPLAY_CAPABILITY_TEST_DRIVER = 1 << 0,
 } WaylandDisplayCapabilities;
 
@@ -29,4 +30,6 @@ int create_anonymous_file (off_t size);
 
 WaylandDisplay * wayland_display_new (WaylandDisplayCapabilities capabilities);
 
+void wayland_display_free (WaylandDisplay *display);
+
 #endif /* WAYLAND_TEST_CLIENT_UTILS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]