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
|
/*
** Zabbix
** Copyright (C) 2001-2018 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 "zbxmockutil.h"
#include "comms.h"
#include "sysinfo.h"
#include "../../../../src/libs/zbxsysinfo/common/http.h"
static const char *http_req;
static size_t http_len;
void zbx_mock_test_entry(void **state)
{
AGENT_REQUEST request;
AGENT_RESULT param_result;
int expected_result, actual_result;
const char *buffer, *init_param;
char *rvalue;
ZBX_UNUSED(state);
expected_result = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return"));
buffer = zbx_mock_get_parameter_string("out.req");
init_request(&request);
init_result(¶m_result);
init_param = zbx_mock_get_parameter_string("in.key");
if (SUCCEED != parse_item_key(init_param, &request))
fail_msg("Cannot parse item key: %s", init_param);
if (expected_result != (actual_result = WEB_PAGE_GET(&request,¶m_result)))
{
fail_msg("Got %s instead of %s as a result.", zbx_sysinfo_ret_string(actual_result),
zbx_sysinfo_ret_string(expected_result));
}
if (SYSINFO_RET_FAIL == expected_result)
rvalue = (NULL != GET_MSG_RESULT(¶m_result)) ? *GET_MSG_RESULT(¶m_result) : NULL;
else
rvalue = (NULL != GET_TEXT_RESULT(¶m_result)) ? *GET_TEXT_RESULT(¶m_result) : NULL;
if (NULL == rvalue)
fail_msg("Got 'NULL' response.");
if (SYSINFO_RET_OK == expected_result)
rvalue[strlen(rvalue) - 1] = '\0'; /* remove last char from __wrap_zbx_tcp_recv_raw_ext */
if (0 != strcmp(buffer, rvalue))
fail_msg("Got '%s' instead of '%s' as a value.", rvalue, buffer);
free_request(&request);
free_result(¶m_result);
}
int __wrap_zbx_tcp_connect(zbx_socket_t *s, const char *source_ip, const char *ip, unsigned short port,
int timeout, unsigned int tls_connect, const char *tls_arg1, const char *tls_arg2)
{
ZBX_UNUSED(s);
ZBX_UNUSED(source_ip);
ZBX_UNUSED(ip);
ZBX_UNUSED(port);
ZBX_UNUSED(timeout);
ZBX_UNUSED(tls_connect);
ZBX_UNUSED(tls_arg1);
ZBX_UNUSED(tls_arg2);
return SUCCEED;
}
int __wrap_zbx_tcp_send_ext(zbx_socket_t *s, const char *data, size_t len, unsigned char flags, int timeout)
{
ZBX_UNUSED(s);
ZBX_UNUSED(flags);
ZBX_UNUSED(timeout);
http_req = data;
http_len = len;
return SUCCEED;
}
ssize_t __wrap_zbx_tcp_recv_raw_ext(zbx_socket_t *s, int timeout)
{
ZBX_UNUSED(s);
ZBX_UNUSED(timeout);
s->buffer = (char *)http_req;
s->buffer[http_len++] = '*'; /* workaround for zbx_rtrim */
s->buffer[http_len++] = '\0';
return http_len;
}
void __wrap_zbx_tcp_close(zbx_socket_t *s)
{
ZBX_UNUSED(s);
}
|