From 8b4ce0ba86d0396bde2546dd248c863876da4106 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 11 Jun 2017 10:08:37 +0100 Subject: Another step toward filters working --- test/Makefile | 2 +- test/basic.c | 10 +++++----- test/explicitfilter.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/runtest.sh | 2 +- 4 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 test/explicitfilter.c (limited to 'test') diff --git a/test/Makefile b/test/Makefile index 0cebdaa..033033f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,3 +1,3 @@ -DIR_TEST_ITEMS := basic:basic.c +DIR_TEST_ITEMS := basic:basic.c explicitfilter:explicitfilter.c include $(NSBUILD)/Makefile.subdir diff --git a/test/basic.c b/test/basic.c index 7626dd8..d514814 100644 --- a/test/basic.c +++ b/test/basic.c @@ -4,7 +4,7 @@ * This file is part of libnslog. * * Licensed under the MIT License, - * http://www.opensource.org/licenses/mit-license.php + * http://www.opensource.org/licenses/mit-license.php */ #include "nslog/nslog.h" @@ -18,10 +18,10 @@ static void test_render_function( const char *fmt, va_list args) { (void)ctx; - fprintf(stderr, "%s %s:%d [%s] %s() ", - nslog_level_name(ctx->level), - ctx->filename, ctx->lineno, - ctx->category->name, + fprintf(stderr, "%s %s:%d [%s] %s() ", + nslog_level_name(ctx->level), + ctx->filename, ctx->lineno, + ctx->category->name, ctx->funcname); vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); diff --git a/test/explicitfilter.c b/test/explicitfilter.c new file mode 100644 index 0000000..c7aca8a --- /dev/null +++ b/test/explicitfilter.c @@ -0,0 +1,50 @@ +/* + * Copyright 2017 Daniel Silverstone + * + * This file is part of libnslog. + * + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + */ + +#include "nslog/nslog.h" + +#include +#include + +NSLOG_DEFINE_CATEGORY(test, "Test category"); + +static void test_render_function( + void *_ctx, nslog_entry_context_t *ctx, + const char *fmt, va_list args) +{ + (void)ctx; + fprintf(stderr, "%s %s:%d [%s] %s() ", + nslog_level_name(ctx->level), + ctx->filename, ctx->lineno, + ctx->category->name, + ctx->funcname); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + +int main(int argc, char **argv) +{ + nslog_set_render_callback(test_render_function, NULL); + nslog_uncork(); + + nslog_filter_t *cat_test, *cat_another; + + assert(nslog_filter_category_new("test", &cat_test) == NSLOG_NO_ERROR); + assert(nslog_filter_category_new("another", &cat_another) == NSLOG_NO_ERROR); + + NSLOG(test, INFO, "Hurrah, a message!"); + assert(nslog_filter_set_active(cat_test, NULL) == NSLOG_NO_ERROR); + NSLOG(test, INFO, "You should see me."); + assert(nslog_filter_set_active(cat_another, NULL) == NSLOG_NO_ERROR); + NSLOG(test, INFO, "You should not see me!"); + assert(nslog_filter_set_active(NULL, NULL) == NSLOG_NO_ERROR); + NSLOG(test, INFO, "You should see this one though."); + + return 0; +} diff --git a/test/runtest.sh b/test/runtest.sh index 1b67a97..3bf903e 100755 --- a/test/runtest.sh +++ b/test/runtest.sh @@ -5,7 +5,7 @@ set -e TEST_PATH=$1 TEST_PFX=$4 -for TEST in basic; do +for TEST in basic explicitfilter; do ${TEST_PATH}/${TEST_PFX}${TEST} done -- cgit v1.2.3