[mutter] monitor-config-store: Add test for monitor configuration policy



commit 3d4a6875e68dbec00c1bc58637ded1fb636bf498
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Thu Sep 30 17:32:31 2021 +0200

    monitor-config-store: Add test for monitor configuration policy
    
    The test aims to verify that setting the following policy
    
        <policy>
          <stores>
            <store>system</store>
          </stores>
        </policy>
    
    only applies monitor configurations from the system level.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2030>

 src/tests/monitor-configs/system/monitors.xml |  27 +++++
 src/tests/monitor-configs/user/monitors.xml   |  22 ++++
 src/tests/monitor-unit-tests.c                | 149 ++++++++++++++++++++++++++
 3 files changed, 198 insertions(+)
---
diff --git a/src/tests/monitor-configs/system/monitors.xml b/src/tests/monitor-configs/system/monitors.xml
new file mode 100644
index 0000000000..4d2eafec13
--- /dev/null
+++ b/src/tests/monitor-configs/system/monitors.xml
@@ -0,0 +1,27 @@
+<monitors version="2">
+  <policy>
+    <stores>
+      <store>system</store>
+    </stores>
+  </policy>
+  <configuration>
+    <logicalmonitor>
+      <x>0</x>
+      <y>0</y>
+      <primary>yes</primary>
+      <monitor>
+       <monitorspec>
+         <connector>DP-1</connector>
+         <vendor>MetaProduct&apos;s Inc.</vendor>
+         <product>MetaMonitor</product>
+         <serial>0x123456</serial>
+       </monitorspec>
+       <mode>
+         <width>640</width>
+         <height>480</height>
+         <rate>60</rate>
+       </mode>
+      </monitor>
+    </logicalmonitor>
+  </configuration>
+</monitors>
diff --git a/src/tests/monitor-configs/user/monitors.xml b/src/tests/monitor-configs/user/monitors.xml
new file mode 100644
index 0000000000..f125972e01
--- /dev/null
+++ b/src/tests/monitor-configs/user/monitors.xml
@@ -0,0 +1,22 @@
+<monitors version="2">
+  <configuration>
+    <logicalmonitor>
+      <x>0</x>
+      <y>0</y>
+      <primary>yes</primary>
+      <monitor>
+       <monitorspec>
+         <connector>DP-1</connector>
+         <vendor>MetaProduct&apos;s Inc.</vendor>
+         <product>MetaMonitor</product>
+         <serial>0x123456</serial>
+       </monitorspec>
+       <mode>
+         <width>800</width>
+         <height>600</height>
+         <rate>60</rate>
+       </mode>
+      </monitor>
+    </logicalmonitor>
+  </configuration>
+</monitors>
diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c
index ca337ce7e8..bec8184c82 100644
--- a/src/tests/monitor-unit-tests.c
+++ b/src/tests/monitor-unit-tests.c
@@ -8742,6 +8742,136 @@ meta_test_monitor_supported_fractional_scales (void)
                                             META_MONITOR_SCALES_CONSTRAINT_NONE));
 }
 
+static void
+meta_test_monitor_policy_system_only (void)
+{
+  MetaMonitorTestSetup *test_setup;
+  MonitorTestCase test_case = {
+    .setup = {
+      .modes = {
+        {
+          .width = 1024,
+          .height = 768,
+          .refresh_rate = 60.0
+        },
+        {
+          .width = 800,
+          .height = 600,
+          .refresh_rate = 60.0
+        },
+        {
+          .width = 640,
+          .height = 480,
+          .refresh_rate = 60.0
+        }
+      },
+      .n_modes = 3,
+      .outputs = {
+         {
+          .crtc = 0,
+          .modes = { 0, 1, 2 },
+          .n_modes = 3,
+          .preferred_mode = 0,
+          .possible_crtcs = { 0 },
+          .n_possible_crtcs = 1,
+          .width_mm = 222,
+          .height_mm = 125
+        },
+      },
+      .n_outputs = 1,
+      .crtcs = {
+        {
+          .current_mode = 0
+        }
+      },
+      .n_crtcs = 1
+    },
+
+    .expect = {
+      .monitors = {
+        {
+          .outputs = { 0 },
+          .n_outputs = 1,
+          .modes = {
+            {
+              .width = 1024,
+              .height = 768,
+              .refresh_rate = 60.0,
+              .crtc_modes = {
+                {
+                  .output = 0,
+                  .crtc_mode = 0
+                }
+              }
+            },
+            {
+              .width = 800,
+              .height = 600,
+              .refresh_rate = 60.0,
+              .crtc_modes = {
+                {
+                  .output = 0,
+                  .crtc_mode = 1
+                }
+              }
+            },
+            {
+              .width = 640,
+              .height = 480,
+              .refresh_rate = 60.0,
+              .crtc_modes = {
+                {
+                  .output = 0,
+                  .crtc_mode = 2
+                }
+              }
+            }
+          },
+          .n_modes = 3,
+          .current_mode = 2,
+          .width_mm = 222,
+          .height_mm = 125
+        },
+      },
+      .n_monitors = 1,
+      .logical_monitors = {
+        {
+          .monitors = { 0 },
+          .n_monitors = 1,
+          .layout = { .x = 0, .y = 0, .width = 640, .height = 480 },
+          .scale = 1
+        },
+      },
+      .n_logical_monitors = 1,
+      .primary_logical_monitor = 0,
+      .n_outputs = 1,
+      .crtcs = {
+        {
+          .current_mode = 2,
+          .x = 0,
+        }
+      },
+      .n_crtcs = 1,
+      .screen_width = 640,
+      .screen_height = 480,
+    }
+  };
+  MetaBackend *backend = meta_context_get_backend (test_context);
+  MetaMonitorManager *monitor_manager =
+    meta_backend_get_monitor_manager (backend);
+  MetaMonitorConfigManager *config_manager = monitor_manager->config_manager;
+  MetaMonitorConfigStore *config_store =
+    meta_monitor_config_manager_get_store (config_manager);
+
+  test_setup = create_monitor_test_setup (&test_case.setup,
+                                          MONITOR_TEST_FLAG_NONE);
+
+  meta_monitor_config_store_reset (config_store);
+  emulate_hotplug (test_setup);
+  META_TEST_LOG_CALL ("Checking monitor configuration",
+                      check_monitor_configuration (&test_case.expect));
+}
+
 static void
 test_case_setup (void       **fixture,
                  const void   *data)
@@ -8909,6 +9039,9 @@ init_monitor_tests (void)
                     meta_test_monitor_supported_integer_scales);
   add_monitor_test ("/backends/monitor/suppported_scales/fractional",
                     meta_test_monitor_supported_fractional_scales);
+
+  add_monitor_test ("/backends/monitor/policy/system-only",
+                    meta_test_monitor_policy_system_only);
 }
 
 static void
@@ -8928,11 +9061,27 @@ main (int   argc,
       char *argv[])
 {
   g_autoptr (MetaContext) context = NULL;
+  char *path;
 
   context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED,
                                       META_CONTEXT_TEST_FLAG_TEST_CLIENT);
   g_assert (meta_context_configure (context, &argc, &argv, NULL));
 
+  path = g_test_build_filename (G_TEST_DIST,
+                                "tests",
+                                "monitor-configs",
+                                "system",
+                                NULL);
+  g_setenv ("XDG_CONFIG_DIRS", path, TRUE);
+  g_free (path);
+  path = g_test_build_filename (G_TEST_DIST,
+                                "tests",
+                                "monitor-configs",
+                                "user",
+                                NULL);
+  g_setenv ("XDG_CONFIG_HOME", path, TRUE);
+  g_free (path);
+
   test_context = context;
 
   init_monitor_tests ();


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