Browse Source

* added tests for f2b_regex_*

master
Alex 'AdUser' Z 9 years ago
parent
commit
8f5867d2ed
  1. 2
      t/CMakeLists.txt
  2. 22
      t/t_rx_posix.c

2
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_logfile" "t_logfile.c" "${SRC_DIR}/logfile.c")
add_executable("t_matches" "t_matches.c" "${SRC_DIR}/matches.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_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_logfile_*" "t_logfile")
add_test("tests/f2b_matches_*" "t_matches") add_test("tests/f2b_matches_*" "t_matches")
add_test("tests/f2b_ipaddr_*" "t_ipaddr") add_test("tests/f2b_ipaddr_*" "t_ipaddr")
add_test("tests/f2b_regex_*" "t_rx_posix")

22
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 <HOST>", 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;
}
Loading…
Cancel
Save