[mutter] tests/stacking: Add workspace management commands



commit ed7a9af62a197c32895605f8f534a783a51a08d6
Author: Sebastian Wick <sebastian wick redhat com>
Date:   Thu Jul 7 15:47:10 2022 +0200

    tests/stacking: Add workspace management commands
    
    New commands to set the number of workspaces, activate a workspace, with
    and without focus, move windows to specific workspaces, and check the
    stacking on a specific workspace.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2489>

 src/core/meta-workspace-manager-private.h   |   1 +
 src/tests/meson.build                       |   2 +
 src/tests/stacking/workspace-basic.metatest |  41 +++++++++
 src/tests/stacking/workspace-test.metatest  |  30 +++++++
 src/tests/test-runner.c                     | 132 ++++++++++++++++++++++++++--
 5 files changed, 199 insertions(+), 7 deletions(-)
---
diff --git a/src/core/meta-workspace-manager-private.h b/src/core/meta-workspace-manager-private.h
index 261c4d47ca..fec0270240 100644
--- a/src/core/meta-workspace-manager-private.h
+++ b/src/core/meta-workspace-manager-private.h
@@ -89,6 +89,7 @@ void meta_workspace_manager_workspace_switched (MetaWorkspaceManager *workspace_
                                                 int                   to,
                                                 MetaMotionDirection   direction);
 
+META_EXPORT_TEST
 void meta_workspace_manager_update_num_workspaces (MetaWorkspaceManager *workspace_manager,
                                                    guint32               timestamp,
                                                    int                   new_num);
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 99efa984e9..9c26e33481 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -440,6 +440,8 @@ stacking_tests = [
   'map-fixed-size',
   'client-resize-respect-constraints',
   'map-on-hotplug',
+  'workspace-basic',
+  'workspace-test',
 ]
 
 foreach stacking_test: stacking_tests
diff --git a/src/tests/stacking/workspace-basic.metatest b/src/tests/stacking/workspace-basic.metatest
new file mode 100644
index 0000000000..a84c0c52ca
--- /dev/null
+++ b/src/tests/stacking/workspace-basic.metatest
@@ -0,0 +1,41 @@
+num_workspaces 2
+activate_workspace 1
+
+new_client 1 wayland
+create 1/1
+show 1/1
+create 1/2
+show 1/2
+wait
+assert_stacking 1/1 1/2
+assert_stacking_workspace 1 1/1 1/2
+assert_stacking_workspace 0
+
+activate_workspace 0
+wait
+assert_stacking 1/1 1/2
+assert_stacking_workspace 1 1/1 1/2
+assert_stacking_workspace 0
+
+activate_workspace_with_focus 0 1/1
+wait
+assert_stacking 1/2 1/1
+assert_stacking_workspace 1 1/2 1/1
+assert_stacking_workspace 0
+
+window_to_workspace 1/2 0
+wait
+assert_stacking 1/2 1/1
+assert_stacking_workspace 1 1/1
+assert_stacking_workspace 0 1/2
+
+activate_workspace 0
+wait
+new_client 2 wayland
+create 2/1
+show 2/1
+wait
+
+assert_stacking 1/1 1/2 2/1
+assert_stacking_workspace 1 1/1
+assert_stacking_workspace 0 1/2 2/1
\ No newline at end of file
diff --git a/src/tests/stacking/workspace-test.metatest b/src/tests/stacking/workspace-test.metatest
new file mode 100644
index 0000000000..c119675460
--- /dev/null
+++ b/src/tests/stacking/workspace-test.metatest
@@ -0,0 +1,30 @@
+num_workspaces 2
+activate_workspace 0
+
+new_client 1 wayland
+create 1/1
+show 1/1
+create 1/2
+show 1/2
+wait
+assert_stacking_workspace 0 1/1 1/2
+assert_stacking_workspace 1
+
+activate_workspace 1
+new_client 2 wayland
+create 2/1
+show 2/1
+wait
+assert_stacking_workspace 0 1/1 1/2
+assert_stacking_workspace 1 2/1
+
+create 1/3
+show 1/3
+wait
+assert_stacking_workspace 0 1/1 1/2
+assert_stacking_workspace 1 2/1 1/3
+
+activate_workspace_with_focus 0 1/1
+wait
+assert_stacking_workspace 0 1/2 1/1
+assert_stacking_workspace 1 2/1 1/3
\ No newline at end of file
diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c
index 9a9fb96310..0553e251d3 100644
--- a/src/tests/test-runner.c
+++ b/src/tests/test-runner.c
@@ -29,7 +29,7 @@
 #include "meta-test/meta-context-test.h"
 #include "meta/util.h"
 #include "meta/window.h"
-#include "meta/meta-workspace-manager.h"
+#include "core/meta-workspace-manager-private.h"
 #include "tests/meta-test-utils.h"
 #include "ui/ui.h"
 #include "wayland/meta-wayland.h"
@@ -224,10 +224,11 @@ test_case_parse_window_id (TestCase        *test,
 }
 
 static gboolean
