diff options
author | Andris Zeila <andris.zeila@zabbix.com> | 2018-01-24 16:31:14 +0300 |
---|---|---|
committer | Andris Zeila <andris.zeila@zabbix.com> | 2018-01-24 16:31:14 +0300 |
commit | 3ef2121328f2044619008319d8165e0f011c9845 (patch) | |
tree | a34f33687ec3fbe545d04a720f0f8ae5ee855707 /tests/libs/zbxcommshigh | |
parent | 22fdf63031f0766015101caddd8d36f0f44c7552 (diff) |
....I..... [ZBXNEXT-3581] updated test cases
Diffstat (limited to 'tests/libs/zbxcommshigh')
-rw-r--r-- | tests/libs/zbxcommshigh/Makefile.am | 1 | ||||
-rw-r--r-- | tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c | 22 | ||||
-rw-r--r-- | tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml | 88 | ||||
-rw-r--r-- | tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.c | 19 | ||||
-rw-r--r-- | tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.yaml | 31 |
5 files changed, 81 insertions, 80 deletions
diff --git a/tests/libs/zbxcommshigh/Makefile.am b/tests/libs/zbxcommshigh/Makefile.am index 2458569513b..c5e1c66e9f4 100644 --- a/tests/libs/zbxcommshigh/Makefile.am +++ b/tests/libs/zbxcommshigh/Makefile.am @@ -20,6 +20,7 @@ COMMON_SRC_FILES = \ ../../zbxmocktest.h COMMON_LIB_FILES = \ + $(top_srcdir)/tests/libzbxmockdata.a \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxagentsysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/$(ARCH)/libspecsysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/$(ARCH)/libspechostnamesysinfo.a \ diff --git a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c index 3409d7c4976..3ba6a4b5373 100644 --- a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c +++ b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.c @@ -19,6 +19,8 @@ #include "zbxmocktest.h" #include "zbxmockdata.h" +#include "zbxmockassert.h" +#include "zbxmockutil.h" #include "zbxmockhelper.h" #include "common.h" @@ -30,27 +32,25 @@ void zbx_mock_test_entry(void **state) char *buffer; zbx_socket_t s; - ssize_t received, expected; + ssize_t received; + int expected_ret; ZBX_UNUSED(state); - if (SUCCEED != zbx_tcp_connect(&s, NULL, "127.0.0.1", 10050, 0, ZBX_TCP_SEC_UNENCRYPTED, NULL, NULL)) - fail_msg("Failed to connect"); + zbx_mock_assert_result_eq("zbx_tcp_connect() return code", SUCCEED, + zbx_tcp_connect(&s, NULL, "127.0.0.1", 10050, 0, ZBX_TCP_SEC_UNENCRYPTED, NULL, NULL)); - if (zbx_read_yaml_expected_ret() != SUCCEED_OR_FAIL((received = zbx_tcp_recv_ext(&s, 0)))) - fail_msg("Unexpected return code '%s'", zbx_result_string(SUCCEED_OR_FAIL(received))); + expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return")); + received = zbx_tcp_recv_ext(&s, 0); - if (FAIL == SUCCEED_OR_FAIL(received)) + if (FAIL == expected_ret) { + zbx_mock_assert_result_eq("zbx_tcp_recv_ext() return code", FAIL, received); zbx_tcp_close(&s); return; } - if (received != (expected = zbx_read_yaml_expected_uint64("number of bytes"))) - fail_msg("Expected bytes to receive:" ZBX_FS_UI64 " received:" ZBX_FS_UI64, expected, received); - - if (ZBX_TCP_HEADER_DATALEN_LEN > received) - fail_msg("Received less than header size"); + zbx_mock_assert_uint64_eq("Received bytes", zbx_mock_get_parameter_uint64("out.bytes"), received); buffer = zbx_yaml_assemble_binary_sequence("fragments", received); diff --git a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml index 975aabcabde..0dcbea49d3f 100644 --- a/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml +++ b/tests/libs/zbxcommshigh/zbx_tcp_recv_ext.yaml @@ -4,15 +4,15 @@ in: fragments: - '' out: - ret: 'fail' + return: FAIL --- test case: Correct number of bytes received in: fragments: - 'ZBXD\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'succeed' - number of bytes: '23' + return: SUCCEED + bytes: 23 # Start of header parsing tests --- test case: Fragmented header @@ -21,8 +21,8 @@ in: - 'ZB' - 'XD\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'succeed' - number of bytes: '23' + return: SUCCEED + bytes: 23 --- test case: Fragmented incorrect header in part 1 in: @@ -30,7 +30,7 @@ in: - 'ZZ' - 'XD\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'fail' + return: FAIL --- test case: Fragmented incorrect header in part 2 in: @@ -38,7 +38,7 @@ in: - 'ZB' - 'XX\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'fail' + return: FAIL --- test case: Header in separate fragment in: @@ -46,8 +46,8 @@ in: - 'ZBXD\x01' - '\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'succeed' - number of bytes: '23' + return: SUCCEED + bytes: 23 --- test case: Header in separate fragment incorrect in: @@ -55,7 +55,7 @@ in: - 'ZBBD\x01' - '\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'fail' + return: FAIL --- test case: Whole header fragmented in: @@ -67,24 +67,23 @@ in: - '\x01' - '\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'succeed' - number of bytes: '23' + return: SUCCEED + bytes: 23 --- test case: Only header with 0 data in: fragments: - 'ZBXD\x01\x00\x00\x00\x00\x00\x00\x00\x00' out: - ret: 'succeed' - number of bytes: '13' + return: SUCCEED + bytes: 13 --- test case: Header is too small in: fragments: - 'ZBX' out: - ret: 'fail' - number of bytes: '3' + return: FAIL --- # End of header parsing tests # Start of data length parsing tests @@ -106,8 +105,8 @@ in: - '\x00' - 'agent.ping' out: - ret: 'succeed' - number of bytes: '23' + return: SUCCEED + bytes: 23 --- test case: Data length indicator exceed max size in: @@ -120,31 +119,28 @@ in: - '\x01\x00\x00\x08\x00\x00\x00\x00' - 'agent.ping' out: - ret: 'fail' + return: FAIL --- test case: Don't accept if bigger length is supplied in header than sent in: fragments: - 'ZBXD\x01\x0B\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'fail' - number of bytes: '23' + return: FAIL --- test case: Don't accept if smaller length supplied than sent in: fragments: - 'ZBXD\x01\x09\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'fail' - number of bytes: '23' + return: FAIL --- test case: Data length is too small in: fragments: - 'ZBXD\x01\x01\x00\x00\x00\x00\x00\x00' out: - ret: 'fail' - number of bytes: '12' + return: FAIL --- # End of data length parsing tests # Start of data tests @@ -155,8 +151,8 @@ in: - '\x00\x00\x00\x00\x00agent.pi' - 'ng' out: - ret: 'succeed' - number of bytes: '23' + return: SUCCEED + bytes: 23 --- test case: Fragmented key by bytes in: @@ -174,8 +170,8 @@ in: - 'n' - 'g' out: - ret: 'succeed' - number of bytes: '23' + return: SUCCEED + bytes: 23 --- test case: Whole message streamed by 1 byte in: @@ -204,57 +200,58 @@ in: - 'n' - 'g' out: - ret: 'succeed' - number of bytes: '23' + return: SUCCEED + bytes: 23 --- test case: Stat buffer almost filled in: fragments: - 'ZBXD\x01\xF2\x07\x00\x00\x00\x00\x00\x000123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn' out: - ret: 'succeed' - number of bytes: '2047' + return: SUCCEED + bytes: 2047 --- test case: Stat buffer filled in: fragments: - 'ZBXD\x01\xF3\x07\x00\x00\x00\x00\x00\x000123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmno' out: - ret: 'succeed' - number of bytes: '2048' + return: SUCCEED + bytes: 2048 --- test case: Second receive is required but still stat buffer in: fragments: - 'ZBXD\x01\xF4\x07\x00\x00\x00\x00\x00\x000123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop' out: - ret: 'succeed' - number of bytes: '2049' + return: SUCCEED + bytes: 2049 --- test case: Stat buffer is not enough for data, switching to dinamic in: fragments: - 'ZBXD\x01\x00\x08\x00\x00\x00\x00\x00\x000123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01' out: - ret: 'succeed' - number of bytes: '2061' + return: SUCCEED + bytes: 2061 --- -test case: Second receive, dinamic and fragmented +test case: Second receive, dynamic and fragmented in: fragments: - 'ZBXD\x01\x13\x08\x00\x00\x00\x00\x00\x000123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEF' - 'GHI\x00' - 'K' out: - ret: 'succeed' - number of bytes: '2080' + return: SUCCEED + bytes: 2080 --- test case: Second receive, received more than expected in: fragments: # 2050 expected - 'ZBXD\x01\x02\x08\x00\x00\x00\x00\x00\x000123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' out: - ret: 'fail' + return: FAIL +--- test case: Lots of binary data in: fragments: @@ -324,7 +321,6 @@ in: - *1 - *1 out: - ret: 'succeed' - number of bytes: '131085' -... + return: SUCCEED + bytes: 131085 ... diff --git a/tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.c b/tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.c index 07734ddd235..c0fefe472c3 100644 --- a/tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.c +++ b/tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.c @@ -19,6 +19,8 @@ #include "zbxmocktest.h" #include "zbxmockdata.h" +#include "zbxmockassert.h" +#include "zbxmockutil.h" #include "zbxmockhelper.h" #include "common.h" @@ -28,24 +30,25 @@ void zbx_mock_test_entry(void **state) { char *buffer; zbx_socket_t s; - ssize_t received, expected; + ssize_t received; + int expected_ret; ZBX_UNUSED(state); - if (SUCCEED != zbx_tcp_connect(&s, NULL, "127.0.0.1", 10050, 0, ZBX_TCP_SEC_UNENCRYPTED, NULL, NULL)) - fail_msg("Failed to connect"); + zbx_mock_assert_result_eq("zbx_tcp_connect() return code", SUCCEED, + zbx_tcp_connect(&s, NULL, "127.0.0.1", 10050, 0, ZBX_TCP_SEC_UNENCRYPTED, NULL, NULL)); - if (zbx_read_yaml_expected_ret() != SUCCEED_OR_FAIL((received = zbx_tcp_recv_raw_ext(&s, 0)))) - fail_msg("Unexpected return code '%s'", zbx_result_string(SUCCEED_OR_FAIL(received))); + expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return")); + received = zbx_tcp_recv_raw_ext(&s, 0); - if (FAIL == SUCCEED_OR_FAIL(received) || 0 == received) + if (FAIL == expected_ret) { + zbx_mock_assert_result_eq("zbx_tcp_recv_ext() return code", FAIL, received); zbx_tcp_close(&s); return; } - if (received != (expected = zbx_read_yaml_expected_uint64("number of bytes"))) - fail_msg("Expected bytes to receive:" ZBX_FS_UI64 " received:" ZBX_FS_UI64, expected, received); + zbx_mock_assert_uint64_eq("Received bytes", zbx_mock_get_parameter_uint64("out.bytes"), received); buffer = zbx_yaml_assemble_binary_sequence("fragments", received); diff --git a/tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.yaml b/tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.yaml index 4d666c98dfa..b0c6625faf4 100644 --- a/tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.yaml +++ b/tests/libs/zbxcommshigh/zbx_tcp_recv_raw_ext.yaml @@ -4,7 +4,8 @@ in: fragments: - '' out: - ret: 'succeed' + return: SUCCEED + bytes: 0 --- test case: Correct number of bytes received in: @@ -27,8 +28,8 @@ in: <address>Apache/2.4.10 (Debian) Server at www.zabbix.com Port 80</address> </body></html>' out: - ret: 'succeed' - number of bytes: '506' + return: SUCCEED + bytes: 506 --- test case: Correct number of bytes received fragmented in: @@ -66,16 +67,16 @@ in: ' - '</body></html>' out: - ret: 'succeed' - number of bytes: '506' + return: SUCCEED + bytes: 506 --- test case: Stat buffer filled in: fragments: - '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01' out: - ret: 'succeed' - number of bytes: '2048' + return: SUCCEED + bytes: 2048 --- test case: Stat buffer filled and switched to dynamic fragmented in: @@ -86,16 +87,16 @@ in: - 'q' - 'r' out: - ret: 'succeed' - number of bytes: '2100' + return: SUCCEED + bytes: 2100 --- test case: Correct number of bytes received binary stat buffer in: fragments: - 'ZBXD\x01\x0A\x00\x00\x00\x00\x00\x00\x00agent.ping' out: - ret: 'succeed' - number of bytes: '23' + return: SUCCEED + bytes: 23 --- test case: Correct number of bytes received binary dynamic buffer in: @@ -106,8 +107,8 @@ in: - 'q' - 'r' out: - ret: 'succeed' - number of bytes: '2100' + return: SUCCEED + bytes: 2100 --- test case: Lots of binary data in: @@ -177,6 +178,6 @@ in: - *1 - *1 out: - ret: 'succeed' - number of bytes: '131072' + return: SUCCEED + bytes: 131072 ... |