Commit 6ab1c772 authored by Matthias Clasen's avatar Matthias Clasen

Pass correct data to fatal log handlers

This was pointed out by John Ralls in bug 653052.
He also provided the test case.
parent 1435db48
...@@ -734,7 +734,7 @@ g_logv (const gchar *log_domain, ...@@ -734,7 +734,7 @@ g_logv (const gchar *log_domain,
&& !(test_level & G_LOG_LEVEL_ERROR)) && !(test_level & G_LOG_LEVEL_ERROR))
{ {
masquerade_fatal = fatal_log_func masquerade_fatal = fatal_log_func
&& !fatal_log_func (log_domain, test_level, msg, data); && !fatal_log_func (log_domain, test_level, msg, fatal_log_data);
} }
g_free (msg); g_free (msg);
......
...@@ -169,10 +169,67 @@ test_printerr_handler (void) ...@@ -169,10 +169,67 @@ test_printerr_handler (void)
g_set_printerr_handler (NULL); g_set_printerr_handler (NULL);
} }
static char *fail_str = "foo";
static char *log_str = "bar";
gboolean
good_failure_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *msg,
gpointer user_data)
{
g_test_message ("The Good Fail Message Handler\n");
g_assert ((char *)user_data != log_str);
g_assert ((char *)user_data == fail_str);
return FALSE;
}
gboolean
bad_failure_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *msg,
gpointer user_data)
{
g_test_message ("The Bad Fail Message Handler\n");
g_assert ((char *)user_data == log_str);
g_assert ((char *)user_data != fail_str);
return FALSE;
}
void
test_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *msg,
gpointer user_data)
{
g_test_message ("The Log Message Handler\n");
g_assert ((char *)user_data != fail_str);
g_assert ((char *)user_data == log_str);
}
void
bug653052 (void)
{
g_test_bug ("653052");
g_test_log_set_fatal_handler (good_failure_handler, fail_str);
g_log_set_default_handler (test_handler, log_str);
g_return_if_fail (0);
g_test_log_set_fatal_handler (bad_failure_handler, fail_str);
g_log_set_default_handler (test_handler, log_str);
g_return_if_fail (0);
}
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://bugzilla.gnome.org/");
g_test_add_func ("/logging/default-handler", test_default_handler); g_test_add_func ("/logging/default-handler", test_default_handler);
g_test_add_func ("/logging/warnings", test_warnings); g_test_add_func ("/logging/warnings", test_warnings);
...@@ -180,6 +237,7 @@ main (int argc, char *argv[]) ...@@ -180,6 +237,7 @@ main (int argc, char *argv[])
g_test_add_func ("/logging/set-handler", test_set_handler); 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/print-handler", test_print_handler);
g_test_add_func ("/logging/printerr-handler", test_printerr_handler); g_test_add_func ("/logging/printerr-handler", test_printerr_handler);
g_test_add_func ("/logging/653052", bug653052);
return g_test_run (); return g_test_run ();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment