summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile2
-rw-r--r--test/basictests.c43
-rw-r--r--test/parse.c25
3 files changed, 62 insertions, 8 deletions
diff --git a/test/Makefile b/test/Makefile
index 36d5092..5ebac01 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,3 +1,3 @@
-DIR_TEST_ITEMS := testrunner:testmain.c;basictests.c
+DIR_TEST_ITEMS := testrunner:testmain.c;basictests.c parse:parse.c
include $(NSBUILD)/Makefile.subdir
diff --git a/test/basictests.c b/test/basictests.c
index b83ed9f..d74df87 100644
--- a/test/basictests.c
+++ b/test/basictests.c
@@ -171,7 +171,7 @@ START_TEST (test_nslog_simple_filter_corked_message)
"Captured message wasn't correct filename");
fail_unless(strcmp(captured_context.funcname, "test_nslog_simple_filter_corked_message") == 0,
"Captured message wasn't correct function name");
-
+
}
END_TEST
@@ -198,7 +198,34 @@ START_TEST (test_nslog_simple_filter_uncorked_message)
"Captured message wasn't correct filename");
fail_unless(strcmp(captured_context.funcname, "test_nslog_simple_filter_uncorked_message") == 0,
"Captured message wasn't correct function name");
-
+
+}
+END_TEST
+
+START_TEST (test_nslog_basic_filter_sprintf)
+{
+ char *ct = nslog_filter_sprintf(cat_test);
+ fail_unless(ct != NULL, "Unable to sprintf");
+ fail_unless(strcmp(ct, "cat:test") == 0,
+ "Printed category test is wrong");
+ free(ct);
+ ct = nslog_filter_sprintf(cat_another);
+ fail_unless(ct != NULL, "Unable to sprintf");
+ fail_unless(strcmp(ct, "cat:another") == 0,
+ "Printed category another is wrong");
+ free(ct);
+}
+END_TEST
+
+START_TEST (test_nslog_parse_and_sprintf)
+{
+ nslog_filter_t *filt;
+ fail_unless(nslog_filter_from_text("cat:test", &filt) == NSLOG_NO_ERROR,
+ "Unable to parse cat:test");
+ char *ct = nslog_filter_sprintf(filt);
+ nslog_filter_unref(filt);
+ fail_unless(strcmp(ct, "cat:test") == 0,
+ "Printed parsed cat:test not right");
}
END_TEST
@@ -209,22 +236,24 @@ nslog_basic_suite(SRunner *sr)
{
Suite *s = suite_create("libnslog: Basic tests");
TCase *tc_basic = NULL;
-
+
tc_basic = tcase_create("Simple log checks, no filters");
-
+
tcase_add_checked_fixture(tc_basic, with_simple_context_setup,
with_simple_context_teardown);
tcase_add_test(tc_basic, test_nslog_trivial_corked_message);
tcase_add_test(tc_basic, test_nslog_trivial_uncorked_message);
suite_add_tcase(s, tc_basic);
-
+
tc_basic = tcase_create("Simple filter checks");
-
+
tcase_add_checked_fixture(tc_basic, with_simple_filter_context_setup,
with_simple_filter_context_teardown);
tcase_add_test(tc_basic, test_nslog_simple_filter_corked_message);
tcase_add_test(tc_basic, test_nslog_simple_filter_uncorked_message);
+ tcase_add_test(tc_basic, test_nslog_basic_filter_sprintf);
+ tcase_add_test(tc_basic, test_nslog_parse_and_sprintf);
suite_add_tcase(s, tc_basic);
-
+
srunner_add_suite(sr, s);
}
diff --git a/test/parse.c b/test/parse.c
new file mode 100644
index 0000000..9fca97b
--- /dev/null
+++ b/test/parse.c
@@ -0,0 +1,25 @@
+#include "nslog/nslog.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ if (argc != 2) {
+ fprintf(stderr, "usage: parse 'filtertext'\n");
+ return 1;
+ }
+ nslog_filter_t *filt;
+ nslog_error err;
+
+ err = nslog_filter_from_text(argv[1], &filt);
+ if (err != NSLOG_NO_ERROR) {
+ fprintf(stderr, "Unable to parse.\n");
+ return 2;
+ }
+ char *ct = nslog_filter_sprintf(filt);
+ filt = nslog_filter_unref(filt);
+ printf("%s\n", ct);
+ free(ct);
+ return 0;
+}