From b5c62a138575872a1d2b45ea74d14960d4d4015c Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 24 Mar 2012 22:19:58 +0000 Subject: [PATCH] Testing: Add a basic print-to-stdout log handler as a test debugging aid. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22112 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/test-core/test-stuff.c | 11 +++++++++++ src/test-core/test-stuff.h | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/src/test-core/test-stuff.c b/src/test-core/test-stuff.c index 6c5d5b3728..6e4ef920fa 100644 --- a/src/test-core/test-stuff.c +++ b/src/test-core/test-stuff.c @@ -450,6 +450,17 @@ test_checked_handler (const char *log_domain, GLogLevelFlags log_level, } +gboolean +test_log_handler (const char *log_domain, GLogLevelFlags log_level, + const gchar *msg, gpointer user_data ) +{ + gchar *level = test_log_level (log_level); + g_printf ( "<%s> (%s) %s\n", level, log_domain, msg); + g_free (level); + g_assert (log_level ^ G_LOG_FLAG_FATAL); + return FALSE; +} + void test_set_called( const gboolean val ) { diff --git a/src/test-core/test-stuff.h b/src/test-core/test-stuff.h index 4bd1969411..748b4d6d96 100644 --- a/src/test-core/test-stuff.h +++ b/src/test-core/test-stuff.h @@ -112,6 +112,15 @@ typedef struct */ gboolean test_checked_handler (const char *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data); + +/** + * Just print the log message. Since GLib has a habit of eating its + * log messages, it's sometimes useful to call + * g_test_log_set_fatal_handler() with this to make sure that + * g_return_if_fail() error messages make it to the surface. + */ +gboolean test_log_handler (const char *log_domain, GLogLevelFlags log_level, + const gchar *msg, gpointer user_data); /** * Just returns FALSE or suppresses the message regardless of what the * error is. Use this only as a last resort.