Source
static zbx_mock_error_t zbx_mock_builtin_parameter(zbx_mock_parameter_t type, const char *name, zbx_mock_handle_t *parameter)
/*
** Zabbix
** 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 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.
**/
FILE *__real_fopen(const char *path, const char *mode);
int __real_fclose(FILE *stream);
static zbx_vector_ptr_t handle_pool; /* a place to store handles provided to mock data user */
static zbx_vector_str_t string_pool; /* a place to store strings provided to mock data user */
static yaml_document_t test_case; /* parsed YAML document with test case data */
static const yaml_node_t *root; /* the root document node */
static const yaml_node_t *in = NULL; /* pointer to "in" section of test case document */
static const yaml_node_t *out = NULL; /* pointer to "out" section of test case document */
static const yaml_node_t *db_data = NULL; /* pointer to "db data" section of test case document */
static const yaml_node_t *files = NULL; /* pointer to "files" section of test case document */
static const yaml_node_t *exit_code = NULL; /* pointer to "exit code" section of test case document */
typedef struct
{
const yaml_node_t *node; /* node of test_case document handle is associated with */
const yaml_node_item_t *item; /* current iterator position for vector handle */
}
zbx_mock_pool_handle_t;
typedef enum
{
ZBX_MOCK_IN, /* parameter from "in" section of test case data */
ZBX_MOCK_OUT, /* parameter from "out" section of test case data */
ZBX_MOCK_DB_DATA, /* data source from "db data" section of test case data */
ZBX_MOCK_FILES /* file contents from "files" section of test case data */
}
zbx_mock_parameter_t;
static const char *zbx_yaml_error_string(yaml_error_type_t error)
{
switch (error)
{
case YAML_NO_ERROR:
return "No error is produced.";
case YAML_MEMORY_ERROR:
return "Cannot allocate or reallocate a block of memory.";
case YAML_READER_ERROR:
return "Cannot read or decode the input stream.";
case YAML_SCANNER_ERROR:
return "Cannot scan the input stream.";
case YAML_PARSER_ERROR:
return "Cannot parse the input stream.";
case YAML_COMPOSER_ERROR:
return "Cannot compose a YAML document.";
case YAML_WRITER_ERROR:
return "Cannot write to the output stream.";
case YAML_EMITTER_ERROR:
return "Cannot emit a YAML stream.";
default:
return "Unknown error.";
}
}
static int zbx_yaml_scalar_cmp(const char *str, const yaml_node_t *node)
{
size_t len;
if (YAML_SCALAR_NODE != node->type)
fail_msg("Internal error: scalar comparison of nonscalar node.");
len = strlen(str);
ZBX_RETURN_IF_NOT_EQUAL(len, node->data.scalar.length);