diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libs/zbxconf/parse_cfg_file.c | 38 | ||||
-rw-r--r-- | tests/libs/zbxconf/parse_cfg_file.yaml | 2 | ||||
-rw-r--r-- | tests/zbxmockdata.c | 3 | ||||
-rw-r--r-- | tests/zbxmocktest.c | 10 |
4 files changed, 24 insertions, 29 deletions
diff --git a/tests/libs/zbxconf/parse_cfg_file.c b/tests/libs/zbxconf/parse_cfg_file.c index ccc4f8f89f5..131c8279c65 100644 --- a/tests/libs/zbxconf/parse_cfg_file.c +++ b/tests/libs/zbxconf/parse_cfg_file.c @@ -79,7 +79,7 @@ void zbx_mock_test_entry(void **state) if (0 == strcmp(tmp, "numeric")) { - if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "expected", &handle))) + if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "expect", &handle))) { expected_values[parameter_count] = NULL; } @@ -99,23 +99,6 @@ void zbx_mock_test_entry(void **state) cfg[parameter_count].variable = zbx_malloc(NULL, sizeof(zbx_uint64_t)); *(zbx_uint64_t *)cfg[parameter_count].variable = (zbx_uint64_t)-1; - if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "expected", &handle))) - { - expected_values[parameter_count] = NULL; - } - else if (ZBX_MOCK_SUCCESS == error && ZBX_MOCK_SUCCESS == (error = zbx_mock_string(handle, &tmp))) - { - expected_values[parameter_count] = zbx_malloc(NULL, sizeof(zbx_uint64_t)); - - if (SUCCEED != is_uint64(tmp, expected_values[parameter_count])) - { - fail_msg("Expected value \"%s\" of parameter #%d is not numeric.", tmp, - parameter_count + 1); - } - } - else - break; - if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "min", &handle))) { cfg[parameter_count].min = 0; @@ -154,7 +137,7 @@ void zbx_mock_test_entry(void **state) } else if (0 == strcmp(tmp, "string")) { - if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "expected", &handle))) + if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "expect", &handle))) { expected_values[parameter_count] = NULL; } @@ -176,7 +159,7 @@ void zbx_mock_test_entry(void **state) { expected_values[parameter_count] = zbx_malloc(NULL, sizeof(zbx_mock_handle_t)); - if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "expected", + if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "expect", expected_values[parameter_count]))) { fail_msg("Missing expected field for parameter #%d of string list type, use [] instead.", @@ -196,7 +179,7 @@ void zbx_mock_test_entry(void **state) { expected_values[parameter_count] = zbx_malloc(NULL, sizeof(zbx_mock_handle_t)); - if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "expected", + if (ZBX_MOCK_NO_SUCH_MEMBER == (error = zbx_mock_object_member(parameter, "expect", expected_values[parameter_count]))) { fail_msg("Missing expected field for parameter #%d of multi string type, use [] instead.", @@ -333,7 +316,18 @@ void zbx_mock_test_entry(void **state) } break; case TYPE_STRING: - if (0 != strcmp(*(char **)cfg[i].variable, *(char **)expected_values[i])) + if (NULL == *(char **)cfg[i].variable && NULL != *(char **)expected_values[i]) + { + fail_msg("No value of string parameter \"%s\" while expected \"%s\".", + cfg[i].parameter, *(char **)expected_values[i]); + } + else if (NULL != *(char **)cfg[i].variable && NULL == *(char **)expected_values[i]) + { + fail_msg("Got value \"%s\" of string parameter \"%s\" none was expected.", + *(char **)cfg[i].variable, cfg[i].parameter); + } + else if (NULL != *(char **)cfg[i].variable && NULL != *(char **)expected_values[i] && + 0 != strcmp(*(char **)cfg[i].variable, *(char **)expected_values[i])) { fail_msg("Value \"%s\" of string parameter \"%s\" differs from expected \"%s\".", *(char **)cfg[i].variable, cfg[i].parameter, diff --git a/tests/libs/zbxconf/parse_cfg_file.yaml b/tests/libs/zbxconf/parse_cfg_file.yaml index 14fe0cf2253..5a5c9de2fc7 100644 --- a/tests/libs/zbxconf/parse_cfg_file.yaml +++ b/tests/libs/zbxconf/parse_cfg_file.yaml @@ -29,7 +29,7 @@ files: Server = 1.2.3.4 , 5.6.7.8 , localhost LoadModule=dummy.so StartDBSyncers=4 - Include= db.conf # DB credentials + Include= db.conf LoadModule=smarty.so #LoadModule=beauty.so db.conf: | diff --git a/tests/zbxmockdata.c b/tests/zbxmockdata.c index 388bdb129ce..c1789ad79a6 100644 --- a/tests/zbxmockdata.c +++ b/tests/zbxmockdata.c @@ -82,7 +82,8 @@ static int zbx_yaml_scalar_cmp(const char *str, const yaml_node_t *node) if (YAML_SCALAR_NODE != node->type) fail_msg("Internal error: scalar comparison of nonscalar node."); - return strncmp(str, (const char *)node->data.scalar.value, node->data.scalar.length); + return strncmp(str, (const char *)node->data.scalar.value, node->data.scalar.length) || + strlen(str) > node->data.scalar.length; } static int zbx_yaml_scalar_ncmp(const char *str, size_t len, const yaml_node_t *node) diff --git a/tests/zbxmocktest.c b/tests/zbxmocktest.c index d65560c73bd..05fdc739cb8 100644 --- a/tests/zbxmocktest.c +++ b/tests/zbxmocktest.c @@ -149,11 +149,11 @@ char *CONFIG_SOCKET_PATH = NULL; char *CONFIG_HISTORY_STORAGE_URL = NULL; char *CONFIG_HISTORY_STORAGE_OPTS = NULL; -const char title_message[] = ""; -const char *usage_message[] = {NULL}; -const char *help_message[] = {NULL}; -const char *progname = NULL; -const char syslog_app_name[] = ""; +const char title_message[] = "mock_title_message"; +const char *usage_message[] = {"mock_usage_message", NULL}; +const char *help_message[] = {"mock_help_message", NULL}; +const char *progname = "mock_progname"; +const char syslog_app_name[] = "mock_syslog_app_name"; char *CONFIG_HOSTS_ALLOWED = NULL; char *CONFIG_HOSTNAME = NULL; |