[mutter] tests/monitor-unit-tests: Set initial state during backend construction



commit 2724f36527fc32abbcff835099f0d9cd9644e2c4
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Feb 25 10:18:22 2020 +0100

    tests/monitor-unit-tests: Set initial state during backend construction
    
    This way we can construct CRTCs and Outputs and associated them with the
    fake GPUs at construction.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1287

 src/tests/headless-start-test.c       |  5 +----
 src/tests/meta-monitor-manager-test.c | 23 ++++++++++++++++-------
 src/tests/meta-monitor-manager-test.h |  4 +++-
 src/tests/monitor-test-utils.h        |  4 ++--
 src/tests/monitor-unit-tests.c        | 13 ++++++++-----
 src/tests/monitor-unit-tests.h        |  7 +++++++
 src/tests/stage-view-tests.c          | 14 ++++++++------
 7 files changed, 45 insertions(+), 25 deletions(-)
---
diff --git a/src/tests/headless-start-test.c b/src/tests/headless-start-test.c
index 95ba3fa533..16a7fd4714 100644
--- a/src/tests/headless-start-test.c
+++ b/src/tests/headless-start-test.c
@@ -184,10 +184,7 @@ create_headless_test_setup (void)
 static void
 init_tests (int argc, char **argv)
 {
-  MetaMonitorTestSetup *initial_test_setup;
-
-  initial_test_setup = create_headless_test_setup ();
-  meta_monitor_manager_test_init_test_setup (initial_test_setup);
+  meta_monitor_manager_test_init_test_setup (create_headless_test_setup);
 
   g_test_add_func ("/headless-start/start", meta_test_headless_start);
   g_test_add_func ("/headless-start/monitor-getters",
diff --git a/src/tests/meta-monitor-manager-test.c b/src/tests/meta-monitor-manager-test.c
index 42a57608ed..4bfbb8da17 100644
--- a/src/tests/meta-monitor-manager-test.c
+++ b/src/tests/meta-monitor-manager-test.c
@@ -42,12 +42,12 @@ struct _MetaMonitorManagerTest
 G_DEFINE_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test,
                META_TYPE_MONITOR_MANAGER)
 
-static MetaMonitorTestSetup *_initial_test_setup = NULL;
+static CreateTestSetupFunc initial_setup_func;
 
 void
-meta_monitor_manager_test_init_test_setup (MetaMonitorTestSetup *test_setup)
+meta_monitor_manager_test_init_test_setup (CreateTestSetupFunc func)
 {
-  _initial_test_setup = test_setup;
+  initial_setup_func = func;
 }
 
 void
@@ -409,16 +409,24 @@ meta_monitor_manager_test_dispose (GObject *object)
   MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (object);
 
   g_clear_pointer (&manager_test->test_setup, g_free);
+
+  G_OBJECT_CLASS (meta_monitor_manager_test_parent_class)->dispose (object);
 }
 
 static void
-meta_monitor_manager_test_init (MetaMonitorManagerTest *manager_test)
+meta_monitor_manager_test_constructed (GObject *object)
 {
-  g_assert (_initial_test_setup);
+  MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (object);
 
-  manager_test->handles_transforms = TRUE;
+  manager_test->test_setup = initial_setup_func ();
+
+  G_OBJECT_CLASS (meta_monitor_manager_test_parent_class)->constructed (object);
+}
 
-  manager_test->test_setup = _initial_test_setup;
+static void
+meta_monitor_manager_test_init (MetaMonitorManagerTest *manager_test)
+{
+  manager_test->handles_transforms = TRUE;
 }
 
 static void
@@ -428,6 +436,7 @@ meta_monitor_manager_test_class_init (MetaMonitorManagerTestClass *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;
 
   manager_class->ensure_initial_config = meta_monitor_manager_test_ensure_initial_config;
   manager_class->apply_monitors_config = meta_monitor_manager_test_apply_monitors_config;
diff --git a/src/tests/meta-monitor-manager-test.h b/src/tests/meta-monitor-manager-test.h
index 0512a7fcb0..4724d38cbc 100644
--- a/src/tests/meta-monitor-manager-test.h
+++ b/src/tests/meta-monitor-manager-test.h
@@ -34,11 +34,13 @@ typedef struct _MetaOutputTest
   float scale;
 } MetaOutputTest;
 
