[mutter] tests: Make monitor unit tests create initial config
- From: Jonas Ådahl <jadahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] tests: Make monitor unit tests create initial config
- Date: Wed, 25 Jan 2017 08:33:14 +0000 (UTC)
commit c6d940d3b2bb7db15eabe8a21f31ef0e78ca2d63
Author: Jonas Ådahl <jadahl gmail com>
Date: Mon Dec 5 21:28:22 2016 +0800
tests: Make monitor unit tests create initial config
This way we have both the test setup and testing in the same file.
https://bugzilla.gnome.org/show_bug.cgi?id=777732
src/tests/meta-monitor-manager-test.c | 71 ++++++++++-----------------------
src/tests/meta-monitor-manager-test.h | 12 ++++++
src/tests/monitor-unit-tests.c | 65 ++++++++++++++++++++++++++++++
src/tests/unit-tests.c | 3 +-
4 files changed, 100 insertions(+), 51 deletions(-)
---
diff --git a/src/tests/meta-monitor-manager-test.c b/src/tests/meta-monitor-manager-test.c
index 88e7c29..c5249cd 100644
--- a/src/tests/meta-monitor-manager-test.c
+++ b/src/tests/meta-monitor-manager-test.c
@@ -21,74 +21,42 @@
#include "tests/meta-monitor-manager-test.h"
-#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1)
-
struct _MetaMonitorManagerTest
{
MetaMonitorManager parent;
+
+ MetaMonitorTestSetup *test_setup;
};
G_DEFINE_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test,
META_TYPE_MONITOR_MANAGER)
+static MetaMonitorTestSetup *_initial_test_setup = NULL;
+
+void
+meta_monitor_manager_test_init_test_setup (MetaMonitorTestSetup *test_setup)
+{
+ _initial_test_setup = test_setup;
+}
+
static void
meta_monitor_manager_test_read_current (MetaMonitorManager *manager)
{
- int n_monitors = 2;
- int i;
+ MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager);
manager->max_screen_width = 65535;
manager->max_screen_height = 65535;
- manager->screen_width = 1024;
- manager->screen_height = 768;
- manager->modes = g_new0 (MetaMonitorMode, 1);
- manager->n_modes = 1;
+ g_assert (manager_test->test_setup);
- manager->modes[0].mode_id = 0;
- manager->modes[0].width = 1024;
- manager->modes[0].height = 768;
- manager->modes[0].refresh_rate = 60.0;
+ manager->modes = manager_test->test_setup->modes;
+ manager->n_modes = manager_test->test_setup->n_modes;
- manager->crtcs = g_new0 (MetaCRTC, n_monitors);
- manager->n_crtcs = n_monitors;
- manager->outputs = g_new0 (MetaOutput, n_monitors);
- manager->n_outputs = n_monitors;
+ manager->crtcs = manager_test->test_setup->crtcs;
+ manager->n_crtcs = manager_test->test_setup->n_crtcs;
- for (i = 0; i < n_monitors; i++)
- {
- manager->crtcs[i].crtc_id = i + 1;
- manager->crtcs[i].current_mode = &manager->modes[0];
- manager->crtcs[i].transform = META_MONITOR_TRANSFORM_NORMAL;
- manager->crtcs[i].all_transforms = ALL_TRANSFORMS;
-
-
- manager->outputs[i].crtc = &manager->crtcs[i];
- manager->outputs[i].winsys_id = i + 1;
- manager->outputs[i].name = g_strdup_printf ("LVDS%d", i + 1);
- manager->outputs[i].vendor = g_strdup ("MetaProducts Inc.");
- manager->outputs[i].product = g_strdup ("unknown");
- manager->outputs[i].serial = g_strdup ("0xC0FFEE");
- manager->outputs[i].suggested_x = -1;
- manager->outputs[i].suggested_y = -1;
- manager->outputs[i].width_mm = 222;
- manager->outputs[i].height_mm = 125;
- manager->outputs[i].subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
- manager->outputs[i].preferred_mode = &manager->modes[0];
- manager->outputs[i].n_modes = 1;
- manager->outputs[i].modes = g_new0 (MetaMonitorMode *, 1);
- manager->outputs[i].modes[0] = &manager->modes[0];
- manager->outputs[i].n_possible_crtcs = 1;
- manager->outputs[i].possible_crtcs = g_new0 (MetaCRTC *, 1);
- manager->outputs[i].possible_crtcs[0] = &manager->crtcs[i];
- manager->outputs[i].n_possible_clones = 0;
- manager->outputs[i].possible_clones = g_new0 (MetaOutput *, 0);
- manager->outputs[i].backlight = -1;
- manager->outputs[i].backlight_min = 0;
- manager->outputs[i].backlight_max = 0;
- manager->outputs[i].connector_type = META_CONNECTOR_TYPE_LVDS;
- manager->outputs[i].scale = 1;
- }
+ manager->outputs = manager_test->test_setup->outputs;
+ manager->n_outputs = manager_test->test_setup->n_outputs;
}
static void
@@ -208,6 +176,9 @@ meta_monitor_manager_test_apply_configuration (MetaMonitorManager *manager,
static void
meta_monitor_manager_test_init (MetaMonitorManagerTest *manager_test)
{
+ g_assert (_initial_test_setup);
+
+ manager_test->test_setup = _initial_test_setup;
}
static void
diff --git a/src/tests/meta-monitor-manager-test.h b/src/tests/meta-monitor-manager-test.h
index 91120ca..4ad9095 100644
--- a/src/tests/meta-monitor-manager-test.h
+++ b/src/tests/meta-monitor-manager-test.h
@@ -22,8 +22,20 @@
#include "backends/meta-monitor-manager-private.h"
+typedef struct _MetaMonitorTestSetup
+{
+ MetaMonitorMode *modes;
+ int n_modes;
+ MetaOutput *outputs;
+ int n_outputs;
+ MetaCRTC *crtcs;
+ int n_crtcs;
+} MetaMonitorTestSetup;
+
#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);
+
#endif /* META_MONITOR_MANAGER_TEST_H */
diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c
index 3aa7187..62712b5 100644
--- a/src/tests/monitor-unit-tests.c
+++ b/src/tests/monitor-unit-tests.c
@@ -22,6 +22,11 @@
#include "tests/monitor-unit-tests.h"
#include "backends/meta-backend-private.h"
+#include "tests/meta-monitor-manager-test.h"
+
+#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1)
+
+static MetaMonitorTestSetup *current_test_setup = NULL;
static void
meta_test_monitor_linear_config (void)
@@ -60,9 +65,69 @@ meta_test_monitor_linear_config (void)
}
}
+static void
+setup_initial_monitor_test_setup (void)
+{
+ MetaMonitorTestSetup *test_setup;
+ int n_monitors = 2;
+ int i;
+
+ test_setup = g_new0 (MetaMonitorTestSetup, 1);
+
+ test_setup->n_modes = 1;
+ test_setup->modes = g_new0 (MetaMonitorMode, 1);
+ test_setup->modes[0].mode_id = 0;
+ test_setup->modes[0].width = 1024;
+ test_setup->modes[0].height = 768;
+ test_setup->modes[0].refresh_rate = 60.0;
+
+ test_setup->n_crtcs = n_monitors;
+ test_setup->crtcs = g_new0 (MetaCRTC, n_monitors);
+
+ test_setup->n_outputs = n_monitors;
+ test_setup->outputs = g_new0 (MetaOutput, n_monitors);
+
+ for (i = 0; i < n_monitors; i++)
+ {
+ test_setup->crtcs[i].crtc_id = i + 1;
+ test_setup->crtcs[i].current_mode = &test_setup->modes[0];
+ test_setup->crtcs[i].transform = META_MONITOR_TRANSFORM_NORMAL;
+ test_setup->crtcs[i].all_transforms = ALL_TRANSFORMS;
+
+ test_setup->outputs[i].crtc = &test_setup->crtcs[i];
+ test_setup->outputs[i].winsys_id = i + 1;
+ test_setup->outputs[i].name = g_strdup_printf ("LVDS%d", i + 1);
+ test_setup->outputs[i].vendor = g_strdup ("MetaProducts Inc.");
+ test_setup->outputs[i].product = g_strdup ("unknown");
+ test_setup->outputs[i].serial = g_strdup ("0xC0FFEE");
+ test_setup->outputs[i].suggested_x = -1;
+ test_setup->outputs[i].suggested_y = -1;
+ test_setup->outputs[i].width_mm = 222;
+ test_setup->outputs[i].height_mm = 125;
+ test_setup->outputs[i].subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
+ test_setup->outputs[i].preferred_mode = &test_setup->modes[0];
+ test_setup->outputs[i].n_modes = 1;
+ test_setup->outputs[i].modes = g_new0 (MetaMonitorMode *, 1);
+ test_setup->outputs[i].modes[0] = &test_setup->modes[0];
+ test_setup->outputs[i].n_possible_crtcs = 1;
+ test_setup->outputs[i].possible_crtcs = g_new0 (MetaCRTC *, 1);
+ test_setup->outputs[i].possible_crtcs[0] = &test_setup->crtcs[i];
+ test_setup->outputs[i].n_possible_clones = 0;
+ test_setup->outputs[i].possible_clones = NULL;
+ test_setup->outputs[i].backlight = -1;
+ test_setup->outputs[i].connector_type = META_CONNECTOR_TYPE_LVDS;
+ test_setup->outputs[i].scale = 1;
+ }
+
+ meta_monitor_manager_test_init_test_setup (test_setup);
+ current_test_setup = test_setup;
+}
+
void
init_monitor_tests (void)
{
+ setup_initial_monitor_test_setup ();
+
g_test_add_func ("/backends/monitor/linear-config",
meta_test_monitor_linear_config);
}
diff --git a/src/tests/unit-tests.c b/src/tests/unit-tests.c
index 4f2856b..7b7818c 100644
--- a/src/tests/unit-tests.c
+++ b/src/tests/unit-tests.c
@@ -221,6 +221,8 @@ main (int argc, char *argv[])
g_option_context_free (ctx);
+ init_tests (argc, argv);
+
meta_plugin_manager_load ("default");
meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND,
@@ -230,7 +232,6 @@ main (int argc, char *argv[])
meta_init ();
meta_register_with_session ();
- init_tests (argc, argv);
g_idle_add (run_tests, NULL);
return meta_run ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]