tests: Move monitor test utils into libmutter-test.so

It already was built into it without any symbols exported, but also
duplicated in test cases that used it. Make it so that the built in
functions are exported, with prefixes, and make all tests use the
exported functions. While at it, make things go via MetaContext or
MetaBackend depending on how early in initialization things are run.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2262>
This commit is contained in:
Jonas Ådahl 2022-01-28 16:28:32 +01:00 committed by Marge Bot
parent 3fc0d8b81d
commit afca974405
14 changed files with 617 additions and 426 deletions

View File

@ -148,7 +148,7 @@ meta_test_headless_monitor_connect (void)
} }
static MetaMonitorTestSetup * static MetaMonitorTestSetup *
create_headless_test_setup (void) create_headless_test_setup (MetaBackend *backend)
{ {
return g_new0 (MetaMonitorTestSetup, 1); return g_new0 (MetaMonitorTestSetup, 1);
} }
@ -156,7 +156,7 @@ create_headless_test_setup (void)
static void static void
init_tests (void) init_tests (void)
{ {
meta_monitor_manager_test_init_test_setup (create_headless_test_setup); meta_init_monitor_test_setup (create_headless_test_setup);
g_test_add_func ("/headless-start/start", meta_test_headless_start); g_test_add_func ("/headless-start/start", meta_test_headless_start);
g_test_add_func ("/headless-start/monitor-getters", g_test_add_func ("/headless-start/monitor-getters",

View File

@ -6,14 +6,14 @@ mutter_test_sources = [
'meta-gpu-test.h', 'meta-gpu-test.h',
'meta-monitor-manager-test.c', 'meta-monitor-manager-test.c',
'meta-monitor-manager-test.h', 'meta-monitor-manager-test.h',
'meta-monitor-test-utils.c',
'meta-monitor-test-utils.h',
'meta-ref-test.c', 'meta-ref-test.c',
'meta-ref-test.h', 'meta-ref-test.h',
'meta-sensors-proxy-mock.c', 'meta-sensors-proxy-mock.c',
'meta-sensors-proxy-mock.h', 'meta-sensors-proxy-mock.h',
'meta-test-utils.c', 'meta-test-utils.c',
'meta-test-utils.h', 'meta-test-utils.h',
'monitor-test-utils.c',
'monitor-test-utils.h',
] ]
libmutter_test_name = 'mutter-test-' + libmutter_api_version libmutter_test_name = 'mutter-test-' + libmutter_api_version
@ -139,8 +139,6 @@ unit_tests = executable('mutter-test-unit-tests',
'monitor-config-migration-unit-tests.h', 'monitor-config-migration-unit-tests.h',
'monitor-store-unit-tests.c', 'monitor-store-unit-tests.c',
'monitor-store-unit-tests.h', 'monitor-store-unit-tests.h',
'monitor-test-utils.c',
'monitor-test-utils.h',
'monitor-transform-tests.c', 'monitor-transform-tests.c',
'monitor-transform-tests.h', 'monitor-transform-tests.h',
'orientation-manager-unit-tests.c', 'orientation-manager-unit-tests.c',
@ -154,8 +152,6 @@ unit_tests = executable('mutter-test-unit-tests',
monitor_unit_tests = executable('mutter-monitor-unit-tests', monitor_unit_tests = executable('mutter-monitor-unit-tests',
sources: [ sources: [
'monitor-test-utils.c',
'monitor-test-utils.h',
'monitor-unit-tests.c', 'monitor-unit-tests.c',
], ],
include_directories: tests_includes, include_directories: tests_includes,
@ -178,8 +174,6 @@ headless_start_test = executable('mutter-headless-start-test',
stage_view_tests = executable('mutter-stage-view-tests', stage_view_tests = executable('mutter-stage-view-tests',
sources: [ sources: [
'monitor-test-utils.c',
'monitor-test-utils.h',
'stage-view-tests.c', 'stage-view-tests.c',
], ],
include_directories: tests_includes, include_directories: tests_includes,

View File

@ -27,7 +27,7 @@
#include "backends/meta-monitor-config-manager.h" #include "backends/meta-monitor-config-manager.h"
#include "backends/meta-output.h" #include "backends/meta-output.h"
#include "tests/meta-backend-test.h" #include "tests/meta-backend-test.h"
#include "tests/monitor-test-utils.h" #include "tests/meta-monitor-test-utils.h"
G_DEFINE_TYPE (MetaCrtcTest, meta_crtc_test, META_TYPE_CRTC) G_DEFINE_TYPE (MetaCrtcTest, meta_crtc_test, META_TYPE_CRTC)
G_DEFINE_TYPE (MetaOutputTest, meta_output_test, META_TYPE_OUTPUT) G_DEFINE_TYPE (MetaOutputTest, meta_output_test, META_TYPE_OUTPUT)
@ -46,10 +46,49 @@ struct _MetaMonitorManagerTest
G_DEFINE_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test, G_DEFINE_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test,
META_TYPE_MONITOR_MANAGER) META_TYPE_MONITOR_MANAGER)
static CreateTestSetupFunc initial_setup_func; static MetaCreateTestSetupFunc initial_setup_func;
static MonitorTestCaseSetup default_test_case_setup = {
.modes = {
{
.width = 800,
.height = 600,
.refresh_rate = 60.0
}
},
.n_modes = 1,
.outputs = {
{
.crtc = 0,
.modes = { 0 },
.n_modes = 1,
.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,
};
static MetaMonitorTestSetup *
create_default_test_setup (MetaBackend *backend)
{
return meta_create_monitor_test_setup (backend,
&default_test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
}
void void
meta_monitor_manager_test_init_test_setup (CreateTestSetupFunc func) meta_init_monitor_test_setup (MetaCreateTestSetupFunc func)
{ {
initial_setup_func = func; initial_setup_func = func;
} }
@ -381,6 +420,21 @@ meta_monitor_manager_test_get_default_layout_mode (MetaMonitorManager *manager)
return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL; return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
} }
static void
meta_monitor_manager_test_constructed (GObject *object)
{
MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (object);
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_test);
MetaBackend *backend = meta_monitor_manager_get_backend (manager);
if (initial_setup_func)
manager_test->test_setup = initial_setup_func (backend);
else
manager_test->test_setup = create_default_test_setup (backend);
G_OBJECT_CLASS (meta_monitor_manager_test_parent_class)->constructed (object);
}
static void static void
meta_monitor_manager_test_dispose (GObject *object) meta_monitor_manager_test_dispose (GObject *object)
{ {
@ -391,57 +445,6 @@ meta_monitor_manager_test_dispose (GObject *object)
G_OBJECT_CLASS (meta_monitor_manager_test_parent_class)->dispose (object); G_OBJECT_CLASS (meta_monitor_manager_test_parent_class)->dispose (object);
} }
static MonitorTestCaseSetup default_test_case_setup = {
.modes = {
{
.width = 800,
.height = 600,
.refresh_rate = 60.0
}
},
.n_modes = 1,
.outputs = {
{
.crtc = 0,
.modes = { 0 },
.n_modes = 1,
.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,
};
static MetaMonitorTestSetup *
create_default_test_setup (void)
{
return create_monitor_test_setup (&default_test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
}
static void
meta_monitor_manager_test_constructed (GObject *object)
{
MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (object);
if (initial_setup_func)
manager_test->test_setup = initial_setup_func ();
else
manager_test->test_setup = create_default_test_setup ();
G_OBJECT_CLASS (meta_monitor_manager_test_parent_class)->constructed (object);
}
static void static void
meta_monitor_manager_test_init (MetaMonitorManagerTest *manager_test) meta_monitor_manager_test_init (MetaMonitorManagerTest *manager_test)
{ {
@ -454,8 +457,8 @@ meta_monitor_manager_test_class_init (MetaMonitorManagerTestClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass); MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass);
object_class->dispose = meta_monitor_manager_test_dispose;
object_class->constructed = meta_monitor_manager_test_constructed; object_class->constructed = meta_monitor_manager_test_constructed;
object_class->dispose = meta_monitor_manager_test_dispose;
manager_class->ensure_initial_config = meta_monitor_manager_test_ensure_initial_config; manager_class->ensure_initial_config = meta_monitor_manager_test_ensure_initial_config;
manager_class->apply_monitors_config = meta_monitor_manager_test_apply_monitors_config; manager_class->apply_monitors_config = meta_monitor_manager_test_apply_monitors_config;

View File

@ -44,7 +44,7 @@ struct _MetaOutputTest
float scale; float scale;
}; };
typedef MetaMonitorTestSetup * (* CreateTestSetupFunc) (void); typedef MetaMonitorTestSetup * (* MetaCreateTestSetupFunc) (MetaBackend *backend);
#define META_TYPE_CRTC_TEST (meta_crtc_test_get_type ()) #define META_TYPE_CRTC_TEST (meta_crtc_test_get_type ())
META_EXPORT META_EXPORT
@ -64,7 +64,7 @@ G_DECLARE_FINAL_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test,
META, MONITOR_MANAGER_TEST, MetaMonitorManager) META, MONITOR_MANAGER_TEST, MetaMonitorManager)
META_EXPORT META_EXPORT
void meta_monitor_manager_test_init_test_setup (CreateTestSetupFunc func); void meta_init_monitor_test_setup (MetaCreateTestSetupFunc func);
META_EXPORT META_EXPORT
void meta_monitor_manager_test_read_current (MetaMonitorManager *manager); void meta_monitor_manager_test_read_current (MetaMonitorManager *manager);

View File

@ -19,7 +19,7 @@
#include "config.h" #include "config.h"
#include "tests/monitor-test-utils.h" #include "tests/meta-monitor-test-utils.h"
#include <float.h> #include <float.h>
@ -33,33 +33,31 @@
#include "meta-backend-test.h" #include "meta-backend-test.h"
MetaGpu * MetaGpu *
test_get_gpu (void) meta_test_get_gpu (MetaBackend *backend)
{ {
return META_GPU (meta_backend_get_gpus (meta_get_backend ())->data); return META_GPU (meta_backend_get_gpus (backend)->data);
}
static void
set_custom_monitor_config_common (const char *filename,
MetaMonitorsConfigFlag configs_flags)
{
meta_set_custom_monitor_config (meta_get_backend (), filename, configs_flags);
} }
void void
set_custom_monitor_config (const char *filename) meta_set_custom_monitor_config (MetaContext *context,
const char *filename)
{ {
set_custom_monitor_config_common (filename, META_MONITORS_CONFIG_FLAG_NONE); meta_set_custom_monitor_config_full (meta_context_get_backend (context),
filename,
META_MONITORS_CONFIG_FLAG_NONE);
} }
void void
set_custom_monitor_system_config (const char *filename) meta_set_custom_monitor_system_config (MetaContext *context,
const char *filename)
{ {
set_custom_monitor_config_common (filename, meta_set_custom_monitor_config_full (meta_context_get_backend (context),
META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG); filename,
META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG);
} }
char * char *
read_file (const char *file_path) meta_read_file (const char *file_path)
{ {
g_autoptr (GFile) file = NULL; g_autoptr (GFile) file = NULL;
g_autoptr (GFileInputStream) input_stream = NULL; g_autoptr (GFileInputStream) input_stream = NULL;
@ -322,9 +320,10 @@ check_logical_monitor (MetaMonitorManager *monitor_manager,
} }
void void
check_monitor_configuration (MonitorTestCaseExpect *expect) meta_check_monitor_configuration (MetaContext *context,
MonitorTestCaseExpect *expect)
{ {
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = meta_context_get_backend (context);
MetaRenderer *renderer = meta_backend_get_renderer (backend); MetaRenderer *renderer = meta_backend_get_renderer (backend);
MetaMonitorManager *monitor_manager = MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend); meta_backend_get_monitor_manager (backend);
@ -621,8 +620,9 @@ check_monitor_configuration (MonitorTestCaseExpect *expect)
} }
MetaMonitorTestSetup * MetaMonitorTestSetup *
create_monitor_test_setup (MonitorTestCaseSetup *setup, meta_create_monitor_test_setup (MetaBackend *backend,
MonitorTestFlag flags) MonitorTestCaseSetup *setup,
MonitorTestFlag flags)
{ {
MetaMonitorTestSetup *test_setup; MetaMonitorTestSetup *test_setup;
int i; int i;
@ -658,7 +658,7 @@ create_monitor_test_setup (MonitorTestCaseSetup *setup,
crtc = g_object_new (META_TYPE_CRTC_TEST, crtc = g_object_new (META_TYPE_CRTC_TEST,
"id", (uint64_t) i + 1, "id", (uint64_t) i + 1,
"gpu", test_get_gpu (), "gpu", meta_test_get_gpu (backend),
NULL); NULL);
test_setup->crtcs = g_list_append (test_setup->crtcs, crtc); test_setup->crtcs = g_list_append (test_setup->crtcs, crtc);
@ -765,7 +765,7 @@ create_monitor_test_setup (MonitorTestCaseSetup *setup,
output = g_object_new (META_TYPE_OUTPUT_TEST, output = g_object_new (META_TYPE_OUTPUT_TEST,
"id", (uint64_t) i, "id", (uint64_t) i,
"gpu", test_get_gpu (), "gpu", meta_test_get_gpu (backend),
"info", output_info, "info", output_info,
NULL); NULL);
@ -828,12 +828,13 @@ check_expected_scales (MetaMonitor *monitor,
} }
} }
void check_monitor_scales (MonitorTestCaseExpect *expect, void
meta_check_monitor_scales (MetaContext *context,
MonitorTestCaseExpect *expect,
MetaMonitorScalesConstraint scales_constraints) MetaMonitorScalesConstraint scales_constraints)
{ {
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager = MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend); meta_backend_get_monitor_manager (meta_context_get_backend (context));
GList *monitors; GList *monitors;
GList *l; GList *l;

View File

@ -197,27 +197,43 @@ typedef struct _MonitorTestCase
MonitorTestCaseExpect expect; MonitorTestCaseExpect expect;
} MonitorTestCase; } MonitorTestCase;
MetaGpu * test_get_gpu (void); META_EXPORT
MetaGpu * meta_test_get_gpu (MetaBackend *backend);
void set_custom_monitor_config (const char *filename); META_EXPORT
void meta_set_custom_monitor_config (MetaContext *context,
const char *filename);
void set_custom_monitor_system_config (const char *filename); META_EXPORT
void meta_set_custom_monitor_system_config (MetaContext *context,
const char *filename);
char * read_file (const char *file_path); META_EXPORT
char * meta_read_file (const char *file_path);
void check_monitor_configuration (MonitorTestCaseExpect *expect); META_EXPORT
void check_monitor_scales (MonitorTestCaseExpect *expect, void meta_check_monitor_configuration (MetaContext *context,
MetaMonitorScalesConstraint scales_constraints); MonitorTestCaseExpect *expect);
MetaMonitorTestSetup * create_monitor_test_setup (MonitorTestCaseSetup *setup, META_EXPORT
MonitorTestFlag flags); void meta_check_monitor_scales (MetaContext *context,
MonitorTestCaseExpect *expect,
MetaMonitorScalesConstraint scales_constraints);
META_EXPORT
MetaMonitorTestSetup * meta_create_monitor_test_setup (MetaBackend *backend,
MonitorTestCaseSetup *setup,
MonitorTestFlag flags);
META_EXPORT
const char * meta_orientation_to_string (MetaOrientation orientation); const char * meta_orientation_to_string (MetaOrientation orientation);
META_EXPORT
void meta_wait_for_orientation (MetaOrientationManager *orientation_manager, void meta_wait_for_orientation (MetaOrientationManager *orientation_manager,
MetaOrientation orientation, MetaOrientation orientation,
unsigned int *times_signalled_out); unsigned int *times_signalled_out);
META_EXPORT
void meta_wait_for_possible_orientation_change (MetaOrientationManager *orientation_manager, void meta_wait_for_possible_orientation_change (MetaOrientationManager *orientation_manager,
unsigned int *times_signalled_out); unsigned int *times_signalled_out);

View File

@ -596,9 +596,9 @@ meta_test_get_plugin_name (void)
} }
void void
meta_set_custom_monitor_config (MetaBackend *backend, meta_set_custom_monitor_config_full (MetaBackend *backend,
const char *filename, const char *filename,
MetaMonitorsConfigFlag configs_flags) MetaMonitorsConfigFlag configs_flags)
{ {
MetaMonitorManager *monitor_manager = MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend); meta_backend_get_monitor_manager (backend);

View File

@ -114,9 +114,9 @@ META_EXPORT
const char * meta_test_get_plugin_name (void); const char * meta_test_get_plugin_name (void);
META_EXPORT META_EXPORT
void meta_set_custom_monitor_config (MetaBackend *backend, void meta_set_custom_monitor_config_full (MetaBackend *backend,
const char *filename, const char *filename,
MetaMonitorsConfigFlag configs_flags); MetaMonitorsConfigFlag configs_flags);
META_EXPORT META_EXPORT
void meta_wait_for_paint (MetaContext *context); void meta_wait_for_paint (MetaContext *context);

View File

@ -29,7 +29,7 @@
#include "backends/meta-monitor-config-store.h" #include "backends/meta-monitor-config-store.h"
#include "backends/meta-monitor-manager-private.h" #include "backends/meta-monitor-manager-private.h"
#include "backends/meta-monitor-config-migration.h" #include "backends/meta-monitor-config-migration.h"
#include "tests/monitor-test-utils.h" #include "tests/meta-monitor-test-utils.h"
static void static void
test_migration (const char *old_config, test_migration (const char *old_config,
@ -70,8 +70,8 @@ test_migration (const char *old_config,
expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration",
new_config, NULL); new_config, NULL);
expected_data = read_file (expected_path); expected_data = meta_read_file (expected_path);
migrated_data = read_file (migrated_path); migrated_data = meta_read_file (migrated_path);
g_assert_nonnull (expected_data); g_assert_nonnull (expected_data);
g_assert_nonnull (migrated_data); g_assert_nonnull (migrated_data);

View File

@ -25,7 +25,7 @@
#include "backends/meta-monitor-config-store.h" #include "backends/meta-monitor-config-store.h"
#include "backends/meta-monitor-config-manager.h" #include "backends/meta-monitor-config-manager.h"
#include "backends/meta-monitor-manager-private.h" #include "backends/meta-monitor-manager-private.h"
#include "tests/monitor-test-utils.h" #include "tests/meta-monitor-test-utils.h"
#include "tests/unit-tests.h" #include "tests/unit-tests.h"
#define MAX_N_MONITORS 10 #define MAX_N_MONITORS 10
@ -258,7 +258,7 @@ meta_test_monitor_store_single (void)
.n_configurations = 1 .n_configurations = 1
}; };
set_custom_monitor_config ("single.xml"); meta_set_custom_monitor_config (test_context, "single.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -327,7 +327,7 @@ meta_test_monitor_store_vertical (void)
.n_configurations = 1 .n_configurations = 1
}; };
set_custom_monitor_config ("vertical.xml"); meta_set_custom_monitor_config (test_context, "vertical.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -396,7 +396,7 @@ meta_test_monitor_store_primary (void)
.n_configurations = 1 .n_configurations = 1
}; };
set_custom_monitor_config ("primary.xml"); meta_set_custom_monitor_config (test_context, "primary.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -441,7 +441,7 @@ meta_test_monitor_store_underscanning (void)
.n_configurations = 1 .n_configurations = 1
}; };
set_custom_monitor_config ("underscanning.xml"); meta_set_custom_monitor_config (test_context, "underscanning.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -491,7 +491,7 @@ meta_test_monitor_store_scale (void)
return; return;
} }
set_custom_monitor_config ("scale.xml"); meta_set_custom_monitor_config (test_context, "scale.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -541,7 +541,7 @@ meta_test_monitor_store_fractional_scale (void)
return; return;
} }
set_custom_monitor_config ("fractional-scale.xml"); meta_set_custom_monitor_config (test_context, "fractional-scale.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -591,7 +591,7 @@ meta_test_monitor_store_high_precision_fractional_scale (void)
return; return;
} }
set_custom_monitor_config ("high-precision-fractional-scale.xml"); meta_set_custom_monitor_config (test_context, "high-precision-fractional-scale.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -645,7 +645,7 @@ meta_test_monitor_store_mirrored (void)
.n_configurations = 1 .n_configurations = 1
}; };
set_custom_monitor_config ("mirrored.xml"); meta_set_custom_monitor_config (test_context, "mirrored.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -716,7 +716,7 @@ meta_test_monitor_store_first_rotated (void)
.n_configurations = 1 .n_configurations = 1
}; };
set_custom_monitor_config ("first-rotated.xml"); meta_set_custom_monitor_config (test_context, "first-rotated.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -787,7 +787,7 @@ meta_test_monitor_store_second_rotated (void)
.n_configurations = 1 .n_configurations = 1
}; };
set_custom_monitor_config ("second-rotated.xml"); meta_set_custom_monitor_config (test_context, "second-rotated.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -832,7 +832,7 @@ meta_test_monitor_store_interlaced (void)
.n_configurations = 1 .n_configurations = 1
}; };
set_custom_monitor_config ("interlaced.xml"); meta_set_custom_monitor_config (test_context, "interlaced.xml");
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
} }
@ -885,7 +885,7 @@ meta_test_monitor_store_unknown_elements (void)
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"Unknown element <unknownunderlogicalmonitor> " "Unknown element <unknownunderlogicalmonitor> "
"under <logicalmonitor>, ignoring"); "under <logicalmonitor>, ignoring");
set_custom_monitor_config ("unknown-elements.xml"); meta_set_custom_monitor_config (test_context, "unknown-elements.xml");
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
check_monitor_store_configurations (&expect); check_monitor_store_configurations (&expect);
@ -897,7 +897,7 @@ meta_test_monitor_store_policy_not_allowed (void)
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*Policy can only be defined in system level " "*Policy can only be defined in system level "
"configurations*"); "configurations*");
set_custom_monitor_config ("policy.xml"); meta_set_custom_monitor_config (test_context, "policy.xml");
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
} }
@ -912,7 +912,7 @@ meta_test_monitor_store_policy (void)
meta_monitor_config_manager_get_store (config_manager); meta_monitor_config_manager_get_store (config_manager);
GList *stores_policy; GList *stores_policy;
set_custom_monitor_system_config ("policy.xml"); meta_set_custom_monitor_system_config (test_context, "policy.xml");
stores_policy = meta_monitor_config_store_get_stores_policy (config_store); stores_policy = meta_monitor_config_store_get_stores_policy (config_store);
g_assert_cmpuint (g_list_length (stores_policy), ==, 1); g_assert_cmpuint (g_list_length (stores_policy), ==, 1);
g_assert_cmpint (GPOINTER_TO_INT (stores_policy->data), g_assert_cmpint (GPOINTER_TO_INT (stores_policy->data),
@ -925,7 +925,7 @@ meta_test_monitor_store_policy_empty (void)
{ {
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*Invalid store*"); "*Invalid store*");
set_custom_monitor_system_config ("policy-empty.xml"); meta_set_custom_monitor_system_config (test_context, "policy-empty.xml");
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
} }
@ -934,7 +934,7 @@ meta_test_monitor_store_policy_duplicate (void)
{ {
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*Multiple identical stores*"); "*Multiple identical stores*");
set_custom_monitor_system_config ("policy-duplicate.xml"); meta_set_custom_monitor_system_config (test_context, "policy-duplicate.xml");
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
} }
@ -943,7 +943,7 @@ meta_test_monitor_store_policy_invalid (void)
{ {
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*Invalid store*"); "*Invalid store*");
set_custom_monitor_system_config ("policy-invalid.xml"); meta_set_custom_monitor_system_config (test_context, "policy-invalid.xml");
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
} }
@ -952,7 +952,7 @@ meta_test_monitor_store_policy_multiple (void)
{ {
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*Multiple stores elements under policy*"); "*Multiple stores elements under policy*");
set_custom_monitor_system_config ("policy-multiple.xml"); meta_set_custom_monitor_system_config (test_context, "policy-multiple.xml");
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
} }
@ -972,7 +972,7 @@ meta_test_monitor_store_policy_dbus (void)
g_assert_nonnull (policy); g_assert_nonnull (policy);
g_assert_cmpint (policy->enable_dbus, ==, TRUE); g_assert_cmpint (policy->enable_dbus, ==, TRUE);
set_custom_monitor_system_config ("policy-dbus.xml"); meta_set_custom_monitor_system_config (test_context, "policy-dbus.xml");
policy = meta_monitor_config_store_get_policy (config_store); policy = meta_monitor_config_store_get_policy (config_store);
g_assert_nonnull (policy); g_assert_nonnull (policy);
@ -993,7 +993,8 @@ meta_test_monitor_store_policy_dbus_invalid (void)
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*Multiple dbus elements under policy*"); "*Multiple dbus elements under policy*");
set_custom_monitor_system_config ("policy-dbus-invalid.xml"); meta_set_custom_monitor_system_config (test_context,
"policy-dbus-invalid.xml");
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
policy = meta_monitor_config_store_get_policy (config_store); policy = meta_monitor_config_store_get_policy (config_store);

File diff suppressed because it is too large Load Diff

View File

@ -66,8 +66,8 @@ meta_test_warp_on_hotplug (void)
virtual_pointer = clutter_seat_create_virtual_device (seat, virtual_pointer = clutter_seat_create_virtual_device (seat,
CLUTTER_POINTER_DEVICE); CLUTTER_POINTER_DEVICE);
meta_set_custom_monitor_config (backend, "pointer-constraint.xml", meta_set_custom_monitor_config_full (backend, "pointer-constraint.xml",
META_MONITORS_CONFIG_FLAG_NONE); META_MONITORS_CONFIG_FLAG_NONE);
monitor_info1 = meta_virtual_monitor_info_new (100, 100, 60.0, monitor_info1 = meta_virtual_monitor_info_new (100, 100, 60.0,
"MetaTestVendor", "MetaTestVendor",

View File

@ -22,8 +22,8 @@
#include "orientation-manager-unit-tests.h" #include "orientation-manager-unit-tests.h"
#include "tests/meta-monitor-test-utils.h"
#include "tests/meta-sensors-proxy-mock.h" #include "tests/meta-sensors-proxy-mock.h"
#include "tests/monitor-test-utils.h"
static void static void
meta_test_orientation_manager_no_daemon (void) meta_test_orientation_manager_no_daemon (void)

View File

@ -23,14 +23,15 @@
#include "meta-test/meta-context-test.h" #include "meta-test/meta-context-test.h"
#include "meta/meta-window-actor.h" #include "meta/meta-window-actor.h"
#include "tests/meta-backend-test.h" #include "tests/meta-backend-test.h"
#include "tests/meta-monitor-test-utils.h"
#include "tests/meta-test-utils.h" #include "tests/meta-test-utils.h"
#include "tests/monitor-test-utils.h"
#include "x11/meta-x11-display-private.h" #include "x11/meta-x11-display-private.h"
#define X11_TEST_CLIENT_NAME "x11_test_client" #define X11_TEST_CLIENT_NAME "x11_test_client"
#define X11_TEST_CLIENT_WINDOW "window1" #define X11_TEST_CLIENT_WINDOW "window1"
static MetaContext *test_context; static MetaContext *test_context;
static MetaBackend *test_backend;
static MonitorTestCaseSetup initial_test_case_setup = { static MonitorTestCaseSetup initial_test_case_setup = {
.modes = { .modes = {
@ -480,10 +481,11 @@ meta_test_actor_stage_views_hide_parent (void)
} }
static MetaMonitorTestSetup * static MetaMonitorTestSetup *
create_stage_view_test_setup (void) create_stage_view_test_setup (MetaBackend *backend)
{ {
return create_monitor_test_setup (&initial_test_case_setup, return meta_create_monitor_test_setup (backend,
MONITOR_TEST_FLAG_NO_STORED); &initial_test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
} }
static void static void
@ -546,8 +548,9 @@ meta_test_actor_stage_views_hot_plug (void)
prev_stage_views = g_list_copy_deep (stage_views, prev_stage_views = g_list_copy_deep (stage_views,
(GCopyFunc) g_object_ref, NULL); (GCopyFunc) g_object_ref, NULL);
test_setup = create_monitor_test_setup (&hotplug_test_case_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &hotplug_test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage));
@ -596,8 +599,9 @@ meta_test_actor_stage_views_frame_clock (void)
frame_clock_test_setup.n_modes = 2; frame_clock_test_setup.n_modes = 2;
frame_clock_test_setup.outputs[1].modes[0] = 1; frame_clock_test_setup.outputs[1].modes[0] = 1;
frame_clock_test_setup.outputs[1].preferred_mode = 1; frame_clock_test_setup.outputs[1].preferred_mode = 1;
test_setup = create_monitor_test_setup (&frame_clock_test_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &frame_clock_test_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage));
@ -740,8 +744,9 @@ meta_test_actor_stage_views_timeline (void)
frame_clock_test_setup.n_modes = 2; frame_clock_test_setup.n_modes = 2;
frame_clock_test_setup.outputs[1].modes[0] = 1; frame_clock_test_setup.outputs[1].modes[0] = 1;
frame_clock_test_setup.outputs[1].preferred_mode = 1; frame_clock_test_setup.outputs[1].preferred_mode = 1;
test_setup = create_monitor_test_setup (&frame_clock_test_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &frame_clock_test_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage));
@ -819,8 +824,9 @@ meta_test_actor_stage_views_parent_views_rebuilt (void)
frame_clock_test_setup = initial_test_case_setup; frame_clock_test_setup = initial_test_case_setup;
frame_clock_test_setup.n_outputs = 1; frame_clock_test_setup.n_outputs = 1;
frame_clock_test_setup.n_crtcs = 1; frame_clock_test_setup.n_crtcs = 1;
test_setup = create_monitor_test_setup (&frame_clock_test_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &frame_clock_test_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage));
@ -856,8 +862,9 @@ meta_test_actor_stage_views_parent_views_rebuilt (void)
old_frame_clock = old_frame_clock =
g_object_ref (clutter_stage_view_get_frame_clock (old_stage_view)); g_object_ref (clutter_stage_view_get_frame_clock (old_stage_view));
test_setup = create_monitor_test_setup (&frame_clock_test_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &frame_clock_test_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
wait_for_paint (stage); wait_for_paint (stage);
@ -900,8 +907,9 @@ meta_test_actor_stage_views_parent_views_changed (void)
stage = meta_backend_get_stage (backend); stage = meta_backend_get_stage (backend);
frame_clock_test_setup = initial_test_case_setup; frame_clock_test_setup = initial_test_case_setup;
test_setup = create_monitor_test_setup (&frame_clock_test_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &frame_clock_test_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage));
@ -1043,8 +1051,9 @@ meta_test_actor_stage_views_and_frame_clocks_freed (void)
frame_clock_test_setup = initial_test_case_setup; frame_clock_test_setup = initial_test_case_setup;
frame_clock_test_setup.n_outputs = 0; frame_clock_test_setup.n_outputs = 0;
frame_clock_test_setup.n_crtcs = 0; frame_clock_test_setup.n_crtcs = 0;
test_setup = create_monitor_test_setup (&frame_clock_test_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &frame_clock_test_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
timeline_frame_clock = clutter_timeline_get_frame_clock (timeline); timeline_frame_clock = clutter_timeline_get_frame_clock (timeline);
@ -1075,8 +1084,9 @@ ensure_view_count (int n_views)
test_case_setup = initial_test_case_setup; test_case_setup = initial_test_case_setup;
test_case_setup.n_outputs = n_views; test_case_setup.n_outputs = n_views;
test_case_setup.n_crtcs = n_views; test_case_setup.n_crtcs = n_views;
test_setup = create_monitor_test_setup (&test_case_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage));
@ -1148,8 +1158,9 @@ meta_test_actor_stage_views_queue_frame_drawn (void)
/* Make sure we have a single output. */ /* Make sure we have a single output. */
hotplug_test_case_setup.n_outputs = 1; hotplug_test_case_setup.n_outputs = 1;
hotplug_test_case_setup.n_crtcs = 1; hotplug_test_case_setup.n_crtcs = 1;
test_setup = create_monitor_test_setup (&hotplug_test_case_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &hotplug_test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
wait_for_paint (stage); wait_for_paint (stage);
g_assert_cmpint (g_list_length (clutter_actor_peek_stage_views (stage)), g_assert_cmpint (g_list_length (clutter_actor_peek_stage_views (stage)),
@ -1171,8 +1182,9 @@ meta_test_actor_stage_views_queue_frame_drawn (void)
meta_window_actor_queue_frame_drawn (META_WINDOW_ACTOR (window_actor), TRUE); meta_window_actor_queue_frame_drawn (META_WINDOW_ACTOR (window_actor), TRUE);
/* Hotplug to rebuild the views, will clear the window actor view list. */ /* Hotplug to rebuild the views, will clear the window actor view list. */
test_setup = create_monitor_test_setup (&hotplug_test_case_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &hotplug_test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
g_assert_null (clutter_actor_peek_stage_views (window_actor)); g_assert_null (clutter_actor_peek_stage_views (window_actor));
@ -1183,8 +1195,9 @@ meta_test_actor_stage_views_queue_frame_drawn (void)
/* Hotplug again to re-rebuild the views, will again clear the window actor /* Hotplug again to re-rebuild the views, will again clear the window actor
* view list, which will be a no-op. */ * view list, which will be a no-op. */
test_setup = create_monitor_test_setup (&hotplug_test_case_setup, test_setup = meta_create_monitor_test_setup (test_backend,
MONITOR_TEST_FLAG_NO_STORED); &hotplug_test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup);
/* Make sure we're not using some old frame clock when queuing another /* Make sure we're not using some old frame clock when queuing another
@ -1306,10 +1319,16 @@ meta_test_timeline_actor_tree_clear (void)
clutter_actor_destroy (container2); clutter_actor_destroy (container2);
} }
static void
on_before_tests (MetaContext *context)
{
test_backend = meta_context_get_backend (context);
}
static void static void
init_tests (void) init_tests (void)
{ {
meta_monitor_manager_test_init_test_setup (create_stage_view_test_setup); meta_init_monitor_test_setup (create_stage_view_test_setup);
g_test_add_func ("/stage-view/stage-views-exist", g_test_add_func ("/stage-view/stage-views-exist",
meta_test_stage_views_exist); meta_test_stage_views_exist);
@ -1356,6 +1375,8 @@ main (int argc, char *argv[])
init_tests (); init_tests ();
g_signal_connect (context, "before-tests",
G_CALLBACK (on_before_tests), NULL);
return meta_context_test_run_tests (META_CONTEXT_TEST (context), return meta_context_test_run_tests (META_CONTEXT_TEST (context),
META_TEST_RUN_FLAG_NONE); META_TEST_RUN_FLAG_NONE);
} }