mirror of
https://github.com/emqx/neuron.git
synced 2026-10-18 13:41:22 +08:00
Add datatag table tag JSON analysis and test modifications
This commit is contained in:
@@ -24,8 +24,12 @@
|
||||
#include <nng/nng.h>
|
||||
#include <nng/supplemental/http/http.h>
|
||||
|
||||
#include "parser/neu_json_add_tag.h"
|
||||
#include "parser/neu_json_delete_tag.h"
|
||||
#include "parser/neu_json_get_tag.h"
|
||||
#include "parser/neu_json_login.h"
|
||||
#include "parser/neu_json_parser.h"
|
||||
#include "parser/neu_json_updata_tag.h"
|
||||
|
||||
#include "handle.h"
|
||||
|
||||
@@ -35,6 +39,9 @@ static void read(nng_aio *aio);
|
||||
static void write(nng_aio *aio);
|
||||
static void login(nng_aio *aio);
|
||||
static void logout(nng_aio *aio);
|
||||
static void get_tags(nng_aio *aio);
|
||||
static void add_tags(nng_aio *aio);
|
||||
static void delete_tags(nng_aio *aio);
|
||||
|
||||
struct neu_rest_handler rest_handlers[] = {
|
||||
{
|
||||
@@ -72,6 +79,25 @@ struct neu_rest_handler rest_handlers[] = {
|
||||
.type = NEU_REST_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/logout",
|
||||
.value.handler = logout,
|
||||
},
|
||||
{
|
||||
.method = NEU_REST_METHOD_POST,
|
||||
.type = NEU_REST_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/tags",
|
||||
.value.handler = add_tags,
|
||||
|
||||
},
|
||||
{
|
||||
.method = NEU_REST_METHOD_GET,
|
||||
.type = NEU_REST_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/tags",
|
||||
.value.handler = get_tags,
|
||||
},
|
||||
{
|
||||
.method = NEU_REST_METHOD_DELETE,
|
||||
.type = NEU_REST_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/tags",
|
||||
.value.handler = delete_tags,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -161,6 +187,156 @@ static void logout(nng_aio *aio)
|
||||
(void) aio;
|
||||
}
|
||||
|
||||
static void add_tags(nng_aio *aio)
|
||||
{
|
||||
int ret = -1;
|
||||
nng_http_res *res = NULL;
|
||||
char * res_data = NULL;
|
||||
char * req_data = NULL;
|
||||
char req_cdata[1024] = { 0 };
|
||||
size_t req_data_size = 0;
|
||||
|
||||
nng_http_req *req = nng_aio_get_input(aio, 0);
|
||||
|
||||
struct neu_parse_add_tags_req *add_tags_req = NULL;
|
||||
struct neu_parse_add_tags_res add_tags_res = {
|
||||
.function = NEU_PARSE_OP_ADD_TAGS,
|
||||
.error = 1,
|
||||
};
|
||||
|
||||
nng_http_req_get_data(req, (void **) &req_data, &req_data_size);
|
||||
if (req_data_size <= 0) {
|
||||
neu_parse_encode(&add_tags_res, &res_data);
|
||||
bad_request(aio, res_data);
|
||||
free(res_data);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(req_cdata, req_data, req_data_size);
|
||||
ret = neu_parse_decode(req_cdata, (void **) &add_tags_req);
|
||||
if (ret != 0) {
|
||||
neu_parse_encode(&add_tags_res, &res_data);
|
||||
bad_request(aio, res_data);
|
||||
free(res_data);
|
||||
return;
|
||||
}
|
||||
|
||||
add_tags_res.error = 0;
|
||||
add_tags_res.uuid = add_tags_req->uuid;
|
||||
|
||||
neu_parse_encode(&add_tags_res, &res_data);
|
||||
nng_http_res_alloc(&res);
|
||||
|
||||
nng_http_res_copy_data(res, res_data, strlen(res_data));
|
||||
nng_http_res_set_status(res, NNG_HTTP_STATUS_OK);
|
||||
nng_http_res_set_header(res, "Content-Type", "application/json");
|
||||
|
||||
nng_aio_set_output(aio, 0, res);
|
||||
nng_aio_finish(aio, 0);
|
||||
free(res_data);
|
||||
neu_parse_decode_free(add_tags_req);
|
||||
}
|
||||
|
||||
static void get_tags(nng_aio *aio)
|
||||
{
|
||||
int ret = -1;
|
||||
nng_http_res *res = NULL;
|
||||
char * res_data = NULL;
|
||||
char * req_data = NULL;
|
||||
char req_cdata[1024] = { 0 };
|
||||
size_t req_data_size = 0;
|
||||
|
||||
nng_http_req *req = nng_aio_get_input(aio, 0);
|
||||
|
||||
struct neu_parse_get_tags_req *get_tags_req = NULL;
|
||||
struct neu_parse_get_tags_res get_tags_res = {
|
||||
.function = NEU_PARSE_OP_GET_TAGS,
|
||||
.error = 1,
|
||||
};
|
||||
|
||||
nng_http_req_get_data(req, (void **) &req_data, &req_data_size);
|
||||
if (req_data_size <= 0) {
|
||||
neu_parse_encode(&get_tags_res, &res_data);
|
||||
bad_request(aio, res_data);
|
||||
free(res_data);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(req_cdata, req_data, req_data_size);
|
||||
ret = neu_parse_decode(req_cdata, (void **) &get_tags_req);
|
||||
if (ret != 0) {
|
||||
neu_parse_encode(&get_tags_res, &res_data);
|
||||
bad_request(aio, res_data);
|
||||
free(res_data);
|
||||
return;
|
||||
}
|
||||
|
||||
get_tags_res.error = 0;
|
||||
get_tags_res.uuid = get_tags_req->uuid;
|
||||
|
||||
neu_parse_encode(&get_tags_res, &res_data);
|
||||
nng_http_res_alloc(&res);
|
||||
|
||||
nng_http_res_copy_data(res, res_data, strlen(res_data));
|
||||
nng_http_res_set_status(res, NNG_HTTP_STATUS_OK);
|
||||
nng_http_res_set_header(res, "Content-Type", "application/json");
|
||||
|
||||
nng_aio_set_output(aio, 0, res);
|
||||
nng_aio_finish(aio, 0);
|
||||
free(res_data);
|
||||
neu_parse_decode_free(get_tags_req);
|
||||
}
|
||||
|
||||
static void delete_tags(nng_aio *aio)
|
||||
{
|
||||
int ret = -1;
|
||||
nng_http_res *res = NULL;
|
||||
char * res_data = NULL;
|
||||
char * req_data = NULL;
|
||||
char req_cdata[1024] = { 0 };
|
||||
size_t req_data_size = 0;
|
||||
|
||||
nng_http_req *req = nng_aio_get_input(aio, 0);
|
||||
|
||||
struct neu_parse_delete_tags_req *delete_tags_req = NULL;
|
||||
struct neu_parse_delete_tags_res delete_tags_res = {
|
||||
.function = NEU_PARSE_OP_DELETE_TAGS,
|
||||
.error = 1,
|
||||
};
|
||||
|
||||
nng_http_req_get_data(req, (void **) &req_data, &req_data_size);
|
||||
if (req_data_size <= 0) {
|
||||
neu_parse_encode(&delete_tags_res, &res_data);
|
||||
bad_request(aio, res_data);
|
||||
free(res_data);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(req_cdata, req_data, req_data_size);
|
||||
ret = neu_parse_decode(req_cdata, (void **) &delete_tags_res);
|
||||
if (ret != 0) {
|
||||
neu_parse_encode(&delete_tags_res, &res_data);
|
||||
bad_request(aio, res_data);
|
||||
free(res_data);
|
||||
return;
|
||||
}
|
||||
|
||||
delete_tags_res.error = 0;
|
||||
delete_tags_res.uuid = delete_tags_req->uuid;
|
||||
|
||||
neu_parse_encode(&delete_tags_res, &res_data);
|
||||
nng_http_res_alloc(&res);
|
||||
|
||||
nng_http_res_copy_data(res, res_data, strlen(res_data));
|
||||
nng_http_res_set_status(res, NNG_HTTP_STATUS_OK);
|
||||
nng_http_res_set_header(res, "Content-Type", "application/json");
|
||||
|
||||
nng_aio_set_output(aio, 0, res);
|
||||
nng_aio_finish(aio, 0);
|
||||
free(res_data);
|
||||
neu_parse_decode_free(delete_tags_req);
|
||||
}
|
||||
|
||||
static void bad_request(nng_aio *aio, char *error)
|
||||
{
|
||||
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "neu_json_add_tag.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#define NODE_ID "node_id"
|
||||
|
||||
#define TAGS "tags"
|
||||
#define NAME "name"
|
||||
#define TYPE "type"
|
||||
#define DECIMAL "decimal"
|
||||
#define ADDRESS "address"
|
||||
#define FLAG "flag"
|
||||
|
||||
int neu_parse_decode_add_tags_req(char * buf,
|
||||
struct neu_parse_add_tags_req **result)
|
||||
{
|
||||
struct neu_parse_add_tags_req *req =
|
||||
calloc(1, sizeof(struct neu_parse_add_tags_req));
|
||||
neu_json_elem_t elem[] = { {
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = NODE_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->function = NEU_PARSE_OP_ADD_TAGS;
|
||||
req->uuid = elem[0].v.val_str;
|
||||
req->node_id = elem[1].v.val_int;
|
||||
|
||||
req->n_tag = neu_json_decode_array_size(buf, TAGS);
|
||||
req->tags = calloc(req->n_tag, sizeof(struct neu_parse_add_tags_req_tag));
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
neu_json_elem_t celem[] = { {
|
||||
.name = NAME,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = TYPE,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = DECIMAL,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = ADDRESS,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = FLAG,
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
|
||||
neu_json_decode_array(buf, TAGS, i, NEU_JSON_ELEM_SIZE(celem), celem);
|
||||
req->tags[i].name = celem[0].v.val_str;
|
||||
req->tags[i].type = celem[1].v.val_int;
|
||||
req->tags[i].decimal = celem[2].v.val_int;
|
||||
req->tags[i].address = celem[3].v.val_str;
|
||||
req->tags[i].flag = celem[4].v.val_int;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_parse_encode_add_tags_res(struct neu_parse_add_tags_res *res,
|
||||
char ** buf)
|
||||
{
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = NEU_PARSE_FUNCTION,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = NEU_PARSE_OP_ADD_TAGS,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->uuid,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_ERROR,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->error,
|
||||
} };
|
||||
|
||||
return neu_json_encode(elems, 3, buf);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
#ifndef _NEU_JSON_API_ADD_TAG_H_
|
||||
#define _NEU_JSON_API_ADD_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "neu_json_parser.h"
|
||||
|
||||
struct neu_parse_add_tags_req_tag {
|
||||
char *name;
|
||||
int type;
|
||||
int decimal;
|
||||
char *address;
|
||||
int flag;
|
||||
};
|
||||
|
||||
struct neu_parse_add_tags_req {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
uint32_t node_id;
|
||||
int n_tag;
|
||||
struct neu_parse_add_tags_req_tag *tags;
|
||||
};
|
||||
|
||||
struct neu_parse_add_tags_res {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
int error;
|
||||
};
|
||||
|
||||
int neu_parse_decode_add_tags_req(char * buf,
|
||||
struct neu_parse_add_tags_req **req);
|
||||
int neu_parse_encode_add_tags_res(struct neu_parse_add_tags_res *res,
|
||||
char ** buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "neu_json_delete_tag.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#define NODE_ID "node_id"
|
||||
#define TAG_ID "tag_id"
|
||||
|
||||
int neu_parse_decode_delete_tags_req(char * buf,
|
||||
struct neu_parse_delete_tags_req **result)
|
||||
{
|
||||
struct neu_parse_delete_tags_req *req =
|
||||
calloc(1, sizeof(struct neu_parse_delete_tags_req));
|
||||
neu_json_elem_t elem[] = { {
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = NODE_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = TAG_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->function = NEU_PARSE_OP_DELETE_TAGS;
|
||||
req->uuid = elem[0].v.val_str;
|
||||
req->node_id = elem[1].v.val_int;
|
||||
req->tag_id = elem[2].v.val_int;
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_parse_encode_delete_tags_res(struct neu_parse_delete_tags_res *res,
|
||||
char ** buf)
|
||||
{
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = NEU_PARSE_FUNCTION,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = NEU_PARSE_OP_DELETE_TAGS,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->uuid,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_ERROR,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->error,
|
||||
} };
|
||||
|
||||
return neu_json_encode(elems, 3, buf);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
#ifndef _NEU_JSON_API_DELETE_TAG_H_
|
||||
#define _NEU_JSON_API_DELETE_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "neu_json_parser.h"
|
||||
|
||||
struct neu_parse_delete_tags_req {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
uint32_t node_id;
|
||||
uint32_t tag_id;
|
||||
};
|
||||
|
||||
struct neu_parse_delete_tags_res {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
int error;
|
||||
};
|
||||
|
||||
int neu_parse_decode_delete_tags_req(char * buf,
|
||||
struct neu_parse_delete_tags_req **req);
|
||||
int neu_parse_encode_delete_tags_res(struct neu_parse_delete_tags_res *res,
|
||||
char ** buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "neu_json_get_tag.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#define NODE_ID "node_id"
|
||||
|
||||
#define TAGS "tags"
|
||||
#define NAME "name"
|
||||
#define TYPE "type"
|
||||
#define DECIMAL "decimal"
|
||||
#define ADDRESS "address"
|
||||
#define FLAG "flag"
|
||||
|
||||
int neu_parse_decode_get_tags_req(char * buf,
|
||||
struct neu_parse_get_tags_req **result)
|
||||
{
|
||||
struct neu_parse_get_tags_req *req =
|
||||
calloc(1, sizeof(struct neu_parse_get_tags_req));
|
||||
neu_json_elem_t elem[] = {
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
|
||||
},
|
||||
{
|
||||
.name = NODE_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
}
|
||||
// {
|
||||
// .name = GROUP,
|
||||
// .t = NEU_JSON_STR,
|
||||
// },
|
||||
// {
|
||||
// .name = CONFIG,
|
||||
// .t = NEU_JSON_STR,
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->function = NEU_PARSE_OP_GET_TAGS;
|
||||
req->uuid = elem[0].v.val_str;
|
||||
req->node_id = elem[1].v.val_int;
|
||||
// req->group = elem[1].v.val_str;
|
||||
// req->config = elem[2].v.val_str;
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_parse_encode_get_tags_res(struct neu_parse_get_tags_res *res,
|
||||
char ** buf)
|
||||
{
|
||||
void *array = NULL;
|
||||
for (int i = 0; i < res->n_tag; i++) {
|
||||
neu_json_elem_t tag[] = { {
|
||||
.name = NAME,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->tags[i].name,
|
||||
},
|
||||
{
|
||||
.name = TYPE,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->tags[i].type,
|
||||
},
|
||||
{
|
||||
.name = DECIMAL,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->tags[i].decimal,
|
||||
},
|
||||
{ .name = ADDRESS,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->tags[i].address },
|
||||
{
|
||||
.name = FLAG,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->tags[i].flag,
|
||||
} };
|
||||
array = neu_json_encode_array(array, tag, 5);
|
||||
}
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = NEU_PARSE_FUNCTION,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = NEU_PARSE_OP_GET_TAGS,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->uuid,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_ERROR,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->error,
|
||||
},
|
||||
{
|
||||
.name = TAGS,
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.object = array,
|
||||
} };
|
||||
return neu_json_encode(elems, 4, buf);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
#ifndef _NEU_JSON_API_GTETAGLIST_H_
|
||||
#define _NEU_JSON_API_GTETAGLIST_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "neu_json_parser.h"
|
||||
|
||||
struct neu_parse_get_tags_res_tag {
|
||||
char *name;
|
||||
int type;
|
||||
int decimal;
|
||||
char *address;
|
||||
int flag;
|
||||
};
|
||||
|
||||
struct neu_parse_get_tags_req {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
uint32_t node_id;
|
||||
// char * config;
|
||||
// char * group;
|
||||
};
|
||||
|
||||
struct neu_parse_get_tags_res {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
int error;
|
||||
int n_tag;
|
||||
struct neu_parse_get_tags_res_tag *tags;
|
||||
};
|
||||
|
||||
int neu_parse_decode_get_tags_req(char * buf,
|
||||
struct neu_parse_get_tags_req **req);
|
||||
int neu_parse_encode_get_tags_res(struct neu_parse_get_tags_res *res,
|
||||
char ** buf);
|
||||
|
||||
#endif
|
||||
@@ -23,9 +23,13 @@
|
||||
#include "neu_log.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#include "neu_json_add_tag.h"
|
||||
#include "neu_json_delete_tag.h"
|
||||
#include "neu_json_get_tag.h"
|
||||
#include "neu_json_login.h"
|
||||
#include "neu_json_parser.h"
|
||||
#include "neu_json_read.h"
|
||||
#include "neu_json_updata_tag.h"
|
||||
#include "neu_json_write.h"
|
||||
|
||||
int neu_parse_decode(char *buf, void **result)
|
||||
@@ -54,6 +58,22 @@ int neu_parse_decode(char *buf, void **result)
|
||||
break;
|
||||
case NEU_PARSE_OP_LOGOUT:
|
||||
break;
|
||||
case NEU_PARSE_OP_ADD_TAGS:
|
||||
ret = neu_parse_decode_add_tags_req(
|
||||
buf, (struct neu_parse_add_tags_req **) result);
|
||||
break;
|
||||
case NEU_PARSE_OP_GET_TAGS:
|
||||
ret = neu_parse_decode_get_tags_req(
|
||||
buf, (struct neu_parse_get_tags_req **) result);
|
||||
break;
|
||||
case NEU_PARSE_OP_DELETE_TAGS:
|
||||
ret = neu_parse_decode_delete_tags_req(
|
||||
buf, (struct neu_parse_delete_tags_req **) result);
|
||||
break;
|
||||
case NEU_PARSE_OP_UPDATA_TAGS:
|
||||
ret = neu_parse_decode_updata_tags_req(
|
||||
buf, (struct neu_parse_updata_tags_req **) result);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -75,6 +95,22 @@ int neu_parse_encode(void *result, char **buf)
|
||||
break;
|
||||
case NEU_PARSE_OP_LOGOUT:
|
||||
break;
|
||||
case NEU_PARSE_OP_ADD_TAGS:
|
||||
neu_parse_encode_add_tags_res((struct neu_parse_add_tags_res *) result,
|
||||
buf);
|
||||
break;
|
||||
case NEU_PARSE_OP_GET_TAGS:
|
||||
neu_parse_encode_get_tags_res((struct neu_parse_get_tags_res *) result,
|
||||
buf);
|
||||
break;
|
||||
case NEU_PARSE_OP_DELETE_TAGS:
|
||||
neu_parse_encode_delete_tags_res(
|
||||
(struct neu_parse_delete_tags_res *) result, buf);
|
||||
break;
|
||||
case NEU_PARSE_OP_UPDATA_TAGS:
|
||||
neu_parse_encode_updata_tags_res(
|
||||
(struct neu_parse_updata_tags_res *) result, buf);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -123,6 +159,40 @@ void neu_parse_decode_free(void *result)
|
||||
case NEU_PARSE_OP_LOGOUT: {
|
||||
break;
|
||||
}
|
||||
case NEU_PARSE_OP_ADD_TAGS: {
|
||||
struct neu_parse_add_tags_req *req = result;
|
||||
|
||||
free(req->uuid);
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
free(req->tags[i].name);
|
||||
free(req->tags[i].address);
|
||||
}
|
||||
free(req->tags);
|
||||
break;
|
||||
}
|
||||
case NEU_PARSE_OP_GET_TAGS: {
|
||||
struct neu_parse_get_tags_req *req = result;
|
||||
|
||||
free(req->uuid);
|
||||
break;
|
||||
}
|
||||
case NEU_PARSE_OP_DELETE_TAGS: {
|
||||
struct neu_parse_delete_tags_req *req = result;
|
||||
|
||||
free(req->uuid);
|
||||
break;
|
||||
}
|
||||
case NEU_PARSE_OP_UPDATA_TAGS: {
|
||||
struct neu_parse_updata_tags_req *req = result;
|
||||
|
||||
free(req->uuid);
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
free(req->tags[i].name);
|
||||
free(req->tags[i].address);
|
||||
}
|
||||
free(req->tags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(result);
|
||||
|
||||
@@ -31,10 +31,14 @@ extern "C" {
|
||||
#define NEU_PARSE_ERROR "error"
|
||||
|
||||
enum neu_parse_function {
|
||||
NEU_PARSE_OP_READ = 50,
|
||||
NEU_PARSE_OP_WRITE = 51,
|
||||
NEU_PARSE_OP_LOGIN = 10,
|
||||
NEU_PARSE_OP_LOGOUT = 11
|
||||
NEU_PARSE_OP_READ = 50,
|
||||
NEU_PARSE_OP_WRITE = 51,
|
||||
NEU_PARSE_OP_LOGIN = 10,
|
||||
NEU_PARSE_OP_LOGOUT = 11,
|
||||
NEU_PARSE_OP_ADD_TAGS = 31,
|
||||
NEU_PARSE_OP_GET_TAGS = 32,
|
||||
NEU_PARSE_OP_DELETE_TAGS = 33,
|
||||
NEU_PARSE_OP_UPDATA_TAGS = 34
|
||||
};
|
||||
|
||||
int neu_parse_decode(char *buf, void **result);
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "neu_json_updata_tag.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#define NODE_ID "node_id"
|
||||
#define TAG_ID "tag_id"
|
||||
|
||||
#define TAGS "tags"
|
||||
#define NAME "name"
|
||||
#define TYPE "type"
|
||||
#define DECIMAL "decimal"
|
||||
#define ADDRESS "address"
|
||||
#define FLAG "flag"
|
||||
|
||||
int neu_parse_decode_updata_tags_req(char * buf,
|
||||
struct neu_parse_updata_tags_req **result)
|
||||
{
|
||||
struct neu_parse_updata_tags_req *req =
|
||||
calloc(1, sizeof(struct neu_parse_updata_tags_req));
|
||||
neu_json_elem_t elem[] = { {
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = NODE_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = TAG_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
}
|
||||
|
||||
};
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->function = NEU_PARSE_OP_UPDATA_TAGS;
|
||||
req->uuid = elem[0].v.val_str;
|
||||
req->node_id = elem[1].v.val_int;
|
||||
req->tag_id = elem[2].v.val_int;
|
||||
|
||||
req->n_tag = neu_json_decode_array_size(buf, TAGS);
|
||||
req->tags =
|
||||
calloc(req->n_tag, sizeof(struct neu_parse_updata_tags_req_tag));
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
neu_json_elem_t celem[] = { {
|
||||
.name = NAME,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = TYPE,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = DECIMAL,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = ADDRESS,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = FLAG,
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
|
||||
neu_json_decode_array(buf, TAGS, i, NEU_JSON_ELEM_SIZE(celem), celem);
|
||||
|
||||
req->tags[i].name = celem[0].v.val_str;
|
||||
req->tags[i].type = celem[1].v.val_int;
|
||||
req->tags[i].decimal = celem[2].v.val_int;
|
||||
req->tags[i].address = celem[3].v.val_str;
|
||||
req->tags[i].flag = celem[4].v.val_int;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_parse_encode_updata_tags_res(struct neu_parse_updata_tags_res *res,
|
||||
char ** buf)
|
||||
{
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = NEU_PARSE_FUNCTION,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = NEU_PARSE_OP_UPDATA_TAGS,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->uuid,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_ERROR,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->error,
|
||||
} };
|
||||
|
||||
return neu_json_encode(elems, 3, buf);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
#ifndef _NEU_JSON_API_UPDATA_TAG_H_
|
||||
#define _NEU_JSON_API_UPDATA_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "neu_json_parser.h"
|
||||
|
||||
struct neu_parse_updata_tags_req_tag {
|
||||
char *name;
|
||||
int type;
|
||||
int decimal;
|
||||
char *address;
|
||||
int flag;
|
||||
};
|
||||
|
||||
struct neu_parse_updata_tags_req {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
uint32_t node_id;
|
||||
uint32_t tag_id;
|
||||
int n_tag;
|
||||
struct neu_parse_updata_tags_req_tag *tags;
|
||||
};
|
||||
|
||||
struct neu_parse_updata_tags_res {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
int error;
|
||||
};
|
||||
|
||||
int neu_parse_decode_updata_tags_req(char * buf,
|
||||
struct neu_parse_updata_tags_req **req);
|
||||
int neu_parse_encode_updata_tags_res(struct neu_parse_updata_tags_res *res,
|
||||
char ** buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -29,17 +29,24 @@ target_include_directories(modbus_point_test PRIVATE
|
||||
)
|
||||
target_link_libraries(modbus_point_test neuron-base gtest_main gtest pthread)
|
||||
|
||||
add_executable(datatag_table_test datatag_table_test.cc ${CMAKE_SOURCE_DIR}/src/core/neu_datatag_table.c)
|
||||
add_executable(datatag_table_test datatag_table_test.cc ${CMAKE_SOURCE_DIR}/src/base/neu_datatag_table.c)
|
||||
target_include_directories(datatag_table_test PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
)
|
||||
target_link_libraries(datatag_table_test nng neuron-base gtest_main gtest pthread jansson)
|
||||
|
||||
add_executable(json_datatag_table_test json_datatag_table_test.cc ${SRC_PARSER})
|
||||
target_include_directories(json_datatag_table_test PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
)
|
||||
target_link_libraries(json_datatag_table_test neuron-base gtest_main gtest pthread jansson)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(json_test)
|
||||
gtest_discover_tests(api_json_test)
|
||||
gtest_discover_tests(variable_test)
|
||||
gtest_discover_tests(modbus_point_test)
|
||||
gtest_discover_tests(datatag_table_test)
|
||||
|
||||
gtest_discover_tests(json_datatag_table_test)
|
||||
|
||||
+149
-117
@@ -1,167 +1,200 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "neu_datatag_table.h"
|
||||
#include "neu_types.h"
|
||||
#include "pthread.h"
|
||||
#include <bits/pthreadtypes.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define NUM_DatatagTable_Modify 100
|
||||
#define NUM_DATATAGTABLE_MODIFY 100
|
||||
|
||||
TEST(DatatageTableTest,DatatagTableAdd)
|
||||
TEST(DatatageTableTest, DatatagTableAdd)
|
||||
{
|
||||
neu_datatag_table_t *datatag_table = neu_datatag_tbl_create();
|
||||
neu_address_t address_t;
|
||||
neu_datatag_t datatag_t_1 = {123,NEU_ATTRIBUTETYPE_READ,NEU_DATATYPE_BYTE,address_t};
|
||||
neu_datatag_t datatag_t_2 = {456,NEU_ATTRIBUTETYPE_WRITE,NEU_DATATYPE_WORD,address_t};
|
||||
neu_datatag_t datatag_t_3 = {789,NEU_ATTRIBUTETYPE_SUBSCRIBE,NEU_DATATYPE_UWORD,address_t};
|
||||
|
||||
datatag_id_t datatag_add_1,datatag_add_2,datatag_add_3;
|
||||
neu_datatag_t *datatag_get_1 = NULL;
|
||||
neu_datatag_t *datatag_get_2 = NULL;
|
||||
neu_datatag_t *datatag_get_3 = NULL;
|
||||
|
||||
datatag_add_1 = neu_datatag_tbl_add(datatag_table, &datatag_t_1);
|
||||
datatag_add_2 = neu_datatag_tbl_add(datatag_table, &datatag_t_2);
|
||||
datatag_add_3 = neu_datatag_tbl_add(datatag_table, &datatag_t_3);
|
||||
neu_datatag_table_t *datatag_table_create = neu_datatag_tbl_create();
|
||||
neu_datatag_id_t id;
|
||||
neu_address_t datatag_address;
|
||||
char * str_addr;
|
||||
neu_datatag_t datatag1 = { id, NEU_ATTRIBUTETYPE_READ, NEU_DATATYPE_BYTE,
|
||||
datatag_address, str_addr };
|
||||
neu_datatag_t datatag2 = { id, NEU_ATTRIBUTETYPE_WRITE, NEU_DATATYPE_WORD,
|
||||
datatag_address, str_addr };
|
||||
neu_datatag_t datatag3 = { id, NEU_ATTRIBUTETYPE_SUBSCRIBE,
|
||||
NEU_DATATYPE_UWORD, datatag_address, str_addr };
|
||||
|
||||
datatag_get_1 = neu_datatag_tbl_get(datatag_table, datatag_add_1);
|
||||
datatag_get_2 = neu_datatag_tbl_get(datatag_table, datatag_add_2);
|
||||
datatag_get_3 = neu_datatag_tbl_get(datatag_table, datatag_add_3);
|
||||
datatag_id_t datatag_id1, datatag_id2, datatag_id3;
|
||||
neu_datatag_t *datatag_id_return1 = NULL;
|
||||
neu_datatag_t *datatag_id_return2 = NULL;
|
||||
neu_datatag_t *datatag_id_return3 = NULL;
|
||||
|
||||
EXPECT_EQ(datatag_get_1->id,datatag_t_1.id);
|
||||
EXPECT_EQ(datatag_get_1->dataType,datatag_t_1.dataType);
|
||||
EXPECT_EQ(datatag_get_1->type,datatag_t_1.type);
|
||||
datatag_id1 = neu_datatag_tbl_add(datatag_table_create, &datatag1);
|
||||
datatag_id2 = neu_datatag_tbl_add(datatag_table_create, &datatag2);
|
||||
datatag_id3 = neu_datatag_tbl_add(datatag_table_create, &datatag3);
|
||||
|
||||
EXPECT_EQ(datatag_get_2->id,datatag_t_2.id);
|
||||
EXPECT_EQ(datatag_get_2->dataType,datatag_t_2.dataType);
|
||||
EXPECT_EQ(datatag_get_2->type,datatag_t_2.type);
|
||||
datatag_id_return1 = neu_datatag_tbl_get(datatag_table_create, datatag_id1);
|
||||
datatag_id_return2 = neu_datatag_tbl_get(datatag_table_create, datatag_id2);
|
||||
datatag_id_return3 = neu_datatag_tbl_get(datatag_table_create, datatag_id3);
|
||||
|
||||
EXPECT_EQ(datatag_get_3->id,datatag_t_3.id);
|
||||
EXPECT_EQ(datatag_get_3->dataType,datatag_t_3.dataType);
|
||||
EXPECT_EQ(datatag_get_3->type,datatag_t_3.type);
|
||||
EXPECT_EQ(datatag_id_return1->id, datatag1.id);
|
||||
EXPECT_EQ(datatag_id_return1->dataType, datatag1.dataType);
|
||||
EXPECT_EQ(datatag_id_return1->type, datatag1.type);
|
||||
EXPECT_EQ(datatag_id_return1->str_addr, datatag1.str_addr);
|
||||
|
||||
neu_datatag_tbl_destroy(datatag_table);
|
||||
EXPECT_EQ(datatag_id_return2->id, datatag2.id);
|
||||
EXPECT_EQ(datatag_id_return2->dataType, datatag2.dataType);
|
||||
EXPECT_EQ(datatag_id_return2->type, datatag2.type);
|
||||
EXPECT_EQ(datatag_id_return2->str_addr, datatag2.str_addr);
|
||||
|
||||
EXPECT_EQ(datatag_id_return3->id, datatag3.id);
|
||||
EXPECT_EQ(datatag_id_return3->dataType, datatag3.dataType);
|
||||
EXPECT_EQ(datatag_id_return3->type, datatag3.type);
|
||||
EXPECT_EQ(datatag_id_return3->str_addr, datatag3.str_addr);
|
||||
|
||||
neu_datatag_tbl_destroy(datatag_table_create);
|
||||
}
|
||||
|
||||
TEST(DatatageTableTest,DatatagTableRemove)
|
||||
TEST(DatatageTableTest, DatatagTableRemove)
|
||||
{
|
||||
neu_datatag_table_t *datatag_table = neu_datatag_tbl_create();
|
||||
neu_address_t address_t;
|
||||
neu_datatag_t datatag_t_1 = {123,NEU_ATTRIBUTETYPE_READ,NEU_DATATYPE_BYTE,address_t};
|
||||
neu_datatag_t datatag_t_2 = {456,NEU_ATTRIBUTETYPE_WRITE,NEU_DATATYPE_WORD,address_t};
|
||||
neu_datatag_t datatag_t_3 = {789,NEU_ATTRIBUTETYPE_SUBSCRIBE,NEU_DATATYPE_UWORD,address_t};
|
||||
neu_datatag_table_t *datatag_table_create = neu_datatag_tbl_create();
|
||||
neu_address_t datatag_address;
|
||||
neu_datatag_id_t id;
|
||||
char * str_addr;
|
||||
neu_datatag_t datatag1 = { id, NEU_ATTRIBUTETYPE_READ, NEU_DATATYPE_BYTE,
|
||||
datatag_address, str_addr };
|
||||
neu_datatag_t datatag2 = { id, NEU_ATTRIBUTETYPE_WRITE, NEU_DATATYPE_WORD,
|
||||
datatag_address, str_addr };
|
||||
neu_datatag_t datatag3 = { id, NEU_ATTRIBUTETYPE_SUBSCRIBE,
|
||||
NEU_DATATYPE_UWORD, datatag_address, str_addr };
|
||||
|
||||
datatag_id_t datatag_add_1,datatag_add_2,datatag_add_3;
|
||||
neu_datatag_t *datatag_get_1 = NULL;
|
||||
neu_datatag_t *datatag_get_2 = NULL;
|
||||
neu_datatag_t *datatag_get_3 = NULL;
|
||||
datatag_id_t datatag_id1, datatag_id2, datatag_id3;
|
||||
neu_datatag_t *datatag_id_return1 = NULL;
|
||||
neu_datatag_t *datatag_id_return2 = NULL;
|
||||
neu_datatag_t *datatag_id_return3 = NULL;
|
||||
|
||||
datatag_add_1 = neu_datatag_tbl_add(datatag_table, &datatag_t_1);
|
||||
datatag_add_2 = neu_datatag_tbl_add(datatag_table, &datatag_t_2);
|
||||
datatag_add_3 = neu_datatag_tbl_add(datatag_table, &datatag_t_3);
|
||||
datatag_id1 = neu_datatag_tbl_add(datatag_table_create, &datatag1);
|
||||
datatag_id2 = neu_datatag_tbl_add(datatag_table_create, &datatag2);
|
||||
datatag_id3 = neu_datatag_tbl_add(datatag_table_create, &datatag3);
|
||||
|
||||
EXPECT_EQ(0,neu_datatag_tbl_remove(datatag_table, datatag_add_1));
|
||||
EXPECT_EQ(0, neu_datatag_tbl_remove(datatag_table_create, datatag_id1));
|
||||
|
||||
datatag_get_1 = neu_datatag_tbl_get(datatag_table, datatag_add_1);
|
||||
datatag_get_2 = neu_datatag_tbl_get(datatag_table, datatag_add_2);
|
||||
datatag_get_3 = neu_datatag_tbl_get(datatag_table, datatag_add_3);
|
||||
datatag_id_return1 = neu_datatag_tbl_get(datatag_table_create, datatag_id1);
|
||||
datatag_id_return2 = neu_datatag_tbl_get(datatag_table_create, datatag_id2);
|
||||
datatag_id_return3 = neu_datatag_tbl_get(datatag_table_create, datatag_id3);
|
||||
|
||||
EXPECT_EQ(NULL,datatag_get_1);
|
||||
|
||||
EXPECT_EQ(datatag_get_2->id,datatag_t_2.id);
|
||||
EXPECT_EQ(datatag_get_2->dataType,datatag_t_2.dataType);
|
||||
EXPECT_EQ(datatag_get_2->type,datatag_t_2.type);
|
||||
EXPECT_EQ(NULL, datatag_id_return1);
|
||||
|
||||
EXPECT_EQ(datatag_get_3->id,datatag_t_3.id);
|
||||
EXPECT_EQ(datatag_get_3->dataType,datatag_t_3.dataType);
|
||||
EXPECT_EQ(datatag_get_3->type,datatag_t_3.type);
|
||||
EXPECT_EQ(datatag_id_return2->id, datatag2.id);
|
||||
EXPECT_EQ(datatag_id_return2->dataType, datatag2.dataType);
|
||||
EXPECT_EQ(datatag_id_return2->type, datatag2.type);
|
||||
EXPECT_EQ(datatag_id_return2->str_addr, datatag2.str_addr);
|
||||
|
||||
neu_datatag_tbl_destroy(datatag_table);
|
||||
EXPECT_EQ(datatag_id_return3->id, datatag3.id);
|
||||
EXPECT_EQ(datatag_id_return3->dataType, datatag3.dataType);
|
||||
EXPECT_EQ(datatag_id_return3->type, datatag3.type);
|
||||
EXPECT_EQ(datatag_id_return3->str_addr, datatag3.str_addr);
|
||||
|
||||
neu_datatag_tbl_destroy(datatag_table_create);
|
||||
}
|
||||
|
||||
TEST(DatatageTableTest,DatatagTableUpdate)
|
||||
TEST(DatatageTableTest, DatatagTableUpdate)
|
||||
{
|
||||
neu_datatag_table_t *datatag_table = neu_datatag_tbl_create();
|
||||
neu_address_t address_t;
|
||||
neu_datatag_t datatag_t = {123,NEU_ATTRIBUTETYPE_READ,NEU_DATATYPE_BYTE,address_t};
|
||||
neu_datatag_table_t *datatag_table_create = neu_datatag_tbl_create();
|
||||
neu_address_t datatag_address;
|
||||
neu_datatag_id_t id;
|
||||
char * str_addr;
|
||||
neu_datatag_t datatag = { id, NEU_ATTRIBUTETYPE_READ, NEU_DATATYPE_BYTE,
|
||||
datatag_address, str_addr };
|
||||
|
||||
datatag_id_t datatag_add;
|
||||
neu_datatag_t *datatag_get = NULL;
|
||||
datatag_id_t datatag_id;
|
||||
neu_datatag_t *datatag_id_return = NULL;
|
||||
|
||||
datatag_add = neu_datatag_tbl_add(datatag_table, &datatag_t);
|
||||
datatag_t.id = 456;
|
||||
EXPECT_EQ(0,neu_datatag_tbl_update(datatag_table,datatag_add,&datatag_t));
|
||||
datatag_get = neu_datatag_tbl_get(datatag_table, datatag_add);
|
||||
datatag_id = neu_datatag_tbl_add(datatag_table_create, &datatag);
|
||||
|
||||
EXPECT_EQ(456,datatag_get->id);
|
||||
datatag.type = NEU_ATTRIBUTETYPE_WRITE;
|
||||
datatag.dataType = NEU_DATATYPE_BOOLEAN;
|
||||
EXPECT_EQ(
|
||||
0, neu_datatag_tbl_update(datatag_table_create, datatag_id, &datatag));
|
||||
|
||||
neu_datatag_tbl_destroy(datatag_table);
|
||||
datatag_id_return = neu_datatag_tbl_get(datatag_table_create, datatag_id);
|
||||
|
||||
EXPECT_EQ(datatag_id_return->type, NEU_ATTRIBUTETYPE_WRITE);
|
||||
EXPECT_EQ(datatag_id_return->dataType, NEU_DATATYPE_BOOLEAN);
|
||||
EXPECT_EQ(datatag_id_return->id, datatag.id);
|
||||
EXPECT_EQ(datatag_id_return->str_addr, datatag.str_addr);
|
||||
|
||||
neu_datatag_tbl_destroy(datatag_table_create);
|
||||
}
|
||||
|
||||
void * datatag_table_thread(void * arg)
|
||||
void *datatag_table_thread(void *arg)
|
||||
{
|
||||
neu_datatag_table_t *datatag_table = (neu_datatag_table_t *)arg;
|
||||
neu_address_t address_t;
|
||||
neu_datatag_t datatag_t_1 = {123,NEU_ATTRIBUTETYPE_READ,NEU_DATATYPE_BYTE,address_t};
|
||||
neu_datatag_t datatag_t_2 = {456,NEU_ATTRIBUTETYPE_WRITE,NEU_DATATYPE_WORD,address_t};
|
||||
neu_datatag_t datatag_t_3 = {789,NEU_ATTRIBUTETYPE_SUBSCRIBE,NEU_DATATYPE_UWORD,address_t};
|
||||
|
||||
datatag_id_t datatag_add_1,datatag_add_2,datatag_add_3,datatag_add_4;
|
||||
neu_datatag_t *datatag_get_1 = NULL;
|
||||
neu_datatag_t *datatag_get_2 = NULL;
|
||||
neu_datatag_t *datatag_get_3 = NULL;
|
||||
neu_datatag_table_t *datatag_table_create = (neu_datatag_table_t *) arg;
|
||||
neu_address_t address;
|
||||
datatag_id_t id;
|
||||
char * str_addr;
|
||||
neu_datatag_t datatag1 = { id, NEU_ATTRIBUTETYPE_READ, NEU_DATATYPE_BYTE,
|
||||
address, str_addr };
|
||||
neu_datatag_t datatag2 = { id, NEU_ATTRIBUTETYPE_WRITE, NEU_DATATYPE_WORD,
|
||||
address, str_addr };
|
||||
neu_datatag_t datatag3 = { id, NEU_ATTRIBUTETYPE_SUBSCRIBE,
|
||||
NEU_DATATYPE_UWORD, address, str_addr };
|
||||
|
||||
for(int i = 0; i < NUM_DatatagTable_Modify; ++i )
|
||||
{
|
||||
datatag_add_1 = neu_datatag_tbl_add(datatag_table, &datatag_t_1);
|
||||
datatag_add_2 = neu_datatag_tbl_add(datatag_table, &datatag_t_2);
|
||||
datatag_add_3 = neu_datatag_tbl_add(datatag_table, &datatag_t_3);
|
||||
datatag_id_t datatag_id1, datatag_id2, datatag_id3;
|
||||
neu_datatag_t *datatag_id_return1 = NULL;
|
||||
neu_datatag_t *datatag_id_return2 = NULL;
|
||||
neu_datatag_t *datatag_id_return3 = NULL;
|
||||
|
||||
EXPECT_EQ(0,neu_datatag_tbl_remove(datatag_table, datatag_add_1));
|
||||
for (int i = 0; i < NUM_DATATAGTABLE_MODIFY; ++i) {
|
||||
datatag_id1 = neu_datatag_tbl_add(datatag_table_create, &datatag1);
|
||||
datatag_id2 = neu_datatag_tbl_add(datatag_table_create, &datatag2);
|
||||
datatag_id3 = neu_datatag_tbl_add(datatag_table_create, &datatag3);
|
||||
|
||||
datatag_get_1 = neu_datatag_tbl_get(datatag_table, datatag_add_1);
|
||||
datatag_get_2 = neu_datatag_tbl_get(datatag_table, datatag_add_2);
|
||||
datatag_get_3 = neu_datatag_tbl_get(datatag_table, datatag_add_3);
|
||||
|
||||
datatag_t_2.id = 123;
|
||||
datatag_t_3.type = NEU_ATTRIBUTETYPE_WRITE;
|
||||
EXPECT_EQ(0,neu_datatag_tbl_update(datatag_table,datatag_add_2,&datatag_t_2));
|
||||
EXPECT_EQ(0,neu_datatag_tbl_update(datatag_table,datatag_add_3,&datatag_t_3));
|
||||
EXPECT_EQ(0, neu_datatag_tbl_remove(datatag_table_create, datatag_id1));
|
||||
|
||||
datatag_get_1 = neu_datatag_tbl_get(datatag_table, datatag_add_1);
|
||||
datatag_get_2 = neu_datatag_tbl_get(datatag_table, datatag_add_2);
|
||||
datatag_get_3 = neu_datatag_tbl_get(datatag_table, datatag_add_3);
|
||||
datatag2.type = NEU_ATTRIBUTETYPE_WRITE;
|
||||
datatag3.dataType = NEU_DATATYPE_BOOLEAN;
|
||||
EXPECT_EQ(0,
|
||||
neu_datatag_tbl_update(datatag_table_create, datatag_id2,
|
||||
&datatag2));
|
||||
EXPECT_EQ(0,
|
||||
neu_datatag_tbl_update(datatag_table_create, datatag_id3,
|
||||
&datatag3));
|
||||
|
||||
EXPECT_EQ(NULL,datatag_get_1);
|
||||
datatag_id_return1 =
|
||||
neu_datatag_tbl_get(datatag_table_create, datatag_id1);
|
||||
datatag_id_return2 =
|
||||
neu_datatag_tbl_get(datatag_table_create, datatag_id2);
|
||||
datatag_id_return3 =
|
||||
neu_datatag_tbl_get(datatag_table_create, datatag_id3);
|
||||
|
||||
EXPECT_EQ(datatag_get_2->id,123);
|
||||
EXPECT_EQ(datatag_get_2->dataType,datatag_t_2.dataType);
|
||||
EXPECT_EQ(datatag_get_2->type,datatag_t_2.type);
|
||||
EXPECT_EQ(NULL, datatag_id_return1);
|
||||
|
||||
EXPECT_EQ(datatag_get_3->id,datatag_t_3.id);
|
||||
EXPECT_EQ(datatag_get_3->dataType,datatag_t_3.dataType);
|
||||
EXPECT_EQ(datatag_get_3->type,NEU_ATTRIBUTETYPE_WRITE);
|
||||
EXPECT_EQ(datatag_id_return2->id, datatag2.id);
|
||||
EXPECT_EQ(datatag_id_return2->type, NEU_ATTRIBUTETYPE_WRITE);
|
||||
EXPECT_EQ(datatag_id_return2->dataType, datatag2.dataType);
|
||||
EXPECT_EQ(datatag_id_return2->str_addr, datatag2.str_addr);
|
||||
|
||||
EXPECT_EQ(datatag_id_return3->id, datatag3.id);
|
||||
EXPECT_EQ(datatag_id_return3->dataType, NEU_DATATYPE_BOOLEAN);
|
||||
EXPECT_EQ(datatag_id_return3->type, datatag3.type);
|
||||
EXPECT_EQ(datatag_id_return3->str_addr, datatag3.str_addr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
TEST(DatatageTableTest,DatatagTablePthread)
|
||||
TEST(DatatageTableTest, DatatagTablePthread)
|
||||
{
|
||||
pthread_t tids[2];
|
||||
int ret1,ret2;
|
||||
neu_datatag_table_t *datatag_table = neu_datatag_tbl_create();
|
||||
pthread_t tids[2];
|
||||
int ret1, ret2;
|
||||
neu_datatag_table_t *datatag_table_create = neu_datatag_tbl_create();
|
||||
ret1 = pthread_create(&tids[0], NULL, datatag_table_thread,
|
||||
(void *) datatag_table_create);
|
||||
ret2 = pthread_create(&tids[1], NULL, datatag_table_thread,
|
||||
(void *) datatag_table_create);
|
||||
|
||||
ret1 = pthread_create(&tids[0],NULL,datatag_table_thread,(void*)datatag_table);
|
||||
ret2 = pthread_create(&tids[1],NULL,datatag_table_thread,(void*)datatag_table);
|
||||
|
||||
pthread_join(tids[0],NULL);
|
||||
pthread_join(tids[1],NULL);
|
||||
pthread_join(tids[0], NULL);
|
||||
pthread_join(tids[1], NULL);
|
||||
|
||||
EXPECT_EQ(0,ret1);
|
||||
EXPECT_EQ(0,ret2);
|
||||
EXPECT_EQ(0, ret1);
|
||||
EXPECT_EQ(0, ret2);
|
||||
|
||||
neu_datatag_tbl_destroy(datatag_table);
|
||||
neu_datatag_tbl_destroy(datatag_table_create);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -169,4 +202,3 @@ int main(int argc, char **argv)
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "parser/neu_json_add_tag.h"
|
||||
#include "parser/neu_json_delete_tag.h"
|
||||
#include "parser/neu_json_get_tag.h"
|
||||
#include "parser/neu_json_parser.h"
|
||||
#include "parser/neu_json_updata_tag.h"
|
||||
|
||||
TEST(JsonDatatagTableTest, AddTagDecode)
|
||||
{
|
||||
char *buf = (char *) "{\"function\":31, "
|
||||
"\"uuid\":\"554f5fd8-f437-11eb-975c-7704b9e17821\", "
|
||||
"\"node_id\":123456, "
|
||||
"\"tags\": "
|
||||
"[{\"name\":\"name1\", \"type\":0,\"decimal\":1, "
|
||||
"\"address\":\"1!400001\",\"flag\":0}, "
|
||||
"{\"name\":\"name2\", \"type\":1,\"decimal\":1, "
|
||||
"\"address\":\"1!400002\",\"flag\":0} ] }";
|
||||
void * result = NULL;
|
||||
struct neu_parse_add_tags_req *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode(buf, &result));
|
||||
|
||||
req = (struct neu_parse_add_tags_req *) result;
|
||||
|
||||
EXPECT_EQ(NEU_PARSE_OP_ADD_TAGS, req->function);
|
||||
EXPECT_STREQ("554f5fd8-f437-11eb-975c-7704b9e17821", req->uuid);
|
||||
EXPECT_EQ(123456, req->node_id);
|
||||
|
||||
EXPECT_STREQ("name1", req->tags[0].name);
|
||||
EXPECT_EQ(0, req->tags[0].type);
|
||||
EXPECT_EQ(1, req->tags[0].decimal);
|
||||
EXPECT_STREQ("1!400001", req->tags[0].address);
|
||||
EXPECT_EQ(0, req->tags[0].flag);
|
||||
|
||||
EXPECT_STREQ("name2", req->tags[1].name);
|
||||
EXPECT_EQ(1, req->tags[1].type);
|
||||
EXPECT_EQ(1, req->tags[1].decimal);
|
||||
EXPECT_STREQ("1!400002", req->tags[1].address);
|
||||
EXPECT_EQ(0, req->tags[1].flag);
|
||||
|
||||
neu_parse_decode_free(result);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, AddTagEncode)
|
||||
{
|
||||
char *buf = (char *) "{\"function\": 31, "
|
||||
"\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", "
|
||||
"\"error\": 0}";
|
||||
char * result = NULL;
|
||||
struct neu_parse_add_tags_res res = {
|
||||
.function = NEU_PARSE_OP_ADD_TAGS,
|
||||
.uuid = (char *) "554f5fd8-f437-11eb-975c-7704b9e17821",
|
||||
.error = 0,
|
||||
};
|
||||
|
||||
EXPECT_EQ(0, neu_parse_encode(&res, &result));
|
||||
EXPECT_STREQ(buf, result);
|
||||
|
||||
free(result);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, GetTagDecode)
|
||||
{
|
||||
char *buf = (char *) "{\"function\": 32, "
|
||||
"\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", "
|
||||
"\"node_id\": 123456}";
|
||||
void * result = NULL;
|
||||
struct neu_parse_get_tags_req *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode(buf, &result));
|
||||
|
||||
req = (struct neu_parse_get_tags_req *) result;
|
||||
|
||||
EXPECT_EQ(NEU_PARSE_OP_GET_TAGS, req->function);
|
||||
EXPECT_STREQ("554f5fd8-f437-11eb-975c-7704b9e17821", req->uuid);
|
||||
EXPECT_EQ(123456, req->node_id);
|
||||
|
||||
neu_parse_decode_free(result);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, GetTagEncode)
|
||||
{
|
||||
char *buf = (char *) "{\"function\": 32, "
|
||||
"\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", "
|
||||
"\"error\": 0, "
|
||||
"\"tags\": "
|
||||
"[{\"name\": \"Tag0001\", \"type\": 0, \"decimal\": "
|
||||
"1, \"address\": \"1!400001\", \"flag\": 0}, "
|
||||
"{\"name\": \"Tag0002\", \"type\": 1, \"decimal\": 1, "
|
||||
"\"address\": \"1!400002\", \"flag\": 0}]}";
|
||||
char * result = NULL;
|
||||
struct neu_parse_get_tags_res res = {
|
||||
.function = NEU_PARSE_OP_GET_TAGS,
|
||||
.uuid = (char *) "554f5fd8-f437-11eb-975c-7704b9e17821",
|
||||
.error = 0,
|
||||
.n_tag = 2,
|
||||
};
|
||||
|
||||
res.tags = (struct neu_parse_get_tags_res_tag *) calloc(
|
||||
2, sizeof(struct neu_parse_get_tags_res_tag));
|
||||
res.tags[0].name = strdup((char *) "Tag0001");
|
||||
res.tags[0].type = 0;
|
||||
res.tags[0].decimal = 1;
|
||||
res.tags[0].address = strdup((char *) "1!400001");
|
||||
res.tags[0].flag = 0;
|
||||
|
||||
res.tags[1].name = strdup((char *) "Tag0002");
|
||||
res.tags[1].type = 1;
|
||||
res.tags[1].decimal = 1;
|
||||
res.tags[1].address = strdup((char *) "1!400002");
|
||||
res.tags[1].flag = 0;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_encode(&res, &result));
|
||||
EXPECT_STREQ(buf, result);
|
||||
|
||||
free(res.tags[0].name);
|
||||
free(res.tags[1].name);
|
||||
free(res.tags[0].address);
|
||||
free(res.tags[1].address);
|
||||
free(res.tags);
|
||||
free(result);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, DeleteTagDecode)
|
||||
{
|
||||
char *buf = (char *) "{\"function\": 33, "
|
||||
"\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", "
|
||||
"\"node_id\": 123456, "
|
||||
"\"tag_id\": 123}";
|
||||
void * result = NULL;
|
||||
struct neu_parse_delete_tags_req *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode(buf, &result));
|
||||
|
||||
req = (struct neu_parse_delete_tags_req *) result;
|
||||
|
||||
EXPECT_EQ(NEU_PARSE_OP_DELETE_TAGS, req->function);
|
||||
EXPECT_STREQ("554f5fd8-f437-11eb-975c-7704b9e17821", req->uuid);
|
||||
EXPECT_EQ(123456, req->node_id);
|
||||
EXPECT_EQ(123, req->tag_id);
|
||||
|
||||
neu_parse_decode_free(result);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, DeleteTagEncode)
|
||||
{
|
||||
char *buf = (char *) "{\"function\": 33, "
|
||||
"\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", "
|
||||
"\"error\": 0}";
|
||||
char * result = NULL;
|
||||
struct neu_parse_delete_tags_res res = {
|
||||
.function = NEU_PARSE_OP_DELETE_TAGS,
|
||||
.uuid = (char *) "554f5fd8-f437-11eb-975c-7704b9e17821",
|
||||
.error = 0,
|
||||
};
|
||||
|
||||
EXPECT_EQ(0, neu_parse_encode(&res, &result));
|
||||
EXPECT_STREQ(buf, result);
|
||||
|
||||
free(result);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, UpdataTaDecode)
|
||||
{
|
||||
char *buf = (char *) "{\"function\":34, "
|
||||
"\"uuid\":\"554f5fd8-f437-11eb-975c-7704b9e17821\", "
|
||||
"\"node_id\":123456, "
|
||||
"\"tag_id\":123, "
|
||||
"\"tags\": "
|
||||
"[{\"name\":\"name1\", \"type\":0,\"decimal\":1, "
|
||||
"\"address\":\"1!400001\",\"flag\":0}, "
|
||||
"{\"name\":\"name2\", \"type\":1,\"decimal\":1, "
|
||||
"\"address\":\"1!400003\",\"flag\":0} ] }";
|
||||
void * result = NULL;
|
||||
struct neu_parse_updata_tags_req *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode(buf, &result));
|
||||
|
||||
req = (struct neu_parse_updata_tags_req *) result;
|
||||
|
||||
EXPECT_EQ(NEU_PARSE_OP_UPDATA_TAGS, req->function);
|
||||
EXPECT_STREQ("554f5fd8-f437-11eb-975c-7704b9e17821", req->uuid);
|
||||
EXPECT_EQ(123456, req->node_id);
|
||||
EXPECT_EQ(123, req->tag_id);
|
||||
|
||||
EXPECT_STREQ("name1", req->tags[0].name);
|
||||
EXPECT_EQ(0, req->tags[0].type);
|
||||
EXPECT_EQ(1, req->tags[0].decimal);
|
||||
EXPECT_STREQ("1!400001", req->tags[0].address);
|
||||
EXPECT_EQ(0, req->tags[0].flag);
|
||||
|
||||
EXPECT_STREQ("name2", req->tags[1].name);
|
||||
EXPECT_EQ(1, req->tags[1].type);
|
||||
EXPECT_EQ(1, req->tags[1].decimal);
|
||||
EXPECT_STREQ("1!400003", req->tags[1].address);
|
||||
EXPECT_EQ(0, req->tags[1].flag);
|
||||
|
||||
neu_parse_decode_free(result);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, UpdataTagEncode)
|
||||
{
|
||||
char *buf = (char *) "{\"function\": 34, "
|
||||
"\"uuid\": \"554f5fd8-f437-11eb-975c-7704b9e17821\", "
|
||||
"\"error\": 0}";
|
||||
char * result = NULL;
|
||||
struct neu_parse_updata_tags_res res = {
|
||||
.function = NEU_PARSE_OP_UPDATA_TAGS,
|
||||
.uuid = (char *) "554f5fd8-f437-11eb-975c-7704b9e17821",
|
||||
.error = 0,
|
||||
};
|
||||
|
||||
EXPECT_EQ(0, neu_parse_encode(&res, &result));
|
||||
EXPECT_STREQ(buf, result);
|
||||
|
||||
free(result);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user