[mutter] tests/monitor-unit-tests: Run a client while testing



commit e2d904c32b565626afe5602a4a03c1dc8cf999e0
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Aug 18 14:37:53 2017 +0800

    tests/monitor-unit-tests: Run a client while testing
    
    Run a client while testing and check that it's alive when checking each
    monitor configuration.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730551

 src/Makefile-tests.am          |    2 +
 src/tests/monitor-unit-tests.c |   62 ++++++++++++++++++++++++++++++++++++++++
 src/tests/monitor-unit-tests.h |    4 ++
 src/tests/unit-tests.c         |    6 ++++
 4 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile-tests.am b/src/Makefile-tests.am
index 3d8683c..1c50301 100644
--- a/src/Makefile-tests.am
+++ b/src/Makefile-tests.am
@@ -43,6 +43,8 @@ mutter_test_runner_SOURCES = \
 mutter_test_runner_LDADD = $(MUTTER_LIBS) libmutter-$(LIBMUTTER_API_VERSION).la
 
 mutter_test_unit_tests_SOURCES = \
+       tests/test-utils.c \
+       tests/test-utils.h \
        tests/unit-tests.c \
        tests/meta-backend-test.c \
        tests/meta-backend-test.h \
diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c
index d1cb24d..d17b0cd 100644
--- a/src/tests/monitor-unit-tests.c
+++ b/src/tests/monitor-unit-tests.c
@@ -28,6 +28,7 @@
 #include "backends/meta-monitor-config-store.h"
 #include "tests/meta-monitor-manager-test.h"
 #include "tests/monitor-test-utils.h"
+#include "tests/test-utils.h"
 
 #define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1)
 
@@ -313,6 +314,53 @@ static MonitorTestCase initial_test_case = {
   }
 };
 
+static TestClient *monitor_test_client = NULL;
+
+#define TEST_CLIENT_NAME "client1"
+#define TEST_CLIENT_WINDOW "window1"
+
+static void
+create_monitor_test_client (void)
+{
+  GError *error = NULL;
+
+  monitor_test_client = test_client_new (TEST_CLIENT_NAME,
+                                         META_WINDOW_CLIENT_TYPE_WAYLAND,
+                                         &error);
+  if (!monitor_test_client)
+    g_error ("Failed to launch test client: %s", error->message);
+
+  if (!test_client_do (monitor_test_client, &error,
+                       "create", TEST_CLIENT_WINDOW,
+                       NULL))
+    g_error ("Failed to create window: %s", error->message);
+
+  if (!test_client_do (monitor_test_client, &error,
+                       "show", TEST_CLIENT_WINDOW,
+                       NULL))
+    g_error ("Failed to show the window: %s", error->message);
+}
+
+static void
+check_monitor_test_client_state (void)
+{
+  GError *error = NULL;
+
+  if (!test_client_wait (monitor_test_client, &error))
+    g_error ("Failed to sync test client: %s", error->message);
+}
+
+static void
+destroy_monitor_test_client (void)
+{
+  GError *error = NULL;
+
+  if (!test_client_quit (monitor_test_client, &error))
+    g_error ("Failed to quit test client: %s", error->message);
+
+  test_client_destroy (monitor_test_client);
+}
+
 static MetaOutput *
 output_from_winsys_id (MetaMonitorManager *monitor_manager,
                        long                winsys_id)
@@ -782,6 +830,8 @@ check_monitor_configuration (MonitorTestCase *test_case)
             }
         }
     }
+
+  check_monitor_test_client_state ();
 }
 
 static void
@@ -4876,3 +4926,15 @@ init_monitor_tests (void)
   add_monitor_test ("/backends/monitor/migrated/rotated",
                     meta_test_monitor_migrated_rotated);
 }
+
+void
+pre_run_monitor_tests (void)
+{
+  create_monitor_test_client ();
+}
+
+void
+finish_monitor_tests (void)
+{
+  destroy_monitor_test_client ();
+}
diff --git a/src/tests/monitor-unit-tests.h b/src/tests/monitor-unit-tests.h
index a98f9d5..b215e31 100644
--- a/src/tests/monitor-unit-tests.h
+++ b/src/tests/monitor-unit-tests.h
@@ -22,4 +22,8 @@
 
 void init_monitor_tests (void);
 
+void pre_run_monitor_tests (void);
+
+void finish_monitor_tests (void);
+
 #endif /* MONITOR_UNIT_TESTS_H */
diff --git a/src/tests/unit-tests.c b/src/tests/unit-tests.c
index 36915f4..59c70d5 100644
--- a/src/tests/unit-tests.c
+++ b/src/tests/unit-tests.c
@@ -32,6 +32,7 @@
 #include "tests/monitor-config-migration-unit-tests.h"
 #include "tests/monitor-unit-tests.h"
 #include "tests/monitor-store-unit-tests.h"
+#include "tests/test-utils.h"
 #include "wayland/meta-wayland.h"
 
 typedef struct _MetaTestLaterOrderCallbackData
@@ -225,8 +226,12 @@ run_tests (gpointer data)
     settings,
     META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER);
 
+  pre_run_monitor_tests ();
+
   ret = g_test_run ();
 
+  finish_monitor_tests ();
+
   meta_quit (ret != 0);
 
   return FALSE;
@@ -252,6 +257,7 @@ init_tests (int argc, char **argv)
 int
 main (int argc, char *argv[])
 {
+  test_init (argc, argv);
   init_tests (argc, argv);
 
   meta_plugin_manager_load ("default");


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