-test_case_assert_stacking (TestCase *test,
-                           char    **expected_windows,
-                           int       n_expected_windows,
-                           GError  **error)
+test_case_assert_stacking (TestCase       *test,
+                           char          **expected_windows,
+                           int             n_expected_windows,
+                           MetaWorkspace  *workspace,
+                           GError        **error)
 {
   MetaDisplay *display = meta_get_display ();
   guint64 *windows;
@@ -240,6 +241,10 @@ test_case_assert_stacking (TestCase *test,
   for (i = 0; i < n_windows; i++)
     {
       MetaWindow *window = meta_display_lookup_stack_id (display, windows[i]);
+
+      if (workspace && !meta_window_located_on_workspace (window, workspace))
+        continue;
+
       if (window != NULL && window->title)
         {
           /* See comment in meta_ui_new() about why the dummy window for GTK+ theming
@@ -893,7 +898,7 @@ test_case_do (TestCase *test,
     }
   else if (strcmp (argv[0], "assert_stacking") == 0)
     {
-      if (!test_case_assert_stacking (test, argv + 1, argc - 1, error))
+      if (!test_case_assert_stacking (test, argv + 1, argc - 1, NULL, error))
         return FALSE;
 
       if (!test_case_check_xserver_stacking (test, error))
@@ -1030,6 +1035,119 @@ test_case_do (TestCase *test,
                                      crtc_mode_info->refresh_rate);
       meta_monitor_manager_reload (monitor_manager);
     }
+  else if (strcmp (argv[0], "num_workspaces") == 0)
+    {
+      if (argc != 2)
+        BAD_COMMAND("usage: %s <num>", argv[0]);
+
+      MetaDisplay *display = meta_get_display ();
+      MetaWorkspaceManager *workspace_manager =
+        meta_display_get_workspace_manager (display);
+      uint32_t timestamp = meta_display_get_current_time_roundtrip (display);
+      int num = atoi (argv[1]);
+      meta_workspace_manager_update_num_workspaces (workspace_manager,
+                                                    timestamp, num);
+    }
+  else if (strcmp (argv[0], "activate_workspace") == 0)
+    {
+      if (argc != 2)
+        BAD_COMMAND("usage: %s <workspace-index>", argv[0]);
+
+      MetaDisplay *display = meta_get_display ();
+      MetaWorkspaceManager *workspace_manager =
+        meta_display_get_workspace_manager (display);
+
+      int index = atoi (argv[1]);
+      if (index >= meta_workspace_manager_get_n_workspaces (workspace_manager))
+        return FALSE;
+
+      MetaWorkspace *workspace =
+        meta_workspace_manager_get_workspace_by_index (workspace_manager,
+                                                       index);
+      uint32_t timestamp = meta_display_get_current_time_roundtrip (display);
+      meta_workspace_activate (workspace, timestamp);
+    }
+  else if (strcmp (argv[0], "activate_workspace_with_focus") == 0)
+    {
+      if (argc != 3)
+        BAD_COMMAND("usage: %s <workspace-index> <window-id>", argv[0]);
+
+      MetaTestClient *client;
+      const char *window_id;
+      if (!test_case_parse_window_id (test, argv[2], &client, &window_id, error))
+        return FALSE;
+
+      MetaWindow *window;
+      window = meta_test_client_find_window (client, window_id, error);
+      if (!window)
+        return FALSE;
+
+      MetaDisplay *display = meta_get_display ();
+      MetaWorkspaceManager *workspace_manager =
+        meta_display_get_workspace_manager (display);
+
+      int index = atoi (argv[1]);
+      if (index >= meta_workspace_manager_get_n_workspaces (workspace_manager))
+        return FALSE;
+
+      MetaWorkspace *workspace =
+        meta_workspace_manager_get_workspace_by_index (workspace_manager,
+                                                       index);
+      uint32_t timestamp = meta_display_get_current_time_roundtrip (display);
+      meta_workspace_activate_with_focus (workspace, window, timestamp);
+    }
+  else if (strcmp (argv[0], "assert_stacking_workspace") == 0)
+    {
+      if (argc < 2)
+        BAD_COMMAND("usage: %s <workspace-index> [<window-id1> ...]", argv[0]);
+
+      MetaDisplay *display = meta_get_display ();
+      MetaWorkspaceManager *workspace_manager =
+        meta_display_get_workspace_manager (display);
+
+      int index = atoi (argv[1]);
+      if (index >= meta_workspace_manager_get_n_workspaces (workspace_manager))
+        return FALSE;
+
+      MetaWorkspace *workspace =
+        meta_workspace_manager_get_workspace_by_index (workspace_manager,
+                                                       index);
+
+      if (!test_case_assert_stacking (test, argv + 2, argc - 2, workspace, error))
+        return FALSE;
+
+      if (!test_case_check_xserver_stacking (test, error))
+        return FALSE;
+    }
+  else if (strcmp (argv[0], "window_to_workspace") == 0)
+    {
+      if (argc != 3)
+        BAD_COMMAND("usage: %s <window-id> <workspace-index>", argv[0]);
+
+      MetaTestClient *client;
+      const char *window_id;
+      if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error))
+        return FALSE;
+
+      MetaWindow *window;
+      window = meta_test_client_find_window (client, window_id, error);
+      if (!window)
+        return FALSE;
+
+      MetaDisplay *display = meta_get_display ();
+      MetaWorkspaceManager *workspace_manager =
+        meta_display_get_workspace_manager (display);
+
+      int index = atoi (argv[2]);
+      if (index >= meta_workspace_manager_get_n_workspaces (workspace_manager))
+        return FALSE;
+
+      MetaWorkspace *workspace =
+        meta_workspace_manager_get_workspace_by_index (workspace_manager,
+                                                       index);
+
+      meta_window_change_workspace (window, workspace);
+    }
   else
     {
       BAD_COMMAND("Unknown command %s", argv[0]);
@@ -1061,7 +1179,7 @@ test_case_destroy (TestCase *test,
   if (!test_case_wait (test, error))
     return FALSE;
 
-  if (!test_case_assert_stacking (test, NULL, 0, error))
+  if (!test_case_assert_stacking (test, NULL, 0, NULL, error))
     return FALSE;
 
   g_hash_table_iter_init (&iter, test->clients);


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