Source
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
void zbx_mock_test_entry(void **state)
{
/* variables for test infrastructure */
zbx_mock_error_t mock_ret_code; /* return code from zbx_mock_*() functions */
zbx_mock_handle_t mock_handle;
int expected_ret = 0;
const char *expected_error_msg = NULL, *expected_ret_str = NULL,
*expected_context_switches_str = NULL;
zbx_uint64_t expected_context_switches_count;
/* variables for calling function-under-test */
AGENT_REQUEST zbx_agent_request;
AGENT_RESULT zbx_agent_result;
int actual_ret;
ZBX_UNUSED(state);
/* set up test case values from an external source */
/* system_cpu_switches() does not use AGENT_REQUEST argument, only output parameters have to be set up */
if (ZBX_MOCK_SUCCESS != (mock_ret_code = zbx_mock_out_parameter("expected_ret", &mock_handle)) ||
ZBX_MOCK_SUCCESS != (mock_ret_code = zbx_mock_string(mock_handle, &expected_ret_str)))
{
fail_msg("Cannot get \"expected_ret\" parameter from test case data: %s",
zbx_mock_error_string(mock_ret_code));
}
if (0 == strcmp("SYSINFO_RET_OK", expected_ret_str))
expected_ret = SYSINFO_RET_OK;
else if (0 == strcmp("SYSINFO_RET_FAIL", expected_ret_str))
expected_ret = SYSINFO_RET_FAIL;
else
fail_msg("Invalid \"expected_ret\" parameter in test case data: %s", expected_ret_str);
if (SYSINFO_RET_OK == expected_ret)
{
if (ZBX_MOCK_SUCCESS != (mock_ret_code = zbx_mock_out_parameter("ctxt", &mock_handle)) ||
ZBX_MOCK_SUCCESS != (mock_ret_code = zbx_mock_string(mock_handle,
&expected_context_switches_str)))
{
fail_msg("Cannot get \"ctxt\" parameter from test case data: %s",
zbx_mock_error_string(mock_ret_code));