From cad1ccfa3bead12ebdb58900c53dc45f1215d64e Mon Sep 17 00:00:00 2001 From: Ken Bannister Date: Sat, 8 Sep 2018 05:46:57 -0400 Subject: [PATCH] net/nanocoap: add unit test for trailing slash in path --- .../unittests/tests-nanocoap/tests-nanocoap.c | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/unittests/tests-nanocoap/tests-nanocoap.c b/tests/unittests/tests-nanocoap/tests-nanocoap.c index bd3e9e7a58..cc4b9769f6 100644 --- a/tests/unittests/tests-nanocoap/tests-nanocoap.c +++ b/tests/unittests/tests-nanocoap/tests-nanocoap.c @@ -151,6 +151,30 @@ static void test_nanocoap__get_multi_path(void) TEST_ASSERT_EQUAL_STRING((char *)path, (char *)uri); } +/* + * Builds on get_req test, to test path with trailing slash. + */ +static void test_nanocoap__get_path_trailing_slash(void) +{ + uint8_t buf[128]; + coap_pkt_t pkt; + uint16_t msgid = 0xABCD; + uint8_t token[2] = {0xDA, 0xEC}; + char path[] = "/time/"; + size_t uri_opt_len = 6; + + size_t len = coap_build_hdr((coap_hdr_t *)&buf[0], COAP_TYPE_NON, + &token[0], 2, COAP_METHOD_GET, msgid); + + coap_pkt_init(&pkt, &buf[0], sizeof(buf), len); + + len = coap_opt_add_string(&pkt, COAP_OPT_URI_PATH, &path[0], '/'); + TEST_ASSERT_EQUAL_INT(uri_opt_len, len); + + char uri[10] = {0}; + coap_get_uri_path(&pkt, (uint8_t *)&uri[0]); + TEST_ASSERT_EQUAL_STRING((char *)path, (char *)uri); +} /* * Builds on get_req test, to test '/' path. This path is the default when * otherwise not specified. @@ -233,6 +257,7 @@ Test *tests_nanocoap_tests(void) new_TestFixture(test_nanocoap__get_req), new_TestFixture(test_nanocoap__put_req), new_TestFixture(test_nanocoap__get_multi_path), + new_TestFixture(test_nanocoap__get_path_trailing_slash), new_TestFixture(test_nanocoap__get_root_path), new_TestFixture(test_nanocoap__get_max_path), new_TestFixture(test_nanocoap__get_path_too_long),