Browse Source

* fix test for filter/preg

+ add test for filter/pcre
master
Alex 'AdUser' Z 9 years ago
parent
commit
484b28469d
  1. 9
      t/CMakeLists.txt
  2. 50
      t/t_filters.c
  3. 22
      t/t_rx_posix.c

9
t/CMakeLists.txt

@ -5,11 +5,16 @@ 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" "${SRC_DIR}/log.c")
add_executable("t_config_param" "t_config_param.c" "${SRC_DIR}/config.c" "${SRC_DIR}/log.c")
add_executable("t_filter_preg" "t_filters.c" "${SRC_DIR}/filters/preg.c")
add_executable("t_filter_pcre" "t_filters.c" "${SRC_DIR}/filters/pcre.c")
target_link_libraries("t_filter_pcre" "pcre")
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")
add_test("tests/f2b_config_param*" "t_config_param")
add_test("tests/filter/preg" "t_filter_preg")
add_test("tests/filter/pcre" "t_filter_pcre")

50
t/t_filters.c

@ -0,0 +1,50 @@
#include "../src/common.h"
#include "../src/log.h"
#include "../src/ipaddr.h"
#include "../src/filters/filter.h"
int main() {
cfg_t *filter = NULL;
char matchbuf[IPADDR_MAX] = "";
bool result = false;
filter = create("test");
assert(filter != NULL);
result = config(filter, "nonexistent", "yes");
assert(result == false);
result = config(filter, "icase", "yes");
assert(result == true);
result = config(filter, "icase", "no");
assert(result == true);
result = ready(filter);
assert(result == false);
result = append(filter, "host without marker");
assert(result == false);
result = append(filter, "host with marker <HOST>");
assert(result == true);
result = ready(filter);
assert(result == true);
result = match(filter, "host", matchbuf, sizeof(matchbuf));
assert(result == false);
result = match(filter, "host with marker <HOST>", matchbuf, sizeof(matchbuf));
assert(result == false);
result = match(filter, "host with marker 1.2.3.4", matchbuf, sizeof(matchbuf));
assert(result == true);
result = match(filter, "host with marker example.com", matchbuf, sizeof(matchbuf));
assert(result == false);
destroy(filter);
return 0;
}

22
t/t_rx_posix.c

@ -1,22 +0,0 @@
#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