Browse Source

+ t/t_cmd.c

master
Alex 'AdUser' Z 8 years ago
parent
commit
923c950a88
  1. 2
      t/CMakeLists.txt
  2. 32
      t/t_cmd.c

2
t/CMakeLists.txt

@ -2,12 +2,14 @@ enable_testing()
set(SRC_DIR "../src") set(SRC_DIR "../src")
add_executable("t_cmd" "t_cmd.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/commands.c")
add_executable("t_cmsg" "t_cmsg.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/cmsg.c") add_executable("t_cmsg" "t_cmsg.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/cmsg.c")
add_executable("t_matches" "t_matches.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/matches.c") add_executable("t_matches" "t_matches.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/matches.c")
add_executable("t_ipaddr" "t_ipaddr.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/matches.c" "${SRC_DIR}/ipaddr.c") add_executable("t_ipaddr" "t_ipaddr.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/matches.c" "${SRC_DIR}/ipaddr.c")
add_executable("t_config_param" "t_config_param.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/config.c" "${SRC_DIR}/log.c") add_executable("t_config_param" "t_config_param.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/config.c" "${SRC_DIR}/log.c")
add_executable("t_backend_usage" "t_backend_usage.c" "${SRC_DIR}/strlcpy.c") add_executable("t_backend_usage" "t_backend_usage.c" "${SRC_DIR}/strlcpy.c")
add_test("tests/f2b_cmd_*" "t_cmd")
add_test("tests/f2b_cmsg_*" "t_cmsg") add_test("tests/f2b_cmsg_*" "t_cmsg")
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")

32
t/t_cmd.c

@ -0,0 +1,32 @@
#include "../src/common.h"
#include "../src/commands.h"
int main() {
char buf[1024];
const char *line;
buf[0] = '\0';
f2b_cmd_append_arg(buf, sizeof(buf), "42");
assert(strcmp(buf, "42\n") == 0);
line = "status";
assert(f2b_cmd_parse(buf, sizeof(buf), line) == CMD_STATUS);
line = "statu"; /* no such command */
assert(f2b_cmd_parse(buf, sizeof(buf), line) == CMD_NONE);
line = "jail test"; /* incomplete command */
assert(f2b_cmd_parse(buf, sizeof(buf), line) == CMD_NONE);
buf[0] = '\0';
line = "jail test status";
assert(f2b_cmd_parse(buf, sizeof(buf), line) == CMD_JAIL_STATUS);
assert(strcmp(buf, "test\n") == 0);
buf[0] = '\0';
line = "jail test set bantime 7200";
assert(f2b_cmd_parse(buf, sizeof(buf), line) == CMD_JAIL_SET);
assert(strcmp(buf, "test\nbantime\n7200\n") == 0);
return EXIT_SUCCESS;
}
Loading…
Cancel
Save