From 532a1d6f579a99304f5b96ea3f57cee4c793b695 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Sat, 20 Feb 2016 18:18:25 +1000 Subject: [PATCH] * basic tests for ipaddr.[ch] --- t/CMakeLists.txt | 2 ++ t/t_ipaddr.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 t/t_ipaddr.c diff --git a/t/CMakeLists.txt b/t/CMakeLists.txt index 711a59a..7f1b045 100644 --- a/t/CMakeLists.txt +++ b/t/CMakeLists.txt @@ -4,6 +4,8 @@ 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_test("tests/f2b_logfile_*" "t_logfile") add_test("tests/f2b_matches_*" "t_matches") +add_test("tests/f2b_ipaddr_*" "t_ipaddr") diff --git a/t/t_ipaddr.c b/t/t_ipaddr.c new file mode 100644 index 0000000..ea6bcf1 --- /dev/null +++ b/t/t_ipaddr.c @@ -0,0 +1,30 @@ +#include "../src/common.h" +#include "../src/ipaddr.h" + +int main() { + f2b_ipaddr_t *list = NULL; + f2b_ipaddr_t *addr = NULL; + + assert(f2b_addrlist_lookup(list, "127.0.0.1") == NULL); + + assert((addr = f2b_ipaddr_create("400.400.400.400", 15)) == NULL); + assert((addr = f2b_ipaddr_create("127.0.0.1", 15)) != NULL); + + assert(addr->type == AF_INET); + assert(addr->next == NULL); + assert(strncmp(addr->text, "127.0.0.1", sizeof(addr->text)) == 0); + assert(addr->matches.times != NULL); + assert(addr->matches.max == 15); + assert(addr->matches.used == 0); + + assert(0); /* TODO: add more ips to list & test this cases */ + + assert((list = f2b_addrlist_append(list, addr)) != NULL); + assert(f2b_addrlist_lookup(list, "127.0.0.1") != NULL); + assert(list == addr); + + assert((list = f2b_addrlist_remove(list, "127.4.4.4")) != NULL); + assert((list = f2b_addrlist_remove(list, "127.0.0.1")) == NULL); + + return 0; +}