From 45fe87a4252d27c5bd20ca64b37f4254b6e2fbfa Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Tue, 21 Feb 2017 15:25:26 -0800 Subject: [PATCH] tests/zoap: Adds test for the length of payload on the RX side This unit test verifies that zoap_packet_get_payload() returns the expected size for received packets. Jira: ZEP-1662 Change-Id: Ibe011959f4d6593f4f20f0f5901c9033c76c9518 Signed-off-by: Vinicius Costa Gomes --- tests/net/lib/zoap/src/main.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/net/lib/zoap/src/main.c b/tests/net/lib/zoap/src/main.c index cf4e1fa27ac..3723cd5ef3c 100644 --- a/tests/net/lib/zoap/src/main.c +++ b/tests/net/lib/zoap/src/main.c @@ -348,8 +348,8 @@ static int test_parse_simple_pdu(void) struct net_buf *buf, *frag; struct zoap_option options[16]; uint8_t ver, type, code, tkl; - const uint8_t *token; - uint16_t id; + const uint8_t *token, *payload; + uint16_t id, len; int result = TC_FAIL; int r, count = 16; @@ -442,6 +442,17 @@ static int test_parse_simple_pdu(void) goto done; } + payload = zoap_packet_get_payload(&pkt, &len); + if (!payload || !len) { + TC_PRINT("There should be a payload in the packet\n"); + goto done; + } + + if (len != (strlen("payload") + 1)) { + TC_PRINT("Invalid payload in the packet\n"); + goto done; + } + result = TC_PASS; done: