summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2012-07-30 16:38:30 -0400
committerDan Winship <danw@gnome.org>2012-08-20 13:54:52 -0400
commitcc24dac3c8edbe2068ba15522bb5d937602082dc (patch)
tree16ad9a37ff379169358dcdeac9b037284ad0f0ca
parent25ac137c0a47ccc5214dabeaa41da18dac2b0cee (diff)
downloadglib-cc24dac3c8edbe2068ba15522bb5d937602082dc.tar.gz
glib/tests: use g_test_expect_message()
Replace some tests that used to use g_test_trap_fork() with g_test_expect_message() instead. https://bugzilla.gnome.org/show_bug.cgi?id=679556
-rw-r--r--glib/tests/Makefile.am1
-rw-r--r--glib/tests/error.c45
-rw-r--r--glib/tests/gvariant.c56
-rw-r--r--glib/tests/mainloop.c11
-rw-r--r--glib/tests/markup-collect.c20
-rw-r--r--glib/tests/strfuncs.c163
6 files changed, 159 insertions, 137 deletions
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 26ae31cd6..983259b65 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -3,6 +3,7 @@ include $(top_srcdir)/Makefile.decl
INCLUDES = \
-g \
$(glib_INCLUDES) \
+ -DG_LOG_DOMAIN=\"GLib\" \
-DSRCDIR=\""$(srcdir)"\" \
$(GLIB_DEBUG_FLAGS)
diff --git a/glib/tests/error.c b/glib/tests/error.c
index be03cfd7c..81b4055dd 100644
--- a/glib/tests/error.c
+++ b/glib/tests/error.c
@@ -3,28 +3,35 @@
static void
test_overwrite (void)
{
+ GError *error, *dest, *src;
+
if (!g_test_undefined ())
return;
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- GError *error;
- error = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
- g_set_error_literal (&error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "bla");
- }
- g_test_trap_assert_failed ();
- g_test_trap_assert_stderr ("*set over the top*");
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- GError *dest;
- GError *src;
- dest = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
- src = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "bla");
- g_propagate_error (&dest, src);
- }
- g_test_trap_assert_failed ();
- g_test_trap_assert_stderr ("*set over the top*");
+ error = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*set over the top*");
+ g_set_error_literal (&error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "bla");
+ g_test_assert_expected_messages ();
+
+ g_assert_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY);
+ g_error_free (error);
+
+
+ dest = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
+ src = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "bla");
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*set over the top*");
+ g_propagate_error (&dest, src);
+ g_test_assert_expected_messages ();
+
+ g_assert_error (dest, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY);
+ g_assert_error (src, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE);
+ g_error_free (dest);
+ g_error_free (src);
+
}
static void
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
index a6bef2379..d91b78fa0 100644
--- a/glib/tests/gvariant.c
+++ b/glib/tests/gvariant.c
@@ -2832,28 +2832,36 @@ do_failed_test (const gchar *pattern)
static void
test_invalid_varargs (void)
{
+ GVariant *value;
+ const gchar *end;
+
if (!g_test_undefined ())
return;
- if (do_failed_test ("*GVariant format string*"))
- {
- g_variant_new ("z");
- abort ();
- }
-
- if (do_failed_test ("*valid GVariant format string as a prefix*"))
- {
- const gchar *end;
-
- g_variant_new_va ("z", &end, NULL);
- abort ();
- }
-
- if (do_failed_test ("*type of `q' but * has a type of `y'*"))
- {
- g_variant_get (g_variant_new ("y", 'a'), "q");
- abort ();
- }
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*GVariant format string*");
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*valid_format_string*");
+ value = g_variant_new ("z");
+ g_test_assert_expected_messages ();
+ g_assert (value == NULL);
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*valid GVariant format string as a prefix*");
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*valid_format_string*");
+ value = g_variant_new_va ("z", &end, NULL);
+ g_test_assert_expected_messages ();
+ g_assert (value == NULL);
+
+ value = g_variant_new ("y", 'a');
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*type of `q' but * has a type of `y'*");
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*valid_format_string*");
+ g_variant_get (value, "q");
+ g_test_assert_expected_messages ();
+ g_variant_unref (value);
}
static void
@@ -3133,12 +3141,10 @@ test_varargs (void)
g_free (str);
}
- if (do_failed_test ("*NULL has already been returned*"))
- {
- g_variant_iter_next_value (&iter);
- abort ();
- }
-
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*NULL has already been returned*");
+ g_variant_iter_next_value (&iter);
+ g_test_assert_expected_messages ();
while (g_variant_iter_loop (i3, "*", &sub))
{
diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c
index e162202cd..31bf72f9f 100644
--- a/glib/tests/mainloop.c
+++ b/glib/tests/mainloop.c
@@ -87,9 +87,18 @@ test_maincontext_basic (void)
g_assert (g_source_get_context (source) == ctx);
g_assert (g_main_context_find_source_by_id (ctx, id) == NULL);
- g_source_unref (source);
g_main_context_unref (ctx);
+ if (g_test_undefined ())
+ {
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*source->context != NULL*failed*");
+ g_assert (g_source_get_context (source) == NULL);
+ g_test_assert_expected_messages ();
+ }
+
+ g_source_unref (source);
+
ctx = g_main_context_default ();
source = g_source_new (&funcs, sizeof (GSource));
g_source_set_funcs (source, &funcs);
diff --git a/glib/tests/markup-collect.c b/glib/tests/markup-collect.c
index 65cc67b5b..6c88a932e 100644
--- a/glib/tests/markup-collect.c
+++ b/glib/tests/markup-collect.c
@@ -238,22 +238,20 @@ static GMarkupParser cleanup_parser = {
static void
test_cleanup (void)
{
+ GMarkupParseContext *context;
+
if (!g_test_undefined ())
return;
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- GMarkupParseContext *context;
+ context = g_markup_parse_context_new (&cleanup_parser, 0, NULL, NULL);
+ g_markup_parse_context_parse (context, XML, -1, NULL);
- context = g_markup_parse_context_new (&cleanup_parser, 0, NULL, NULL);
- g_markup_parse_context_parse (context, XML, -1, NULL);
- g_markup_parse_context_end_parse (context, NULL);
- g_markup_parse_context_free (context);
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "assertion `context->state != STATE_ERROR' failed");
+ g_markup_parse_context_end_parse (context, NULL);
+ g_test_assert_expected_messages ();
- exit (0);
- }
- g_test_trap_assert_failed ();
- g_test_trap_assert_stderr ("*assertion `context->state != STATE_ERROR' failed*");
+ g_markup_parse_context_free (context);
}
int
diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c
index 8e376f740..f0ea4a229 100644
--- a/glib/tests/strfuncs.c
+++ b/glib/tests/strfuncs.c
@@ -329,19 +329,21 @@ test_strcanon (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- str = g_strcanon (NULL, "ab", 'y');
- }
- g_test_trap_assert_failed ();
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- str = g_strdup ("abxabxab");
- str = g_strcanon (str, NULL, 'y');
- g_free (str);
- }
- g_test_trap_assert_failed ();
+ gchar *ret;
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ str = g_strcanon (NULL, "ab", 'y');
+ g_test_assert_expected_messages ();
+ g_assert (str == NULL);
+
+ str = g_strdup ("abxabxab");
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ ret = g_strcanon (str, NULL, 'y');
+ g_test_assert_expected_messages ();
+ g_assert (ret == NULL);
+ g_free (str);
}
str = g_strdup ("abxabxab");
@@ -360,18 +362,19 @@ test_strcompress_strescape (void)
/* test compress */
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- str = g_strcompress (NULL);
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ str = g_strcompress (NULL);
+ g_test_assert_expected_messages ();
+ g_assert (str == NULL);
/* trailing slashes are not allowed */
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- str = g_strcompress ("abc\\");
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "*trailing \\*");
+ str = g_strcompress ("abc\\");
+ g_test_assert_expected_messages ();
+ g_assert_cmpstr (str, ==, "abc");
+ g_free (str);
}
str = g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\003\\177\\234\\313\\12345z");
@@ -382,11 +385,11 @@ test_strcompress_strescape (void)
/* test escape */
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- str = g_strescape (NULL, NULL);
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ str = g_strescape (NULL, NULL);
+ g_test_assert_expected_messages ();
+ g_assert (str == NULL);
}
str = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313", NULL);
@@ -416,17 +419,17 @@ test_ascii_strcasecmp (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- res = g_ascii_strcasecmp ("foo", NULL);
- }
- g_test_trap_assert_failed ();
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- res = g_ascii_strcasecmp (NULL, "foo");
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ res = g_ascii_strcasecmp ("foo", NULL);
+ g_test_assert_expected_messages ();
+ g_assert (res == FALSE);
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ res = g_ascii_strcasecmp (NULL, "foo");
+ g_test_assert_expected_messages ();
+ g_assert (res == FALSE);
}
res = g_ascii_strcasecmp ("FroboZZ", "frobozz");
@@ -492,11 +495,10 @@ test_strchug (void)
{
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- g_strchug (NULL);
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ g_strchug (NULL);
+ g_test_assert_expected_messages ();
}
do_test_strchug ("", "");
@@ -528,11 +530,10 @@ test_strchomp (void)
{
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- g_strchomp (NULL);
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ g_strchomp (NULL);
+ g_test_assert_expected_messages ();
}
do_test_strchomp ("", "");
@@ -552,11 +553,11 @@ test_strreverse (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- str = g_strreverse (NULL);
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ str = g_strreverse (NULL);
+ g_test_assert_expected_messages ();
+ g_assert (str == NULL);
}
str = p = g_strdup ("abcde");
@@ -656,17 +657,17 @@ test_has_prefix (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- res = g_str_has_prefix ("foo", NULL);
- }
- g_test_trap_assert_failed ();
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- res = g_str_has_prefix (NULL, "foo");
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ res = g_str_has_prefix ("foo", NULL);
+ g_test_assert_expected_messages ();
+ g_assert (res == FALSE);
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ res = g_str_has_prefix (NULL, "foo");
+ g_test_assert_expected_messages ();
+ g_assert (res == FALSE);
}
res = g_str_has_prefix ("foo", "bar");
@@ -698,17 +699,17 @@ test_has_suffix (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- res = g_str_has_suffix ("foo", NULL);
- }
- g_test_trap_assert_failed ();
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- res = g_str_has_suffix (NULL, "foo");
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ res = g_str_has_suffix ("foo", NULL);
+ g_test_assert_expected_messages ();
+ g_assert (res == FALSE);
+
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ res = g_str_has_suffix (NULL, "foo");
+ g_test_assert_expected_messages ();
+ g_assert (res == FALSE);
}
res = g_str_has_suffix ("foo", "bar");
@@ -880,11 +881,11 @@ test_strv_length (void)
if (g_test_undefined ())
{
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
- {
- l = g_strv_length (NULL);
- }
- g_test_trap_assert_failed ();
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+ "*assertion*!= NULL*");
+ l = g_strv_length (NULL);
+ g_test_assert_expected_messages ();
+ g_assert_cmpint (l, ==, 0);
}
strv = g_strsplit ("1,2,3,4", ",", -1);