tests: Also make test case verification declarative

Set up the expected result in a declarative way in the same place as
the test case setup is declared. This way we have a completely
declarative way to create test cases.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2016-12-07 14:18:28 +08:00
parent 376a76a082
commit d920eaba4a

View File

@ -67,9 +67,26 @@ typedef struct _MonitorTestCaseSetup
int n_crtcs; int n_crtcs;
} MonitorTestCaseSetup; } MonitorTestCaseSetup;
typedef struct _MonitorTestCaseLogicalMonitor
{
MetaRectangle layout;
int scale;
} MonitorTestCaseLogicalMonitor;
typedef struct _MonitorTestCaseExpect
{
MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS];
int n_logical_monitors;
int n_outputs;
int n_crtcs;
int screen_width;
int screen_height;
} MonitorTestCaseExpect;
typedef struct _MonitorTestCase typedef struct _MonitorTestCase
{ {
MonitorTestCaseSetup setup; MonitorTestCaseSetup setup;
MonitorTestCaseExpect expect;
} MonitorTestCase; } MonitorTestCase;
static MonitorTestCase initial_test_case = { static MonitorTestCase initial_test_case = {
@ -114,44 +131,64 @@ static MonitorTestCase initial_test_case = {
} }
}, },
.n_crtcs = 2 .n_crtcs = 2
},
.expect = {
.logical_monitors = {
{
.layout = { .x = 0, .y = 0, .width = 1024, .height = 768 },
.scale = 1
},
{
.layout = { .x = 1024, .y = 0, .width = 1024, .height = 768 },
.scale = 1
}
},
.n_logical_monitors = 2,
.n_outputs = 2,
.n_crtcs = 2,
.screen_width = 1024 * 2,
.screen_height = 768
} }
}; };
static void static void
meta_test_monitor_linear_config (void) check_monitor_configuration (MonitorTestCase *test_case)
{ {
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager = MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend); meta_backend_get_monitor_manager (backend);
GList *logical_monitors, *l; GList *logical_monitors;
int n_logical_monitors, i; int n_logical_monitors;
MetaRectangle expected_rects[] = { GList *l;
{ .x = 0, .y = 0, .width = 1024, .height = 768 }, int i;
{ .x = 1024, .y = 0, .width = 1024, .height = 768 },
};
g_assert (monitor_manager->screen_width == 1024 * 2); g_assert (monitor_manager->screen_width == test_case->expect.screen_width);
g_assert (monitor_manager->screen_height == 768); g_assert (monitor_manager->screen_height == test_case->expect.screen_height);
g_assert (monitor_manager->n_outputs == 2); g_assert ((int) monitor_manager->n_outputs == test_case->expect.n_outputs);
g_assert (monitor_manager->n_crtcs == 2); g_assert ((int) monitor_manager->n_crtcs == test_case->expect.n_crtcs);
n_logical_monitors = n_logical_monitors =
meta_monitor_manager_get_num_logical_monitors (monitor_manager); meta_monitor_manager_get_num_logical_monitors (monitor_manager);
g_assert (n_logical_monitors == 2); g_assert (n_logical_monitors == test_case->expect.n_logical_monitors);
logical_monitors = logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager); meta_monitor_manager_get_logical_monitors (monitor_manager);
i = 0; for (l = logical_monitors, i = 0; l; l = l->next, i++)
for (l = logical_monitors; l; l = l->next)
{ {
MetaLogicalMonitor *logical_monitor = l->data; MetaLogicalMonitor *logical_monitor = l->data;
MonitorTestCaseLogicalMonitor *test_logical_monitor =
&test_case->expect.logical_monitors[i];
g_assert (logical_monitor->rect.x == expected_rects[i].x); g_assert (logical_monitor->rect.x == test_logical_monitor->layout.x);
g_assert (logical_monitor->rect.y == expected_rects[i].y); g_assert (logical_monitor->rect.y == test_logical_monitor->layout.y);
g_assert (logical_monitor->rect.width == expected_rects[i].width); g_assert (logical_monitor->rect.width ==
g_assert (logical_monitor->rect.height == expected_rects[i].height); test_logical_monitor->layout.width);
i++; g_assert (logical_monitor->rect.height ==
test_logical_monitor->layout.height);
g_assert (logical_monitor->scale == test_logical_monitor->scale);
} }
g_assert (n_logical_monitors == i);
} }
static MetaMonitorTestSetup * static MetaMonitorTestSetup *
@ -270,6 +307,12 @@ create_monitor_test_setup (MonitorTestCase *test_case)
return test_setup; return test_setup;
} }
static void
meta_test_monitor_initial_linear_config (void)
{
check_monitor_configuration (&initial_test_case);
}
void void
init_monitor_tests (void) init_monitor_tests (void)
{ {
@ -278,6 +321,6 @@ init_monitor_tests (void)
initial_test_setup = create_monitor_test_setup (&initial_test_case); initial_test_setup = create_monitor_test_setup (&initial_test_case);
meta_monitor_manager_test_init_test_setup (initial_test_setup); meta_monitor_manager_test_init_test_setup (initial_test_setup);
g_test_add_func ("/backends/monitor/linear-config", g_test_add_func ("/backends/monitor/initial-linear-config",
meta_test_monitor_linear_config); meta_test_monitor_initial_linear_config);
} }