From 7ebc8c7bd20ddcf9b5f82c4486039a849f7dfce6 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 21 Apr 2016 17:07:23 +1000 Subject: [PATCH] + t/t_cmsg.c --- t/CMakeLists.txt | 2 ++ t/t_cmsg.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 t/t_cmsg.c diff --git a/t/CMakeLists.txt b/t/CMakeLists.txt index 8771499..bc257e0 100644 --- a/t/CMakeLists.txt +++ b/t/CMakeLists.txt @@ -2,11 +2,13 @@ enable_testing() set(SRC_DIR "../src") +add_executable("t_cmsg" "t_cmsg.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/cmsg.c") add_executable("t_logfile" "t_logfile.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/logfile.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_config_param" "t_config_param.c" "${SRC_DIR}/strlcpy.c" "${SRC_DIR}/config.c" "${SRC_DIR}/log.c") +add_test("tests/f2b_cmsg_*" "t_cmsg") 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_cmsg.c b/t/t_cmsg.c new file mode 100644 index 0000000..0d31102 --- /dev/null +++ b/t/t_cmsg.c @@ -0,0 +1,24 @@ +#include "../src/common.h" +#include "../src/cmsg.h" + +int main() { + const char *argv[DATA_ARGS_MAX]; + f2b_cmsg_t msg; + + memset(&msg, 0x0, sizeof(msg)); + memset(argv, 0x0, sizeof(argv)); + + snprintf(msg.data, sizeof(msg.data), "test1\ntest2\n"); + msg.size = strlen(msg.data); + + f2b_cmsg_convert_args(&msg); + assert(memcmp(msg.data, "test1\0test2\0", 12) == 0); + + f2b_cmsg_extract_args(&msg, argv); + assert(argv[0] == msg.data + 0); + assert(argv[1] == msg.data + 6); + assert(memcmp(argv[0], "test1\0", 6) == 0); + assert(memcmp(argv[1], "test2\0", 6) == 0); + + return EXIT_SUCCESS; +}