123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include <check.h>
- #include <stdio.h>
- #include <libgen.h>
-
- #include "ttail_check.h"
- #include "ttail.h"
- #include "ttail_init.h"
- #include "ttail_search.h"
-
- /*
- * ttail_logline_subst() tests
- */
- START_TEST (test_search_subst_const1)
- {
- char expl[] = "Hello world !";
- const char *res;
- ttail->flag |= TTAIL_FLAG_PREFIX;
- ttail->prefix_sz = 4;
- res = ttail_logline_subst(ttail, expl);
- ck_assert(res != NULL);
- ck_assert(res == expl+4);
- }
- END_TEST
-
- START_TEST (test_search_subst_const2)
- {
- char expl[] = "Hello world !";
- const char *res;
- ttail->flag |= TTAIL_FLAG_PREFIX;
- ttail->prefix_sz = 0;
- res = ttail_logline_subst(ttail, expl);
- ck_assert(res != NULL);
- ck_assert(res == expl);
- }
- END_TEST
-
- START_TEST (test_search_subst_re1)
- {
- char expl[] = "1337 Foo Bar - Hello world !";
- char re[] = "^1337 Fo* Bar - ";
- const char *res;
- int ret;
- ret = ttail_set_prefix(ttail, re);
- ck_assert_int_eq(ret,0);
- res = ttail_logline_subst(ttail, expl);
- ck_assert(res != NULL);
- ck_assert_str_eq(res, "Hello world !");
- }
- END_TEST
-
- START_TEST (test_search_subst_re2)
- {
- char expl[] = "1337 Foo Bar - Hello world !";
- char re[] = "^[0-9]+ Fo{2} Bar - ";
- const char *res;
- int ret;
- ttail->flag |= TTAIL_FLAG_EXTENDED_RE;
- ret = ttail_set_prefix(ttail, re);
- ck_assert_int_eq(ret,0);
- res = ttail_logline_subst(ttail, expl);
- ck_assert(res != NULL);
- ck_assert_str_eq(res, "Hello world !");
- }
- END_TEST
-
- START_TEST (test_search_subst_re_nomatch)
- {
- char expl[] = "1337 Foo Bar - Hello world !";
- char re[] = "Never match m*";
- const char *res;
- int ret;
- ret = ttail_set_prefix(ttail, re);
- ck_assert_int_eq(ret,0);
- res = ttail_logline_subst(ttail, expl);
- ck_assert(res == NULL);
- }
- END_TEST
-
- TTAIL_CHECK_START("ttail search_files checks", "ttail_logline_subst() checks")
- TTAIL_SET_FIXTURE(setup_closest_fileinit, teardown_closest_fileinit);
- TTAIL_ADD_TEST(test_search_subst_const1);
- TTAIL_ADD_TEST(test_search_subst_const2);
- TTAIL_ADD_TEST(test_search_subst_re1);
- TTAIL_ADD_TEST(test_search_subst_re2);
- TTAIL_ADD_TEST(test_search_subst_re_nomatch);
- TTAIL_CHECK_END
|