Add unit test for getting neu_json_tty

This commit is contained in:
lixiumei
2022-02-14 17:00:04 +08:00
committed by Parker Liu
parent a43e2d56c9
commit 3e4f0e073e
2 changed files with 53 additions and 0 deletions
+8
View File
@@ -43,6 +43,13 @@ target_include_directories(json_group_config_test PRIVATE
)
target_link_libraries(json_group_config_test neuron-base gtest_main gtest)
add_executable(json_tty_test json_tty_test.cc ${SRC_PARSER})
target_include_directories(json_tty_test PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/include
)
target_link_libraries(json_tty_test neuron-base gtest_main gtest pthread jansson)
add_executable(variable_test variable_test.cc)
target_include_directories(variable_test PRIVATE
${CMAKE_SOURCE_DIR}/src
@@ -171,6 +178,7 @@ gtest_discover_tests(json_datatag_table_test)
gtest_discover_tests(json_nodes_test)
gtest_discover_tests(json_plugin_test)
gtest_discover_tests(json_group_config_test)
gtest_discover_tests(json_tty_test)
gtest_discover_tests(uuid_test)
gtest_discover_tests(schema_valid_test)
gtest_discover_tests(http_test)
+45
View File
@@ -0,0 +1,45 @@
#include <stdlib.h>
#include <gtest/gtest.h>
#include "json/neu_json_fn.h"
#include "json/neu_json_tty.h"
TEST(JsonTtytest, GetTtyEncode)
{
char *buf =
(char *) "{\"ttys\": [\"/dev/tty0\", \"/dev/tty1\", \"/dev/tty2\", "
"\"/dev/tty3\", \"/dev/tty4\", \"/dev/tty5\", \"/dev/tty6\"]}";
char *result = NULL;
neu_json_get_tty_resp_t resp = {
.n_tty = 7,
};
resp.ttys = (neu_json_get_tty_resp_tty_t *) calloc(
7, sizeof(neu_json_get_tty_resp_tty_t));
resp.ttys[0] = strdup((char *) "/dev/tty0");
resp.ttys[1] = strdup((char *) "/dev/tty1");
resp.ttys[2] = strdup((char *) "/dev/tty2");
resp.ttys[3] = strdup((char *) "/dev/tty3");
resp.ttys[4] = strdup((char *) "/dev/tty4");
resp.ttys[5] = strdup((char *) "/dev/tty5");
resp.ttys[6] = strdup((char *) "/dev/tty6");
EXPECT_EQ(
0, neu_json_encode_by_fn(&resp, neu_json_encode_get_tty_resp, &result));
EXPECT_STREQ(buf, result);
free(resp.ttys[0]);
free(resp.ttys[1]);
free(resp.ttys[2]);
free(resp.ttys[3]);
free(resp.ttys[4]);
free(resp.ttys[5]);
free(resp.ttys[6]);
free(resp.ttys);
free(result);
}