From 2af229fe981a1eaa6e2e4e7cdc5a29545a3c01e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 16 Jul 2018 16:40:31 +0200 Subject: [PATCH] tests: Call g_test_init() in test-runner too This makes the log handler that breaks test redundant, as GTest already does this. --- src/tests/test-runner.c | 48 ++--------------------------------------- src/tests/test-utils.c | 7 ++++-- src/tests/test-utils.h | 4 ++-- src/tests/unit-tests.c | 5 +---- 4 files changed, 10 insertions(+), 54 deletions(-) diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c index 84c3f8a84..343865952 100644 --- a/src/tests/test-runner.c +++ b/src/tests/test-runner.c @@ -37,7 +37,6 @@ typedef struct { GHashTable *clients; AsyncWaiter *waiter; - guint log_handler_id; GString *warning_messages; GMainLoop *loop; } TestCase; @@ -62,49 +61,11 @@ test_case_alarm_filter (MetaX11Display *x11_display, return FALSE; } -static gboolean -test_case_check_warnings (TestCase *test, - GError **error) -{ - if (test->warning_messages != NULL) - { - g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_RUNTIME_ERROR, - "Warning messages:\n %s", test->warning_messages->str); - g_string_free (test->warning_messages, TRUE); - test->warning_messages = NULL; - return FALSE; - } - - return TRUE; -} - -static void -test_case_log_func (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer user_data) -{ - TestCase *test = user_data; - - if (test->warning_messages == NULL) - test->warning_messages = g_string_new (message); - else - { - g_string_append (test->warning_messages, "\n "); - g_string_append (test->warning_messages, message); - } -} - static TestCase * test_case_new (void) { TestCase *test = g_new0 (TestCase, 1); - test->log_handler_id = g_log_set_handler ("mutter", - G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING, - test_case_log_func, - test); - meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display, test_case_alarm_filter, test); @@ -529,7 +490,7 @@ test_case_do (TestCase *test, BAD_COMMAND("Unknown command %s", argv[0]); } - return test_case_check_warnings (test, error); + return TRUE; } static gboolean @@ -557,9 +518,6 @@ test_case_destroy (TestCase *test, if (!test_case_assert_stacking (test, NULL, 0, error)) return FALSE; - if (!test_case_check_warnings (test, error)) - return FALSE; - g_hash_table_iter_init (&iter, test->clients); while (g_hash_table_iter_next (&iter, &key, &value)) test_client_destroy (value); @@ -572,8 +530,6 @@ test_case_destroy (TestCase *test, g_hash_table_destroy (test->clients); g_free (test); - g_log_remove_handler ("mutter", test->log_handler_id); - return TRUE; } @@ -795,7 +751,7 @@ main (int argc, char **argv) g_option_context_free (ctx); - test_init (argc, argv); + test_init (&argc, &argv); GPtrArray *tests = g_ptr_array_new (); diff --git a/src/tests/test-utils.c b/src/tests/test-utils.c index 3df98f305..5faaaa781 100644 --- a/src/tests/test-utils.c +++ b/src/tests/test-utils.c @@ -58,12 +58,15 @@ G_DEFINE_QUARK (test-runner-error-quark, test_runner_error) static char *test_client_path; void -test_init (int argc, - char **argv) +test_init (int *argc, + char ***argv) { char *basename = g_path_get_basename (argv[0]); char *dirname = g_path_get_dirname (argv[0]); + g_test_init (argc, argv, NULL); + g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id="); + if (g_str_has_prefix (basename, "lt-")) test_client_path = g_build_filename (dirname, "../mutter-test-client", NULL); diff --git a/src/tests/test-utils.h b/src/tests/test-utils.h index db11fea6e..5dfec8367 100644 --- a/src/tests/test-utils.h +++ b/src/tests/test-utils.h @@ -40,8 +40,8 @@ GQuark test_runner_error_quark (void); typedef struct _AsyncWaiter AsyncWaiter; typedef struct _TestClient TestClient; -void test_init (int argc, - char **argv); +void test_init (int *argc, + char ***argv); gboolean async_waiter_alarm_filter (AsyncWaiter *waiter, MetaX11Display *x11_display, diff --git a/src/tests/unit-tests.c b/src/tests/unit-tests.c index ade759948..50ec89dc5 100644 --- a/src/tests/unit-tests.c +++ b/src/tests/unit-tests.c @@ -241,9 +241,6 @@ run_tests (gpointer data) static void init_tests (int argc, char **argv) { - g_test_init (&argc, &argv, NULL); - g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id="); - g_test_add_func ("/util/meta-later/order", meta_test_util_later_order); g_test_add_func ("/util/meta-later/schedule-from-later", meta_test_util_later_schedule_from_later); @@ -259,7 +256,7 @@ init_tests (int argc, char **argv) int main (int argc, char *argv[]) { - test_init (argc, argv); + test_init (&argc, &argv); init_tests (argc, argv); meta_plugin_manager_load (test_get_plugin_name ());