From d7763a295a05c6495a92c73245509d1e8fc76b57 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 8 Mar 2017 11:05:31 +0100 Subject: [PATCH] test_options.c: unit test for extended delta PR #65 reports wrong encoding of option value 269. The new unit test t_encode_option9() tests for correct encoding according to [RFC 7252, Section 3.1](https://tools.ietf.org/html/rfc7252#section-3.1). --- tests/test_options.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_options.c b/tests/test_options.c index 5bb51f4d..eb94afb0 100644 --- a/tests/test_options.c +++ b/tests/test_options.c @@ -337,6 +337,18 @@ t_encode_option8(void) { CU_ASSERT(result == 0); } +static void +t_encode_option9(void) { + uint8_t teststr[] = { 0xe1, 0x00, 0x00 }; + unsigned char buf[40] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + size_t result; + + result = coap_opt_setheader((coap_opt_t *)buf, sizeof(buf), 269, 1); + CU_ASSERT(result == sizeof(teststr)); + + CU_ASSERT(memcmp(buf, teststr, result) == 0); +} + /************************************************************************ ** accessor tests ************************************************************************/ @@ -929,6 +941,7 @@ t_init_option_tests(void) { OPTION_ENCODER_TEST(6, "encode option #6"); OPTION_ENCODER_TEST(7, "encode option #7"); OPTION_ENCODER_TEST(8, "encode option #8"); + OPTION_ENCODER_TEST(9, "encode option #9"); } else { fprintf(stderr, "W: cannot add option encoder test suite (%s)\n",