#include "configcache_mock.h"
void mock_config_free_user_macros(void);
static int mock_um_macro_compare(const void *d1, const void *d2)
const zbx_um_macro_t *m1 = *(const zbx_um_macro_t * const *)d1;
const zbx_um_macro_t *m2 = *(const zbx_um_macro_t * const *)d2;
if (0 != (ret = strcmp(m1->name, m2->name)))
ZBX_RETURN_IF_NOT_EQUAL(m1->context_op, m2->context_op);
return zbx_strcmp_null(m1->context, m2->context);
void mock_config_load_user_macros(const char *path)
zbx_mock_handle_t hmacros, handle;
zbx_mock_config_t *mock_config = get_mock_config();
zbx_vector_um_host_create(&(mock_config->um_hosts));
hmacros = zbx_mock_get_parameter_handle(path);
while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(hmacros, &handle))))
zbx_um_host_t *host, host_local;
char *name = NULL, *context = NULL;
const char *macro_name, *macro_value;
zbx_mock_handle_t hhostid;
if (ZBX_MOCK_SUCCESS != err)
fail_msg("Cannot read 'macros' element #%d: %s", index, zbx_mock_error_string(err));
if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(handle, "hostid", &hhostid))
if (ZBX_MOCK_SUCCESS != zbx_mock_uint64(hhostid, &host_local.hostid))
fail_msg("Cannot parse macro hostid");
if (FAIL == (i = zbx_vector_um_host_search(&(mock_config->um_hosts), &host_local,
ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC)))
host = (zbx_um_host_t *)zbx_malloc(NULL, sizeof(zbx_um_host_t));
host->hostid = host_local.hostid;
zbx_vector_um_macro_create(&host->macros);
zbx_vector_uint64_create(&host->templateids);
zbx_vector_um_host_append(&(mock_config->um_hosts), host);
host = mock_config->um_hosts.values[i];
macro_name = zbx_mock_get_object_member_string(handle, "name");
macro_value = zbx_mock_get_object_member_string(handle, "value");
if (SUCCEED != zbx_user_macro_parse_dyn(macro_name, &name, &context, NULL, NULL))
fail_msg("invalid user macro: %s", macro_name);
macro = (zbx_um_macro_t *)zbx_malloc(NULL, sizeof(zbx_um_macro_t));