[mutter] tests: Move monitor test helpers to a helper file



commit 4652bde3d7e6e261aca14b2b52b09102119944d9
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Jan 13 11:41:05 2017 +0800

    tests: Move monitor test helpers to a helper file
    
    Both the monitor unit tests and monitor store unit tests will want to
    check whether the config manager is used and set custom configuration
    files.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777732

 src/Makefile-tests.am                |    2 +
 src/tests/monitor-store-unit-tests.c |   64 +++++++--------------------------
 src/tests/monitor-test-utils.c       |   57 ++++++++++++++++++++++++++++++
 src/tests/monitor-test-utils.h       |   29 +++++++++++++++
 src/tests/monitor-unit-tests.c       |   13 ++-----
 5 files changed, 106 insertions(+), 59 deletions(-)
---
diff --git a/src/Makefile-tests.am b/src/Makefile-tests.am
index 9349992..860d3c4 100644
--- a/src/Makefile-tests.am
+++ b/src/Makefile-tests.am
@@ -40,6 +40,8 @@ mutter_test_unit_tests_SOURCES = \
        tests/meta-monitor-manager-test.h \
        tests/monitor-store-unit-tests.c \
        tests/monitor-store-unit-tests.h \
+       tests/monitor-test-utils.c \
+       tests/monitor-test-utils.h \
        tests/monitor-unit-tests.c \
        tests/monitor-unit-tests.h \
        $(NULL)
diff --git a/src/tests/monitor-store-unit-tests.c b/src/tests/monitor-store-unit-tests.c
index 3d6a647..824ec11 100644
--- a/src/tests/monitor-store-unit-tests.c
+++ b/src/tests/monitor-store-unit-tests.c
@@ -25,6 +25,7 @@
 #include "backends/meta-monitor-config-store.h"
 #include "backends/meta-monitor-config-manager.h"
 #include "backends/meta-monitor-manager-private.h"
+#include "tests/monitor-test-utils.h"
 
 #define MAX_N_MONITORS 10
 #define MAX_N_LOGICAL_MONITORS 10
@@ -65,44 +66,6 @@ typedef struct _MonitorStoreTestExpect
   int n_configurations;
 } MonitorStoreTestExpect;
 
