Increase the timeout for some GLib tests
[glib.git] / glib / tests / error.c
blobebbd965dc075b575341c60dcec4a159f212c467c
1 #include <glib.h>
3 static void
4 test_overwrite (void)
6 GError *error, *dest, *src;
8 if (!g_test_undefined ())
9 return;
11 error = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
13 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
14 "*set over the top*");
15 g_set_error_literal (&error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "bla");
16 g_test_assert_expected_messages ();
18 g_assert_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY);
19 g_error_free (error);
22 dest = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
23 src = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "bla");
25 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
26 "*set over the top*");
27 g_propagate_error (&dest, src);
28 g_test_assert_expected_messages ();
30 g_assert_error (dest, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY);
31 g_error_free (dest);
34 static void
35 test_prefix (void)
37 GError *error;
38 GError *dest, *src;
40 error = NULL;
41 g_prefix_error (&error, "foo %d %s: ", 1, "two");
42 g_assert (error == NULL);
44 error = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
45 g_prefix_error (&error, "foo %d %s: ", 1, "two");
46 g_assert_cmpstr (error->message, ==, "foo 1 two: bla");
47 g_error_free (error);
49 dest = NULL;
50 src = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
51 g_propagate_prefixed_error (&dest, src, "foo %d %s: ", 1, "two");
52 g_assert_cmpstr (dest->message, ==, "foo 1 two: bla");
53 g_error_free (dest);
56 static void
57 test_literal (void)
59 GError *error;
61 error = NULL;
62 g_set_error_literal (&error, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "%s %d %x");
63 g_assert_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY);
64 g_assert_cmpstr (error->message, ==, "%s %d %x");
65 g_error_free (error);
68 static void
69 test_copy (void)
71 GError *error;
72 GError *copy;
74 error = NULL;
75 g_set_error_literal (&error, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "%s %d %x");
76 copy = g_error_copy (error);
78 g_assert_error (copy, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY);
79 g_assert_cmpstr (copy->message, ==, "%s %d %x");
81 g_error_free (error);
82 g_error_free (copy);
85 int
86 main (int argc, char *argv[])
88 g_test_init (&argc, &argv, NULL);
90 g_test_add_func ("/error/overwrite", test_overwrite);
91 g_test_add_func ("/error/prefix", test_prefix);
92 g_test_add_func ("/error/literal", test_literal);
93 g_test_add_func ("/error/copy", test_copy);
95 return g_test_run ();