Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndris Zeila <andris.zeila@zabbix.com>2019-05-29 10:36:17 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2019-05-29 11:20:58 +0300
commit2ad0f6e57e10e6ec2e5cb388b20f6fbcefdc87fe (patch)
tree3487d2adc58c585e9fa180d1f0a6323cb32e1575 /tests/libs/zbxjson/zbx_json_decodevalue_dyn.c
parent1150e17faac99eaccd3ea9363ecaa05e27066b3e (diff)
.......PS. [ZBX-16151] fixed theoretical possibility of large numbers in json data being truncated, added boolean value support to json parser
* commit '9f6b629f6f46f89d251a336a7fbce728d8b8bf4d': .......... [ZBX-16151] added changelog entry .......... [ZBX-16151] added cmocka tests for zbx_json_decodevalue_dyn function .......... [ZBX-16151] added cmocka tests for zbx_json_decodevalue function .......PS. [ZBX-16151] backported json large number fix and boolean value support (cherry picked from commit a41263020188a0ae22ecbd3e55c39ba54d3f95f1) (cherry picked from commit 08dcbd76edf035a9c0a56544609cf7657bbfced0)
Diffstat (limited to 'tests/libs/zbxjson/zbx_json_decodevalue_dyn.c')
-rw-r--r--tests/libs/zbxjson/zbx_json_decodevalue_dyn.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/libs/zbxjson/zbx_json_decodevalue_dyn.c b/tests/libs/zbxjson/zbx_json_decodevalue_dyn.c
new file mode 100644
index 00000000000..978e457be92
--- /dev/null
+++ b/tests/libs/zbxjson/zbx_json_decodevalue_dyn.c
@@ -0,0 +1,63 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2019 Zabbix SIA
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 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 General Public License for more details.
+**
+** You should have received a copy of the GNU 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 "common.h"
+#include "zbxjson.h"
+
+#include "zbxmocktest.h"
+#include "zbxmockdata.h"
+#include "zbxmockassert.h"
+#include "zbxmockutil.h"
+
+#include "mock_json.h"
+
+void zbx_mock_test_entry(void **state)
+{
+ const char *data, *result;
+ size_t size;
+ char *buffer;
+ int expected_offset;
+ zbx_json_type_t returned_type;
+
+ ZBX_UNUSED(state);
+
+ data = zbx_mock_get_parameter_string("in.data");
+ size = zbx_mock_get_parameter_uint64("in.size");
+ buffer = (0 != size ? (char *)zbx_malloc(NULL, size) : NULL);
+
+ result = zbx_json_decodevalue_dyn(data, &buffer, &size, &returned_type);
+
+ expected_offset = atoi(zbx_mock_get_parameter_string("out.offset"));
+
+ if (0 == expected_offset)
+ zbx_mock_assert_ptr_eq("Returned value", NULL, result);
+ else
+ zbx_mock_assert_ptr_ne("Returned value", NULL, result);
+
+ if (NULL != result)
+ {
+ zbx_mock_assert_int_eq("Returned value offset", expected_offset, result - data);
+ zbx_mock_assert_str_eq("Returned json type", zbx_mock_get_parameter_string("out.type"),
+ zbx_mock_json_type_to_str(returned_type));
+ zbx_mock_assert_str_eq("Returned value", buffer, zbx_mock_get_parameter_string("out.value"));
+ }
+
+ zbx_free(buffer);
+}
+