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:
authorAndrejs Kozlovs <andrejs.kozlovs@zabbix.com>2019-04-09 16:32:29 +0300
committerAndrejs Kozlovs <andrejs.kozlovs@zabbix.com>2019-04-09 16:32:29 +0300
commit83a338b1a0e5691f966c98d327d1f03c80147fdd (patch)
treedf16a34c18c2e8d9ca395863191a833fe249b756 /tests/zabbix_server
parent5b15dc8ea0b0add0c5696e9f1d89c4ad58511530 (diff)
.......... [DEV-873] converted item_preproc_xpath function cunit test to cmocka framework
Diffstat (limited to 'tests/zabbix_server')
-rw-r--r--tests/zabbix_server/preprocessor/Makefile.am23
-rw-r--r--tests/zabbix_server/preprocessor/item_preproc_test.c23
-rw-r--r--tests/zabbix_server/preprocessor/item_preproc_test.h24
-rw-r--r--tests/zabbix_server/preprocessor/item_preproc_xpath.c60
-rw-r--r--tests/zabbix_server/preprocessor/item_preproc_xpath.yaml105
5 files changed, 234 insertions, 1 deletions
diff --git a/tests/zabbix_server/preprocessor/Makefile.am b/tests/zabbix_server/preprocessor/Makefile.am
index 5cdcf1209ee..6b7719e104c 100644
--- a/tests/zabbix_server/preprocessor/Makefile.am
+++ b/tests/zabbix_server/preprocessor/Makefile.am
@@ -1,5 +1,14 @@
if SERVER
-noinst_PROGRAMS = zbx_item_preproc
+SERVER_tests = zbx_item_preproc
+
+if HAVE_LIBXML2
+SERVER_tests += item_preproc_xpath
+endif
+
+noinst_PROGRAMS = $(SERVER_tests)
+
+COMMON_SRC_FILES = \
+ ../../zbxmocktest.h
JSON_LIBS = \
$(top_srcdir)/tests/libzbxmocktest.a \
@@ -32,4 +41,16 @@ zbx_item_preproc_LDADD += @SERVER_LIBS@
zbx_item_preproc_LDFLAGS = @SERVER_LDFLAGS@
zbx_item_preproc_CFLAGS = -I@top_srcdir@/tests @LIBXML2_CFLAGS@
+
+item_preproc_xpath_SOURCES = \
+ ../../../src/zabbix_server/preprocessor/item_preproc.c \
+ item_preproc_xpath.c \
+ $(COMMON_SRC_FILES)
+
+item_preproc_xpath_LDADD = $(JSON_LIBS)
+
+item_preproc_xpath_LDADD += @SERVER_LIBS@
+item_preproc_xpath_LDFLAGS = @SERVER_LDFLAGS@
+
+item_preproc_xpath_CFLAGS = -I@top_srcdir@/tests @LIBXML2_CFLAGS@
endif
diff --git a/tests/zabbix_server/preprocessor/item_preproc_test.c b/tests/zabbix_server/preprocessor/item_preproc_test.c
new file mode 100644
index 00000000000..27c58a97701
--- /dev/null
+++ b/tests/zabbix_server/preprocessor/item_preproc_test.c
@@ -0,0 +1,23 @@
+/*
+** 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.
+**/
+
+int zbx_item_preproc_xpath(zbx_variant_t *value, const char *params, char **errmsg)
+{
+ return item_preproc_xpath(value, params, errmsg);
+}
diff --git a/tests/zabbix_server/preprocessor/item_preproc_test.h b/tests/zabbix_server/preprocessor/item_preproc_test.h
new file mode 100644
index 00000000000..203b187878e
--- /dev/null
+++ b/tests/zabbix_server/preprocessor/item_preproc_test.h
@@ -0,0 +1,24 @@
+/*
+** 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.
+**/
+#ifndef ITEM_PREPROC_TEST_H
+#define ITEM_PREPROC_TEST_H
+
+int zbx_item_preproc_xpath(zbx_variant_t *value, const char *params, char **errmsg);
+
+#endif
diff --git a/tests/zabbix_server/preprocessor/item_preproc_xpath.c b/tests/zabbix_server/preprocessor/item_preproc_xpath.c
new file mode 100644
index 00000000000..7a9ff5b0bf7
--- /dev/null
+++ b/tests/zabbix_server/preprocessor/item_preproc_xpath.c
@@ -0,0 +1,60 @@
+/*
+** 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 <stdio.h>
+#include "zbxmocktest.h"
+#include "zbxmockdata.h"
+#include "zbxmockutil.h"
+#include "zbxmockassert.h"
+#include "common.h"
+
+#include "item_preproc_test.h"
+#include "zbxembed.h"
+
+zbx_es_t es_engine;
+
+void zbx_mock_test_entry(void **state)
+{
+ zbx_variant_t value;
+ const char *xml;
+ const char *xpath, *exp_xml;
+ char *errmsg = NULL;
+ int act_ret, exp_ret;
+
+ ZBX_UNUSED(state);
+
+ xml = zbx_mock_get_parameter_string("in.xml");
+ xpath = zbx_mock_get_parameter_string("in.xpath");
+ exp_xml = zbx_mock_get_parameter_string("out.result");
+ zbx_variant_set_str(&value, zbx_strdup(NULL, xml));
+
+ act_ret = zbx_item_preproc_xpath(&value, xpath, &errmsg);
+
+ exp_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return"));
+ zbx_mock_assert_int_eq("return value", exp_ret, act_ret);
+
+ if (FAIL == act_ret)
+ {
+ zbx_mock_assert_ptr_ne("error message", NULL, errmsg);
+ zbx_free(errmsg);
+ }
+ else
+ zbx_mock_assert_str_eq("result", exp_xml, value.data.str);
+
+ zbx_variant_clear(&value);
+}
diff --git a/tests/zabbix_server/preprocessor/item_preproc_xpath.yaml b/tests/zabbix_server/preprocessor/item_preproc_xpath.yaml
new file mode 100644
index 00000000000..bec529d3e45
--- /dev/null
+++ b/tests/zabbix_server/preprocessor/item_preproc_xpath.yaml
@@ -0,0 +1,105 @@
+---
+test case: 'empty input parameters'
+in:
+ xml: ''
+ xpath: ''
+out:
+ result: ''
+ return: 'FAIL'
+---
+test case: 'single start tag'
+in:
+ xml: '<a>'
+ xpath: ''
+out:
+ result: ''
+ return: 'FAIL'
+---
+test case: 'single end tag'
+in:
+ xml: '<a/>'
+ xpath: ''
+out:
+ result: ''
+ return: 'FAIL'
+---
+test case: 'wrong operation format'
+in:
+ xml: '<a/>'
+ xpath: '/a[\'
+out:
+ result: ''
+ return: 'FAIL'
+---
+test case: 'wrong operation expression'
+in:
+ xml: '<a/>'
+ xpath: '1 div 0'
+out:
+ result: ''
+ return: 'FAIL'
+---
+test case: 'wrong operation format 2'
+in:
+ xml: '<a/>'
+ xpath: '-a'
+out:
+ result: ''
+ return: 'FAIL'
+---
+test case: 'empty output'
+in:
+ xml: '<a/>'
+ xpath: '/b'
+out:
+ result: ''
+ return: 'SUCCEED'
+---
+test case: 'successful expression'
+in:
+ xml: '<a/>'
+ xpath: '3 div 2'
+out:
+ result: '1.5'
+ return: 'SUCCEED'
+---
+test case: 'return end tag'
+in:
+ xml: '<a/>'
+ xpath: '/a'
+out:
+ result: '<a/>'
+ return: 'SUCCEED'
+---
+test case: 'return text'
+in:
+ xml: '<a>1</a>'
+ xpath: '/a/text()'
+out:
+ result: '1'
+ return: 'SUCCEED'
+---
+test case: 'return string'
+in:
+ xml: '<a>1</a>'
+ xpath: 'string(/a)'
+out:
+ result: '1'
+ return: 'SUCCEED'
+---
+test case: 'return attribute'
+in:
+ xml: '<a b="10">1</a>'
+ xpath: 'string(/a/@b)'
+out:
+ result: '10'
+ return: 'SUCCEED'
+---
+test case: 'return pattern'
+in:
+ xml: '<a><b x="1"/><c x="2"/><d x="1"/></a>'
+ xpath: '//*[@x="1"]'
+out:
+ result: '<b x="1"/><d x="1"/>'
+ return: 'SUCCEED'
+...