[glib] Test some GError functionality explicitly
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Test some GError functionality explicitly
- Date: Sat, 31 Jul 2010 06:49:46 +0000 (UTC)
commit ef4690c6c96824a2099a5feca11a1785329ec5ca
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jul 31 02:14:28 2010 -0400
Test some GError functionality explicitly
glib/tests/Makefile.am | 3 ++
glib/tests/error.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 0269dc9..81a3cec 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -140,6 +140,9 @@ pattern_LDADD = $(progs_ldadd)
TEST_PROGS += logging
logging_LDADD = $(progs_ldadd)
+TEST_PROGS += error
+error_LDADD = $(progs_ldadd)
+
if OS_UNIX
# some testing of gtester funcitonality
diff --git a/glib/tests/error.c b/glib/tests/error.c
new file mode 100644
index 0000000..ed5211a
--- /dev/null
+++ b/glib/tests/error.c
@@ -0,0 +1,73 @@
+#include <glib.h>
+
+static void
+test_overwrite (void)
+{
+ 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*");
+}
+
+static void
+test_prefix (void)
+{
+ GError *error;
+ GError *dest, *src;
+
+ error = NULL;
+ g_prefix_error (&error, "foo %d %s: ", 1, "two");
+ g_assert (error == NULL);
+
+ error = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
+ g_prefix_error (&error, "foo %d %s: ", 1, "two");
+ g_assert_cmpstr (error->message, ==, "foo 1 two: bla");
+ g_error_free (error);
+
+ dest = NULL;
+ src = g_error_new_literal (G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "bla");
+ g_propagate_prefixed_error (&dest, src, "foo %d %s: ", 1, "two");
+ g_assert_cmpstr (dest->message, ==, "foo 1 two: bla");
+ g_error_free (dest);
+ g_error_free (src);
+}
+
+static void
+test_literal (void)
+{
+ GError *error;
+
+ error = NULL;
+ g_set_error_literal (&error, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "%s %d %x");
+ g_assert_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY);
+ g_assert_cmpstr (error->message, ==, "%s %d %x");
+ g_error_free (error);
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/error/overwrite", test_overwrite);
+ g_test_add_func ("/error/prefix", test_prefix);
+ g_test_add_func ("/error/literal", test_literal);
+
+ return g_test_run ();
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]