Skip to content
Snippets Groups Projects
Commit b33ae7df authored by Kaspar Schleiser's avatar Kaspar Schleiser
Browse files

unittests/tests-nanocoap: add coap_get_uri() test

parent dee793d2
No related branches found
No related tags found
No related merge requests found
...@@ -22,13 +22,14 @@ ...@@ -22,13 +22,14 @@
#include "tests-nanocoap.h" #include "tests-nanocoap.h"
/* /*
* Validates encoded message ID byte order. * Validates encoded message ID byte order and put/get URI option.
*/ */
static void test_nanocoap__req_msgid(void) static void test_nanocoap__hdr(void)
{ {
uint8_t buf[128]; uint8_t buf[128];
uint16_t msgid = 0xABCD; uint16_t msgid = 0xABCD;
char path[] = "/test"; char path[] = "/test/abcd/efgh";
unsigned char path_tmp[64] = {0};
uint8_t *pktpos = &buf[0]; uint8_t *pktpos = &buf[0];
pktpos += coap_build_hdr((coap_hdr_t *)pktpos, COAP_REQ, NULL, 0, COAP_METHOD_GET, msgid); pktpos += coap_build_hdr((coap_hdr_t *)pktpos, COAP_REQ, NULL, 0, COAP_METHOD_GET, msgid);
...@@ -38,12 +39,16 @@ static void test_nanocoap__req_msgid(void) ...@@ -38,12 +39,16 @@ static void test_nanocoap__req_msgid(void)
coap_parse(&pkt, &buf[0], pktpos - &buf[0]); coap_parse(&pkt, &buf[0], pktpos - &buf[0]);
TEST_ASSERT_EQUAL_INT(msgid, coap_get_id(&pkt)); TEST_ASSERT_EQUAL_INT(msgid, coap_get_id(&pkt));
int res = coap_get_uri(&pkt, path_tmp);
TEST_ASSERT_EQUAL_INT(sizeof(path), res);
TEST_ASSERT_EQUAL_STRING((char *)path, (char *)path_tmp);
} }
Test *tests_nanocoap_tests(void) Test *tests_nanocoap_tests(void)
{ {
EMB_UNIT_TESTFIXTURES(fixtures) { EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_nanocoap__req_msgid), new_TestFixture(test_nanocoap__hdr),
}; };
EMB_UNIT_TESTCALLER(nanocoap_tests, NULL, NULL, fixtures); EMB_UNIT_TESTCALLER(nanocoap_tests, NULL, NULL, fixtures);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment