diff options
author | Vladislavs Sokurenko <vladislavs.sokurenko@zabbix.com> | 2018-01-17 20:19:50 +0300 |
---|---|---|
committer | Vladislavs Sokurenko <vladislavs.sokurenko@zabbix.com> | 2018-01-17 20:19:50 +0300 |
commit | 3b4804fedc716cf077a4f659b57dc9840f95ca55 (patch) | |
tree | c9cf850a3850fb8ad3ad9f4934fa24fd6b1f6ece /tests/libs/zbxcommshigh | |
parent | 80cc0221daf8cde311afbd5a776c0e9b0e54b5e9 (diff) |
.......... [ZBXNEXT-3581] mock tests improvements
Diffstat (limited to 'tests/libs/zbxcommshigh')
-rw-r--r-- | tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c | 9 | ||||
-rw-r--r-- | tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml | 37 |
2 files changed, 40 insertions, 6 deletions
diff --git a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c index 3ed30c47fbd..0fc7dded050 100644 --- a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c +++ b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c @@ -4,7 +4,7 @@ #include "common.h" #include "comms.h" -static zbx_mock_handle_t recv_data_handle; +static zbx_mock_handle_t recv_vector, recv_elem; static int read_yaml_ret(void) { @@ -64,7 +64,10 @@ ssize_t __wrap_read(int fd, void *buf, size_t nbytes) ZBX_UNUSED(fd); - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_binary(recv_data_handle, &value, &length))) + if (ZBX_MOCK_SUCCESS != zbx_mock_vector_element(recv_vector, &recv_elem)) + return 0; /* no more data */ + + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_binary(recv_elem, &value, &length))) fail_msg("Cannot read data '%s'", zbx_mock_error_string(error)); memcpy(buf, value, length); @@ -81,7 +84,7 @@ void zbx_mock_test_entry(void **state) ZBX_UNUSED(state); - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("recv data", &recv_data_handle))) + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("recv data", &recv_vector))) fail_msg("Cannot get recv data handle: %s", zbx_mock_error_string(error)); zbx_tcp_connect_mock(&s, "127.0.0.2", "127.0.0.1", 10050, 0, 0, NULL, NULL); diff --git a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml index 314a4cdf40e..51a1e1a8b6c 100644 --- a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml +++ b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml @@ -1,22 +1,53 @@ --- test case: Correct number of bytes received in: - recv data: "ZBXD\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping" + recv data: + - "ZBXD\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping" out: ret: 'succeed' number of bytes: '23' --- test case: Don't accept if bigger length is supplied in header than sent in: - recv data: "ZBXD\x01\x0B\x00\x00\x00\x00\x00\x00\x00agent.ping" + recv data: + - "ZBXD\x01\x0B\x00\x00\x00\x00\x00\x00\x00agent.ping" out: ret: 'fail' number of bytes: '23' --- test case: Don't accept if smaller length supplied than sent in: - recv data: "ZBXD\x01\x09\x00\x00\x00\x00\x00\x00\x00agent.ping" + recv data: + - "ZBXD\x01\x09\x00\x00\x00\x00\x00\x00\x00agent.ping" out: ret: 'fail' number of bytes: '23' +--- +test case: Fragmented header +in: + recv data: + - "ZB" + - "XD\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping" +out: + ret: 'succeed' + number of bytes: '23' +--- +test case: Fragmented data length +in: + recv data: + - "ZBXD\x01\x0A\x00\x00" + - "\x00\x00\x00\x00\x00agent.ping" +out: + ret: 'succeed' + number of bytes: '23' +--- +test case: Fragmented key +in: + recv data: + - "ZBXD\x01\x0A\x00\x00" + - "\x00\x00\x00\x00\x00agent.pi" + - "ng" +out: + ret: 'succeed' + number of bytes: '23' ... |