From 63522de4d043a600f56887a5d540e18225583b68 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 7 Feb 2023 17:41:04 +0100 Subject: [PATCH] tests/stacking: Change primary monitor handling The first monitor in stacking tests is the primary monitor but that doesn't have to stay this way forever. Instead of special casing the name "primary" to refer to whatever monitor happens to be the primary monitor, we add an `assert_primary_monitor` command to verify that the monitor that should be the primary monitor actually is. Part-of: --- src/backends/meta-monitor.h | 1 + .../click-to-focus-and-raise.metatest | 2 +- ...client-resize-respect-constraints.metatest | 2 +- src/tests/stacking/map-on-hotplug.metatest | 2 +- .../workspace-only-on-primary-focus.metatest | 3 ++- src/tests/test-runner.c | 27 ++++++++++++++++++- 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/backends/meta-monitor.h b/src/backends/meta-monitor.h index 387938b3b..3f98a58f6 100644 --- a/src/backends/meta-monitor.h +++ b/src/backends/meta-monitor.h @@ -112,6 +112,7 @@ gboolean meta_monitor_is_active (MetaMonitor *monitor); META_EXPORT_TEST MetaOutput * meta_monitor_get_main_output (MetaMonitor *monitor); +META_EXPORT_TEST gboolean meta_monitor_is_primary (MetaMonitor *monitor); gboolean meta_monitor_supports_underscanning (MetaMonitor *monitor); diff --git a/src/tests/stacking/click-to-focus-and-raise.metatest b/src/tests/stacking/click-to-focus-and-raise.metatest index f6b91f876..b2f145e9c 100644 --- a/src/tests/stacking/click-to-focus-and-raise.metatest +++ b/src/tests/stacking/click-to-focus-and-raise.metatest @@ -1,4 +1,4 @@ -resize_monitor primary 800 600 +resize_monitor default 800 600 num_workspaces 2 diff --git a/src/tests/stacking/client-resize-respect-constraints.metatest b/src/tests/stacking/client-resize-respect-constraints.metatest index fd524784e..10789395f 100644 --- a/src/tests/stacking/client-resize-respect-constraints.metatest +++ b/src/tests/stacking/client-resize-respect-constraints.metatest @@ -4,7 +4,7 @@ # 3. Resize such that the following resize will extend beyond the screen # 4. Check that the window was moved to the position that would allow it to fit on the screen -resize_monitor primary 800 600 +resize_monitor default 800 600 new_client w wayland create w/1 csd diff --git a/src/tests/stacking/map-on-hotplug.metatest b/src/tests/stacking/map-on-hotplug.metatest index 664ae21f1..683b75856 100644 --- a/src/tests/stacking/map-on-hotplug.metatest +++ b/src/tests/stacking/map-on-hotplug.metatest @@ -7,7 +7,7 @@ freeze w/1 resize w/1 100 200 show w/1 async -resize_monitor primary 1024 768 +resize_monitor default 1024 768 wait diff --git a/src/tests/stacking/workspace-only-on-primary-focus.metatest b/src/tests/stacking/workspace-only-on-primary-focus.metatest index 5fb1e91da..8f6fac7a9 100644 --- a/src/tests/stacking/workspace-only-on-primary-focus.metatest +++ b/src/tests/stacking/workspace-only-on-primary-focus.metatest @@ -1,5 +1,6 @@ -resize_monitor primary 800 600 +resize_monitor default 800 600 add_monitor secondary 800 600 +assert_primary_monitor default num_workspaces 2 diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c index cc2650db2..282c4ec6f 100644 --- a/src/tests/test-runner.c +++ b/src/tests/test-runner.c @@ -104,7 +104,7 @@ test_case_new (MetaContext *context) g_free, g_object_unref); monitor = meta_create_test_monitor (context, 800, 600, 60.0); - g_hash_table_insert (test->virtual_monitors, g_strdup ("primary"), monitor); + g_hash_table_insert (test->virtual_monitors, g_strdup ("default"), monitor); return test; } @@ -1069,6 +1069,31 @@ test_case_do (TestCase *test, g_hash_table_insert (test->virtual_monitors, g_strdup (argv[1]), monitor); } + else if (strcmp (argv[0], "assert_primary_monitor") == 0) + { + MetaVirtualMonitor *virtual_monitor; + MetaOutput *output; + MetaMonitor *monitor; + + if (argc != 2) + BAD_COMMAND ("usage: %s ", argv[0]); + + virtual_monitor = g_hash_table_lookup (test->virtual_monitors, argv[1]); + if (!virtual_monitor) + BAD_COMMAND ("Unknown monitor %s", argv[1]); + + output = meta_virtual_monitor_get_output (virtual_monitor); + monitor = meta_output_get_monitor (output); + + if (!meta_monitor_is_primary (monitor)) + { + g_set_error (error, + META_TEST_CLIENT_ERROR, + META_TEST_CLIENT_ERROR_ASSERTION_FAILED, + "Monitor %s is not the primary monitor", argv[1]); + return FALSE; + } + } else if (strcmp (argv[0], "num_workspaces") == 0) { if (argc != 2)