1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

gcoap: Use client token length macro when generate expected data.

This commit is contained in:
Ken Bannister 2016-12-19 12:55:20 -05:00
parent 7c19ad65e2
commit 412d0dd67e

View File

@ -25,7 +25,7 @@
/* /*
* Client GET request success case. Test request generation. * Client GET request success case. Test request generation.
* Request /time resource from libcoap example * Request /time resource from libcoap example
* Includes 2-byte token * Includes token of length GCOAP_TOKENLEN.
*/ */
static void test_gcoap__client_get_req(void) static void test_gcoap__client_get_req(void)
{ {
@ -34,17 +34,27 @@ static void test_gcoap__client_get_req(void)
size_t len; size_t len;
char path[] = "/time"; char path[] = "/time";
uint8_t pdu_data[] = { /* Create expected pdu_data, with token length from GCOAP_TOKENLEN. */
0x52, 0x01, 0xe6, 0x02, 0x9b, 0xce, 0xb4, 0x74, size_t hdr_fixed_len = 4;
0x69, 0x6d, 0x65 uint8_t hdr_fixed[] = { 0x52, 0x01, 0xe6, 0x02 };
}; size_t options_len = 5;
uint8_t options[] = { 0xb4, 0x74, 0x69, 0x6d, 0x65 };
uint8_t pdu_data[hdr_fixed_len + GCOAP_TOKENLEN + options_len];
memcpy(&pdu_data[0], &hdr_fixed[0], hdr_fixed_len);
#if GCOAP_TOKENLEN
/* actual value is random */
memset(&pdu_data[hdr_fixed_len], 0x9b, GCOAP_TOKENLEN);
#endif
memcpy(&pdu_data[hdr_fixed_len + GCOAP_TOKENLEN], &options[0], options_len);
len = gcoap_request(&pdu, &buf[0], GCOAP_PDU_BUF_SIZE, COAP_METHOD_GET, len = gcoap_request(&pdu, &buf[0], GCOAP_PDU_BUF_SIZE, COAP_METHOD_GET,
&path[0]); &path[0]);
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pdu)); TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pdu));
TEST_ASSERT_EQUAL_INT(GCOAP_TOKENLEN, coap_get_token_len(&pdu)); TEST_ASSERT_EQUAL_INT(GCOAP_TOKENLEN, coap_get_token_len(&pdu));
TEST_ASSERT_EQUAL_INT(4 + GCOAP_TOKENLEN, coap_get_total_hdr_len(&pdu)); TEST_ASSERT_EQUAL_INT(hdr_fixed_len + GCOAP_TOKENLEN, coap_get_total_hdr_len(&pdu));
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pdu)); TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pdu));
TEST_ASSERT_EQUAL_STRING(&path[0], (char *)&pdu.url[0]); TEST_ASSERT_EQUAL_STRING(&path[0], (char *)&pdu.url[0]);
TEST_ASSERT_EQUAL_INT(0, pdu.payload_len); TEST_ASSERT_EQUAL_INT(0, pdu.payload_len);