[glib] logging: improve test coverage



commit e1d4e06ab3dc9be6e239eb27f2f168e277ae273c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 19 01:04:48 2011 -0400

    logging: improve test coverage

 glib/tests/logging.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/logging.c b/glib/tests/logging.c
index ae7054d..0c83b80 100644
--- a/glib/tests/logging.c
+++ b/glib/tests/logging.c
@@ -132,6 +132,43 @@ test_fatal_log_mask (void)
   g_log_set_fatal_mask ("bu", flags);
 }
 
+static gint my_print_count = 0;
+static void
+my_print_handler (const gchar *text)
+{
+  my_print_count++;
+}
+
+static void
+test_print_handler (void)
+{
+  GPrintFunc old_print_handler;
+
+  old_print_handler = g_set_print_handler (my_print_handler);
+  g_assert (old_print_handler == NULL);
+
+  my_print_count = 0;
+  g_print ("bu ba");
+  g_assert_cmpint (my_print_count, ==, 1);
+
+  g_set_print_handler (NULL);
+}
+
+static void
+test_printerr_handler (void)
+{
+  GPrintFunc old_printerr_handler;
+
+  old_printerr_handler = g_set_printerr_handler (my_print_handler);
+  g_assert (old_printerr_handler == NULL);
+
+  my_print_count = 0;
+  g_printerr ("bu ba");
+  g_assert_cmpint (my_print_count, ==, 1);
+
+  g_set_printerr_handler (NULL);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -141,6 +178,8 @@ main (int argc, char *argv[])
   g_test_add_func ("/logging/warnings", test_warnings);
   g_test_add_func ("/logging/fatal-log-mask", test_fatal_log_mask);
   g_test_add_func ("/logging/set-handler", test_set_handler);
+  g_test_add_func ("/logging/print-handler", test_print_handler);
+  g_test_add_func ("/logging/printerr-handler", test_printerr_handler);
 
   return g_test_run ();
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]