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
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
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))
{
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");
/* 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");
/* 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);
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");
{
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 ("", "");
{
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 ("", "");
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");
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");
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");
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);