[mutter/wip/carlosg/move-pointer-onscreen: 7/7] tests: Add test for constraining pointer on hotplug




commit 9d3a0d7d7b7b42861fd46820a635a178d4a78eb6
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Fri Jan 14 22:16:46 2022 +0100

    tests: Add test for constraining pointer on hotplug
    
    It tests that if we go from (x is the pointer cursor)
    
        +--------+
        |        |
        |     X  |
        +--------+
    
    to
                 +----------------+
                 |                |
                 |                |
        +--------+                |
        |        |                |
        |     X  |                |
        +--------+----------------+
    
    i.e. making sure that X ends up somewhere within the logical monitor
    region.

 src/backends/meta-backend-private.h              |   2 +
 src/tests/meson.build                            |  18 +++
 src/tests/monitor-configs/pointer-constraint.xml |  60 ++++++++++
 src/tests/native-pointer-constraints.c           | 145 +++++++++++++++++++++++
 4 files changed, 225 insertions(+)
---
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index 546c612e23..9d88d8a58e 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -127,6 +127,7 @@ MetaIdleManager * meta_backend_get_idle_manager (MetaBackend *backend);
 
 META_EXPORT_TEST
 MetaOrientationManager * meta_backend_get_orientation_manager (MetaBackend *backend);
+META_EXPORT_TEST
 MetaCursorTracker * meta_backend_get_cursor_tracker (MetaBackend *backend);
 MetaCursorRenderer * meta_backend_get_cursor_renderer_for_device (MetaBackend        *backend,
                                                                   ClutterInputDevice *device);
@@ -152,6 +153,7 @@ void meta_backend_finish_touch_sequence (MetaBackend          *backend,
                                          ClutterEventSequence *sequence,
                                          MetaSequenceState     state);
 
+META_EXPORT_TEST
 MetaLogicalMonitor * meta_backend_get_current_logical_monitor (MetaBackend *backend);
 
 struct xkb_keymap * meta_backend_get_keymap (MetaBackend *backend);
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 879b89e876..6f790f9f3d 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -222,6 +222,17 @@ if have_native_tests
     install_dir: mutter_installed_tests_libexecdir,
   )
 
