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>2017-12-07 16:34:51 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2017-12-07 16:34:51 +0300
commit8c4141e83e2e9ca202a4fd3f9067b320838384d0 (patch)
tree2b6595d635d2496d7a0f1bd3e52a14a867807696 /tests/libs/zbxjson
parentc63e2a6875e11590424386ee4490f092bdf0c3d9 (diff)
.......... [DEV-753] added zbx_json_path_open tests
Diffstat (limited to 'tests/libs/zbxjson')
-rw-r--r--tests/libs/zbxjson/Makefile.am22
-rw-r--r--tests/libs/zbxjson/zbx_json_path_open.c60
-rw-r--r--tests/libs/zbxjson/zbx_json_path_open.yaml124
-rw-r--r--tests/libs/zbxjson/zbx_jsonpath_next.c2
-rw-r--r--tests/libs/zbxjson/zbx_jsonpath_next.yaml30
5 files changed, 216 insertions, 22 deletions
diff --git a/tests/libs/zbxjson/Makefile.am b/tests/libs/zbxjson/Makefile.am
index a7f64b038a7..56e6327b6d5 100644
--- a/tests/libs/zbxjson/Makefile.am
+++ b/tests/libs/zbxjson/Makefile.am
@@ -1,10 +1,6 @@
-noinst_PROGRAMS = zbx_jsonpath_next
+noinst_PROGRAMS = zbx_jsonpath_next zbx_json_path_open
-zbx_jsonpath_next_SOURCES = \
- zbx_jsonpath_next.c \
- ../../zbxmocktest.h
-
-zbx_jsonpath_next_LDADD = \
+JSON_LIBS = \
$(top_srcdir)/tests/libzbxmocktest.a \
$(top_srcdir)/tests/libzbxmockdata.a \
$(top_srcdir)/src/libs/zbxjson/libzbxjson.a \
@@ -16,5 +12,19 @@ zbx_jsonpath_next_LDADD = \
$(top_srcdir)/src/libs/zbxconf/libzbxconf.a \
$(top_srcdir)/tests/libzbxmockdata.a
+zbx_jsonpath_next_SOURCES = \
+ zbx_jsonpath_next.c \
+ ../../zbxmocktest.h
+
+zbx_jsonpath_next_LDADD = $(JSON_LIBS)
+
zbx_jsonpath_next_CFLAGS = -I@top_srcdir@/tests
+
+zbx_json_path_open_SOURCES = \
+ zbx_json_path_open.c \
+ ../../zbxmocktest.h
+
+zbx_json_path_open_LDADD = $(JSON_LIBS)
+
+zbx_json_path_open_CFLAGS = -I@top_srcdir@/tests
diff --git a/tests/libs/zbxjson/zbx_json_path_open.c b/tests/libs/zbxjson/zbx_json_path_open.c
new file mode 100644
index 00000000000..d51d43fa2bd
--- /dev/null
+++ b/tests/libs/zbxjson/zbx_json_path_open.c
@@ -0,0 +1,60 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2017 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 "zbxmocktest.h"
+#include "zbxmockdata.h"
+#include "zbxmockassert.h"
+#include "zbxmockutil.h"
+
+#include "common.h"
+#include "zbxjson.h"
+
+void zbx_mock_test_entry(void **state)
+{
+ const char *json, *path, *result, *value;
+ struct zbx_json_parse jp, jp_out;
+ char *buffer;
+ int ret;
+
+ ZBX_UNUSED(state);
+
+ zbx_mock_get_parameter_string("in.json", &json);
+ zbx_mock_get_parameter_string("in.path", &path);
+ zbx_mock_get_parameter_string("out.result", &result);
+
+ ret = zbx_json_open(json, &jp);
+ zbx_mock_assert_inteq("Invalid zbx_json_open() return value", SUCCEED, ret);
+
+ if (FAIL == (ret = zbx_json_path_open(&jp, path, &jp_out)))
+ {
+ zbx_mock_assert_streq("Invalid zbx_json_path_open() return value", result, "fail");
+ return;
+ }
+
+ zbx_mock_assert_streq("Invalid zbx_json_path_open() return value", result, "succeed");
+
+ buffer = zbx_malloc(NULL, strlen(json));
+ zbx_strlcpy(buffer, jp_out.start, jp_out.end - jp_out.start + 2);
+
+ zbx_mock_get_parameter_string("out.value", &value);
+ zbx_mock_assert_streq("Invalid value", value, buffer);
+
+ zbx_free(buffer);
+}
+
diff --git a/tests/libs/zbxjson/zbx_json_path_open.yaml b/tests/libs/zbxjson/zbx_json_path_open.yaml
new file mode 100644
index 00000000000..7a455eefbc0
--- /dev/null
+++ b/tests/libs/zbxjson/zbx_json_path_open.yaml
@@ -0,0 +1,124 @@
+---
+test case: 'Invalid path $.a[] in {"a":{"b": [{"x":10}, 2, 3] }}'
+in:
+ json: '{"a":{"b": [{"x":10}, 2, 3] }}'
+ path: $.a[]
+out:
+ result: fail
+---
+test case: 'Invalid path $a in {"a":1}'
+in:
+ json: '{"a":1}'
+ path: $a
+out:
+ result: fail
+---
+test case: 'Invalid path "" in {"a":1}'
+in:
+ json: '{"a":1}'
+ path: ""
+out:
+ result: fail
+---
+test case: 'Invalid location $.x.b in {"a":{"b": [{"x":10}, 2, 3] }}'
+in:
+ json: '{"a":{"b": [{"x":10}, 2, 3] }}'
+ path: $.x.b
+out:
+ result: fail
+---
+test case: 'Invalid location $[3] in [1, 2, 3]'
+in:
+ json: '[1, 2, 3]'
+ path: $[3]
+out:
+ result: fail
+---
+test case: 'Valid location $[0] in [1, 2, 3]'
+in:
+ json: '[1, 2, 3]'
+ path: $[0]
+out:
+ result: succeed
+ value: 1
+---
+test case: 'Valid location $[1] in [1, 2, 3]'
+in:
+ json: '[1, 2, 3]'
+ path: $[1]
+out:
+ result: succeed
+ value: 2
+---
+test case: 'Valid location $[2] in [1, 2, 3]'
+in:
+ json: '[1, 2, 3]'
+ path: $[2]
+out:
+ result: succeed
+ value: 3
+---
+test case: 'Valid location $[1][0] in [1,["a","b","c"],3]'
+in:
+ json: '[1,["a","b","c"],3]'
+ path: $[1][0]
+out:
+ result: succeed
+ value: '"a"'
+---
+test case: 'Valid location $.x[1][2] in {"x":[1, ["a", "b", "c"], 3]}'
+in:
+ json: '{"x":[1, ["a", "b", "c"], 3]}'
+ path: $.x[1][2]
+out:
+ result: succeed
+ value: '"c"'
+---
+test case: 'Valid location $.a in {"a":{"b": [{"x":10}, 2, 3] }}'
+in:
+ json: '{"a":{"b": [{"x":10}, 2, 3] }}'
+ path: $.a
+out:
+ result: succeed
+ value: '{"b": [{"x":10}, 2, 3] }'
+---
+test case: 'Valid location $.a in {"a" : {"b": [{"x":10}, 2, 3] }}'
+in:
+ json: '{"a" : {"b": [{"x":10}, 2, 3] }}'
+ path: $.a
+out:
+ result: succeed
+ value: '{"b": [{"x":10}, 2, 3] }'
+---
+test case: 'Valid location $.a.b in {"a":{"b": [{"x":10}, 2, 3] }}'
+in:
+ json: '{"a":{"b": [{"x":10}, 2, 3] }}'
+ path: $.a.b
+out:
+ result: succeed
+ value: '[{"x":10}, 2, 3]'
+---
+test case: 'Valid location $.a.b[0] in {"a":{"b": [{"x":10}, 2, 3] }}'
+in:
+ json: '{"a":{"b": [{"x":10}, 2, 3] }}'
+ path: $.a.b[0]
+out:
+ result: succeed
+ value: '{"x":10}'
+---
+test case: 'Valid location $.a.b[1] in {"a":{"b": [{"x":10}, 2, 3] }}'
+in:
+ json: '{"a":{"b": [{"x":10}, 2, 3] }}'
+ path: $.a.b[1]
+out:
+ result: succeed
+ value: 2
+---
+test case: 'Valid location $.a.b[2] in {"a":{"b": [{"x":10}, 2, 3] }}'
+in:
+ json: '{"a":{"b": [{"x":10}, 2, 3] }}'
+ path: $.a.b[2]
+out:
+ result: succeed
+ value: 3
+...
diff --git a/tests/libs/zbxjson/zbx_jsonpath_next.c b/tests/libs/zbxjson/zbx_jsonpath_next.c
index 199ba3ce0a1..6a00a09671b 100644
--- a/tests/libs/zbxjson/zbx_jsonpath_next.c
+++ b/tests/libs/zbxjson/zbx_jsonpath_next.c
@@ -79,7 +79,7 @@ void zbx_mock_test_entry(void **state)
if ('\0' == *next)
{
- zbx_mock_assert_streq("Return value", result, "ok");
+ zbx_mock_assert_streq("Return value", result, "succeed");
break;
}
}
diff --git a/tests/libs/zbxjson/zbx_jsonpath_next.yaml b/tests/libs/zbxjson/zbx_jsonpath_next.yaml
index b60f0e5c00f..03c724313ab 100644
--- a/tests/libs/zbxjson/zbx_jsonpath_next.yaml
+++ b/tests/libs/zbxjson/zbx_jsonpath_next.yaml
@@ -109,7 +109,7 @@ test case: Valid path $.a
in:
path: $.a
out:
- result: ok
+ result: succeed
components:
- class: dot
value: a
@@ -118,7 +118,7 @@ test case: Valid path $['a']
in:
path: $['a']
out:
- result: ok
+ result: succeed
components:
- class: bracket
value: a
@@ -127,7 +127,7 @@ test case: Valid path $[ 'a' ]
in:
path: $[ 'a' ]
out:
- result: ok
+ result: succeed
components:
- class: bracket
value: a
@@ -136,7 +136,7 @@ test case: Valid path $["a"]
in:
path: $["a"]
out:
- result: ok
+ result: succeed
components:
- class: bracket
value: a
@@ -145,7 +145,7 @@ test case: Valid path $.a.b
in:
path: $.a.b
out:
- result: ok
+ result: succeed
components:
- class: dot
value: a
@@ -156,7 +156,7 @@ test case: Valid path $['a'].b
in:
path: $['a'].b
out:
- result: ok
+ result: succeed
components:
- class: bracket
value: a
@@ -167,7 +167,7 @@ test case: Valid path $['a']['b']
in:
path: $['a']['b']
out:
- result: ok
+ result: succeed
components:
- class: bracket
value: a
@@ -178,7 +178,7 @@ test case: Valid path $.a['b']
in:
path: $.a['b']
out:
- result: ok
+ result: succeed
components:
- class: dot
value: a
@@ -189,7 +189,7 @@ test case: Valid path $.a[0]
in:
path: $.a[0]
out:
- result: ok
+ result: succeed
components:
- class: dot
value: a
@@ -200,7 +200,7 @@ test case: Valid path $.a[0].b[1]
in:
path: $.a[0].b[1]
out:
- result: ok
+ result: succeed
components:
- class: dot
value: a
@@ -215,7 +215,7 @@ test case: Valid path $.a[1000]
in:
path: $.a[1000]
out:
- result: ok
+ result: succeed
components:
- class: dot
value: a
@@ -226,7 +226,7 @@ test case: Valid path $.a[ 1 ]
in:
path: $.a[ 1 ]
out:
- result: ok
+ result: succeed
components:
- class: dot
value: a
@@ -237,7 +237,7 @@ test case: Valid path $['a'][2]
in:
path: $['a'][2]
out:
- result: ok
+ result: succeed
components:
- class: bracket
value: a
@@ -248,7 +248,7 @@ test case: Valid path $['a'][2]['b'][3]
in:
path: $['a'][2]['b'][3]
out:
- result: ok
+ result: succeed
components:
- class: bracket
value: a
@@ -263,7 +263,7 @@ test case: Valid path $[1][2]
in:
path: $[1][2]
out:
- result: ok
+ result: succeed
components:
- class: index
value: 1