+typedef MetaMonitorTestSetup * (* CreateTestSetupFunc) (void);
+
 #define META_TYPE_MONITOR_MANAGER_TEST (meta_monitor_manager_test_get_type ())
 G_DECLARE_FINAL_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test,
                       META, MONITOR_MANAGER_TEST, MetaMonitorManager)
 
-void meta_monitor_manager_test_init_test_setup (MetaMonitorTestSetup *test_setup);
+void meta_monitor_manager_test_init_test_setup (CreateTestSetupFunc func);
 
 void meta_monitor_manager_test_read_current (MetaMonitorManager *manager);
 
diff --git a/src/tests/monitor-test-utils.h b/src/tests/monitor-test-utils.h
index e99799861c..ef6330665b 100644
--- a/src/tests/monitor-test-utils.h
+++ b/src/tests/monitor-test-utils.h
@@ -185,11 +185,11 @@ typedef struct _MonitorTestCaseExpect
   int screen_height;
 } MonitorTestCaseExpect;
 
-typedef struct _MonitorTestCase
+struct _MonitorTestCase
 {
   MonitorTestCaseSetup setup;
   MonitorTestCaseExpect expect;
-} MonitorTestCase;
+};
 
 void set_custom_monitor_config (const char *filename);
 
diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c
index 975c9970c3..8d857b3e3d 100644
--- a/src/tests/monitor-unit-tests.c
+++ b/src/tests/monitor-unit-tests.c
@@ -5614,14 +5614,17 @@ add_monitor_test (const char *test_path,
               NULL);
 }
 
+static MetaMonitorTestSetup *
+create_initial_test_setup (void)
+{
+  return create_monitor_test_setup (&initial_test_case.setup,
+                                    MONITOR_TEST_FLAG_NO_STORED);
+}
+
 void
 init_monitor_tests (void)
 {
-  MetaMonitorTestSetup *initial_test_setup;
-
-  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);
+  meta_monitor_manager_test_init_test_setup (create_initial_test_setup);
 
   add_monitor_test ("/backends/monitor/initial-linear-config",
                     meta_test_monitor_initial_linear_config);
diff --git a/src/tests/monitor-unit-tests.h b/src/tests/monitor-unit-tests.h
index b215e31d1e..b497c8a3d7 100644
--- a/src/tests/monitor-unit-tests.h
+++ b/src/tests/monitor-unit-tests.h
@@ -20,10 +20,17 @@
 #ifndef MONITOR_UNIT_TESTS_H
 #define MONITOR_UNIT_TESTS_H
 
+#include "core/util-private.h"
+#include "tests/monitor-test-utils.h"
+
+typedef struct _MonitorTestCase MonitorTestCase;
+
 void init_monitor_tests (void);
 
 void pre_run_monitor_tests (void);
 
 void finish_monitor_tests (void);
 
+MonitorTestCase * test_get_initial_monitor_test_case (void);
+
 #endif /* MONITOR_UNIT_TESTS_H */
diff --git a/src/tests/stage-view-tests.c b/src/tests/stage-view-tests.c
index 47eb4bc991..9c31353e00 100644
--- a/src/tests/stage-view-tests.c
+++ b/src/tests/stage-view-tests.c
@@ -462,15 +462,17 @@ meta_test_actor_stage_views_hide_parent (void)
   clutter_actor_destroy (outer_container);
 }
 
+static MetaMonitorTestSetup *
+create_stage_view_test_setup (void)
+{
+  return create_monitor_test_setup (&initial_test_case_setup,
+                                    MONITOR_TEST_FLAG_NO_STORED);
+}
+
 static void
 init_tests (int argc, char **argv)
 {
-  MetaMonitorTestSetup *test_setup;
-
-  test_setup = create_monitor_test_setup (&initial_test_case_setup,
-                                          MONITOR_TEST_FLAG_NO_STORED);
-
-  meta_monitor_manager_test_init_test_setup (test_setup);
+  meta_monitor_manager_test_init_test_setup (create_stage_view_test_setup);
 
   g_test_add_func ("/stage-view/stage-views-exist",
                    meta_test_stage_views_exist);


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