-static MetaMonitorConfigStore *
-get_monitor_config_store (void)
-{
-  MetaBackend *backend = meta_get_backend ();
-  MetaMonitorManager *monitor_manager =
-    meta_backend_get_monitor_manager (backend);
-  MetaMonitorConfigManager *config_manager = monitor_manager->config_manager;
-
-  if (!config_manager)
-    return NULL;
-
-  return meta_monitor_config_manager_get_store (config_manager);
-}
-
-static const char *
-get_monitor_test_file (const char *filename)
-{
-  return g_test_get_filename (G_TEST_DIST, "tests", "monitor-configs",
-                              filename, NULL);
-}
-
-static void
-set_custom_test_file (MetaMonitorConfigStore *config_store,
-                      const char             *filename)
-{
-  const char *path;
-  GError *error = NULL;
-
-  path = get_monitor_test_file (filename);
-  g_assert (path);
-
-  if (!meta_monitor_config_store_set_custom (config_store, path, &error))
-    {
-      g_error ("Failed to set custom monitors config: %s", error->message);
-      g_assert_not_reached ();
-    }
-}
-
 static MetaMonitorsConfigKey *
 create_config_key_from_expect (MonitorStoreTestConfiguration *expect_config)
 {
@@ -209,9 +172,14 @@ check_monitor_configuration (MetaMonitorConfigStore        *config_store,
 }
 
 static void
-check_monitor_configurations (MetaMonitorConfigStore *config_store,
-                              MonitorStoreTestExpect *expect)
+check_monitor_configurations (MonitorStoreTestExpect *expect)
 {
+  MetaBackend *backend = meta_get_backend ();
+  MetaMonitorManager *monitor_manager =
+    meta_backend_get_monitor_manager (backend);
+  MetaMonitorConfigManager *config_manager = monitor_manager->config_manager;
+  MetaMonitorConfigStore *config_store =
+    meta_monitor_config_manager_get_store (config_manager);
   int i;
 
   g_assert_cmpint (meta_monitor_config_store_get_config_count (config_store),
@@ -225,7 +193,6 @@ check_monitor_configurations (MetaMonitorConfigStore *config_store,
 static void
 meta_test_monitor_store_single (void)
 {
-  MetaMonitorConfigStore *config_store;
   MonitorStoreTestExpect expect = {
     .configurations = {
       {
@@ -259,22 +226,20 @@ meta_test_monitor_store_single (void)
     .n_configurations = 1
   };
 
-  config_store = get_monitor_config_store ();
-  if (!config_store)
+  if (!is_using_monitor_config_manager ())
     {
       g_test_skip ("Not using MetaMonitorConfigManager");
       return;
     }
 
-  set_custom_test_file (config_store, "single.xml");
+  set_custom_monitor_config ("single.xml");
 
-  check_monitor_configurations (config_store, &expect);
+  check_monitor_configurations (&expect);
 }
 
 static void
 meta_test_monitor_store_vertical (void)
 {
-  MetaMonitorConfigStore *config_store;
   MonitorStoreTestExpect expect = {
     .configurations = {
       {
@@ -330,16 +295,15 @@ meta_test_monitor_store_vertical (void)
     .n_configurations = 1
   };
 
-  config_store = get_monitor_config_store ();
-  if (!config_store)
+  if (!is_using_monitor_config_manager ())
     {
       g_test_skip ("Not using MetaMonitorConfigManager");
       return;
     }
 
-  set_custom_test_file (config_store, "vertical.xml");
+  set_custom_monitor_config ("vertical.xml");
 
-  check_monitor_configurations (config_store, &expect);
+  check_monitor_configurations (&expect);
 }
 
 void
diff --git a/src/tests/monitor-test-utils.c b/src/tests/monitor-test-utils.c
new file mode 100644
index 0000000..5389485
--- /dev/null
+++ b/src/tests/monitor-test-utils.c
@@ -0,0 +1,57 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/*
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "tests/monitor-test-utils.h"
+
+#include "backends/meta-backend-private.h"
+#include "backends/meta-monitor-config-manager.h"
+#include "backends/meta-monitor-config-store.h"
+
+gboolean
+is_using_monitor_config_manager (void)
+{
+  MetaBackend *backend = meta_get_backend ();
+  MetaMonitorManager *monitor_manager =
+    meta_backend_get_monitor_manager (backend);
+
+  return !!monitor_manager->config_manager;
+}
+
+void
+set_custom_monitor_config (const char *filename)
+{
+  MetaBackend *backend = meta_get_backend ();
+  MetaMonitorManager *monitor_manager =
+    meta_backend_get_monitor_manager (backend);
+  MetaMonitorConfigManager *config_manager = monitor_manager->config_manager;
+  MetaMonitorConfigStore *config_store;
+  GError *error = NULL;
+  const char *path;
+
+  g_assert_nonnull (config_manager);
+
+  config_store = meta_monitor_config_manager_get_store (config_manager);
+
+  path = g_test_get_filename (G_TEST_DIST, "tests", "monitor-configs",
+                              filename, NULL);
+  if (!meta_monitor_config_store_set_custom (config_store, path, &error))
+    g_error ("Failed to set custom config: %s", error->message);
+}
diff --git a/src/tests/monitor-test-utils.h b/src/tests/monitor-test-utils.h
new file mode 100644
index 0000000..c71f170
--- /dev/null
+++ b/src/tests/monitor-test-utils.h
@@ -0,0 +1,29 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/*
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MONITOR_TEST_UTILS_H
+#define MONITOR_TEST_UTILS_H
+
+#include <glib.h>
+
+gboolean is_using_monitor_config_manager (void);
+
+void set_custom_monitor_config (const char *filename);
+
+#endif /* MONITOR_TEST_UTILS_H */
diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c
index fc708ea..42c1dab 100644
--- a/src/tests/monitor-unit-tests.c
+++ b/src/tests/monitor-unit-tests.c
@@ -25,6 +25,7 @@
 #include "backends/meta-logical-monitor.h"
 #include "backends/meta-monitor.h"
 #include "tests/meta-monitor-manager-test.h"
+#include "tests/monitor-test-utils.h"
 
 #define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1)
 
@@ -1364,9 +1365,6 @@ meta_test_monitor_limited_crtcs (void)
     }
   };
   MetaMonitorTestSetup *test_setup;
-  MetaBackend *backend = meta_get_backend ();
-  MetaMonitorManager *monitor_manager =
-    meta_backend_get_monitor_manager (backend);
 
   test_setup = create_monitor_test_setup (&test_case);
 
@@ -1374,7 +1372,7 @@ meta_test_monitor_limited_crtcs (void)
    * With the config manager, we'll get a g_warning.
    * With the old it's just a meta_warning().
    */
-  if (monitor_manager->config_manager)
+  if (is_using_monitor_config_manager ())
     {
       g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
                              "Failed to use linear *");
@@ -1642,7 +1640,7 @@ meta_test_monitor_lid_opened_config (void)
   MetaMonitorManagerTest *monitor_manager_test =
     META_MONITOR_MANAGER_TEST (monitor_manager);
 
-  if (!monitor_manager->config_manager)
+  if (!is_using_monitor_config_manager ())
     {
       g_test_skip ("Only the new monitor config manager handles this case.");
       return;
@@ -1772,11 +1770,8 @@ meta_test_monitor_no_outputs (void)
     }
   };
   MetaMonitorTestSetup *test_setup;
-  MetaBackend *backend = meta_get_backend ();
-  MetaMonitorManager *monitor_manager =
-    meta_backend_get_monitor_manager (backend);
 
-  if (!monitor_manager->config_manager)
+  if (!is_using_monitor_config_manager ())
     {
       g_test_skip ("Only the new monitor config manager handles this case.");
       return;


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