From 14cf3a64de917598a7f10e45026661c00563799d Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Wed, 2 Mar 2016 13:25:26 +1000 Subject: [PATCH] + t/t_config_param.c --- t/CMakeLists.txt | 2 ++ t/t_config_param.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 t/t_config_param.c diff --git a/t/CMakeLists.txt b/t/CMakeLists.txt index f158aca..788ef7a 100644 --- a/t/CMakeLists.txt +++ b/t/CMakeLists.txt @@ -6,8 +6,10 @@ 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_executable("t_config_param" "t_config_param.c" "${SRC_DIR}/config.c" "${SRC_DIR}/log.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") +add_test("tests/f2b_config_param*" "t_config_param") diff --git a/t/t_config_param.c b/t/t_config_param.c new file mode 100644 index 0000000..0b7f264 --- /dev/null +++ b/t/t_config_param.c @@ -0,0 +1,38 @@ +#include "../src/common.h" +#include "../src/config.h" + +int main() { + f2b_config_param_t *param = NULL; + + assert(f2b_config_parse_kv_pair("") == NULL); + assert(f2b_config_parse_kv_pair("#") == NULL); + assert(f2b_config_parse_kv_pair("=") == NULL); + assert(f2b_config_parse_kv_pair("key=") == NULL); + assert(f2b_config_parse_kv_pair("key =") == NULL); + assert(f2b_config_parse_kv_pair("key = ") == NULL); + assert(f2b_config_parse_kv_pair( "=value") == NULL); + assert(f2b_config_parse_kv_pair( "= value") == NULL); + assert(f2b_config_parse_kv_pair(" = value") == NULL); + + assert((param = f2b_config_parse_kv_pair("key=value")) != NULL); + assert(strcmp(param->name, "key") == 0); + assert(strcmp(param->value, "value") == 0); + free(param); + + assert((param = f2b_config_parse_kv_pair("key = value")) != NULL); + assert(strcmp(param->name, "key") == 0); + assert(strcmp(param->value, "value") == 0); + free(param); + + assert((param = f2b_config_parse_kv_pair("key=value #comment")) != NULL); + assert(strcmp(param->name, "key") == 0); + assert(strcmp(param->value, "value") == 0); + free(param); + + assert((param = f2b_config_parse_kv_pair("key=value#compose")) != NULL); + assert(strcmp(param->name, "key") == 0); + assert(strcmp(param->value, "value#compose") == 0); + free(param); + + return 0; +}