#include <glib.h>

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
log_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
good_test_func( void )
{
  g_test_log_set_fatal_handler((GTestLogFatalFunc)good_failure_handler,
			       (gpointer)fail_str);
  g_log_set_default_handler((GLogFunc)log_handler, (gpointer)log_str);
  g_return_if_fail(0);
}

void
bad_test_func( void )
{
  g_test_log_set_fatal_handler((GTestLogFatalFunc)bad_failure_handler,
			       (gpointer)fail_str);
  g_log_set_default_handler((GLogFunc)log_handler, (gpointer)log_str);
  g_return_if_fail(0);
}

int main (int argc, char**argv)
{
  g_test_init(&argc, &argv);
  g_test_add_func("/LogTest/Bad", (GTestFunc)bad_test_func);
  g_test_add_func("/LogTest/Good", (GTestFunc)good_test_func);
  g_test_run();
}
