1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
/*
** Zabbix
** Copyright (C) 2001-2020 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.
**/
#include "zbxmocktest.h"
#include "zbxmockdata.h"
#include "zbxmockassert.h"
#include "zbxmockutil.h"
#include "common.h"
#include "module.h"
#include <malloc.h>
const char *zbx_mock_get_parameter_string(const char *path)
{
zbx_mock_error_t err;
zbx_mock_handle_t handle;
const char *parameter;
if (ZBX_MOCK_SUCCESS != (err = zbx_mock_parameter(path, &handle)) ||
ZBX_MOCK_SUCCESS != (err = zbx_mock_string(handle, ¶meter)))
{
fail_msg("Cannot read parameter at \"%s\": %s", path, zbx_mock_error_string(err));
}
return parameter;
}
const char *zbx_mock_get_object_member_string(zbx_mock_handle_t object, const char *name)
{
zbx_mock_error_t err;
zbx_mock_handle_t handle;
const char *member;
if (ZBX_MOCK_SUCCESS != (err = zbx_mock_object_member(object, name, &handle)) ||
ZBX_MOCK_SUCCESS != (err = zbx_mock_string(handle, &member)))
{
fail_msg("Cannot read object member \"%s\": %s", name, zbx_mock_error_string(err));
}
return member;
}
zbx_mock_handle_t zbx_mock_get_parameter_handle(const char *path)
{
zbx_mock_error_t err;
zbx_mock_handle_t parameter;
if (ZBX_MOCK_SUCCESS != (err = zbx_mock_parameter(path, ¶meter)))
fail_msg("Cannot read parameter at \"%s\": %s", path, zbx_mock_error_string(err));
return parameter;
}
zbx_mock_handle_t zbx_mock_get_object_member_handle(zbx_mock_handle_t object, const char *name)
{
zbx_mock_error_t err;
zbx_mock_handle_t member;
if (ZBX_MOCK_SUCCESS != (err = zbx_mock_object_member(object, name, &member)))
fail_msg("Cannot read object member \"%s\": %s", name, zbx_mock_error_string(err));
return member;
}
/******************************************************************************
* *
* Function: zbx_mock_str_to_token_type *
* *
* Purpose: converts token type from text format *
* *
******************************************************************************/
void zbx_mock_str_to_token_type(const char *str, int *out)
{
if (0 == strcmp(str, "ZBX_TOKEN_OBJECTID"))
*out = ZBX_TOKEN_OBJECTID;
else if (0 == strcmp(str, "ZBX_TOKEN_MACRO"))
*out = ZBX_TOKEN_MACRO;
else if (0 == strcmp(str, "ZBX_TOKEN_LLD_MACRO"))
*out = ZBX_TOKEN_LLD_MACRO;
else if (0 == strcmp(str, "ZBX_TOKEN_USER_MACRO"))
*out = ZBX_TOKEN_USER_MACRO;
else if (0 == strcmp(str, "ZBX_TOKEN_FUNC_MACRO"))
*out = ZBX_TOKEN_FUNC_MACRO;
else if (0 == strcmp(str, "ZBX_TOKEN_SIMPLE_MACRO"))
*out = ZBX_TOKEN_SIMPLE_MACRO;
else if (0 == strcmp(str, "ZBX_TOKEN_REFERENCE"))
*out = ZBX_TOKEN_REFERENCE;
else if (0 == strcmp(str, "ZBX_TOKEN_LLD_FUNC_MACRO"))
*out = ZBX_TOKEN_LLD_FUNC_MACRO;
else
fail_msg("Unknown token type \"%s\"", str);
}
/******************************************************************************
* *
* Function: zbx_mock_str_to_value_type *
* *
* Purpose: converts item value type from text format *
* *
******************************************************************************/
unsigned char zbx_mock_str_to_value_type(const char *str)
{
if (0 == strcmp(str, "ITEM_VALUE_TYPE_FLOAT"))
return ITEM_VALUE_TYPE_FLOAT;
if (0 == strcmp(str, "ITEM_VALUE_TYPE_STR"))
return ITEM_VALUE_TYPE_STR;
if (0 == strcmp(str, "ITEM_VALUE_TYPE_LOG"))
return ITEM_VALUE_TYPE_LOG;
if (0 == strcmp(str, "ITEM_VALUE_TYPE_UINT64"))
return ITEM_VALUE_TYPE_UINT64;
if (0 == strcmp(str, "ITEM_VALUE_TYPE_TEXT"))
return ITEM_VALUE_TYPE_TEXT;
fail_msg("Unknown value type \"%s\"", str);
return ITEM_VALUE_TYPE_MAX;
}
/******************************************************************************
* *
* Function: zbx_mock_str_to_item_type *
* *
* Purpose: converts item type from text format *
* *
******************************************************************************/
int zbx_mock_str_to_item_type(const char *str)
{
if (0 == strcmp(str, "ITEM_TYPE_ZABBIX"))
return ITEM_TYPE_ZABBIX;
if (0 == strcmp(str, "ITEM_TYPE_TRAPPER"))
return ITEM_TYPE_TRAPPER;
if (0 == strcmp(str, "ITEM_TYPE_SIMPLE"))
return ITEM_TYPE_SIMPLE;
if (0 == strcmp(str, "ITEM_TYPE_INTERNAL"))
return ITEM_TYPE_INTERNAL;
if (0 == strcmp(str, "ITEM_TYPE_ZABBIX_ACTIVE"))
return ITEM_TYPE_ZABBIX_ACTIVE;
if (0 == strcmp(str, "ITEM_TYPE_AGGREGATE"))
return ITEM_TYPE_AGGREGATE;
if (0 == strcmp(str, "ITEM_TYPE_HTTPTEST"))
return ITEM_TYPE_HTTPTEST;
if (0 == strcmp(str, "ITEM_TYPE_EXTERNAL"))
return ITEM_TYPE_EXTERNAL;
if (0 == strcmp(str, "ITEM_TYPE_DB_MONITOR"))
return ITEM_TYPE_DB_MONITOR;
if (0 == strcmp(str, "ITEM_TYPE_IPMI"))
return ITEM_TYPE_IPMI;
if (0 == strcmp(str, "ITEM_TYPE_SSH"))
return ITEM_TYPE_SSH;
if (0 == strcmp(str, "ITEM_TYPE_TELNET"))
return ITEM_TYPE_TELNET;
if (0 == strcmp(str, "ITEM_TYPE_CALCULATED"))
return ITEM_TYPE_CALCULATED;
if (0 == strcmp(str, "ITEM_TYPE_JMX"))
return ITEM_TYPE_JMX;
if (0 == strcmp(str, "ITEM_TYPE_SNMPTRAP"))
return ITEM_TYPE_SNMPTRAP;
if (0 == strcmp(str, "ITEM_TYPE_DEPENDENT"))
return ITEM_TYPE_DEPENDENT;
if (0 == strcmp(str, "ITEM_TYPE_HTTPAGENT"))
return ITEM_TYPE_HTTPAGENT;
if (0 == strcmp(str, "ITEM_TYPE_SNMP"))
return ITEM_TYPE_SNMP;
return FAIL;
}
/******************************************************************************
* *
* Function: zbx_mock_str_to_variant *
* *
* Purpose: converts variant from text format *
* *
******************************************************************************/
unsigned char zbx_mock_str_to_variant(const char *str)
{
if (0 == strcmp(str, "ZBX_VARIANT_NONE"))
return ZBX_VARIANT_NONE;
if (0 == strcmp(str, "ZBX_VARIANT_STR"))
return ZBX_VARIANT_STR;
if (0 == strcmp(str, "ZBX_VARIANT_DBL"))
return ZBX_VARIANT_DBL;
if (0 == strcmp(str, "ZBX_VARIANT_UI64"))
return ZBX_VARIANT_UI64;
fail_msg("Unknown variant \"%s\"", str);
return ZBX_VARIANT_NONE;
}
zbx_uint64_t zbx_mock_get_parameter_uint64(const char *path)
{
zbx_mock_error_t err;
zbx_mock_handle_t handle;
zbx_uint64_t parameter;
if (ZBX_MOCK_SUCCESS != (err = zbx_mock_parameter(path, &handle)) ||
ZBX_MOCK_SUCCESS != (err = zbx_mock_uint64(handle, ¶meter)))
{
fail_msg("Cannot read parameter at \"%s\": %s", path, zbx_mock_error_string(err));
}
return parameter;
}
zbx_uint64_t zbx_mock_get_object_member_uint64(zbx_mock_handle_t object, const char *name)
{
zbx_mock_error_t err;
zbx_mock_handle_t handle;
zbx_uint64_t member;
if (ZBX_MOCK_SUCCESS != (err = zbx_mock_object_member(object, name, &handle)) ||
ZBX_MOCK_SUCCESS != (err = zbx_mock_uint64(handle, &member)))
{
fail_msg("Cannot read object member \"%s\": %s", name, zbx_mock_error_string(err));
}
return member;
}
double zbx_mock_get_parameter_float(const char *path)
{
zbx_mock_error_t err;
zbx_mock_handle_t handle;
double parameter;
if (ZBX_MOCK_SUCCESS != (err = zbx_mock_parameter(path, &handle)) ||
ZBX_MOCK_SUCCESS != (err = zbx_mock_float(handle, ¶meter)))
{
fail_msg("Cannot read parameter at \"%s\": %s", path, zbx_mock_error_string(err));
}
return parameter;
}
double zbx_mock_get_object_member_float(zbx_mock_handle_t object, const char *name)
{
zbx_mock_error_t err;
zbx_mock_handle_t handle;
double member;
if (ZBX_MOCK_SUCCESS != (err = zbx_mock_object_member(object, name, &handle)) ||
ZBX_MOCK_SUCCESS != (err = zbx_mock_float(handle, &member)))
{
fail_msg("Cannot read object member \"%s\": %s", name, zbx_mock_error_string(err));
}
return member;
}
/******************************************************************************
* *
* Function: zbx_mock_str_to_return_code *
* *
* Purpose: converts common function return code from text format *
* *
******************************************************************************/
int zbx_mock_str_to_return_code(const char *str)
{
if (0 == strcmp(str, "SUCCEED"))
return SUCCEED;
if (0 == strcmp(str, "FAIL"))
return FAIL;
if (0 == strcmp(str, "NOTSUPPORTED"))
return NOTSUPPORTED;
if (0 == strcmp(str, "NETWORK_ERROR"))
return NETWORK_ERROR;
if (0 == strcmp(str, "TIMEOUT_ERROR"))
return TIMEOUT_ERROR;
if (0 == strcmp(str, "AGENT_ERROR"))
return AGENT_ERROR;
if (0 == strcmp(str, "GATEWAY_ERROR"))
return GATEWAY_ERROR;
if (0 == strcmp(str, "CONFIG_ERROR"))
return CONFIG_ERROR;
if (0 == strcmp(str, "SYSINFO_RET_OK"))
return SYSINFO_RET_OK;
if (0 == strcmp(str, "SYSINFO_RET_FAIL"))
return SYSINFO_RET_FAIL;
fail_msg("Unknown return code \"%s\"", str);
return 0;
}
/******************************************************************************
* *
* Function: zbx_mock_str_to_value_type *
* *
* Purpose: converts item value type from text format *
* *
******************************************************************************/
int zbx_mock_str_to_family(const char *str)
{
if (0 == strcmp(str, "AF_INET"))
return AF_INET;
if (0 == strcmp(str, "AF_INET6"))
return AF_INET6;
fail_msg("Unknown family \"%s\"", str);
return AF_UNSPEC;
}
|