Source
static void test_queue_ptr_remove_value(zbx_queue_ptr_t *queue, void **values, int values_num, void *value)
/*
** 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/>.
**/
static void mock_read_values(zbx_mock_handle_t hdata, zbx_vector_ptr_t *values)
{
zbx_mock_error_t err;
zbx_mock_handle_t hvalue;
while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(hdata, &hvalue))))
{
zbx_uint64_t value;
if (ZBX_MOCK_SUCCESS != (err = zbx_mock_uint64(hvalue, &value)))
{
fail_msg("Cannot read vector member: %s", zbx_mock_error_string(err));
}
zbx_vector_ptr_append(values, (void *)value);
}
}
static void test_queue_range_values(int iterations, zbx_vector_ptr_t *values)
{
zbx_queue_ptr_t queue;
void *ptr;
int i, j;
zbx_queue_ptr_create(&queue);
/* Test pushing/popping values from queue. Queue buffer size is always larger than the number */
/* of stored values, therefore pushing and popping N values from the queue will have different */
/* head/tail positions for each iteration, resulting in good brute force test with using various */
/* positions. */
for (j = 0; j < iterations; j++)
{
for (i = 0; i < values->values_num; i++)
{
zbx_queue_ptr_push(&queue, values->values[i]);
zbx_mock_assert_int_eq("quantity", zbx_queue_ptr_values_num(&queue), i + 1);
}
for (i = 0; i < values->values_num; i++)
{
ptr = zbx_queue_ptr_pop(&queue);
zbx_mock_assert_ptr_eq("value", ptr, values->values[i]);
}
ptr = zbx_queue_ptr_pop(&queue);
zbx_mock_assert_ptr_eq("value", NULL, ptr);
}
zbx_queue_ptr_destroy(&queue);
}
static void test_queue_range(void)
{
zbx_vector_ptr_t values;
zbx_vector_ptr_create(&values);
mock_read_values(zbx_mock_get_parameter_handle("in.values"), &values);
test_queue_range_values(ZBX_QUEUE_TEST_ITERATIONS, &values);
zbx_vector_ptr_destroy(&values);
}