tests: Call g_test_init() in test-runner too

This makes the log handler that breaks test redundant, as GTest already
does this.
This commit is contained in:
Jonas Ådahl 2018-07-16 16:40:31 +02:00
parent c65617cb5a
commit 2af229fe98
4 changed files with 10 additions and 54 deletions

View File

@ -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 ();

View File

@ -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);

View File

@ -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,

View File

@ -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 ());