+  pointer_constraints_tests = executable('mutter-native-pointer-constraints',
+    sources: [
+      'native-pointer-constraints.c',
+    ],
+    include_directories: tests_includes,
+    c_args: tests_c_args,
+    dependencies: libmutter_test_dep,
+    install: have_installed_tests,
+    install_dir: mutter_installed_tests_libexecdir,
+  )
+
   ref_test_sanity = executable('mutter-ref-test-sanity',
     sources: [
       'ref-test-sanity.c',
@@ -373,6 +384,13 @@ if have_native_tests
     timeout: 60,
   )
 
+  test('native-pointer-constraints', pointer_constraints_tests,
+    suite: ['core', 'mutter/native/input'],
+    env: test_env,
+    is_parallel: false,
+    timeout: 60,
+  )
+
   test('ref-test-sanity', ref_test_sanity,
     suite: ['core', 'mutter/ref-test/sanity'],
     env: test_env,
diff --git a/src/tests/monitor-configs/pointer-constraint.xml 
b/src/tests/monitor-configs/pointer-constraint.xml
new file mode 100644
index 0000000000..2e9709f030
--- /dev/null
+++ b/src/tests/monitor-configs/pointer-constraint.xml
@@ -0,0 +1,60 @@
+<monitors version="2">
+  <configuration>
+    <logicalmonitor>
+      <x>0</x>
+      <y>0</y>
+      <primary>yes</primary>
+      <monitor>
+       <monitorspec>
+         <connector>Meta-0</connector>
+         <vendor>MetaTestVendor</vendor>
+         <product>MetaVirtualMonitor</product>
+         <serial>0x1234</serial>
+       </monitorspec>
+       <mode>
+         <width>100</width>
+         <height>100</height>
+         <rate>60</rate>
+       </mode>
+      </monitor>
+    </logicalmonitor>
+  </configuration>
+
+  <configuration>
+    <logicalmonitor>
+      <x>0</x>
+      <y>100</y>
+      <primary>yes</primary>
+      <monitor>
+       <monitorspec>
+         <connector>Meta-0</connector>
+         <vendor>MetaTestVendor</vendor>
+         <product>MetaVirtualMonitor</product>
+         <serial>0x1234</serial>
+       </monitorspec>
+       <mode>
+         <width>100</width>
+         <height>100</height>
+         <rate>60</rate>
+       </mode>
+      </monitor>
+    </logicalmonitor>
+    <logicalmonitor>
+      <x>100</x>
+      <y>0</y>
+      <monitor>
+       <monitorspec>
+         <connector>Meta-1</connector>
+         <vendor>MetaTestVendor</vendor>
+         <product>MetaVirtualMonitor</product>
+         <serial>0x1235</serial>
+       </monitorspec>
+       <mode>
+         <width>200</width>
+         <height>200</height>
+         <rate>60</rate>
+       </mode>
+      </monitor>
+    </logicalmonitor>
+  </configuration>
+</monitors>
diff --git a/src/tests/native-pointer-constraints.c b/src/tests/native-pointer-constraints.c
new file mode 100644
index 0000000000..ca6746f974
--- /dev/null
+++ b/src/tests/native-pointer-constraints.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2021 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include "meta/meta-cursor-tracker.h"
+#include "backends/meta-monitor-config-manager.h"
+#include "backends/meta-virtual-monitor.h"
+#include "meta-test/meta-context-test.h"
+#include "meta/meta-backend.h"
+#include "tests/meta-test-utils.h"
+#include "tests/native-screen-cast.h"
+#include "tests/native-virtual-monitor.h"
+
+static MetaContext *test_context;
+
+static void
+run_test_client_command (MetaTestClient *client, ...)
+{
+  va_list vap;
+  GError *error = NULL;
+  gboolean retval;
+
+  va_start (vap, client);
+  retval = meta_test_client_dov (client, &error, vap);
+  va_end (vap);
+
+  if (!retval)
+    g_error ("Failed to execute client command: %s", error->message);
+}
+
+static void
+meta_test_warp_on_hotplug (void)
+{
+  MetaBackend *backend = meta_context_get_backend (test_context);
+  MetaMonitorManager *monitor_manager =
+    meta_backend_get_monitor_manager (backend);
+  g_autoptr (MetaVirtualMonitorInfo) monitor_info1 = NULL;
+  g_autoptr (MetaVirtualMonitorInfo) monitor_info2 = NULL;
+  MetaVirtualMonitor *virtual_monitor1;
+  MetaVirtualMonitor *virtual_monitor2;
+  ClutterSeat *seat;
+  g_autoptr (ClutterVirtualInputDevice) virtual_pointer = NULL;
+  MetaTestClient *test_client;
+  GError *error = NULL;
+  graphene_point_t coords;
+
+  seat = meta_backend_get_default_seat (backend);
+  virtual_pointer = clutter_seat_create_virtual_device (seat,
+                                                        CLUTTER_POINTER_DEVICE);
+
+  meta_set_custom_monitor_config (backend, "pointer-constraint.xml");
+
+  monitor_info1 = meta_virtual_monitor_info_new (100, 100, 60.0,
+                                                 "MetaTestVendor",
+                                                 "MetaVirtualMonitor",
+                                                 "0x1234");
+  virtual_monitor1 = meta_monitor_manager_create_virtual_monitor (monitor_manager,
+                                                                  monitor_info1,
+                                                                  &error);
+  if (!virtual_monitor1)
+    g_error ("Failed to create virtual monitor: %s", error->message);
+  meta_monitor_manager_reload (monitor_manager);
+
+  clutter_virtual_input_device_notify_absolute_motion (virtual_pointer,
+                                                       g_get_monotonic_time (),
+                                                       50, 50);
+  meta_wait_for_paint (test_context);
+
+  meta_cursor_tracker_get_pointer (meta_backend_get_cursor_tracker (backend),
+                                   &coords, NULL);
+  g_assert_nonnull (meta_backend_get_current_logical_monitor (backend));
+
+  monitor_info2 = meta_virtual_monitor_info_new (200, 200, 60.0,
+                                                 "MetaTestVendor",
+                                                 "MetaVirtualMonitor",
+                                                 "0x1235");
+  virtual_monitor2 = meta_monitor_manager_create_virtual_monitor (monitor_manager,
+                                                                  monitor_info2,
+                                                                  &error);
+  if (!virtual_monitor2)
+    g_error ("Failed to create virtual monitor: %s", error->message);
+  meta_monitor_manager_reload (monitor_manager);
+
+  test_client = meta_test_client_new (test_context,
+                                      "test-client",
+                                      META_WINDOW_CLIENT_TYPE_WAYLAND,
+                                      &error);
+  if (!test_client)
+    g_error ("Failed to launch test client: %s", error->message);
+
+  run_test_client_command (test_client, "create", "1", NULL);;
+  run_test_client_command (test_client, "show", "1", NULL);
+  run_test_client_command (test_client, "sync", NULL);
+
+  meta_wait_for_paint (test_context);
+
+  meta_cursor_tracker_get_pointer (meta_backend_get_cursor_tracker (backend),
+                                   &coords, NULL);
+
+  g_assert_nonnull (meta_backend_get_current_logical_monitor (backend));
+}
+
+static void
+init_tests (void)
+{
+  g_test_add_func ("/backends/native/pointer-constraints/warp-on-hotplug",
+                   meta_test_warp_on_hotplug);
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  g_autoptr (MetaContext) context = NULL;
+
+  context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
+                                      META_CONTEXT_TEST_FLAG_NO_X11 |
+                                      META_CONTEXT_TEST_FLAG_TEST_CLIENT);
+  g_assert (meta_context_configure (context, &argc, &argv, NULL));
+
+  test_context = context;
+
+  init_tests ();
+
+  return meta_context_test_run_tests (META_CONTEXT_TEST (context),
+                                      META_TEST_RUN_FLAG_NONE);
+}


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