[mutter] tests: Add helper for creating virtual test monitors



commit 195766cb69dfbf759a25dbac901b1ed160b7cd5f
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Fri Jan 28 00:12:59 2022 +0100

    tests: Add helper for creating virtual test monitors
    
    This uses virtual monitors in the headless backend, in contrast to the
    ones used by the monitor configuration tests which use the nseted
    backend.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2262>

 src/tests/meta-test-utils.c    | 30 ++++++++++++++++++++++++++++++
 src/tests/meta-test-utils.h    |  6 ++++++
 src/tests/wayland-unit-tests.c | 19 ++++---------------
 3 files changed, 40 insertions(+), 15 deletions(-)
---
diff --git a/src/tests/meta-test-utils.c b/src/tests/meta-test-utils.c
index 6be07af04b..c70886a6b8 100644
--- a/src/tests/meta-test-utils.c
+++ b/src/tests/meta-test-utils.c
@@ -26,6 +26,7 @@
 #include <X11/Xlib-xcb.h>
 
 #include "backends/meta-monitor-config-store.h"
+#include "backends/meta-virtual-monitor.h"
 #include "core/display-private.h"
 #include "core/window-private.h"
 #include "meta-test/meta-context-test.h"
@@ -645,3 +646,32 @@ meta_wait_for_paint (MetaContext *context)
     g_main_context_iteration (NULL, TRUE);
   g_signal_handler_disconnect (stage, handler_id);
 }
+
+MetaVirtualMonitor *
+meta_create_test_monitor (MetaContext *context,
+                          int          width,
+                          int          height,
+                          float        refresh_rate)
+{
+  MetaBackend *backend = meta_context_get_backend (context);
+  MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend);
+  g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL;
+  g_autoptr (GError) error = NULL;
+  static int serial_count = 0x10000;
+  g_autofree char *serial = NULL;
+  MetaVirtualMonitor *virtual_monitor;
+
+  serial = g_strdup_printf ("0x%x", serial_count++);
+  monitor_info = meta_virtual_monitor_info_new (width, height, refresh_rate,
+                                                "MetaTestVendor",
+                                                "MetaVirtualMonitor",
+                                                serial);
+  virtual_monitor = meta_monitor_manager_create_virtual_monitor (monitor_manager,
+                                                                 monitor_info,
+                                                                 &error);
+  if (!virtual_monitor)
+    g_error ("Failed to create virtual monitor: %s", error->message);
+  meta_monitor_manager_reload (monitor_manager);
+
+  return virtual_monitor;
+}
diff --git a/src/tests/meta-test-utils.h b/src/tests/meta-test-utils.h
index 2a42fa641c..423f96c491 100644
--- a/src/tests/meta-test-utils.h
+++ b/src/tests/meta-test-utils.h
@@ -121,4 +121,10 @@ void meta_set_custom_monitor_config (MetaBackend            *backend,
 META_EXPORT
 void meta_wait_for_paint (MetaContext *context);
 
+META_EXPORT
+MetaVirtualMonitor * meta_create_test_monitor (MetaContext *context,
+                                               int          width,
+                                               int          height,
+                                               float        refresh_rate);
+
 #endif /* TEST_UTILS_H */
diff --git a/src/tests/wayland-unit-tests.c b/src/tests/wayland-unit-tests.c
index f7e201e04e..185d3cc6a9 100644
--- a/src/tests/wayland-unit-tests.c
+++ b/src/tests/wayland-unit-tests.c
@@ -24,6 +24,7 @@
 #include "core/display-private.h"
 #include "core/window-private.h"
 #include "meta-test/meta-context-test.h"
+#include "tests/meta-test-utils.h"
 #include "tests/meta-wayland-test-driver.h"
 #include "tests/meta-wayland-test-utils.h"
 #include "wayland/meta-wayland-surface.h"
@@ -365,30 +366,18 @@ toplevel_activation (void)
 static void
 on_before_tests (void)
 {
-  MetaBackend *backend = meta_context_get_backend (test_context);
-  MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend);
   MetaWaylandCompositor *compositor =
     meta_context_get_wayland_compositor (test_context);
-  g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL;
-  g_autoptr (GError) error = NULL;
 
   test_driver = meta_wayland_test_driver_new (compositor);
-
-  monitor_info = meta_virtual_monitor_info_new (400, 400, 60.0,
-                                                "MetaTestVendor",
-                                                "MetaVirtualMonitor",
-                                                "0x1234");
-  virtual_monitor = meta_monitor_manager_create_virtual_monitor (monitor_manager,
-                                                                 monitor_info,
-                                                                 &error);
-  if (!virtual_monitor)
-    g_error ("Failed to create virtual monitor: %s", error->message);
-  meta_monitor_manager_reload (monitor_manager);
+  virtual_monitor = meta_create_test_monitor (test_context,
+                                              400, 400, 60.0);
 }
 
 static void
 on_after_tests (void)
 {
+  g_clear_object (&test_driver);
   g_clear_object (&virtual_monitor);
 }
 


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