From 8f5867d2edb46df7f8b02ae122a98c6281596752 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Fri, 26 Feb 2016 12:16:23 +1000 Subject: [PATCH] * added tests for f2b_regex_* --- t/CMakeLists.txt | 2 ++ t/t_rx_posix.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 t/t_rx_posix.c diff --git a/t/CMakeLists.txt b/t/CMakeLists.txt index 7f1b045..f158aca 100644 --- a/t/CMakeLists.txt +++ b/t/CMakeLists.txt @@ -5,7 +5,9 @@ set(SRC_DIR "../src") add_executable("t_logfile" "t_logfile.c" "${SRC_DIR}/logfile.c") add_executable("t_matches" "t_matches.c" "${SRC_DIR}/matches.c") add_executable("t_ipaddr" "t_ipaddr.c" "${SRC_DIR}/ipaddr.c" "${SRC_DIR}/matches.c") +add_executable("t_rx_posix" "t_rx_posix.c" "${SRC_DIR}/regexps_posix.c") add_test("tests/f2b_logfile_*" "t_logfile") add_test("tests/f2b_matches_*" "t_matches") add_test("tests/f2b_ipaddr_*" "t_ipaddr") +add_test("tests/f2b_regex_*" "t_rx_posix") diff --git a/t/t_rx_posix.c b/t/t_rx_posix.c new file mode 100644 index 0000000..fb7d636 --- /dev/null +++ b/t/t_rx_posix.c @@ -0,0 +1,22 @@ +#include "../src/common.h" +#include "../src/regexps.h" + +int main() { + f2b_regex_t *list = NULL; + f2b_regex_t *regex = NULL; + char matchbuf[32] = ""; + + assert((regex = f2b_regex_create("line without HOST", true)) == NULL); + assert((regex = f2b_regex_create("line with ", true)) != NULL); + + assert(f2b_regexlist_match(list, "line with 192.168.0.1", matchbuf, sizeof(matchbuf)) == false); + + assert((list = f2b_regexlist_append(list, regex)) != NULL); + + assert(f2b_regexlist_match(list, "line with 192.168.0.1", matchbuf, sizeof(matchbuf)) == true); + assert(strncmp(matchbuf, "192.168.0.1", sizeof(matchbuf)) == 0); + + assert((list = f2b_regexlist_destroy(list)) == NULL); + + return 0; +}