diff --git a/src/tests/monitor-store-unit-tests.c b/src/tests/monitor-store-unit-tests.c index 4a73d89db4c6375a7acf8e37c466875c4179abfc..b9d5622b7ae33cdb045d8c789d8fd06d6a7aff90 100644 --- a/src/tests/monitor-store-unit-tests.c +++ b/src/tests/monitor-store-unit-tests.c @@ -31,38 +31,38 @@ #define MAX_N_LOGICAL_MONITORS 10 #define MAX_N_CONFIGURATIONS 10 -typedef struct _MonitorTestCaseMonitorMode +typedef struct _MonitorStoreTestCaseMonitorMode { int width; int height; float refresh_rate; MetaCrtcModeFlag flags; -} MonitorTestCaseMonitorMode; +} MonitorStoreTestCaseMonitorMode; -typedef struct _MonitorTestCaseMonitor +typedef struct _MonitorStoreTestCaseMonitor { const char *connector; const char *vendor; const char *product; const char *serial; - MonitorTestCaseMonitorMode mode; + MonitorStoreTestCaseMonitorMode mode; gboolean is_underscanning; -} MonitorTestCaseMonitor; +} MonitorStoreTestCaseMonitor; -typedef struct _MonitorTestCaseLogicalMonitor +typedef struct _MonitorStoreTestCaseLogicalMonitor { MetaRectangle layout; float scale; MetaMonitorTransform transform; gboolean is_primary; gboolean is_presentation; - MonitorTestCaseMonitor monitors[MAX_N_MONITORS]; + MonitorStoreTestCaseMonitor monitors[MAX_N_MONITORS]; int n_monitors; -} MonitorTestCaseLogicalMonitor; +} MonitorStoreTestCaseLogicalMonitor; typedef struct _MonitorStoreTestConfiguration { - MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; + MonitorStoreTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; int n_logical_monitors; } MonitorStoreTestConfiguration; @@ -87,7 +87,7 @@ create_config_key_from_expect (MonitorStoreTestConfiguration *expect_config) for (j = 0; j < expect_config->logical_monitors[i].n_monitors; j++) { MetaMonitorSpec *monitor_spec; - MonitorTestCaseMonitor *test_monitor = + MonitorStoreTestCaseMonitor *test_monitor = &expect_config->logical_monitors[i].monitors[j]; monitor_spec = g_new0 (MetaMonitorSpec, 1); @@ -115,8 +115,8 @@ create_config_key_from_expect (MonitorStoreTestConfiguration *expect_config) } static void -check_monitor_configuration (MetaMonitorConfigStore *config_store, - MonitorStoreTestConfiguration *config_expect) +check_monitor_store_configuration (MetaMonitorConfigStore *config_store, + MonitorStoreTestConfiguration *config_expect) { MetaMonitorsConfigKey *config_key; MetaMonitorsConfig *config; @@ -164,7 +164,7 @@ check_monitor_configuration (MetaMonitorConfigStore *config_store, k = k->next, j++) { MetaMonitorConfig *monitor_config = k->data; - MonitorTestCaseMonitor *test_monitor = + MonitorStoreTestCaseMonitor *test_monitor = &config_expect->logical_monitors[i].monitors[j]; g_assert_cmpstr (monitor_config->monitor_spec->connector, @@ -200,7 +200,7 @@ check_monitor_configuration (MetaMonitorConfigStore *config_store, } static void -check_monitor_configurations (MonitorStoreTestExpect *expect) +check_monitor_store_configurations (MonitorStoreTestExpect *expect) { MetaBackend *backend = meta_get_backend (); MetaMonitorManager *monitor_manager = @@ -215,7 +215,7 @@ check_monitor_configurations (MonitorStoreTestExpect *expect) expect->n_configurations); for (i = 0; i < expect->n_configurations; i++) - check_monitor_configuration (config_store, &expect->configurations[i]); + check_monitor_store_configuration (config_store, &expect->configurations[i]); } static void @@ -259,7 +259,7 @@ meta_test_monitor_store_single (void) set_custom_monitor_config ("single.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -328,7 +328,7 @@ meta_test_monitor_store_vertical (void) set_custom_monitor_config ("vertical.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -397,7 +397,7 @@ meta_test_monitor_store_primary (void) set_custom_monitor_config ("primary.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -442,7 +442,7 @@ meta_test_monitor_store_underscanning (void) set_custom_monitor_config ("underscanning.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -492,7 +492,7 @@ meta_test_monitor_store_scale (void) set_custom_monitor_config ("scale.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -542,7 +542,7 @@ meta_test_monitor_store_fractional_scale (void) set_custom_monitor_config ("fractional-scale.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -592,7 +592,7 @@ meta_test_monitor_store_high_precision_fractional_scale (void) set_custom_monitor_config ("high-precision-fractional-scale.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -646,7 +646,7 @@ meta_test_monitor_store_mirrored (void) set_custom_monitor_config ("mirrored.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -717,7 +717,7 @@ meta_test_monitor_store_first_rotated (void) set_custom_monitor_config ("first-rotated.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -788,7 +788,7 @@ meta_test_monitor_store_second_rotated (void) set_custom_monitor_config ("second-rotated.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } static void @@ -833,7 +833,7 @@ meta_test_monitor_store_interlaced (void) set_custom_monitor_config ("interlaced.xml"); - check_monitor_configurations (&expect); + check_monitor_store_configurations (&expect); } void diff --git a/src/tests/monitor-test-utils.c b/src/tests/monitor-test-utils.c index 54881569102e989b962bfb0594fa70c14cf646d4..6de2682bba2d5e3519d2862ad7b440bcd744ff04 100644 --- a/src/tests/monitor-test-utils.c +++ b/src/tests/monitor-test-utils.c @@ -22,8 +22,12 @@ #include "tests/monitor-test-utils.h" #include "backends/meta-backend-private.h" +#include "backends/meta-crtc.h" +#include "backends/meta-logical-monitor.h" #include "backends/meta-monitor-config-manager.h" #include "backends/meta-monitor-config-store.h" +#include "backends/meta-output.h" +#include "meta-backend-test.h" void set_custom_monitor_config (const char *filename) @@ -79,3 +83,600 @@ read_file (const char *file_path) return g_steal_pointer (&buffer); } + +static MetaOutput * +output_from_winsys_id (MetaBackend *backend, + uint64_t winsys_id) +{ + MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); + GList *l; + + for (l = meta_gpu_get_outputs (gpu); l; l = l->next) + { + MetaOutput *output = l->data; + + if (output->winsys_id == winsys_id) + return output; + } + + return NULL; +} + +typedef struct _CheckMonitorModeData +{ + MetaBackend *backend; + MetaTestCaseMonitorCrtcMode *expect_crtc_mode_iter; +} CheckMonitorModeData; + +static gboolean +check_monitor_mode (MetaMonitor *monitor, + MetaMonitorMode *mode, + MetaMonitorCrtcMode *monitor_crtc_mode, + gpointer user_data, + GError **error) +{ + CheckMonitorModeData *data = user_data; + MetaBackend *backend = data->backend; + MetaOutput *output; + MetaCrtcMode *crtc_mode; + int expect_crtc_mode_index; + + output = output_from_winsys_id (backend, + data->expect_crtc_mode_iter->output); + g_assert (monitor_crtc_mode->output == output); + + expect_crtc_mode_index = data->expect_crtc_mode_iter->crtc_mode; + if (expect_crtc_mode_index == -1) + { + crtc_mode = NULL; + } + else + { + MetaGpu *gpu = meta_output_get_gpu (output); + + crtc_mode = g_list_nth_data (meta_gpu_get_modes (gpu), + expect_crtc_mode_index); + } + g_assert (monitor_crtc_mode->crtc_mode == crtc_mode); + + if (crtc_mode) + { + float refresh_rate; + MetaCrtcModeFlag flags; + + refresh_rate = meta_monitor_mode_get_refresh_rate (mode); + flags = meta_monitor_mode_get_flags (mode); + + g_assert_cmpfloat (refresh_rate, ==, crtc_mode->refresh_rate); + g_assert_cmpint (flags, ==, (crtc_mode->flags & HANDLED_CRTC_MODE_FLAGS)); + } + + data->expect_crtc_mode_iter++; + + return TRUE; +} + +static gboolean +check_current_monitor_mode (MetaMonitor *monitor, + MetaMonitorMode *mode, + MetaMonitorCrtcMode *monitor_crtc_mode, + gpointer user_data, + GError **error) +{ + CheckMonitorModeData *data = user_data; + MetaBackend *backend = data->backend; + MetaOutput *output; + MetaCrtc *crtc; + + output = output_from_winsys_id (backend, + data->expect_crtc_mode_iter->output); + crtc = meta_output_get_assigned_crtc (output); + + if (data->expect_crtc_mode_iter->crtc_mode == -1) + { + g_assert_null (crtc); + } + else + { + MetaCrtcConfig *crtc_config; + MetaLogicalMonitor *logical_monitor; + + g_assert_nonnull (crtc); + + crtc_config = crtc->config; + g_assert_nonnull (crtc_config); + + g_assert (monitor_crtc_mode->crtc_mode == crtc_config->mode); + + logical_monitor = meta_monitor_get_logical_monitor (monitor); + g_assert_nonnull (logical_monitor); + } + + + data->expect_crtc_mode_iter++; + + return TRUE; +} + +static MetaLogicalMonitor * +logical_monitor_from_layout (MetaMonitorManager *monitor_manager, + MetaRectangle *layout) +{ + GList *l; + + for (l = monitor_manager->logical_monitors; l; l = l->next) + { + MetaLogicalMonitor *logical_monitor = l->data; + + if (meta_rectangle_equal (layout, &logical_monitor->rect)) + return logical_monitor; + } + + return NULL; +} + +static void +check_logical_monitor (MetaMonitorManager *monitor_manager, + MonitorTestCaseLogicalMonitor *test_logical_monitor) +{ + MetaLogicalMonitor *logical_monitor; + MetaOutput *primary_output; + GList *monitors; + GList *l; + int i; + + logical_monitor = logical_monitor_from_layout (monitor_manager, + &test_logical_monitor->layout); + g_assert_nonnull (logical_monitor); + + g_assert_cmpint (logical_monitor->rect.x, + ==, + test_logical_monitor->layout.x); + g_assert_cmpint (logical_monitor->rect.y, + ==, + test_logical_monitor->layout.y); + g_assert_cmpint (logical_monitor->rect.width, + ==, + test_logical_monitor->layout.width); + g_assert_cmpint (logical_monitor->rect.height, + ==, + test_logical_monitor->layout.height); + g_assert_cmpfloat (logical_monitor->scale, + ==, + test_logical_monitor->scale); + g_assert_cmpuint (logical_monitor->transform, + ==, + test_logical_monitor->transform); + + if (logical_monitor == monitor_manager->primary_logical_monitor) + g_assert (meta_logical_monitor_is_primary (logical_monitor)); + + primary_output = NULL; + monitors = meta_logical_monitor_get_monitors (logical_monitor); + g_assert_cmpint ((int) g_list_length (monitors), + ==, + test_logical_monitor->n_monitors); + + for (i = 0; i < test_logical_monitor->n_monitors; i++) + { + MetaMonitor *monitor = + g_list_nth (monitor_manager->monitors, + test_logical_monitor->monitors[i])->data; + + g_assert_nonnull (g_list_find (monitors, monitor)); + } + + for (l = monitors; l; l = l->next) + { + MetaMonitor *monitor = l->data; + GList *outputs; + GList *l_output; + + outputs = meta_monitor_get_outputs (monitor); + for (l_output = outputs; l_output; l_output = l_output->next) + { + MetaOutput *output = l_output->data; + MetaCrtc *crtc; + + if (output->is_primary) + { + g_assert_null (primary_output); + primary_output = output; + } + + crtc = meta_output_get_assigned_crtc (output); + g_assert (!crtc || + meta_monitor_get_logical_monitor (monitor) == logical_monitor); + g_assert_cmpint (logical_monitor->is_presentation, + ==, + output->is_presentation); + } + } + + if (logical_monitor == monitor_manager->primary_logical_monitor) + g_assert_nonnull (primary_output); +} + +void +check_monitor_configuration (MonitorTestCaseExpect *expect) +{ + MetaBackend *backend = meta_get_backend (); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + MetaMonitorManagerTest *monitor_manager_test = + META_MONITOR_MANAGER_TEST (monitor_manager); + MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); + int tiled_monitor_count; + GList *monitors; + GList *crtcs; + int n_logical_monitors; + GList *l; + int i; + + g_assert_cmpint (monitor_manager->screen_width, + ==, + expect->screen_width); + g_assert_cmpint (monitor_manager->screen_height, + ==, + expect->screen_height); + g_assert_cmpint ((int) g_list_length (meta_gpu_get_outputs (gpu)), + ==, + expect->n_outputs); + g_assert_cmpint ((int) g_list_length (meta_gpu_get_crtcs (gpu)), + ==, + expect->n_crtcs); + + tiled_monitor_count = + meta_monitor_manager_test_get_tiled_monitor_count (monitor_manager_test); + g_assert_cmpint (tiled_monitor_count, + ==, + expect->n_tiled_monitors); + + monitors = meta_monitor_manager_get_monitors (monitor_manager); + g_assert_cmpint ((int) g_list_length (monitors), + ==, + expect->n_monitors); + for (l = monitors, i = 0; l; l = l->next, i++) + { + MetaMonitor *monitor = l->data; + GList *outputs; + GList *l_output; + int j; + int width_mm, height_mm; + GList *modes; + GList *l_mode; + MetaMonitorMode *current_mode; + int expected_current_mode_index; + MetaMonitorMode *expected_current_mode; + + outputs = meta_monitor_get_outputs (monitor); + + g_assert_cmpint ((int) g_list_length (outputs), + ==, + expect->monitors[i].n_outputs); + + for (l_output = outputs, j = 0; l_output; l_output = l_output->next, j++) + { + MetaOutput *output = l_output->data; + uint64_t winsys_id = expect->monitors[i].outputs[j]; + + g_assert (output == output_from_winsys_id (backend, winsys_id)); + g_assert_cmpint (expect->monitors[i].is_underscanning, + ==, + output->is_underscanning); + } + + meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm); + g_assert_cmpint (width_mm, + ==, + expect->monitors[i].width_mm); + g_assert_cmpint (height_mm, + ==, + expect->monitors[i].height_mm); + + modes = meta_monitor_get_modes (monitor); + g_assert_cmpint (g_list_length (modes), + ==, + expect->monitors[i].n_modes); + + for (l_mode = modes, j = 0; l_mode; l_mode = l_mode->next, j++) + { + MetaMonitorMode *mode = l_mode->data; + int width; + int height; + float refresh_rate; + MetaCrtcModeFlag flags; + CheckMonitorModeData data; + + meta_monitor_mode_get_resolution (mode, &width, &height); + refresh_rate = meta_monitor_mode_get_refresh_rate (mode); + flags = meta_monitor_mode_get_flags (mode); + + g_assert_cmpint (width, + ==, + expect->monitors[i].modes[j].width); + g_assert_cmpint (height, + ==, + expect->monitors[i].modes[j].height); + g_assert_cmpfloat (refresh_rate, + ==, + expect->monitors[i].modes[j].refresh_rate); + g_assert_cmpint (flags, + ==, + expect->monitors[i].modes[j].flags); + + data = (CheckMonitorModeData) { + .backend = backend, + .expect_crtc_mode_iter = + expect->monitors[i].modes[j].crtc_modes + }; + meta_monitor_mode_foreach_output (monitor, mode, + check_monitor_mode, + &data, + NULL); + } + + current_mode = meta_monitor_get_current_mode (monitor); + expected_current_mode_index = expect->monitors[i].current_mode; + if (expected_current_mode_index == -1) + expected_current_mode = NULL; + else + expected_current_mode = g_list_nth (modes, + expected_current_mode_index)->data; + + g_assert (current_mode == expected_current_mode); + if (current_mode) + g_assert (meta_monitor_is_active (monitor)); + else + g_assert (!meta_monitor_is_active (monitor)); + + if (current_mode) + { + CheckMonitorModeData data; + + data = (CheckMonitorModeData) { + .backend = backend, + .expect_crtc_mode_iter = + expect->monitors[i].modes[expected_current_mode_index].crtc_modes + }; + meta_monitor_mode_foreach_output (monitor, expected_current_mode, + check_current_monitor_mode, + &data, + NULL); + } + + meta_monitor_derive_current_mode (monitor); + g_assert (current_mode == meta_monitor_get_current_mode (monitor)); + } + + n_logical_monitors = + meta_monitor_manager_get_num_logical_monitors (monitor_manager); + g_assert_cmpint (n_logical_monitors, + ==, + expect->n_logical_monitors); + + /* + * Check that we have a primary logical monitor (except for headless), + * and that the main output of the first monitor is the only output + * that is marked as primary (further below). Note: outputs being primary or + * not only matters on X11. + */ + if (expect->primary_logical_monitor == -1) + { + g_assert_null (monitor_manager->primary_logical_monitor); + g_assert_null (monitor_manager->logical_monitors); + } + else + { + MonitorTestCaseLogicalMonitor *test_logical_monitor = + &expect->logical_monitors[expect->primary_logical_monitor]; + MetaLogicalMonitor *logical_monitor; + + logical_monitor = + logical_monitor_from_layout (monitor_manager, + &test_logical_monitor->layout); + g_assert (logical_monitor == monitor_manager->primary_logical_monitor); + } + + for (i = 0; i < expect->n_logical_monitors; i++) + { + MonitorTestCaseLogicalMonitor *test_logical_monitor = + &expect->logical_monitors[i]; + + check_logical_monitor (monitor_manager, test_logical_monitor); + } + g_assert_cmpint (n_logical_monitors, ==, i); + + crtcs = meta_gpu_get_crtcs (gpu); + for (l = crtcs, i = 0; l; l = l->next, i++) + { + MetaCrtc *crtc = l->data; + MetaCrtcConfig *crtc_config = crtc->config; + + if (expect->crtcs[i].current_mode == -1) + { + g_assert_null (crtc_config); + } + else + { + MetaCrtcMode *expected_current_mode; + + g_assert_nonnull (crtc_config); + + expected_current_mode = + g_list_nth_data (meta_gpu_get_modes (gpu), + expect->crtcs[i].current_mode); + g_assert (crtc_config->mode == expected_current_mode); + + g_assert_cmpuint (crtc_config->transform, + ==, + expect->crtcs[i].transform); + + g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.x, + expect->crtcs[i].x, + FLT_EPSILON); + g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.y, + expect->crtcs[i].y, + FLT_EPSILON); + } + } +} + +static void +meta_output_test_destroy_notify (MetaOutput *output) +{ + g_clear_pointer (&output->driver_private, g_free); +} + +MetaMonitorTestSetup * +create_monitor_test_setup (MonitorTestCaseSetup *setup, + MonitorTestFlag flags) +{ + MetaMonitorTestSetup *test_setup; + int i; + int n_laptop_panels = 0; + int n_normal_panels = 0; + gboolean hotplug_mode_update; + + if (flags & MONITOR_TEST_FLAG_NO_STORED) + hotplug_mode_update = TRUE; + else + hotplug_mode_update = FALSE; + + test_setup = g_new0 (MetaMonitorTestSetup, 1); + + test_setup->modes = NULL; + for (i = 0; i < setup->n_modes; i++) + { + MetaCrtcMode *mode; + + mode = g_object_new (META_TYPE_CRTC_MODE, NULL); + mode->mode_id = i; + mode->width = setup->modes[i].width; + mode->height = setup->modes[i].height; + mode->refresh_rate = setup->modes[i].refresh_rate; + mode->flags = setup->modes[i].flags; + + test_setup->modes = g_list_append (test_setup->modes, mode); + } + + test_setup->crtcs = NULL; + for (i = 0; i < setup->n_crtcs; i++) + { + MetaCrtc *crtc; + + crtc = g_object_new (META_TYPE_CRTC, NULL); + crtc->crtc_id = i + 1; + crtc->all_transforms = ALL_TRANSFORMS; + + test_setup->crtcs = g_list_append (test_setup->crtcs, crtc); + } + + test_setup->outputs = NULL; + for (i = 0; i < setup->n_outputs; i++) + { + MetaOutput *output; + MetaOutputTest *output_test; + int crtc_index; + MetaCrtc *crtc; + int preferred_mode_index; + MetaCrtcMode *preferred_mode; + MetaCrtcMode **modes; + int n_modes; + int j; + MetaCrtc **possible_crtcs; + int n_possible_crtcs; + int scale; + gboolean is_laptop_panel; + const char *serial; + + crtc_index = setup->outputs[i].crtc; + if (crtc_index == -1) + crtc = NULL; + else + crtc = g_list_nth_data (test_setup->crtcs, crtc_index); + + preferred_mode_index = setup->outputs[i].preferred_mode; + if (preferred_mode_index == -1) + preferred_mode = NULL; + else + preferred_mode = g_list_nth_data (test_setup->modes, + preferred_mode_index); + + n_modes = setup->outputs[i].n_modes; + modes = g_new0 (MetaCrtcMode *, n_modes); + for (j = 0; j < n_modes; j++) + { + int mode_index; + + mode_index = setup->outputs[i].modes[j]; + modes[j] = g_list_nth_data (test_setup->modes, mode_index); + } + + n_possible_crtcs = setup->outputs[i].n_possible_crtcs; + possible_crtcs = g_new0 (MetaCrtc *, n_possible_crtcs); + for (j = 0; j < n_possible_crtcs; j++) + { + int possible_crtc_index; + + possible_crtc_index = setup->outputs[i].possible_crtcs[j]; + possible_crtcs[j] = g_list_nth_data (test_setup->crtcs, + possible_crtc_index); + } + + output_test = g_new0 (MetaOutputTest, 1); + + scale = setup->outputs[i].scale; + if (scale < 1) + scale = 1; + + *output_test = (MetaOutputTest) { + .scale = scale + }; + + is_laptop_panel = setup->outputs[i].is_laptop_panel; + + serial = setup->outputs[i].serial; + if (!serial) + serial = "0x123456"; + + output = g_object_new (META_TYPE_OUTPUT, NULL); + + if (crtc) + meta_output_assign_crtc (output, crtc); + output->winsys_id = i; + output->name = (is_laptop_panel ? g_strdup_printf ("eDP-%d", + ++n_laptop_panels) + : g_strdup_printf ("DP-%d", + ++n_normal_panels)); + output->vendor = g_strdup ("MetaProduct's Inc."); + output->product = g_strdup ("MetaMonitor"); + output->serial = g_strdup (serial); + output->suggested_x = -1; + output->suggested_y = -1; + output->hotplug_mode_update = hotplug_mode_update; + output->width_mm = setup->outputs[i].width_mm; + output->height_mm = setup->outputs[i].height_mm; + output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN; + output->preferred_mode = preferred_mode; + output->n_modes = n_modes; + output->modes = modes; + output->n_possible_crtcs = n_possible_crtcs; + output->possible_crtcs = possible_crtcs; + output->n_possible_clones = 0; + output->possible_clones = NULL; + output->backlight = -1; + output->connector_type = (is_laptop_panel ? META_CONNECTOR_TYPE_eDP + : META_CONNECTOR_TYPE_DisplayPort); + output->tile_info = setup->outputs[i].tile_info; + output->is_underscanning = setup->outputs[i].is_underscanning; + output->panel_orientation_transform = + setup->outputs[i].panel_orientation_transform; + output->driver_private = output_test; + output->driver_notify = (GDestroyNotify) meta_output_test_destroy_notify; + + test_setup->outputs = g_list_append (test_setup->outputs, output); + } + + return test_setup; +} diff --git a/src/tests/monitor-test-utils.h b/src/tests/monitor-test-utils.h index 4b9b3f0c790d77686de3a2c1eeab433c7af1e8f7..e99799861cd9acdcb9d784d62cd2dd388ae9e8d1 100644 --- a/src/tests/monitor-test-utils.h +++ b/src/tests/monitor-test-utils.h @@ -22,10 +22,182 @@ #include -gboolean is_using_monitor_config_manager (void); +#include "tests/meta-monitor-manager-test.h" +#include "backends/meta-crtc.h" +#include "backends/meta-output.h" + +#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1) + +#define MAX_N_MODES 10 +#define MAX_N_OUTPUTS 10 +#define MAX_N_CRTCS 10 +#define MAX_N_MONITORS 10 +#define MAX_N_LOGICAL_MONITORS 10 + +/* + * The following structures are used to define test cases. + * + * Each test case consists of a test case setup and a test case expectaction. + * and a expected result, consisting + * of an array of monitors, logical monitors and a screen size. + * + * TEST CASE SETUP: + * + * A test case setup consists of an array of modes, an array of outputs and an + * array of CRTCs. + * + * A mode has a width and height in pixels, and a refresh rate in updates per + * second. + * + * An output has an array of available modes, and a preferred mode. Modes are + * defined as indices into the modes array of the test case setup. + * + * It also has CRTc and an array of possible CRTCs. Crtcs are defined as indices + * into the CRTC array. The CRTC value -1 means no CRTC. + * + * It also has various meta data, such as physical dimension, tile info and + * scale. + * + * A CRTC only has a current mode. A mode is defined as an index into the modes + * array. + * + * + * TEST CASE EXPECTS: + * + * A test case expects consists of an array of monitors, an array of logical + * monitors, a output and crtc count, and a screen width. + * + * A monitor represents a physical monitor (such as an external monitor, or a + * laptop panel etc). A monitor consists of an array of outputs, defined by + * indices into the setup output array, an array of monitor modes, and the + * current mode, defined by an index into the monitor modes array, and the + * physical dimensions. + * + * A logical monitor represents a region of the total screen area. It contains + * the expected layout and a scale. + */ + +typedef enum _MonitorTestFlag +{ + MONITOR_TEST_FLAG_NONE, + MONITOR_TEST_FLAG_NO_STORED +} MonitorTestFlag; + +typedef struct _MonitorTestCaseMode +{ + int width; + int height; + float refresh_rate; + MetaCrtcModeFlag flags; +} MonitorTestCaseMode; + +typedef struct _MonitorTestCaseOutput +{ + int crtc; + int modes[MAX_N_MODES]; + int n_modes; + int preferred_mode; + int possible_crtcs[MAX_N_CRTCS]; + int n_possible_crtcs; + int width_mm; + int height_mm; + MetaTileInfo tile_info; + float scale; + gboolean is_laptop_panel; + gboolean is_underscanning; + const char *serial; + MetaMonitorTransform panel_orientation_transform; +} MonitorTestCaseOutput; + +typedef struct _MonitorTestCaseCrtc +{ + int current_mode; +} MonitorTestCaseCrtc; + +typedef struct _MonitorTestCaseSetup +{ + MonitorTestCaseMode modes[MAX_N_MODES]; + int n_modes; + + MonitorTestCaseOutput outputs[MAX_N_OUTPUTS]; + int n_outputs; + + MonitorTestCaseCrtc crtcs[MAX_N_CRTCS]; + int n_crtcs; +} MonitorTestCaseSetup; + +typedef struct _MonitorTestCaseMonitorCrtcMode +{ + uint64_t output; + int crtc_mode; +} MetaTestCaseMonitorCrtcMode; + +typedef struct _MonitorTestCaseMonitorMode +{ + int width; + int height; + float refresh_rate; + MetaCrtcModeFlag flags; + MetaTestCaseMonitorCrtcMode crtc_modes[MAX_N_CRTCS]; +} MetaMonitorTestCaseMonitorMode; + +typedef struct _MonitorTestCaseMonitor +{ + uint64_t outputs[MAX_N_OUTPUTS]; + int n_outputs; + MetaMonitorTestCaseMonitorMode modes[MAX_N_MODES]; + int n_modes; + int current_mode; + int width_mm; + int height_mm; + gboolean is_underscanning; +} MonitorTestCaseMonitor; + +typedef struct _MonitorTestCaseLogicalMonitor +{ + MetaRectangle layout; + float scale; + int monitors[MAX_N_MONITORS]; + int n_monitors; + MetaMonitorTransform transform; +} MonitorTestCaseLogicalMonitor; + +typedef struct _MonitorTestCaseCrtcExpect +{ + MetaMonitorTransform transform; + int current_mode; + float x; + float y; +} MonitorTestCaseCrtcExpect; + +typedef struct _MonitorTestCaseExpect +{ + MonitorTestCaseMonitor monitors[MAX_N_MONITORS]; + int n_monitors; + MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; + int n_logical_monitors; + int primary_logical_monitor; + int n_outputs; + MonitorTestCaseCrtcExpect crtcs[MAX_N_CRTCS]; + int n_crtcs; + int n_tiled_monitors; + int screen_width; + int screen_height; +} MonitorTestCaseExpect; + +typedef struct _MonitorTestCase +{ + MonitorTestCaseSetup setup; + MonitorTestCaseExpect expect; +} MonitorTestCase; void set_custom_monitor_config (const char *filename); char * read_file (const char *file_path); +void check_monitor_configuration (MonitorTestCaseExpect *expect); + +MetaMonitorTestSetup * create_monitor_test_setup (MonitorTestCaseSetup *setup, + MonitorTestFlag flags); + #endif /* MONITOR_TEST_UTILS_H */ diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index 8e416624336ede1a29c9ee5f2392a26fc29b75d2..975c9970c3ca80db4e9f416f4112656b50716cbd 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -35,171 +35,6 @@ #include "tests/test-utils.h" #include "x11/meta-x11-display-private.h" -#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1) - -#define MAX_N_MODES 10 -#define MAX_N_OUTPUTS 10 -#define MAX_N_CRTCS 10 -#define MAX_N_MONITORS 10 -#define MAX_N_LOGICAL_MONITORS 10 - -/* - * The following structures are used to define test cases. - * - * Each test case consists of a test case setup and a test case expectaction. - * and a expected result, consisting - * of an array of monitors, logical monitors and a screen size. - * - * TEST CASE SETUP: - * - * A test case setup consists of an array of modes, an array of outputs and an - * array of CRTCs. - * - * A mode has a width and height in pixels, and a refresh rate in updates per - * second. - * - * An output has an array of available modes, and a preferred mode. Modes are - * defined as indices into the modes array of the test case setup. - * - * It also has CRTc and an array of possible CRTCs. Crtcs are defined as indices - * into the CRTC array. The CRTC value -1 means no CRTC. - * - * It also has various meta data, such as physical dimension, tile info and - * scale. - * - * A CRTC only has a current mode. A mode is defined as an index into the modes - * array. - * - * - * TEST CASE EXPECTS: - * - * A test case expects consists of an array of monitors, an array of logical - * monitors, a output and crtc count, and a screen width. - * - * A monitor represents a physical monitor (such as an external monitor, or a - * laptop panel etc). A monitor consists of an array of outputs, defined by - * indices into the setup output array, an array of monitor modes, and the - * current mode, defined by an index into the monitor modes array, and the - * physical dimensions. - * - * A logical monitor represents a region of the total screen area. It contains - * the expected layout and a scale. - */ - -typedef enum _MonitorTestFlag -{ - MONITOR_TEST_FLAG_NONE, - MONITOR_TEST_FLAG_NO_STORED -} MonitorTestFlag; - -typedef struct _MonitorTestCaseMode -{ - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; -} MonitorTestCaseMode; - -typedef struct _MonitorTestCaseOutput -{ - int crtc; - int modes[MAX_N_MODES]; - int n_modes; - int preferred_mode; - int possible_crtcs[MAX_N_CRTCS]; - int n_possible_crtcs; - int width_mm; - int height_mm; - MetaTileInfo tile_info; - float scale; - gboolean is_laptop_panel; - gboolean is_underscanning; - const char *serial; - MetaMonitorTransform panel_orientation_transform; -} MonitorTestCaseOutput; - -typedef struct _MonitorTestCaseCrtc -{ - int current_mode; -} MonitorTestCaseCrtc; - -typedef struct _MonitorTestCaseSetup -{ - MonitorTestCaseMode modes[MAX_N_MODES]; - int n_modes; - - MonitorTestCaseOutput outputs[MAX_N_OUTPUTS]; - int n_outputs; - - MonitorTestCaseCrtc crtcs[MAX_N_CRTCS]; - int n_crtcs; -} MonitorTestCaseSetup; - -typedef struct _MonitorTestCaseMonitorCrtcMode -{ - uint64_t output; - int crtc_mode; -} MetaTestCaseMonitorCrtcMode; - -typedef struct _MonitorTestCaseMonitorMode -{ - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; - MetaTestCaseMonitorCrtcMode crtc_modes[MAX_N_CRTCS]; -} MetaMonitorTestCaseMonitorMode; - -typedef struct _MonitorTestCaseMonitor -{ - uint64_t outputs[MAX_N_OUTPUTS]; - int n_outputs; - MetaMonitorTestCaseMonitorMode modes[MAX_N_MODES]; - int n_modes; - int current_mode; - int width_mm; - int height_mm; - gboolean is_underscanning; -} MonitorTestCaseMonitor; - -typedef struct _MonitorTestCaseLogicalMonitor -{ - MetaRectangle layout; - float scale; - int monitors[MAX_N_MONITORS]; - int n_monitors; - MetaMonitorTransform transform; -} MonitorTestCaseLogicalMonitor; - -typedef struct _MonitorTestCaseCrtcExpect -{ - MetaMonitorTransform transform; - int current_mode; - float x; - float y; -} MonitorTestCaseCrtcExpect; - -typedef struct _MonitorTestCaseExpect -{ - MonitorTestCaseMonitor monitors[MAX_N_MONITORS]; - int n_monitors; - MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; - int n_logical_monitors; - int primary_logical_monitor; - int n_outputs; - MonitorTestCaseCrtcExpect crtcs[MAX_N_CRTCS]; - int n_crtcs; - int n_tiled_monitors; - int screen_width; - int screen_height; -} MonitorTestCaseExpect; - -typedef struct _MonitorTestCase -{ - MonitorTestCaseSetup setup; - MonitorTestCaseExpect expect; -} MonitorTestCase; - static MonitorTestCase initial_test_case = { .setup = { .modes = { @@ -418,610 +253,11 @@ destroy_monitor_test_clients (void) NULL, NULL); } -static MetaOutput * -output_from_winsys_id (MetaBackend *backend, - uint64_t winsys_id) -{ - MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); - GList *l; - - for (l = meta_gpu_get_outputs (gpu); l; l = l->next) - { - MetaOutput *output = l->data; - - if (output->winsys_id == winsys_id) - return output; - } - - return NULL; -} - -typedef struct _CheckMonitorModeData -{ - MetaBackend *backend; - MetaTestCaseMonitorCrtcMode *expect_crtc_mode_iter; -} CheckMonitorModeData; - -static gboolean -check_monitor_mode (MetaMonitor *monitor, - MetaMonitorMode *mode, - MetaMonitorCrtcMode *monitor_crtc_mode, - gpointer user_data, - GError **error) -{ - CheckMonitorModeData *data = user_data; - MetaBackend *backend = data->backend; - MetaOutput *output; - MetaCrtcMode *crtc_mode; - int expect_crtc_mode_index; - - output = output_from_winsys_id (backend, - data->expect_crtc_mode_iter->output); - g_assert (monitor_crtc_mode->output == output); - - expect_crtc_mode_index = data->expect_crtc_mode_iter->crtc_mode; - if (expect_crtc_mode_index == -1) - { - crtc_mode = NULL; - } - else - { - MetaGpu *gpu = meta_output_get_gpu (output); - - crtc_mode = g_list_nth_data (meta_gpu_get_modes (gpu), - expect_crtc_mode_index); - } - g_assert (monitor_crtc_mode->crtc_mode == crtc_mode); - - if (crtc_mode) - { - float refresh_rate; - MetaCrtcModeFlag flags; - - refresh_rate = meta_monitor_mode_get_refresh_rate (mode); - flags = meta_monitor_mode_get_flags (mode); - - g_assert_cmpfloat (refresh_rate, ==, crtc_mode->refresh_rate); - g_assert_cmpint (flags, ==, (crtc_mode->flags & HANDLED_CRTC_MODE_FLAGS)); - } - - data->expect_crtc_mode_iter++; - - return TRUE; -} - -static gboolean -check_current_monitor_mode (MetaMonitor *monitor, - MetaMonitorMode *mode, - MetaMonitorCrtcMode *monitor_crtc_mode, - gpointer user_data, - GError **error) -{ - CheckMonitorModeData *data = user_data; - MetaBackend *backend = data->backend; - MetaOutput *output; - MetaCrtc *crtc; - - output = output_from_winsys_id (backend, - data->expect_crtc_mode_iter->output); - crtc = meta_output_get_assigned_crtc (output); - - if (data->expect_crtc_mode_iter->crtc_mode == -1) - { - g_assert_null (crtc); - } - else - { - MetaCrtcConfig *crtc_config; - MetaLogicalMonitor *logical_monitor; - - g_assert_nonnull (crtc); - - crtc_config = crtc->config; - g_assert_nonnull (crtc_config); - - g_assert (monitor_crtc_mode->crtc_mode == crtc_config->mode); - - logical_monitor = meta_monitor_get_logical_monitor (monitor); - g_assert_nonnull (logical_monitor); - } - - - data->expect_crtc_mode_iter++; - - return TRUE; -} - -static MetaLogicalMonitor * -logical_monitor_from_layout (MetaMonitorManager *monitor_manager, - MetaRectangle *layout) -{ - GList *l; - - for (l = monitor_manager->logical_monitors; l; l = l->next) - { - MetaLogicalMonitor *logical_monitor = l->data; - - if (meta_rectangle_equal (layout, &logical_monitor->rect)) - return logical_monitor; - } - - return NULL; -} - -static void -check_logical_monitor (MonitorTestCase *test_case, - MetaMonitorManager *monitor_manager, - MonitorTestCaseLogicalMonitor *test_logical_monitor) -{ - MetaLogicalMonitor *logical_monitor; - MetaOutput *primary_output; - GList *monitors; - GList *l; - int i; - - logical_monitor = logical_monitor_from_layout (monitor_manager, - &test_logical_monitor->layout); - g_assert_nonnull (logical_monitor); - - g_assert_cmpint (logical_monitor->rect.x, - ==, - test_logical_monitor->layout.x); - g_assert_cmpint (logical_monitor->rect.y, - ==, - test_logical_monitor->layout.y); - g_assert_cmpint (logical_monitor->rect.width, - ==, - test_logical_monitor->layout.width); - g_assert_cmpint (logical_monitor->rect.height, - ==, - test_logical_monitor->layout.height); - g_assert_cmpfloat (logical_monitor->scale, - ==, - test_logical_monitor->scale); - g_assert_cmpuint (logical_monitor->transform, - ==, - test_logical_monitor->transform); - - if (logical_monitor == monitor_manager->primary_logical_monitor) - g_assert (meta_logical_monitor_is_primary (logical_monitor)); - - primary_output = NULL; - monitors = meta_logical_monitor_get_monitors (logical_monitor); - g_assert_cmpint ((int) g_list_length (monitors), - ==, - test_logical_monitor->n_monitors); - - for (i = 0; i < test_logical_monitor->n_monitors; i++) - { - MetaMonitor *monitor = - g_list_nth (monitor_manager->monitors, - test_logical_monitor->monitors[i])->data; - - g_assert_nonnull (g_list_find (monitors, monitor)); - } - - for (l = monitors; l; l = l->next) - { - MetaMonitor *monitor = l->data; - GList *outputs; - GList *l_output; - - outputs = meta_monitor_get_outputs (monitor); - for (l_output = outputs; l_output; l_output = l_output->next) - { - MetaOutput *output = l_output->data; - MetaCrtc *crtc; - - if (output->is_primary) - { - g_assert_null (primary_output); - primary_output = output; - } - - crtc = meta_output_get_assigned_crtc (output); - g_assert (!crtc || - meta_monitor_get_logical_monitor (monitor) == logical_monitor); - g_assert_cmpint (logical_monitor->is_presentation, - ==, - output->is_presentation); - } - } - - if (logical_monitor == monitor_manager->primary_logical_monitor) - g_assert_nonnull (primary_output); -} - -static void -check_monitor_configuration (MonitorTestCase *test_case) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); - int tiled_monitor_count; - GList *monitors; - GList *crtcs; - int n_logical_monitors; - GList *l; - int i; - - g_assert_cmpint (monitor_manager->screen_width, - ==, - test_case->expect.screen_width); - g_assert_cmpint (monitor_manager->screen_height, - ==, - test_case->expect.screen_height); - g_assert_cmpint ((int) g_list_length (meta_gpu_get_outputs (gpu)), - ==, - test_case->expect.n_outputs); - g_assert_cmpint ((int) g_list_length (meta_gpu_get_crtcs (gpu)), - ==, - test_case->expect.n_crtcs); - - tiled_monitor_count = - meta_monitor_manager_test_get_tiled_monitor_count (monitor_manager_test); - g_assert_cmpint (tiled_monitor_count, - ==, - test_case->expect.n_tiled_monitors); - - monitors = meta_monitor_manager_get_monitors (monitor_manager); - g_assert_cmpint ((int) g_list_length (monitors), - ==, - test_case->expect.n_monitors); - for (l = monitors, i = 0; l; l = l->next, i++) - { - MetaMonitor *monitor = l->data; - GList *outputs; - GList *l_output; - int j; - int width_mm, height_mm; - GList *modes; - GList *l_mode; - MetaMonitorMode *current_mode; - int expected_current_mode_index; - MetaMonitorMode *expected_current_mode; - - outputs = meta_monitor_get_outputs (monitor); - - g_assert_cmpint ((int) g_list_length (outputs), - ==, - test_case->expect.monitors[i].n_outputs); - - for (l_output = outputs, j = 0; l_output; l_output = l_output->next, j++) - { - MetaOutput *output = l_output->data; - uint64_t winsys_id = test_case->expect.monitors[i].outputs[j]; - - g_assert (output == output_from_winsys_id (backend, winsys_id)); - g_assert_cmpint (test_case->expect.monitors[i].is_underscanning, - ==, - output->is_underscanning); - } - - meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm); - g_assert_cmpint (width_mm, - ==, - test_case->expect.monitors[i].width_mm); - g_assert_cmpint (height_mm, - ==, - test_case->expect.monitors[i].height_mm); - - modes = meta_monitor_get_modes (monitor); - g_assert_cmpint (g_list_length (modes), - ==, - test_case->expect.monitors[i].n_modes); - - for (l_mode = modes, j = 0; l_mode; l_mode = l_mode->next, j++) - { - MetaMonitorMode *mode = l_mode->data; - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; - CheckMonitorModeData data; - - meta_monitor_mode_get_resolution (mode, &width, &height); - refresh_rate = meta_monitor_mode_get_refresh_rate (mode); - flags = meta_monitor_mode_get_flags (mode); - - g_assert_cmpint (width, - ==, - test_case->expect.monitors[i].modes[j].width); - g_assert_cmpint (height, - ==, - test_case->expect.monitors[i].modes[j].height); - g_assert_cmpfloat (refresh_rate, - ==, - test_case->expect.monitors[i].modes[j].refresh_rate); - g_assert_cmpint (flags, - ==, - test_case->expect.monitors[i].modes[j].flags); - - data = (CheckMonitorModeData) { - .backend = backend, - .expect_crtc_mode_iter = - test_case->expect.monitors[i].modes[j].crtc_modes - }; - meta_monitor_mode_foreach_output (monitor, mode, - check_monitor_mode, - &data, - NULL); - } - - current_mode = meta_monitor_get_current_mode (monitor); - expected_current_mode_index = test_case->expect.monitors[i].current_mode; - if (expected_current_mode_index == -1) - expected_current_mode = NULL; - else - expected_current_mode = g_list_nth (modes, - expected_current_mode_index)->data; - - g_assert (current_mode == expected_current_mode); - if (current_mode) - g_assert (meta_monitor_is_active (monitor)); - else - g_assert (!meta_monitor_is_active (monitor)); - - if (current_mode) - { - CheckMonitorModeData data; - - data = (CheckMonitorModeData) { - .backend = backend, - .expect_crtc_mode_iter = - test_case->expect.monitors[i].modes[expected_current_mode_index].crtc_modes - }; - meta_monitor_mode_foreach_output (monitor, expected_current_mode, - check_current_monitor_mode, - &data, - NULL); - } - - meta_monitor_derive_current_mode (monitor); - g_assert (current_mode == meta_monitor_get_current_mode (monitor)); - } - - n_logical_monitors = - meta_monitor_manager_get_num_logical_monitors (monitor_manager); - g_assert_cmpint (n_logical_monitors, - ==, - test_case->expect.n_logical_monitors); - - /* - * Check that we have a primary logical monitor (except for headless), - * and that the main output of the first monitor is the only output - * that is marked as primary (further below). Note: outputs being primary or - * not only matters on X11. - */ - if (test_case->expect.primary_logical_monitor == -1) - { - g_assert_null (monitor_manager->primary_logical_monitor); - g_assert_null (monitor_manager->logical_monitors); - } - else - { - MonitorTestCaseLogicalMonitor *test_logical_monitor = - &test_case->expect.logical_monitors[test_case->expect.primary_logical_monitor]; - MetaLogicalMonitor *logical_monitor; - - logical_monitor = - logical_monitor_from_layout (monitor_manager, - &test_logical_monitor->layout); - g_assert (logical_monitor == monitor_manager->primary_logical_monitor); - } - - for (i = 0; i < test_case->expect.n_logical_monitors; i++) - { - MonitorTestCaseLogicalMonitor *test_logical_monitor = - &test_case->expect.logical_monitors[i]; - - check_logical_monitor (test_case, monitor_manager, test_logical_monitor); - } - g_assert_cmpint (n_logical_monitors, ==, i); - - crtcs = meta_gpu_get_crtcs (gpu); - for (l = crtcs, i = 0; l; l = l->next, i++) - { - MetaCrtc *crtc = l->data; - MetaCrtcConfig *crtc_config = crtc->config; - - if (test_case->expect.crtcs[i].current_mode == -1) - { - g_assert_null (crtc_config); - } - else - { - MetaCrtcMode *expected_current_mode; - - g_assert_nonnull (crtc_config); - - expected_current_mode = - g_list_nth_data (meta_gpu_get_modes (gpu), - test_case->expect.crtcs[i].current_mode); - g_assert (crtc_config->mode == expected_current_mode); - - g_assert_cmpuint (crtc_config->transform, - ==, - test_case->expect.crtcs[i].transform); - - g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.x, - test_case->expect.crtcs[i].x, - FLT_EPSILON); - g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.y, - test_case->expect.crtcs[i].y, - FLT_EPSILON); - } - } - - check_monitor_test_clients_state (); -} - -static void -meta_output_test_destroy_notify (MetaOutput *output) -{ - g_clear_pointer (&output->driver_private, g_free); -} - -static MetaMonitorTestSetup * -create_monitor_test_setup (MonitorTestCase *test_case, - MonitorTestFlag flags) -{ - MetaMonitorTestSetup *test_setup; - int i; - int n_laptop_panels = 0; - int n_normal_panels = 0; - gboolean hotplug_mode_update; - - if (flags & MONITOR_TEST_FLAG_NO_STORED) - hotplug_mode_update = TRUE; - else - hotplug_mode_update = FALSE; - - test_setup = g_new0 (MetaMonitorTestSetup, 1); - - test_setup->modes = NULL; - for (i = 0; i < test_case->setup.n_modes; i++) - { - MetaCrtcMode *mode; - - mode = g_object_new (META_TYPE_CRTC_MODE, NULL); - mode->mode_id = i; - mode->width = test_case->setup.modes[i].width; - mode->height = test_case->setup.modes[i].height; - mode->refresh_rate = test_case->setup.modes[i].refresh_rate; - mode->flags = test_case->setup.modes[i].flags; - - test_setup->modes = g_list_append (test_setup->modes, mode); - } - - test_setup->crtcs = NULL; - for (i = 0; i < test_case->setup.n_crtcs; i++) - { - MetaCrtc *crtc; - - crtc = g_object_new (META_TYPE_CRTC, NULL); - crtc->crtc_id = i + 1; - crtc->all_transforms = ALL_TRANSFORMS; - - test_setup->crtcs = g_list_append (test_setup->crtcs, crtc); - } - - test_setup->outputs = NULL; - for (i = 0; i < test_case->setup.n_outputs; i++) - { - MetaOutput *output; - MetaOutputTest *output_test; - int crtc_index; - MetaCrtc *crtc; - int preferred_mode_index; - MetaCrtcMode *preferred_mode; - MetaCrtcMode **modes; - int n_modes; - int j; - MetaCrtc **possible_crtcs; - int n_possible_crtcs; - int scale; - gboolean is_laptop_panel; - const char *serial; - - crtc_index = test_case->setup.outputs[i].crtc; - if (crtc_index == -1) - crtc = NULL; - else - crtc = g_list_nth_data (test_setup->crtcs, crtc_index); - - preferred_mode_index = test_case->setup.outputs[i].preferred_mode; - if (preferred_mode_index == -1) - preferred_mode = NULL; - else - preferred_mode = g_list_nth_data (test_setup->modes, - preferred_mode_index); - - n_modes = test_case->setup.outputs[i].n_modes; - modes = g_new0 (MetaCrtcMode *, n_modes); - for (j = 0; j < n_modes; j++) - { - int mode_index; - - mode_index = test_case->setup.outputs[i].modes[j]; - modes[j] = g_list_nth_data (test_setup->modes, mode_index); - } - - n_possible_crtcs = test_case->setup.outputs[i].n_possible_crtcs; - possible_crtcs = g_new0 (MetaCrtc *, n_possible_crtcs); - for (j = 0; j < n_possible_crtcs; j++) - { - int possible_crtc_index; - - possible_crtc_index = test_case->setup.outputs[i].possible_crtcs[j]; - possible_crtcs[j] = g_list_nth_data (test_setup->crtcs, - possible_crtc_index); - } - - output_test = g_new0 (MetaOutputTest, 1); - - scale = test_case->setup.outputs[i].scale; - if (scale < 1) - scale = 1; - - *output_test = (MetaOutputTest) { - .scale = scale - }; - - is_laptop_panel = test_case->setup.outputs[i].is_laptop_panel; - - serial = test_case->setup.outputs[i].serial; - if (!serial) - serial = "0x123456"; - - output = g_object_new (META_TYPE_OUTPUT, NULL); - - if (crtc) - meta_output_assign_crtc (output, crtc); - output->winsys_id = i; - output->name = (is_laptop_panel ? g_strdup_printf ("eDP-%d", - ++n_laptop_panels) - : g_strdup_printf ("DP-%d", - ++n_normal_panels)); - output->vendor = g_strdup ("MetaProduct's Inc."); - output->product = g_strdup ("MetaMonitor"); - output->serial = g_strdup (serial); - output->suggested_x = -1; - output->suggested_y = -1; - output->hotplug_mode_update = hotplug_mode_update; - output->width_mm = test_case->setup.outputs[i].width_mm; - output->height_mm = test_case->setup.outputs[i].height_mm; - output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN; - output->preferred_mode = preferred_mode; - output->n_modes = n_modes; - output->modes = modes; - output->n_possible_crtcs = n_possible_crtcs; - output->possible_crtcs = possible_crtcs; - output->n_possible_clones = 0; - output->possible_clones = NULL; - output->backlight = -1; - output->connector_type = (is_laptop_panel ? META_CONNECTOR_TYPE_eDP - : META_CONNECTOR_TYPE_DisplayPort); - output->tile_info = test_case->setup.outputs[i].tile_info; - output->is_underscanning = test_case->setup.outputs[i].is_underscanning; - output->panel_orientation_transform = - test_case->setup.outputs[i].panel_orientation_transform; - output->driver_private = output_test; - output->driver_notify = (GDestroyNotify) meta_output_test_destroy_notify; - - test_setup->outputs = g_list_append (test_setup->outputs, output); - } - - return test_setup; -} - static void meta_test_monitor_initial_linear_config (void) { - check_monitor_configuration (&initial_test_case); + check_monitor_configuration (&initial_test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1094,10 +330,11 @@ meta_test_monitor_one_disconnected_linear_config (void) .screen_height = 768 }; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1212,10 +449,11 @@ meta_test_monitor_one_off_linear_config (void) .screen_height = 768 }; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1332,10 +570,11 @@ meta_test_monitor_preferred_linear_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1461,10 +700,11 @@ meta_test_monitor_tiled_linear_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1634,10 +874,11 @@ meta_test_monitor_tiled_non_preferred_linear_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1783,10 +1024,11 @@ meta_test_monitor_tiled_non_main_origin_linear_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -1929,10 +1171,11 @@ meta_test_monitor_hidpi_linear_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2081,7 +1324,7 @@ meta_test_monitor_suggested_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); set_suggested_output_position (g_list_nth_data (test_setup->outputs, 0), @@ -2090,7 +1333,8 @@ meta_test_monitor_suggested_config (void) 0, 0); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2207,7 +1451,7 @@ meta_test_monitor_limited_crtcs (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, @@ -2216,7 +1460,8 @@ meta_test_monitor_limited_crtcs (void) emulate_hotplug (test_setup); g_test_assert_expected_messages (); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2350,10 +1595,11 @@ meta_test_monitor_lid_switch_config (void) MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); @@ -2370,7 +1616,8 @@ meta_test_monitor_lid_switch_config (void) test_case.expect.crtcs[0].current_mode = -1; test_case.expect.crtcs[1].x = 0; - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); @@ -2390,7 +1637,8 @@ meta_test_monitor_lid_switch_config (void) test_case.expect.crtcs[1].current_mode = 0; test_case.expect.crtcs[1].x = 1024; - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2523,12 +1771,13 @@ meta_test_monitor_lid_opened_config (void) MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); @@ -2541,7 +1790,8 @@ meta_test_monitor_lid_opened_config (void) test_case.expect.crtcs[1].current_mode = 0; test_case.expect.crtcs[1].x = 0; - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2629,12 +1879,13 @@ meta_test_monitor_lid_closed_no_external (void) MetaMonitorTestSetup *test_setup; MetaBackend *backend = meta_get_backend (); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2772,12 +2023,13 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) * 3) Close lid */ - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* External monitor connected */ @@ -2789,10 +2041,11 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.crtcs[1].x = 1024; test_case.expect.screen_width = 1024 * 2; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid closed */ @@ -2803,11 +2056,12 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.crtcs[1].x = 0; test_case.expect.screen_width = 1024; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* * The second part of this test emulate the following: @@ -2827,11 +2081,12 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.crtcs[1].x = 1024; test_case.expect.screen_width = 1024 * 2; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* External monitor disconnected */ @@ -2842,10 +2097,11 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.crtcs[1].current_mode = -1; test_case.expect.screen_width = 1024; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid closed */ @@ -2853,19 +2109,21 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void) test_case.expect.n_logical_monitors = 1; test_case.expect.screen_width = 1024; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid opened */ - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -2961,21 +2219,24 @@ meta_test_monitor_lid_scaled_closed_opened (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("lid-scale.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); meta_monitor_manager_lid_is_closed_changed (monitor_manager); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3002,11 +2263,12 @@ meta_test_monitor_no_outputs (void) MetaMonitorTestSetup *test_setup; GError *error = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); if (!test_client_do (x11_monitor_test_client, &error, "resize", X11_TEST_CLIENT_WINDOW, @@ -3023,11 +2285,12 @@ meta_test_monitor_no_outputs (void) check_monitor_test_clients_state (); /* Also check that we handle going headless -> headless */ - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3114,10 +2377,11 @@ meta_test_monitor_underscanning_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3209,10 +2473,11 @@ meta_test_monitor_preferred_non_first_mode (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3242,10 +2507,11 @@ meta_test_monitor_non_upright_panel (void) test_case.expect.crtcs[0].current_mode = 1; test_case.expect.crtcs[0].transform = META_MONITOR_TRANSFORM_90; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3380,12 +2646,13 @@ meta_test_monitor_custom_vertical_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("vertical.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3520,12 +2787,13 @@ meta_test_monitor_custom_primary_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("primary.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3612,12 +2880,13 @@ meta_test_monitor_custom_underscanning_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("underscanning.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3709,12 +2978,13 @@ meta_test_monitor_custom_scale_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("scale.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3806,12 +3076,13 @@ meta_test_monitor_custom_fractional_scale_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("fractional-scale.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -3903,12 +3174,13 @@ meta_test_monitor_custom_high_precision_fractional_scale_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("high-precision-fractional-scale.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4040,12 +3312,13 @@ meta_test_monitor_custom_tiled_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("tiled.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4197,12 +3470,13 @@ meta_test_monitor_custom_tiled_custom_resolution_config (void) return; } - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("tiled-custom-resolution.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4371,12 +3645,13 @@ meta_test_monitor_custom_tiled_non_preferred_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("non-preferred-tiled-custom-resolution.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4499,12 +3774,13 @@ meta_test_monitor_custom_mirrored_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("mirrored.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4635,11 +3911,12 @@ meta_test_monitor_custom_first_rotated_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("first-rotated.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4771,11 +4048,12 @@ meta_test_monitor_custom_second_rotated_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -4963,11 +4241,12 @@ meta_test_monitor_custom_second_rotated_tiled_config (void) meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, TRUE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated-tiled.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5155,11 +4434,12 @@ meta_test_monitor_custom_second_rotated_nonnative_tiled_config (void) meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, FALSE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated-tiled.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5305,11 +4585,12 @@ meta_test_monitor_custom_second_rotated_nonnative_config (void) meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, FALSE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("second-rotated.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5414,12 +4695,13 @@ meta_test_monitor_custom_interlaced_config (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("interlaced.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5543,12 +4825,13 @@ meta_test_monitor_custom_oneoff (void) }; MetaMonitorTestSetup *test_setup; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("oneoff.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5680,11 +4963,12 @@ meta_test_monitor_custom_lid_switch_config (void) MetaMonitorTestSetup *test_setup; MetaBackend *backend = meta_get_backend (); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); set_custom_monitor_config ("lid-switch.xml"); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* External monitor connected */ @@ -5702,10 +4986,11 @@ meta_test_monitor_custom_lid_switch_config (void) test_case.expect.n_logical_monitors = 2; test_case.expect.screen_width = 1024 + 768; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid was closed */ @@ -5721,10 +5006,11 @@ meta_test_monitor_custom_lid_switch_config (void) test_case.expect.screen_width = 768; meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); /* Lid was opened */ @@ -5743,10 +5029,11 @@ meta_test_monitor_custom_lid_switch_config (void) test_case.expect.screen_width = 1024 + 768; meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); } static void @@ -5847,7 +5134,7 @@ meta_test_monitor_migrated_rotated (void) g_autofree char *expected_data = NULL; g_autoptr (GFile) migrated_file = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); migrated_path = g_build_filename (g_get_tmp_dir (), @@ -5871,7 +5158,8 @@ meta_test_monitor_migrated_rotated (void) emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", @@ -5987,7 +5275,7 @@ meta_test_monitor_migrated_wiggle_discard (void) g_autofree char *expected_data = NULL; g_autoptr (GFile) migrated_file = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); migrated_path = g_build_filename (g_get_tmp_dir (), @@ -6015,7 +5303,8 @@ meta_test_monitor_migrated_wiggle_discard (void) emulate_hotplug (test_setup); g_test_assert_expected_messages (); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", @@ -6086,7 +5375,7 @@ meta_test_monitor_wm_tiling (void) MetaMonitorTestSetup *test_setup; g_autoptr (GError) error = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -6120,11 +5409,11 @@ meta_test_monitor_wm_tiling (void) fprintf(stderr, ":::: %s:%d %s() - UNPLUGGING\n", __FILE__, __LINE__, __func__); test_case.setup.n_outputs = 0; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); test_case.setup.n_outputs = 1; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -6139,7 +5428,7 @@ meta_test_monitor_wm_tiling (void) */ test_case.setup.n_outputs = 2; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -6147,7 +5436,7 @@ meta_test_monitor_wm_tiling (void) meta_window_tile (test_window, META_TILE_NONE); test_case.setup.n_outputs = 1; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NO_STORED); emulate_hotplug (test_setup); @@ -6254,7 +5543,7 @@ meta_test_monitor_migrated_wiggle (void) g_autofree char *expected_data = NULL; g_autoptr (GFile) migrated_file = NULL; - test_setup = create_monitor_test_setup (&test_case, + test_setup = create_monitor_test_setup (&test_case.setup, MONITOR_TEST_FLAG_NONE); migrated_path = g_build_filename (g_get_tmp_dir (), @@ -6278,7 +5567,8 @@ meta_test_monitor_migrated_wiggle (void) emulate_hotplug (test_setup); - check_monitor_configuration (&test_case); + check_monitor_configuration (&test_case.expect); + check_monitor_test_clients_state (); expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", @@ -6329,7 +5619,7 @@ init_monitor_tests (void) { MetaMonitorTestSetup *initial_test_setup; - initial_test_setup = create_monitor_test_setup (&initial_test_case, + initial_test_setup = create_monitor_test_setup (&initial_test_case.setup, MONITOR_TEST_FLAG_NO_STORED); meta_monitor_manager_test_init_test_setup (initial_test_setup);