diff --git a/src/parser/neu_json_node.c b/src/parser/neu_json_node.c index c292eae1..80c46946 100644 --- a/src/parser/neu_json_node.c +++ b/src/parser/neu_json_node.c @@ -186,17 +186,18 @@ int neu_parse_decode_delete_nodes_req( int neu_parse_encode_delete_nodes_res(struct neu_parse_delete_nodes_res *res, char ** buf) { - neu_json_elem_t elems[] = { { - .name = NEU_PARSE_FUNCTION, - .t = NEU_JSON_INT, + neu_json_elem_t elems[] = { { .name = NEU_PARSE_FUNCTION, + .t = NEU_JSON_INT, + .v.val_int = res->function }, + { + .name = NEU_PARSE_UUID, + .t = NEU_JSON_STR, + .v.val_str = res->uuid, }, { - .name = NEU_PARSE_UUID, - .t = NEU_JSON_STR, - }, - { - .name = NEU_PARSE_ERROR, - .t = res->error, + .name = NEU_PARSE_ERROR, + .t = NEU_JSON_INT, + .v.val_int = res->error, } }; return neu_json_encode(elems, 3, buf); diff --git a/src/parser/neu_json_parser.c b/src/parser/neu_json_parser.c index 66c17ed0..975111a4 100644 --- a/src/parser/neu_json_parser.c +++ b/src/parser/neu_json_parser.c @@ -228,7 +228,7 @@ int neu_parse_encode(void *result, char **buf) break; case NEU_PARSE_OP_UPDATE_PLUGIN: neu_parse_encode_update_plugin_res( - (struct neu_parese_update_plugin_res *) result, buf); + (struct neu_parse_update_plugin_res *) result, buf); break; case NEU_PARSE_OP_GET_PLUGIN: neu_parse_encode_get_plugin_res( diff --git a/src/parser/neu_json_plugin.c b/src/parser/neu_json_plugin.c index 131ebae0..b1e9670e 100644 --- a/src/parser/neu_json_plugin.c +++ b/src/parser/neu_json_plugin.c @@ -24,7 +24,6 @@ #define KIND "kind" #define NODE_TYPE "node_type" -#define PLUGIN_NAME "plugin_type" #define PLUGIN_LIB_NAME "plugin_lib_name" #define PLUGIN_ID "plugin_id" #define PLUGIN_NAME "plugin_name" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 575a75e1..2db48e95 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -57,6 +57,13 @@ target_include_directories(json_nodes_test PRIVATE ) target_link_libraries(json_nodes_test neuron-base gtest_main gtest pthread jansson) +add_executable(json_plugin_test json_plugin_test.cc ${SRC_PARSER}) +target_include_directories(json_plugin_test PRIVATE + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/include +) +target_link_libraries(json_plugin_test neuron-base gtest_main gtest pthread jansson) + include(GoogleTest) gtest_discover_tests(json_test) gtest_discover_tests(api_json_test) @@ -66,3 +73,4 @@ gtest_discover_tests(json_group_config_test) gtest_discover_tests(datatag_table_test) gtest_discover_tests(json_datatag_table_test) gtest_discover_tests(json_nodes_test) +gtest_discover_tests(json_plugin_test) diff --git a/tests/json_nodes_test.cc b/tests/json_nodes_test.cc index 63fb78a4..68f21d89 100644 --- a/tests/json_nodes_test.cc +++ b/tests/json_nodes_test.cc @@ -121,6 +121,24 @@ TEST(JsonNodesTest, DeleteNodesDecode) neu_parse_decode_free(result); } +TEST(JsonNodesTest, DeleteNodesEncode) +{ + char *buf = (char *) "{\"function\": 37, " + "\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", " + "\"error\": 0}"; + char * result = NULL; + struct neu_parse_delete_nodes_res res = { + .function = NEU_PARSE_OP_DELETE_NODES, + .uuid = (char *) "554f5fd8-f437-11eb-975c-7704b9e17821", + .error = 0, + }; + + EXPECT_EQ(0, neu_parse_encode(&res, &result)); + EXPECT_STREQ(buf, result); + + free(result); +} + TEST(JsonNodesTest, UpdateNodesDecode) { char *buf = (char *) "{\"function\": 38, " diff --git a/tests/json_plugin_test.cc b/tests/json_plugin_test.cc index 83129550..1ad97980 100644 --- a/tests/json_plugin_test.cc +++ b/tests/json_plugin_test.cc @@ -2,4 +2,170 @@ #include -#include "parser/neu_json_parser.h" \ No newline at end of file +#include "parser/neu_json_parser.h" +#include "parser/neu_json_plugin.h" + +TEST(JsonPluginTest, AddPluginDecode) +{ + char *buf = (char *) "{\"function\": 39, " + "\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", " + "\"kind\": 1, " + "\"node_type\": 1, " + "\"plugin_name\": \"plugin1\", " + "\"plugin_lib_name\": \"lib1\" }"; + void * result = NULL; + struct neu_parse_add_plugin_req *req = NULL; + + EXPECT_EQ(0, neu_parse_decode(buf, &result)); + + req = (struct neu_parse_add_plugin_req *) result; + + EXPECT_EQ(NEU_PARSE_OP_ADD_PLUGIN, req->function); + EXPECT_STREQ("554f5fd8-f437-11eb-975c-7704b9e17821", req->uuid); + EXPECT_EQ(1, req->kind); + EXPECT_EQ(1, req->node_type); + EXPECT_STREQ("plugin1", req->plugin_name); + EXPECT_STREQ("lib1", req->plugin_lib_name); + + neu_parse_decode_free(result); +} + +TEST(JsonPluginTest, AddPluginEncode) +{ + char *buf = (char *) "{\"function\": 39, " + "\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", " + "\"error\": 0}"; + char * result = NULL; + struct neu_parse_add_plugin_res res = { + .function = NEU_PARSE_OP_ADD_PLUGIN, + .uuid = (char *) "554f5fd8-f437-11eb-975c-7704b9e17821", + .error = 0, + }; + + EXPECT_EQ(0, neu_parse_encode(&res, &result)); + EXPECT_STREQ(buf, result); + + free(result); +} + +TEST(JsonPluginTest, DeletePluginDecode) +{ + char *buf = (char *) "{\"function\": 41, " + "\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", " + "\"plugin_id\": 1 }"; + void * result = NULL; + struct neu_parse_delete_plugin_req *req = NULL; + + EXPECT_EQ(0, neu_parse_decode(buf, &result)); + + req = (struct neu_parse_delete_plugin_req *) result; + + EXPECT_EQ(NEU_PARSE_OP_DELETE_PLUGIN, req->function); + EXPECT_STREQ("554f5fd8-f437-11eb-975c-7704b9e17821", req->uuid); + EXPECT_EQ(1, req->plugin_id); + + neu_parse_decode_free(result); +} + +TEST(JsonPluginTest, DeletePluginEncode) +{ + char *buf = (char *) "{\"function\": 41, " + "\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", " + "\"error\": 0}"; + char * result = NULL; + struct neu_parse_delete_plugin_res res = { + .function = NEU_PARSE_OP_DELETE_PLUGIN, + .uuid = (char *) "554f5fd8-f437-11eb-975c-7704b9e17821", + .error = 0, + }; + + EXPECT_EQ(0, neu_parse_encode(&res, &result)); + EXPECT_STREQ(buf, result); + + free(result); +} + +TEST(JsonPluginTest, UpdatePluginDecode) +{ + char *buf = (char *) "{\"function\": 42, " + "\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", " + "\"kind\": 2, " + "\"node_type\": 2, " + "\"plugin_name\": \"plugin1\", " + "\"plugin_lib_name\": \"lib1\" }"; + void * result = NULL; + struct neu_parse_update_plugin_req *req = NULL; + + EXPECT_EQ(0, neu_parse_decode(buf, &result)); + + req = (struct neu_parse_update_plugin_req *) result; + + EXPECT_EQ(NEU_PARSE_OP_UPDATE_PLUGIN, req->function); + EXPECT_STREQ("554f5fd8-f437-11eb-975c-7704b9e17821", req->uuid); + EXPECT_EQ(2, req->kind); + EXPECT_EQ(2, req->node_type); + EXPECT_STREQ("plugin1", req->plugin_name); + EXPECT_STREQ("lib1", req->plugin_lib_name); + + neu_parse_decode_free(result); +} + +TEST(JsonPluginTest, UpdatePluginEncode) +{ + char *buf = (char *) "{\"function\": 42, " + "\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", " + "\"error\": 0}"; + char * result = NULL; + struct neu_parse_add_plugin_res res = { + .function = NEU_PARSE_OP_UPDATE_PLUGIN, + .uuid = (char *) "554f5fd8-f437-11eb-975c-7704b9e17821", + .error = 0, + }; + + EXPECT_EQ(0, neu_parse_encode(&res, &result)); + EXPECT_STREQ(buf, result); + + free(result); +} + +TEST(JsonPluginTest, GetPluginDecode) +{ + char *buf = (char *) "{\"function\": 40, " + "\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\" }"; + void * result = NULL; + struct neu_parse_get_plugin_req *req = NULL; + + EXPECT_EQ(0, neu_parse_decode(buf, &result)); + + req = (struct neu_parse_get_plugin_req *) result; + + EXPECT_EQ(NEU_PARSE_OP_GET_PLUGIN, req->function); + EXPECT_STREQ("554f5fd8-f437-11eb-975c-7704b9e17821", req->uuid); + + neu_parse_decode_free(result); +} + +TEST(JsonPluginTest, GetPluginEncode) +{ + char *buf = (char *) "{\"function\": 40, " + "\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", " + "\"plugin_id\": 123, " + "\"kind\": 1, " + "\"node_type\": 1, " + "\"plugin_name\": \"plugin1\", " + "\"plugin_lib_name\": \"lib1\"}"; + char * result = NULL; + struct neu_parse_get_plugin_res res; + res.function = NEU_PARSE_OP_GET_PLUGIN; + res.uuid = (char *) "554f5fd8-f437-11eb-975c-7704b9e17821"; + res.plugin_id = 123; + res.kind = PLUGIN_KIND_SYSTEM; + res.node_type = NEU_NODE_TYPE_DRIVER; + res.plugin_name = (char *) "plugin1"; + res.plugin_lib_name = (char *) "lib1"; + + EXPECT_EQ(0, neu_parse_encode(&res, &result)); + EXPECT_STREQ(buf, result); + + free(result); +} \ No newline at end of file