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

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergejs Paskevics <git-no-reply@zabbix.com>2017-11-02 10:52:39 +0300
committerSergejs Paskevics <git-no-reply@zabbix.com>2017-11-02 10:52:39 +0300
commit02721138fe9bdf86769f4c388f2448d048ddabe8 (patch)
tree6e3ff3610bc08f7126982b2cd7bf775167440870 /tests
parentc0f3966e8c9a847f946ce7ccd71320f9c2f74d47 (diff)
.......... [DEV-628] modified data initialisation; fixed some bugs
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/db_simulation.c92
-rw-r--r--tests/zabbix_server/Makefile.am2
-rw-r--r--tests/zabbix_server/escalator/Makefile.am74
-rw-r--r--tests/zabbix_server/escalator/process_escalations.c65
-rw-r--r--tests/zabbix_server/escalator/process_escalations.json40
-rw-r--r--tests/zabbix_server/taskmanager/try_task_closes_problem.c37
-rw-r--r--tests/zbxmockdata.c364
-rw-r--r--tests/zbxmockdata.h7
-rw-r--r--tests/zbxmocktest.c6
-rw-r--r--tests/zbxtests.h49
11 files changed, 436 insertions, 301 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 28a5b9a3a4b..d0652fa0323 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,7 +10,6 @@ SUBDIRS = \
noinst_LIBRARIES = libzbxmockdata.a
libzbxmockdata_a_SOURCES = \
- data.c \
db_simulation.c \
zbxmockdata.c \
zbxmockdata.h
diff --git a/tests/db_simulation.c b/tests/db_simulation.c
index 05c8236fabd..6ba2c93860d 100644
--- a/tests/db_simulation.c
+++ b/tests/db_simulation.c
@@ -19,9 +19,7 @@
#include "zbxtests.h"
-#define MAX_ROW_NUM 64
-
-extern char *curr_case_name;
+extern zbx_test_case_t *test_case;
char *generate_data_source(char *sql)
{
@@ -68,63 +66,39 @@ char *generate_data_source(char *sql)
return data_source;
}
-int get_db_rows(const char *case_name, char const *data_source, DB_ROW *rows)
+DB_RESULT __wrap_zbx_db_vselect(const char *fmt, va_list args)
{
- int row_num = -1, c, d, r;
+ DB_RESULT result = NULL;
+ char *sql = NULL, *data_source = NULL;
+ int i, r;
- for (c = 0; c < case_num; c++)
- {
- if (0 != strcmp(cases[c].case_name, case_name))
- continue;
+ sql = zbx_dvsprintf(sql, fmt, args);
- for (d = 0; d < cases[c].datasource_num; d++)
- {
- if (0 != strcmp(cases[c].datasources[d].source_name, data_source))
- continue;
+ if (NULL == (data_source = generate_data_source(sql)))
+ fail_msg("Cannot generate data source from sql!\nSQL:%s", sql);
- row_num = cases[c].datasources[d].row_num;
- for (r = 0; r < row_num; r++)
- rows[r] = cases[c].datasources[d].rows[r].values;
- }
+ for (i = 0; i < test_case->datasource_num; i++)
+ {
+ if (0 == strcmp(test_case->datasources[i].source_name, data_source))
+ break;
}
- return row_num;
-}
-
-void __wrap_DBfree_result(DB_RESULT result)
-{
- if (NULL == result)
- return;
-
- zbx_free(result);
-}
-
-DB_RESULT __wrap_zbx_db_vselect(const char *fmt, va_list args)
-{
- DB_RESULT result = NULL;
- char *sql = NULL, *data_source = NULL, *case_name;
-
- sql = zbx_dvsprintf(sql, fmt, args);
- case_name = curr_case_name;
-
- if (NULL != (data_source = generate_data_source(sql)))
+ if (i > test_case->datasource_num && 0 < test_case->datasources[i].row_num)
{
result = zbx_malloc(NULL, sizeof(struct zbx_db_result));
- result->rows = (DB_ROW *)zbx_malloc(NULL, sizeof(DB_ROW **) * MAX_ROW_NUM);
+ result->rows = (DB_ROW *)zbx_malloc(NULL, sizeof(DB_ROW **) * TEST_MAX_ROW_NUM);
result->data_source = data_source;
- result->case_name = case_name;
result->sql = sql;
result->cur_row_idx = 0;
- result->rows_num = get_db_rows(case_name, data_source, result->rows);
+ result->rows_num = test_case->datasources[i].row_num;
+
+ for (r = 0; r < result->rows_num ; r++)
+ result->rows[r] = test_case->datasources[i].rows[r].values;
}
else
- fail_msg("Cannot generate data source from sql!\nSQL:%s", sql);
-
- if (0 == result->rows_num)
{
zbx_free(sql);
zbx_free(data_source);
- zbx_free(result);
}
return result;
@@ -132,37 +106,33 @@ DB_RESULT __wrap_zbx_db_vselect(const char *fmt, va_list args)
DB_ROW __wrap_zbx_db_fetch(DB_RESULT result)
{
- DB_ROW row = NULL;
+ DB_ROW row = NULL;
if (NULL == result)
- goto out;
+ return NULL;
if (0 > result->rows_num)
{
fail_msg("Cannot find test suite for \"%s\" data source!\nSQL:%s\n",
- result->data_source, result->sql);
- goto out;
+ result->data_source, result->sql);
}
row = result->rows[result->cur_row_idx];
result->cur_row_idx++;
-out:
+
return row;
}
-int __wrap___zbx_DBexecute(const char *fmt, ...)
+void __wrap_DBfree_result(DB_RESULT result)
{
- ZBX_UNUSED(fmt);
-
- return 0;
+ zbx_free(result);
}
-void __wrap_DBbegin(void)
+int __wrap___zbx_DBexecute(const char *fmt, ...)
{
-}
+ ZBX_UNUSED(fmt);
-void __wrap_DBcommit(void)
-{
+ return 0;
}
int __wrap_DBexecute_multiple_query(const char *query, const char *field_name, zbx_vector_uint64_t *ids)
@@ -173,3 +143,11 @@ int __wrap_DBexecute_multiple_query(const char *query, const char *field_name, z
return SUCCEED;
}
+
+void __wrap_DBbegin(void)
+{
+}
+
+void __wrap_DBcommit(void)
+{
+}
diff --git a/tests/zabbix_server/Makefile.am b/tests/zabbix_server/Makefile.am
index 1d0deefde12..427f6012f04 100644
--- a/tests/zabbix_server/Makefile.am
+++ b/tests/zabbix_server/Makefile.am
@@ -1,3 +1,3 @@
SUBDIRS = \
- escalator \
taskmanager
+
diff --git a/tests/zabbix_server/escalator/Makefile.am b/tests/zabbix_server/escalator/Makefile.am
deleted file mode 100644
index 41fa50ccce7..00000000000
--- a/tests/zabbix_server/escalator/Makefile.am
+++ /dev/null
@@ -1,74 +0,0 @@
-noinst_PROGRAMS = process_escalations
-
-process_escalations_SOURCES = \
- process_escalations.json \
- process_escalations.c \
- ../../../src/zabbix_server/actions.c \
- ../../../src/zabbix_server/events.c \
- ../../../src/zabbix_server/operations.c \
- ../../zbxmocktest.c \
- ../../zbxmocktest.h
-
-process_escalations_LDADD = \
- $(top_srcdir)/src/zabbix_server/escalator/libzbxescalator.a \
- $(top_srcdir)/src/zabbix_server/scripts/libzbxscripts.a \
- $(top_srcdir)/src/zabbix_server/poller/libzbxpoller.a \
- $(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/zbxsysinfo/libzbxserversysinfo.a \
- $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \
- $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \
- $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \
- $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \
- $(top_srcdir)/src/libs/zbxdbcache/libzbxdbcache.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/zbxnix/libzbxnix.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/zbxcommon/libzbxcommon.a \
- $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \
- $(top_srcdir)/src/libs/zbxcomms/libzbxcomms.a \
- $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.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/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)/tests/libzbxmockdata.a
-
-process_escalations_LDADD += @SERVER_LIBS@
-
-process_escalations_LDFLAGS = \
- -Wl,--wrap=substitute_simple_macros \
- -Wl,--wrap=check_action_condition
-
-process_escalations_CFLAGS = -I@top_srcdir@/tests
diff --git a/tests/zabbix_server/escalator/process_escalations.c b/tests/zabbix_server/escalator/process_escalations.c
deleted file mode 100644
index fd5d8317126..00000000000
--- a/tests/zabbix_server/escalator/process_escalations.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-** Zabbix
-** Copyright (C) 2001-2017 Zabbix SIA
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-**/
-
-#include "../../zbxtests.h"
-
-#include "zbxmocktest.h"
-
-#include "../../../src/zabbix_server/escalator/escalator.h"
-
-/* make sure that mock functions match unwrapped prototypes */
-
-#define substitute_simple_macros __wrap_substitute_simple_macros
-#define check_action_condition __wrap_check_action_condition
-
-#include "zbxserver.h"
-#include "../../../src/zabbix_server/actions.h"
-
-int __wrap_substitute_simple_macros(zbx_uint64_t *actionid, const DB_EVENT *event, const DB_EVENT *r_event,
- zbx_uint64_t *userid, const zbx_uint64_t *hostid, const DC_HOST *dc_host, DC_ITEM *dc_item,
- DB_ALERT *alert, const DB_ACKNOWLEDGE *ack, char **data, int macro_type, char *error, int maxerrlen)
-{
- return SUCCEED;
-}
-
-int __wrap_check_action_condition(const DB_EVENT *event, DB_CONDITION *condition)
-{
- return SUCCEED;
-}
-
-void zbx_mock_test_entry(void **state)
-{
- int c, ret, param1, param2, param3;
-
- for (c = 0; c < case_num; c++)
- {
- if (0 == strcmp(cases[c].tested_function, "process_escalations"))
- {
- will_return_always(get_case_name, cases[c].case_name);
-
- param1 = atoi(cases[c].in_params.values[0]);
- param2 = atoi(cases[c].in_params.values[1]);
- param3 = atoi(cases[c].in_params.values[2]);
-
- ret = process_escalations(param1, &param2, (unsigned int) param3);
-
- assert_int_equal(ret, atoi(cases[c].out_params.values[0]));
- }
- }
-}
diff --git a/tests/zabbix_server/escalator/process_escalations.json b/tests/zabbix_server/escalator/process_escalations.json
deleted file mode 100644
index 48cd0043321..00000000000
--- a/tests/zabbix_server/escalator/process_escalations.json
+++ /dev/null
@@ -1,40 +0,0 @@
-[
- {
- "test_case": "case_1",
- "in": {
- "names": ["now", "nextcheck", "escalation_source"],
- "values": [1504082776, 1504082776, 2]
- },
- "out": {
- "names": ["return"],
- "values": [1]
- },
- "db_data": {
- "escalations": {
- "fields": [
- "escalationid", "actionid", "triggerid", "eventid", "r_eventid", "nextcheck", "esc_step", "status", "itemid", "acknowledgeid"
- ],
- "rows": [
- [1, 1, 1, 1, 0, 1501594532, 0, 0, 1, 0]
- ]
- },
- "actions": {
- "fields": [
- "actionid", "name", "status", "eventsource", "esc_period", "def_shortdata", "def_longdata", "r_shortdata", "r_longdata", "maintenance_mode", "ack_shortdata", "ack_longdata"
- ],
- "rows": [
- [1, "action name", 0, 0, "60s", "msg subject", "msg subject", "msg body", 0, "ack subject", "ack body"],
- [2, "action name", 0, 0, "60s", "msg subject", "msg subject", "msg body", 0, "ack subject", "ack body"]
- ]
- }
- },
- "functions": {
- "DCconfig_get_triggers_by_triggerids": {
- "out": {
- "params": ["triggerid", "status"],
- "values": [1, 0]
- }
- }
- }
- }
-]
diff --git a/tests/zabbix_server/taskmanager/try_task_closes_problem.c b/tests/zabbix_server/taskmanager/try_task_closes_problem.c
index 2e2d2278b60..483de669fda 100644
--- a/tests/zabbix_server/taskmanager/try_task_closes_problem.c
+++ b/tests/zabbix_server/taskmanager/try_task_closes_problem.c
@@ -18,21 +18,18 @@
**/
#include "../../zbxtests.h"
-
#include "zbxmocktest.h"
-
+#include "zbxmockdata.h"
#include "../../../src/zabbix_server/taskmanager/taskmanager.h"
-extern char *curr_tested_function;
extern char *curr_wrapped_function;
-extern char *curr_case_name;
-extern int curr_case_idx;
void __wrap_DCconfig_lock_triggers_by_triggerids(zbx_vector_uint64_t *triggerids_in,
zbx_vector_uint64_t *triggerids_out)
{
- int i;
- zbx_uint64_t triggerid;
+ zbx_uint64_t triggerid;
+
+ ZBX_UNUSED(triggerids_in);
curr_wrapped_function = "DCconfig_lock_triggers_by_triggerids";
@@ -46,27 +43,13 @@ void __wrap_DCconfig_unlock_triggers(const zbx_vector_uint64_t *triggerids)
void zbx_mock_test_entry(void **state)
{
- int i, ret, taskid, res, executed_num = 0;
-
- curr_tested_function = "try_task_closes_problem";
-
- for (i = 0; i < case_num; i++)
- {
- if (0 == strcmp(cases[i].tested_function, curr_tested_function))
- {
- curr_case_idx = i;
- curr_case_name = cases[i].case_name;
-
- taskid = atoi(get_in_param_by_name("taskid"));
- ret = tm_try_task_close_problem(taskid);
- res = atoi(get_out_param_by_name("return"));
+ int ret, taskid, res;
- assert_int_equal(ret, res);
+ ZBX_UNUSED(state);
- executed_num++;
- }
- }
+ taskid = atoi(get_in_param_by_name("taskid"));
+ ret = tm_try_task_close_problem(taskid);
+ res = atoi(get_out_param_by_name("return"));
- if (0 == executed_num)
- fail_msg("Test was not executed");
+ assert_int_equal(ret, res);
}
diff --git a/tests/zbxmockdata.c b/tests/zbxmockdata.c
index d88a79e37e0..85ba4fc7ecb 100644
--- a/tests/zbxmockdata.c
+++ b/tests/zbxmockdata.c
@@ -17,18 +17,378 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
+#include <stdio.h>
+#include "zbxtests.h"
#include "zbxmockdata.h"
+char *curr_wrapped_function = NULL;
+zbx_test_case_t *test_case = NULL;
+
int zbx_mock_data_init(void **state)
{
- (void) state;
+ char line[MAX_STRING_LEN], *tmp, *p;
+ int idx_str, line_type = ZBX_TEST_DATA_TYPE_UNKNOWN;
+ zbx_test_datasource_t *curr_ds = NULL;
+ zbx_test_data_t *curr_data = NULL;
+ zbx_test_function_t *curr_func = NULL;
+ zbx_test_row_t *curr_row = NULL;
+
+ ZBX_UNUSED(state);
+
+ test_case = malloc(sizeof(zbx_test_case_t));
+
+ test_case->datasources = malloc(TEST_MAX_DATASOURCE_NUM * sizeof(zbx_test_datasource_t));
+ test_case->datasource_num = 0;
+
+ test_case->functions = malloc(TEST_MAX_FUNCTION_NUM * sizeof(zbx_test_function_t));
+ test_case->function_num = 0;
+
+ test_case->in_params.data_num = 0;
+ test_case->out_params.data_num = 0;
+
+ while (fgets(line, MAX_STRING_LEN, stdin) != NULL)
+ {
+ idx_str = 0;
+ tmp = strdup(line);
+ zbx_rtrim(tmp, "\r\n");
+
+ p = strtok(tmp,"|");
+ while (p != NULL)
+ {
+ if (0 == idx_str) /* data type identification */
+ {
+ if (0 == strcmp(p, "DB_DATA"))
+ {
+ curr_ds = &test_case->datasources[test_case->datasource_num];
+ curr_ds->field_names = (char **)malloc(TEST_MAX_DATA_NUM * sizeof(char *));
+ curr_ds->field_num = 0;
+
+ test_case->datasource_num++;
+
+ line_type = ZBX_TEST_DATA_TYPE_DB_DATA;
+ }
+ else if (0 == strcmp(p, "FUNCTION"))
+ {
+ curr_func = &test_case->functions[test_case->function_num];
+ curr_func->data.data_num = 0;
+ test_case->function_num++;
+
+ line_type = ZBX_TEST_DATA_TYPE_FUNCTION;
+ }
+ else if (0 == strcmp(p, "IN_NAMES"))
+ {
+ curr_data = &test_case->in_params;
+ curr_data->names = (char **)malloc(TEST_MAX_DATA_NUM * sizeof(char *));
+ curr_data->data_num = 0;
+
+ line_type = ZBX_TEST_DATA_TYPE_IN_PARAM;
+ }
+ else if (0 == strcmp(p, "OUT_NAMES"))
+ {
+ curr_data = &test_case->out_params;
+ curr_data->names = (char **)malloc(TEST_MAX_DATA_NUM * sizeof(char *));
+ curr_data->data_num = 0;
+
+ line_type = ZBX_TEST_DATA_TYPE_OUT_PARAM;
+ }
+ else if (0 == strcmp(p, "IN_VALUES"))
+ {
+ curr_data = &test_case->in_params;
+ curr_data->values = (char **)malloc(TEST_MAX_DATA_NUM * sizeof(char *));
+
+ line_type = ZBX_TEST_DATA_TYPE_IN_VALUE;
+ }
+ else if (0 == strcmp(p, "OUT_VALUES"))
+ {
+ curr_data = &test_case->out_params;
+ curr_data->values = (char **)malloc(TEST_MAX_DATA_NUM * sizeof(char *));
+
+ line_type = ZBX_TEST_DATA_TYPE_OUT_VALUE;
+ }
+ else if (0 == strcmp(p, "FIELDS"))
+ {
+ curr_ds->rows = malloc(TEST_MAX_ROW_NUM * sizeof(zbx_test_row_t *));
+ curr_ds->row_num = 0;
+
+ line_type = ZBX_TEST_DATA_TYPE_DB_FIELD;
+ }
+ else if (0 == strcmp(p, "ROW"))
+ {
+ curr_row = &curr_ds->rows[curr_ds->row_num];
+ curr_row->values = (char **)malloc(TEST_MAX_DATA_NUM * sizeof(char *));
+ curr_row->value_num = 0;
+
+ curr_ds->row_num++;
+
+ line_type = ZBX_TEST_DATA_TYPE_DB_ROW;
+ }
+ else if (0 == strcmp(p, "FUNC_OUT_PARAMS"))
+ {
+ curr_data = &curr_func->data;
+ curr_data->names = (char **)malloc(TEST_MAX_DATA_NUM * sizeof(char *));
+ curr_data->data_num = 0;
+
+ line_type = ZBX_TEST_DATA_TYPE_FUNC_OUT;
+ }
+ else if (0 == strcmp(p, "FUNC_OUT_VALUES"))
+ {
+ curr_data = &curr_func->data;
+ curr_data->values = (char **)malloc(TEST_MAX_DATA_NUM * sizeof(char *));
+ curr_data->data_num = 0;
+
+ line_type = ZBX_TEST_DATA_TYPE_FUNC_VALUE;
+ }
+ else
+ {
+ line_type = ZBX_TEST_DATA_TYPE_UNKNOWN;
+ }
+ }
+ else if (0 < idx_str) /* filling in data */
+ {
+ switch (line_type)
+ {
+ case ZBX_TEST_DATA_TYPE_DB_DATA:
+ if (1 == idx_str && NULL != curr_data)
+ curr_ds->source_name = strdup(p);
+ break;
+ case ZBX_TEST_DATA_TYPE_FUNCTION:
+ if (1 == idx_str && NULL != curr_func)
+ curr_func->name = strdup(p);
+ break;
+ case ZBX_TEST_DATA_TYPE_IN_PARAM:
+ case ZBX_TEST_DATA_TYPE_OUT_PARAM:
+ case ZBX_TEST_DATA_TYPE_FUNC_OUT:
+ if (NULL != curr_data && NULL != curr_data->names)
+ curr_data->names[idx_str - 1] = strdup(p);
+ break;
+ case ZBX_TEST_DATA_TYPE_IN_VALUE:
+ case ZBX_TEST_DATA_TYPE_OUT_VALUE:
+ case ZBX_TEST_DATA_TYPE_FUNC_VALUE:
+ if (NULL != curr_data && NULL != curr_data->values)
+ {
+ curr_data->values[idx_str - 1] = strdup(p);
+ curr_data->data_num++;
+ }
+ break;
+ case ZBX_TEST_DATA_TYPE_DB_FIELD:
+ if (NULL != curr_ds && NULL != curr_ds->field_names)
+ {
+ curr_ds->field_names[idx_str - 1] = strdup(p);
+ curr_ds->field_num++;
+ }
+ break;
+ case ZBX_TEST_DATA_TYPE_DB_ROW:
+ if (NULL != curr_row && NULL != curr_row->values)
+ {
+ curr_row->values[idx_str - 1] = strdup(p);
+ curr_row->value_num++;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ p = strtok(NULL, "|");
+ idx_str++;
+ }
+ free(tmp);
+ }
return 0;
}
int zbx_mock_data_free(void **state)
{
- (void) state;
+ int n1, n2, n3;
+
+ ZBX_UNUSED(state);
+
+ for (n1 = 0; n1 < test_case->datasource_num; n1++)
+ {
+ free(test_case->datasources[n1].source_name);
+
+ for (n2 = 0; n2 < test_case->datasources[n1].field_num; n2++)
+ free(test_case->datasources[n1].field_names[n2]);
+
+ for (n2 = 0; n2 < test_case->datasources[n1].row_num; n2++)
+ {
+ for (n3 = 0; n3 < test_case->datasources[n1].rows[n2].value_num; n3++)
+ free(test_case->datasources[n1].rows[n2].values[n3]);
+ }
+ }
+
+ free(test_case->datasources);
+
+ for (n1 = 0; n1 < test_case->in_params.data_num; n1++)
+ {
+ free(test_case->in_params.names[n1]);
+ free(test_case->in_params.values[n1]);
+ }
+
+ free(test_case->in_params.names);
+ free(test_case->in_params.values);
+
+ for (n1 = 0; n1 < test_case->out_params.data_num; n1++)
+ {
+ free(test_case->out_params.names[n1]);
+ free(test_case->out_params.values[n1]);
+ }
+
+ free(test_case->out_params.names);
+ free(test_case->out_params.values);
+
+ for (n1 = 0; n1 < test_case->function_num; n1++)
+ {
+ free(test_case->functions[n1].name);
+
+ for (n2 = 0; n2 < test_case->functions[n1].data.data_num; n2++)
+ {
+ free(test_case->functions[n1].data.names[n2]);
+ free(test_case->functions[n1].data.values[n2]);
+ }
+
+ free(test_case->functions[n1].data.names);
+ free(test_case->functions[n1].data.values);
+
+ free(test_case->functions);
+ }
+
+ free(test_case);
return 0;
}
+
+void debug_print_cases(zbx_test_case_t *test_case)
+{
+ int n1, n2, n3;
+
+ printf("in_params.data_num %d\n", test_case->in_params.data_num);
+ for (n1 = 0; n1 < test_case->in_params.data_num; n1++)
+ {
+ printf(" in_params.name[%d]: %s\n", n1, test_case->in_params.names[n1]);
+ printf(" in_params.value[%d]: %s\n", n1, test_case->in_params.values[n1]);
+ }
+
+ printf("out_params.data_num %d\n", test_case->out_params.data_num);
+ for (n1 = 0; n1 < test_case->out_params.data_num; n1++)
+ {
+ printf(" out_params.name[%d]: %s\n", n1, test_case->out_params.names[n1]);
+ printf(" out_params.value[%d]: %s\n", n1, test_case->out_params.values[n1]);
+ }
+
+ printf("datasource_num %d\n", test_case->datasource_num);
+ for (n1 = 0; n1 < test_case->datasource_num; n1++)
+ {
+ printf(" datasources[%d].source_name: %s\n", n1, test_case->datasources[n1].source_name);
+ printf(" datasources[%d].field_num: %d\n", n1, test_case->datasources[n1].field_num);
+
+ for (n2 = 0; n2 < test_case->datasources[n1].field_num; n2++)
+ {
+ printf(" datasources.field_name[%d]: %s\n", n2,
+ test_case->datasources[n1].field_names[n2]);
+ }
+
+ for (n2 = 0; n2 < test_case->datasources[n1].row_num; n2++)
+ {
+ for (n3 = 0; n3 < test_case->datasources[n1].rows[n2].value_num; n3++)
+ {
+ printf(" datasources.row[%d].value[%d]: %s\n", n2, n3,
+ test_case->datasources[n1].rows[n2].values[n3]);
+ }
+ }
+ }
+
+ printf("function_num %d\n", test_case->function_num);
+ for (n1 = 0; n1 < test_case->function_num; n1++)
+ {
+ printf(" functions[%d]: %s\n", n1, test_case->functions[n1].name);
+
+ for (n2 = 0; n2 < test_case->functions[n1].data.data_num; n2++)
+ {
+ printf(" functions.name[%d]: %s\n", n2,
+ test_case->functions[n1].data.names[n2]);
+ printf(" functions.value[%d]: %s\n", n2,
+ test_case->functions[n1].data.values[n2]);
+ }
+ }
+}
+
+char *get_in_param_by_index(int idx)
+{
+ if (idx >= test_case->in_params.data_num)
+ return NULL;
+
+ return test_case->in_params.values[idx];
+}
+
+char *get_out_param_by_index(int idx)
+{
+ if (idx >= test_case->out_params.data_num)
+ return NULL;
+
+ return test_case->out_params.values[idx];
+}
+
+char *get_in_param_by_name(char *name)
+{
+ int i;
+
+ for (i = 0; i < test_case->in_params.data_num; i++)
+ {
+ if (0 == strcmp(test_case->in_params.names[i], name))
+ return test_case->in_params.values[i];
+ }
+
+ return "1";
+}
+
+char *get_out_param_by_name(char *name)
+{
+ int i;
+
+ for (i = 0; i < test_case->out_params.data_num; i++)
+ {
+ if (0 == strcmp(test_case->out_params.names[i], name))
+ return test_case->out_params.values[i];
+ }
+
+ return NULL;
+}
+
+char *get_out_func_param_by_index(int idx)
+{
+ int i;
+
+ for (i = 0; i < test_case->function_num; i++)
+ {
+ if (0 == strcmp(test_case->functions[i].name, curr_wrapped_function))
+ {
+ if (test_case->functions[i].data.data_num > idx)
+ goto out;
+
+ return test_case->functions[i].data.values[idx];
+ }
+ }
+out:
+ return NULL;
+}
+
+char *get_out_func_param_by_name(char *name)
+{
+ int i, n;
+
+ for (i = 0; i < test_case->function_num; i++)
+ {
+ if (0 == strcmp(test_case->functions[i].name, curr_wrapped_function))
+ {
+ for (n = 0; n < test_case->functions[i].data.data_num; n++)
+ {
+ if (0 == strcmp(test_case->functions[i].data.names[n], name))
+ return test_case->functions[i].data.values[n];
+ }
+ }
+ }
+
+ return NULL;
+}
diff --git a/tests/zbxmockdata.h b/tests/zbxmockdata.h
index c9839bbad2a..aa1cbea6783 100644
--- a/tests/zbxmockdata.h
+++ b/tests/zbxmockdata.h
@@ -23,4 +23,11 @@
int zbx_mock_data_init(void **state);
int zbx_mock_data_free(void **state);
+char *get_out_param_by_index(int idx);
+char *get_out_param_by_name(char *name);
+char *get_in_param_by_index(int idx);
+char *get_in_param_by_name(char *name);
+char *get_out_func_param_by_index(int idx);
+char *get_out_func_param_by_name(char *name);
+
#endif /* ZABBIX_MOCK_DATA_H */
diff --git a/tests/zbxmocktest.c b/tests/zbxmocktest.c
index 2d82172ed32..29ceca243bc 100644
--- a/tests/zbxmocktest.c
+++ b/tests/zbxmocktest.c
@@ -159,12 +159,12 @@ void zbx_on_exit(void)
/* test itself */
-int main(void)
+int main ()
{
const struct CMUnitTest tests[] =
{
- cmocka_unit_test(zbx_mock_test_entry)
+ cmocka_unit_test_setup_teardown(zbx_mock_test_entry, zbx_mock_data_init, zbx_mock_data_free)
};
- return cmocka_run_group_tests(tests, zbx_mock_data_init, zbx_mock_data_free);
+ return cmocka_run_group_tests(tests, NULL, NULL);
}
diff --git a/tests/zbxtests.h b/tests/zbxtests.h
index 3b497f064bd..52dc6b3ac63 100644
--- a/tests/zbxtests.h
+++ b/tests/zbxtests.h
@@ -35,20 +35,24 @@
#undef strcpy
#define ZBX_TEST_DATA_TYPE_UNKNOWN 0
-#define ZBX_TEST_DATA_TYPE_CASE 1
-#define ZBX_TEST_DATA_TYPE_PARAM_IN 2
-#define ZBX_TEST_DATA_TYPE_PARAM_OUT 3
-#define ZBX_TEST_DATA_TYPE_DB_DATA 4
-#define ZBX_TEST_DATA_TYPE_FUNCTION 5
-#define ZBX_TEST_DATA_TYPE_IN_PARAM 8
-#define ZBX_TEST_DATA_TYPE_IN_VALUE 9
-#define ZBX_TEST_DATA_TYPE_OUT_PARAM 10
-#define ZBX_TEST_DATA_TYPE_OUT_VALUE 11
-#define ZBX_TEST_DATA_TYPE_DB_FIELD 12
-#define ZBX_TEST_DATA_TYPE_DB_ROW 13
-#define ZBX_TEST_DATA_TYPE_FUNC_OUT 14
-#define ZBX_TEST_DATA_TYPE_FUNC_VALUE 15
-#define ZBX_TEST_DATA_TYPE_TESTED_FUNC 16
+#define ZBX_TEST_DATA_TYPE_PARAM_IN 1
+#define ZBX_TEST_DATA_TYPE_PARAM_OUT 2
+#define ZBX_TEST_DATA_TYPE_DB_DATA 3
+#define ZBX_TEST_DATA_TYPE_FUNCTION 4
+#define ZBX_TEST_DATA_TYPE_IN_PARAM 5
+#define ZBX_TEST_DATA_TYPE_IN_VALUE 6
+#define ZBX_TEST_DATA_TYPE_OUT_PARAM 7
+#define ZBX_TEST_DATA_TYPE_OUT_VALUE 8
+#define ZBX_TEST_DATA_TYPE_DB_FIELD 9
+#define ZBX_TEST_DATA_TYPE_DB_ROW 10
+#define ZBX_TEST_DATA_TYPE_FUNC_OUT 11
+#define ZBX_TEST_DATA_TYPE_FUNC_VALUE 12
+
+#define TEST_MAX_CASE_NUM 512
+#define TEST_MAX_DATASOURCE_NUM 1024
+#define TEST_MAX_FUNCTION_NUM 1024
+#define TEST_MAX_ROW_NUM 512
+#define TEST_MAX_DATA_NUM 512
typedef struct
{
@@ -84,8 +88,6 @@ zbx_test_function_t;
typedef struct
{
- char *case_name;
- char *tested_function;
int datasource_num;
int function_num;
zbx_test_data_t in_params;
@@ -96,24 +98,9 @@ typedef struct
}
zbx_test_case_t;
-zbx_test_case_t *cases;
-int case_num;
-
-char *get_in_param_by_index(int idx);
-char *get_out_param_by_index(int idx);
-char *get_in_param_by_name(const char *name);
-char *get_out_param_by_name(const char *name);
-char *get_out_func_param_by_idx(int idx);
-char *get_out_func_param_by_name(const char *name);
-
-int load_data(char *file_name);
-void free_data();
-void debug_print_cases();
-
struct zbx_db_result
{
char *data_source; /* "<table name>_" + "<table name>" + ... */
- char *case_name;
char *sql;
DB_ROW *rows;
int rows_num;