Commit 059d0744 authored by Christian Kellner's avatar Christian Kellner

test: logging: checks for log_stdstream

Check the stdstream logger (used by the daemon_logger) is working,
but forking and using it as logger and later verifying we got what
we want.
parent 50320cbc
......@@ -241,6 +241,53 @@ test_log_macros (TestLog *tt, gconstpointer user_data)
bolt_bug (msg);
}
static GLogWriterOutput
test_log_logger (GLogLevelFlags level,
const GLogField *fields,
gsize n_fields,
gpointer user_data)
{
g_autoptr(BoltLogCtx) ctx = NULL;
g_return_val_if_fail (fields != NULL, G_LOG_WRITER_UNHANDLED);
g_return_val_if_fail (n_fields > 0, G_LOG_WRITER_UNHANDLED);
ctx = bolt_log_ctx_acquire (fields, n_fields);
if (ctx == NULL)
return G_LOG_WRITER_UNHANDLED;
return bolt_log_stdstream (ctx, level, 0);
}
static void
test_log_stdstream (TestLog *tt, gconstpointer user_data)
{
g_autoptr(GError) err = NULL;
const char *msg = NULL;
if (g_test_subprocess ())
{
g_log_set_writer_func (test_log_logger, tt, NULL);
msg = "no udev";
g_set_error_literal (&err, BOLT_ERROR, BOLT_ERROR_UDEV, msg);
bolt_warn_err (err, LOG_TOPIC ("the_topic"), "WARNUNG-1");
g_warning ("WARNUNG-2");
g_critical ("WARNUNG-3");
exit (0);
}
g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_passed ();
g_test_trap_assert_stderr ("*WARNUNG-1*");
g_test_trap_assert_stderr ("*the_topic*");
g_test_trap_assert_stderr ("*WARNUNG-2*");
g_test_trap_assert_stderr ("*WARNUNG-3*");
}
int
main (int argc, char **argv)
{
......@@ -279,5 +326,13 @@ main (int argc, char **argv)
test_log_macros,
test_log_tear_down);
g_test_add ("/logging/log_stdstream",
TestLog,
NULL,
test_log_setup,
test_log_stdstream,
test_log_tear_down);
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