1c87c5fbaSopenharmony_ci/* libcoap unit tests 2c87c5fbaSopenharmony_ci * 3c87c5fbaSopenharmony_ci * Copyright (C) 2012,2015,2022-2023 Olaf Bergmann <bergmann@tzi.org> 4c87c5fbaSopenharmony_ci * 5c87c5fbaSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause 6c87c5fbaSopenharmony_ci * 7c87c5fbaSopenharmony_ci * This file is part of the CoAP library libcoap. Please see 8c87c5fbaSopenharmony_ci * README for terms of use. 9c87c5fbaSopenharmony_ci */ 10c87c5fbaSopenharmony_ci 11c87c5fbaSopenharmony_ci#include "test_common.h" 12c87c5fbaSopenharmony_ci#include "test_options.h" 13c87c5fbaSopenharmony_ci 14c87c5fbaSopenharmony_ci#include <stdio.h> 15c87c5fbaSopenharmony_ci#include <stdlib.h> 16c87c5fbaSopenharmony_ci#include <string.h> 17c87c5fbaSopenharmony_ci 18c87c5fbaSopenharmony_ci/************************************************************************ 19c87c5fbaSopenharmony_ci ** decoder tests 20c87c5fbaSopenharmony_ci ************************************************************************/ 21c87c5fbaSopenharmony_ci 22c87c5fbaSopenharmony_cistatic void 23c87c5fbaSopenharmony_cit_parse_option1(void) { 24c87c5fbaSopenharmony_ci /* delta == 0, length == 0, value == 0 */ 25c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 1, (const uint8_t *)"" }; 26c87c5fbaSopenharmony_ci 27c87c5fbaSopenharmony_ci size_t result; 28c87c5fbaSopenharmony_ci coap_option_t option; 29c87c5fbaSopenharmony_ci 30c87c5fbaSopenharmony_ci /* result = coap_opt_parse(teststr.s, teststr.s + teststr.length, &option); */ 31c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 32c87c5fbaSopenharmony_ci CU_ASSERT(result == 1); 33c87c5fbaSopenharmony_ci CU_ASSERT(option.delta == 0); 34c87c5fbaSopenharmony_ci CU_ASSERT(option.length == 0); 35c87c5fbaSopenharmony_ci /* FIXME: value? */ 36c87c5fbaSopenharmony_ci} 37c87c5fbaSopenharmony_ci 38c87c5fbaSopenharmony_cistatic void 39c87c5fbaSopenharmony_cit_parse_option2(void) { 40c87c5fbaSopenharmony_ci /* delta == 12, length == 1, value == 0 */ 41c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 2, (const uint8_t *)"\xc1" }; 42c87c5fbaSopenharmony_ci 43c87c5fbaSopenharmony_ci size_t result; 44c87c5fbaSopenharmony_ci coap_option_t option; 45c87c5fbaSopenharmony_ci 46c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 47c87c5fbaSopenharmony_ci CU_ASSERT(result == 2); 48c87c5fbaSopenharmony_ci CU_ASSERT(option.delta == 12); 49c87c5fbaSopenharmony_ci CU_ASSERT(option.length == 1); 50c87c5fbaSopenharmony_ci CU_ASSERT(option.value == teststr.s + 1); 51c87c5fbaSopenharmony_ci} 52c87c5fbaSopenharmony_ci 53c87c5fbaSopenharmony_cistatic void 54c87c5fbaSopenharmony_cit_parse_option3(void) { 55c87c5fbaSopenharmony_ci /* delta == 3, length == 12, value == 0 */ 56c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 13, (const uint8_t *)"\x3c\x00\x01\x02\x03\x04" 57c87c5fbaSopenharmony_ci "\x05\x06\x07\x08\x09\x0a\x0b" 58c87c5fbaSopenharmony_ci }; 59c87c5fbaSopenharmony_ci 60c87c5fbaSopenharmony_ci size_t result; 61c87c5fbaSopenharmony_ci coap_option_t option; 62c87c5fbaSopenharmony_ci 63c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 64c87c5fbaSopenharmony_ci CU_ASSERT(result == 13); 65c87c5fbaSopenharmony_ci CU_ASSERT(option.delta == 3); 66c87c5fbaSopenharmony_ci CU_ASSERT(option.length == 12); 67c87c5fbaSopenharmony_ci CU_ASSERT(option.value == teststr.s + 1); 68c87c5fbaSopenharmony_ci /* CU_ASSERT(memcmp(option.value, teststr.s + 1, 12) == 0); */ 69c87c5fbaSopenharmony_ci} 70c87c5fbaSopenharmony_ci 71c87c5fbaSopenharmony_cistatic void 72c87c5fbaSopenharmony_cit_parse_option4(void) { 73c87c5fbaSopenharmony_ci /* delta == 15, length == 3, value == 0 */ 74c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 2, (const uint8_t *)"\xf3" }; 75c87c5fbaSopenharmony_ci 76c87c5fbaSopenharmony_ci size_t result; 77c87c5fbaSopenharmony_ci coap_option_t option; 78c87c5fbaSopenharmony_ci 79c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 80c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 81c87c5fbaSopenharmony_ci} 82c87c5fbaSopenharmony_ci 83c87c5fbaSopenharmony_cistatic void 84c87c5fbaSopenharmony_cit_parse_option5(void) { 85c87c5fbaSopenharmony_ci /* delta == 3, length == 15, value == 0 */ 86c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 2, (const uint8_t *)"\x3f" }; 87c87c5fbaSopenharmony_ci 88c87c5fbaSopenharmony_ci size_t result; 89c87c5fbaSopenharmony_ci coap_option_t option; 90c87c5fbaSopenharmony_ci 91c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 92c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 93c87c5fbaSopenharmony_ci} 94c87c5fbaSopenharmony_ci 95c87c5fbaSopenharmony_cistatic void 96c87c5fbaSopenharmony_cit_parse_option6(void) { 97c87c5fbaSopenharmony_ci /* delta == 15, length == 15 */ 98c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 1, (const uint8_t *)"\xff" }; 99c87c5fbaSopenharmony_ci 100c87c5fbaSopenharmony_ci size_t result; 101c87c5fbaSopenharmony_ci coap_option_t option; 102c87c5fbaSopenharmony_ci 103c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 104c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 105c87c5fbaSopenharmony_ci} 106c87c5fbaSopenharmony_ci 107c87c5fbaSopenharmony_cistatic void 108c87c5fbaSopenharmony_cit_parse_option7(void) { 109c87c5fbaSopenharmony_ci /* delta == 20, length == 0 */ 110c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 2, (const uint8_t *)"\xd0\x07" }; 111c87c5fbaSopenharmony_ci 112c87c5fbaSopenharmony_ci size_t result; 113c87c5fbaSopenharmony_ci coap_option_t option; 114c87c5fbaSopenharmony_ci 115c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 116c87c5fbaSopenharmony_ci CU_ASSERT(result == 2); 117c87c5fbaSopenharmony_ci CU_ASSERT(option.delta == 20); 118c87c5fbaSopenharmony_ci CU_ASSERT(option.length == 0); 119c87c5fbaSopenharmony_ci} 120c87c5fbaSopenharmony_ci 121c87c5fbaSopenharmony_cistatic void 122c87c5fbaSopenharmony_cit_parse_option8(void) { 123c87c5fbaSopenharmony_ci /* delta == 780, length == 0 */ 124c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 3, (const uint8_t *)"\xe0\x01\xff" }; 125c87c5fbaSopenharmony_ci 126c87c5fbaSopenharmony_ci size_t result; 127c87c5fbaSopenharmony_ci coap_option_t option; 128c87c5fbaSopenharmony_ci 129c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 130c87c5fbaSopenharmony_ci CU_ASSERT(result == 3); 131c87c5fbaSopenharmony_ci CU_ASSERT(option.delta == 780); 132c87c5fbaSopenharmony_ci CU_ASSERT(option.length == 0); 133c87c5fbaSopenharmony_ci} 134c87c5fbaSopenharmony_ci 135c87c5fbaSopenharmony_cistatic void 136c87c5fbaSopenharmony_cit_parse_option9(void) { 137c87c5fbaSopenharmony_ci /* delta == 65535, length == 0 */ 138c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 3, (const uint8_t *)"\xe0\xfe\xf2" }; 139c87c5fbaSopenharmony_ci 140c87c5fbaSopenharmony_ci size_t result; 141c87c5fbaSopenharmony_ci coap_option_t option; 142c87c5fbaSopenharmony_ci 143c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 144c87c5fbaSopenharmony_ci CU_ASSERT(result == 3); 145c87c5fbaSopenharmony_ci CU_ASSERT(option.delta == 65535); 146c87c5fbaSopenharmony_ci} 147c87c5fbaSopenharmony_ci 148c87c5fbaSopenharmony_cistatic void 149c87c5fbaSopenharmony_cit_parse_option10(void) { 150c87c5fbaSopenharmony_ci /* delta > 65535 (illegal), length == 0 */ 151c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 3, (const uint8_t *)"\xe0\xff\xff" }; 152c87c5fbaSopenharmony_ci 153c87c5fbaSopenharmony_ci size_t result; 154c87c5fbaSopenharmony_ci coap_option_t option; 155c87c5fbaSopenharmony_ci 156c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 157c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 158c87c5fbaSopenharmony_ci} 159c87c5fbaSopenharmony_ci 160c87c5fbaSopenharmony_cistatic void 161c87c5fbaSopenharmony_cit_parse_option11(void) { 162c87c5fbaSopenharmony_ci /* illegal delta value (option too short) */ 163c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 1, (const uint8_t *)"\xd0" }; 164c87c5fbaSopenharmony_ci 165c87c5fbaSopenharmony_ci size_t result; 166c87c5fbaSopenharmony_ci coap_option_t option; 167c87c5fbaSopenharmony_ci 168c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 169c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 170c87c5fbaSopenharmony_ci} 171c87c5fbaSopenharmony_ci 172c87c5fbaSopenharmony_cistatic void 173c87c5fbaSopenharmony_cit_parse_option12(void) { 174c87c5fbaSopenharmony_ci /* delta == 280, length == 500 */ 175c87c5fbaSopenharmony_ci coap_str_const_t teststr = { 3, (const uint8_t *)"\xee\xff\x0b" }; 176c87c5fbaSopenharmony_ci 177c87c5fbaSopenharmony_ci size_t result; 178c87c5fbaSopenharmony_ci coap_option_t option; 179c87c5fbaSopenharmony_ci 180c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 181c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 182c87c5fbaSopenharmony_ci} 183c87c5fbaSopenharmony_ci 184c87c5fbaSopenharmony_cistatic void 185c87c5fbaSopenharmony_cit_parse_option13(void) { 186c87c5fbaSopenharmony_ci /* delta == 280, length == 500 */ 187c87c5fbaSopenharmony_ci unsigned char _data[505]; 188c87c5fbaSopenharmony_ci coap_string_t teststr = { sizeof(_data), _data }; 189c87c5fbaSopenharmony_ci teststr.s[0] = 0xee; 190c87c5fbaSopenharmony_ci teststr.s[1] = 0x00; 191c87c5fbaSopenharmony_ci teststr.s[2] = 0x0b; 192c87c5fbaSopenharmony_ci teststr.s[3] = 0x00; 193c87c5fbaSopenharmony_ci teststr.s[4] = 0xe7; 194c87c5fbaSopenharmony_ci 195c87c5fbaSopenharmony_ci size_t result; 196c87c5fbaSopenharmony_ci coap_option_t option; 197c87c5fbaSopenharmony_ci 198c87c5fbaSopenharmony_ci result = coap_opt_parse(teststr.s, teststr.length, &option); 199c87c5fbaSopenharmony_ci CU_ASSERT(result == sizeof(_data)); 200c87c5fbaSopenharmony_ci CU_ASSERT(option.delta == 280); 201c87c5fbaSopenharmony_ci CU_ASSERT(option.length == 500); 202c87c5fbaSopenharmony_ci CU_ASSERT(option.value == &_data[5]); 203c87c5fbaSopenharmony_ci} 204c87c5fbaSopenharmony_ci 205c87c5fbaSopenharmony_cistatic void 206c87c5fbaSopenharmony_cit_parse_option14(void) { 207c87c5fbaSopenharmony_ci /* delta == 268, length == 65535 */ 208c87c5fbaSopenharmony_ci unsigned char *data; 209c87c5fbaSopenharmony_ci unsigned int length = 4 + 65535; 210c87c5fbaSopenharmony_ci 211c87c5fbaSopenharmony_ci data = (unsigned char *)malloc(length); 212c87c5fbaSopenharmony_ci if (!data) { 213c87c5fbaSopenharmony_ci CU_FAIL("internal error in test framework -- insufficient memory\n"); 214c87c5fbaSopenharmony_ci return; 215c87c5fbaSopenharmony_ci } 216c87c5fbaSopenharmony_ci 217c87c5fbaSopenharmony_ci data[0] = 0xde; 218c87c5fbaSopenharmony_ci data[1] = 0xff; 219c87c5fbaSopenharmony_ci data[2] = 0xfe; 220c87c5fbaSopenharmony_ci data[3] = 0xf2; 221c87c5fbaSopenharmony_ci 222c87c5fbaSopenharmony_ci size_t result; 223c87c5fbaSopenharmony_ci coap_option_t option; 224c87c5fbaSopenharmony_ci 225c87c5fbaSopenharmony_ci result = coap_opt_parse(data, length, &option); 226c87c5fbaSopenharmony_ci CU_ASSERT(result == length); 227c87c5fbaSopenharmony_ci CU_ASSERT(option.delta == 268); 228c87c5fbaSopenharmony_ci CU_ASSERT(option.length == 65535); 229c87c5fbaSopenharmony_ci CU_ASSERT(option.value == &data[4]); 230c87c5fbaSopenharmony_ci free(data); 231c87c5fbaSopenharmony_ci} 232c87c5fbaSopenharmony_ci 233c87c5fbaSopenharmony_ci/************************************************************************ 234c87c5fbaSopenharmony_ci ** encoder tests 235c87c5fbaSopenharmony_ci ************************************************************************/ 236c87c5fbaSopenharmony_ci 237c87c5fbaSopenharmony_cistatic void 238c87c5fbaSopenharmony_cit_encode_option1(void) { 239c87c5fbaSopenharmony_ci char teststr[] = { 0x00 }; 240c87c5fbaSopenharmony_ci unsigned char buf[40]; 241c87c5fbaSopenharmony_ci size_t result; 242c87c5fbaSopenharmony_ci 243c87c5fbaSopenharmony_ci result = coap_opt_setheader((coap_opt_t *)buf, sizeof(buf), 0, 0); 244c87c5fbaSopenharmony_ci CU_ASSERT(result == sizeof(teststr)); 245c87c5fbaSopenharmony_ci 246c87c5fbaSopenharmony_ci CU_ASSERT(memcmp(buf, teststr, result) == 0); 247c87c5fbaSopenharmony_ci} 248c87c5fbaSopenharmony_ci 249c87c5fbaSopenharmony_cistatic void 250c87c5fbaSopenharmony_cit_encode_option2(void) { 251c87c5fbaSopenharmony_ci uint8_t teststr[] = { 0x5d, 0xff }; 252c87c5fbaSopenharmony_ci unsigned char buf[40]; 253c87c5fbaSopenharmony_ci size_t result; 254c87c5fbaSopenharmony_ci 255c87c5fbaSopenharmony_ci result = coap_opt_setheader((coap_opt_t *)buf, sizeof(buf), 5, 268); 256c87c5fbaSopenharmony_ci CU_ASSERT(result == sizeof(teststr)); 257c87c5fbaSopenharmony_ci 258c87c5fbaSopenharmony_ci CU_ASSERT(memcmp(buf, teststr, result) == 0); 259c87c5fbaSopenharmony_ci} 260c87c5fbaSopenharmony_ci 261c87c5fbaSopenharmony_cistatic void 262c87c5fbaSopenharmony_cit_encode_option3(void) { 263c87c5fbaSopenharmony_ci uint8_t teststr[] = { 0xd1, 0x01 }; 264c87c5fbaSopenharmony_ci unsigned char buf[40]; 265c87c5fbaSopenharmony_ci size_t result; 266c87c5fbaSopenharmony_ci 267c87c5fbaSopenharmony_ci result = coap_opt_setheader((coap_opt_t *)buf, sizeof(buf), 14, 1); 268c87c5fbaSopenharmony_ci CU_ASSERT(result == sizeof(teststr)); 269c87c5fbaSopenharmony_ci 270c87c5fbaSopenharmony_ci CU_ASSERT(memcmp(buf, teststr, result) == 0); 271c87c5fbaSopenharmony_ci} 272c87c5fbaSopenharmony_ci 273c87c5fbaSopenharmony_cistatic void 274c87c5fbaSopenharmony_cit_encode_option4(void) { 275c87c5fbaSopenharmony_ci uint8_t teststr[] = { 0xdd, 0xff, 0xab }; 276c87c5fbaSopenharmony_ci unsigned char buf[40]; 277c87c5fbaSopenharmony_ci size_t result; 278c87c5fbaSopenharmony_ci 279c87c5fbaSopenharmony_ci result = coap_opt_setheader((coap_opt_t *)buf, sizeof(buf), 268, 184); 280c87c5fbaSopenharmony_ci CU_ASSERT(result == sizeof(teststr)); 281c87c5fbaSopenharmony_ci 282c87c5fbaSopenharmony_ci CU_ASSERT(memcmp(buf, teststr, result) == 0); 283c87c5fbaSopenharmony_ci} 284c87c5fbaSopenharmony_ci 285c87c5fbaSopenharmony_cistatic void 286c87c5fbaSopenharmony_cit_encode_option5(void) { 287c87c5fbaSopenharmony_ci uint8_t teststr[] = { 0xed, 0x13, 0x00, 0xff }; 288c87c5fbaSopenharmony_ci unsigned char buf[40]; 289c87c5fbaSopenharmony_ci size_t result; 290c87c5fbaSopenharmony_ci 291c87c5fbaSopenharmony_ci result = coap_opt_setheader((coap_opt_t *)buf, sizeof(buf), 5133, 268); 292c87c5fbaSopenharmony_ci CU_ASSERT(result == sizeof(teststr)); 293c87c5fbaSopenharmony_ci 294c87c5fbaSopenharmony_ci CU_ASSERT(memcmp(buf, teststr, result) == 0); 295c87c5fbaSopenharmony_ci} 296c87c5fbaSopenharmony_ci 297c87c5fbaSopenharmony_cistatic void 298c87c5fbaSopenharmony_cit_encode_option6(void) { 299c87c5fbaSopenharmony_ci uint8_t teststr[] = { 0xee, 0xfe, 0xf2, 0xfe, 0xf2 }; 300c87c5fbaSopenharmony_ci unsigned char buf[40]; 301c87c5fbaSopenharmony_ci size_t result; 302c87c5fbaSopenharmony_ci 303c87c5fbaSopenharmony_ci result = coap_opt_setheader((coap_opt_t *)buf, sizeof(buf), 65535, 65535); 304c87c5fbaSopenharmony_ci CU_ASSERT(result == sizeof(teststr)); 305c87c5fbaSopenharmony_ci 306c87c5fbaSopenharmony_ci CU_ASSERT(memcmp(buf, teststr, result) == 0); 307c87c5fbaSopenharmony_ci} 308c87c5fbaSopenharmony_ci 309c87c5fbaSopenharmony_cistatic void 310c87c5fbaSopenharmony_cit_encode_option7(void) { 311c87c5fbaSopenharmony_ci uint8_t teststr[] = { 0x35, 'v', 'a', 'l', 'u', 'e' }; 312c87c5fbaSopenharmony_ci const size_t valoff = 1; 313c87c5fbaSopenharmony_ci unsigned char buf[40]; 314c87c5fbaSopenharmony_ci size_t result; 315c87c5fbaSopenharmony_ci 316c87c5fbaSopenharmony_ci result = coap_opt_encode((coap_opt_t *)buf, sizeof(buf), 3, 317c87c5fbaSopenharmony_ci (unsigned char *)teststr + valoff, 318c87c5fbaSopenharmony_ci sizeof(teststr) - valoff); 319c87c5fbaSopenharmony_ci 320c87c5fbaSopenharmony_ci CU_ASSERT(result == sizeof(teststr)); 321c87c5fbaSopenharmony_ci 322c87c5fbaSopenharmony_ci CU_ASSERT(memcmp(buf, teststr, sizeof(teststr)) == 0); 323c87c5fbaSopenharmony_ci} 324c87c5fbaSopenharmony_ci 325c87c5fbaSopenharmony_cistatic void 326c87c5fbaSopenharmony_cit_encode_option8(void) { 327c87c5fbaSopenharmony_ci /* value does not fit in message buffer */ 328c87c5fbaSopenharmony_ci unsigned char buf[40]; 329c87c5fbaSopenharmony_ci size_t result; 330c87c5fbaSopenharmony_ci 331c87c5fbaSopenharmony_ci result = coap_opt_encode((coap_opt_t *)buf, 8, 15, 332c87c5fbaSopenharmony_ci (const uint8_t *)"something", 9); 333c87c5fbaSopenharmony_ci 334c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 335c87c5fbaSopenharmony_ci 336c87c5fbaSopenharmony_ci result = coap_opt_encode((coap_opt_t *)buf, 1, 15, 337c87c5fbaSopenharmony_ci (const uint8_t *)"something", 9); 338c87c5fbaSopenharmony_ci 339c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 340c87c5fbaSopenharmony_ci} 341c87c5fbaSopenharmony_ci 342c87c5fbaSopenharmony_cistatic void 343c87c5fbaSopenharmony_cit_encode_option9(void) { 344c87c5fbaSopenharmony_ci uint8_t teststr[] = { 0xe1, 0x00, 0x00 }; 345c87c5fbaSopenharmony_ci unsigned char buf[40] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 346c87c5fbaSopenharmony_ci size_t result; 347c87c5fbaSopenharmony_ci 348c87c5fbaSopenharmony_ci result = coap_opt_setheader((coap_opt_t *)buf, sizeof(buf), 269, 1); 349c87c5fbaSopenharmony_ci CU_ASSERT(result == sizeof(teststr)); 350c87c5fbaSopenharmony_ci 351c87c5fbaSopenharmony_ci CU_ASSERT(memcmp(buf, teststr, result) == 0); 352c87c5fbaSopenharmony_ci} 353c87c5fbaSopenharmony_ci 354c87c5fbaSopenharmony_ci/************************************************************************ 355c87c5fbaSopenharmony_ci ** accessor tests 356c87c5fbaSopenharmony_ci ************************************************************************/ 357c87c5fbaSopenharmony_ci 358c87c5fbaSopenharmony_cistatic void 359c87c5fbaSopenharmony_cit_access_option1(void) { 360c87c5fbaSopenharmony_ci const uint8_t teststr[] = { 0x12, 'a', 'b' }; 361c87c5fbaSopenharmony_ci coap_option_t opt; 362c87c5fbaSopenharmony_ci 363c87c5fbaSopenharmony_ci CU_ASSERT(sizeof(teststr) == coap_opt_parse((const coap_opt_t *)teststr, 364c87c5fbaSopenharmony_ci sizeof(teststr), &opt)); 365c87c5fbaSopenharmony_ci CU_ASSERT(opt.delta == 1); 366c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_length((const coap_opt_t *)teststr) == 2); 367c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL_C(coap_opt_value((const coap_opt_t *)teststr), teststr + 1); 368c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_size((const coap_opt_t *)teststr) == sizeof(teststr)); 369c87c5fbaSopenharmony_ci} 370c87c5fbaSopenharmony_ci 371c87c5fbaSopenharmony_cistatic void 372c87c5fbaSopenharmony_cit_access_option2(void) { 373c87c5fbaSopenharmony_ci const uint8_t teststr[] = { 0xe2, 0x18, 0xfd, 'a', 'b' }; 374c87c5fbaSopenharmony_ci coap_option_t opt; 375c87c5fbaSopenharmony_ci 376c87c5fbaSopenharmony_ci CU_ASSERT(sizeof(teststr) == coap_opt_parse((const coap_opt_t *)teststr, 377c87c5fbaSopenharmony_ci sizeof(teststr), &opt)); 378c87c5fbaSopenharmony_ci CU_ASSERT(opt.delta == 6666); 379c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_length((const coap_opt_t *)teststr) == 2); 380c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL_C(coap_opt_value((const coap_opt_t *)teststr), teststr + 3); 381c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_size((const coap_opt_t *)teststr) == sizeof(teststr)); 382c87c5fbaSopenharmony_ci} 383c87c5fbaSopenharmony_ci 384c87c5fbaSopenharmony_cistatic void 385c87c5fbaSopenharmony_cit_access_option3(void) { 386c87c5fbaSopenharmony_ci const uint8_t teststr[] = { 0xed, 0x18, 0x0a, 0x00, 'a', 'b', 'c', 'd', 387c87c5fbaSopenharmony_ci 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 388c87c5fbaSopenharmony_ci 'm' 389c87c5fbaSopenharmony_ci }; 390c87c5fbaSopenharmony_ci coap_option_t opt; 391c87c5fbaSopenharmony_ci 392c87c5fbaSopenharmony_ci CU_ASSERT(sizeof(teststr) == coap_opt_parse((const coap_opt_t *)teststr, 393c87c5fbaSopenharmony_ci sizeof(teststr), &opt)); 394c87c5fbaSopenharmony_ci CU_ASSERT(opt.delta == 6423); 395c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_length((const coap_opt_t *)teststr) == 13); 396c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL_C(coap_opt_value((const coap_opt_t *)teststr), teststr + 4); 397c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_size((const coap_opt_t *)teststr) == sizeof(teststr)); 398c87c5fbaSopenharmony_ci} 399c87c5fbaSopenharmony_ci 400c87c5fbaSopenharmony_cistatic void 401c87c5fbaSopenharmony_cit_access_option4(void) { 402c87c5fbaSopenharmony_ci const uint8_t teststr[] = { 0xde, 0xff, 0xfe, 0xf2, 'a', 'b', 'c' }; 403c87c5fbaSopenharmony_ci coap_option_t opt; 404c87c5fbaSopenharmony_ci 405c87c5fbaSopenharmony_ci CU_ASSERT(0 == coap_opt_parse((const coap_opt_t *)teststr, 406c87c5fbaSopenharmony_ci sizeof(teststr), &opt)); 407c87c5fbaSopenharmony_ci CU_ASSERT(opt.delta == 268); 408c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_length((const coap_opt_t *)teststr) == 65535); 409c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL_C(coap_opt_value((const coap_opt_t *)teststr), teststr + 4); 410c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_size((const coap_opt_t *)teststr) == 65535 + 4); 411c87c5fbaSopenharmony_ci} 412c87c5fbaSopenharmony_ci 413c87c5fbaSopenharmony_cistatic void 414c87c5fbaSopenharmony_cit_access_option5(void) { 415c87c5fbaSopenharmony_ci const uint8_t teststr[] = { 0xee, 0xfe, 0xf2, 0x00, 0xdd, 'a', 'b', 'c' }; 416c87c5fbaSopenharmony_ci coap_option_t opt; 417c87c5fbaSopenharmony_ci 418c87c5fbaSopenharmony_ci CU_ASSERT(0 == coap_opt_parse((const coap_opt_t *)teststr, 419c87c5fbaSopenharmony_ci sizeof(teststr), &opt)); 420c87c5fbaSopenharmony_ci CU_ASSERT(opt.delta == 65535); 421c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_length((const coap_opt_t *)teststr) == 490); 422c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL_C(coap_opt_value((const coap_opt_t *)teststr), teststr + 5); 423c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_size((const coap_opt_t *)teststr) == 495); 424c87c5fbaSopenharmony_ci} 425c87c5fbaSopenharmony_ci 426c87c5fbaSopenharmony_cistatic void 427c87c5fbaSopenharmony_cit_access_option6(void) { 428c87c5fbaSopenharmony_ci coap_log_t level = coap_get_log_level(); 429c87c5fbaSopenharmony_ci const uint8_t teststr[] = { 0xf2, 'a', 'b' }; 430c87c5fbaSopenharmony_ci coap_option_t opt; 431c87c5fbaSopenharmony_ci 432c87c5fbaSopenharmony_ci coap_set_log_level(COAP_LOG_CRIT); 433c87c5fbaSopenharmony_ci 434c87c5fbaSopenharmony_ci CU_ASSERT(0 == coap_opt_parse((const coap_opt_t *)teststr, 435c87c5fbaSopenharmony_ci sizeof(teststr), &opt)); 436c87c5fbaSopenharmony_ci coap_set_log_level(level); 437c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_length((const coap_opt_t *)teststr) == 0); 438c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL_C(coap_opt_value((const coap_opt_t *)teststr), NULL); 439c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_size((const coap_opt_t *)teststr) == 0); 440c87c5fbaSopenharmony_ci} 441c87c5fbaSopenharmony_ci 442c87c5fbaSopenharmony_cistatic void 443c87c5fbaSopenharmony_cit_access_option7(void) { 444c87c5fbaSopenharmony_ci const uint8_t teststr[] = { 0x2f, 'a', 'b' }; 445c87c5fbaSopenharmony_ci coap_option_t opt; 446c87c5fbaSopenharmony_ci 447c87c5fbaSopenharmony_ci CU_ASSERT(0 == coap_opt_parse((const coap_opt_t *)teststr, 448c87c5fbaSopenharmony_ci sizeof(teststr), &opt)); 449c87c5fbaSopenharmony_ci CU_ASSERT(opt.delta == 2); 450c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_length((const coap_opt_t *)teststr) == 0); 451c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL_C(coap_opt_value((const coap_opt_t *)teststr), NULL); 452c87c5fbaSopenharmony_ci CU_ASSERT(coap_opt_size((const coap_opt_t *)teststr) == 0); 453c87c5fbaSopenharmony_ci} 454c87c5fbaSopenharmony_ci 455c87c5fbaSopenharmony_ci/************************************************************************ 456c87c5fbaSopenharmony_ci ** accessor tests 457c87c5fbaSopenharmony_ci ************************************************************************/ 458c87c5fbaSopenharmony_ci 459c87c5fbaSopenharmony_ci#define TEST_MAX_SIZE 1000 460c87c5fbaSopenharmony_ci 461c87c5fbaSopenharmony_ci#ifdef _MSC_VER 462c87c5fbaSopenharmony_ci# define ALIGNED(x) 463c87c5fbaSopenharmony_ci#else 464c87c5fbaSopenharmony_ci# define ALIGNED(x) __attribute__ ((aligned (x))) 465c87c5fbaSopenharmony_ci#endif 466c87c5fbaSopenharmony_ci 467c87c5fbaSopenharmony_cistatic void 468c87c5fbaSopenharmony_cit_iterate_option1(void) { 469c87c5fbaSopenharmony_ci /* CoAP PDU without token, options, or data */ 470c87c5fbaSopenharmony_ci uint8_t teststr[] ALIGNED(8) = { 471c87c5fbaSopenharmony_ci 0x00, 0x00, 0x00, 0x00 472c87c5fbaSopenharmony_ci }; 473c87c5fbaSopenharmony_ci 474c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 475c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 476c87c5fbaSopenharmony_ci .token = teststr, 477c87c5fbaSopenharmony_ci .used_size = 0 478c87c5fbaSopenharmony_ci }; 479c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 480c87c5fbaSopenharmony_ci coap_opt_t *option; 481c87c5fbaSopenharmony_ci 482c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, COAP_OPT_ALL); 483c87c5fbaSopenharmony_ci 484c87c5fbaSopenharmony_ci CU_ASSERT(result == NULL); 485c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 486c87c5fbaSopenharmony_ci 487c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 488c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 489c87c5fbaSopenharmony_ci CU_ASSERT(option == NULL); 490c87c5fbaSopenharmony_ci} 491c87c5fbaSopenharmony_ci 492c87c5fbaSopenharmony_cistatic void 493c87c5fbaSopenharmony_cit_iterate_option2(void) { 494c87c5fbaSopenharmony_ci /* CoAP PDU with token but without options and data */ 495c87c5fbaSopenharmony_ci uint8_t teststr[3] ALIGNED(8) = { 496c87c5fbaSopenharmony_ci 't', 'o', 'k' 497c87c5fbaSopenharmony_ci }; 498c87c5fbaSopenharmony_ci 499c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 500c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 501c87c5fbaSopenharmony_ci .e_token_length = 3, 502c87c5fbaSopenharmony_ci .token = teststr, 503c87c5fbaSopenharmony_ci .used_size = sizeof(teststr) 504c87c5fbaSopenharmony_ci }; 505c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 506c87c5fbaSopenharmony_ci coap_opt_t *option; 507c87c5fbaSopenharmony_ci 508c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, COAP_OPT_ALL); 509c87c5fbaSopenharmony_ci 510c87c5fbaSopenharmony_ci CU_ASSERT(result == NULL); 511c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 512c87c5fbaSopenharmony_ci 513c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 514c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 515c87c5fbaSopenharmony_ci CU_ASSERT(option == NULL); 516c87c5fbaSopenharmony_ci} 517c87c5fbaSopenharmony_ci 518c87c5fbaSopenharmony_cistatic void 519c87c5fbaSopenharmony_cit_iterate_option3(void) { 520c87c5fbaSopenharmony_ci /* CoAP PDU with token and options */ 521c87c5fbaSopenharmony_ci uint8_t teststr[] ALIGNED(8) = { 522c87c5fbaSopenharmony_ci 't', 'o', 'k', 0x13, 523c87c5fbaSopenharmony_ci 'o', 'p', 't', 0x00, 0xd1, 0x10, 'x' 524c87c5fbaSopenharmony_ci }; 525c87c5fbaSopenharmony_ci 526c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 527c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 528c87c5fbaSopenharmony_ci .e_token_length = 3, 529c87c5fbaSopenharmony_ci .token = teststr, 530c87c5fbaSopenharmony_ci .used_size = sizeof(teststr) 531c87c5fbaSopenharmony_ci }; 532c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 533c87c5fbaSopenharmony_ci coap_opt_t *option; 534c87c5fbaSopenharmony_ci 535c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, COAP_OPT_ALL); 536c87c5fbaSopenharmony_ci 537c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(result, &oi); 538c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 539c87c5fbaSopenharmony_ci 540c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 541c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 542c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 1); 543c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 3); 544c87c5fbaSopenharmony_ci 545c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 546c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 547c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 1); 548c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 7); 549c87c5fbaSopenharmony_ci 550c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 551c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 552c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 30); 553c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 8); 554c87c5fbaSopenharmony_ci 555c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 556c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 557c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, NULL); 558c87c5fbaSopenharmony_ci} 559c87c5fbaSopenharmony_ci 560c87c5fbaSopenharmony_cistatic void 561c87c5fbaSopenharmony_cit_iterate_option4(void) { 562c87c5fbaSopenharmony_ci /* CoAP PDU with token, options, and data */ 563c87c5fbaSopenharmony_ci uint8_t teststr[] ALIGNED(8) = { 564c87c5fbaSopenharmony_ci 't', 'o', 'k', 0x13, 565c87c5fbaSopenharmony_ci 'o', 'p', 't', 0x00, 0xd1, 0x10, 'x', 0xff, 566c87c5fbaSopenharmony_ci 'd', 'a', 't', 'a' 567c87c5fbaSopenharmony_ci }; 568c87c5fbaSopenharmony_ci 569c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 570c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 571c87c5fbaSopenharmony_ci .e_token_length = 3, 572c87c5fbaSopenharmony_ci .token = teststr, 573c87c5fbaSopenharmony_ci .used_size = sizeof(teststr) 574c87c5fbaSopenharmony_ci }; 575c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 576c87c5fbaSopenharmony_ci coap_opt_t *option; 577c87c5fbaSopenharmony_ci 578c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, COAP_OPT_ALL); 579c87c5fbaSopenharmony_ci 580c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(result, &oi); 581c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 582c87c5fbaSopenharmony_ci 583c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 584c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 585c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 1); 586c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 3); 587c87c5fbaSopenharmony_ci 588c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 589c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 590c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 1); 591c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 7); 592c87c5fbaSopenharmony_ci 593c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 594c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 595c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 30); 596c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 8); 597c87c5fbaSopenharmony_ci 598c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 599c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 600c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, NULL); 601c87c5fbaSopenharmony_ci} 602c87c5fbaSopenharmony_ci 603c87c5fbaSopenharmony_cistatic void 604c87c5fbaSopenharmony_cit_iterate_option5(void) { 605c87c5fbaSopenharmony_ci /* CoAP PDU with malformed option */ 606c87c5fbaSopenharmony_ci uint8_t teststr[] ALIGNED(8) = { 607c87c5fbaSopenharmony_ci 0x52, 'o', 'p', 0xee, 608c87c5fbaSopenharmony_ci 0x12, 0x03, 0x00 609c87c5fbaSopenharmony_ci }; 610c87c5fbaSopenharmony_ci 611c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 612c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 613c87c5fbaSopenharmony_ci .e_token_length = 0, 614c87c5fbaSopenharmony_ci .token = teststr, 615c87c5fbaSopenharmony_ci .used_size = sizeof(teststr) 616c87c5fbaSopenharmony_ci }; 617c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 618c87c5fbaSopenharmony_ci coap_opt_t *option; 619c87c5fbaSopenharmony_ci 620c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, COAP_OPT_ALL); 621c87c5fbaSopenharmony_ci 622c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(result, &oi); 623c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 624c87c5fbaSopenharmony_ci 625c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 626c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 627c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 5); 628c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr); 629c87c5fbaSopenharmony_ci 630c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 631c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 632c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, NULL); 633c87c5fbaSopenharmony_ci} 634c87c5fbaSopenharmony_ci 635c87c5fbaSopenharmony_cistatic void 636c87c5fbaSopenharmony_cit_iterate_option6(void) { 637c87c5fbaSopenharmony_ci /* option filter */ 638c87c5fbaSopenharmony_ci /* CoAP PDU with token, options, and data */ 639c87c5fbaSopenharmony_ci uint8_t teststr[] ALIGNED(8) = { 640c87c5fbaSopenharmony_ci 0x80, 0x20, 0x00, 0x00, 641c87c5fbaSopenharmony_ci 0xc0, 0x00 642c87c5fbaSopenharmony_ci }; 643c87c5fbaSopenharmony_ci 644c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 645c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 646c87c5fbaSopenharmony_ci .e_token_length = 0, 647c87c5fbaSopenharmony_ci .token = teststr, 648c87c5fbaSopenharmony_ci .used_size = sizeof(teststr) 649c87c5fbaSopenharmony_ci }; 650c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 651c87c5fbaSopenharmony_ci coap_opt_t *option; 652c87c5fbaSopenharmony_ci coap_opt_filter_t filter; 653c87c5fbaSopenharmony_ci 654c87c5fbaSopenharmony_ci coap_option_filter_clear(&filter); 655c87c5fbaSopenharmony_ci coap_option_filter_set(&filter, 10); /* option nr 10 only */ 656c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, &filter); 657c87c5fbaSopenharmony_ci 658c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(result, &oi); 659c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 660c87c5fbaSopenharmony_ci 661c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 662c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 663c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 10); 664c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 1); 665c87c5fbaSopenharmony_ci 666c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 667c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 668c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 10); 669c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 2); 670c87c5fbaSopenharmony_ci 671c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 672c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 673c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 10); 674c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 3); 675c87c5fbaSopenharmony_ci 676c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 677c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 678c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, NULL); 679c87c5fbaSopenharmony_ci} 680c87c5fbaSopenharmony_ci 681c87c5fbaSopenharmony_cistatic void 682c87c5fbaSopenharmony_cit_iterate_option7(void) { 683c87c5fbaSopenharmony_ci /* option filter */ 684c87c5fbaSopenharmony_ci uint8_t teststr[] ALIGNED(8) = { 685c87c5fbaSopenharmony_ci 0x80, 0x20, 0x00, 0x00, 686c87c5fbaSopenharmony_ci 0xc0, 0x00, 0x10, 0x10, 0x00 687c87c5fbaSopenharmony_ci }; 688c87c5fbaSopenharmony_ci 689c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 690c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 691c87c5fbaSopenharmony_ci .e_token_length = 0, 692c87c5fbaSopenharmony_ci .token = teststr, 693c87c5fbaSopenharmony_ci .used_size = sizeof(teststr) 694c87c5fbaSopenharmony_ci }; 695c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 696c87c5fbaSopenharmony_ci coap_opt_t *option; 697c87c5fbaSopenharmony_ci coap_opt_filter_t filter; 698c87c5fbaSopenharmony_ci 699c87c5fbaSopenharmony_ci /* search options nr 8 and 22 */ 700c87c5fbaSopenharmony_ci coap_option_filter_clear(&filter); 701c87c5fbaSopenharmony_ci coap_option_filter_set(&filter, 8); 702c87c5fbaSopenharmony_ci coap_option_filter_set(&filter, 22); 703c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, &filter); 704c87c5fbaSopenharmony_ci 705c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(result, &oi); 706c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 707c87c5fbaSopenharmony_ci 708c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 709c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 710c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 8); 711c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr); 712c87c5fbaSopenharmony_ci 713c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 714c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 715c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 22); 716c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 4); 717c87c5fbaSopenharmony_ci 718c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 719c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 720c87c5fbaSopenharmony_ci CU_ASSERT(oi.number == 22); 721c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 5); 722c87c5fbaSopenharmony_ci 723c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 724c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 725c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, NULL); 726c87c5fbaSopenharmony_ci} 727c87c5fbaSopenharmony_ci 728c87c5fbaSopenharmony_cistatic void 729c87c5fbaSopenharmony_cit_iterate_option8(void) { 730c87c5fbaSopenharmony_ci /* option filter */ 731c87c5fbaSopenharmony_ci uint8_t teststr[] ALIGNED(8) = { 732c87c5fbaSopenharmony_ci 0x80, 0x20, 0x00, 0x00, 733c87c5fbaSopenharmony_ci 0xc0, 0x00, 0x10, 0x10, 0x00 734c87c5fbaSopenharmony_ci }; 735c87c5fbaSopenharmony_ci 736c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 737c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 738c87c5fbaSopenharmony_ci .e_token_length = 0, 739c87c5fbaSopenharmony_ci .token = teststr, 740c87c5fbaSopenharmony_ci .used_size = sizeof(teststr) 741c87c5fbaSopenharmony_ci }; 742c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 743c87c5fbaSopenharmony_ci coap_opt_t *option; 744c87c5fbaSopenharmony_ci coap_opt_filter_t filter; 745c87c5fbaSopenharmony_ci 746c87c5fbaSopenharmony_ci /* search option nr 36 */ 747c87c5fbaSopenharmony_ci coap_option_filter_clear(&filter); 748c87c5fbaSopenharmony_ci coap_option_filter_set(&filter, 36); 749c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, &filter); 750c87c5fbaSopenharmony_ci 751c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(result, &oi); 752c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 753c87c5fbaSopenharmony_ci 754c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 755c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 756c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, NULL); 757c87c5fbaSopenharmony_ci} 758c87c5fbaSopenharmony_ci 759c87c5fbaSopenharmony_cistatic void 760c87c5fbaSopenharmony_cit_iterate_option9(void) { 761c87c5fbaSopenharmony_ci /* options filter: option number too large for filter */ 762c87c5fbaSopenharmony_ci uint8_t teststr[] ALIGNED(8) = { 763c87c5fbaSopenharmony_ci 0x80, 0x20, 0x00, 0x00, 764c87c5fbaSopenharmony_ci 0xc0, 0x00, 0x10, 0x10, 0x00 765c87c5fbaSopenharmony_ci }; 766c87c5fbaSopenharmony_ci 767c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 768c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 769c87c5fbaSopenharmony_ci .e_token_length = 0, 770c87c5fbaSopenharmony_ci .token = teststr, 771c87c5fbaSopenharmony_ci .used_size = sizeof(teststr) 772c87c5fbaSopenharmony_ci }; 773c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 774c87c5fbaSopenharmony_ci coap_opt_t *option; 775c87c5fbaSopenharmony_ci coap_opt_filter_t filter; 776c87c5fbaSopenharmony_ci 777c87c5fbaSopenharmony_ci /* search option nr 100 */ 778c87c5fbaSopenharmony_ci coap_option_filter_clear(&filter); 779c87c5fbaSopenharmony_ci coap_option_filter_set(&filter, 100); 780c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, &filter); 781c87c5fbaSopenharmony_ci 782c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(result, &oi); 783c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 784c87c5fbaSopenharmony_ci 785c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 786c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 787c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, NULL); 788c87c5fbaSopenharmony_ci} 789c87c5fbaSopenharmony_ci 790c87c5fbaSopenharmony_cistatic void 791c87c5fbaSopenharmony_cit_iterate_option10(void) { 792c87c5fbaSopenharmony_ci /* options filter: option numbers in PDU exceed filter size */ 793c87c5fbaSopenharmony_ci uint8_t teststr[] ALIGNED(8) = { 794c87c5fbaSopenharmony_ci 0x80, 0x20, 0x00, 0x00, 795c87c5fbaSopenharmony_ci 0xd0, 0x26, 0xe0, 0x10, 0x00 796c87c5fbaSopenharmony_ci }; 797c87c5fbaSopenharmony_ci 798c87c5fbaSopenharmony_ci coap_pdu_t pdu = { 799c87c5fbaSopenharmony_ci .max_size = TEST_MAX_SIZE, 800c87c5fbaSopenharmony_ci .e_token_length = 0, 801c87c5fbaSopenharmony_ci .token = teststr, 802c87c5fbaSopenharmony_ci .used_size = sizeof(teststr) 803c87c5fbaSopenharmony_ci }; 804c87c5fbaSopenharmony_ci coap_opt_iterator_t oi, *result; 805c87c5fbaSopenharmony_ci coap_opt_t *option; 806c87c5fbaSopenharmony_ci coap_opt_filter_t filter; 807c87c5fbaSopenharmony_ci 808c87c5fbaSopenharmony_ci /* search option nr 61 */ 809c87c5fbaSopenharmony_ci coap_option_filter_clear(&filter); 810c87c5fbaSopenharmony_ci coap_option_filter_set(&filter, 61); 811c87c5fbaSopenharmony_ci result = coap_option_iterator_init(&pdu, &oi, &filter); 812c87c5fbaSopenharmony_ci 813c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(result, &oi); 814c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 815c87c5fbaSopenharmony_ci 816c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 817c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 0); 818c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, teststr + 4); 819c87c5fbaSopenharmony_ci 820c87c5fbaSopenharmony_ci option = coap_option_next(&oi); 821c87c5fbaSopenharmony_ci CU_ASSERT(oi.bad == 1); 822c87c5fbaSopenharmony_ci CU_ASSERT_PTR_EQUAL(option, NULL); 823c87c5fbaSopenharmony_ci} 824c87c5fbaSopenharmony_ci 825c87c5fbaSopenharmony_ci/************************************************************************ 826c87c5fbaSopenharmony_ci ** filter tests 827c87c5fbaSopenharmony_ci ************************************************************************/ 828c87c5fbaSopenharmony_ci 829c87c5fbaSopenharmony_cistatic void 830c87c5fbaSopenharmony_cit_filter_option1(void) { 831c87c5fbaSopenharmony_ci coap_opt_filter_t filter; 832c87c5fbaSopenharmony_ci 833c87c5fbaSopenharmony_ci coap_option_filter_clear(&filter); 834c87c5fbaSopenharmony_ci 835c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 0) == 1); 836c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 37) == 1); 837c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 37) == 1); 838c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 43) == 1); 839c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 290) == 1); 840c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 65535) == 1); 841c87c5fbaSopenharmony_ci 842c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 0) == 1); 843c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 37) == 1); 844c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 43) == 1); 845c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 290) == 1); 846c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 65535) == 1); 847c87c5fbaSopenharmony_ci 848c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_unset(&filter, 37) == 1); 849c87c5fbaSopenharmony_ci 850c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 0) == 1); 851c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 43) == 1); 852c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 290) == 1); 853c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 65535) == 1); 854c87c5fbaSopenharmony_ci 855c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 37) == 0); 856c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 89) == 0); 857c87c5fbaSopenharmony_ci} 858c87c5fbaSopenharmony_ci 859c87c5fbaSopenharmony_cistatic void 860c87c5fbaSopenharmony_cit_filter_option2(void) { 861c87c5fbaSopenharmony_ci coap_opt_filter_t filter; 862c87c5fbaSopenharmony_ci int s; 863c87c5fbaSopenharmony_ci 864c87c5fbaSopenharmony_ci coap_option_filter_clear(&filter); 865c87c5fbaSopenharmony_ci 866c87c5fbaSopenharmony_ci /* fill all COAP_OPT_FILTER_SHORT slots */ 867c87c5fbaSopenharmony_ci for (s = 0; s < COAP_OPT_FILTER_SHORT; s++) { 868c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, s)); 869c87c5fbaSopenharmony_ci } 870c87c5fbaSopenharmony_ci 871c87c5fbaSopenharmony_ci /* adding a short option type must fail */ 872c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, COAP_OPT_FILTER_SHORT) == 0); 873c87c5fbaSopenharmony_ci 874c87c5fbaSopenharmony_ci /* adding a long option type must succeed */ 875c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 256) == 1); 876c87c5fbaSopenharmony_ci} 877c87c5fbaSopenharmony_ci 878c87c5fbaSopenharmony_cistatic void 879c87c5fbaSopenharmony_cit_filter_option3(void) { 880c87c5fbaSopenharmony_ci coap_opt_filter_t filter; 881c87c5fbaSopenharmony_ci int l; 882c87c5fbaSopenharmony_ci 883c87c5fbaSopenharmony_ci coap_option_filter_clear(&filter); 884c87c5fbaSopenharmony_ci 885c87c5fbaSopenharmony_ci /* set COAP_OPT_FILTER_LONG long filters */ 886c87c5fbaSopenharmony_ci for (l = 0; l < COAP_OPT_FILTER_LONG; l++) { 887c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 256 + l) == 1); 888c87c5fbaSopenharmony_ci } 889c87c5fbaSopenharmony_ci 890c87c5fbaSopenharmony_ci /* the next must fail and must not be found */ 891c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 256 + COAP_OPT_FILTER_LONG) == 0); 892c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 256 + COAP_OPT_FILTER_LONG) == 0); 893c87c5fbaSopenharmony_ci 894c87c5fbaSopenharmony_ci /* remove one item */ 895c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_unset(&filter, 256) == 1); 896c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 256) == 0); 897c87c5fbaSopenharmony_ci 898c87c5fbaSopenharmony_ci /* now, storing a new filter must succeed */ 899c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, 256 + COAP_OPT_FILTER_LONG) == 1); 900c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 256 + COAP_OPT_FILTER_LONG) == 1); 901c87c5fbaSopenharmony_ci 902c87c5fbaSopenharmony_ci /* and all other items must be available as well */ 903c87c5fbaSopenharmony_ci for (l = 0; l < COAP_OPT_FILTER_LONG; l++) { 904c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 256 + l + 1) == 1); 905c87c5fbaSopenharmony_ci } 906c87c5fbaSopenharmony_ci 907c87c5fbaSopenharmony_ci /* set COAP_OPT_FILTER_SHORT short filters */ 908c87c5fbaSopenharmony_ci for (l = 0; l < COAP_OPT_FILTER_SHORT; l++) { 909c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, l) == 1); 910c87c5fbaSopenharmony_ci } 911c87c5fbaSopenharmony_ci 912c87c5fbaSopenharmony_ci /* the next must fail and must not be found */ 913c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, COAP_OPT_FILTER_SHORT) == 0); 914c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, COAP_OPT_FILTER_SHORT) == 0); 915c87c5fbaSopenharmony_ci 916c87c5fbaSopenharmony_ci /* remove one item */ 917c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_unset(&filter, 0) == 1); 918c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, 0) == 0); 919c87c5fbaSopenharmony_ci 920c87c5fbaSopenharmony_ci /* now, storing a new filter must succeed */ 921c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_set(&filter, COAP_OPT_FILTER_SHORT) == 1); 922c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, COAP_OPT_FILTER_SHORT) == 1); 923c87c5fbaSopenharmony_ci 924c87c5fbaSopenharmony_ci /* and all other items must be available as well */ 925c87c5fbaSopenharmony_ci for (l = 0; l < COAP_OPT_FILTER_SHORT; l++) { 926c87c5fbaSopenharmony_ci CU_ASSERT(coap_option_filter_get(&filter, l + 1) == 1); 927c87c5fbaSopenharmony_ci } 928c87c5fbaSopenharmony_ci} 929c87c5fbaSopenharmony_ci 930c87c5fbaSopenharmony_ci/************************************************************************ 931c87c5fbaSopenharmony_ci ** initialization 932c87c5fbaSopenharmony_ci ************************************************************************/ 933c87c5fbaSopenharmony_ci 934c87c5fbaSopenharmony_ciCU_pSuite 935c87c5fbaSopenharmony_cit_init_option_tests(void) { 936c87c5fbaSopenharmony_ci CU_pSuite suite[5]; 937c87c5fbaSopenharmony_ci 938c87c5fbaSopenharmony_ci suite[0] = CU_add_suite("option parser", NULL, NULL); 939c87c5fbaSopenharmony_ci if (!suite[0]) { /* signal error */ 940c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option parser test suite (%s)\n", 941c87c5fbaSopenharmony_ci CU_get_error_msg()); 942c87c5fbaSopenharmony_ci 943c87c5fbaSopenharmony_ci return NULL; 944c87c5fbaSopenharmony_ci } 945c87c5fbaSopenharmony_ci 946c87c5fbaSopenharmony_ci#define OPTION_TEST(n,s) \ 947c87c5fbaSopenharmony_ci if (!CU_add_test(suite[0], s, t_parse_option##n)) { \ 948c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option parser test (%s)\n", \ 949c87c5fbaSopenharmony_ci CU_get_error_msg()); \ 950c87c5fbaSopenharmony_ci } 951c87c5fbaSopenharmony_ci 952c87c5fbaSopenharmony_ci OPTION_TEST(1, "parse option #1"); 953c87c5fbaSopenharmony_ci OPTION_TEST(2, "parse option #2"); 954c87c5fbaSopenharmony_ci OPTION_TEST(3, "parse option #3"); 955c87c5fbaSopenharmony_ci OPTION_TEST(4, "parse option #4"); 956c87c5fbaSopenharmony_ci OPTION_TEST(5, "parse option #5"); 957c87c5fbaSopenharmony_ci OPTION_TEST(6, "parse option #6"); 958c87c5fbaSopenharmony_ci OPTION_TEST(7, "parse option #7"); 959c87c5fbaSopenharmony_ci OPTION_TEST(8, "parse option #8"); 960c87c5fbaSopenharmony_ci OPTION_TEST(9, "parse option #9"); 961c87c5fbaSopenharmony_ci OPTION_TEST(10, "parse option #10"); 962c87c5fbaSopenharmony_ci OPTION_TEST(11, "parse option #11"); 963c87c5fbaSopenharmony_ci OPTION_TEST(12, "parse option #12"); 964c87c5fbaSopenharmony_ci OPTION_TEST(13, "parse option #13"); 965c87c5fbaSopenharmony_ci OPTION_TEST(14, "parse option #14"); 966c87c5fbaSopenharmony_ci 967c87c5fbaSopenharmony_ci if ((suite[1] = CU_add_suite("option encoder", NULL, NULL))) { 968c87c5fbaSopenharmony_ci#define OPTION_ENCODER_TEST(n,s) \ 969c87c5fbaSopenharmony_ci if (!CU_add_test(suite[1], s, t_encode_option##n)) { \ 970c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option encoder test (%s)\n", \ 971c87c5fbaSopenharmony_ci CU_get_error_msg()); \ 972c87c5fbaSopenharmony_ci } 973c87c5fbaSopenharmony_ci 974c87c5fbaSopenharmony_ci OPTION_ENCODER_TEST(1, "encode option #1"); 975c87c5fbaSopenharmony_ci OPTION_ENCODER_TEST(2, "encode option #2"); 976c87c5fbaSopenharmony_ci OPTION_ENCODER_TEST(3, "encode option #3"); 977c87c5fbaSopenharmony_ci OPTION_ENCODER_TEST(4, "encode option #4"); 978c87c5fbaSopenharmony_ci OPTION_ENCODER_TEST(5, "encode option #5"); 979c87c5fbaSopenharmony_ci OPTION_ENCODER_TEST(6, "encode option #6"); 980c87c5fbaSopenharmony_ci OPTION_ENCODER_TEST(7, "encode option #7"); 981c87c5fbaSopenharmony_ci OPTION_ENCODER_TEST(8, "encode option #8"); 982c87c5fbaSopenharmony_ci OPTION_ENCODER_TEST(9, "encode option #9"); 983c87c5fbaSopenharmony_ci 984c87c5fbaSopenharmony_ci } else { 985c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option encoder test suite (%s)\n", 986c87c5fbaSopenharmony_ci CU_get_error_msg()); 987c87c5fbaSopenharmony_ci } 988c87c5fbaSopenharmony_ci 989c87c5fbaSopenharmony_ci if ((suite[2] = CU_add_suite("option accessors", NULL, NULL))) { 990c87c5fbaSopenharmony_ci#define OPTION_ACCESSOR_TEST(n,s) \ 991c87c5fbaSopenharmony_ci if (!CU_add_test(suite[2], s, t_access_option##n)) { \ 992c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option accessor function test (%s)\n", \ 993c87c5fbaSopenharmony_ci CU_get_error_msg()); \ 994c87c5fbaSopenharmony_ci } 995c87c5fbaSopenharmony_ci 996c87c5fbaSopenharmony_ci OPTION_ACCESSOR_TEST(1, "access option #1"); 997c87c5fbaSopenharmony_ci OPTION_ACCESSOR_TEST(2, "access option #2"); 998c87c5fbaSopenharmony_ci OPTION_ACCESSOR_TEST(3, "access option #3"); 999c87c5fbaSopenharmony_ci OPTION_ACCESSOR_TEST(4, "access option #4"); 1000c87c5fbaSopenharmony_ci OPTION_ACCESSOR_TEST(5, "access option #5"); 1001c87c5fbaSopenharmony_ci OPTION_ACCESSOR_TEST(6, "access option #6"); 1002c87c5fbaSopenharmony_ci OPTION_ACCESSOR_TEST(7, "access option #7"); 1003c87c5fbaSopenharmony_ci 1004c87c5fbaSopenharmony_ci } else { 1005c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option acessor function test suite (%s)\n", 1006c87c5fbaSopenharmony_ci CU_get_error_msg()); 1007c87c5fbaSopenharmony_ci } 1008c87c5fbaSopenharmony_ci 1009c87c5fbaSopenharmony_ci if ((suite[3] = CU_add_suite("option iterator", NULL, NULL))) { 1010c87c5fbaSopenharmony_ci#define OPTION_ITERATOR_TEST(n,s) \ 1011c87c5fbaSopenharmony_ci if (!CU_add_test(suite[3], s, t_iterate_option##n)) { \ 1012c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option iterator test (%s)\n", \ 1013c87c5fbaSopenharmony_ci CU_get_error_msg()); \ 1014c87c5fbaSopenharmony_ci } 1015c87c5fbaSopenharmony_ci 1016c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(1, "option iterator #1"); 1017c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(2, "option iterator #2"); 1018c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(3, "option iterator #3"); 1019c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(4, "option iterator #4"); 1020c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(5, "option iterator #5"); 1021c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(6, "option iterator #6"); 1022c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(7, "option iterator #7"); 1023c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(8, "option iterator #8"); 1024c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(9, "option iterator #9"); 1025c87c5fbaSopenharmony_ci OPTION_ITERATOR_TEST(10, "option iterator #10"); 1026c87c5fbaSopenharmony_ci 1027c87c5fbaSopenharmony_ci } else { 1028c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option iterator test suite (%s)\n", 1029c87c5fbaSopenharmony_ci CU_get_error_msg()); 1030c87c5fbaSopenharmony_ci } 1031c87c5fbaSopenharmony_ci 1032c87c5fbaSopenharmony_ci if ((suite[4] = CU_add_suite("option filter", NULL, NULL))) { 1033c87c5fbaSopenharmony_ci#define OPTION_FILTER_TEST(n,s) \ 1034c87c5fbaSopenharmony_ci if (!CU_add_test(suite[4], s, t_filter_option##n)) { \ 1035c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option filter test (%s)\n", \ 1036c87c5fbaSopenharmony_ci CU_get_error_msg()); \ 1037c87c5fbaSopenharmony_ci } 1038c87c5fbaSopenharmony_ci 1039c87c5fbaSopenharmony_ci OPTION_FILTER_TEST(1, "option filter #1"); 1040c87c5fbaSopenharmony_ci OPTION_FILTER_TEST(2, "option filter #2"); 1041c87c5fbaSopenharmony_ci OPTION_FILTER_TEST(3, "option filter #3"); 1042c87c5fbaSopenharmony_ci 1043c87c5fbaSopenharmony_ci } else { 1044c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add option filter test suite (%s)\n", 1045c87c5fbaSopenharmony_ci CU_get_error_msg()); 1046c87c5fbaSopenharmony_ci } 1047c87c5fbaSopenharmony_ci 1048c87c5fbaSopenharmony_ci return suite[0]; 1049c87c5fbaSopenharmony_ci} 1050