From 0802791081ba39298aa93f0e6860c3b62800df73 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 14 Feb 2012 04:05:43 +1030 Subject: tdb: import unit tests from CCAN into tdb/test/ I pulled tdb into CCAN as an experiment a while ago; it doesn't belong there, but it has accumulated some important unit tests. These are copied from CCAN version init-1486-gc438ec1 with #include "../" changed to #include "../common/". Signed-off-by: Rusty Russell --- lib/tdb/test/logging.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/tdb/test/logging.c (limited to 'lib/tdb/test/logging.c') diff --git a/lib/tdb/test/logging.c b/lib/tdb/test/logging.c new file mode 100644 index 0000000000..ae598a9845 --- /dev/null +++ b/lib/tdb/test/logging.c @@ -0,0 +1,33 @@ +#include "logging.h" +#include +#include +#include +#include +#include + +bool suppress_logging = false; +const char *log_prefix = ""; + +/* Turn log messages into tap diag messages. */ +static void taplog(struct tdb_context *tdb, + enum tdb_debug_level level, + const char *fmt, ...) +{ + va_list ap; + char line[200]; + + if (suppress_logging) + return; + + va_start(ap, fmt); + vsprintf(line, fmt, ap); + va_end(ap); + + /* Strip trailing \n: diag adds it. */ + if (line[0] && line[strlen(line)-1] == '\n') + diag("%s%.*s", log_prefix, (unsigned)strlen(line)-1, line); + else + diag("%s%s", log_prefix, line); +} + +struct tdb_logging_context taplogctx = { taplog, NULL }; -- cgit