diff options
Diffstat (limited to 'tests/libs')
46 files changed, 8780 insertions, 1610 deletions
diff --git a/tests/libs/Makefile.am b/tests/libs/Makefile.am index dac31952174..3493efe46dc 100644 --- a/tests/libs/Makefile.am +++ b/tests/libs/Makefile.am @@ -13,4 +13,5 @@ SUBDIRS = \ zbxcomms \ zbxregexp \ zbxserver \ - zbxtrends + zbxtrends \ + zbxeval diff --git a/tests/libs/zbxcommon/zbx_tm_add.yaml b/tests/libs/zbxcommon/zbx_tm_add.yaml index 4c6c00d8db5..5e04bbea7ec 100644 --- a/tests/libs/zbxcommon/zbx_tm_add.yaml +++ b/tests/libs/zbxcommon/zbx_tm_add.yaml @@ -166,5 +166,53 @@ in: param: 1d out: time: 2020-01-30 00:00:00 +00:00 +--- +test case: 2020-09-01 00:00:00 +03:00 + 1m +in: + timezone: :Europe/Riga + time: 2020-09-01 00:00:00 +03:00 + param: 1m +out: + time: 2020-09-01 00:01:00 +03:00 +--- +test case: 2020-09-01 00:59:00 +03:00 + 1m +in: + timezone: :Europe/Riga + time: 2020-09-01 00:59:00 +03:00 + param: 1m +out: + time: 2020-09-01 01:00:00 +03:00 +--- +test case: 2020-03-29 02:59:00 +02:00 + 1m +in: + timezone: :Europe/Riga + time: 2020-03-29 02:59:00 +02:00 + param: 1m +out: + time: 2020-03-29 03:00:00 +03:00 +--- +test case: 2020-09-01 00:00:00 +03:00 + 1s +in: + timezone: :Europe/Riga + time: 2020-09-01 00:00:00 +03:00 + param: 1s +out: + time: 2020-09-01 00:00:01 +03:00 +--- +test case: 2020-09-01 00:00:59 +03:00 + 1s +in: + timezone: :Europe/Riga + time: 2020-09-01 00:00:59 +03:00 + param: 1s +out: + time: 2020-09-01 00:01:00 +03:00 +--- +test case: 2020-03-29 02:59:59 +02:00 + 1s +in: + timezone: :Europe/Riga + time: 2020-03-29 02:59:59 +02:00 + param: 1s +out: + time: 2020-03-29 03:00:00 +03:00 ... diff --git a/tests/libs/zbxcommon/zbx_tm_round_down.yaml b/tests/libs/zbxcommon/zbx_tm_round_down.yaml index 0ff6b745081..0f4f3e9871f 100644 --- a/tests/libs/zbxcommon/zbx_tm_round_down.yaml +++ b/tests/libs/zbxcommon/zbx_tm_round_down.yaml @@ -94,5 +94,21 @@ in: base: w out: time: 2020-09-07 00:00:00 +03:00 +--- +test case: 2020-09-01 00:00:00 +03:00 / m +in: + timezone: :Europe/Riga + time: 2020-09-01 00:00:00 +03:00 + base: m +out: + time: 2020-09-01 00:00:00 +03:00 +--- +test case: 2020-09-01 00:01:01 +03:00 / m +in: + timezone: :Europe/Riga + time: 2020-09-01 00:01:01 +03:00 + base: m +out: + time: 2020-09-01 00:01:00 +03:00 ... diff --git a/tests/libs/zbxcommon/zbx_tm_round_up.yaml b/tests/libs/zbxcommon/zbx_tm_round_up.yaml index fb803b6c52d..463bfe62617 100644 --- a/tests/libs/zbxcommon/zbx_tm_round_up.yaml +++ b/tests/libs/zbxcommon/zbx_tm_round_up.yaml @@ -70,5 +70,21 @@ in: base: y out: time: 2021-01-01 00:00:00 +02:00 +--- +test case: 2020-09-01 00:00:00 +03:00 / m +in: + timezone: :Europe/Riga + time: 2020-09-01 00:00:00 +03:00 + base: m +out: + time: 2020-09-01 00:00:00 +03:00 +--- +test case: 2020-09-01 00:00:01 +03:00 / m +in: + timezone: :Europe/Riga + time: 2020-09-01 00:00:01 +03:00 + base: m +out: + time: 2020-09-01 00:01:00 +03:00 ... diff --git a/tests/libs/zbxcommon/zbx_tm_sub.yaml b/tests/libs/zbxcommon/zbx_tm_sub.yaml index cee97408550..d9bb0fbccfe 100644 --- a/tests/libs/zbxcommon/zbx_tm_sub.yaml +++ b/tests/libs/zbxcommon/zbx_tm_sub.yaml @@ -174,4 +174,36 @@ in: param: 1h out: time: 2019-12-31 23:00:00 +02:00 +--- +test case: 2020-09-01 12:00:00 +03:00 - 1m +in: + timezone: :Europe/Riga + time: 2020-09-01 12:00:00 +03:00 + param: 1m +out: + time: 2020-09-01 11:59:00 +03:00 +--- +test case: 2020-10-25 03:00:00 +02:00 - 1m +in: + timezone: :Europe/Riga + time: 2020-10-25 03:00:00 +02:00 + param: 1m +out: + time: 2020-10-25 02:59:00 +03:00 +--- +test case: 2020-09-01 12:00:00 +03:00 - 1s +in: + timezone: :Europe/Riga + time: 2020-09-01 12:00:00 +03:00 + param: 1s +out: + time: 2020-09-01 11:59:59 +03:00 +--- +test case: 2020-10-25 03:00:00 +02:00 - 1s +in: + timezone: :Europe/Riga + time: 2020-10-25 03:00:00 +02:00 + param: 1s +out: + time: 2020-10-25 02:59:59 +03:00 ... diff --git a/tests/libs/zbxcommon/zbx_token_find.yaml b/tests/libs/zbxcommon/zbx_token_find.yaml index 798680d3e45..c09ddf73479 100644 --- a/tests/libs/zbxcommon/zbx_token_find.yaml +++ b/tests/libs/zbxcommon/zbx_token_find.yaml @@ -543,7 +543,7 @@ in: out: token: '{?{HOST.HOST}' token_type: ZBX_TOKEN_EXPRESSION_MACRO - expression: '{HOST.HOST' + expression: '{HOST.HOST}' return: SUCCEED --- test case: 'Success: {?{$MACRO}}' diff --git a/tests/libs/zbxcommon/zbx_variant_compare.c b/tests/libs/zbxcommon/zbx_variant_compare.c index d6a14c6e819..a972a5bdd8c 100644 --- a/tests/libs/zbxcommon/zbx_variant_compare.c +++ b/tests/libs/zbxcommon/zbx_variant_compare.c @@ -23,6 +23,7 @@ #include "zbxmockutil.h" #include "common.h" +#include "zbxvariant.h" static unsigned int hex2num(char c) { diff --git a/tests/libs/zbxdbcache/Makefile.am b/tests/libs/zbxdbcache/Makefile.am index bb6690c133f..42ec3ded75b 100644 --- a/tests/libs/zbxdbcache/Makefile.am +++ b/tests/libs/zbxdbcache/Makefile.am @@ -7,9 +7,7 @@ SERVER_tests = \ dc_check_maintenance_period \ is_item_processed_by_server \ dc_item_poller_type_update \ - dc_expand_user_macros_in_expression \ dc_expand_user_macros_in_func_params \ - dc_expand_user_macros_in_calcitem \ dc_function_calculate_nextcheck endif @@ -45,6 +43,7 @@ CACHE_LIBS = \ $(top_srcdir)/src/libs/zbxtrends/libzbxtrends.a \ $(top_srcdir)/src/zabbix_server/libzbxserver.a \ $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \ + $(top_srcdir)/src/libs/zbxeval/libzbxeval.a \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ @@ -156,17 +155,6 @@ dc_item_poller_type_update_LDADD = $(CACHE_LIBS) @SERVER_LIBS@ dc_item_poller_type_update_LDFLAGS = @SERVER_LDFLAGS@ dc_item_poller_type_update_CFLAGS = -I@top_srcdir@/tests -I@top_srcdir@/src/libs/zbxdbcache -dc_expand_user_macros_in_expression_CFLAGS = \ - -I@top_srcdir@/tests \ - -I@top_srcdir@/tests/mocks/configcache \ - -I@top_srcdir@/src/libs/zbxdbcache -dc_expand_user_macros_in_expression_SOURCES = \ - dc_expand_user_macros_in_expression.c -dc_expand_user_macros_in_expression_LDADD = \ - $(top_srcdir)/tests/mocks/configcache/libconfigcachemock.a \ - $(CACHE_LIBS) @SERVER_LIBS@ -dc_expand_user_macros_in_expression_LDFLAGS = @SERVER_LDFLAGS@ \ - -Wl,--wrap=zbx_hashset_search dc_expand_user_macros_in_func_params_CFLAGS = \ -I@top_srcdir@/tests \ -I@top_srcdir@/tests/mocks/configcache \ @@ -178,17 +166,6 @@ dc_expand_user_macros_in_func_params_LDADD = \ $(CACHE_LIBS) @SERVER_LIBS@ dc_expand_user_macros_in_func_params_LDFLAGS = @SERVER_LDFLAGS@ \ -Wl,--wrap=zbx_hashset_search -dc_expand_user_macros_in_calcitem_CFLAGS = \ - -I@top_srcdir@/tests \ - -I@top_srcdir@/tests/mocks/configcache \ - -I@top_srcdir@/src/libs/zbxdbcache -dc_expand_user_macros_in_calcitem_SOURCES = \ - dc_expand_user_macros_in_calcitem.c -dc_expand_user_macros_in_calcitem_LDADD = \ - $(top_srcdir)/tests/mocks/configcache/libconfigcachemock.a \ - $(CACHE_LIBS) @SERVER_LIBS@ -dc_expand_user_macros_in_calcitem_LDFLAGS = @SERVER_LDFLAGS@ \ - -Wl,--wrap=zbx_hashset_search dc_function_calculate_nextcheck_CFLAGS = \ -I@top_srcdir@/tests diff --git a/tests/libs/zbxdbcache/dc_expand_user_macros_in_calcitem.c b/tests/libs/zbxdbcache/dc_expand_user_macros_in_calcitem.c deleted file mode 100644 index 241ada7c693..00000000000 --- a/tests/libs/zbxdbcache/dc_expand_user_macros_in_calcitem.c +++ /dev/null @@ -1,62 +0,0 @@ -/* -** Zabbix -** Copyright (C) 2001-2021 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 "zbxserver.h" -#include "common.h" -#include "zbxalgo.h" -#include "dbcache.h" -#include "mutexs.h" - -#define ZBX_DBCONFIG_IMPL -#include "dbconfig.h" - -#include "configcache_mock.h" - -/****************************************************************************** - * * - * Function: zbx_mock_test_entry * - * * - ******************************************************************************/ -void zbx_mock_test_entry(void **state) -{ - char *returned_formula; - const char *formula, *expected_formula; - zbx_uint64_t hostid; - - ZBX_UNUSED(state); - - mock_config_init(); - mock_config_load_user_macros("in.macros"); - mock_config_load_hosts("in.hosts"); - - formula = zbx_mock_get_parameter_string("in.formula"); - hostid = zbx_mock_get_parameter_uint64("in.hostid"); - expected_formula = zbx_mock_get_parameter_string("out.formula"); - returned_formula = dc_expand_user_macros_in_calcitem(formula, hostid); - zbx_mock_assert_str_eq("Expanded parameters", expected_formula, returned_formula); - - zbx_free(returned_formula); - - mock_config_free(); -} diff --git a/tests/libs/zbxdbcache/dc_expand_user_macros_in_calcitem.yaml b/tests/libs/zbxdbcache/dc_expand_user_macros_in_calcitem.yaml deleted file mode 100644 index f286db500cd..00000000000 --- a/tests/libs/zbxdbcache/dc_expand_user_macros_in_calcitem.yaml +++ /dev/null @@ -1,174 +0,0 @@ ---- -test case: Expand 'last("hostA:key[{$A}]",{$A}) + last("hostB:key[{$A}]",{$A})' with hostA:{$A}=#1, hostB:{$A}=#2 -in: - hosts: - - hostid: 1 - host: hostA - - hostid: 2 - host: hostB - macros: - - hostid: 1 - name: '{$A}' - value: '#1' - - hostid: 2 - name: '{$A}' - value: '#2' - hostid: 1 - formula: 'last("hostA:key[{$A}]",{$A}) + last("hostB:key[{$A}]",{$A})' -out: - formula: 'last("hostA:key[{$A}]",#1) + last("hostB:key[{$A}]",#2)' ---- -test case: Expand 'last("hostA:key[{$A}]",{$A}) + last("hostB:key[{$A}]",{$A})' with hostA:{$A}='', hostB:{$A}='' -in: - hosts: - - hostid: 1 - host: hostA - - hostid: 2 - host: hostB - macros: - - hostid: 1 - name: '{$A}' - value: '' - - hostid: 2 - name: '{$A}' - value: '' - hostid: 1 - formula: 'last("hostA:key[{$A}]",{$A}) + last("hostB:key[{$A}]",{$A})' -out: - formula: 'last("hostA:key[{$A}]",) + last("hostB:key[{$A}]",)' ---- -test case: Expand 'last(host:key)' -in: - hosts: [] - macros: [] - hostid: 1 - formula: 'last(host:key)' -out: - formula: 'last(host:key)' ---- -test case: Expand 'last("key[{$A}]",{$A})' on hostA with hostA:{$A}='#1', hostB:{$A}='#2' -in: - hosts: - - hostid: 1 - host: hostA - - hostid: 2 - host: hostB - macros: - - hostid: 1 - name: '{$A}' - value: '#1' - - hostid: 2 - name: '{$A}' - value: '#2' - hostid: 1 - formula: 'last("key[{$A}]",{$A})' -out: - formula: 'last("key[{$A}]",#1)' ---- -test case: Expand 'last("key[{$A}]",{$A})' on hostB with hostA:{$A}='#1', hostB:{$A}='#2' -in: - hosts: - - hostid: 1 - host: hostA - - hostid: 2 - host: hostB - macros: - - hostid: 1 - name: '{$A}' - value: '#1' - - hostid: 2 - name: '{$A}' - value: '#2' - hostid: 2 - formula: 'last("key[{$A}]",{$A})' -out: - formula: 'last("key[{$A}]",#2)' ---- -test case: Expand '{$A}last(host:key){$B}' -in: - hosts: [] - macros: - - hostid: 1 - name: '{$A}' - value: '11' - - hostid: 2 - name: '{$A}' - value: '21' - - hostid: 1 - name: '{$B}' - value: '12' - - hostid: 2 - name: '{$B}' - value: '22' - hostid: 1 - formula: '{$A}last(host:key){$B}' -out: - formula: '11last(host:key)12' ---- -test case: Expand '{$A}last(host:key){$B}' -in: - hosts: [] - macros: - - hostid: 1 - name: '{$A}' - value: '11' - - hostid: 2 - name: '{$A}' - value: '21' - - hostid: 1 - name: '{$B}' - value: '12' - - hostid: 2 - name: '{$B}' - value: '22' - hostid: 2 - formula: '{$A}last(host:key){$B}' -out: - formula: '21last(host:key)22' ---- -test case: Expand '{$X}+last("hostB:key[{$X}]",{$X})+{$Y}+last("key[{$X}]",{$X})+{$Z}' -in: - hosts: - - hostid: 1 - host: hostA - - hostid: 2 - host: hostB - macros: - - hostid: 1 - name: '{$X}' - value: '1' - - hostid: 1 - name: '{$Y}' - value: '2' - - hostid: 1 - name: '{$Z}' - value: '3' - - hostid: 2 - name: '{$X}' - value: '100' - hostid: 1 - formula: '{$X}+last("hostB:key[{$X}]",{$X})+{$Y}+last("key[{$X}]",{$X})+{$Z}' -out: - formula: '1+last("hostB:key[{$X}]",100)+2+last("key[{$X}]",1)+3' ---- -test case: Expand '{$A}{$B}last("hostA:key[{$A}]",{$A}${B}){$A}{$B}' -in: - hosts: - - hostid: 1 - host: hostA - - hostid: 2 - host: hostB - macros: - - hostid: 1 - name: '{$A}' - value: '#' - - hostid: 1 - name: '{$B}' - value: '1' - hostid: 1 - formula: '{$A}{$B}last("hostA:key[{$A}]",{$A}{$B}){$A}{$B}' -out: - formula: '"#"1last("hostA:key[{$A}]",#1)"#"1' -... - - diff --git a/tests/libs/zbxdbcache/dc_expand_user_macros_in_expression.c b/tests/libs/zbxdbcache/dc_expand_user_macros_in_expression.c deleted file mode 100644 index ec3eef5c8cb..00000000000 --- a/tests/libs/zbxdbcache/dc_expand_user_macros_in_expression.c +++ /dev/null @@ -1,58 +0,0 @@ -/* -** Zabbix -** Copyright (C) 2001-2021 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 "zbxserver.h" -#include "common.h" -#include "zbxalgo.h" -#include "dbcache.h" -#include "mutexs.h" -#define ZBX_DBCONFIG_IMPL -#include "dbconfig.h" - -#include "configcache_mock.h" - -/****************************************************************************** - * * - * Function: zbx_mock_test_entry * - * * - ******************************************************************************/ -void zbx_mock_test_entry(void **state) -{ - char *returned_expression; - const char *expression, *expected_expression; - - ZBX_UNUSED(state); - - mock_config_init(); - mock_config_load_user_macros("in.macros"); - - expression = zbx_mock_get_parameter_string("in.expression"); - expected_expression = zbx_mock_get_parameter_string("out.expression"); - returned_expression = dc_expand_user_macros_in_expression(expression, NULL, 0); - zbx_mock_assert_str_eq("Expanded expression", expected_expression, returned_expression); - - zbx_free(returned_expression); - - mock_config_free(); -} diff --git a/tests/libs/zbxdbcache/dc_expand_user_macros_in_expression.yaml b/tests/libs/zbxdbcache/dc_expand_user_macros_in_expression.yaml deleted file mode 100644 index 6a47452544e..00000000000 --- a/tests/libs/zbxdbcache/dc_expand_user_macros_in_expression.yaml +++ /dev/null @@ -1,222 +0,0 @@ ---- -test case: Expand '{1} < {$A}' with {$A}=1 -in: - macros: - - name: '{$A}' - value: 1 - expression: '{1} < {$A}' -out: - expression: '{1} < 1' ---- -test case: Expand '{1} < "{$A}"' with {$A}=1 -in: - macros: - - name: '{$A}' - value: 1 - expression: '{1} < "{$A}"' -out: - expression: '{1} < "1"' ---- -test case: Expand '{1} < {$A}' -in: - macros: [] - expression: '{1} < {$A}' -out: - expression: '{1} < {$A}' ---- -test case: Expand '{1} < {$A}' with {$A}=x -in: - macros: - - name: '{$A}' - value: x - expression: '{1} < {$A}' -out: - expression: '{1} < "x"' ---- -test case: Expand '{1} < {$A}' with {$A}="x" -in: - macros: - - name: '{$A}' - value: '"x"' - expression: '{1} < {$A}' -out: - expression: '{1} < "\"x\""' ---- -test case: Expand '{1} < "{$A}"' with {$A}="x" -in: - macros: - - name: '{$A}' - value: '"x"' - expression: '{1} < "{$A}"' -out: - expression: '{1} < "\"x\""' ---- -test case: Expand '{1} < "{$A}"' -in: - macros: [] - expression: '{1} < "{$A}"' -out: - expression: '{1} < "{$A}"' ---- -test case: Expand '{1} = "x" and {2} < {$A}' with {$A}="x" -in: - macros: - - name: '{$A}' - value: '"x"' - expression: '{1} = "x" and {2} < {$A}' -out: - expression: '{1} = "x" and {2} < "\"x\""' ---- -test case: Expand '{1} < "{$A}{$B}"' with {$A}=1,'{$B}'="x" -in: - macros: - - name: '{$A}' - value: 1 - - name: '{$B}' - value: '"x"' - expression: '{1} < "{$A}{$B}"' -out: - expression: '{1} < "1\"x\""' ---- -test case: Expand '{1} < "{$A}{$B}"' with {$A}=1,'{$B}'=2 -in: - macros: - - name: '{$A}' - value: 1 - - name: '{$B}' - value: 2 - expression: '{1} < "{$A}{$B}"' -out: - expression: '{1} < "12"' ---- -test case: Expand '{1} < "{$A}{$B}"' with {$A}="x",'{$B}'="y" -in: - macros: - - name: '{$A}' - value: '"x"' - - name: '{$B}' - value: '"y"' - expression: '{1} < "{$A}{$B}"' -out: - expression: '{1} < "\"x\"\"y\""' ---- -test case: Expand '{1} < {$A}{$B}' with {$A}="x",'{$B}'="y" -in: - macros: - - name: '{$A}' - value: '"x"' - - name: '{$B}' - value: '"y"' - expression: '{1} < {$A}{$B}' -out: - expression: '{1} < "\"x\"""\"y\""' ---- -test case: Expand '{1} < {$A}{$B}' with {$A}=1,'{$B}'=0 -in: - macros: - - name: '{$A}' - value: 1 - - name: '{$B}' - value: 0 - expression: '{1} < {$A}{$B}' -out: - expression: '{1} < 10' ---- -test case: Expand '{1} < "\"{$A}\"{$B}\""' with {$A}=\",'{$B}'=\ -in: - macros: - - name: '{$A}' - value: '\"' - - name: '{$B}' - value: '\' - expression: '{1} < "\"{$A}\"{$B}\""' -out: - expression: '{1} < "\"\\\"\"\\\""' ---- -test case: Expand '{1} < " \" {$A} \" {$B} \" " and {$A}<>"\"{$B}" and " {$A} " = " {$A} "' with {$A}=",'{$B}'=\\ -in: - macros: - - name: '{$A}' - value: '"' - - name: '{$B}' - value: '\\' - expression: '{1} < " \" {$A} \" {$B} \" " and {$A}<>"\"{$B}" and " {$A} " = " {$A} "' -out: - expression: '{1} < " \" \" \" \\\\ \" " and "\""<>"\"\\\\" and " \" " = " \" "' ---- -test case: Expand '{1} < {$A}' with {$A}="" -in: - macros: - - name: '{$A}' - value: '' - expression: '{1} < {$A}' -out: - expression: '{1} < ""' ---- -test case: Expand '{1} < "{$A}"' with {$A}="" -in: - macros: - - name: '{$A}' - value: '' - expression: '{1} < "{$A}"' -out: - expression: '{1} < ""' ---- -test case: Expand '{1} = {$A:"x:\"1\""} or {2} = {$A:"y"}' with {$A:"x:\"1\""}=ax, {$A}=a -in: - macros: - - name: '{$A:"x:\"1\""}' - value: ax - - name: '{$A}' - value: a - expression: '{1} = {$A:"x:\"1\""} or {2} = {$A:"y"}' -out: - expression: '{1} = "ax" or {2} = "a"' ---- -test case: Expand '{1} < {$A:"x:\"1\""}' -in: - macros: [] - expression: '{1} < {$A:"x:\"1\""}' -out: - expression: '{1} < {$A:"x:\"1\""}' ---- -test case: Expand '{2000} < {$A}' with {$A}=2e+3 -in: - macros: - - name: '{$A}' - value: 2e+3 - expression: '{2000} < {$A}' -out: - expression: '{2000} < 2e+3' ---- -test case: Expand '{1} < "\\\"a\"" and {1} = {$A}' with {$A}="b" -in: - macros: - - name: '{$A}' - value: '"b"' - expression: '{1} < "\\\"a\"" and {1} = {$A}' -out: - expression: '{1} < "\\\"a\"" and {1} = "\"b\""' ---- -test case: Expand '{1} < "{$A}{$B}"' with {$A}=<large 2048 macro>,'{$B}'=<large 2048 macro> -in: - macros: - - name: '{$A}' - value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' - - name: '{$B}' - value: 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB' - expression: '{1} < "{$A}{$B}"' -out: - expression: '{1} < "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"' ---- -test case: Expand '{1} < {$A}{$B}' with {$A}=<large 2050 macro>,'{$B}'=<large 2050 macro> -in: - macros: - - name: '{$A}' - value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' - - name: '{$B}' - value: 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB' - expression: '{1} < {$A}{$B}' -out: - expression: '{1} < "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA""BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"' -... diff --git a/tests/libs/zbxdbcache/dc_function_calculate_nextcheck.c b/tests/libs/zbxdbcache/dc_function_calculate_nextcheck.c index d35438ff898..0eadec95d61 100644 --- a/tests/libs/zbxdbcache/dc_function_calculate_nextcheck.c +++ b/tests/libs/zbxdbcache/dc_function_calculate_nextcheck.c @@ -30,16 +30,21 @@ int zbx_dc_function_calculate_nextcheck(const zbx_trigger_timer_t *timer, time_t from, zbx_uint64_t seed); -static int str_to_function_type(const char *str) +/* copiedf from zbxdbcache/dbconfig.c */ +#define ZBX_TRIGGER_TIMER_TRIGGER 0x0001 +#define ZBX_TRIGGER_TIMER_FUNCTION_TIME 0x0002 +#define ZBX_TRIGGER_TIMER_FUNCTION_TREND 0x0004 + +static int str_to_timer_type(const char *str) { - if (0 == strcmp(str, "ZBX_FUNCTION_TYPE_TIMER")) - return ZBX_FUNCTION_TYPE_TIMER; - if (0 == strcmp(str, "ZBX_FUNCTION_TYPE_TRENDS")) - return ZBX_FUNCTION_TYPE_TRENDS; - if (0 == strcmp(str, "ZBX_FUNCTION_TYPE_HISTORY")) - return ZBX_FUNCTION_TYPE_HISTORY; + if (0 == strcmp(str, "ZBX_TRIGGER_TIMER_TRIGGER")) + return ZBX_TRIGGER_TIMER_TRIGGER; + if (0 == strcmp(str, "ZBX_TRIGGER_TIMER_FUNCTION_TIME")) + return ZBX_TRIGGER_TIMER_FUNCTION_TIME; + if (0 == strcmp(str, "ZBX_TRIGGER_TIMER_FUNCTION_TREND")) + return ZBX_TRIGGER_TIMER_FUNCTION_TREND; - fail_msg("unknown function type \"%s\"", str); + fail_msg("unknown timer type \"%s\"", str); return ZBX_FUNCTION_TYPE_UNKNOWN; } @@ -60,10 +65,10 @@ void zbx_mock_test_entry(void **state) if (ZBX_MOCK_SUCCESS != zbx_strtime_to_timespec(zbx_mock_get_parameter_string("in.time"), &ts_from)) fail_msg("Invalid input time format"); - timer.type = str_to_function_type(zbx_mock_get_parameter_string("in.type")); + timer.type = str_to_timer_type(zbx_mock_get_parameter_string("in.type")); timer.parameter = zbx_mock_get_parameter_string("in.params"); - if (ZBX_FUNCTION_TYPE_TRENDS == timer.type) + if (ZBX_TRIGGER_TIMER_FUNCTION_TREND == timer.type) { if (SUCCEED != zbx_trends_parse_base(timer.parameter, &timer.trend_base, &error)) { diff --git a/tests/libs/zbxdbcache/dc_function_calculate_nextcheck.yaml b/tests/libs/zbxdbcache/dc_function_calculate_nextcheck.yaml index 4c3414e3b74..de7cff99cb5 100644 --- a/tests/libs/zbxdbcache/dc_function_calculate_nextcheck.yaml +++ b/tests/libs/zbxdbcache/dc_function_calculate_nextcheck.yaml @@ -1,7 +1,7 @@ --- test case: Schedule time based trigger from 2020-09-01 00:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TIMER + type: ZBX_TRIGGER_TIMER_FUNCTION_TIME params: timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 @@ -10,7 +10,7 @@ out: --- test case: Schedule time based trigger from 2020-09-01 00:00:15.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TIMER + type: ZBX_TRIGGER_TIMER_FUNCTION_TIME params: timezone: :Europe/Riga time: 2020-09-01 00:00:15.000000000 +03:00 @@ -19,107 +19,107 @@ out: --- test case: Schedule time based trigger from 2020-09-01 00:00:30.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TIMER + type: ZBX_TRIGGER_TIMER_FUNCTION_TIME params: timezone: :Europe/Riga time: 2020-09-01 00:00:30.000000000 +03:00 out: nextcheck: 2020-09-01 00:01:00.000000000 +03:00 --- -test case: Schedule 1h,now/h 2020-09-01 10:30:30.000000000 +03:00 +test case: Schedule 1h:now/h 2020-09-01 10:30:30.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 1h,now/h + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 1h:now/h timezone: :Europe/Riga time: 2020-09-01 10:30:30.000000000 +03:00 out: nextcheck: 2020-09-01 11:10:00.000000000 +03:00 --- -test case: Schedule 1h,now/h 2020-09-01 10:00:00.000000000 +03:00 +test case: Schedule 1h:now/h 2020-09-01 10:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 1h,now/h + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 1h:now/h timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: nextcheck: 2020-09-01 10:10:00.000000000 +03:00 --- -test case: Schedule 1h,now/h 2020-09-01 10:59:00.000000000 +03:00 +test case: Schedule 1h:now/h 2020-09-01 10:59:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 1h,now/h + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 1h:now/h timezone: :Europe/Riga time: 2020-09-01 10:59:00.000000000 +03:00 out: nextcheck: 2020-09-01 11:10:00.000000000 +03:00 --- -test case: Schedule 1h,now/d 2020-09-01 10:00:00.000000000 +03:00 +test case: Schedule 1h:now/d 2020-09-01 10:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 1h,now/d + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 1h:now/d timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: nextcheck: 2020-09-02 00:10:00.000000000 +03:00 --- -test case: Schedule 1h,now/M+1h 2020-09-01 10:00:00.000000000 +03:00 +test case: Schedule 1h:now/M+1h 2020-09-01 10:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 1h,now/M+1h + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 1h:now/M+1h timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: nextcheck: 2020-10-01 01:10:00.000000000 +03:00 --- -test case: Schedule 1h,now/M+1d 2020-09-01 10:00:00.000000000 +03:00 +test case: Schedule 1h:now/M+1d 2020-09-01 10:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 1h,now/M+1d + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 1h:now/M+1d timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: nextcheck: 2020-09-02 00:10:00.000000000 +03:00 --- -test case: Schedule 1h,now/M+1d 2020-09-02 10:00:00.000000000 +03:00 +test case: Schedule 1h:now/M+1d 2020-09-02 10:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 1h,now/M+1d + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 1h:now/M+1d timezone: :Europe/Riga time: 2020-09-02 10:00:00.000000000 +03:00 out: nextcheck: 2020-10-02 00:10:00.000000000 +03:00 --- -test case: Schedule 1d,now/M+6d/w+1d 2020-09-01 10:00:00.000000000 +03:00 +test case: Schedule 1d:now/M+6d/w+1d 2020-09-01 10:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 1h,now/M+6d/w+1d + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 1h:now/M+6d/w+1d timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: nextcheck: 2020-09-08 00:10:00.000000000 +03:00 --- -test case: Schedule 1d,now/M+6d/w+1d 2020-09-09 10:00:00.000000000 +03:00 +test case: Schedule 1d:now/M+6d/w+1d 2020-09-09 10:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 1h,now/M+6d/w+1d + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 1h:now/M+6d/w+1d timezone: :Europe/Riga time: 2020-09-09 10:00:00.000000000 +03:00 out: nextcheck: 2020-10-06 00:10:00.000000000 +03:00 --- -test case: Schedule 8h,now/d+17h 2020-09-01 10:00:00.000000000 +03:00 +test case: Schedule 8h:now/d+17h 2020-09-01 10:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 8h,now/d+17h + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 8h:now/d+17h timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: nextcheck: 2020-09-01 17:10:00.000000000 +03:00 --- -test case: Schedule 8h,now/d+17h 2020-09-01 18:00:00.000000000 +03:00 +test case: Schedule 8h:now/d+17h 2020-09-01 18:00:00.000000000 +03:00 in: - type: ZBX_FUNCTION_TYPE_TRENDS - params: 8h,now/d+17h + type: ZBX_TRIGGER_TIMER_FUNCTION_TREND + params: 8h:now/d+17h timezone: :Europe/Riga time: 2020-09-01 18:00:00.000000000 +03:00 out: diff --git a/tests/libs/zbxdbcache/dc_item_poller_type_update.yaml b/tests/libs/zbxdbcache/dc_item_poller_type_update.yaml index 1841deac362..203c5ac7e2a 100644 --- a/tests/libs/zbxdbcache/dc_item_poller_type_update.yaml +++ b/tests/libs/zbxdbcache/dc_item_poller_type_update.yaml @@ -846,84 +846,84 @@ in: result: ZBX_NO_POLLER - ref: 169 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_NO_POLLER flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 170 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_NO_POLLER flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 171 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_NORMAL flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 172 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_NORMAL flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 173 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_IPMI flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 174 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_IPMI flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 175 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_PINGER flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 176 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_PINGER flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 177 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_JAVA flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 178 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_JAVA flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 179 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_UNREACHABLE flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 180 access: DIRECT - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_UNREACHABLE flags: ZBX_ITEM_COLLECTED @@ -3202,84 +3202,84 @@ in: result: ZBX_NO_POLLER - ref: 229 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_NO_POLLER flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 230 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_NO_POLLER flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 231 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_NORMAL flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 232 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_NORMAL flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 233 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_IPMI flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 234 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_IPMI flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 235 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_PINGER flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 236 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_PINGER flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 237 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_JAVA flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 238 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_JAVA flags: ZBX_ITEM_COLLECTED result: ZBX_POLLER_TYPE_HISTORY - ref: 239 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_UNREACHABLE flags: 0 result: ZBX_POLLER_TYPE_HISTORY - ref: 240 access: PROXY - type: ITEM_TYPE_AGGREGATE + type: ITEM_TYPE_CALCULATED key: k poller: ZBX_POLLER_TYPE_UNREACHABLE flags: ZBX_ITEM_COLLECTED diff --git a/tests/libs/zbxdbcache/is_item_processed_by_server.yaml b/tests/libs/zbxdbcache/is_item_processed_by_server.yaml index b6dad791c95..6dbc8b18566 100644 --- a/tests/libs/zbxdbcache/is_item_processed_by_server.yaml +++ b/tests/libs/zbxdbcache/is_item_processed_by_server.yaml @@ -202,20 +202,6 @@ in: out: return: 'FAIL' --- -test case: valid item key type (30) -in: - type: 'ITEM_TYPE_AGGREGATE' - key: 'key1[]' -out: - return: 'SUCCEED' ---- -test case: valid item key type (31) -in: - type: 'ITEM_TYPE_AGGREGATE' - key: 'zabbix[host,,items]' -out: - return: 'SUCCEED' ---- test case: invalid item key type (32) in: type: 'ITEM_TYPE_HTTPTEST' diff --git a/tests/libs/zbxdbhigh/Makefile.am b/tests/libs/zbxdbhigh/Makefile.am index 99645864610..f5eb49f58b7 100644 --- a/tests/libs/zbxdbhigh/Makefile.am +++ b/tests/libs/zbxdbhigh/Makefile.am @@ -79,6 +79,7 @@ SERVER_COMMON_LIB = \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxdbcache/libzbxdbcache.a \ + $(top_srcdir)/src/libs/zbxeval/libzbxeval.a \ $(top_srcdir)/src/zabbix_server/availability/libavailability.a \ $(top_srcdir)/src/libs/zbxavailability/libzbxavailability.a \ $(top_srcdir)/src/libs/zbxipcservice/libzbxipcservice.a \ diff --git a/tests/libs/zbxeval/Makefile.am b/tests/libs/zbxeval/Makefile.am new file mode 100755 index 00000000000..3f62d6a9e90 --- /dev/null +++ b/tests/libs/zbxeval/Makefile.am @@ -0,0 +1,216 @@ +if SERVER +SERVER_tests = \ + zbx_eval_parse_expression \ + zbx_eval_serialize \ + zbx_eval_compose_expression \ + zbx_eval_execute \ + zbx_eval_execute_ext \ + zbx_eval_get_constant \ + zbx_eval_prepare_filter \ + zbx_eval_get_group_filter \ + zbx_eval_parse_query +endif + +noinst_PROGRAMS = $(SERVER_tests) + +if SERVER +COMMON_SRC_FILES = \ + ../../zbxmocktest.h + +COMMON_LIB_FILES = \ + $(top_srcdir)/src/zabbix_server/alerter/libzbxalerter.a \ + $(top_srcdir)/src/zabbix_server/dbsyncer/libzbxdbsyncer.a \ + $(top_srcdir)/src/zabbix_server/dbconfig/libzbxdbconfig.a \ + $(top_srcdir)/src/zabbix_server/discoverer/libzbxdiscoverer.a \ + $(top_srcdir)/src/zabbix_server/pinger/libzbxpinger.a \ + $(top_srcdir)/src/zabbix_server/poller/libzbxpoller.a \ + $(top_srcdir)/src/zabbix_server/housekeeper/libzbxhousekeeper.a \ + $(top_srcdir)/src/zabbix_server/timer/libzbxtimer.a \ + $(top_srcdir)/src/zabbix_server/trapper/libzbxtrapper.a \ + $(top_srcdir)/src/zabbix_server/snmptrapper/libzbxsnmptrapper.a \ + $(top_srcdir)/src/zabbix_server/httppoller/libzbxhttppoller.a \ + $(top_srcdir)/src/zabbix_server/escalator/libzbxescalator.a \ + $(top_srcdir)/src/zabbix_server/proxypoller/libzbxproxypoller.a \ + $(top_srcdir)/src/zabbix_server/selfmon/libzbxselfmon.a \ + $(top_srcdir)/src/zabbix_server/vmware/libzbxvmware.a \ + $(top_srcdir)/src/zabbix_server/taskmanager/libzbxtaskmanager.a \ + $(top_srcdir)/src/zabbix_server/ipmi/libipmi.a \ + $(top_srcdir)/src/zabbix_server/odbc/libzbxodbc.a \ + $(top_srcdir)/src/zabbix_server/scripts/libzbxscripts.a \ + $(top_srcdir)/src/zabbix_server/preprocessor/libpreprocessor.a \ + $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \ + $(top_srcdir)/src/libs/zbxdbcache/libzbxdbcache.a \ + $(top_srcdir)/src/libs/zbxeval/libzbxeval.a \ + $(top_srcdir)/src/libs/zbxtrends/libzbxtrends.a \ + $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ + $(top_srcdir)/src/libs/zbxmemory/libzbxmemory.a \ + $(top_srcdir)/src/libs/zbxself/libzbxself.a \ + $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ + $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ + $(top_srcdir)/src/libs/zbxconf/libzbxconf.a \ + $(top_srcdir)/src/libs/zbxmedia/libzbxmedia.a \ + $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \ + $(top_srcdir)/src/zabbix_server/availability/libavailability.a \ + $(top_srcdir)/src/libs/zbxavailability/libzbxavailability.a \ + $(top_srcdir)/src/libs/zbxipcservice/libzbxipcservice.a \ + $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ + $(top_srcdir)/src/libs/zbxnix/libzbxnix.a \ + $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \ + $(top_srcdir)/src/libs/zbxcomms/libzbxcomms.a \ + $(top_srcdir)/src/libs/zbxcompress/libzbxcompress.a \ + $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ + $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ + $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \ + $(top_srcdir)/src/libs/zbxcommshigh/libzbxcommshigh.a \ + $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \ + $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ + $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a \ + $(top_srcdir)/src/libs/zbxipcservice/libzbxipcservice.a \ + $(top_srcdir)/src/libs/zbxexec/libzbxexec.a \ + $(top_srcdir)/src/libs/zbxicmpping/libzbxicmpping.a \ + $(top_srcdir)/src/libs/zbxdbupgrade/libzbxdbupgrade.a \ + $(top_srcdir)/src/libs/zbxdbhigh/libzbxdbhigh.a \ + $(top_srcdir)/src/libs/zbxdb/libzbxdb.a \ + $(top_srcdir)/src/libs/zbxmodules/libzbxmodules.a \ + $(top_srcdir)/src/libs/zbxtasks/libzbxtasks.a \ + $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \ + $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ + $(top_srcdir)/src/libs/zbxconf/libzbxconf.a \ + $(top_srcdir)/src/libs/zbxhistory/libzbxhistory.a \ + $(top_srcdir)/src/zabbix_server/libzbxserver.a \ + $(top_srcdir)/tests/libzbxmocktest.a \ + $(top_srcdir)/tests/libzbxmockdata.a \ + $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ + $(top_srcdir)/src/libs/zbxdbhigh/libzbxdbhigh.a \ + $(top_srcdir)/src/libs/zbxvault/libzbxvault.a \ + $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a + +COMMON_COMPILER_FLAGS = -I@top_srcdir@/tests + +zbx_eval_parse_expression_SOURCES = \ + zbx_eval_parse_expression.c \ + mock_eval.c mock_eval.h + +zbx_eval_parse_expression_LDADD = \ + $(COMMON_LIB_FILES) + +zbx_eval_parse_expression_LDADD += @SERVER_LIBS@ + +zbx_eval_parse_expression_LDFLAGS = @SERVER_LDFLAGS@ + +zbx_eval_parse_expression_CFLAGS = $(COMMON_COMPILER_FLAGS) + + +zbx_eval_serialize_SOURCES = \ + zbx_eval_serialize.c + +zbx_eval_serialize_LDADD = \ + $(COMMON_LIB_FILES) + +zbx_eval_serialize_LDADD += @SERVER_LIBS@ + +zbx_eval_serialize_LDFLAGS = @SERVER_LDFLAGS@ + +zbx_eval_serialize_CFLAGS = $(COMMON_COMPILER_FLAGS) + + +zbx_eval_compose_expression_SOURCES = \ + zbx_eval_compose_expression.c \ + mock_eval.c mock_eval.h + +zbx_eval_compose_expression_LDADD = \ + $(COMMON_LIB_FILES) + +zbx_eval_compose_expression_LDADD += @SERVER_LIBS@ + +zbx_eval_compose_expression_LDFLAGS = @SERVER_LDFLAGS@ + +zbx_eval_compose_expression_CFLAGS = $(COMMON_COMPILER_FLAGS) + + +zbx_eval_execute_SOURCES = \ + zbx_eval_execute.c \ + mock_eval.c mock_eval.h + +zbx_eval_execute_LDADD = \ + $(COMMON_LIB_FILES) + +zbx_eval_execute_LDADD += @SERVER_LIBS@ + +zbx_eval_execute_LDFLAGS = @SERVER_LDFLAGS@ + +zbx_eval_execute_CFLAGS = $(COMMON_COMPILER_FLAGS) + + +zbx_eval_execute_ext_SOURCES = \ + zbx_eval_execute_ext.c \ + mock_eval.c mock_eval.h + +zbx_eval_execute_ext_LDADD = \ + $(COMMON_LIB_FILES) + +zbx_eval_execute_ext_LDADD += @SERVER_LIBS@ + +zbx_eval_execute_ext_LDFLAGS = @SERVER_LDFLAGS@ + +zbx_eval_execute_ext_CFLAGS = $(COMMON_COMPILER_FLAGS) + + +zbx_eval_get_constant_SOURCES = \ + zbx_eval_get_constant.c \ + mock_eval.c mock_eval.h + +zbx_eval_get_constant_LDADD = \ + $(COMMON_LIB_FILES) + +zbx_eval_get_constant_LDADD += @SERVER_LIBS@ + +zbx_eval_get_constant_LDFLAGS = @SERVER_LDFLAGS@ + +zbx_eval_get_constant_CFLAGS = $(COMMON_COMPILER_FLAGS) + + +zbx_eval_prepare_filter_SOURCES = \ + zbx_eval_prepare_filter.c \ + mock_eval.c mock_eval.h + +zbx_eval_prepare_filter_LDADD = \ + $(COMMON_LIB_FILES) + +zbx_eval_prepare_filter_LDADD += @SERVER_LIBS@ + +zbx_eval_prepare_filter_LDFLAGS = @SERVER_LDFLAGS@ + +zbx_eval_prepare_filter_CFLAGS = $(COMMON_COMPILER_FLAGS) + + +zbx_eval_get_group_filter_SOURCES = \ + zbx_eval_get_group_filter.c \ + mock_eval.c mock_eval.h + +zbx_eval_get_group_filter_LDADD = \ + $(COMMON_LIB_FILES) + +zbx_eval_get_group_filter_LDADD += @SERVER_LIBS@ + +zbx_eval_get_group_filter_LDFLAGS = @SERVER_LDFLAGS@ + +zbx_eval_get_group_filter_CFLAGS = $(COMMON_COMPILER_FLAGS) + + +zbx_eval_parse_query_SOURCES = \ + zbx_eval_parse_query.c \ + mock_eval.c mock_eval.h + +zbx_eval_parse_query_LDADD = \ + $(COMMON_LIB_FILES) + +zbx_eval_parse_query_LDADD += @SERVER_LIBS@ + +zbx_eval_parse_query_LDFLAGS = @SERVER_LDFLAGS@ + +zbx_eval_parse_query_CFLAGS = $(COMMON_COMPILER_FLAGS) +endif + diff --git a/tests/libs/zbxeval/mock_eval.c b/tests/libs/zbxeval/mock_eval.c new file mode 100644 index 00000000000..d47cdafb909 --- /dev/null +++ b/tests/libs/zbxeval/mock_eval.c @@ -0,0 +1,329 @@ +/* +** Zabbix +** Copyright (C) 2001-2020 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 "zbxserver.h" +#include "zbxvariant.h" +#include "mock_eval.h" + +zbx_uint64_t mock_eval_read_rules(const char *path) +{ + zbx_uint64_t rules = 0; + zbx_mock_handle_t hrules, hflag; + zbx_mock_error_t err; + int rules_num = 0; + + hrules = zbx_mock_get_parameter_handle(path); + while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(hrules, &hflag)))) + { + const char *flag; + + if (ZBX_MOCK_SUCCESS != err || ZBX_MOCK_SUCCESS != (err = zbx_mock_string(hflag, &flag))) + fail_msg("Cannot read flag #%d: %s", rules_num, zbx_mock_error_string(err)); + + if (0 == strcmp(flag, "ZBX_EVAL_PARSE_FUNCTIONID")) + rules |= ZBX_EVAL_PARSE_FUNCTIONID; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_FUNCTION")) + rules |= ZBX_EVAL_PARSE_FUNCTION; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_ITEM_QUERY")) + rules |= ZBX_EVAL_PARSE_ITEM_QUERY; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_MACRO")) + rules |= ZBX_EVAL_PARSE_MACRO; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_USERMACRO")) + rules |= ZBX_EVAL_PARSE_USERMACRO; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_LLDMACRO")) + rules |= ZBX_EVAL_PARSE_LLDMACRO; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_CONST_INDEX")) + rules |= ZBX_EVAL_PARSE_CONST_INDEX; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_MATH")) + rules |= ZBX_EVAL_PARSE_MATH; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_COMPARE_EQ")) + rules |= ZBX_EVAL_PARSE_COMPARE_EQ; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_LOGIC")) + rules |= ZBX_EVAL_PARSE_LOGIC; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_VAR_NUM")) + rules |= ZBX_EVAL_PARSE_VAR_NUM; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_VAR_STR")) + rules |= ZBX_EVAL_PARSE_VAR_STR; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_GROUP")) + rules |= ZBX_EVAL_PARSE_GROUP; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_PROP_TAG")) + rules |= ZBX_EVAL_PARSE_PROP_TAG; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_PROP_GROUP")) + rules |= ZBX_EVAL_PARSE_PROP_GROUP; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_COMPARE")) + rules |= ZBX_EVAL_PARSE_COMPARE; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_VAR")) + rules |= ZBX_EVAL_PARSE_VAR; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_PROPERTY")) + rules |= ZBX_EVAL_PARSE_PROPERTY; + else if (0 == strcmp(flag, "ZBX_EVAL_COMPOSE_LLD")) + rules |= ZBX_EVAL_COMPOSE_LLD; + else if (0 == strcmp(flag, "ZBX_EVAL_COMPOSE_FUNCTIONID")) + rules |= ZBX_EVAL_COMPOSE_FUNCTIONID; + else if (0 == strcmp(flag, "ZBX_EVAL_PROCESS_ERROR")) + rules |= ZBX_EVAL_PROCESS_ERROR; + else if (0 == strcmp(flag, "ZBX_EVAL_PARSE_COMPOUND_CONST")) + rules |= ZBX_EVAL_PARSE_COMPOUND_CONST; + else + fail_msg("Unsupported flag: %s", flag); + + rules_num++; + } + + return rules; +} + +void mock_eval_read_values(zbx_eval_context_t *ctx, const char *path) +{ + zbx_mock_handle_t htokens, htoken, hdata; + zbx_mock_error_t err; + + if (ZBX_MOCK_SUCCESS != zbx_mock_parameter(path, &htokens)) + return; + + while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(htokens, &htoken)))) + { + const char *data, *value = NULL, *error = NULL; + int i; + size_t data_len; + + if (ZBX_MOCK_SUCCESS != err) + fail_msg("cannot read token contents"); + + data = zbx_mock_get_object_member_string(htoken, "token"); + if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(htoken, "value", &hdata)) + { + if (ZBX_MOCK_SUCCESS != zbx_mock_string(hdata, &value)) + fail_msg("invalid token value"); + } + else if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(htoken, "error", &hdata)) + { + if (ZBX_MOCK_SUCCESS != zbx_mock_string(hdata, &error)) + fail_msg("invalid token error"); + } + else + fail_msg("invalid token contents"); + + data_len = strlen(data); + + for (i = 0; i < ctx->stack.values_num; i++) + { + zbx_eval_token_t *token = &ctx->stack.values[i]; + + if (data_len == token->loc.r - token->loc.l + 1 && + 0 == memcmp(data, ctx->expression + token->loc.l, data_len)) + { + if (NULL != value) + zbx_variant_set_str(&token->value, zbx_strdup(NULL, value)); + else + zbx_variant_set_error(&token->value, zbx_strdup(NULL, error)); + break; + } + } + } +} + +static const char *mock_token_type2str(zbx_uint32_t type) +{ +#define ZBX_MOCK_TOKEN_CASE(x) case ZBX_EVAL_TOKEN_##x: return "ZBX_EVAL_TOKEN_" #x; + + switch(type) + { + ZBX_MOCK_TOKEN_CASE(OP_ADD) + ZBX_MOCK_TOKEN_CASE(OP_SUB) + ZBX_MOCK_TOKEN_CASE(OP_MUL) + ZBX_MOCK_TOKEN_CASE(OP_DIV) + ZBX_MOCK_TOKEN_CASE(OP_MINUS) + ZBX_MOCK_TOKEN_CASE(OP_EQ) + ZBX_MOCK_TOKEN_CASE(OP_LT) + ZBX_MOCK_TOKEN_CASE(OP_GT) + ZBX_MOCK_TOKEN_CASE(OP_LE) + ZBX_MOCK_TOKEN_CASE(OP_GE) + ZBX_MOCK_TOKEN_CASE(OP_NE) + ZBX_MOCK_TOKEN_CASE(OP_AND) + ZBX_MOCK_TOKEN_CASE(OP_OR) + ZBX_MOCK_TOKEN_CASE(OP_NOT) + ZBX_MOCK_TOKEN_CASE(VAR_NUM) + ZBX_MOCK_TOKEN_CASE(VAR_STR) + ZBX_MOCK_TOKEN_CASE(VAR_MACRO) + ZBX_MOCK_TOKEN_CASE(VAR_USERMACRO) + ZBX_MOCK_TOKEN_CASE(VAR_LLDMACRO) + ZBX_MOCK_TOKEN_CASE(FUNCTIONID) + ZBX_MOCK_TOKEN_CASE(FUNCTION) + ZBX_MOCK_TOKEN_CASE(HIST_FUNCTION) + ZBX_MOCK_TOKEN_CASE(GROUP_OPEN) + ZBX_MOCK_TOKEN_CASE(GROUP_CLOSE) + ZBX_MOCK_TOKEN_CASE(COMMA) + ZBX_MOCK_TOKEN_CASE(ARG_QUERY) + ZBX_MOCK_TOKEN_CASE(ARG_PERIOD) + ZBX_MOCK_TOKEN_CASE(ARG_NULL) + ZBX_MOCK_TOKEN_CASE(PROP_TAG) + ZBX_MOCK_TOKEN_CASE(PROP_GROUP) + ZBX_MOCK_TOKEN_CASE(NOP) + } + + fail_msg("unknown token type: %d", type); + return NULL; + +#undef ZBX_MOCK_TOKEN_CASE +} + +static zbx_uint32_t mock_token_str2type(const char *str) +{ +#define ZBX_MOCK_TOKEN_IF(x) if (0 == strcmp(str, "ZBX_EVAL_TOKEN_" #x)) return ZBX_EVAL_TOKEN_##x; + + ZBX_MOCK_TOKEN_IF(OP_ADD) + ZBX_MOCK_TOKEN_IF(OP_SUB) + ZBX_MOCK_TOKEN_IF(OP_MUL) + ZBX_MOCK_TOKEN_IF(OP_DIV) + ZBX_MOCK_TOKEN_IF(OP_MINUS) + ZBX_MOCK_TOKEN_IF(OP_EQ) + ZBX_MOCK_TOKEN_IF(OP_LT) + ZBX_MOCK_TOKEN_IF(OP_GT) + ZBX_MOCK_TOKEN_IF(OP_LE) + ZBX_MOCK_TOKEN_IF(OP_GE) + ZBX_MOCK_TOKEN_IF(OP_NE) + ZBX_MOCK_TOKEN_IF(OP_AND) + ZBX_MOCK_TOKEN_IF(OP_OR) + ZBX_MOCK_TOKEN_IF(OP_NOT) + ZBX_MOCK_TOKEN_IF(VAR_NUM) + ZBX_MOCK_TOKEN_IF(VAR_STR) + ZBX_MOCK_TOKEN_IF(VAR_MACRO) + ZBX_MOCK_TOKEN_IF(VAR_USERMACRO) + ZBX_MOCK_TOKEN_IF(VAR_LLDMACRO) + ZBX_MOCK_TOKEN_IF(FUNCTIONID) + ZBX_MOCK_TOKEN_IF(FUNCTION) + ZBX_MOCK_TOKEN_IF(HIST_FUNCTION) + ZBX_MOCK_TOKEN_IF(GROUP_OPEN) + ZBX_MOCK_TOKEN_IF(GROUP_CLOSE) + ZBX_MOCK_TOKEN_IF(COMMA) + ZBX_MOCK_TOKEN_IF(ARG_QUERY) + ZBX_MOCK_TOKEN_IF(ARG_PERIOD) + ZBX_MOCK_TOKEN_IF(ARG_NULL) + ZBX_MOCK_TOKEN_IF(PROP_TAG) + ZBX_MOCK_TOKEN_IF(PROP_GROUP) + ZBX_MOCK_TOKEN_IF(NOP) + + fail_msg("unknown token type %s", str); + return 0; + +#undef ZBX_MOCK_TOKEN_IF +} + +void mock_compare_stack(const zbx_eval_context_t *ctx, const char *path) +{ + int token_num = 0, len; + zbx_mock_handle_t htokens, htoken; + zbx_mock_error_t err; + zbx_uint32_t expected_type, expected_opt; + const char *expected_token; + const zbx_eval_token_t *token; + + htokens = zbx_mock_get_parameter_handle(path); + while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(htokens, &htoken)))) + { + if (ZBX_MOCK_SUCCESS != err) + fail_msg("cannot read token #%d: %s", token_num, zbx_mock_error_string(err)); + + if (token_num == ctx->stack.values_num) + { + mock_dump_stack(ctx); + fail_msg("expected more than %d tokens", token_num); + } + + token = &ctx->stack.values[token_num++]; + + expected_type = mock_token_str2type(zbx_mock_get_object_member_string(htoken, "type")); + expected_token = zbx_mock_get_object_member_string(htoken, "token"); + expected_opt = (zbx_uint32_t)zbx_mock_get_object_member_uint64(htoken, "opt"); + + if (expected_type != token->type) + { + mock_dump_stack(ctx); + fail_msg( "expected token #%d type %s while got %s", token_num, + mock_token_type2str(expected_type), mock_token_type2str(token->type)); + } + + if (ZBX_EVAL_TOKEN_NOP == token->type) + continue; + + if (expected_opt != token->opt) + { + mock_dump_stack(ctx); + fail_msg("expected token optional data %d while got %d", expected_opt, token->opt); + } + + len = token->loc.r - token->loc.l + 1; + if (ZBX_EVAL_TOKEN_ARG_NULL != token->type && + 0 != strncmp(expected_token, ctx->expression + token->loc.l, len)) + { + mock_dump_stack(ctx); + fail_msg("expected token %s while got %.*s", expected_token, len, + ctx->expression + token->loc.l); + } + } + + if (token_num != ctx->stack.values_num) + { + mock_dump_stack(ctx); + fail_msg("expected %d tokens while got more", token_num); + } +} + + +static void dump_token(const zbx_eval_context_t *ctx, const zbx_eval_token_t *token) +{ + if (ZBX_EVAL_TOKEN_ARG_NULL == token->type) + { + printf("\t(null)"); + } + if (ZBX_EVAL_TOKEN_OP_MINUS == token->type) + { + printf("\t'-'"); + } + if (ZBX_EVAL_TOKEN_NOP == token->type) + { + printf("\t'.'"); + } + else + { + if (ZBX_VARIANT_NONE == token->value.type) + printf("\t%.*s", (int)(token->loc.r - token->loc.l + 1), ctx->expression + token->loc.l); + else + printf("\t'%s'", zbx_variant_value_desc(&token->value)); + } + + printf(" : %s (%d)\n", mock_token_type2str(token->type), token->opt); +} + +void mock_dump_stack(const zbx_eval_context_t *ctx) +{ + int i; + + printf("STACK:\n"); + + for (i = 0; i < ctx->stack.values_num; i++) + dump_token(ctx, &ctx->stack.values[i]); +} diff --git a/tests/libs/zbxeval/mock_eval.h b/tests/libs/zbxeval/mock_eval.h new file mode 100644 index 00000000000..2ecf4ae59ac --- /dev/null +++ b/tests/libs/zbxeval/mock_eval.h @@ -0,0 +1,31 @@ +/* +** Zabbix +** Copyright (C) 2001-2020 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" + +#ifndef ZABBIX_MOCK_EXPRESSION_EVAL_H +#define ZABBIX_MOCK_EXPRESSION_EVAL_H + +zbx_uint64_t mock_eval_read_rules(const char *path); +void mock_eval_read_values(zbx_eval_context_t *ctx, const char *path); + +void mock_compare_stack(const zbx_eval_context_t *ctx, const char *path); +void mock_dump_stack(const zbx_eval_context_t *ctx); + +#endif diff --git a/tests/libs/zbxeval/zbx_eval_compose_expression.c b/tests/libs/zbxeval/zbx_eval_compose_expression.c new file mode 100644 index 00000000000..352d0e2fc6c --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_compose_expression.c @@ -0,0 +1,87 @@ +/* +** Zabbix +** Copyright (C) 2001-2020 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 "zbxeval.h" +#include "mock_eval.h" + +static void replace_values(zbx_eval_context_t *ctx, const char *path) +{ + zbx_mock_handle_t htokens, htoken; + zbx_mock_error_t err; + + htokens = zbx_mock_get_parameter_handle(path); + + while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(htokens, &htoken)))) + { + const char *data, *value; + int i; + size_t data_len; + + if (ZBX_MOCK_SUCCESS != err) + fail_msg("cannot read token value"); + + data = zbx_mock_get_object_member_string(htoken, "token"); + value = zbx_mock_get_object_member_string(htoken, "value"); + data_len = strlen(data); + + for (i = 0; i < ctx->stack.values_num; i++) + { + zbx_eval_token_t *token = &ctx->stack.values[i]; + + if (data_len == token->loc.r - token->loc.l + 1 && + 0 == memcmp(data, ctx->expression + token->loc.l, data_len)) + { + zbx_variant_set_str(&token->value, zbx_strdup(NULL, value)); + break; + } + } + } +} + +void zbx_mock_test_entry(void **state) +{ + zbx_eval_context_t ctx; + char *error = NULL, *ret_expression = NULL; + zbx_uint64_t rules; + const char *exp_expression; + + ZBX_UNUSED(state); + + rules = mock_eval_read_rules("in.rules"); + + if (SUCCEED != zbx_eval_parse_expression(&ctx, zbx_mock_get_parameter_string("in.expression"), rules, &error)) + fail_msg("failed to parse expression: %s", error); + + replace_values(&ctx, "in.replace"); + + exp_expression = zbx_mock_get_parameter_string("out.expression"); + + zbx_eval_compose_expression(&ctx, &ret_expression); + + zbx_mock_assert_str_eq("invalid composed expression", exp_expression, ret_expression); + + zbx_free(ret_expression); + zbx_eval_clear(&ctx); +} diff --git a/tests/libs/zbxeval/zbx_eval_compose_expression.yaml b/tests/libs/zbxeval/zbx_eval_compose_expression.yaml new file mode 100644 index 00000000000..2a93a71fa29 --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_compose_expression.yaml @@ -0,0 +1,86 @@ +--- +test case: Replace '{$U} -> 10' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1 + {$U}' + replace: + - {token: '{$U}', value: 10} +out: + expression: '1 + 10' +--- +test case: Replace '{$U} -> xyz' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1 + {$U}' + replace: + - {token: '{$U}', value: 'xyz'} +out: + expression: '1 + "xyz"' +--- +test case: Replace '{$U} -> x\y/z' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1 + {$U}' + replace: + - {token: '{$U}', value: 'x\y/z'} +out: + expression: '1 + "x\\y/z"' +--- +test case: Replace '{$U} -> xyz' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'strlen({$U})' + replace: + - {token: '{$U}', value: 'xyz'} +out: + expression: 'strlen("xyz")' +--- +test case: Replace '"{$U}" -> 123' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'strlen("{$U}")' + replace: + - {token: '"{$U}"', value: '123'} +out: + expression: 'strlen("123")' +--- +test case: Replace '"{#LLD}" -> c:\data' +in: + rules: [ZBX_EVAL_PARSE_FUNCTIONID,ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_COMPOSE_LLD,ZBX_EVAL_PARSE_COMPARE] + expression: '{123} < {$LIMIT:"{#LLD}"}' + replace: + - {token: '{$LIMIT:"{#LLD}"}', value: '{$LIMIT:"c:\\data"}'} +out: + expression: '{123} < {$LIMIT:"c:\\data"}' +--- +test case: Replace '"{#U}" -> 123' +in: + rules: [ZBX_EVAL_PARSE_LLDMACRO,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_COMPOSE_LLD] + expression: 'strlen({#U})' + replace: + - {token: '{#U}', value: 'xyz'} +out: + expression: 'strlen("xyz")' +--- +test case: Replace '{123} -> {456}' +in: + rules: [ZBX_EVAL_PARSE_FUNCTIONID,ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_COMPOSE_FUNCTIONID,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_VAR] + expression: '{123} < 0' + replace: + - {token: '{123}', value: '456'} +out: + expression: '{456} < 0' +--- +test case: Replace '"{#U}" -> 1m' +in: + rules: [ZBX_EVAL_PARSE_LLDMACRO,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_COMPOSE_LLD,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_VAR] + expression: '{#U} = 60' + replace: + - {token: '{#U}', value: '1m'} +out: + expression: '1m = 60' +... + + + + diff --git a/tests/libs/zbxeval/zbx_eval_execute.c b/tests/libs/zbxeval/zbx_eval_execute.c new file mode 100644 index 00000000000..07ca3b84b2b --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_execute.c @@ -0,0 +1,87 @@ +/* +** Zabbix +** Copyright (C) 2001-2020 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 "zbxeval.h" +#include "log.h" +#include "mock_eval.h" + +void zbx_mock_test_entry(void **state) +{ + zbx_eval_context_t ctx; + char *error = NULL; + zbx_uint64_t rules; + int expected_ret, returned_ret; + zbx_variant_t value; + zbx_mock_handle_t htime; + zbx_timespec_t ts, *pts = NULL; + + ZBX_UNUSED(state); + + rules = mock_eval_read_rules("in.rules"); + expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.result")); + + if (SUCCEED != zbx_eval_parse_expression(&ctx, zbx_mock_get_parameter_string("in.expression"), rules, &error)) + { + if (SUCCEED != expected_ret) + goto out; + + fail_msg("failed to parse expression: %s", error); + } + + mock_eval_read_values(&ctx, "in.replace"); + + if (ZBX_MOCK_SUCCESS == zbx_mock_parameter("in.time", &htime)) + { + const char *str; + + if (ZBX_MOCK_SUCCESS != zbx_mock_string(htime, &str)) + fail_msg("invalid in.time field"); + + if (ZBX_MOCK_SUCCESS != zbx_strtime_to_timespec(str, &ts)) + fail_msg("Invalid in.time format"); + + if (0 != setenv("TZ", zbx_mock_get_parameter_string("in.timezone"), 1)) + fail_msg("Cannot set 'TZ' environment variable: %s", zbx_strerror(errno)); + + pts = &ts; + } + + returned_ret = zbx_eval_execute(&ctx, pts, &value, &error); + + if (SUCCEED != returned_ret) + printf("ERROR: %s\n", error); + + zbx_mock_assert_result_eq("return value", expected_ret, returned_ret); + + if (SUCCEED == expected_ret) + { + zbx_mock_assert_str_eq("output value", zbx_mock_get_parameter_string("out.value"), + zbx_variant_value_desc(&value)); + zbx_variant_clear(&value); + } +out: + zbx_free(error); + zbx_eval_clear(&ctx); +} diff --git a/tests/libs/zbxeval/zbx_eval_execute.yaml b/tests/libs/zbxeval/zbx_eval_execute.yaml new file mode 100644 index 00000000000..05ff5b75833 --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_execute.yaml @@ -0,0 +1,920 @@ +--- +test case: Expression '1 + 2 * 3' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1 + 2 * 3' +out: + result: SUCCEED + value: 7 +--- +test case: Expression '1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1' +out: + result: SUCCEED + value: 1 +--- +test case: Expression '"x\"y\"z"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '"x\"y\"z"' +out: + result: SUCCEED + value: 'x"y"z' +--- +test case: Expression '{$M}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO] + expression: '{$M}' + replace: + - {token: '{$M}', value: '2'} +out: + result: SUCCEED + value: 2 +--- +test case: Expression '{$M}' +in: + rules: [] + expression: '{$M}' + replace: + - {token: '{$M}', value: '2'} +out: + result: FAIL +--- +test case: Expression '{M}' +in: + rules: [ZBX_EVAL_PARSE_MACRO] + expression: '{M}' + replace: + - {token: '{M}', value: '3'} +out: + result: SUCCEED + value: 3 +--- +test case: Expression '{M}' +in: + rules: [] + expression: '{M}' + replace: + - {token: '{M}', value: '2'} +out: + result: FAIL +--- +test case: Expression '{123}' +in: + rules: [ZBX_EVAL_PARSE_FUNCTIONID] + expression: '{123}' + replace: + - {token: '{123}', value: '4'} +out: + result: SUCCEED + value: 4 +--- +test case: Expression '{123}' +in: + rules: [ZBX_EVAL_PARSE_FUNCTIONID] + expression: '{123}' +out: + result: FAIL +--- +test case: Expression '-1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '-1' +out: + result: SUCCEED + value: '-1' +--- +test case: Expression '--1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '--1' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '- "2"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '- "2"' +out: + result: SUCCEED + value: '-2' +--- +test case: Expression '1+2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1+2' +out: + result: SUCCEED + value: '3' +--- +test case: Expression '1-2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1-2' +out: + result: SUCCEED + value: '-1' +--- +test case: Expression '3*2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '3*2' +out: + result: SUCCEED + value: '6' +--- +test case: Expression '1/2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1/2' +out: + result: SUCCEED + value: '0.5' +--- +test case: Expression '1=1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '1=1' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '1=2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '1=2' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '"xyz"="xyz"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '"xyz"="xyz"' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '"xyz"="abc"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '"xyz"="abc"' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '1<>1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '1<>1' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '1<>2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '1<>2' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '"xyz"<>"xyz"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '"xyz"<>"xyz"' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '"xyz"<>"abc"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '"xyz"<>"abc"' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '1<2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '1<2' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '3<2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '3<2' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '1<1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '1<1' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '2>2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '2>2' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '2>1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '2>1' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '1<=2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '1<=2' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '2<=2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '2<=2' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '1<=3' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '3<=2' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '2>=1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '2>=1' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '2>=2' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '2>=2' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '2>=3' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '2>=3' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '0 or 0' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: '0 or 0' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '0 or 1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: '0 or 1' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '1 or 0' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: '1 or 0' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '1 or 1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: '1 or 1' +out: + result: SUCCEED + value: '1' +--- +test case: Expression '0 and 0' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: '0 and 0' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '0 and 1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: '0 and 1' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '1 and 0' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: '1 and 0' +out: + result: SUCCEED + value: '0' +--- +test case: Expression '1 and 1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: '1 and 1' +out: + result: SUCCEED + value: '1' +--- +test case: Expression 'not 1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: 'not 1' +out: + result: SUCCEED + value: '0' +--- +test case: Expression 'not not 1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: 'not not 1' +out: + result: SUCCEED + value: '1' +--- +test case: Expression 'not "a"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: 'not "a"' +out: + result: FAIL +--- +test case: Expression 'min(2, 1)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(2, 1)' +out: + result: SUCCEED + value: '1' +--- +test case: Expression 'min(2, 3)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(2, 3)' +out: + result: SUCCEED + value: '2' +--- +test case: Expression 'max(2, 1)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'max(2, 1)' +out: + result: SUCCEED + value: '2' +--- +test case: Expression 'max(2, 3)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'max(2, 3)' +out: + result: SUCCEED + value: '3' +--- +test case: Expression 'sum(1, 2, 3)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'sum(1, 2, 3)' +out: + result: SUCCEED + value: '6' +--- +test case: Expression 'avg(1, 2, 9)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'avg(1, 2, 9)' +out: + result: SUCCEED + value: '4' +--- +test case: Expression 'min(max(1, 3), max(2, 4))' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(max(1, 3), max(2, 4))' +out: + result: SUCCEED + value: '3' +--- +test case: Expression 'max("2", "1")' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'max("2", "1")' +out: + result: SUCCEED + value: '2' +--- +test case: Expression 'max("2", "a")' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'max("2", "a")' +out: + result: FAIL +--- +test case: Expression 'min(1 + 2, 0.5 + 1.5)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(1 + 2, 0.5 + 1.5)' +out: + result: SUCCEED + value: '2' +--- +test case: Expression '{$M} or 1' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} or 1' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: FAIL +--- +test case: Expression '{$M} or 0' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} or 0' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: FAIL +--- +test case: Expression '{$M} or 1' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} or 1' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: SUCCEED + value: 1 +--- +test case: Expression '{$M} or "a"' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} or "a"' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: FAIL +--- +test case: Expression '{$M} or 0' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} or 0' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: FAIL +--- +test case: Expression '{$M} and 1' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} and 1' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: FAIL +--- +test case: Expression '{$M} and 0' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} and 0' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: FAIL +--- +test case: Expression '{$M} and 1' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} and 1' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: FAIL +--- +test case: Expression '{$M} and 0' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} and 0' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: SUCCEED + value: 0 +--- +test case: Expression '{$M} and "a"' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M} and "a"' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: FAIL +--- +test case: Expression '{$M} + 2 or 1' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_MATH] + expression: '{$M} + 2 or 1' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: SUCCEED + value: 1 +--- +test case: Expression '{$M} + 2 and 0' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_MATH] + expression: '{$M} + 2 and 0' + replace: + - {token: '{$M}', error: 'forced operand error'} +out: + result: SUCCEED + value: 0 +--- +test case: Expression 'length("")' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'length("")' +out: + result: SUCCEED + value: '0' +--- +test case: Expression 'length("abc")' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'length("abc")' +out: + result: SUCCEED + value: '3' +--- +test case: Expression 'length(4)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'length(4)' +out: + result: SUCCEED + value: '1' +--- +test case: Expression 'length("ы")' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'length("ы")' +out: + result: SUCCEED + value: '1' +--- +test case: Expression 'length()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'length()' +out: + result: FAIL +--- +test case: Expression 'length(1, 2)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'length(1, 2)' +out: + result: FAIL +--- +test case: Expression 'abs(5)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'abs(5)' +out: + result: SUCCEED + value: '5' +--- +test case: Expression 'abs(-10)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'abs(-10)' +out: + result: SUCCEED + value: '10' +--- +test case: Expression 'abs()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'abs()' +out: + result: FAIL +--- +test case: Expression 'abs("xyz")' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'abs("xyz")' +out: + result: FAIL +--- +test case: Expression 'date(1)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'date(1)' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: FAIL +--- +test case: Expression 'date()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'date()' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: SUCCEED + value: '20200901' +--- +test case: Expression 'time(1)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'time(1)' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: FAIL +--- +test case: Expression 'time()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'time()' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: SUCCEED + value: '010203' +--- +test case: Expression 'now(1)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'now(1)' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: FAIL +--- +test case: Expression 'now()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'now()' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: SUCCEED + value: '1598911323' +--- +test case: Expression 'dayofmonth(1)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'dayofmonth(1)' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: FAIL +--- +test case: Expression 'dayofmonth()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'dayofmonth()' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: SUCCEED + value: '1' +--- +test case: Expression 'dayofweek(1)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'dayofweek(1)' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: FAIL +--- +test case: Expression 'dayofweek()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'dayofweek()' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: SUCCEED + value: '2' +--- +test case: Expression '1K' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: '1K' + timezone: :Europe/Riga + time: 2020-09-01 01:02:03 +03:00 +out: + result: SUCCEED + value: '1024' +--- +test case: Expression '3 + 4 * 2 / ( 1 - 5 )' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP] + expression: '3 + 4 * 2 / ( 1 - 5 )' +out: + result: SUCCEED + value: 1 +--- +test case: Expression '1 + 3*4 = 13' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1 + 3*4 = 13' +out: + result: SUCCEED + value: 1 +--- +test case: Expression '1 + 2*4 = 13' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1 + 2*4 = 13' +out: + result: SUCCEED + value: 0 +--- +test case: Expression '0.1+0.1 > 0.1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '0.1+0.1 > 0.1' +out: + result: SUCCEED + value: 1 +--- +test case: Expression '.1+.1 > 0.1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '.1+.1 > .1' +out: + result: SUCCEED + value: 1 +--- +test case: Expression '1m=60s' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1m=60s' +out: + result: SUCCEED + value: 1 +--- +test case: Expression '1e+309<>0' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1e+309<>0' +out: + result: FAIL + value: 1 +--- +test case: Expression '1e+309s<>0' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1e+309s<>0' +out: + result: FAIL + value: 1 +--- +test case: Expression '1e+308<>0' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1e+308<>0' +out: + result: SUCCEED + value: 1 +--- +test case: Expression '"a" and "b"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_LOGIC] + expression: '"a" and "b"' +out: + result: FAIL + value: 1 +--- +test case: Expression '1e+308K<>0' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1e+308K<>0' +out: + result: FAIL + value: 1 +--- +test case: Expression '1e+308K<>0' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1e+304K<>0' +out: + result: SUCCEED + value: 1 +--- +test case: Expression '{$M}=60' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '{$M}=60' + replace: + - {token: '{$M}', value: '1m'} +out: + result: SUCCEED + value: 1 +--- +test case: Expression '{$M}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_LOGIC] + expression: '{$M}' + replace: + - {token: '{$M}', value: '1m'} +out: + result: SUCCEED + value: 60 +--- +test case: Expression '"1" < "g"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '"1" < "g"' +out: + result: FAIL +--- +test case: Expression '"1" = "1.0"' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '"1" = "1.0"' +out: + result: SUCCEED + value: 1 +--- +test case: Expression 'min(2s, 1m)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(2s, 1m)' +out: + result: SUCCEED + value: '2' +--- +test case: Expression 'min(2s, 1m),' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(2s, 1m),' +out: + result: FAIL + value: '2' +--- +test case: Expression '-60={$M}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_COMPARE] + expression: '-60={$M}' + replace: + - {token: '{$M}', value: '-1m'} +out: + result: SUCCEED + value: 1 +--- +test case: Expression '"1m"=60s' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_COMPARE] + expression: '"1m"=60s' +out: + result: SUCCEED + value: 1 +--- +test case: Expression 'min("1m", 30s)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min("1m", 30s)' +out: + result: SUCCEED + value: '30' +... diff --git a/tests/libs/zbxeval/zbx_eval_execute_ext.c b/tests/libs/zbxeval/zbx_eval_execute_ext.c new file mode 100644 index 00000000000..0a03776c7bd --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_execute_ext.c @@ -0,0 +1,193 @@ +/* +** Zabbix +** Copyright (C) 2001-2020 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 "zbxeval.h" +#include "mock_eval.h" + +typedef struct +{ + const char *name; + int args_num; + zbx_variant_t retval; + const char *error; +} +zbx_mock_callback_t; + +zbx_vector_ptr_t callbacks; + +static void mock_callback_free(zbx_mock_callback_t *cb) +{ + zbx_variant_clear(&cb->retval); + zbx_free(cb); +} + +static void mock_read_callbacks(const char *path) +{ + zbx_mock_handle_t hcbs, hcb, hdata, hvalue; + zbx_mock_error_t err; + + if (ZBX_MOCK_SUCCESS != zbx_mock_parameter(path, &hcbs)) + return; + + while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(hcbs, &hcb)))) + { + zbx_mock_callback_t *cb; + const char *value; + + if (ZBX_MOCK_SUCCESS != err) + fail_msg("cannot read callback contents"); + + cb = (zbx_mock_callback_t *)zbx_malloc(NULL, sizeof(zbx_mock_callback_t)); + memset(cb, 0, sizeof(zbx_mock_callback_t)); + cb->name = zbx_mock_get_object_member_string(hcb, "name"); + cb->args_num = zbx_mock_get_object_member_uint64(hcb, "args_num"); + + if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(hcb, "retval", &hdata)) + { + if (ZBX_MOCK_SUCCESS == zbx_mock_string(hdata, &value)) + { + zbx_variant_set_dbl(&cb->retval, atof(value)); + } + else + { + zbx_vector_dbl_t *values; + + values = (zbx_vector_dbl_t *)zbx_malloc(NULL, sizeof(zbx_vector_dbl_t)); + zbx_vector_dbl_create(values); + + while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(hdata, &hvalue)))) + { + if (ZBX_MOCK_SUCCESS != err) + fail_msg("cannot read callback retval contents"); + + if (ZBX_MOCK_SUCCESS != zbx_mock_string(hvalue, &value)) + fail_msg("cannot read callback retval"); + + zbx_vector_dbl_append(values, atof(value)); + } + + zbx_variant_set_dbl_vector(&cb->retval, values); + } + } + else if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(hcb, "error", &hdata)) + { + if (ZBX_MOCK_SUCCESS != zbx_mock_string(hdata, &cb->error)) + fail_msg("invalid token error"); + } + else if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(hcb, "reterr", &hdata)) + { + const char *errmsg; + + if (ZBX_MOCK_SUCCESS != zbx_mock_string(hdata, &errmsg)) + fail_msg("invalid token error"); + + zbx_variant_set_error(&cb->retval, zbx_strdup(NULL, errmsg)); + } + else + fail_msg("invalid token contents"); + + zbx_vector_ptr_append(&callbacks, cb); + } +} + +static int callback_cb(const char *name, size_t len, int args_num, const zbx_variant_t *args, void *data, + const zbx_timespec_t *ts, zbx_variant_t *value, char **error) +{ + int i; + + ZBX_UNUSED(args); + ZBX_UNUSED(data); + ZBX_UNUSED(ts); + + for (i = 0; i < callbacks.values_num; i++) + { + zbx_mock_callback_t *cb = (zbx_mock_callback_t *)callbacks.values[i]; + + if (len == strlen(cb->name) && 0 == memcmp(name, cb->name, len)) + { + zbx_mock_assert_int_eq("callback argument count", cb->args_num, args_num); + if (NULL != cb->error) + { + *error = zbx_strdup(*error, cb->error); + return FAIL; + } + zbx_variant_copy(value, &cb->retval); + return SUCCEED; + } + } + *error = zbx_strdup(*error, "unknown callback"); + + return FAIL; +} + + +void zbx_mock_test_entry(void **state) +{ + zbx_eval_context_t ctx; + char *error = NULL; + zbx_uint64_t rules; + int expected_ret, returned_ret; + zbx_variant_t value; + + ZBX_UNUSED(state); + + zbx_vector_ptr_create(&callbacks); + + rules = mock_eval_read_rules("in.rules"); + expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.result")); + + if (SUCCEED != zbx_eval_parse_expression(&ctx, zbx_mock_get_parameter_string("in.expression"), rules, &error)) + { + if (SUCCEED != expected_ret) + goto out; + + fail_msg("failed to parse expression: %s", error); + } + + mock_eval_read_values(&ctx, "in.replace"); + mock_read_callbacks("in.callbacks"); + + returned_ret = zbx_eval_execute_ext(&ctx, NULL, callback_cb, callback_cb, NULL, &value, &error); + + if (SUCCEED != returned_ret) + printf("ERROR: %s\n", error); + + zbx_mock_assert_result_eq("return value", expected_ret, returned_ret); + + if (SUCCEED == expected_ret) + { + zbx_mock_assert_str_eq("output value", zbx_mock_get_parameter_string("out.value"), + zbx_variant_value_desc(&value)); + zbx_variant_clear(&value); + } + else + zbx_free(error); + +out: + zbx_free(error); + zbx_vector_ptr_clear_ext(&callbacks, (zbx_clean_func_t)mock_callback_free); + zbx_vector_ptr_destroy(&callbacks); + zbx_eval_clear(&ctx); +} diff --git a/tests/libs/zbxeval/zbx_eval_execute_ext.yaml b/tests/libs/zbxeval/zbx_eval_execute_ext.yaml new file mode 100644 index 00000000000..d769e6a2f7f --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_execute_ext.yaml @@ -0,0 +1,117 @@ +--- +test case: Expression 'forty_two()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: 'forty_two()' + callbacks: + - name: forty_two + args_num: 0 + error: 'forced function error' +out: + result: FAIL +--- +test case: Expression 'forty_two()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: 'forty_two()' + callbacks: + - name: forty_two + args_num: 0 + retval: 42s +out: + result: SUCCEED + value: 42 +--- +test case: Expression 'sum(hist(/host/key,1h))' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_ITEM_QUERY] + expression: 'sum(hist(/host/key,1h))' + callbacks: + - name: hist + args_num: 2 + retval: [1, 2, 3] +out: + result: SUCCEED + value: 6 +--- +test case: Expression 'sum(hist(/host/key,1h),0)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_VAR] + expression: 'sum(hist(/host/key,1h),0)' + callbacks: + - name: hist + args_num: 2 + retval: [1, 2, 3] +out: + result: FAIL +--- +test case: Expression 'min(err(), 1) or 1' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: 'min(err(), 1) or 1' + callbacks: + - name: err + args_num: 0 + error: 'forced return error' +out: + result: SUCCEED + value: 1 +--- +test case: Expression 'min(err(), 1) or 1' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: 'min(err(), 1) or 1' + callbacks: + - name: err + args_num: 0 + error: 'forced return error' +out: + result: FAIL +--- +test case: Expression 'min(1, 2, err()) and 0' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PROCESS_ERROR,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: 'min(1, 2, err()) and 0' + callbacks: + - name: err + args_num: 0 + error: 'forced return error' +out: + result: SUCCEED + value: 0 +--- +test case: Expression 'min(1, 2, err()) and 0' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: 'min(1, 2, err()) and 0' + callbacks: + - name: err + args_num: 0 + error: 'forced return error' +out: + result: FAIL +--- +test case: Expression 'sum(hist(/host/key,1h))' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_ITEM_QUERY] + expression: 'sum(hist(/host/key,1h))' + callbacks: + - name: hist + args_num: 2 + retval: [] +out: + result: FAIL +--- +test case: Expression 'sum(hist(/host/key,))' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_ITEM_QUERY] + expression: 'sum(hist(/host/key,))' + callbacks: + - name: hist + args_num: 2 + retval: [1, 2, 3] +out: + result: SUCCEED + value: 6 +... + diff --git a/tests/libs/zbxserver/get_trigger_expression_constant.c b/tests/libs/zbxeval/zbx_eval_get_constant.c index 60b4efbc923..f7e9a3f576a 100755 --- a/tests/libs/zbxserver/get_trigger_expression_constant.c +++ b/tests/libs/zbxeval/zbx_eval_get_constant.c @@ -30,8 +30,8 @@ void zbx_mock_test_entry(void **state) zbx_mock_handle_t param_handle; zbx_uint64_t index = 0; const char *expected_result = NULL, *expression = NULL; - char *actual_result = NULL; - zbx_token_reference_t token; + char *actual_result = NULL, *errmsg = NULL; + zbx_eval_context_t ctx; ZBX_UNUSED(state); @@ -54,10 +54,15 @@ void zbx_mock_test_entry(void **state) zbx_mock_error_string(error)); } - token.index = index; - get_trigger_expression_constant(expression, &token, &actual_result); + if (SUCCEED != zbx_eval_parse_expression(&ctx, expression, ZBX_EVAL_TRIGGER_EXPRESSION, &errmsg)) + fail_msg("Cannot parse expression: %s", errmsg); + + zbx_eval_get_constant(&ctx, index, &actual_result); + if (NULL == actual_result) + actual_result = zbx_strdup(NULL, ""); zbx_mock_assert_str_eq("Invalid result", expected_result, actual_result); zbx_free(actual_result); + zbx_eval_clear(&ctx); } diff --git a/tests/libs/zbxserver/get_trigger_expression_constant.yaml b/tests/libs/zbxeval/zbx_eval_get_constant.yaml index bb0e052964c..fac9d242909 100755 --- a/tests/libs/zbxserver/get_trigger_expression_constant.yaml +++ b/tests/libs/zbxeval/zbx_eval_get_constant.yaml @@ -1,11 +1,4 @@ --- -test case: 'extract token 0' -in: - expression: '("ccc")="ccca"' - index: 0 -out: - return: 'ccc' ---- test case: 'extract token 1' in: expression: '("ccc")="ccca"' @@ -71,7 +64,7 @@ out: --- test case: 'escape function' in: - expression: '{0286} (0)<>("-2"/1 - {2370897})' + expression: '{0286} + (0)<>("-2"/1 - {2370897})' index: 1 out: return: '0' @@ -125,13 +118,6 @@ in: out: return: '{$MACRO:"x:\"1\""}' --- -test case: 'broken user macro with context' -in: - expression: '{19928}<>{$MACRO:"x:\"1} and 1' - index: 1 -out: - return: '' ---- test case: 'fraction' in: expression: '{19928}<>.5' @@ -146,13 +132,6 @@ in: out: return: '-.5' --- -test case: 'invalid number .5.5.5' -in: - expression: '{19928}<>.5.5.5' - index: 1 -out: - return: '' ---- test case: 'constant after macro' in: expression: '{TRIGGER.VALUE}=1 and {19928}<>10' @@ -174,13 +153,6 @@ in: out: return: '1e-5' --- -test case: 'constant 1e-5.0' -in: - expression: '{19928}=1e-5.0' - index: 1 -out: - return: '' ---- test case: 'string constant -10e-10' in: expression: '{TRIGGER.VALUE}=1 and {19928}<>"-10e-10"' diff --git a/tests/libs/zbxeval/zbx_eval_get_group_filter.c b/tests/libs/zbxeval/zbx_eval_get_group_filter.c new file mode 100644 index 00000000000..267c02387b8 --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_get_group_filter.c @@ -0,0 +1,87 @@ +/* +** Zabbix +** Copyright (C) 2001-2020 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 "zbxeval.h" +#include "log.h" +#include "mock_eval.h" + +void zbx_mock_test_entry(void **state) +{ + zbx_eval_context_t ctx; + char *error = NULL, *filter = NULL; + const char *filter_exp, *group; + zbx_vector_str_t groups; + int index = 0; + zbx_mock_handle_t hgroups, hgroup; + zbx_mock_error_t err; + + ZBX_UNUSED(state); + + zbx_vector_str_create(&groups); + + if (SUCCEED != zbx_eval_parse_expression(&ctx, zbx_mock_get_parameter_string("in.expression"), + ZBX_EVAL_PARSE_QUERY_EXPRESSION, &error)) + { + fail_msg("failed to parse expression: %s", error); + } + + zbx_eval_prepare_filter(&ctx); + + if (SUCCEED != zbx_eval_get_group_filter(&ctx, &groups, &filter, &error)) + fail_msg("failed to get group filter: %s", error); + + + filter_exp = zbx_mock_get_parameter_string("out.filter"); + + if (NULL == filter) + { + if ('\0' != *filter_exp) + fail_msg("got empty filter while expected %s", filter_exp); + } + else + zbx_mock_assert_str_eq("group filter", filter_exp, filter); + + hgroups = zbx_mock_get_parameter_handle("out.groups"); + while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(hgroups, &hgroup)))) + { + if (index >= groups.values_num) + fail_msg("got %d groups while expected more", groups.values_num); + + if (ZBX_MOCK_SUCCESS != err || ZBX_MOCK_SUCCESS != (err = zbx_mock_string(hgroup, &group))) + fail_msg("Cannot read group #%d: %s", index, zbx_mock_error_string(err)); + + zbx_mock_assert_str_eq("group values", group, groups.values[index++]); + } + + if (index != groups.values_num) + fail_msg("got %d groups while expected %d", groups.values_num, index); + + zbx_vector_str_clear_ext(&groups, zbx_str_free); + zbx_vector_str_destroy(&groups); + zbx_free(filter); + + zbx_free(error); + zbx_eval_clear(&ctx); +} diff --git a/tests/libs/zbxeval/zbx_eval_get_group_filter.yaml b/tests/libs/zbxeval/zbx_eval_get_group_filter.yaml new file mode 100644 index 00000000000..0fea7eee08c --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_get_group_filter.yaml @@ -0,0 +1,99 @@ +--- +test case: Expression 'group="x"' +in: + expression: 'group="x"' +out: + groups: ['x'] + filter: '{0}' +--- +test case: Expression '"x"=group' +in: + expression: '"x"=group' +out: + groups: ['x'] + filter: '{0}' +--- +test case: Expression 'group="x" or "y"=group' +in: + expression: 'group="x" or "y"=group' +out: + groups: ['x','y'] + filter: '({0} or {1})' +--- +test case: Expression 'tag="a"' +in: + expression: 'tag="a"' +out: + groups: [] + filter: '' +--- +test case: Expression 'tag="abc" and group<>"xyz"' +in: + expression: 'tag="abc" and group<>"xyz"' +out: + groups: [xyz] + filter: 'not {0}' +--- +test case: Expression 'tag="abc" or group="xyz"' +in: + expression: 'tag="abc" or group="xyz"' +out: + groups: [] + filter: '' +--- +test case: Expression 'group="x" and tag="a" or group="y" and tag="b"' +in: + expression: 'group="x" and tag="a" or group="y" and tag="b"' +out: + groups: ['x', 'y'] + filter: '({0} or {1})' +--- +test case: Expression '(group="x" or tag="a") and (group="y" or tag="b")' +in: + expression: '(group="x" or tag="a") and (group="y" or tag="b")' +out: + groups: [] + filter: '' +--- +test case: Expression '"a" <> "b" and group="xyz"' +in: + expression: '"a" <> "b" and group="xyz"' +out: + groups: [xyz] + filter: '(("a"<>"b") and {0})' +--- +test case: Expression '"a" <> "b" and tag="abc" and group="xyz"' +in: + expression: '"a" <> "b" and tag="abc" and group="xyz"' +out: + groups: [xyz] + filter: '(("a"<>"b") and {0})' +--- +test case: Expression '"a" <> "b" or tag="abc" and group="xyz"' +in: + expression: '"a" <> "b" or tag="abc" and group="xyz"' +out: + groups: [xyz] + filter: '(("a"<>"b") or {0})' +--- +test case: Expression '(group="x") = (group="y")' +in: + expression: '(group="x") = (group="y")' +out: + groups: ['x', 'y'] + filter: '({0}={1})' +--- +test case: Expression 'group<>"abc" and group<>"xyz"' +in: + expression: 'group<>"abc" and group<>"xyz"' +out: + groups: [abc,xyz] + filter: '(not {0} and not {1})' +--- +test case: Expression '(group="Zabbix servers") or ("Zabbix servers"=group)' +in: + expression: '(group="Zabbix servers") or ("Zabbix servers"=group)' +out: + groups: [Zabbix servers,Zabbix servers] + filter: '({0} or {1})' +... diff --git a/tests/libs/zbxeval/zbx_eval_parse_expression.c b/tests/libs/zbxeval/zbx_eval_parse_expression.c new file mode 100644 index 00000000000..ecc85030e54 --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_parse_expression.c @@ -0,0 +1,53 @@ +/* +** Zabbix +** Copyright (C) 2001-2020 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 "zbxeval.h" +#include "mock_eval.h" + +void zbx_mock_test_entry(void **state) +{ + int returned_ret, expected_ret; + zbx_eval_context_t ctx; + char *error = NULL; + zbx_uint64_t rules; + + ZBX_UNUSED(state); + + rules = mock_eval_read_rules("in.rules"); + returned_ret = zbx_eval_parse_expression(&ctx, zbx_mock_get_parameter_string("in.expression"), rules, &error); + expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.result")); + if (SUCCEED != returned_ret) + printf("ERROR: %s\n", error); + else + mock_dump_stack(&ctx); + zbx_mock_assert_result_eq("return value", expected_ret, returned_ret); + + if (SUCCEED == expected_ret) + mock_compare_stack(&ctx, "out.stack"); + + zbx_eval_clear(&ctx); + zbx_free(error); + +} diff --git a/tests/libs/zbxeval/zbx_eval_parse_expression.yaml b/tests/libs/zbxeval/zbx_eval_parse_expression.yaml new file mode 100644 index 00000000000..bedecd798e8 --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_parse_expression.yaml @@ -0,0 +1,1778 @@ +--- +test case: Fail '' +in: + rules: [] + expression: '' +out: + result: FAIL +--- # numeric variables +test case: Succeed '0' +in: + rules: [ZBX_EVAL_PARSE_VAR_NUM] + expression: '0' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '0' + opt: 0 + result: SUCCEED +--- +test case: Fail (no rules) '0' +in: + rules: [] + expression: '0' +out: + result: FAIL +--- +test case: Succeed '0.1' +in: + rules: [ZBX_EVAL_PARSE_VAR_NUM] + expression: '0.1' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '0.1' + opt: 0 + result: SUCCEED +--- +test case: Succeed '1s' +in: + rules: [ZBX_EVAL_PARSE_VAR_NUM] + expression: '1s' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '1s' + opt: 0 + result: SUCCEED +--- +test case: FAIL 's' +in: + rules: [] + expression: 's' +out: + result: FAIL +--- +test case: Succeed '.1' +in: + rules: [ZBX_EVAL_PARSE_VAR_NUM] + expression: '.1' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '.1' + opt: 0 + result: SUCCEED +--- +test case: Succeed '1.' +in: + rules: [ZBX_EVAL_PARSE_VAR_NUM] + expression: '1.' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '1.' + opt: 0 + result: SUCCEED +--- +test case: Fail '1.1.' +in: + rules: [ZBX_EVAL_PARSE_VAR_NUM] + expression: '1.1.' +out: + result: FAIL +--- +test case: Succeed '1e10' +in: + rules: [ZBX_EVAL_PARSE_VAR_NUM] + expression: '1e10' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '1e10' + opt: 0 + result: SUCCEED +--- +test case: Fail '1e1000' +in: + rules: [ZBX_EVAL_PARSE_VAR_NUM] + expression: '1e1000' +out: + result: FAIL +--- # string variables +test case: Succeed '"xyz"' +in: + rules: [ZBX_EVAL_PARSE_VAR_STR] + expression: '"xyz"' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_STR + token: '"xyz"' + opt: 0 + result: SUCCEED +--- +test case: Fail (no rules) '"xyz"' +in: + rules: [] + expression: '"xyz"' +out: + result: FAIL +--- +test case: Succeed '"x\\\"y\"z/"' +in: + rules: [ZBX_EVAL_PARSE_VAR_STR] + expression: '"x\\\"y\"z/"' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_STR + token: '"x\\\"y\"z/"' + opt: 0 + result: SUCCEED +--- +test case: Fail '"x\yz"' +in: + rules: [ZBX_EVAL_PARSE_VAR_STR] + expression: '"x\yz"' +out: + result: FAIL +--- +test case: Succeed '""' +in: + rules: [ZBX_EVAL_PARSE_VAR_STR] + expression: '""' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_STR + token: '""' + opt: 0 + result: SUCCEED +--- +test case: Fail '"xyz' +in: + rules: [ZBX_EVAL_PARSE_VAR_STR] + expression: '"xyz' +out: + result: FAIL +--- +test case: Fail '"xyz\"' +in: + rules: [ZBX_EVAL_PARSE_VAR_STR] + expression: '"xyz\"' +out: + result: FAIL +--- # functionid +test case: Succeed '{1}' +in: + rules: [ZBX_EVAL_PARSE_FUNCTIONID] + expression: '{1}' +out: + stack: + - type: ZBX_EVAL_TOKEN_FUNCTIONID + token: '{1}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{1}' +in: + rules: [ZBX_EVAL_PARSE_MACRO] + expression: '{1}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_MACRO + token: '{1}' + opt: 0 + result: SUCCEED +--- +test case: Fail '{1}' +in: + rules: [] + expression: '{1}' +out: + result: FAIL +--- # macros +test case: Succeed '{MACRO}' +in: + rules: [ZBX_EVAL_PARSE_MACRO] + expression: '{MACRO}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_MACRO + token: '{MACRO}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{{MACRO}.func()}' +in: + rules: [ZBX_EVAL_PARSE_MACRO] + expression: '{{MACRO}.func()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_MACRO + token: '{{MACRO}.func()}' + opt: 0 + result: SUCCEED +--- # user macros +test case: Succeed '{$MACRO}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO] + expression: '{$MACRO}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_USERMACRO + token: '{$MACRO}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{$MACRO:context}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO] + expression: '{$MACRO:context}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_USERMACRO + token: '{$MACRO:context}' + opt: 0 + result: SUCCEED +--- +test case: Fail '{$MACRO:context' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO] + expression: '{$MACRO:context' +out: + result: FAIL +--- +test case: Succeed '{$MACRO:"context:\"context\""}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO] + expression: '{$MACRO:"context:\"context\""}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_USERMACRO + token: '{$MACRO:"context:\"context\""}' + opt: 0 + result: SUCCEED +--- +test case: Fail '{$MACRO:"context:\"context\"}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO] + expression: '{$MACRO:"context:\"context\"}' +out: + result: FAIL +--- +test case: Fail '{$MACRO}1' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_VAR_NUM] + expression: '{$MACRO}1' +out: + result: FAIL +--- +test case: Succeed '{$MACRO}1' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_VAR_NUM] + expression: '{$MACRO}1' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{$MACRO}1' + opt: 0 + result: SUCCEED +--- +test case: Succeed '1{$MACRO}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_VAR_NUM] + expression: '1{$MACRO}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '1{$MACRO}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{$USER}{$MACRO}' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_VAR_NUM] + expression: '{$USER}{$MACRO}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{$USER}{$MACRO}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{$MACRO}s' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_VAR_NUM] + expression: '{$MACRO}s' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{$MACRO}s' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{$MACRO}x' +in: + rules: [ZBX_EVAL_PARSE_USERMACRO,ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_VAR_NUM] + expression: '{$MACRO}x' +out: + result: FAIL +--- # LLD macros +test case: Succeed '{#LLD}' +in: + rules: [ZBX_EVAL_PARSE_LLDMACRO] + expression: '{#LLD}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_LLDMACRO + token: '{#LLD}' + opt: 0 + result: SUCCEED +--- +test case: Fail '{#LLD}' +in: + rules: [] + expression: '{#LLD}' +out: + result: FAIL +--- +test case: Fail '{#LLD' +in: + rules: [ZBX_EVAL_PARSE_LLDMACRO] + expression: '{#LLD' +out: + result: FAIL +--- +test case: Succeed '{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_LLDMACRO] + expression: '{{#LLD}.function()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_LLDMACRO + token: '{{#LLD}.function()}}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '1{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO,ZBX_EVAL_PARSE_VAR_NUM] + expression: '1{{#LLD}.function()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '1{{#LLD}.function()}}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '.{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO,ZBX_EVAL_PARSE_VAR_NUM] + expression: '.{{#LLD}.function()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '.{{#LLD}.function()}}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{{#LLD}.function()}.{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO,ZBX_EVAL_PARSE_VAR_NUM] + expression: '{{#LLD}.function()}.{{#LLD}.function()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{{#LLD}.function()}.{{#LLD}.function()}}' + opt: 0 + result: SUCCEED +--- +test case: Succeed '{{#LLD}.function()}e{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO,ZBX_EVAL_PARSE_VAR_NUM] + expression: '{{#LLD}.function()}e{{#LLD}.function()}' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '{{#LLD}.function()}e{{#LLD}.function()}}' + opt: 0 + result: SUCCEED +--- +test case: Succeed 'e{{#LLD}.function()}' +in: + rules: [ZBX_EVAL_PARSE_COMPOUND_CONST,ZBX_EVAL_PARSE_LLDMACRO,ZBX_EVAL_PARSE_VAR_NUM] + expression: 'e{{#LLD}.function()}' +out: + result: FAIL +--- # parenthesis +test case: Fail '()' +in: + rules: [ZBX_EVAL_PARSE_GROUP] + expression: '()' +out: + result: FAIL +--- +test case: Succeed '(0)' +in: + rules: [ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: '(0)' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '0' + opt: 0 + result: SUCCEED +--- +test case: Fail '(0' +in: + rules: [ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: '(0' +out: + result: FAIL +--- +test case: Fail '0)' +in: + rules: [ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: '0)' +out: + result: FAIL +--- +test case: Succeed '((0))' +in: + rules: [ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: '((0))' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '0', opt: 0} + result: SUCCEED +--- # unary minus operations +test case: Fail '-' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '-' +out: + result: FAIL +--- +test case: Succeed '-1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '-1' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '-1', opt: 0} + result: SUCCEED +--- +test case: Succeed '-(1)' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP] + expression: '-(1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MINUS, token: '-', opt: 0} + result: SUCCEED +--- +test case: Succeed '-{MACRO}' +in: + rules: [ZBX_EVAL_PARSE_MACRO,ZBX_EVAL_PARSE_MATH] + expression: '-{MACRO}' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_MACRO, token: '{MACRO}', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MINUS, token: '-', opt: 0} + result: SUCCEED +--- +test case: Succeed '--1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '--1' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '-1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MINUS, token: '-', opt: 0} + result: SUCCEED +--- +test case: Succeed '- - 1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '- - 1' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MINUS, token: '-', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MINUS, token: '-', opt: 0} + result: SUCCEED +--- +test case: Succeed '-(-1)' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP] + expression: '-(-1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '-1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MINUS, token: '-', opt: 0} + result: SUCCEED +--- # arithmetic operations +test case: Fail '+' +in: + rules: [ZBX_EVAL_PARSE_MATH] + expression: '+' +out: + result: FAIL +--- +test case: Fail '-' +in: + rules: [ZBX_EVAL_PARSE_MATH] + expression: '-' +out: + result: FAIL +--- +test case: Fail '/' +in: + rules: [ZBX_EVAL_PARSE_MATH] + expression: '/' +out: + result: FAIL +--- +test case: Fail '*' +in: + rules: [ZBX_EVAL_PARSE_MATH] + expression: '*' +out: + result: FAIL +--- +test case: Fail '1+' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1+' +out: + result: FAIL +--- +test case: Fail '1-' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1-' +out: + result: FAIL +--- +test case: Fail '1/' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1/' +out: + result: FAIL +--- +test case: Fail '1*' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1*' +out: + result: FAIL +--- +test case: Fail '+1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '+1' +out: + result: FAIL +--- +test case: Fail '/1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '/1' +out: + result: FAIL +--- +test case: Fail '*1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '*1' +out: + result: FAIL +--- +test case: Succeed '1+2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1+2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Succeed '1+2-3' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1+2-3' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_SUB, token: '-', opt: 0} + result: SUCCEED +--- +test case: Succeed '1-2+3' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1-2+3' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_SUB, token: '-', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Fail '2**1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '2**1' +out: + result: FAIL +--- +test case: Fail '2++1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '2++1' +out: + result: FAIL +--- +test case: Fail '2//1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '2//1' +out: + result: FAIL +--- +test case: Succeed '2--1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '2--1' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '-1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_SUB, token: '-', opt: 0} + result: SUCCEED +--- +test case: Succeed '1+2*3' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1+2*3' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MUL, token: '*', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Succeed '1*2+3' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1*2+3' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MUL, token: '*', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Succeed '1+2*3-4' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1+2*3-4' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MUL, token: '*', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_SUB, token: '-', opt: 0} + result: SUCCEED +--- +test case: Succeed '1/2+3*4' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: '1/2+3*4' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_DIV, token: '/', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MUL, token: '*', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Succeed '1/(2+3)*4' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP] + expression: '1/(2+3)*4' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_DIV, token: '/', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MUL, token: '*', opt: 0} + result: SUCCEED +--- +test case: Succeed '1+(2-(3+4))' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP] + expression: '1+(2-(3+4))' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_SUB, token: '-', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Succeed '((1+2)-3)+4' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP] + expression: '((1+2)-3)+4' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_SUB, token: '-', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- # comparison operators +test case: Succeed '1=2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1=2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + result: SUCCEED +--- +test case: Succeed '1<>2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1<>2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NE, token: '<>', opt: 0} + result: SUCCEED +--- +test case: Succeed '1<2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1<2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_LT, token: '<', opt: 0} + result: SUCCEED +--- +test case: Succeed '1<=2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1<=2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_LE, token: '<=', opt: 0} + result: SUCCEED +--- +test case: Succeed '1>2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1>2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_GT, token: '>', opt: 0} + result: SUCCEED +--- +test case: Succeed '1>=2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1>=2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_GE, token: '>=', opt: 0} + result: SUCCEED +--- +test case: Fail '1=' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1=' +out: + result: FAIL +--- +test case: Fail '1<>' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1<>' +out: + result: FAIL +--- +test case: Fail '1<' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1<' +out: + result: FAIL +--- +test case: Fail '1<=' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1<=' +out: + result: FAIL +--- +test case: Fail '1>' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1>' +out: + result: FAIL +--- +test case: Fail '1>=' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1>=' +out: + result: FAIL +--- +test case: Fail '=1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '=1' +out: + result: FAIL +--- +test case: Fail '<>1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '<>1' +out: + result: FAIL +--- +test case: Fail '<1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '<1' +out: + result: FAIL +--- +test case: Fail '<=1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '<=1' +out: + result: FAIL +--- +test case: Fail '>1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '>1' +out: + result: FAIL +--- +test case: Fail '>=1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '>=1' +out: + result: FAIL +--- +test case: Fail '1==1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1==1' +out: + result: FAIL +--- +test case: Fail '1=<1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1=<1' +out: + result: FAIL +--- +test case: Fail '1=>1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1=>1' +out: + result: FAIL +--- +test case: Succeed '3 > 2 <> 1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '3 > 2 <> 1' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_GT, token: '>', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NE, token: '<>', opt: 0} + result: SUCCEED +--- # mixed arithmetic and comparison operators +test case: Succeed '3 = 2 + 1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '3 = 2 + 1' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + result: SUCCEED +--- +test case: Succeed '(3 = 2) + 1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '(3 = 2) + 1' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Fail '1=+2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1=+2' +out: + result: FAIL +--- +test case: Fail '1+=2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1+=2' +out: + result: FAIL +--- +test case: Succeed '1=-2' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1=-2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '-2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + result: SUCCEED +--- # logical not +test case: Fail 'not 1' +in: + rules: [ZBX_EVAL_PARSE_VAR] + expression: 'not 1' +out: + result: FAIL +--- +test case: Succeed 'not 1' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_LOGIC] + expression: 'not 1' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NOT, token: 'not', opt: 0} + result: SUCCEED +--- +test case: Fail 'not1' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP] + expression: 'not1' +out: + result: FAIL +--- +test case: Succeed 'not(1)' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP] + expression: 'not(1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NOT, token: 'not', opt: 0} + result: SUCCEED +--- +test case: Succeed 'not 1 + 2' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: 'not 1 + 2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NOT, token: 'not', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Succeed 'not (1 + 2)' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: 'not (1 + 2)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NOT, token: 'not', opt: 0} + result: SUCCEED +--- +test case: Succeed '(not 1)' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '(not 1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NOT, token: 'not', opt: 0} + result: SUCCEED +--- +test case: Succeed '1 = not 2' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPARE] + expression: '1 = not 2' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NOT, token: 'not', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + result: SUCCEED +--- +test case: Fail '1 + not' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '1 + not' +out: + result: FAIL +--- +test case: Fail '1 +not 2' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '1 +not 2' +out: + stack: + result: FAIL +--- # constant variable index +test case: Succeed '1+2*3-{MACRO}' +in: + rules: [ZBX_EVAL_PARSE_CONST_INDEX,ZBX_EVAL_PARSE_MACRO,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '1+2*3-{MACRO}' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 1} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 2} + - {type: ZBX_EVAL_TOKEN_OP_MUL, token: '*', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_MACRO, token: '{MACRO}', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_SUB, token: '-', opt: 0} + result: SUCCEED +--- # logical and/or +test case: Succeed '1=2 or 3<4' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_LOGIC] + expression: '1=2 or 3<4' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_LT, token: '<', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_OR, token: 'or', opt: 0} + result: SUCCEED +--- +test case: Succeed '1=2 and 3<4' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE] + expression: '1=2 and 3<4' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_LT, token: '<', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_AND, token: 'and', opt: 0} + result: SUCCEED +--- +test case: Succeed '1 or 2 and 3 or 4' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '1 or 2 and 3 or 4' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_AND, token: 'and', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_OR, token: 'or', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_OR, token: 'or', opt: 0} + result: SUCCEED +--- +test case: Succeed '1 or 2 and 3 or 4' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '1 and 2 or 3 and 4' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_AND, token: 'and', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_AND, token: 'and', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_OR, token: 'or', opt: 0} + result: SUCCEED +--- +test case: Fail '1 and' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '1 and' +out: + result: FAIL +--- +test case: Fail '1 or' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '1 or' +out: + result: FAIL +--- +test case: Fail 'and 1' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: 'and 1' +out: + result: FAIL +--- +test case: Fail 'or 1' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: 'or 1' +out: + result: FAIL +--- +test case: Fail '1 and1' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '1 and1' +out: + result: FAIL +--- +test case: Fail '1and 1' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '1and 1' +out: + result: FAIL +--- +test case: Succeed '(1)and(2)' +in: + rules: [ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH] + expression: '(1)and(2)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_AND, token: 'and', opt: 0} + result: SUCCEED +--- # built-in functions +test case: Succeed 'min()' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: 'min()' +out: + stack: + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 0} + result: SUCCEED +--- +test case: Fail 'min(' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: 'min(' +out: + result: FAIL +--- +test case: Succeed 'min(1)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 1} + result: SUCCEED +--- +test case: Succeed 'min(1,2)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(1,2)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(1,)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(1,)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_NULL, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(,)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(,)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_NULL, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_NULL, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(1,"xyz")' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(1,"xyz")' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"xyz"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(1,{$MACRO:context,})' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_USERMACRO] + expression: 'min(1,{$MACRO:context,})' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_USERMACRO, token: '{$MACRO:context,}', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed '1 + min(2, 3) - 4' +in: + rules: [ZBX_EVAL_PARSE_CONST_INDEX,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1 + min(2, 3) - 4' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 2} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 1} + - {type: ZBX_EVAL_TOKEN_OP_SUB, token: '-', opt: 0} + result: SUCCEED +--- +test case: Succeed 'avg(min(1, 2), 3, max(4, 5, 6))' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'avg(min(1, 2), 3, max(4, 5, 6))' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 2} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '5', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '6', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'max', opt: 3} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'avg', opt: 3} + result: SUCCEED +--- +test case: Succeed 'min(1, , 2)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(1, , 2)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_NULL, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 3} + result: SUCCEED +--- +test case: Succeed 'min(/host/key,1)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(/host/key,1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Fail 'min(/host/key,1)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(/host/key,1)' +out: + result: FAIL +--- +test case: Fail 'min(,1m:now-1d)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(,1m:now-1d)' +out: + result: FAIL +--- +test case: Succeed 'min(/host/key,5m)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(/host/key,5m)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '5m', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/host/key,5m:now-1h)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(/host/key,5m:now-1h)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '5m:now-1h', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/host/key,#10)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: 'min(/host/key,#10)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#10', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/host/key,{$MACRO})' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: 'min(/host/key,{$MACRO})' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '{$MACRO}', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/host/key,#{$MACRO})' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPOUND_CONST] + expression: 'min(/host/key,#{$MACRO})' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#{$MACRO}', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/host/key,#{{#LLD}.func})' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_COMPOUND_CONST] + expression: 'min(/host/key,#{{#LLD}.func})' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#{{#LLD}.func}', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- # suffixed numbers +test case: Succeed '1w + 2G + 3h + 4K + 5s' +in: + rules: [ZBX_EVAL_PARSE_CONST_INDEX,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: '1w + 2G + 3h + 4K + 5s ' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1w', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2G', opt: 1} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3h', opt: 2} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4K', opt: 3} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '5s', opt: 4} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Succeed 'min(1w, 2d, 3h, 4m, 5s)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(1w, 2d, 3h, 4m, 5s)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1w', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2d', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3h', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '4m', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '5s', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 5} + result: SUCCEED +--- +test case: Fail '10y' +in: + rules: [ZBX_EVAL_PARSE_VAR] + expression: '10y' +out: + result: FAIL +--- +test case: Succeed '1G' +in: + rules: [ZBX_EVAL_PARSE_VAR] + expression: '1G' +out: + stack: + - type: ZBX_EVAL_TOKEN_VAR_NUM + token: '1G' + opt: 0 + result: SUCCEED +--- +test case: Fail '1N' +in: + rules: [ZBX_EVAL_PARSE_VAR] + expression: '1N' +out: + result: FAIL +--- +test case: Succeed '1m=60s' +in: + rules: [ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_COMPARE] + expression: '1m=60s' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1m', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '60s', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + result: SUCCEED +--- +test case: Fail '1e+309s' +in: + rules: [ZBX_EVAL_PARSE_VAR] + expression: '1e+309s' +out: + result: FAIL +--- +test case: Fail '1e+308K' +in: + rules: [ZBX_EVAL_PARSE_VAR] + expression: '1e+308K' +out: + result: FAIL +--- +test case: Fail 'min(2s, 1m),' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'min(2s, 1m),' +out: + result: FAIL +--- +test case: Fail '1 + ((/host/key))' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: '1 + ((/host/key,1d))' +out: + result: FAIL +--- +test case: Succeed 'last(/host/key)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: 'last(/host/key)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'last', opt: 1} + result: SUCCEED +--- +test case: Succeed 'last(/host/key,#1)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: 'last(/host/key,#1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#1', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'last', opt: 2} + result: SUCCEED +--- +test case: Succeed 'count(//trap[1],#5,,0)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR] + expression: 'count(//trap[1],#5,,0)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '//trap[1]', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#5', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_NULL, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '0', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'count', opt: 4} + result: SUCCEED +--- +test case: Succeed 'count(//trap[1],#5,,0) + count(/Trapper/trap[1] ,5m ,"1h ","1 ")' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR] + expression: 'count(//trap[1],#5,,0) + count(/Trapper/trap[1] ,5m ,"1h","1")' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '//trap[1]', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#5', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_NULL, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '0', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'count', opt: 4} + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/Trapper/trap[1]', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '5m', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"1h"', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"1"', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'count', opt: 4} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + result: SUCCEED +--- +test case: Succeed 'min(1 + 2, 0.5 + 1.5)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR_NUM] + expression: 'min(1 + 2, 0.5 + 1.5)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '0.5', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1.5', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Fail '(1, 2, 3)' +in: + rules: [] + expression: '(1, 2, 3)' +out: + result: FAIL +--- +test case: Succeed 'min(3 * (1 + 2), 0.5 + 1.5)' +in: + rules: [ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_VAR_NUM] + expression: 'min(3 * (1 + 2), 0.5 + 1.5)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '3', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '2', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_MUL, token: '*', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '0.5', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1.5', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_ADD, token: '+', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed '1=-1' +in: + rules: [ZBX_EVAL_PARSE_MATH,ZBX_EVAL_PARSE_COMPARE,ZBX_EVAL_PARSE_VAR_NUM] + expression: '1=-1' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_NUM, token: '-1', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + result: SUCCEED +--- +test case: Succeed 'last(/host/key,#1:now-1h)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP] + expression: 'last(/host/key,#1:now-1h)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/host/key', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '#1:now-1h', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'last', opt: 2} + result: SUCCEED +--- +test case: Succeed 'tag="xyz" and group<>"abc"' +in: + rules: [ZBX_EVAL_PARSE_PROPERTY,ZBX_EVAL_PARSE_VAR_STR,ZBX_EVAL_PARSE_COMPARE_EQ,ZBX_EVAL_PARSE_LOGIC] + expression: 'tag="xyz" and group<>"abc"' +out: + stack: + - {type: ZBX_EVAL_TOKEN_PROP_TAG, token: 'tag', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"xyz"', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + - {type: ZBX_EVAL_TOKEN_PROP_GROUP, token: 'group', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"abc"', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NE, token: '<>', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_AND, token: 'and', opt: 0} + result: SUCCEED +--- +test case: Succeed 'tag' +in: + rules: [ZBX_EVAL_PARSE_PROPERTY,ZBX_EVAL_PARSE_VAR_STR,ZBX_EVAL_PARSE_COMPARE_EQ,ZBX_EVAL_PARSE_LOGIC] + expression: 'tag' +out: + result: FAIL +--- +test case: Succeed 'tag=group' +in: + rules: [ZBX_EVAL_PARSE_PROPERTY,ZBX_EVAL_PARSE_VAR_STR,ZBX_EVAL_PARSE_COMPARE_EQ,ZBX_EVAL_PARSE_LOGIC] + expression: 'tag=group' +out: + result: FAIL +--- +test case: Succeed '"xyz"=tag' +in: + rules: [ZBX_EVAL_PARSE_PROPERTY,ZBX_EVAL_PARSE_VAR_STR,ZBX_EVAL_PARSE_COMPARE_EQ,ZBX_EVAL_PARSE_LOGIC] + expression: '"xyz"=tag' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"xyz"', opt: 0} + - {type: ZBX_EVAL_TOKEN_PROP_TAG, token: 'tag', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + result: SUCCEED +--- +test case: Succeed 'tag=("xyz")' +in: + rules: [ZBX_EVAL_PARSE_PROPERTY,ZBX_EVAL_PARSE_VAR_STR,ZBX_EVAL_PARSE_COMPARE_EQ,ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_GROUP] + expression: 'tag=("xyz")' +out: + stack: + - {type: ZBX_EVAL_TOKEN_PROP_TAG, token: 'tag', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"xyz"', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + result: SUCCEED +--- +test case: Succeed 'group=1' +in: + rules: [ZBX_EVAL_PARSE_PROPERTY,ZBX_EVAL_PARSE_VAR_STR,ZBX_EVAL_PARSE_COMPARE_EQ,ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_GROUP] + expression: 'group=1' +out: + result: FAIL +--- +test case: Succeed 'group="xyz" = tag' +in: + rules: [ZBX_EVAL_PARSE_PROPERTY,ZBX_EVAL_PARSE_VAR_STR,ZBX_EVAL_PARSE_COMPARE_EQ,ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_GROUP] + expression: 'group="xyz" = tag' +out: + result: FAIL +--- +test case: Succeed '(tag="xyz") = (group<>"abc")' +in: + rules: [ZBX_EVAL_PARSE_PROPERTY,ZBX_EVAL_PARSE_VAR_STR,ZBX_EVAL_PARSE_COMPARE_EQ,ZBX_EVAL_PARSE_LOGIC,ZBX_EVAL_PARSE_GROUP] + expression: '(tag="xyz") = (group<>"abc")' +out: + stack: + - {type: ZBX_EVAL_TOKEN_PROP_TAG, token: 'tag', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"xyz"', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + - {type: ZBX_EVAL_TOKEN_PROP_GROUP, token: 'group', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"abc"', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_NE, token: '<>', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_EQ, token: '=', opt: 0} + result: SUCCEED +--- # query filters +test case: Succeed 'min(/*/key?[group="a"],1)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(/*/key?[group="a"],1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/*/key?[group="a"]', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/*/key?[group="a:\"1\""],1)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(/*/key?[group="a:\"1\""],1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/*/key?[group="a:\"1\""]', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Succeed 'min(/*/key?[group="[]"],1)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(/*/key?[group="[]"],1)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_ARG_QUERY, token: '/*/key?[group="[]"]', opt: 0} + - {type: ZBX_EVAL_TOKEN_ARG_PERIOD, token: '1', opt: 0} + - {type: ZBX_EVAL_TOKEN_HIST_FUNCTION, token: 'min', opt: 2} + result: SUCCEED +--- +test case: Fail 'min(/*/key?[group="a",1)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(/*/key?[group="a",1)' +out: + result: FAIL +--- +test case: Fail 'min(/*/key?[group="a],1)' +in: + rules: [ZBX_EVAL_PARSE_ITEM_QUERY,ZBX_EVAL_PARSE_FUNCTION,ZBX_EVAL_PARSE_GROUP,ZBX_EVAL_PARSE_VAR,ZBX_EVAL_PARSE_MATH] + expression: 'min(/*/key?[group="a],1)' +out: + result: FAIL +--- +test case: Fail '1 < 2' +in: + rules: [ZBX_EVAL_PARSE_VAR] + expression: '1 < 2' +out: + result: FAIL +... diff --git a/tests/libs/zbxeval/zbx_eval_parse_query.c b/tests/libs/zbxeval/zbx_eval_parse_query.c new file mode 100755 index 00000000000..db10cd3ec3a --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_parse_query.c @@ -0,0 +1,74 @@ +/* +** Zabbix +** Copyright (C) 2001-2021 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 "zbxserver.h" +#include "zbxmocktest.h" +#include "zbxmockdata.h" +#include "zbxmockassert.h" +#include "zbxmockutil.h" +#include "zbxeval.h" + +void zbx_mock_test_entry(void **state) +{ + zbx_item_query_t query; + const char *itemquery, *host, *key, *filter; + size_t len; + + ZBX_UNUSED(state); + + itemquery = zbx_mock_get_parameter_string("in.query"); + len = zbx_eval_parse_query(itemquery, strlen(itemquery), &query); + + + key = zbx_mock_get_parameter_string("out.key"); + + if (0 == len) + { + if ('\0' != *key) + fail_msg("failed to parse query"); + } + else + { + zbx_mock_assert_uint64_eq("returned value", strlen(itemquery), len); + host = zbx_mock_get_parameter_string("out.host"); + filter = zbx_mock_get_parameter_string("out.filter"); + + zbx_mock_assert_str_eq("key", key, query.key); + + if (NULL == query.host) + { + if ('\0' != *host) + fail_msg("expected host value '%s' while got null", host); + } + else + zbx_mock_assert_str_eq("host", host, query.host); + + if (NULL == query.filter) + { + if ('\0' != *filter) + fail_msg("expected filter value '%s' while got null", filter); + } + else + zbx_mock_assert_str_eq("filter", filter, query.filter); + + zbx_eval_clear_query(&query); + } +} diff --git a/tests/libs/zbxeval/zbx_eval_parse_query.yaml b/tests/libs/zbxeval/zbx_eval_parse_query.yaml new file mode 100644 index 00000000000..83274faee88 --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_parse_query.yaml @@ -0,0 +1,63 @@ +--- +test case: Success '/host/key?[filter]' +in: + query: '/host/key?[filter]' +out: + host: 'host' + key: 'key' + filter: 'filter' +--- +test case: Success '/*/*' +in: + query: '/*/*' +out: + host: '*' + key: '*' + filter: '' +--- +test case: Success '//*?[group="a"]' +in: + query: '//*?[group="a"]' +out: + host: '' + key: '*' + filter: 'group="a"' +--- +test case: Success '/host/key[]?[group="a"]' +in: + query: '/host/key[]?[group="a"]' +out: + host: 'host' + key: 'key[]' + filter: 'group="a"' +--- +test case: Success '/h o s t/key[?, "[]"]?[group="\"a\""]' +in: + query: '/h o s t/key[?, "[]"]?[group="\"a\""]' +out: + host: 'h o s t' + key: 'key[?, "[]"]' + filter: 'group="\"a\""' +--- +test case: Failure '/*/*?' +in: + query: '/*/*?' +out: + key: '' +--- +test case: Failure '/*/*?[' +in: + query: '/*/*?[' +out: + key: '' +--- +test case: Failure '/*/*[' +in: + query: '/*/*[' +out: + key: '' +... + + + + diff --git a/tests/libs/zbxeval/zbx_eval_prepare_filter.c b/tests/libs/zbxeval/zbx_eval_prepare_filter.c new file mode 100644 index 00000000000..e972d3d1fd8 --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_prepare_filter.c @@ -0,0 +1,50 @@ +/* +** Zabbix +** Copyright (C) 2001-2020 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 "zbxeval.h" +#include "log.h" +#include "mock_eval.h" + +void zbx_mock_test_entry(void **state) +{ + zbx_eval_context_t ctx; + char *error = NULL; + + ZBX_UNUSED(state); + + + if (SUCCEED != zbx_eval_parse_expression(&ctx, zbx_mock_get_parameter_string("in.expression"), + ZBX_EVAL_PARSE_QUERY_EXPRESSION, &error)) + { + fail_msg("failed to parse expression: %s", error); + } + + zbx_eval_prepare_filter(&ctx); + + mock_compare_stack(&ctx, "out.stack"); + + zbx_free(error); + zbx_eval_clear(&ctx); +} diff --git a/tests/libs/zbxeval/zbx_eval_prepare_filter.yaml b/tests/libs/zbxeval/zbx_eval_prepare_filter.yaml new file mode 100644 index 00000000000..62f51f623b4 --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_prepare_filter.yaml @@ -0,0 +1,76 @@ +--- +test case: Expression 'group="x"' +in: + expression: 'group="x"' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1} + - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0} +--- +test case: Expression 'group="x"' +in: + expression: 'group<>"x"' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1} + - {type: ZBX_EVAL_TOKEN_OP_NOT, token: '<>', opt: 0} +--- +test case: Expression 'group="x" and tag="a"' +in: + expression: 'group="x" and tag="a"' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1} + - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"a"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'tag', opt: 1} + - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_AND, token: 'and', opt: 0} +--- +test case: Expression 'group="x" or group="y" and tag="a"' +in: + expression: 'group="x" or group="y" and tag="a"' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1} + - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"y"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1} + - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"a"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'tag', opt: 1} + - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_AND, token: 'and', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_OR, token: 'or', opt: 0} +--- +test case: Expression 'group<>"x" or tag<>"a"' +in: + expression: 'group<>"x" or tag<>"a"' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"x"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1} + - {type: ZBX_EVAL_TOKEN_OP_NOT, token: '<>', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"a"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'tag', opt: 1} + - {type: ZBX_EVAL_TOKEN_OP_NOT, token: '<>', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_OR, token: 'or', opt: 0} +--- +test case: Expression '(group="Zabbix servers") or ("Zabbix servers"=group)' +in: + expression: '(group="Zabbix servers") or ("Zabbix servers"=group)' +out: + stack: + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"Zabbix servers"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1} + - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_VAR_STR, token: '"Zabbix servers"', opt: 0} + - {type: ZBX_EVAL_TOKEN_FUNCTION, token: 'group', opt: 1} + - {type: ZBX_EVAL_TOKEN_NOP, token: '', opt: 0} + - {type: ZBX_EVAL_TOKEN_OP_OR, token: 'or', opt: 0} +... + diff --git a/tests/libs/zbxeval/zbx_eval_serialize.c b/tests/libs/zbxeval/zbx_eval_serialize.c new file mode 100644 index 00000000000..fc440d7f52f --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_serialize.c @@ -0,0 +1,154 @@ +/* +** Zabbix +** Copyright (C) 2001-2020 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 "zbxeval.h" + +static void mock_read_token(zbx_eval_token_t *token, zbx_mock_handle_t htoken) +{ + zbx_mock_handle_t hvalue; + zbx_mock_error_t err; + + token->type = (zbx_uint32_t)zbx_mock_get_object_member_uint64(htoken, "type"); + token->opt = (zbx_uint32_t)zbx_mock_get_object_member_uint64(htoken, "opt"); + + if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(htoken, "value", &hvalue)) + { + const char *value; + zbx_uint64_t ui64; + int len; + + token->loc.l = token->loc.r = 0; + if (ZBX_MOCK_SUCCESS != (err = zbx_mock_string(hvalue, &value))) + fail_msg("cannot read token value: %s", zbx_mock_error_string(err)); + + if (SUCCEED == is_uint64(value, &ui64)) + zbx_variant_set_ui64(&token->value, ui64); + else if (SUCCEED == zbx_number_parse(value, &len) && strlen(value) == (size_t)len) + zbx_variant_set_dbl(&token->value, atof(value)); + else + zbx_variant_set_str(&token->value, zbx_strdup(NULL, value)); + } + else + { + zbx_variant_set_none(&token->value); + token->loc.l = (size_t)zbx_mock_get_object_member_uint64(htoken, "left"); + token->loc.r = (size_t)zbx_mock_get_object_member_uint64(htoken, "right"); + } +} + +static void mock_read_stack(zbx_vector_eval_token_t *stack, const char *path) +{ + zbx_mock_handle_t hstack, htoken, hrepeat; + zbx_mock_error_t err; + + hstack = zbx_mock_get_parameter_handle(path); + + while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(hstack, &htoken)))) + { + zbx_eval_token_t token; + + if (ZBX_MOCK_SUCCESS != err) + fail_msg("cannot read token $%d", stack->values_num); + + mock_read_token(&token, htoken); + zbx_vector_eval_token_append_ptr(stack, &token); + } + + if (ZBX_MOCK_SUCCESS == zbx_mock_in_parameter("repeat", &hrepeat)) + { + const char *repeat; + int i, repeat_num; + zbx_vector_eval_token_t template; + + if (ZBX_MOCK_SUCCESS != (err = zbx_mock_string(hrepeat, &repeat))) + fail_msg("cannot read repeat number: %s", zbx_mock_error_string(err)); + + if (SUCCEED != is_uint32(repeat, &repeat_num)) + fail_msg("invalid repeat value"); + + zbx_vector_eval_token_create(&template); + zbx_vector_eval_token_append_array(&template, stack->values, stack->values_num); + + for (i = 0; i < repeat_num - 1; i++) + { + zbx_vector_eval_token_append_array(stack, template.values, template.values_num); + } + + zbx_vector_eval_token_destroy(&template); + } +} + +static void mock_compare_stacks(const zbx_vector_eval_token_t *stack1, const zbx_vector_eval_token_t *stack2) +{ + int i; + + if (stack1->values_num != stack2->values_num) + fail_msg("serialized %d tokens while deserialized %d", stack1->values_num, stack2->values_num); + + for (i = 0; i < stack1->values_num; i++) + { + char msg[1024]; + + zbx_snprintf(msg, sizeof(msg), "token #%d: ", i); + + zbx_mock_assert_int_eq(msg, stack1->values[i].type, stack2->values[i].type); + zbx_mock_assert_int_eq(msg, stack1->values[i].opt, stack2->values[i].opt); + zbx_mock_assert_uint64_eq(msg, stack1->values[i].loc.l, stack2->values[i].loc.l); + zbx_mock_assert_uint64_eq(msg, stack1->values[i].loc.r, stack2->values[i].loc.r); + + if (0 != zbx_variant_compare(&stack1->values[i].value, &stack2->values[i].value)) + { + fail_msg("%sexpected value '%s' while got '%s'", msg, + zbx_variant_value_desc(&stack1->values[i].value), + zbx_variant_value_desc(&stack2->values[i].value)); + } + } +} + +void zbx_mock_test_entry(void **state) +{ + zbx_eval_context_t ctx1, ctx2; + unsigned char *data; + + ZBX_UNUSED(state); + + memset(&ctx1, 0, sizeof(ctx1)); + zbx_vector_eval_token_create(&ctx1.stack); + + memset(&ctx2, 0, sizeof(ctx2)); + zbx_vector_eval_token_create(&ctx2.stack); + + mock_read_stack(&ctx1.stack, "in.stack"); + + zbx_eval_serialize(&ctx1, NULL, &data); + zbx_eval_deserialize(&ctx2, NULL, 0, data); + + zbx_free(data); + + mock_compare_stacks(&ctx1.stack, &ctx2.stack); + + zbx_eval_clear(&ctx1); + zbx_eval_clear(&ctx2); +} diff --git a/tests/libs/zbxeval/zbx_eval_serialize.yaml b/tests/libs/zbxeval/zbx_eval_serialize.yaml new file mode 100644 index 00000000000..15597be8ec7 --- /dev/null +++ b/tests/libs/zbxeval/zbx_eval_serialize.yaml @@ -0,0 +1,3569 @@ +--- +test case: Base +in: + stack: + - type: 1539029947 #* 0x5bbbbbb -> 10101010101... + opt: 0 + left: 0 + right: 0 + - type: 0 + opt: 1 + left: 2 + right: 3 + - type: 1000 + opt: 10 + left: 20 + right: 30 + - type: 217726 + opt: 1 + value: 'xyz' + - type: 1 + opt: 0 + value: '' + - type: 1 + opt: 0 + value: '1.234e10' + - type: 1 + opt: 0 + value: '12345678901234567890' + - type: 1 + opt: 0 + value: '1.234e10' +--- +test case: Stack size +in: + stack: + - type: 1539029947 #* 0x5bbbbbb -> 10101010101... + opt: 0 + left: 0 + right: 0 + - type: 0 + opt: 1 + left: 2 + right: 3 + - type: 1000 + opt: 10 + left: 20 + right: 30 + repeat: 1000 +--- +test case: Auto-generated case 1 for random limit 7 +in: + stack: + - type: 6 + opt: 2 + left: 1 + right: 0 + - type: 6 + opt: 4 + left: 3 + right: 5 + - type: 4 + opt: 1 + left: 4 + right: 6 + - type: 4 + opt: 3 + left: 1 + right: 4 + - type: 0 + opt: 6 + left: 0 + right: 5 + - type: 3 + opt: 2 + left: 3 + right: 6 + - type: 1 + opt: 3 + left: 1 + right: 6 + - type: 4 + opt: 2 + left: 0 + right: 3 + - type: 6 + opt: 4 + left: 3 + right: 6 + - type: 0 + opt: 0 + left: 5 + right: 4 +--- +test case: Auto-generated case 2 for random limit 7 +in: + stack: + - type: 6 + opt: 3 + left: 6 + right: 0 + - type: 6 + opt: 1 + left: 1 + right: 4 + - type: 6 + opt: 4 + left: 6 + right: 0 + - type: 5 + opt: 0 + left: 1 + right: 4 + - type: 2 + opt: 3 + left: 5 + right: 6 + - type: 5 + opt: 0 + left: 1 + right: 3 + - type: 5 + opt: 4 + left: 0 + right: 1 + - type: 5 + opt: 2 + left: 1 + right: 0 + - type: 1 + opt: 2 + left: 3 + right: 4 + - type: 0 + opt: 0 + left: 6 + right: 5 +--- +test case: Auto-generated case 3 for random limit 7 +in: + stack: + - type: 0 + opt: 1 + left: 0 + right: 3 + - type: 5 + opt: 3 + left: 4 + right: 6 + - type: 1 + opt: 5 + left: 6 + right: 3 + - type: 6 + opt: 5 + left: 3 + right: 4 + - type: 6 + opt: 6 + left: 6 + right: 2 + - type: 6 + opt: 3 + left: 5 + right: 3 + - type: 5 + opt: 3 + left: 0 + right: 1 + - type: 0 + opt: 5 + left: 4 + right: 0 + - type: 6 + opt: 1 + left: 5 + right: 5 + - type: 6 + opt: 2 + left: 0 + right: 3 +--- +test case: Auto-generated case 4 for random limit 7 +in: + stack: + - type: 2 + opt: 6 + left: 4 + right: 6 + - type: 5 + opt: 6 + left: 6 + right: 4 + - type: 0 + opt: 4 + left: 3 + right: 4 + - type: 6 + opt: 5 + left: 5 + right: 6 + - type: 1 + opt: 5 + left: 3 + right: 4 + - type: 3 + opt: 0 + left: 3 + right: 6 + - type: 0 + opt: 4 + left: 2 + right: 0 + - type: 4 + opt: 3 + left: 4 + right: 5 + - type: 5 + opt: 5 + left: 2 + right: 3 + - type: 3 + opt: 0 + left: 2 + right: 0 +--- +test case: Auto-generated case 5 for random limit 7 +in: + stack: + - type: 3 + opt: 0 + left: 1 + right: 0 + - type: 1 + opt: 6 + left: 0 + right: 1 + - type: 0 + opt: 3 + left: 1 + right: 3 + - type: 5 + opt: 0 + left: 5 + right: 2 + - type: 1 + opt: 1 + left: 1 + right: 5 + - type: 5 + opt: 4 + left: 6 + right: 0 + - type: 4 + opt: 0 + left: 2 + right: 4 + - type: 4 + opt: 0 + left: 1 + right: 2 + - type: 3 + opt: 2 + left: 2 + right: 3 + - type: 4 + opt: 5 + left: 6 + right: 2 +--- +test case: Auto-generated case 6 for random limit 7 +in: + stack: + - type: 4 + opt: 0 + left: 4 + right: 5 + - type: 0 + opt: 2 + left: 2 + right: 0 + - type: 5 + opt: 5 + left: 2 + right: 3 + - type: 3 + opt: 4 + left: 4 + right: 5 + - type: 5 + opt: 2 + left: 0 + right: 6 + - type: 0 + opt: 5 + left: 0 + right: 5 + - type: 3 + opt: 5 + left: 4 + right: 2 + - type: 6 + opt: 4 + left: 3 + right: 4 + - type: 4 + opt: 3 + left: 4 + right: 1 + - type: 2 + opt: 5 + left: 3 + right: 6 +--- +test case: Auto-generated case 7 for random limit 7 +in: + stack: + - type: 0 + opt: 1 + left: 5 + right: 2 + - type: 2 + opt: 2 + left: 3 + right: 2 + - type: 3 + opt: 3 + left: 5 + right: 1 + - type: 4 + opt: 2 + left: 2 + right: 5 + - type: 2 + opt: 3 + left: 3 + right: 0 + - type: 1 + opt: 0 + left: 2 + right: 2 + - type: 4 + opt: 4 + left: 0 + right: 5 + - type: 3 + opt: 1 + left: 3 + right: 3 + - type: 3 + opt: 6 + left: 4 + right: 0 + - type: 2 + opt: 2 + left: 2 + right: 2 +--- +test case: Auto-generated case 8 for random limit 7 +in: + stack: + - type: 3 + opt: 3 + left: 2 + right: 5 + - type: 5 + opt: 5 + left: 3 + right: 1 + - type: 4 + opt: 1 + left: 1 + right: 6 + - type: 0 + opt: 6 + left: 0 + right: 6 + - type: 1 + opt: 4 + left: 0 + right: 3 + - type: 4 + opt: 0 + left: 4 + right: 6 + - type: 4 + opt: 3 + left: 5 + right: 0 + - type: 5 + opt: 4 + left: 5 + right: 2 + - type: 1 + opt: 3 + left: 1 + right: 2 + - type: 2 + opt: 6 + left: 0 + right: 0 +--- +test case: Auto-generated case 9 for random limit 7 +in: + stack: + - type: 3 + opt: 2 + left: 0 + right: 1 + - type: 4 + opt: 2 + left: 1 + right: 3 + - type: 4 + opt: 4 + left: 0 + right: 6 + - type: 4 + opt: 4 + left: 3 + right: 0 + - type: 6 + opt: 3 + left: 5 + right: 0 + - type: 3 + opt: 0 + left: 2 + right: 3 + - type: 4 + opt: 1 + left: 1 + right: 1 + - type: 5 + opt: 3 + left: 1 + right: 2 + - type: 6 + opt: 4 + left: 5 + right: 1 + - type: 4 + opt: 5 + left: 5 + right: 5 +--- +test case: Auto-generated case 10 for random limit 7 +in: + stack: + - type: 0 + opt: 5 + left: 5 + right: 5 + - type: 1 + opt: 5 + left: 6 + right: 5 + - type: 2 + opt: 6 + left: 2 + right: 1 + - type: 6 + opt: 6 + left: 1 + right: 6 + - type: 0 + opt: 1 + left: 6 + right: 1 + - type: 3 + opt: 2 + left: 5 + right: 0 + - type: 6 + opt: 3 + left: 2 + right: 2 + - type: 1 + opt: 1 + left: 6 + right: 3 + - type: 3 + opt: 3 + left: 2 + right: 0 + - type: 6 + opt: 2 + left: 0 + right: 5 +--- +test case: Auto-generated case 1 for random limit 7f +in: + stack: + - type: 116 + opt: 53 + left: 27 + right: 19 + - type: 126 + opt: 66 + left: 40 + right: 108 + - type: 126 + opt: 71 + left: 91 + right: 32 + - type: 66 + opt: 82 + left: 106 + right: 74 + - type: 120 + opt: 97 + left: 0 + right: 91 + - type: 38 + opt: 67 + left: 3 + right: 54 + - type: 76 + opt: 105 + left: 110 + right: 13 + - type: 48 + opt: 14 + left: 44 + right: 40 + - type: 49 + opt: 86 + left: 18 + right: 8 + - type: 6 + opt: 63 + left: 32 + right: 49 +--- +test case: Auto-generated case 2 for random limit 7f +in: + stack: + - type: 12 + opt: 61 + left: 55 + right: 97 + - type: 6 + opt: 92 + left: 109 + right: 35 + - type: 50 + opt: 91 + left: 104 + right: 70 + - type: 50 + opt: 78 + left: 82 + right: 100 + - type: 5 + opt: 34 + left: 71 + right: 70 + - type: 1 + opt: 45 + left: 73 + right: 102 + - type: 47 + opt: 53 + left: 31 + right: 88 + - type: 56 + opt: 9 + left: 95 + right: 58 + - type: 20 + opt: 61 + left: 22 + right: 109 + - type: 79 + opt: 102 + left: 120 + right: 58 +--- +test case: Auto-generated case 3 for random limit 7f +in: + stack: + - type: 16 + opt: 28 + left: 125 + right: 0 + - type: 76 + opt: 118 + left: 50 + right: 27 + - type: 22 + opt: 39 + left: 11 + right: 10 + - type: 114 + opt: 114 + left: 27 + right: 12 + - type: 117 + opt: 81 + left: 37 + right: 61 + - type: 110 + opt: 120 + left: 82 + right: 34 + - type: 82 + opt: 0 + left: 121 + right: 21 + - type: 6 + opt: 70 + left: 121 + right: 111 + - type: 4 + opt: 99 + left: 29 + right: 123 + - type: 11 + opt: 53 + left: 62 + right: 63 +--- +test case: Auto-generated case 4 for random limit 7f +in: + stack: + - type: 70 + opt: 62 + left: 84 + right: 104 + - type: 104 + opt: 101 + left: 73 + right: 38 + - type: 72 + opt: 61 + left: 51 + right: 110 + - type: 44 + opt: 90 + left: 118 + right: 72 + - type: 35 + opt: 44 + left: 14 + right: 57 + - type: 60 + opt: 117 + left: 92 + right: 41 + - type: 13 + opt: 83 + left: 114 + right: 6 + - type: 2 + opt: 89 + left: 31 + right: 14 + - type: 97 + opt: 58 + left: 83 + right: 122 + - type: 77 + opt: 49 + left: 13 + right: 107 +--- +test case: Auto-generated case 5 for random limit 7f +in: + stack: + - type: 68 + opt: 115 + left: 6 + right: 97 + - type: 78 + opt: 40 + left: 78 + right: 90 + - type: 30 + opt: 114 + left: 37 + right: 97 + - type: 16 + opt: 100 + left: 101 + right: 45 + - type: 118 + opt: 78 + left: 9 + right: 15 + - type: 14 + opt: 73 + left: 98 + right: 14 + - type: 64 + opt: 102 + left: 103 + right: 101 + - type: 28 + opt: 34 + left: 35 + right: 119 + - type: 97 + opt: 100 + left: 48 + right: 79 + - type: 68 + opt: 48 + left: 93 + right: 120 +--- +test case: Auto-generated case 6 for random limit 7f +in: + stack: + - type: 80 + opt: 84 + left: 18 + right: 77 + - type: 16 + opt: 99 + left: 106 + right: 58 + - type: 102 + opt: 38 + left: 118 + right: 106 + - type: 55 + opt: 39 + left: 35 + right: 1 + - type: 106 + opt: 41 + left: 18 + right: 124 + - type: 50 + opt: 68 + left: 115 + right: 86 + - type: 92 + opt: 97 + left: 24 + right: 6 + - type: 102 + opt: 11 + left: 119 + right: 44 + - type: 59 + opt: 35 + left: 82 + right: 96 + - type: 70 + opt: 48 + left: 70 + right: 104 +--- +test case: Auto-generated case 7 for random limit 7f +in: + stack: + - type: 16 + opt: 53 + left: 7 + right: 109 + - type: 28 + opt: 9 + left: 94 + right: 10 + - type: 110 + opt: 4 + left: 12 + right: 77 + - type: 72 + opt: 16 + left: 90 + right: 6 + - type: 16 + opt: 28 + left: 58 + right: 104 + - type: 102 + opt: 20 + left: 81 + right: 8 + - type: 107 + opt: 121 + left: 3 + right: 66 + - type: 23 + opt: 106 + left: 109 + right: 37 + - type: 18 + opt: 121 + left: 94 + right: 120 + - type: 43 + opt: 70 + left: 42 + right: 103 +--- +test case: Auto-generated case 8 for random limit 7f +in: + stack: + - type: 112 + opt: 119 + left: 52 + right: 2 + - type: 105 + opt: 79 + left: 59 + right: 47 + - type: 66 + opt: 64 + left: 111 + right: 50 + - type: 84 + opt: 86 + left: 1 + right: 84 + - type: 48 + opt: 123 + left: 56 + right: 5 + - type: 108 + opt: 80 + left: 126 + right: 37 + - type: 22 + opt: 47 + left: 124 + right: 46 + - type: 115 + opt: 44 + left: 85 + right: 69 + - type: 23 + opt: 47 + left: 125 + right: 106 + - type: 124 + opt: 3 + left: 37 + right: 6 +--- +test case: Auto-generated case 9 for random limit 7f +in: + stack: + - type: 106 + opt: 36 + left: 48 + right: 99 + - type: 65 + opt: 44 + left: 50 + right: 23 + - type: 110 + opt: 112 + left: 74 + right: 104 + - type: 60 + opt: 10 + left: 78 + right: 38 + - type: 109 + opt: 54 + left: 10 + right: 64 + - type: 45 + opt: 24 + left: 116 + right: 100 + - type: 103 + opt: 83 + left: 61 + right: 70 + - type: 18 + opt: 48 + left: 126 + right: 86 + - type: 46 + opt: 48 + left: 106 + right: 104 + - type: 101 + opt: 79 + left: 76 + right: 25 +--- +test case: Auto-generated case 10 for random limit 7f +in: + stack: + - type: 61 + opt: 69 + left: 116 + right: 1 + - type: 12 + opt: 46 + left: 89 + right: 9 + - type: 71 + opt: 106 + left: 49 + right: 12 + - type: 21 + opt: 51 + left: 36 + right: 22 + - type: 32 + opt: 119 + left: 61 + right: 97 + - type: 4 + opt: 30 + left: 50 + right: 33 + - type: 125 + opt: 21 + left: 63 + right: 80 + - type: 5 + opt: 66 + left: 57 + right: 96 + - type: 100 + opt: 41 + left: 61 + right: 71 + - type: 64 + opt: 54 + left: 88 + right: 10 +--- +test case: Auto-generated case 1 for random limit 7ff +in: + stack: + - type: 1463 + opt: 1823 + left: 154 + right: 1437 + - type: 1271 + opt: 2002 + left: 860 + right: 1149 + - type: 1029 + opt: 1169 + left: 868 + right: 1032 + - type: 932 + opt: 1697 + left: 102 + right: 162 + - type: 981 + opt: 331 + left: 926 + right: 45 + - type: 936 + opt: 1199 + left: 1533 + right: 457 + - type: 654 + opt: 1651 + left: 141 + right: 655 + - type: 1236 + opt: 1901 + left: 143 + right: 1786 + - type: 16 + opt: 2008 + left: 2032 + right: 1784 + - type: 1080 + opt: 50 + left: 2042 + right: 226 +--- +test case: Auto-generated case 2 for random limit 7ff +in: + stack: + - type: 1038 + opt: 13 + left: 52 + right: 1268 + - type: 1901 + opt: 337 + left: 1378 + right: 529 + - type: 594 + opt: 1165 + left: 1522 + right: 889 + - type: 520 + opt: 1524 + left: 425 + right: 183 + - type: 311 + opt: 494 + left: 1060 + right: 815 + - type: 1629 + opt: 1776 + left: 1794 + right: 1712 + - type: 1163 + opt: 291 + left: 358 + right: 1797 + - type: 1701 + opt: 298 + left: 382 + right: 657 + - type: 564 + opt: 875 + left: 1139 + right: 284 + - type: 1638 + opt: 1360 + left: 600 + right: 1440 +--- +test case: Auto-generated case 3 for random limit 7ff +in: + stack: + - type: 1240 + opt: 413 + left: 1320 + right: 307 + - type: 386 + opt: 627 + left: 1586 + right: 1064 + - type: 1051 + opt: 1395 + left: 131 + right: 1876 + - type: 604 + opt: 975 + left: 741 + right: 1680 + - type: 1423 + opt: 1631 + left: 785 + right: 1157 + - type: 506 + opt: 1608 + left: 32 + right: 454 + - type: 1223 + opt: 1146 + left: 850 + right: 312 + - type: 328 + opt: 1958 + left: 45 + right: 1217 + - type: 1697 + opt: 1948 + left: 545 + right: 1901 + - type: 206 + opt: 996 + left: 1778 + right: 716 +--- +test case: Auto-generated case 4 for random limit 7ff +in: + stack: + - type: 1756 + opt: 1199 + left: 597 + right: 1471 + - type: 877 + opt: 683 + left: 272 + right: 1751 + - type: 622 + opt: 101 + left: 1574 + right: 597 + - type: 448 + opt: 899 + left: 611 + right: 357 + - type: 407 + opt: 1736 + left: 727 + right: 1433 + - type: 1623 + opt: 1449 + left: 1894 + right: 1049 + - type: 2025 + opt: 553 + left: 1789 + right: 1150 + - type: 910 + opt: 1126 + left: 1150 + right: 1641 + - type: 896 + opt: 1079 + left: 1760 + right: 1492 + - type: 691 + opt: 665 + left: 1516 + right: 1154 +--- +test case: Auto-generated case 5 for random limit 7ff +in: + stack: + - type: 632 + opt: 216 + left: 1551 + right: 60 + - type: 394 + opt: 1811 + left: 691 + right: 1276 + - type: 1848 + opt: 162 + left: 939 + right: 703 + - type: 611 + opt: 807 + left: 1387 + right: 1794 + - type: 1316 + opt: 1375 + left: 199 + right: 1134 + - type: 689 + opt: 1778 + left: 208 + right: 919 + - type: 2009 + opt: 1091 + left: 1684 + right: 1029 + - type: 2007 + opt: 1383 + left: 294 + right: 1938 + - type: 217 + opt: 1195 + left: 1586 + right: 259 + - type: 1075 + opt: 1353 + left: 2013 + right: 697 +--- +test case: Auto-generated case 6 for random limit 7ff +in: + stack: + - type: 706 + opt: 1474 + left: 30 + right: 2007 + - type: 943 + opt: 563 + left: 670 + right: 289 + - type: 391 + opt: 1013 + left: 5 + right: 621 + - type: 1271 + opt: 101 + left: 1113 + right: 1965 + - type: 546 + opt: 1811 + left: 1805 + right: 1266 + - type: 1910 + opt: 1492 + left: 1917 + right: 672 + - type: 1574 + opt: 1133 + left: 1118 + right: 1607 + - type: 1834 + opt: 2029 + left: 1544 + right: 215 + - type: 1033 + opt: 1771 + left: 1226 + right: 599 + - type: 1470 + opt: 1070 + left: 1954 + right: 1530 +--- +test case: Auto-generated case 7 for random limit 7ff +in: + stack: + - type: 1604 + opt: 1567 + left: 542 + right: 1524 + - type: 195 + opt: 1509 + left: 1253 + right: 514 + - type: 78 + opt: 1946 + left: 1331 + right: 857 + - type: 1319 + opt: 830 + left: 1655 + right: 1377 + - type: 1748 + opt: 709 + left: 1825 + right: 154 + - type: 1518 + opt: 1496 + left: 741 + right: 1317 + - type: 126 + opt: 487 + left: 1587 + right: 213 + - type: 1200 + opt: 739 + left: 784 + right: 1635 + - type: 2036 + opt: 1124 + left: 1344 + right: 8 + - type: 261 + opt: 1323 + left: 1488 + right: 1819 +--- +test case: Auto-generated case 8 for random limit 7ff +in: + stack: + - type: 1258 + opt: 1965 + left: 1488 + right: 898 + - type: 1314 + opt: 1979 + left: 479 + right: 244 + - type: 1768 + opt: 1948 + left: 586 + right: 332 + - type: 251 + opt: 1981 + left: 760 + right: 880 + - type: 899 + opt: 1778 + left: 1876 + right: 313 + - type: 1999 + opt: 997 + left: 483 + right: 739 + - type: 375 + opt: 1704 + left: 517 + right: 125 + - type: 563 + opt: 649 + left: 1153 + right: 422 + - type: 394 + opt: 173 + left: 1139 + right: 541 + - type: 249 + opt: 1916 + left: 1489 + right: 710 +--- +test case: Auto-generated case 9 for random limit 7ff +in: + stack: + - type: 1570 + opt: 828 + left: 837 + right: 62 + - type: 991 + opt: 419 + left: 1790 + right: 1714 + - type: 271 + opt: 536 + left: 1929 + right: 477 + - type: 131 + opt: 1276 + left: 70 + right: 265 + - type: 271 + opt: 1048 + left: 1089 + right: 2033 + - type: 1021 + opt: 422 + left: 1803 + right: 1896 + - type: 1561 + opt: 47 + left: 117 + right: 1238 + - type: 1525 + opt: 1618 + left: 1385 + right: 1141 + - type: 413 + opt: 347 + left: 1974 + right: 533 + - type: 900 + opt: 800 + left: 1625 + right: 1030 +--- +test case: Auto-generated case 10 for random limit 7ff +in: + stack: + - type: 1081 + opt: 1848 + left: 1191 + right: 315 + - type: 1419 + opt: 1480 + left: 1002 + right: 269 + - type: 139 + opt: 390 + left: 400 + right: 773 + - type: 1663 + opt: 1036 + left: 448 + right: 619 + - type: 106 + opt: 669 + left: 1154 + right: 539 + - type: 1529 + opt: 1314 + left: 46 + right: 1403 + - type: 6 + opt: 62 + left: 2042 + right: 1299 + - type: 1213 + opt: 1476 + left: 452 + right: 1624 + - type: 1623 + opt: 647 + left: 558 + right: 503 + - type: 936 + opt: 921 + left: 1834 + right: 1213 +--- +test case: Auto-generated case 1 for random limit 7fff +in: + stack: + - type: 25568 + opt: 29171 + left: 26772 + right: 5451 + - type: 10967 + opt: 11279 + left: 20552 + right: 2319 + - type: 476 + opt: 31117 + left: 3106 + right: 21831 + - type: 5035 + opt: 28239 + left: 2047 + right: 6719 + - type: 26138 + opt: 16787 + left: 32705 + right: 1942 + - type: 1020 + opt: 31636 + left: 24915 + right: 31478 + - type: 8632 + opt: 29884 + left: 11377 + right: 20009 + - type: 16700 + opt: 16003 + left: 5172 + right: 10723 + - type: 26073 + opt: 20810 + left: 26452 + right: 5906 + - type: 31739 + opt: 4172 + left: 17603 + right: 3944 +--- +test case: Auto-generated case 2 for random limit 7fff +in: + stack: + - type: 24878 + opt: 17324 + left: 9552 + right: 31616 + - type: 22938 + opt: 15439 + left: 4622 + right: 5771 + - type: 16562 + opt: 30307 + left: 26722 + right: 12386 + - type: 3270 + opt: 25792 + left: 8636 + right: 6159 + - type: 24457 + opt: 1560 + left: 30690 + right: 26539 + - type: 27877 + opt: 32660 + left: 30568 + right: 24121 + - type: 29423 + opt: 12244 + left: 18970 + right: 12520 + - type: 17328 + opt: 22449 + left: 19863 + right: 7131 + - type: 17633 + opt: 12219 + left: 20691 + right: 13644 + - type: 1153 + opt: 26514 + left: 2136 + right: 19651 +--- +test case: Auto-generated case 3 for random limit 7fff +in: + stack: + - type: 18086 + opt: 26101 + left: 32079 + right: 32282 + - type: 8927 + opt: 7030 + left: 1602 + right: 385 + - type: 22183 + opt: 14383 + left: 20771 + right: 3807 + - type: 9889 + opt: 8396 + left: 21241 + right: 31694 + - type: 24242 + opt: 27989 + left: 8772 + right: 24241 + - type: 29007 + opt: 24889 + left: 23757 + right: 9698 + - type: 393 + opt: 24624 + left: 16812 + right: 3215 + - type: 30591 + opt: 18242 + left: 29549 + right: 7536 + - type: 4359 + opt: 23195 + left: 4895 + right: 7111 + - type: 10407 + opt: 20981 + left: 12509 + right: 30317 +--- +test case: Auto-generated case 4 for random limit 7fff +in: + stack: + - type: 16738 + opt: 28765 + left: 3940 + right: 24551 + - type: 8862 + opt: 26918 + left: 17125 + right: 30720 + - type: 20420 + opt: 16180 + left: 29294 + right: 22431 + - type: 26831 + opt: 18017 + left: 15868 + right: 31378 + - type: 27021 + opt: 3829 + left: 12239 + right: 30585 + - type: 4214 + opt: 9292 + left: 30621 + right: 3738 + - type: 20670 + opt: 20792 + left: 5488 + right: 26651 + - type: 21494 + opt: 30496 + left: 12526 + right: 10063 + - type: 5493 + opt: 31506 + left: 15075 + right: 20495 + - type: 10380 + opt: 8559 + left: 31008 + right: 21601 +--- +test case: Auto-generated case 5 for random limit 7fff +in: + stack: + - type: 8977 + opt: 26044 + left: 4310 + right: 29308 + - type: 862 + opt: 20360 + left: 13483 + right: 11253 + - type: 301 + opt: 1812 + left: 30043 + right: 28659 + - type: 28595 + opt: 8455 + left: 5864 + right: 9022 + - type: 12001 + opt: 10205 + left: 28740 + right: 5580 + - type: 14137 + opt: 8207 + left: 17325 + right: 27363 + - type: 32217 + opt: 2344 + left: 12385 + right: 12965 + - type: 26526 + opt: 20295 + left: 25209 + right: 7679 + - type: 19771 + opt: 25837 + left: 1712 + right: 1826 + - type: 20427 + opt: 25848 + left: 25683 + right: 31315 +--- +test case: Auto-generated case 6 for random limit 7fff +in: + stack: + - type: 19835 + opt: 16067 + left: 21002 + right: 3422 + - type: 20348 + opt: 27824 + left: 2653 + right: 21837 + - type: 7266 + opt: 6468 + left: 5885 + right: 14447 + - type: 27659 + opt: 28544 + left: 8044 + right: 17191 + - type: 11333 + opt: 29352 + left: 17163 + right: 28425 + - type: 7424 + opt: 18028 + left: 10247 + right: 20668 + - type: 16083 + opt: 13243 + left: 1361 + right: 7114 + - type: 6833 + opt: 4423 + left: 28635 + right: 16671 + - type: 22223 + opt: 28444 + left: 28717 + right: 11607 + - type: 12405 + opt: 16530 + left: 6203 + right: 27960 +--- +test case: Auto-generated case 7 for random limit 7fff +in: + stack: + - type: 30443 + opt: 15678 + left: 5655 + right: 32366 + - type: 24709 + opt: 8965 + left: 25948 + right: 26264 + - type: 32067 + opt: 27091 + left: 8135 + right: 28748 + - type: 13589 + opt: 7111 + left: 28344 + right: 6121 + - type: 18054 + opt: 271 + left: 15507 + right: 12402 + - type: 9925 + opt: 13267 + left: 2020 + right: 27020 + - type: 31578 + opt: 31092 + left: 26435 + right: 5397 + - type: 30953 + opt: 16050 + left: 26482 + right: 26473 + - type: 2930 + opt: 28671 + left: 23121 + right: 4869 + - type: 9121 + opt: 5436 + left: 19426 + right: 10470 +--- +test case: Auto-generated case 8 for random limit 7fff +in: + stack: + - type: 30851 + opt: 10299 + left: 27890 + right: 21202 + - type: 26810 + opt: 5335 + left: 13880 + right: 2166 + - type: 23207 + opt: 29998 + left: 11947 + right: 3405 + - type: 26559 + opt: 3483 + left: 25161 + right: 18763 + - type: 5240 + opt: 14817 + left: 32229 + right: 312 + - type: 15164 + opt: 29101 + left: 20193 + right: 20707 + - type: 8532 + opt: 4277 + left: 15269 + right: 26437 + - type: 2191 + opt: 19668 + left: 23252 + right: 25068 + - type: 1648 + opt: 8310 + left: 23198 + right: 3909 + - type: 1195 + opt: 9687 + left: 11594 + right: 23397 +--- +test case: Auto-generated case 9 for random limit 7fff +in: + stack: + - type: 18785 + opt: 22570 + left: 565 + right: 30674 + - type: 6967 + opt: 19613 + left: 629 + right: 11032 + - type: 21154 + opt: 528 + left: 29562 + right: 15795 + - type: 518 + opt: 12779 + left: 9163 + right: 14311 + - type: 7331 + opt: 4541 + left: 3308 + right: 12305 + - type: 11979 + opt: 14538 + left: 18166 + right: 20209 + - type: 6134 + opt: 22026 + left: 11270 + right: 28902 + - type: 21380 + opt: 31523 + left: 21132 + right: 23715 + - type: 1147 + opt: 27719 + left: 8837 + right: 20192 + - type: 15993 + opt: 18682 + left: 7107 + right: 22245 +--- +test case: Auto-generated case 10 for random limit 7fff +in: + stack: + - type: 12230 + opt: 27732 + left: 12905 + right: 19273 + - type: 21911 + opt: 44 + left: 23208 + right: 7366 + - type: 24915 + opt: 26159 + left: 5450 + right: 4493 + - type: 22574 + opt: 2248 + left: 299 + right: 11313 + - type: 17115 + opt: 8006 + left: 28023 + right: 29568 + - type: 12431 + opt: 5160 + left: 18504 + right: 10430 + - type: 20009 + opt: 6012 + left: 15913 + right: 30621 + - type: 4803 + opt: 29179 + left: 23751 + right: 29117 + - type: 10321 + opt: 25788 + left: 23802 + right: 30637 + - type: 20019 + opt: 12910 + left: 27693 + right: 16332 +--- +test case: Auto-generated case 1 for random limit 7ffff +in: + stack: + - type: 100837 + opt: 449281 + left: 229745 + right: 136947 + - type: 251558 + opt: 269144 + left: 397649 + right: 158037 + - type: 417083 + opt: 207194 + left: 390431 + right: 217656 + - type: 147282 + opt: 252599 + left: 380607 + right: 216357 + - type: 342077 + opt: 62696 + left: 116968 + right: 359960 + - type: 356281 + opt: 197215 + left: 440261 + right: 154965 + - type: 105476 + opt: 271036 + left: 406671 + right: 99912 + - type: 128426 + opt: 349230 + left: 73434 + right: 54906 + - type: 127694 + opt: 248197 + left: 95323 + right: 385904 + - type: 153765 + opt: 401473 + left: 218755 + right: 358968 +--- +test case: Auto-generated case 2 for random limit 7ffff +in: + stack: + - type: 265015 + opt: 183051 + left: 76805 + right: 341726 + - type: 37146 + opt: 80016 + left: 328445 + right: 402194 + - type: 388815 + opt: 7857 + left: 277038 + right: 350237 + - type: 172650 + opt: 410944 + left: 382131 + right: 426169 + - type: 453969 + opt: 38259 + left: 21785 + right: 300557 + - type: 154119 + opt: 40923 + left: 134318 + right: 217875 + - type: 318497 + opt: 172385 + left: 480426 + right: 502138 + - type: 149564 + opt: 506577 + left: 481677 + right: 365015 + - type: 482595 + opt: 146467 + left: 285822 + right: 185948 + - type: 399687 + opt: 183500 + left: 296536 + right: 205569 +--- +test case: Auto-generated case 3 for random limit 7ffff +in: + stack: + - type: 68197 + opt: 477535 + left: 153341 + right: 444758 + - type: 253619 + opt: 27436 + left: 461573 + right: 331572 + - type: 449419 + opt: 54189 + left: 35895 + right: 15954 + - type: 336946 + opt: 322266 + left: 356565 + right: 105820 + - type: 12709 + opt: 59590 + left: 386299 + right: 305244 + - type: 477477 + opt: 451641 + left: 373111 + right: 163181 + - type: 377382 + opt: 316053 + left: 436054 + right: 481381 + - type: 329574 + opt: 461016 + left: 287541 + right: 303000 + - type: 43045 + opt: 14845 + left: 71488 + right: 300940 + - type: 440010 + opt: 133920 + left: 87498 + right: 293403 +--- +test case: Auto-generated case 4 for random limit 7ffff +in: + stack: + - type: 379057 + opt: 394276 + left: 398145 + right: 324348 + - type: 93483 + opt: 28822 + left: 460959 + right: 370663 + - type: 280144 + opt: 247447 + left: 377701 + right: 489536 + - type: 452563 + opt: 432713 + left: 199336 + right: 336415 + - type: 328132 + opt: 468586 + left: 326567 + right: 150373 + - type: 83418 + opt: 285779 + left: 486389 + right: 101030 + - type: 31397 + opt: 125616 + left: 284869 + right: 8659 + - type: 309651 + opt: 31322 + left: 219134 + right: 226155 + - type: 115309 + opt: 295663 + left: 338582 + right: 85811 + - type: 385080 + opt: 471498 + left: 46452 + right: 196432 +--- +test case: Auto-generated case 5 for random limit 7ffff +in: + stack: + - type: 30919 + opt: 291616 + left: 217947 + right: 138552 + - type: 140613 + opt: 59843 + left: 472512 + right: 319836 + - type: 438803 + opt: 415911 + left: 509474 + right: 195414 + - type: 65392 + opt: 255360 + left: 345133 + right: 145069 + - type: 225659 + opt: 372110 + left: 494158 + right: 214269 + - type: 180525 + opt: 523716 + left: 432483 + right: 297223 + - type: 463745 + opt: 450585 + left: 39748 + right: 111985 + - type: 217389 + opt: 486877 + left: 104376 + right: 28893 + - type: 406354 + opt: 89026 + left: 365387 + right: 152153 + - type: 395057 + opt: 57736 + left: 296968 + right: 162456 +--- +test case: Auto-generated case 6 for random limit 7ffff +in: + stack: + - type: 173102 + opt: 413192 + left: 497529 + right: 200196 + - type: 413128 + opt: 365050 + left: 318772 + right: 428015 + - type: 94689 + opt: 346037 + left: 475547 + right: 68401 + - type: 399696 + opt: 97890 + left: 81919 + right: 86086 + - type: 47462 + opt: 143358 + left: 404677 + right: 334434 + - type: 265893 + opt: 318458 + left: 34100 + right: 256442 + - type: 100839 + opt: 115658 + left: 308912 + right: 15458 + - type: 174902 + opt: 134093 + left: 218067 + right: 194919 + - type: 391769 + opt: 166314 + left: 21409 + right: 335410 + - type: 482193 + opt: 451282 + left: 490655 + right: 167696 +--- +test case: Auto-generated case 7 for random limit 7ffff +in: + stack: + - type: 13100 + opt: 480 + left: 170123 + right: 13017 + - type: 230857 + opt: 43258 + left: 179807 + right: 356680 + - type: 345213 + opt: 113695 + left: 151678 + right: 142550 + - type: 198888 + opt: 451971 + left: 523600 + right: 16789 + - type: 323983 + opt: 205374 + left: 37643 + right: 312629 + - type: 72103 + opt: 250443 + left: 309023 + right: 352014 + - type: 186855 + opt: 442839 + left: 18164 + right: 462543 + - type: 314107 + opt: 134916 + left: 35605 + right: 35649 + - type: 219041 + opt: 290128 + left: 442871 + right: 219968 + - type: 473002 + opt: 166198 + left: 218188 + right: 372546 +--- +test case: Auto-generated case 8 for random limit 7ffff +in: + stack: + - type: 402339 + opt: 348525 + left: 73683 + right: 214736 + - type: 456948 + opt: 107553 + left: 112029 + right: 134075 + - type: 444204 + opt: 308000 + left: 437392 + right: 25899 + - type: 509406 + opt: 101236 + left: 334291 + right: 240679 + - type: 209568 + opt: 371755 + left: 25590 + right: 361900 + - type: 513039 + opt: 220773 + left: 14089 + right: 207751 + - type: 464556 + opt: 141649 + left: 13565 + right: 146318 + - type: 239870 + opt: 162357 + left: 301177 + right: 391682 + - type: 389224 + opt: 489896 + left: 348998 + right: 434983 + - type: 421790 + opt: 324917 + left: 284348 + right: 80321 +--- +test case: Auto-generated case 9 for random limit 7ffff +in: + stack: + - type: 380808 + opt: 295805 + left: 367327 + right: 203911 + - type: 502404 + opt: 96001 + left: 272138 + right: 434979 + - type: 150971 + opt: 52832 + left: 132027 + right: 487765 + - type: 102409 + opt: 72365 + left: 230461 + right: 46882 + - type: 490806 + opt: 514482 + left: 444014 + right: 223581 + - type: 397240 + opt: 214316 + left: 125326 + right: 386613 + - type: 374491 + opt: 180167 + left: 116011 + right: 248515 + - type: 388842 + opt: 249298 + left: 435715 + right: 20549 + - type: 154183 + opt: 228385 + left: 115045 + right: 1416 + - type: 92678 + opt: 322124 + left: 387946 + right: 331925 +--- +test case: Auto-generated case 10 for random limit 7ffff +in: + stack: + - type: 335837 + opt: 442090 + left: 267272 + right: 365432 + - type: 428704 + opt: 387926 + left: 182715 + right: 301582 + - type: 466538 + opt: 451239 + left: 410133 + right: 497700 + - type: 465070 + opt: 289723 + left: 454150 + right: 375624 + - type: 486784 + opt: 350314 + left: 37305 + right: 337074 + - type: 231478 + opt: 345186 + left: 419962 + right: 490016 + - type: 186500 + opt: 110633 + left: 389995 + right: 366795 + - type: 412276 + opt: 399548 + left: 347610 + right: 492091 + - type: 473996 + opt: 343659 + left: 169442 + right: 42650 + - type: 144772 + opt: 169781 + left: 360563 + right: 140273 +--- +test case: Auto-generated case 1 for random limit 7fffff +in: + stack: + - type: 4676444 + opt: 991015 + left: 6033838 + right: 4473340 + - type: 4217822 + opt: 2838363 + left: 442757 + right: 3525825 + - type: 1135432 + opt: 1477005 + left: 551265 + right: 8165424 + - type: 6990650 + opt: 4468989 + left: 2489850 + right: 2450526 + - type: 1723618 + opt: 1673635 + left: 6018360 + right: 3828834 + - type: 3870026 + opt: 581269 + left: 3445234 + right: 4421404 + - type: 7643734 + opt: 562155 + left: 2016158 + right: 6252299 + - type: 7759453 + opt: 5731060 + left: 6385876 + right: 7365907 + - type: 7209911 + opt: 1523714 + left: 5292197 + right: 5694595 + - type: 429374 + opt: 8021095 + left: 230905 + right: 191380 +--- +test case: Auto-generated case 2 for random limit 7fffff +in: + stack: + - type: 4243623 + opt: 1690705 + left: 4492379 + right: 6882269 + - type: 5499895 + opt: 5212302 + left: 7076873 + right: 3175124 + - type: 2317225 + opt: 424518 + left: 8308051 + right: 7228279 + - type: 7594721 + opt: 8370908 + left: 5351720 + right: 2694250 + - type: 6269914 + opt: 6213513 + left: 5797779 + right: 3682321 + - type: 176141 + opt: 5606967 + left: 7246718 + right: 1974825 + - type: 6948999 + opt: 7307999 + left: 2757143 + right: 2405934 + - type: 2608485 + opt: 2929098 + left: 5120494 + right: 5854200 + - type: 4723147 + opt: 6320822 + left: 4146399 + right: 220085 + - type: 4672804 + opt: 3492730 + left: 6263864 + right: 7798149 +--- +test case: Auto-generated case 3 for random limit 7fffff +in: + stack: + - type: 2002644 + opt: 6453488 + left: 6562536 + right: 4048306 + - type: 5180960 + opt: 6120076 + left: 6860445 + right: 5367054 + - type: 2599426 + opt: 6766868 + left: 5127555 + right: 679343 + - type: 4286322 + opt: 3968380 + left: 4363842 + right: 7758631 + - type: 6829566 + opt: 2382603 + left: 7978215 + right: 1840426 + - type: 6822372 + opt: 6552998 + left: 3975772 + right: 1268927 + - type: 1904396 + opt: 4420693 + left: 2005747 + right: 4178923 + - type: 8053723 + opt: 2378228 + left: 1124891 + right: 6235848 + - type: 1182171 + opt: 6373594 + left: 4349882 + right: 5439407 + - type: 3236403 + opt: 4922741 + left: 6016851 + right: 6348572 +--- +test case: Auto-generated case 4 for random limit 7fffff +in: + stack: + - type: 8002498 + opt: 4242565 + left: 8212890 + right: 3535155 + - type: 2788979 + opt: 6800480 + left: 4582185 + right: 5872822 + - type: 3008068 + opt: 6579656 + left: 347954 + right: 7819066 + - type: 3810187 + opt: 3921890 + left: 897194 + right: 444212 + - type: 7527898 + opt: 1260888 + left: 2952794 + right: 6923714 + - type: 8097471 + opt: 5963122 + left: 3204281 + right: 7222629 + - type: 3372270 + opt: 5347404 + left: 6638577 + right: 3681974 + - type: 3225131 + opt: 6653643 + left: 2237655 + right: 7132781 + - type: 3630510 + opt: 3034241 + left: 1392237 + right: 5934556 + - type: 5635144 + opt: 6197336 + left: 2685625 + right: 7198122 +--- +test case: Auto-generated case 5 for random limit 7fffff +in: + stack: + - type: 4253896 + opt: 6697206 + left: 2027352 + right: 3325331 + - type: 904855 + opt: 7064184 + left: 5560044 + right: 1522774 + - type: 1324988 + opt: 2483635 + left: 1126001 + right: 4461882 + - type: 3396361 + opt: 4693748 + left: 6781672 + right: 7660486 + - type: 6247468 + opt: 8134080 + left: 6296160 + right: 2378570 + - type: 8236368 + opt: 5205439 + left: 1892658 + right: 6361497 + - type: 4131437 + opt: 536975 + left: 4720809 + right: 518109 + - type: 3961174 + opt: 6216894 + left: 711976 + right: 7603838 + - type: 1366547 + opt: 1815736 + left: 7068329 + right: 7043998 + - type: 7385348 + opt: 3847390 + left: 5602914 + right: 3521832 +--- +test case: Auto-generated case 6 for random limit 7fffff +in: + stack: + - type: 2801002 + opt: 6427203 + left: 4324586 + right: 2812900 + - type: 4344037 + opt: 7894950 + left: 5529210 + right: 1897979 + - type: 3639740 + opt: 2814520 + left: 7986932 + right: 1741822 + - type: 5208669 + opt: 4459767 + left: 6658772 + right: 3162164 + - type: 66491 + opt: 1284904 + left: 5112657 + right: 6549262 + - type: 499720 + opt: 3912127 + left: 5705286 + right: 1823456 + - type: 7946155 + opt: 790652 + left: 3728861 + right: 6758224 + - type: 3338592 + opt: 527074 + left: 6239640 + right: 8354067 + - type: 1122028 + opt: 214922 + left: 7356219 + right: 5109871 + - type: 710943 + opt: 7839922 + left: 5158400 + right: 830887 +--- +test case: Auto-generated case 7 for random limit 7fffff +in: + stack: + - type: 4741345 + opt: 2129531 + left: 7649814 + right: 3181554 + - type: 7710764 + opt: 6447413 + left: 2740739 + right: 2812938 + - type: 6322263 + opt: 4232473 + left: 165923 + right: 72667 + - type: 414766 + opt: 4751955 + left: 743885 + right: 5520549 + - type: 3112813 + opt: 2032034 + left: 6226738 + right: 3706283 + - type: 5490142 + opt: 791798 + left: 1873691 + right: 270242 + - type: 2100886 + opt: 7829663 + left: 4312395 + right: 2942102 + - type: 7421432 + opt: 278565 + left: 7723293 + right: 4341568 + - type: 7122389 + opt: 4107200 + left: 1493079 + right: 4084888 + - type: 4455346 + opt: 3647910 + left: 2151174 + right: 6167203 +--- +test case: Auto-generated case 8 for random limit 7fffff +in: + stack: + - type: 423 + opt: 4040063 + left: 1137196 + right: 6192667 + - type: 1005320 + opt: 6762149 + left: 476992 + right: 7273329 + - type: 7120226 + opt: 8164982 + left: 5785837 + right: 502421 + - type: 4901949 + opt: 7475580 + left: 6677329 + right: 7563686 + - type: 4472052 + opt: 2436400 + left: 6868744 + right: 1303705 + - type: 8144381 + opt: 3396550 + left: 6882544 + right: 2727527 + - type: 82238 + opt: 5497381 + left: 1826648 + right: 7865472 + - type: 5620209 + opt: 6042580 + left: 8183917 + right: 2181149 + - type: 6796611 + opt: 6774590 + left: 5317344 + right: 5344695 + - type: 2622452 + opt: 5786132 + left: 5513966 + right: 8165611 +--- +test case: Auto-generated case 9 for random limit 7fffff +in: + stack: + - type: 5809739 + opt: 6582905 + left: 7539989 + right: 5598979 + - type: 7358748 + opt: 4533542 + left: 6042547 + right: 5202964 + - type: 1514300 + opt: 8240846 + left: 7062133 + right: 6411753 + - type: 563937 + opt: 7976503 + left: 5452173 + right: 7523562 + - type: 122995 + opt: 507970 + left: 5698047 + right: 4782012 + - type: 7029657 + opt: 2805391 + left: 5362331 + right: 5448267 + - type: 5272158 + opt: 6618780 + left: 5418676 + right: 4752604 + - type: 3650582 + opt: 5680691 + left: 2542875 + right: 4719685 + - type: 5822851 + opt: 188550 + left: 6459192 + right: 1104086 + - type: 8272830 + opt: 6447183 + left: 6869708 + right: 2781083 +--- +test case: Auto-generated case 10 for random limit 7fffff +in: + stack: + - type: 3039362 + opt: 4509624 + left: 5802981 + right: 8130365 + - type: 7966107 + opt: 2756672 + left: 1017860 + right: 5441100 + - type: 185027 + opt: 1276845 + left: 6713712 + right: 4971802 + - type: 3995436 + opt: 6769683 + left: 3201294 + right: 2837649 + - type: 1159771 + opt: 2410704 + left: 419352 + right: 4166682 + - type: 4430278 + opt: 3677423 + left: 4617684 + right: 1870787 + - type: 1364444 + opt: 5345167 + left: 295128 + right: 5577646 + - type: 7533553 + opt: 5764715 + left: 2072022 + right: 4905245 + - type: 2600765 + opt: 4894709 + left: 6972265 + right: 4234513 + - type: 1398272 + opt: 794331 + left: 4731401 + right: 5508956 +--- +test case: Auto-generated case 1 for random limit 7ffffff +in: + stack: + - type: 122874804 + opt: 118188782 + left: 114208215 + right: 79906807 + - type: 84420440 + opt: 126790013 + left: 114706322 + right: 104875477 + - type: 131926798 + opt: 126512924 + left: 18759675 + right: 117656452 + - type: 24064763 + opt: 69754731 + left: 49904844 + right: 42619476 + - type: 87783436 + opt: 72003417 + left: 106600345 + right: 72046560 + - type: 31040568 + opt: 66219254 + left: 95342253 + right: 66245670 + - type: 14089890 + opt: 87394674 + left: 43213902 + right: 97599050 + - type: 6250779 + opt: 91652028 + left: 54160370 + right: 105020090 + - type: 42961846 + opt: 86348399 + left: 50226534 + right: 71931840 + - type: 98355192 + opt: 31005256 + left: 134133271 + right: 108184252 +--- +test case: Auto-generated case 2 for random limit 7ffffff +in: + stack: + - type: 39958424 + opt: 11828041 + left: 100332902 + right: 45647447 + - type: 24835935 + opt: 120800092 + left: 90841603 + right: 5220891 + - type: 95739892 + opt: 64609637 + left: 1851828 + right: 43748739 + - type: 100461531 + opt: 36199500 + left: 1890070 + right: 8526390 + - type: 86163845 + opt: 44125461 + left: 30036927 + right: 122357240 + - type: 120506061 + opt: 78930498 + left: 20385816 + right: 14142250 + - type: 54994743 + opt: 17129665 + left: 111704423 + right: 80013039 + - type: 999022 + opt: 32332199 + left: 91753773 + right: 110120392 + - type: 88895445 + opt: 118686564 + left: 115416181 + right: 132039879 + - type: 26013144 + opt: 104518325 + left: 78707965 + right: 60798027 +--- +test case: Auto-generated case 3 for random limit 7ffffff +in: + stack: + - type: 31023427 + opt: 13517062 + left: 53889412 + right: 59838186 + - type: 43847169 + opt: 76203381 + left: 3781714 + right: 26457091 + - type: 131435083 + opt: 101323694 + left: 76470851 + right: 91027786 + - type: 46502477 + opt: 6378516 + left: 94743997 + right: 56480186 + - type: 16808267 + opt: 52943967 + left: 126120050 + right: 104898657 + - type: 84975869 + opt: 98043149 + left: 47952038 + right: 2253638 + - type: 117773768 + opt: 30507285 + left: 63488682 + right: 125830998 + - type: 69293463 + opt: 133366207 + left: 86687077 + right: 122538913 + - type: 126798581 + opt: 34635099 + left: 24294449 + right: 97017439 + - type: 58392456 + opt: 35272870 + left: 18896151 + right: 76005076 +--- +test case: Auto-generated case 4 for random limit 7ffffff +in: + stack: + - type: 25320128 + opt: 22398325 + left: 128921030 + right: 53537924 + - type: 101059413 + opt: 122333473 + left: 132230401 + right: 103883580 + - type: 29407889 + opt: 6624693 + left: 71965876 + right: 132032731 + - type: 129499 + opt: 96462701 + left: 12759351 + right: 2548275 + - type: 26011232 + opt: 115476624 + left: 116842272 + right: 97212119 + - type: 131461542 + opt: 832696 + left: 127202151 + right: 50681376 + - type: 70390470 + opt: 53702249 + left: 43125724 + right: 115658857 + - type: 89231569 + opt: 28696163 + left: 133530847 + right: 17728863 + - type: 35182901 + opt: 3258166 + left: 98659429 + right: 13582704 + - type: 117064197 + opt: 97907669 + left: 126319294 + right: 86086400 +--- +test case: Auto-generated case 5 for random limit 7ffffff +in: + stack: + - type: 4352061 + opt: 112615353 + left: 64261027 + right: 28418880 + - type: 119310677 + opt: 36743574 + left: 115806772 + right: 91947300 + - type: 60434462 + opt: 73419422 + left: 14332905 + right: 11489238 + - type: 78760156 + opt: 83821259 + left: 36202997 + right: 23599624 + - type: 71859823 + opt: 8353092 + left: 62617403 + right: 94564295 + - type: 121923855 + opt: 9217456 + left: 122809723 + right: 88361680 + - type: 58104355 + opt: 34620288 + left: 96762521 + right: 27568576 + - type: 970159 + opt: 100031968 + left: 82293743 + right: 20903920 + - type: 119424984 + opt: 25072716 + left: 50986612 + right: 72438516 + - type: 29590797 + opt: 123569750 + left: 96249562 + right: 3891147 +--- +test case: Auto-generated case 6 for random limit 7ffffff +in: + stack: + - type: 42770925 + opt: 51488922 + left: 51273515 + right: 130414231 + - type: 100428667 + opt: 119933778 + left: 89377976 + right: 60459808 + - type: 100788953 + opt: 6156472 + left: 4980950 + right: 118967685 + - type: 91506084 + opt: 41026678 + left: 48274146 + right: 23274768 + - type: 132754091 + opt: 106486436 + left: 98670049 + right: 12409117 + - type: 832715 + opt: 31306073 + left: 50073831 + right: 79763656 + - type: 14781537 + opt: 112504346 + left: 104680263 + right: 110992292 + - type: 77182608 + opt: 3329021 + left: 103143174 + right: 22901825 + - type: 95617644 + opt: 97329972 + left: 77870600 + right: 47116561 + - type: 114524590 + opt: 56294763 + left: 119174366 + right: 58558962 +--- +test case: Auto-generated case 7 for random limit 7ffffff +in: + stack: + - type: 107627978 + opt: 131306270 + left: 48914189 + right: 49085760 + - type: 113656031 + opt: 96500959 + left: 23737856 + right: 32610649 + - type: 12916706 + opt: 89538026 + left: 34458599 + right: 22696115 + - type: 17767336 + opt: 120558696 + left: 73961268 + right: 99209496 + - type: 77792512 + opt: 118724192 + left: 130013749 + right: 33055446 + - type: 81057065 + opt: 96771268 + left: 16847286 + right: 41896049 + - type: 44672856 + opt: 67118673 + left: 8576956 + right: 7148045 + - type: 43395637 + opt: 109307959 + left: 103432351 + right: 103954988 + - type: 37982415 + opt: 33357091 + left: 61874241 + right: 125205097 + - type: 24115612 + opt: 5654669 + left: 65535283 + right: 102652136 +--- +test case: Auto-generated case 8 for random limit 7ffffff +in: + stack: + - type: 35698716 + opt: 119295938 + left: 101567174 + right: 90541290 + - type: 54040100 + opt: 114214668 + left: 18832601 + right: 127404846 + - type: 7129778 + opt: 2071176 + left: 117994623 + right: 103392519 + - type: 120109612 + opt: 113398356 + left: 113529269 + right: 22444126 + - type: 106566861 + opt: 94714864 + left: 12576375 + right: 22334299 + - type: 34458424 + opt: 128054924 + left: 65856217 + right: 128098551 + - type: 124179786 + opt: 84494399 + left: 12691151 + right: 6717115 + - type: 70096051 + opt: 93942178 + left: 132937362 + right: 77317178 + - type: 20330179 + opt: 67129796 + left: 32783997 + right: 116775113 + - type: 39636917 + opt: 34349299 + left: 26372612 + right: 24914707 +--- +test case: Auto-generated case 9 for random limit 7ffffff +in: + stack: + - type: 87091722 + opt: 100089700 + left: 120380566 + right: 105751410 + - type: 40282768 + opt: 98089731 + left: 34159389 + right: 68612592 + - type: 130209317 + opt: 2102013 + left: 30883357 + right: 24437090 + - type: 62048835 + opt: 16036160 + left: 9305768 + right: 115668440 + - type: 112996538 + opt: 55342471 + left: 50114537 + right: 14851207 + - type: 8437331 + opt: 127725291 + left: 83107919 + right: 99281565 + - type: 94604022 + opt: 91848028 + left: 58501377 + right: 98347590 + - type: 112837151 + opt: 104714738 + left: 44631842 + right: 48525671 + - type: 99699769 + opt: 104770755 + left: 101085031 + right: 31948587 + - type: 16160066 + opt: 37696066 + left: 125279183 + right: 32577895 +--- +test case: Auto-generated case 10 for random limit 7ffffff +in: + stack: + - type: 4325465 + opt: 107661258 + left: 40149303 + right: 23385550 + - type: 38504784 + opt: 32410874 + left: 72296647 + right: 98997772 + - type: 96731610 + opt: 77555672 + left: 106600926 + right: 93470297 + - type: 95185431 + opt: 65369926 + left: 133120245 + right: 7333795 + - type: 71846069 + opt: 18236305 + left: 127243800 + right: 108827883 + - type: 105358865 + opt: 84463728 + left: 132637831 + right: 118100352 + - type: 13232465 + opt: 116317452 + left: 37013488 + right: 124805268 + - type: 26725295 + opt: 9953442 + left: 58411385 + right: 132079404 + - type: 68153355 + opt: 130704117 + left: 115191021 + right: 132881979 + - type: 34588741 + opt: 110159845 + left: 129937266 + right: 7767754 +--- +test case: Auto-generated case 1 for random limit 7fffffff +in: + stack: + - type: 835508170 + opt: 917279953 + left: 667979992 + right: 1304087876 + - type: 463035674 + opt: 441940023 + left: 477471788 + right: 1559064056 + - type: 126415795 + opt: 835642135 + left: 252507011 + right: 305735438 + - type: 499371538 + opt: 1722437595 + left: 1974053411 + right: 2001501328 + - type: 1966098307 + opt: 715911580 + left: 953024959 + right: 987858301 + - type: 1370021142 + opt: 1823943518 + left: 971382312 + right: 485918666 + - type: 1747066990 + opt: 795270022 + left: 1855301088 + right: 1818823689 + - type: 2123035233 + opt: 55660401 + left: 1592903141 + right: 511752704 + - type: 741188429 + opt: 1031491022 + left: 1847426785 + right: 193428618 + - type: 1555672488 + opt: 142327485 + left: 615522737 + right: 746074325 +--- +test case: Auto-generated case 2 for random limit 7fffffff +in: + stack: + - type: 1803438020 + opt: 1183475442 + left: 1462649583 + right: 619023371 + - type: 1940320238 + opt: 1233157639 + left: 1544269674 + right: 1299235346 + - type: 2114492463 + opt: 851261361 + left: 1991245867 + right: 1169235805 + - type: 486887435 + opt: 149830340 + left: 557289683 + right: 515007712 + - type: 1258610586 + opt: 2021204422 + left: 93413084 + right: 189451813 + - type: 91040629 + opt: 1553606279 + left: 684366280 + right: 756495026 + - type: 979237243 + opt: 1786596014 + left: 1463230826 + right: 1222493128 + - type: 1532847932 + opt: 1440750585 + left: 971089194 + right: 1264366790 + - type: 615700439 + opt: 1338928829 + left: 1941867629 + right: 595565704 + - type: 1498035857 + opt: 804406402 + left: 552094123 + right: 893417985 +--- +test case: Auto-generated case 3 for random limit 7fffffff +in: + stack: + - type: 89732768 + opt: 387494460 + left: 1042040126 + right: 135265250 + - type: 357496411 + opt: 2115311650 + left: 89136825 + right: 39885812 + - type: 304138816 + opt: 2038105107 + left: 1521965095 + right: 888204397 + - type: 1134855952 + opt: 722729925 + left: 21802113 + right: 57193966 + - type: 1925033617 + opt: 1866061049 + left: 1924946029 + right: 327685888 + - type: 2131733762 + opt: 1753192684 + left: 1898329463 + right: 1357517759 + - type: 1082302676 + opt: 1838928052 + left: 744556386 + right: 1637907200 + - type: 1929561125 + opt: 1446807160 + left: 1040489310 + right: 1192998406 + - type: 424766384 + opt: 814097479 + left: 1481348923 + right: 2000691253 + - type: 1456025815 + opt: 1673732393 + left: 778159336 + right: 173140696 +--- +test case: Auto-generated case 4 for random limit 7fffffff +in: + stack: + - type: 744028061 + opt: 848706143 + left: 908577540 + right: 1228263185 + - type: 296917506 + opt: 392380011 + left: 1873554654 + right: 960574622 + - type: 1414415183 + opt: 1788219723 + left: 501810425 + right: 1194336919 + - type: 918392693 + opt: 531695617 + left: 1016332470 + right: 1696083017 + - type: 1308428005 + opt: 1796565320 + left: 1583479807 + right: 1519090228 + - type: 1114032170 + opt: 2020170470 + left: 1308013775 + right: 229384285 + - type: 674888069 + opt: 1738179181 + left: 1464202232 + right: 1838900021 + - type: 144787596 + opt: 289524714 + left: 396978692 + right: 1421373107 + - type: 193156880 + opt: 15951451 + left: 2019873799 + right: 239435392 + - type: 1992047163 + opt: 64971477 + left: 1050069609 + right: 1660433998 +--- +test case: Auto-generated case 5 for random limit 7fffffff +in: + stack: + - type: 2023418578 + opt: 1347377573 + left: 842035871 + right: 512143210 + - type: 1997276472 + opt: 2098302071 + left: 2012004696 + right: 561164636 + - type: 1721452409 + opt: 775069675 + left: 1973504771 + right: 1413051184 + - type: 1937693532 + opt: 387797597 + left: 2029321341 + right: 275756359 + - type: 3546065 + opt: 47007187 + left: 1658135726 + right: 503225794 + - type: 1682819560 + opt: 1314811317 + left: 1413791081 + right: 670967861 + - type: 306220120 + opt: 1706859477 + left: 314566082 + right: 137877393 + - type: 1848505728 + opt: 1302545742 + left: 824749083 + right: 2032614279 + - type: 1682815634 + opt: 875915954 + left: 583817824 + right: 1394593897 + - type: 681941250 + opt: 604391279 + left: 413373255 + right: 699460123 +--- +test case: Auto-generated case 6 for random limit 7fffffff +in: + stack: + - type: 333554057 + opt: 1789737236 + left: 333492094 + right: 376214351 + - type: 385941476 + opt: 1266351097 + left: 323534832 + right: 132180557 + - type: 1441816765 + opt: 1837817462 + left: 1880079730 + right: 1745147702 + - type: 410076659 + opt: 2002191832 + left: 1440560312 + right: 215034701 + - type: 225794474 + opt: 1589758678 + left: 1954334932 + right: 619437033 + - type: 1241844121 + opt: 296959707 + left: 281551925 + right: 400850717 + - type: 254746800 + opt: 1816912839 + left: 579470496 + right: 937431946 + - type: 1440345112 + opt: 1990550498 + left: 506594918 + right: 1884199525 + - type: 925278932 + opt: 584410276 + left: 1279002109 + right: 1791230534 + - type: 115037563 + opt: 1434842424 + left: 271648675 + right: 383693932 +--- +test case: Auto-generated case 7 for random limit 7fffffff +in: + stack: + - type: 856434806 + opt: 549611310 + left: 417922951 + right: 1278697934 + - type: 661346461 + opt: 631971868 + left: 1784166903 + right: 978385031 + - type: 556032728 + opt: 1917009422 + left: 734972372 + right: 1896910187 + - type: 1571805245 + opt: 733071361 + left: 1163426436 + right: 228377708 + - type: 1256451806 + opt: 1894132471 + left: 2039114354 + right: 1211216836 + - type: 832093388 + opt: 968139438 + left: 555350724 + right: 1620970228 + - type: 1786817589 + opt: 1843020733 + left: 387279068 + right: 1041003429 + - type: 882901097 + opt: 2068240463 + left: 258519807 + right: 319149720 + - type: 1903945597 + opt: 1215648048 + left: 1399946174 + right: 1474285376 + - type: 2007508711 + opt: 420571705 + left: 1894237686 + right: 1103238141 +--- +test case: Auto-generated case 8 for random limit 7fffffff +in: + stack: + - type: 872444242 + opt: 107614233 + left: 1638770649 + right: 1754915153 + - type: 276036020 + opt: 2054474500 + left: 306840610 + right: 1199770460 + - type: 270187923 + opt: 2019987719 + left: 1983709309 + right: 2070613945 + - type: 1466714864 + opt: 836931933 + left: 1581965139 + right: 700164199 + - type: 2063637358 + opt: 749796010 + left: 1020515535 + right: 559626280 + - type: 617242646 + opt: 1546690580 + left: 112140588 + right: 535969576 + - type: 1235785306 + opt: 1806832569 + left: 1002171936 + right: 1261314003 + - type: 1902084492 + opt: 1200971330 + left: 1084105212 + right: 330643309 + - type: 1581887973 + opt: 658967144 + left: 1443524167 + right: 1800378500 + - type: 215518655 + opt: 819047757 + left: 818825628 + right: 865761877 +--- +test case: Auto-generated case 9 for random limit 7fffffff +in: + stack: + - type: 662781794 + opt: 1333480534 + left: 948278800 + right: 573243310 + - type: 130766844 + opt: 1042654494 + left: 1165359505 + right: 1656351627 + - type: 1074276946 + opt: 1119096146 + left: 195694153 + right: 1805085221 + - type: 1653962556 + opt: 1162795119 + left: 2060143040 + right: 713774169 + - type: 494684249 + opt: 1319638573 + left: 979104640 + right: 1866013507 + - type: 916302633 + opt: 1679825010 + left: 2114387495 + right: 1399753607 + - type: 1648278869 + opt: 1000978166 + left: 1033487752 + right: 999587339 + - type: 1401704763 + opt: 148842996 + left: 989305506 + right: 1025137775 + - type: 544467038 + opt: 1743471217 + left: 1174241953 + right: 191747590 + - type: 163961414 + opt: 1296333620 + left: 1596169590 + right: 929626088 +--- +test case: Auto-generated case 10 for random limit 7fffffff +in: + stack: + - type: 1116885794 + opt: 1342322335 + left: 306857345 + right: 1907464746 + - type: 851894323 + opt: 858522050 + left: 1077251779 + right: 428807356 + - type: 1646204317 + opt: 1183988266 + left: 283867190 + right: 1775821236 + - type: 1035518098 + opt: 100056886 + left: 1710922242 + right: 79715731 + - type: 491413076 + opt: 1767724217 + left: 374022278 + right: 286445618 + - type: 1050639809 + opt: 1697328652 + left: 799318133 + right: 172825028 + - type: 1067133755 + opt: 1561125604 + left: 1445532682 + right: 1066401855 + - type: 667731423 + opt: 2115706446 + left: 151481334 + right: 1775787781 + - type: 1415720527 + opt: 1780314672 + left: 1815798809 + right: 506894502 + - type: 388771049 + opt: 1855606246 + left: 1218590293 + right: 785020079 +... diff --git a/tests/libs/zbxhistory/Makefile.am b/tests/libs/zbxhistory/Makefile.am index 4b47a289c8f..6f8f5eacfee 100644 --- a/tests/libs/zbxhistory/Makefile.am +++ b/tests/libs/zbxhistory/Makefile.am @@ -8,7 +8,6 @@ HISTORY_LIBS = \ $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ $(top_srcdir)/src/libs/zbxcomms/libzbxcomms.a \ $(top_srcdir)/src/libs/zbxcompress/libzbxcompress.a \ - $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ $(top_srcdir)/src/libs/zbxnix/libzbxnix.a \ $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \ $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ @@ -17,6 +16,7 @@ HISTORY_LIBS = \ $(top_srcdir)/src/libs/zbxconf/libzbxconf.a \ $(top_srcdir)/src/libs/zbxmemory/libzbxmemory.a \ $(top_srcdir)/src/libs/zbxhistory/libzbxhistory.a \ + $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \ $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ diff --git a/tests/libs/zbxserver/Makefile.am b/tests/libs/zbxserver/Makefile.am index bfb601796df..b4c9a175ce1 100755 --- a/tests/libs/zbxserver/Makefile.am +++ b/tests/libs/zbxserver/Makefile.am @@ -1,6 +1,5 @@ if SERVER SERVER_tests = \ - get_trigger_expression_constant \ evaluate_function \ substitute_lld_macros \ macro_fmttime @@ -40,13 +39,13 @@ COMMON_LIB_FILES = \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxmemory/libzbxmemory.a \ - $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ $(top_srcdir)/src/libs/zbxself/libzbxself.a \ $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ $(top_srcdir)/src/libs/zbxconf/libzbxconf.a \ $(top_srcdir)/src/libs/zbxmedia/libzbxmedia.a \ $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \ + $(top_srcdir)/src/libs/zbxeval/libzbxeval.a \ $(top_srcdir)/src/zabbix_server/availability/libavailability.a \ $(top_srcdir)/src/libs/zbxavailability/libzbxavailability.a \ $(top_srcdir)/src/libs/zbxipcservice/libzbxipcservice.a \ @@ -55,11 +54,11 @@ COMMON_LIB_FILES = \ $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \ $(top_srcdir)/src/libs/zbxcomms/libzbxcomms.a \ $(top_srcdir)/src/libs/zbxcompress/libzbxcompress.a \ - $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \ $(top_srcdir)/src/libs/zbxcommshigh/libzbxcommshigh.a \ $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \ + $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a \ $(top_srcdir)/src/libs/zbxipcservice/libzbxipcservice.a \ $(top_srcdir)/src/libs/zbxexec/libzbxexec.a \ @@ -74,6 +73,7 @@ COMMON_LIB_FILES = \ $(top_srcdir)/src/libs/zbxconf/libzbxconf.a \ $(top_srcdir)/src/libs/zbxhistory/libzbxhistory.a \ $(top_srcdir)/src/zabbix_server/libzbxserver.a \ + $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \ $(top_srcdir)/tests/libzbxmocktest.a \ $(top_srcdir)/tests/libzbxmockdata.a \ $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ @@ -83,18 +83,6 @@ COMMON_LIB_FILES = \ COMMON_COMPILER_FLAGS = -I@top_srcdir@/tests -get_trigger_expression_constant_SOURCES = \ - get_trigger_expression_constant.c - -get_trigger_expression_constant_LDADD = \ - $(COMMON_LIB_FILES) - -get_trigger_expression_constant_LDADD += @SERVER_LIBS@ - -get_trigger_expression_constant_LDFLAGS = @SERVER_LDFLAGS@ - -get_trigger_expression_constant_CFLAGS = $(COMMON_COMPILER_FLAGS) - substitute_lld_macros_SOURCES = \ substitute_lld_macros.c @@ -160,5 +148,6 @@ evaluate_function_CFLAGS = $(COMMON_COMPILER_FLAGS) \ -I@top_srcdir@/src/libs/zbxalgo \ -I@top_srcdir@/src/libs/zbxdbcache \ -I@top_srcdir@/src/libs/zbxhistory + endif diff --git a/tests/libs/zbxserver/evaluate_function.c b/tests/libs/zbxserver/evaluate_function.c index b0d31bf859f..58d8cbe1e5d 100644 --- a/tests/libs/zbxserver/evaluate_function.c +++ b/tests/libs/zbxserver/evaluate_function.c @@ -70,12 +70,13 @@ int __wrap_DCget_data_expected_from(zbx_uint64_t itemid, int *seconds) void zbx_mock_test_entry(void **state) { int err, expected_ret, returned_ret; - char *error = NULL, *returned_value = NULL; + char *error = NULL; const char *function, *params; DC_ITEM item; zbx_vcmock_ds_item_t *ds_item; zbx_timespec_t ts; zbx_mock_handle_t handle; + zbx_variant_t returned_value; err = zbx_vc_init(&error); zbx_mock_assert_result_eq("Value cache initialization failed", SUCCEED, err); @@ -97,8 +98,12 @@ void zbx_mock_test_entry(void **state) zbx_vcmock_set_time(handle, "time"); ts = zbx_vcmock_get_ts(); - if (SUCCEED != (returned_ret = evaluate_function(&returned_value, &item, function, params, &ts, &error))) + if (SUCCEED != (returned_ret = evaluate_function2(&returned_value, &item, function, params, &ts, &error))) + { printf("evaluate_function returned error: %s\n", error); + zbx_free(error); + } + zbx_vc_flush_stats(); expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return")); @@ -107,21 +112,41 @@ void zbx_mock_test_entry(void **state) if (SUCCEED == expected_ret) { const char *expected_value; - char *ptr; - double expected_dbl; + zbx_uint64_t expected_ui64; handle = zbx_mock_get_parameter_handle("out.value"); if (ZBX_MOCK_SUCCESS != (err = zbx_mock_string_ex(handle, &expected_value))) fail_msg("Cannot read output value: %s", zbx_mock_error_string(err)); - expected_dbl = strtod(expected_value, &ptr); - - if (ptr != expected_value && '\0' == *ptr) - zbx_mock_assert_double_eq("function result", expected_dbl, atof(returned_value)); - else - zbx_mock_assert_str_eq("function result", expected_value, returned_value); + switch (returned_value.type) + { + case ZBX_VARIANT_DBL: + zbx_mock_assert_double_eq("function result", atof(expected_value), + returned_value.data.dbl); + break; + case ZBX_VARIANT_UI64: + if (SUCCEED != is_uint64(expected_value, &expected_ui64)) + { + fail_msg("function result '" ZBX_FS_UI64 "' does not match expected result '%s'", + returned_value.data.ui64, expected_value); + + } + zbx_mock_assert_uint64_eq("function result", expected_ui64, returned_value.data.ui64); + break; + case ZBX_VARIANT_STR: + zbx_mock_assert_str_eq("function result", expected_value, returned_value.data.str); + break; + default: + fail_msg("function result '%s' has unexpected type '%s'", + zbx_variant_value_desc(&returned_value), + zbx_variant_type_desc(&returned_value)); + break; + } } - zbx_free(returned_value); + if (SUCCEED == returned_ret) + zbx_variant_clear(&returned_value); + + zbx_vcmock_ds_destroy(); ZBX_UNUSED(state); } diff --git a/tests/libs/zbxserver/evaluate_function.yaml b/tests/libs/zbxserver/evaluate_function.yaml index aa6ce9db17f..87fbc9dbe69 100644 --- a/tests/libs/zbxserver/evaluate_function.yaml +++ b/tests/libs/zbxserver/evaluate_function.yaml @@ -46,7 +46,7 @@ in: params: '' out: return: SUCCEED - value: '"xyz"' + value: 'xyz' --- test case: Evaluate last() <- '😓...' in: @@ -64,10 +64,10 @@ in: out: return: SUCCEED value: - header: '"' + header: '' page: 😓 pages: 20000 - footer: '"' + footer: '' --- test case: Evaluate last() <- '123' in: @@ -82,7 +82,7 @@ in: params: '' out: return: SUCCEED - value: '"123"' + value: '123' --- test case: Evaluate last() <- ' a b ' in: @@ -97,7 +97,7 @@ in: params: '' out: return: SUCCEED - value: '" a b "' + value: ' a b ' --- test case: Evaluate last() <- '\"c:\\\"' in: @@ -112,9 +112,9 @@ in: params: '' out: return: SUCCEED - value: '"\"c:\\\""' + value: '"c:\"' --- -test case: Evaluate abschange() <- 0.1, 0.2 +test case: Evaluate last(:now-10m) <- 0.1, 0.2 in: history: - itemid: 1 @@ -125,114 +125,36 @@ in: - value: 0.2 ts: 2017-01-10 10:00:30.000000000 +00:00 time: 2017-01-10 10:10:00.000000000 +00:00 - function: abschange - params: '' + function: last + params: :now-10m out: return: SUCCEED value: 0.1 --- -test case: Evaluate abschange() <- 10, 7 +test case: Evaluate avg(#2) in: history: - itemid: 1 value type: ITEM_VALUE_TYPE_UINT64 data: - - value: 10 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: 7 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: abschange - params: '' -out: - return: SUCCEED - value: 3 ---- -test case: Evaluate abschange() <- 'a', 'b' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_STR - data: - - value: a - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: b - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: abschange - params: '' -out: - return: SUCCEED - value: 1 ---- -test case: Evaluate abschange() <- 'x', 'x' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_TEXT - data: - - value: x - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: x - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: abschange - params: '' -out: - return: SUCCEED - value: 0 ---- -test case: Evaluate abschange() <- @log 'a', 'b' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_LOG - data: - - value: a - source: - logeventid: 1 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: b - source: - logeventid: 2 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: abschange - params: '' -out: - return: SUCCEED - value: 1 ---- -test case: Evaluate abschange() <- @log 'x', 'x' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_LOG - data: - - value: x - source: - logeventid: 1 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: x - source: - logeventid: 2 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: abschange - params: '' + - value: 1 + ts: 2017-01-10 10:01:00.000000000 +00:00 + - value: 2 + ts: 2017-01-10 10:02:00.000000000 +00:00 + - value: 3 + ts: 2017-01-10 10:03:00.000000000 +00:00 + - value: 4 + ts: 2017-01-10 10:04:00.000000000 +00:00 + - value: 5 + ts: 2017-01-10 10:05:00.000000000 +00:00 + time: 2017-01-10 10:05:00.000000000 +00:00 + function: avg + params: '#2' out: return: SUCCEED - value: 0 + value: 4.5 --- -test case: Evaluate avg(#2) +test case: Evaluate avg(3m) in: history: - itemid: 1 @@ -250,12 +172,12 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: avg - params: '#2' + params: 3m out: return: SUCCEED - value: 4.5 + value: 4 --- -test case: Evaluate avg(3m) +test case: Evaluate avg(180) in: history: - itemid: 1 @@ -273,12 +195,12 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: avg - params: '3m' + params: 180 out: return: SUCCEED value: 4 --- -test case: Evaluate avg(#2,1m) +test case: Evaluate avg(#2:now-1m) in: history: - itemid: 1 @@ -296,7 +218,7 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: avg - params: '#2,1m' + params: '#2:now-1m' out: return: SUCCEED value: 3.5 @@ -347,7 +269,7 @@ out: return: SUCCEED value: 0 --- -test case: Evaluate band(2m,2,1m) +test case: Evaluate band(#2:now-1m,2) in: history: - itemid: 1 @@ -365,130 +287,12 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: band - params: '#2,2,1m' + params: '#2:now-1m,2' out: return: SUCCEED value: 2 --- -test case: Evaluate change() <- 0.1, 0.2 -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_FLOAT - data: - - value: 0.1 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: 0.2 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: change - params: '' -out: - return: SUCCEED - value: 0.1 ---- -test case: Evaluate change() <- 10, 7 -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_UINT64 - data: - - value: 10 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: 7 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: change - params: '' -out: - return: SUCCEED - value: -3 ---- -test case: Evaluate change() <- 'a', 'b' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_STR - data: - - value: a - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: b - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: change - params: '' -out: - return: SUCCEED - value: 1 ---- -test case: Evaluate change() <- 'x', 'x' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_TEXT - data: - - value: x - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: x - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: change - params: '' -out: - return: SUCCEED - value: 0 ---- -test case: Evaluate change() <- @log 'a', 'b' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_LOG - data: - - value: a - source: - logeventid: 1 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: b - source: - logeventid: 2 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: change - params: '' -out: - return: SUCCEED - value: 1 ---- -test case: Evaluate change() <- @log 'x', 'x' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_LOG - data: - - value: x - source: - logeventid: 1 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: x - source: - logeventid: 2 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: change - params: '' -out: - return: SUCCEED - value: 0 ---- -test case: Evaluate count(#3,4,ge) +test case: Evaluate count(#3,ge,4) in: history: - itemid: 1 @@ -506,12 +310,12 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: count - params: '#3,4,ge' + params: '#3,ge,4' out: return: SUCCEED value: 2 --- -test case: Evaluate count(#3,o,like) +test case: Evaluate count(5m,like,"o") in: history: - itemid: 1 @@ -529,12 +333,12 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: count - params: '5m,"o",like' + params: '5m,like,"o"' out: return: SUCCEED value: 2 --- -test case: Evaluate count(#3,o$,regexp) +test case: Evaluate count(300,like,"o") in: history: - itemid: 1 @@ -552,12 +356,12 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: count - params: '5m,"o$",regexp' + params: '300,like,"o"' out: return: SUCCEED - value: 1 + value: 2 --- -test case: Evaluate count(#3,o,iregexp) +test case: Evaluate count(5m,regexp,"o$") in: history: - itemid: 1 @@ -575,88 +379,81 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: count - params: '5m,"o",iregexp' + params: '5m,regexp,"o$"' out: return: SUCCEED - value: 3 + value: 1 --- -test case: Evaluate count(#3,1/3,band) +test case: Evaluate count(5m,iregexp,"o") in: history: - itemid: 1 - value type: ITEM_VALUE_TYPE_UINT64 + value type: ITEM_VALUE_TYPE_STR data: - - value: 1 + - value: One ts: 2017-01-10 10:01:00.000000000 +00:00 - - value: 2 + - value: Two ts: 2017-01-10 10:02:00.000000000 +00:00 - - value: 3 + - value: Three ts: 2017-01-10 10:03:00.000000000 +00:00 - - value: 4 + - value: Four ts: 2017-01-10 10:04:00.000000000 +00:00 - - value: 5 + - value: Five ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: count - params: '5m,1/3,band' + params: '5m,iregexp,"o"' out: return: SUCCEED - value: 2 + value: 3 --- -test case: Evaluate count(#3,2/3,band) +test case: Evaluate count(5m,iregexp) in: history: - itemid: 1 - value type: ITEM_VALUE_TYPE_UINT64 + value type: ITEM_VALUE_TYPE_STR data: - - value: 1 + - value: One ts: 2017-01-10 10:01:00.000000000 +00:00 - - value: 2 + - value: Two ts: 2017-01-10 10:02:00.000000000 +00:00 - - value: 3 + - value: Three ts: 2017-01-10 10:03:00.000000000 +00:00 - - value: 4 + - value: Four ts: 2017-01-10 10:04:00.000000000 +00:00 - - value: 5 + - value: Five ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: count - params: '5m,2/3,band' -out: - return: SUCCEED - value: 1 ---- -test case: Evaluate date() -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_UINT64 - data: - - value: 1 - ts: 2017-01-10 10:01:00.000000000 +00:00 - time: 2017-12-23 12:34:56.000000000 +00:00 - function: date - params: '' + params: '5m,iregexp' out: return: SUCCEED - value: 20171223 + value: 5 --- -test case: Evaluate dayofmonth() +test case: Evaluate count(5m,eq) in: history: - itemid: 1 - value type: ITEM_VALUE_TYPE_UINT64 + value type: ITEM_VALUE_TYPE_STR data: - - value: 1 + - value: One ts: 2017-01-10 10:01:00.000000000 +00:00 - time: 2017-12-23 12:34:53.000000000 +00:00 - function: dayofmonth - params: '' + - value: Two + ts: 2017-01-10 10:02:00.000000000 +00:00 + - value: '' + ts: 2017-01-10 10:03:00.000000000 +00:00 + - value: Four + ts: 2017-01-10 10:04:00.000000000 +00:00 + - value: Five + ts: 2017-01-10 10:05:00.000000000 +00:00 + time: 2017-01-10 10:05:00.000000000 +00:00 + function: count + params: '5m,eq' out: return: SUCCEED - value: 23 + value: 1 --- -test case: Evaluate dayofweek() +test case: Evaluate count(5m,band,1/3) in: history: - itemid: 1 @@ -664,14 +461,22 @@ in: data: - value: 1 ts: 2017-01-10 10:01:00.000000000 +00:00 - time: 2020-03-17 12:34:53.000000000 +00:00 - function: dayofweek - params: '' + - value: 2 + ts: 2017-01-10 10:02:00.000000000 +00:00 + - value: 3 + ts: 2017-01-10 10:03:00.000000000 +00:00 + - value: 4 + ts: 2017-01-10 10:04:00.000000000 +00:00 + - value: 5 + ts: 2017-01-10 10:05:00.000000000 +00:00 + time: 2017-01-10 10:05:00.000000000 +00:00 + function: count + params: '5m,band,1/3' out: return: SUCCEED value: 2 --- -test case: Evaluate time() +test case: Evaluate count(5m,band,"2/3") in: history: - itemid: 1 @@ -679,20 +484,28 @@ in: data: - value: 1 ts: 2017-01-10 10:01:00.000000000 +00:00 - time: 2017-12-23 12:34:56.000000000 +00:00 - function: time - params: '' + - value: 2 + ts: 2017-01-10 10:02:00.000000000 +00:00 + - value: 3 + ts: 2017-01-10 10:03:00.000000000 +00:00 + - value: 4 + ts: 2017-01-10 10:04:00.000000000 +00:00 + - value: 5 + ts: 2017-01-10 10:05:00.000000000 +00:00 + time: 2017-01-10 10:05:00.000000000 +00:00 + function: count + params: '5m,band,2/3' out: return: SUCCEED - value: 123456 + value: 1 --- -test case: Evaluate delta(#4) +test case: Evaluate count(#3,ge) in: history: - itemid: 1 value type: ITEM_VALUE_TYPE_UINT64 data: - - value: 0 + - value: 1 ts: 2017-01-10 10:01:00.000000000 +00:00 - value: 2 ts: 2017-01-10 10:02:00.000000000 +00:00 @@ -703,19 +516,19 @@ in: - value: 5 ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: delta - params: '#4' + function: count + params: '#3,ge' out: - return: SUCCEED - value: 3 + return: FAIL + value: 2 --- -test case: Evaluate delta(4m,1m) +test case: Evaluate forecast(#5,1h) in: history: - itemid: 1 value type: ITEM_VALUE_TYPE_UINT64 data: - - value: 0 + - value: 1 ts: 2017-01-10 10:01:00.000000000 +00:00 - value: 2 ts: 2017-01-10 10:02:00.000000000 +00:00 @@ -726,165 +539,13 @@ in: - value: 5 ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: delta - params: '4m,1m' -out: - return: SUCCEED - value: 4 ---- -test case: Evaluate diff() <- 0.1, 0.2 -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_FLOAT - data: - - value: 0.1 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: 0.2 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: diff - params: '' -out: - return: SUCCEED - value: 1 ---- -test case: Evaluate diff() <- 0.123, 0.123 -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_FLOAT - data: - - value: 0.123 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: 0.123 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: diff - params: '' -out: - return: SUCCEED - value: 0 ---- -test case: Evaluate diff() <- 10, 7 -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_UINT64 - data: - - value: 10 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: 7 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: diff - params: '' -out: - return: SUCCEED - value: 1 ---- -test case: Evaluate diff() <- 1234567890, 1234567890 -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_UINT64 - data: - - value: 1234567890 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: 1234567890 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: diff - params: '' -out: - return: SUCCEED - value: 0 ---- -test case: Evaluate diff() <- 'a', 'b' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_STR - data: - - value: a - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: b - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: diff - params: '' -out: - return: SUCCEED - value: 1 ---- -test case: Evaluate diff() <- 'x', 'x' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_TEXT - data: - - value: x - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: x - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: diff - params: '' -out: - return: SUCCEED - value: 0 ---- -test case: Evaluate diff() <- @log 'a', 'b' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_LOG - data: - - value: a - source: - logeventid: 1 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: b - source: - logeventid: 2 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: diff - params: '' -out: - return: SUCCEED - value: 1 ---- -test case: Evaluate diff() <- @log 'x', 'x' -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_LOG - data: - - value: x - source: - logeventid: 1 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: x - source: - logeventid: 2 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: diff - params: '' + function: forecast + params: '#5,1h' out: return: SUCCEED - value: 0 + value: 65 --- -test case: Evaluate forecast(#5,,1h) +test case: Evaluate forecast(#5:now-1h,1h) in: history: - itemid: 1 @@ -902,12 +563,12 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: forecast - params: '#5,,1h' + params: '#5:now-1h,1h' out: return: SUCCEED - value: 65 + value: -1 --- -test case: Evaluate forecast(#5,1h,1h) +test case: Evaluate forecast(#5:now-1h,1h,test) in: history: - itemid: 1 @@ -925,12 +586,12 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: forecast - params: '#5,1h,1h' + params: '#5:now-1h,1h,test' out: - return: SUCCEED + return: FAIL value: -1 --- -test case: Evaluate fuzzytime(1) < @uint64 +test case: Evaluate fuzzytime(1s) < @uint64 in: history: - itemid: 1 @@ -940,12 +601,12 @@ in: ts: 2017-01-10 10:01:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: fuzzytime - params: '1' + params: '1s' out: return: SUCCEED value: 0 --- -test case: Evaluate fuzzytime(1) < @float +test case: Evaluate fuzzytime(1s) < @float in: history: - itemid: 1 @@ -955,12 +616,12 @@ in: ts: 2017-01-10 10:01:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: fuzzytime - params: '1' + params: '1s' out: return: SUCCEED value: 0 --- -test case: Evaluate iregexp(^o,#5) +test case: Evaluate find(#5,"iregexp","^o") in: history: - itemid: 1 @@ -971,13 +632,13 @@ in: - value: Two ts: 2017-01-10 10:02:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: iregexp - params: '^o,#5' + function: find + params: '#5,"iregexp","^o"' out: return: SUCCEED value: 1 --- -test case: Evaluate regexp(^o,#5) +test case: Evaluate find(#5,"regexp","^o") in: history: - itemid: 1 @@ -988,13 +649,13 @@ in: - value: Two ts: 2017-01-10 10:02:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: regexp - params: '^o,#5' + function: find + params: '#5,"regexp","^o"' out: return: SUCCEED value: 0 --- -test case: Evaluate str(o,#5) +test case: Evaluate find(#5,"like","o") in: history: - itemid: 1 @@ -1005,13 +666,13 @@ in: - value: Two ts: 2017-01-10 10:02:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: str - params: 'o,#5' + function: find + params: '#5,"like","o"' out: return: SUCCEED value: 1 --- -test case: Evaluate logeventid(^12) +test case: Evaluate logeventid("^12") in: history: - itemid: 1 @@ -1025,12 +686,12 @@ in: ts: 2017-01-10 10:00:00.000000000 +00:00 time: 2017-01-10 10:10:00.000000000 +00:00 function: logeventid - params: '^12' + params: '"^12"' out: return: SUCCEED value: 1 --- -test case: Evaluate logeventid(^34) +test case: Evaluate logeventid("^34") in: history: - itemid: 1 @@ -1044,7 +705,7 @@ in: ts: 2017-01-10 10:00:00.000000000 +00:00 time: 2017-01-10 10:10:00.000000000 +00:00 function: logeventid - params: '^34' + params: '"^34"' out: return: SUCCEED value: 0 @@ -1068,7 +729,7 @@ out: return: SUCCEED value: 4 --- -test case: Evaluate logsource('(Application|System)') <- Application +test case: Evaluate logsource("(Application|System)") <- Application in: history: - itemid: 1 @@ -1147,7 +808,7 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: max - params: '5m,2m' + params: '5m:now-2m' out: return: SUCCEED value: 3 @@ -1193,7 +854,7 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: min - params: '4m,2m' + params: '4m:now-2m' out: return: SUCCEED value: 1 @@ -1228,7 +889,7 @@ out: return: SUCCEED value: 0 --- -test case: Evaluate now() +test case: Evaluate percentile(5m,100) in: history: - itemid: 1 @@ -1236,14 +897,22 @@ in: data: - value: 1 ts: 2017-01-10 10:01:00.000000000 +00:00 + - value: 2 + ts: 2017-01-10 10:02:00.000000000 +00:00 + - value: 3 + ts: 2017-01-10 10:03:00.000000000 +00:00 + - value: 4 + ts: 2017-01-10 10:04:00.000000000 +00:00 + - value: 5 + ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: now - params: '' + function: percentile + params: '5m,100' out: return: SUCCEED - value: 1484042700 + value: 5 --- -test case: Evaluate percentile(5m,,100) +test case: Evaluate percentile(5m,50) in: history: - itemid: 1 @@ -1261,12 +930,12 @@ in: ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 function: percentile - params: '5m,,100' + params: '5m,50' out: return: SUCCEED - value: 5 + value: 3 --- -test case: Evaluate percentile(5m,,50) +test case: Evaluate sum(#4) in: history: - itemid: 1 @@ -1283,133 +952,160 @@ in: - value: 5 ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: percentile - params: '5m,,50' -out: - return: SUCCEED - value: 3 ---- -test case: Evaluate prev() <- 0.1, 0.2 -in: - history: - - itemid: 1 - value type: ITEM_VALUE_TYPE_FLOAT - data: - - value: 0.1 - ts: 2017-01-10 10:00:00.000000000 +00:00 - - value: 0.2 - ts: 2017-01-10 10:00:30.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: prev - params: '' + function: sum + params: '#4' out: return: SUCCEED - value: 0.1 + value: 14 --- -test case: Evaluate strlen() +test case: Evaluate sum(4m:now-1m) in: history: - itemid: 1 - value type: ITEM_VALUE_TYPE_STR + value type: ITEM_VALUE_TYPE_UINT64 data: - - value: One + - value: 1 ts: 2017-01-10 10:01:00.000000000 +00:00 - - value: Two + - value: 2 ts: 2017-01-10 10:02:00.000000000 +00:00 - - value: Three + - value: 3 ts: 2017-01-10 10:03:00.000000000 +00:00 - - value: Four + - value: 4 ts: 2017-01-10 10:04:00.000000000 +00:00 - - value: Five + - value: 5 ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: strlen - params: '' + function: sum + params: '4m:now-1m' out: return: SUCCEED - value: 4 + value: 10 --- -test case: Evaluate strlen(1m) +test case: Evaluate sum(2m) in: history: - itemid: 1 - value type: ITEM_VALUE_TYPE_STR + value type: ITEM_VALUE_TYPE_UINT64 data: - - value: One + - value: 1 ts: 2017-01-10 10:01:00.000000000 +00:00 - - value: Two + - value: 2 + ts: 2017-01-10 10:01:30.000000000 +00:00 + - value: 3 ts: 2017-01-10 10:02:00.000000000 +00:00 - - value: Three + - value: 4 + ts: 2017-01-10 10:02:30.000000000 +00:00 + - value: 5 ts: 2017-01-10 10:03:00.000000000 +00:00 - - value: Four + - value: 6 + ts: 2017-01-10 10:03:30.000000000 +00:00 + - value: 7 ts: 2017-01-10 10:04:00.000000000 +00:00 - - value: Five + - value: 8 + ts: 2017-01-10 10:04:30.000000000 +00:00 + - value: 9 ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: strlen - params: '1m' + function: sum + params: '2m' out: return: SUCCEED - value: 4 + value: 30 --- -test case: Evaluate strlen(,2m) +test case: Evaluate sum(#2) in: history: - itemid: 1 - value type: ITEM_VALUE_TYPE_STR + value type: ITEM_VALUE_TYPE_UINT64 data: - - value: One + - value: 1 ts: 2017-01-10 10:01:00.000000000 +00:00 - - value: Two + - value: 2 + ts: 2017-01-10 10:01:30.000000000 +00:00 + - value: 3 ts: 2017-01-10 10:02:00.000000000 +00:00 - - value: Three + - value: 4 + ts: 2017-01-10 10:02:30.000000000 +00:00 + - value: 5 ts: 2017-01-10 10:03:00.000000000 +00:00 - - value: Four + - value: 6 + ts: 2017-01-10 10:03:30.000000000 +00:00 + - value: 7 ts: 2017-01-10 10:04:00.000000000 +00:00 - - value: Five + - value: 8 + ts: 2017-01-10 10:04:30.000000000 +00:00 + - value: 9 ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: strlen - params: ',2m' + function: sum + params: '#2' out: return: SUCCEED - value: 5 + value: 17 --- -test case: Evaluate strlen() <- 😓 +test case: Evaluate sum(2m:now-1m) in: history: - itemid: 1 - value type: ITEM_VALUE_TYPE_STR + value type: ITEM_VALUE_TYPE_UINT64 data: - - value: 😓 + - value: 1 + ts: 2017-01-10 10:01:00.000000000 +00:00 + - value: 2 + ts: 2017-01-10 10:01:30.000000000 +00:00 + - value: 3 + ts: 2017-01-10 10:02:00.000000000 +00:00 + - value: 4 + ts: 2017-01-10 10:02:30.000000000 +00:00 + - value: 5 + ts: 2017-01-10 10:03:00.000000000 +00:00 + - value: 6 + ts: 2017-01-10 10:03:30.000000000 +00:00 + - value: 7 + ts: 2017-01-10 10:04:00.000000000 +00:00 + - value: 8 + ts: 2017-01-10 10:04:30.000000000 +00:00 + - value: 9 ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: strlen - params: '' + function: sum + params: '2m:now-1m' out: return: SUCCEED - value: 1 + value: 22 --- -test case: Evaluate strlen() <- @log +test case: Evaluate sum(#2:now-1m) in: history: - itemid: 1 - value type: ITEM_VALUE_TYPE_LOG + value type: ITEM_VALUE_TYPE_UINT64 data: - - value: xyz - source: - logeventid: 1 - severity: 1 - timestamp: 2 - ts: 2017-01-10 10:00:00.000000000 +00:00 - time: 2017-01-10 10:10:00.000000000 +00:00 - function: strlen - params: '' + - value: 1 + ts: 2017-01-10 10:01:00.000000000 +00:00 + - value: 2 + ts: 2017-01-10 10:01:30.000000000 +00:00 + - value: 3 + ts: 2017-01-10 10:02:00.000000000 +00:00 + - value: 4 + ts: 2017-01-10 10:02:30.000000000 +00:00 + - value: 5 + ts: 2017-01-10 10:03:00.000000000 +00:00 + - value: 6 + ts: 2017-01-10 10:03:30.000000000 +00:00 + - value: 7 + ts: 2017-01-10 10:04:00.000000000 +00:00 + - value: 8 + ts: 2017-01-10 10:04:30.000000000 +00:00 + - value: 9 + ts: 2017-01-10 10:05:00.000000000 +00:00 + time: 2017-01-10 10:05:00.000000000 +00:00 + function: sum + params: '#2:now-1m' out: return: SUCCEED - value: 3 + value: 13 --- -test case: Evaluate sum(#4) +test case: Evaluate timeleft(5m,65) in: history: - itemid: 1 @@ -1426,13 +1122,13 @@ in: - value: 5 ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: sum - params: '#4' + function: timeleft + params: '5m,65' out: return: SUCCEED - value: 14 + value: 3600 --- -test case: Evaluate sum(4m,1m) +test case: Evaluate timeleft(5m,65,test) in: history: - itemid: 1 @@ -1449,48 +1145,162 @@ in: - value: 5 ts: 2017-01-10 10:05:00.000000000 +00:00 time: 2017-01-10 10:05:00.000000000 +00:00 - function: sum - params: '4m,1m' + function: timeleft + params: '5m,65,test' +out: + return: FAIL + value: 3600 +--- +test case: Evaluate change() <- 0.1, 0.2 +in: + history: + - itemid: 1 + value type: ITEM_VALUE_TYPE_FLOAT + data: + - value: 0.1 + ts: 2017-01-10 10:00:00.000000000 +00:00 + - value: 0.2 + ts: 2017-01-10 10:00:30.000000000 +00:00 + time: 2017-01-10 10:10:00.000000000 +00:00 + function: change + params: '' out: return: SUCCEED - value: 10 + value: 0.1 --- -test case: Evaluate time() +test case: Evaluate change() <- 10, 7 in: history: - itemid: 1 value type: ITEM_VALUE_TYPE_UINT64 data: - - value: 1 + - value: 10 + ts: 2017-01-10 10:00:00.000000000 +00:00 + - value: 7 + ts: 2017-01-10 10:00:30.000000000 +00:00 + time: 2017-01-10 10:10:00.000000000 +00:00 + function: change + params: '' +out: + return: SUCCEED + value: -3 +--- +test case: Evaluate change() <- 'a', 'b' +in: + history: + - itemid: 1 + value type: ITEM_VALUE_TYPE_STR + data: + - value: a + ts: 2017-01-10 10:00:00.000000000 +00:00 + - value: b + ts: 2017-01-10 10:00:30.000000000 +00:00 + time: 2017-01-10 10:10:00.000000000 +00:00 + function: change + params: '' +out: + return: SUCCEED + value: 1 +--- +test case: Evaluate change() <- 'x', 'x' +in: + history: + - itemid: 1 + value type: ITEM_VALUE_TYPE_TEXT + data: + - value: x + ts: 2017-01-10 10:00:00.000000000 +00:00 + - value: x + ts: 2017-01-10 10:00:30.000000000 +00:00 + time: 2017-01-10 10:10:00.000000000 +00:00 + function: change + params: '' +out: + return: SUCCEED + value: 0 +--- +test case: Evaluate change() <- @log 'a', 'b' +in: + history: + - itemid: 1 + value type: ITEM_VALUE_TYPE_LOG + data: + - value: a + source: + logeventid: 1 + severity: 1 + timestamp: 2 + ts: 2017-01-10 10:00:00.000000000 +00:00 + - value: b + source: + logeventid: 2 + severity: 1 + timestamp: 2 + ts: 2017-01-10 10:00:30.000000000 +00:00 + time: 2017-01-10 10:10:00.000000000 +00:00 + function: change + params: '' +out: + return: SUCCEED + value: 1 +--- +test case: Evaluate change() <- @log 'x', 'x' +in: + history: + - itemid: 1 + value type: ITEM_VALUE_TYPE_LOG + data: + - value: x + source: + logeventid: 1 + severity: 1 + timestamp: 2 ts: 2017-01-10 10:00:00.000000000 +00:00 - time: 2017-12-23 12:34:56.000000000 +00:00 - function: time + - value: x + source: + logeventid: 2 + severity: 1 + timestamp: 2 + ts: 2017-01-10 10:00:30.000000000 +00:00 + time: 2017-01-10 10:10:00.000000000 +00:00 + function: change params: '' out: return: SUCCEED - value: 123456 + value: 0 --- -test case: Evaluate timeleft(5m,,65) +test case: Evaluate change() <- 18446744073709551610, 18446744073709551615 in: history: - itemid: 1 value type: ITEM_VALUE_TYPE_UINT64 data: - - value: 1 - ts: 2017-01-10 10:01:00.000000000 +00:00 - - value: 2 - ts: 2017-01-10 10:02:00.000000000 +00:00 - - value: 3 - ts: 2017-01-10 10:03:00.000000000 +00:00 - - value: 4 - ts: 2017-01-10 10:04:00.000000000 +00:00 - - value: 5 - ts: 2017-01-10 10:05:00.000000000 +00:00 - time: 2017-01-10 10:05:00.000000000 +00:00 - function: timeleft - params: '5m,,65' + - value: 18446744073709551610 + ts: 2017-01-10 10:00:00.000000000 +00:00 + - value: 18446744073709551615 + ts: 2017-01-10 10:00:30.000000000 +00:00 + time: 2017-01-10 10:10:00.000000000 +00:00 + function: change + params: '' out: return: SUCCEED - value: 3600 + value: 5 +--- +test case: Evaluate change() <- 18446744073709551615, 18446744073709551610 +in: + history: + - itemid: 1 + value type: ITEM_VALUE_TYPE_UINT64 + data: + - value: 18446744073709551615 + ts: 2017-01-10 10:00:00.000000000 +00:00 + - value: 18446744073709551610 + ts: 2017-01-10 10:00:30.000000000 +00:00 + time: 2017-01-10 10:10:00.000000000 +00:00 + function: change + params: '' +out: + return: SUCCEED + value: -5 ... diff --git a/tests/libs/zbxserver/substitute_lld_macros.c b/tests/libs/zbxserver/substitute_lld_macros.c index 462d8fb4c50..da66b6ffa5d 100644 --- a/tests/libs/zbxserver/substitute_lld_macros.c +++ b/tests/libs/zbxserver/substitute_lld_macros.c @@ -63,11 +63,6 @@ static int get_flags(const char *path) if (ZBX_MOCK_SUCCESS != err || ZBX_MOCK_SUCCESS != (err = zbx_mock_string(hflag, &flag))) fail_msg("Cannot read flag #%d: %s", flags_num, zbx_mock_error_string(err)); - - if (0 == strcmp(flag, "ZBX_TOKEN_TRIGGER")) - flags |= ZBX_TOKEN_TRIGGER; - else if (0 == strcmp(flag, "ZBX_TOKEN_NUMERIC")) - flags |= ZBX_TOKEN_NUMERIC; else if (0 == strcmp(flag, "ZBX_TOKEN_JSON")) flags |= ZBX_TOKEN_JSON; else if (0 == strcmp(flag, "ZBX_TOKEN_XML")) @@ -86,8 +81,6 @@ static int get_flags(const char *path) flags |= ZBX_TOKEN_STR_REPLACE; else if (0 == strcmp(flag, "ZBX_MACRO_ANY")) flags |= ZBX_MACRO_ANY; - else if (0 == strcmp(flag, "ZBX_MACRO_NUMERIC")) - flags |= ZBX_MACRO_NUMERIC; else if (0 == strcmp(flag, "ZBX_MACRO_JSON")) flags |= ZBX_MACRO_JSON; else if (0 == strcmp(flag, "ZBX_MACRO_XML")) diff --git a/tests/libs/zbxserver/substitute_lld_macros.yaml b/tests/libs/zbxserver/substitute_lld_macros.yaml index 44ead7601cb..04d1726517a 100644 --- a/tests/libs/zbxserver/substitute_lld_macros.yaml +++ b/tests/libs/zbxserver/substitute_lld_macros.yaml @@ -1,264 +1,49 @@ --- -test case: Expand '{1} < {#A}' with {#A}=1 +test case: Expand '={?{last(/{HOST.KEY}/key[{#A}]}}=' with {#A}=[] in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":1}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{1} < {#A}' -out: - expression: '{1} < 1' - return: SUCCEED ---- -test case: Expand '{1} < "{#A}"' with {#A}=1 -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":1}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{1} < "{#A}"' -out: - expression: '{1} < "1"' - return: SUCCEED ---- -test case: Expand '{1} < {#A}' -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":1}' - macros: [] - expression: '{1} < {#A}' -out: - expression: '{1} < {#A}' - return: SUCCEED ---- -test case: Expand '{1} < {#A}' with {#A}=x -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"x"}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{1} < {#A}' -out: - expression: '{1} < "x"' - return: SUCCEED ---- -test case: Expand '{1} < {#A}' with {#A}="x" -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"\"x\""}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{1} < {#A}' -out: - expression: '{1} < "\"x\""' - return: SUCCEED ---- -test case: Expand '{1} < "{#A}"' with {#A}="x" -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"\"x\""}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{1} < "{#A}"' -out: - expression: '{1} < "\"x\""' - return: SUCCEED ---- -test case: Expand '{1} < "{#A}"' -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"\"x\""}' - macros: [] - expression: '{1} < "{#A}"' -out: - expression: '{1} < "{#A}"' - return: SUCCEED ---- -test case: Expand '{1} = "x" and {2} < {#A}' with {#A}="x" -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"\"x\""}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{1} = "x" and {2} < {#A}' -out: - expression: '{1} = "x" and {2} < "\"x\""' - return: SUCCEED ---- -test case: Expand '{1} < "{#A}{#B}"' with {#A}=1,'{#B}'="x" -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":1, "b":"\"x\""}' - macros: - - {macro: '{#A}', path: $.a} - - {macro: '{#B}', path: $.b} - expression: '{1} < "{#A}{#B}"' -out: - expression: '{1} < "1\"x\""' - return: SUCCEED ---- -test case: Expand '{1} < "{#A}{#B}"' with {#A}=1,'{#B}'=2 -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":1, "b":2}' - macros: - - {macro: '{#A}', path: $.a} - - {macro: '{#B}', path: $.b} - expression: '{1} < "{#A}{#B}"' -out: - expression: '{1} < "12"' - return: SUCCEED ---- -test case: Expand '{1} < "{#A}{#B}"' with {#A}="x",'{#B}'="y" -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"\"x\"", "b":"\"y\""}' - macros: - - {macro: '{#A}', path: $.a} - - {macro: '{#B}', path: $.b} - expression: '{1} < "{#A}{#B}"' -out: - expression: '{1} < "\"x\"\"y\""' - return: SUCCEED ---- -test case: Expand '{1} < {#A}{#B}' with {#A}="x",'{#B}'="y" -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"\"x\"", "b":"\"y\""}' - macros: - - {macro: '{#A}', path: $.a} - - {macro: '{#B}', path: $.b} - expression: '{1} < {#A}{#B}' -out: - expression: '{1} < "\"x\"""\"y\""' - return: SUCCEED ---- -test case: Expand '{1} < {#A}{#B}' with {#A}=1,'{#B}'=0 -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":1, "b":0}' - macros: - - {macro: '{#A}', path: $.a} - - {macro: '{#B}', path: $.b} - expression: '{1} < {#A}{#B}' -out: - expression: '{1} < 10' - return: SUCCEED ---- -test case: Expand '{1} < "\"{#A}\"{#B}\""' with {#A}=\",'{#B}'=\ -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"\\\"", "b":"\\"}' - macros: - - {macro: '{#A}', path: $.a} - - {macro: '{#B}', path: $.b} - expression: '{1} < "\"{#A}\"{#B}\""' - return: SUCCEED -out: - expression: '{1} < "\"\\\"\"\\\""' - return: SUCCEED ---- -test case: Expand '{1} < " \" {#A} \" {#B} \" " and {#A}<>"\"{#B}" and " {#A} " = " {#A} "' with {#A}=",'{#B}'=\\ -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"\"", "b":"\\\\"}' - macros: - - {macro: '{#A}', path: $.a} - - {macro: '{#B}', path: $.b} - expression: '{1} < " \" {#A} \" {#B} \" " and {#A}<>"\"{#B}" and " {#A} " = " {#A} "' -out: - expression: '{1} < " \" \" \" \\\\ \" " and "\""<>"\"\\\\" and " \" " = " \" "' - return: SUCCEED ---- -test case: Expand '{1} < {#A}' with {#A}="" -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"", "b":"\\\\"}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{1} < {#A}' -out: - expression: '{1} < ""' - return: SUCCEED ---- -test case: Expand '{1} < "{#A}"' with {#A}="" -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"", "b":"\\\\"}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{1} < "{#A}"' -out: - expression: '{1} < ""' - return: SUCCEED ---- -test case: Expand '{2000} < {#A}' with {#A}=2e+3 -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":2e+3}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{2000} < {#A}' -out: - expression: '{2000} < 2e+3' - return: SUCCEED ---- -test case: Expand '{1} < "\\\"a\"" and {1} = {#A}' with {#A}="b" -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"\"b\""}' - macros: - - {macro: '{#A}', path: $.a} - expression: '{1} < "\\\"a\"" and {1} = {#A}' -out: - expression: '{1} < "\\\"a\"" and {1} = "\"b\""' - return: SUCCEED ---- -test case: Expand '{2} <> {$M:"context:\"\\/\""} and {1} < {#A}' with {#A}=x -in: - flags: [ZBX_MACRO_ANY, ZBX_TOKEN_TRIGGER] - lld: '{"a":"x"}' + flags: [ZBX_MACRO_ANY, ZBX_TOKEN_EXPRESSION_MACRO] + lld: '{"a":"[]"}' macros: - {macro: '{#A}', path: $.a} - expression: '{2} <> {$M:"context:\"\\/\""} and {1} < {#A}' + expression: '={?{last(/{HOST.KEY}/key[{#A}]}}=' out: - expression: '{2} <> {$M:"context:\"\\/\""} and {1} < "x"' + expression: '={?{last(/{HOST.KEY}/key[[]]}}=' return: SUCCEED --- -test case: Expand '={?{{HOST.KEY}:key[{#A}].last()}}=' with {#A}=[] +test case: Expand 'Expression:{?last(/host/key) = "{#A}" }.' with {#A}=value:"xyz" in: flags: [ZBX_MACRO_ANY, ZBX_TOKEN_EXPRESSION_MACRO] - lld: '{"a":"[]"}' + lld: '{"a":"value:\"xyz\""}' macros: - {macro: '{#A}', path: $.a} - expression: '={?{{HOST.HOST}:key[{#A}].last()}}=' + expression: 'Expression:{?last(/host/key) = "{#A}" }.' out: - expression: '={?{{HOST.HOST}:key["[]"].last()}}=' + expression: 'Expression:{?last(/host/key) = "value:\"xyz\"" }.' return: SUCCEED --- -test case: Expand 'Expression:{?{host:key.last()} = "{#A}" }.' with {#A}=value:"xyz" +test case: Expand '={?last(/host/key[{#A}],,{#A})}=' with {#A}=() in: flags: [ZBX_MACRO_ANY, ZBX_TOKEN_EXPRESSION_MACRO] - lld: '{"a":"value:\"xyz\""}' + lld: '{"a":"()"}' macros: - {macro: '{#A}', path: $.a} - expression: 'Expression:{?{host:key.last()} = "{#A}" }.' + expression: '={?last(/host/key[{#A}],,{#A})}=' out: - expression: 'Expression:{?{host:key.last()} = "value:\"xyz\"" }.' + expression: '={?last(/host/key[()],,"()")}=' return: SUCCEED --- -test case: Expand '={?{host:key[{#A}].last({#A})}}=' with {#A}=() +test case: Expand '={?func({#A})}=' with {#A}=() in: flags: [ZBX_MACRO_ANY, ZBX_TOKEN_EXPRESSION_MACRO] lld: '{"a":"()"}' macros: - {macro: '{#A}', path: $.a} - expression: '={?{host:key[{#A}].last({#A})}}=' + expression: '={?func({#A})}=' out: - expression: '={?{host:key[()].last("()")}}=' + expression: '={?func("()")}=' return: SUCCEED --- -test case: Expand '{?{$MACRO:"{#A}"} {?{host:key[{#B1},{#B2}].last({#B1},{#B2})}}' with {#A}=x"z, {#B1}=[], {#B2}=() +test case: Expand '{?{$MACRO:"{#A}"} {?last(/host/key[{#B1},{#B2}],{#B1},{#B2})}' with {#A}=x"z, {#B1}=[], {#B2}=() in: flags: [ZBX_MACRO_ANY, ZBX_TOKEN_EXPRESSION_MACRO] lld: '{"a":"x\"z", "b1":"[]", "b2":"()"}' @@ -266,43 +51,43 @@ in: - {macro: '{#A}', path: $.a} - {macro: '{#B1}', path: $.b1} - {macro: '{#B2}', path: $.b2} - expression: '{?{$MACRO:"{#A}"} {?{host:key[{#B1},{#B2}].last({#B1},{#B2})}}' + expression: '{?{$MACRO:"{#A}"} {?last(/host/key[{#B1},{#B2}],{#B1},{#B2})}' out: - expression: '{?{$MACRO:"x\"z"} {?{host:key["[]",()].last([],"()")}}' + expression: '{?{$MACRO:"x\"z"} {?last(/host/key["[]",()],[],"()")}' return: SUCCEED --- -test case: Expand '{?{host:key[{#B1},{#B2}].last({#B1},{#B2})}} {host:key[{#B1},{#B2}].last({#B1},{#B2})}' with {#B1}=[], {#B2}=() +test case: Expand '{?last(/host/key[{#B1},{#B2}],{#B1},{#B2})} last(/host/key[{#B1},{#B2}],{#B1},{#B2})' with {#B1}=[], {#B2}=() in: flags: [ZBX_MACRO_ANY, ZBX_TOKEN_EXPRESSION_MACRO] lld: '{"b1":"[]", "b2":"()"}' macros: - {macro: '{#B1}', path: $.b1} - {macro: '{#B2}', path: $.b2} - expression: '{?{host:key[{#B1},{#B2}].last({#B1},{#B2})}} {host:key[{#B1},{#B2}].last({#B1},{#B2})}' + expression: '{?last(/host/key[{#B1},{#B2}],{#B1},{#B2})} last(/host/key[{#B1},{#B2}],{#B1},{#B2})' out: - expression: '{?{host:key["[]",()].last([],"()")}} {host:key[[],()].last([],())}' + expression: '{?last(/host/key["[]",()],[],"()")} last(/host/key[[],()],[],())' return: SUCCEED --- -test case: Expand '{?{host:key[{#B1},{#B2}].last({#B1},{#B2})}} {?{host:key[{#B2},{#B1}].last({#B2},{#B1})}}' with {#B1}=[], {#B2}=() +test case: Expand '{?last(/host/key[{#B1},{#B2}],{#B1},{#B2})} {?last(/host/key[{#B2},{#B1}],{#B2},{#B1})}' with {#B1}=[], {#B2}=() in: flags: [ZBX_MACRO_ANY, ZBX_TOKEN_EXPRESSION_MACRO] lld: '{"b1":"[]", "b2":"()"}' macros: - {macro: '{#B1}', path: $.b1} - {macro: '{#B2}', path: $.b2} - expression: '{?{host:key[{#B1},{#B2}].last({#B1},{#B2})}} {?{host:key[{#B2},{#B1}].last({#B2},{#B1})}}' + expression: '{?last(/host/key[{#B1},{#B2}],{#B1},{#B2})} {?last(/host/key[{#B2},{#B1}],{#B2},{#B1})}' out: - expression: '{?{host:key["[]",()].last([],"()")}} {?{host:key[(),"[]"].last("()",[])}}' + expression: '{?last(/host/key["[]",()],[],"()")} {?last(/host/key[(),"[]"],(),"[]")}' return: SUCCEED --- -test case: Expand 'Expression:{?{host:key.last()} = "{#A}" }.' with {#A}='= "xyz"' +test case: Expand 'Expression:{?last(/host/key) {#A} }.' with {#A}='= "xyz"' in: flags: [ZBX_MACRO_ANY, ZBX_TOKEN_EXPRESSION_MACRO] lld: '{"a":"= \"xyz\""}' macros: - {macro: '{#A}', path: $.a} - expression: 'Expression:{?{host:key.last()} {#A} }.' + expression: 'Expression:{?last(/host/key) {#A} }.' out: - expression: 'Expression:{?{host:key.last()} = "xyz" }.' + expression: 'Expression:{?last(/host/key) = "xyz" }.' return: SUCCEED ... diff --git a/tests/libs/zbxtrends/zbx_trends_parse_range.c b/tests/libs/zbxtrends/zbx_trends_parse_range.c index 7a2eea47f95..f1d6c1fea55 100644 --- a/tests/libs/zbxtrends/zbx_trends_parse_range.c +++ b/tests/libs/zbxtrends/zbx_trends_parse_range.c @@ -51,7 +51,7 @@ DB_RESULT __wrap_DBselect(const char *fmt, ...) void zbx_mock_test_entry(void **state) { - const char *period, *shift; + const char *param; int expected_ret, returned_ret, start, end; char *error = NULL; zbx_timespec_t ts_from, ts_start, ts_end, ts; @@ -66,11 +66,10 @@ void zbx_mock_test_entry(void **state) if (ZBX_MOCK_SUCCESS != zbx_strtime_to_timespec(zbx_mock_get_parameter_string("in.time"), &ts_from)) fail_msg("Invalid input time format"); - period = zbx_mock_get_parameter_string("in.period"); - shift = zbx_mock_get_parameter_string("in.shift"); + param = zbx_mock_get_parameter_string("in.param"); expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return")); - returned_ret = zbx_trends_parse_range(ts_from.sec, period, shift, &start, &end, &error); + returned_ret = zbx_trends_parse_range(ts_from.sec, param, &start, &end, &error); if (FAIL == returned_ret) { diff --git a/tests/libs/zbxtrends/zbx_trends_parse_range.yaml b/tests/libs/zbxtrends/zbx_trends_parse_range.yaml index 2f2202322fb..aabcd17d562 100644 --- a/tests/libs/zbxtrends/zbx_trends_parse_range.yaml +++ b/tests/libs/zbxtrends/zbx_trends_parse_range.yaml @@ -1,8 +1,7 @@ --- test case: Invalid period '' in: - period: - shift: now/h + param: :now/h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -10,8 +9,7 @@ out: --- test case: Invalid period 'h' in: - period: h - shift: now/h + param: h:now/h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -19,8 +17,7 @@ out: --- test case: Invalid period '1' in: - period: 1 - shift: now/h + param: 1:now/h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -28,8 +25,7 @@ out: --- test case: Invalid period '1H' in: - period: 1H - shift: now/h + param: 1H:now/h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -37,8 +33,7 @@ out: --- test case: Invalid period '0h' in: - period: 0h - shift: now/h + param: 0h:now/h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -46,8 +41,7 @@ out: --- test case: Invalid period '12345678901234567890h' in: - period: 12345678901234567890h - shift: now/h + param: 12345678901234567890h:now/h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -55,8 +49,7 @@ out: --- test case: Valid period '1h' in: - period: 1h - shift: now/h + param: 1h:now/h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -66,8 +59,7 @@ out: --- test case: Invalid period shift '/h' in: - period: 1h - shift: /h + param: 1h:/h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -75,8 +67,7 @@ out: --- test case: Invalid period shift 'now-1' in: - period: 1h - shift: now-1 + param: 1h:now-1 timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -84,8 +75,7 @@ out: --- test case: Invalid period shift 'now/h - 1' in: - period: 1h - shift: now/h - 1 + param: 1h:now/h - 1 timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -93,8 +83,7 @@ out: --- test case: Invalid period shift 'now/h-1' in: - period: 1h - shift: now/h-1 + param: 1h:now/h-1 timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -102,8 +91,7 @@ out: --- test case: Invalid period shift 'now/h - 1h' in: - period: 1h - shift: now/h - 1h + param: 1h:now/h - 1h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -111,8 +99,7 @@ out: --- test case: Invalid period shift 'now/m-1m' in: - period: 1h - shift: now/m-1m + param: 1h:now/m-1m timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -120,8 +107,7 @@ out: --- test case: Valid parameters '1h,now/h-1h' in: - period: 1h - shift: now/h-1h + param: 1h:now/h-1h timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -131,8 +117,7 @@ out: --- test case: Valid parameters '1h,now/d' in: - period: 1h - shift: now/d + param: 1h:now/d timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -142,8 +127,7 @@ out: --- test case: Valid parameters '1h,now/h' from 2020-09-01 10:00:00.000000000 +03:00 in: - period: 1h - shift: now/h + param: 1h:now/h timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: @@ -153,8 +137,7 @@ out: --- test case: Valid parameters '1h,now/d' from 2020-09-01 10:00:00.000000000 +03:00 in: - period: 1h - shift: now/d + param: 1h:now/d timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: @@ -164,8 +147,7 @@ out: --- test case: Valid parameters '1h,now/h-1d' from 2020-09-01 10:00:00.000000000 +03:00 in: - period: 1h - shift: now/h-1d + param: 1h:now/h-1d timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: @@ -175,8 +157,7 @@ out: --- test case: Valid parameters '1d,now/w-6d' from 2020-09-01 10:00:00.000000000 +03:00 in: - period: 1d - shift: now/w-6d + param: 1d:now/w-6d timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: @@ -186,8 +167,7 @@ out: --- test case: Valid parameters '1d,now/M-1M+6d/w+1d' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1d - shift: now/M-1M+6d/w+1d + param: 1d:now/M-1M+6d/w+1d timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -197,8 +177,7 @@ out: --- test case: Valid parameters '1w,now/M' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1w - shift: now/M + param: 1w:now/M timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -208,8 +187,7 @@ out: --- test case: Valid parameters '1M,now/M' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1M - shift: now/M + param: 1M:now/M timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -219,8 +197,7 @@ out: --- test case: Valid parameters '1M,now/M-1M' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1M - shift: now/M-1M + param: 1M:now/M-1M timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -230,8 +207,7 @@ out: --- test case: Valid parameters '1M,now/M-2M' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1M - shift: now/M-2M + param: 1M:now/M-2M timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -241,8 +217,7 @@ out: --- test case: Valid parameters '1d,now/y' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1d - shift: now/y + param: 1d:now/y timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -252,8 +227,7 @@ out: --- test case: Valid parameters '1h,now-1d' from 2020-09-01 10:00:00.000000000 +03:00 in: - period: 1h - shift: now-1d + param: 1h:now-1d timezone: :Europe/Riga time: 2020-09-01 10:00:00.000000000 +03:00 out: @@ -263,8 +237,7 @@ out: --- test case: Valid parameters '3h,now-1d/h' from 2020-09-01 10:30:00.000000000 +03:00 in: - period: 3h - shift: now-1d/h + param: 3h:now-1d/h timezone: :Europe/Riga time: 2020-09-01 10:30:00.000000000 +03:00 out: @@ -274,8 +247,7 @@ out: --- test case: Valid parameters '3h,now+1d-3d/w' from 2020-09-01 10:30:00.000000000 +03:00 in: - period: 3h - shift: now+1d-3d/w + param: 3h:now+1d-3d/w timezone: :Europe/Riga time: 2020-09-01 10:30:00.000000000 +03:00 out: @@ -285,8 +257,7 @@ out: --- test case: Invalid parameters '1M,now/h' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1M - shift: now/h + param: 1M:now/h timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -294,8 +265,7 @@ out: --- test case: Invalid parameters '1M,now/d' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1M - shift: now/d + param: 1M:now/d timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -303,8 +273,7 @@ out: --- test case: Invalid parameters '1M,now/w' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1M - shift: now/w + param: 1M:now/w timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -312,8 +281,7 @@ out: --- test case: Invalid parameters '1M,now/M-1h' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1M - shift: now/M-1h + param: 1M:now/M-1h timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -321,8 +289,7 @@ out: --- test case: Invalid parameters '1M,now/M-1d' from 2020-09-18 10:00:00.000000000 +03:00 in: - period: 1M - shift: now/M-1d + param: 1M:now/M-1d timezone: :Europe/Riga time: 2020-09-18 10:00:00.000000000 +03:00 out: @@ -330,8 +297,7 @@ out: --- test case: Valid period '1y' in: - period: 1y - shift: now/y + param: 1y:now/y timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -341,8 +307,7 @@ out: --- test case: Valid period '12M' in: - period: 12M - shift: now/y + param: 12M:now/y timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -352,8 +317,7 @@ out: --- test case: Valid period '366d' in: - period: 366d - shift: now/y + param: 366d:now/y timezone: :Europe/Riga time: 2021-09-01 00:00:00.000000000 +03:00 out: @@ -363,8 +327,7 @@ out: --- test case: Valid period '8784h' in: - period: 8784h - shift: now/y + param: 8784h:now/y timezone: :Europe/Riga time: 2021-09-01 00:00:00.000000000 +03:00 out: @@ -374,8 +337,7 @@ out: --- test case: Invalid period '2y' in: - period: 2y - shift: now/y + param: 2y:now/y timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -383,8 +345,7 @@ out: --- test case: Invalid period '13M' in: - period: 13M - shift: now/y + param: 13M:now/y timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -392,8 +353,7 @@ out: --- test case: Invalid period '367d' in: - period: 367d - shift: now/y + param: 367d:now/y timezone: :Europe/Riga time: 2020-09-01 00:00:00.000000000 +03:00 out: @@ -401,8 +361,7 @@ out: --- test case: Invalid period '8785h' in: - period: 8785h - shift: now/y + param: 8785h:now/y timezone: :Europe/Riga time: 2021-09-01 00:00:00.000000000 +03:00 out: @@ -410,8 +369,7 @@ out: --- test case: Invalid shift '26y' in: - period: 1h - shift: now/y-26y + param: 1h:now/y-26y timezone: :Europe/Riga time: 2021-09-01 00:00:00.000000000 +03:00 out: @@ -419,8 +377,7 @@ out: --- test case: Valid shift '25y' in: - period: 1h - shift: now/y-25y + param: 1h:now/y-25y timezone: :Europe/Riga time: 2021-09-01 00:00:00.000000000 +03:00 out: @@ -428,10 +385,9 @@ out: end: 1995-12-31 23:00:00.000000000 +02:00 return: SUCCEED --- -test case: Valid parameters '1h,now/M+6d/w+1h' from 2020-09-23 00:59:46.000000000 +03:00 +test case: Valid parameters '1h:now/M+6d/w+1h' from 2020-09-23 00:59:46.000000000 +03:00 in: - period: 1h - shift: now/M+6d/w+1h + param: 1h:now/M+6d/w+1h timezone: :Europe/Riga time: 2020-09-23 00:59:46.000000000 +03:00 out: |