diff options
author | Vladislavs Sokurenko <vladislavs.sokurenko@zabbix.com> | 2018-01-18 11:40:20 +0300 |
---|---|---|
committer | Vladislavs Sokurenko <vladislavs.sokurenko@zabbix.com> | 2018-01-18 11:40:20 +0300 |
commit | 2ddf2fdc136d4fa19701e315dda5ea1df170b952 (patch) | |
tree | 49b9ad9bc95e8c3cafe8af75acb4806f1b302859 /tests/libs/zbxcommshigh | |
parent | 3b4804fedc716cf077a4f659b57dc9840f95ca55 (diff) |
.......... [ZBXNEXT-3581] more mock tests
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 | 150 |
2 files changed, 146 insertions, 13 deletions
diff --git a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c index 0fc7dded050..f642b6e6f1f 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_vector, recv_elem; +static zbx_mock_handle_t fragments; static int read_yaml_ret(void) { @@ -61,13 +61,14 @@ ssize_t __wrap_read(int fd, void *buf, size_t nbytes) zbx_mock_error_t error; const char *value; size_t length; + zbx_mock_handle_t fragment; ZBX_UNUSED(fd); - if (ZBX_MOCK_SUCCESS != zbx_mock_vector_element(recv_vector, &recv_elem)) + if (ZBX_MOCK_SUCCESS != zbx_mock_vector_element(fragments, &fragment)) return 0; /* no more data */ - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_binary(recv_elem, &value, &length))) + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_binary(fragment, &value, &length))) fail_msg("Cannot read data '%s'", zbx_mock_error_string(error)); memcpy(buf, value, length); @@ -84,7 +85,7 @@ void zbx_mock_test_entry(void **state) ZBX_UNUSED(state); - if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("recv data", &recv_vector))) + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("recv data", &fragments))) 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 51a1e1a8b6c..5017a42841f 100644 --- a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml +++ b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml @@ -1,4 +1,11 @@ --- +test case: Zero bytes received +in: + recv data: + - "" +out: + ret: 'fail' +--- test case: Correct number of bytes received in: recv data: @@ -6,6 +13,98 @@ in: out: ret: 'succeed' number of bytes: '23' +# Start of header parsing tests +--- +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 incorrect header in part 1 +in: + recv data: + - "ZZ" + - "XD\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping" +out: + ret: 'fail' +--- +test case: Fragmented incorrect header in part 2 +in: + recv data: + - "ZB" + - "XX\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping" +out: + ret: 'fail' +--- +test case: Header in separate fragment +in: + recv data: + - "ZBXD\x01" + - "\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping" +out: + ret: 'succeed' + number of bytes: '23' +--- +test case: Header in separate fragment incorrect +in: + recv data: + - "ZBBD\x01" + - "\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping" +out: + ret: 'fail' +--- +test case: Whole header fragmented +in: + recv data: + - "Z" + - "B" + - "X" + - "D" + - "\x01" + - "\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping" +out: + ret: 'succeed' + number of bytes: '23' +--- +# End of header parsing tests +# Start of data length parsing tests +test case: Header and data length fragmented +in: + recv data: + - "Z" + - "B" + - "X" + - "D" + - "\x01" + - "\x0A" # data length starts + - "\x00" + - "\x00" + - "\x00" + - "\x00" + - "\x00" + - "\x00" + - "\x00" + - "agent.ping" +out: + ret: 'succeed' + number of bytes: '23' +--- +test case: Data length indicator exceed max size +in: + recv data: + - "Z" + - "B" + - "X" + - "D" + - "\x01" + - "\x01\x00\x00\x08\x00\x00\x00\x00" + - "agent.ping" +out: + ret: 'fail' --- test case: Don't accept if bigger length is supplied in header than sent in: @@ -23,30 +122,63 @@ out: ret: 'fail' number of bytes: '23' --- -test case: Fragmented header +# End of data length parsing tests +# Start of data tests +test case: Fragmented key in: recv data: - - "ZB" - - "XD\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping" + - "ZBXD\x01\x0A\x00\x00" + - "\x00\x00\x00\x00\x00agent.pi" + - "ng" out: ret: 'succeed' number of bytes: '23' --- -test case: Fragmented data length +test case: Fragmented key by bytes in: recv data: - "ZBXD\x01\x0A\x00\x00" - - "\x00\x00\x00\x00\x00agent.ping" + - "\x00\x00\x00\x00\x00" + - "a" + - "g" + - "e" + - "n" + - "t" + - "." + - "p" + - "i" + - "n" + - "g" out: ret: 'succeed' number of bytes: '23' --- -test case: Fragmented key +test case: Whole message streamed by 1 byte in: recv data: - - "ZBXD\x01\x0A\x00\x00" - - "\x00\x00\x00\x00\x00agent.pi" - - "ng" + - "Z" + - "B" + - "X" + - "D" + - "\x01" + - "\x0A" # data length starts + - "\x00" + - "\x00" + - "\x00" + - "\x00" + - "\x00" + - "\x00" + - "\x00" + - "a" + - "g" + - "e" + - "n" + - "t" + - "." + - "p" + - "i" + - "n" + - "g" out: ret: 'succeed' number of bytes: '23' |