ON Semiconductor / mbed-os

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers libCoap_builder_test.cpp Source File

libCoap_builder_test.cpp

00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "CppUTest/TestHarness.h"
00017 #include <string.h>
00018 #include <stdint.h>
00019 #include "sn_nsdl.h"
00020 #include "sn_coap_header.h"
00021 #include "sn_coap_protocol_internal.h"
00022 
00023 #include "sn_coap_header_check_stub.h"
00024 #include "sn_coap_parser_stub.h"
00025 
00026 sn_coap_hdr_s coap_header;
00027 sn_coap_options_list_s option_list;
00028 uint8_t buffer[356];
00029 uint8_t temp[10];
00030 
00031 uint8_t retCounter = 0;
00032 
00033 static void *own_alloc(uint16_t size)
00034 {
00035     if( retCounter > 0 ){
00036         retCounter--;
00037         return malloc(size);
00038     }
00039     return NULL;
00040 }
00041 
00042 static void own_free(void *ptr)
00043 {
00044     free(ptr);
00045 }
00046 
00047 TEST_GROUP(libCoap_builder)
00048 {
00049     void setup() {
00050         sn_coap_header_check_stub.expectedInt8 = 0;
00051         retCounter = 0;
00052         memset(&coap_header, 0, sizeof(sn_coap_hdr_s));
00053         memset(&option_list, 0, sizeof(sn_coap_options_list_s));
00054 
00055         coap_header.options_list_ptr = &option_list;
00056         coap_header.msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT;
00057         coap_header.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
00058         coap_header.msg_id = 12;
00059     }
00060 
00061     void teardown() {
00062 
00063     }
00064 };
00065 
00066 TEST(libCoap_builder, build_confirmable_response)
00067 {
00068     struct coap_s handle;
00069     sn_coap_hdr_s *response = NULL;
00070 
00071     handle.sn_coap_protocol_malloc = &own_alloc;
00072     handle.sn_coap_protocol_free = &own_free;
00073 
00074     coap_header.msg_type = COAP_MSG_TYPE_RESET;
00075     coap_header.msg_code = COAP_MSG_CODE_REQUEST_GET;
00076     coap_header.msg_id = 12;
00077 
00078     //NULL pointer
00079     CHECK(sn_coap_build_response(NULL, NULL, 0) == NULL);
00080     CHECK(sn_coap_build_response(&handle, NULL, 0) == NULL);
00081     CHECK(sn_coap_build_response(NULL, &coap_header, 0) == NULL);
00082     CHECK(sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT) == NULL);
00083 
00084     retCounter = 1;
00085     CHECK(sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT) == NULL);
00086 
00087     coap_header.msg_type = COAP_MSG_TYPE_CONFIRMABLE;
00088 
00089     retCounter = 2;
00090     response = sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT);
00091 
00092     CHECK(response != NULL);
00093     CHECK(response->msg_type == COAP_MSG_TYPE_ACKNOWLEDGEMENT);
00094     CHECK(response->msg_id == 12);
00095     CHECK(response->msg_code == COAP_MSG_CODE_RESPONSE_CONTENT);
00096 
00097     own_free(response);
00098 }
00099 
00100 TEST(libCoap_builder, build_non_confirmable_response)
00101 {
00102     struct coap_s handle;
00103     sn_coap_hdr_s *response = NULL;
00104     uint8_t token_val = 0x99;
00105 
00106     handle.sn_coap_protocol_malloc = &own_alloc;
00107     handle.sn_coap_protocol_free = &own_free;
00108 
00109     coap_header.msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE;
00110     coap_header.msg_code = COAP_MSG_CODE_REQUEST_GET;
00111     coap_header.msg_id = 12;
00112     coap_header.token_len = 1;
00113     coap_header.token_ptr = &token_val;
00114 
00115     retCounter = 1;
00116     CHECK( NULL == sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT));
00117 
00118     retCounter = 2;
00119     response = sn_coap_build_response(&handle, &coap_header, COAP_MSG_CODE_RESPONSE_CONTENT);
00120 
00121     CHECK(response != NULL);
00122     CHECK(response->msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE);
00123     CHECK(response->msg_code == COAP_MSG_CODE_RESPONSE_CONTENT);
00124     CHECK(response->token_ptr != NULL);
00125     CHECK(memcmp(response->token_ptr, coap_header.token_ptr, coap_header.token_len) == 0);
00126     CHECK(response->token_len == coap_header.token_len);
00127 
00128     own_free(response->token_ptr);
00129     response->token_ptr = NULL;
00130     own_free(response);
00131     response = NULL;
00132 }
00133 
00134 TEST(libCoap_builder, build_message_negative_cases)
00135 {
00136     // Null pointers as a parameter
00137     CHECK(sn_coap_builder(NULL, NULL) == -2);
00138     CHECK(sn_coap_builder(NULL, &coap_header) == -2);
00139     CHECK(sn_coap_builder(buffer, NULL) == -2);
00140 
00141     // Invalid option length
00142     coap_header.token_ptr = temp;
00143     CHECK(sn_coap_builder(buffer, &coap_header) == -1);
00144 }
00145 
00146 TEST(libCoap_builder, build_message_ok_cases)
00147 {
00148     CHECK(sn_coap_builder(buffer, &coap_header) == 11);
00149 }
00150 
00151 TEST(libCoap_builder, build_message_options_token)
00152 {
00153     coap_header.token_ptr = temp;
00154     coap_header.token_len = 2;
00155     CHECK(sn_coap_builder(buffer, &coap_header) == 13);
00156 }
00157 
00158 TEST(libCoap_builder, build_message_options_uri_path)
00159 {
00160     coap_header.uri_path_ptr = temp;
00161     coap_header.uri_path_len = 2;
00162     CHECK(sn_coap_builder(buffer, &coap_header) == 11);
00163 }
00164 
00165 TEST(libCoap_builder, build_message_options_content_type)
00166 {
00167     coap_header.content_format = COAP_CT_TEXT_PLAIN;
00168     CHECK(sn_coap_builder(buffer, &coap_header) == 11);
00169 }
00170 
00171 TEST(libCoap_builder, build_message_options_max_age)
00172 {
00173     coap_header.options_list_ptr->max_age = 1;
00174     CHECK(sn_coap_builder(buffer, &coap_header) == 12);
00175 }
00176 
00177 TEST(libCoap_builder, build_message_options_proxy_uri)
00178 {
00179     coap_header.options_list_ptr->proxy_uri_ptr = temp;
00180     coap_header.options_list_ptr->proxy_uri_len = 2;
00181     CHECK(sn_coap_builder(buffer, &coap_header) == 14);
00182 }
00183 
00184 TEST(libCoap_builder, build_message_options_etag)
00185 {
00186     coap_header.options_list_ptr->etag_ptr = temp;
00187     coap_header.options_list_ptr->etag_len = 2;
00188     CHECK(sn_coap_builder(buffer, &coap_header) == 14);
00189 }
00190 
00191 TEST(libCoap_builder, build_message_options_uri_host)
00192 {
00193     coap_header.options_list_ptr->uri_host_ptr = temp;
00194     coap_header.options_list_ptr->uri_host_len = 2;
00195     CHECK(sn_coap_builder(buffer, &coap_header) == 14);
00196 }
00197 
00198 TEST(libCoap_builder, build_message_options_location_path)
00199 {
00200     coap_header.options_list_ptr->location_path_ptr = temp;
00201     coap_header.options_list_ptr->location_path_len = 2;
00202     CHECK(sn_coap_builder(buffer, &coap_header) == 14);
00203 }
00204 
00205 TEST(libCoap_builder, build_message_options_uri_port)
00206 {
00207     coap_header.options_list_ptr->uri_port = 2;
00208     CHECK(sn_coap_builder(buffer, &coap_header) == 12);
00209 }
00210 
00211 
00212 TEST(libCoap_builder, build_message_options_location_query)
00213 {
00214     coap_header.options_list_ptr->location_query_ptr = temp;
00215     coap_header.options_list_ptr->location_query_len = 2;
00216     CHECK(sn_coap_builder(buffer, &coap_header) == 14);
00217 }
00218 
00219 TEST(libCoap_builder, build_message_options_observe)
00220 {
00221     coap_header.options_list_ptr->observe = 0;
00222     CHECK(sn_coap_builder(buffer, &coap_header) == 11);
00223 }
00224 
00225 
00226 TEST(libCoap_builder, build_message_options_accept)
00227 {
00228     coap_header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN;
00229     CHECK(sn_coap_builder(buffer, &coap_header) == 11);
00230 }
00231 
00232 TEST(libCoap_builder, build_message_options_uri_query)
00233 {
00234     coap_header.options_list_ptr->uri_query_ptr = temp;
00235     temp[0] = '1';
00236     temp[1] = '&';
00237     temp[2] = '2';
00238     temp[3] = '&';
00239     temp[4] = '3';
00240     temp[5] = '\0';
00241     coap_header.options_list_ptr->uri_query_len = 6;
00242     uint8_t val = sn_coap_builder(buffer, &coap_header);
00243     CHECK( val == 18);
00244     memset(&temp, 0, 10);
00245 }
00246 
00247 
00248 TEST(libCoap_builder, build_message_options_block1)
00249 {
00250     coap_header.options_list_ptr->block1 = 267;
00251     CHECK(sn_coap_builder(buffer, &coap_header) == 13);
00252 }
00253 
00254 TEST(libCoap_builder, build_message_options_block2)
00255 {
00256     coap_header.options_list_ptr->block2 = 267;
00257 
00258     sn_coap_header_check_stub.expectedInt8 = 44;
00259     CHECK(sn_coap_builder(buffer, &coap_header) == -1);
00260 
00261     sn_coap_header_check_stub.expectedInt8 = 0;
00262     CHECK(sn_coap_builder(buffer, &coap_header) == 13);
00263 
00264     coap_header.options_list_ptr = NULL; //return from sn_coap_builder_options_build immediately
00265     sn_coap_header_check_stub.expectedInt8 = 0;
00266     CHECK( 5 == sn_coap_builder(buffer, &coap_header) );
00267 }
00268 
00269 TEST(libCoap_builder, sn_coap_builder_calc_needed_packet_data_size)
00270 {
00271     CHECK(sn_coap_builder_calc_needed_packet_data_size(NULL) == 0);
00272 
00273     sn_coap_hdr_s header;
00274     memset(&header, 0, sizeof(sn_coap_hdr_s));
00275     header.msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT;
00276     header.token_ptr = (uint8_t*)malloc(10);
00277     header.token_len = 10;
00278     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00279     free(header.token_ptr);
00280     header.token_ptr = (uint8_t*)malloc(6);
00281     header.token_len = 6;
00282 
00283     //Test variations of sn_coap_builder_options_calc_option_size here -->
00284     header.uri_path_ptr = (uint8_t*)malloc(290);
00285     memset(header.uri_path_ptr, '1', 290);
00286     header.uri_path_len = 290;
00287     header.uri_path_ptr[5] = '/';
00288     header.uri_path_ptr[285] = '/';
00289 
00290     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00291 
00292     header.uri_path_ptr[285] = '1';
00293     header.uri_path_ptr[170] = '/';
00294 
00295     header.content_format = sn_coap_content_format_e(0xFFFF22);
00296     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00297 
00298     header.content_format = COAP_CT_TEXT_PLAIN;
00299     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 304);
00300 
00301     sn_coap_options_list_s opt_list;
00302     memset(&opt_list, 0, sizeof(sn_coap_options_list_s));
00303     header.options_list_ptr = &opt_list;
00304 
00305     header.options_list_ptr->accept = sn_coap_content_format_e(0xFFFF22);
00306     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00307 
00308     header.options_list_ptr->observe = COAP_OBSERVE_NONE;
00309     header.options_list_ptr->uri_port = COAP_OPTION_URI_PORT_NONE;
00310     free(header.uri_path_ptr);
00311     header.uri_path_ptr = NULL;
00312     header.content_format = COAP_CT_NONE;
00313     header.options_list_ptr->max_age = COAP_OPTION_MAX_AGE_DEFAULT;
00314     header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN;
00315     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 14);
00316 
00317     header.options_list_ptr->max_age = 6;
00318     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 16);
00319 
00320     //proxy uri tests (4)
00321     header.options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(1800);
00322     header.options_list_ptr->proxy_uri_len = 1800;
00323     header.options_list_ptr->max_age = COAP_OPTION_MAX_AGE_DEFAULT;
00324     header.options_list_ptr->accept = COAP_CT_NONE;
00325 
00326     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00327     header.options_list_ptr->proxy_uri_len = 6;
00328     header.options_list_ptr->etag_ptr = (uint8_t*)malloc(4);
00329     header.options_list_ptr->etag_len = 0;
00330     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00331 
00332     header.options_list_ptr->proxy_uri_len = 14;
00333     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00334 
00335     // init now the buffer up to 4 bytes, as it will be accessed
00336     memset(header.options_list_ptr->etag_ptr, 0, 4);
00337     
00338     header.options_list_ptr->proxy_uri_len = 281;
00339     header.options_list_ptr->block1 = COAP_OPTION_BLOCK_NONE;
00340     header.options_list_ptr->block2 = COAP_OPTION_BLOCK_NONE;
00341     header.options_list_ptr->etag_len = 4;
00342     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 300);
00343 
00344     header.options_list_ptr->uri_host_ptr = (uint8_t*)malloc(6);
00345     header.options_list_ptr->uri_host_len = 0;
00346     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00347 
00348     header.options_list_ptr->uri_host_len = 4;
00349     header.options_list_ptr->location_path_ptr = (uint8_t*)calloc(270, 1);
00350     header.options_list_ptr->location_path_len = 270;
00351     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00352 
00353     header.options_list_ptr->uri_host_len = 44;
00354     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00355 
00356     header.options_list_ptr->location_path_len = 27;
00357     header.options_list_ptr->uri_port = 0xffff22;
00358     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00359 
00360     header.options_list_ptr->uri_port = 6;
00361     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 377);
00362 
00363     header.options_list_ptr->location_query_ptr = (uint8_t*)calloc(277, 1);
00364     header.options_list_ptr->location_query_len = 277;
00365     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00366 
00367     header.options_list_ptr->location_query_len = 27;
00368     header.options_list_ptr->observe = 0;
00369     free(header.options_list_ptr->location_path_ptr);
00370     header.options_list_ptr->location_path_ptr = NULL;
00371     header.options_list_ptr->location_path_len = 0;
00372     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 379);
00373 
00374     header.options_list_ptr->uri_query_ptr = (uint8_t*)malloc(6);
00375     header.options_list_ptr->uri_query_len = 0;
00376     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00377 
00378     // init the 4 bytes to something useful, leave rest uninitialized to let valgrind warn if builder is processing past buffer
00379     memset(header.options_list_ptr->uri_query_ptr, 0, 4);
00380     header.options_list_ptr->uri_query_len = 4;
00381     header.options_list_ptr->block2 = -1;
00382     header.options_list_ptr->observe = 0xFFFFFF22;
00383     header.options_list_ptr->uri_port = COAP_OPTION_URI_PORT_NONE;
00384     free(header.options_list_ptr->etag_ptr);
00385     header.options_list_ptr->etag_ptr = NULL;
00386     header.options_list_ptr->etag_len = 0;
00387     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00388 
00389     header.options_list_ptr->observe = COAP_OBSERVE_NONE;
00390     free(header.options_list_ptr->uri_host_ptr);
00391     header.options_list_ptr->uri_host_ptr = NULL;
00392     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 330);
00393 
00394     header.options_list_ptr->observe = 1;
00395     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 331);
00396 
00397     header.options_list_ptr->block2 = 0xFFFFFF22;
00398     header.options_list_ptr->block1 = -1;
00399     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);
00400 
00401     header.options_list_ptr->block2 = 267;
00402     free(header.options_list_ptr->location_query_ptr);
00403     header.options_list_ptr->location_query_ptr = NULL;
00404     free(header.options_list_ptr->uri_query_ptr);
00405     header.options_list_ptr->uri_query_ptr = NULL;
00406     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 300);
00407 
00408     header.options_list_ptr->block1 = 0xFFFFFF22;
00409     header.payload_len = 1;
00410     CHECK(0 == sn_coap_builder_calc_needed_packet_data_size(&header));
00411 
00412     header.options_list_ptr->block1 = 267;
00413     header.payload_len = 1;
00414     header.options_list_ptr->block2 = COAP_OPTION_BLOCK_NONE;
00415     CHECK(302 == sn_coap_builder_calc_needed_packet_data_size(&header));
00416 
00417     header.options_list_ptr->block1 = COAP_OPTION_BLOCK_NONE;
00418     header.options_list_ptr->size1 = 266;
00419     header.options_list_ptr->use_size1 = true;
00420 
00421     CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 303);
00422 
00423     header.options_list_ptr->size2 = 266;
00424     header.options_list_ptr->use_size2 = true;
00425     header.payload_len = 1;
00426     CHECK(306 == sn_coap_builder_calc_needed_packet_data_size(&header));
00427 
00428     header.options_list_ptr->use_size1 = false;
00429     header.options_list_ptr->use_size2 = false;
00430     // <--
00431     free(header.options_list_ptr->location_query_ptr);
00432     free(header.options_list_ptr->location_path_ptr);
00433     free(header.options_list_ptr->uri_host_ptr);
00434     free(header.options_list_ptr->etag_ptr);
00435     free(header.options_list_ptr->proxy_uri_ptr);
00436     header.options_list_ptr->location_query_ptr = NULL;
00437     header.options_list_ptr->location_path_ptr = NULL;
00438     header.options_list_ptr->uri_host_ptr = NULL;
00439     header.options_list_ptr->etag_ptr = NULL;
00440     header.options_list_ptr->proxy_uri_ptr = NULL;
00441     CHECK(14 == sn_coap_builder_calc_needed_packet_data_size(&header));
00442     free(header.options_list_ptr->uri_query_ptr);
00443 
00444     //Test sn_coap_builder_options_calculate_jump_need "else" case
00445     header.options_list_ptr = NULL;
00446     uint16_t val = sn_coap_builder_calc_needed_packet_data_size(&header);
00447     CHECK( 12 == val );
00448 
00449     free(header.uri_path_ptr);
00450     free(header.token_ptr);
00451 }
00452 
00453 
00454 TEST(libCoap_builder, sn_coap_builder_options_build_add_one_option)
00455 {
00456     coap_header.options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(280);
00457     memset(coap_header.options_list_ptr->proxy_uri_ptr, '1', 280);
00458     coap_header.options_list_ptr->proxy_uri_len = 2;
00459     sn_coap_header_check_stub.expectedInt8 = 0;
00460     CHECK(sn_coap_builder(buffer, &coap_header) == 14);
00461 
00462     coap_header.options_list_ptr->proxy_uri_len = 27;
00463     sn_coap_header_check_stub.expectedInt8 = 0;
00464     CHECK(40 == sn_coap_builder(buffer, &coap_header));
00465 
00466     coap_header.options_list_ptr->proxy_uri_len = 277;
00467     sn_coap_header_check_stub.expectedInt8 = 0;
00468     CHECK(291 == sn_coap_builder(buffer, &coap_header));
00469 
00470     free(coap_header.options_list_ptr->proxy_uri_ptr);
00471     coap_header.options_list_ptr->proxy_uri_ptr = NULL;
00472     coap_header.options_list_ptr->proxy_uri_len = 0;
00473 }
00474 
00475 TEST(libCoap_builder, sn_coap_builder_options_build_add_zero_length_option)
00476 {
00477     coap_header.options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(280);
00478     memset(coap_header.options_list_ptr->proxy_uri_ptr, '1', 280);
00479     coap_header.options_list_ptr->proxy_uri_len = 2;
00480     sn_coap_header_check_stub.expectedInt8 = 0;
00481     coap_header.options_list_ptr->observe = 1;
00482     int16_t val = sn_coap_builder(buffer, &coap_header);
00483     CHECK(val == 15);
00484 
00485     free(coap_header.options_list_ptr->proxy_uri_ptr);
00486 }
00487 
00488 TEST(libCoap_builder, sn_coap_builder_options_get_option_part_position)
00489 {
00490     sn_coap_hdr_s header;
00491     memset(&header, 0, sizeof(sn_coap_hdr_s));
00492     sn_coap_options_list_s opt_list;
00493     memset(&opt_list, 0, sizeof(sn_coap_options_list_s));
00494     header.options_list_ptr = &opt_list;
00495     header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN;
00496     uint16_t val = sn_coap_builder(buffer, &header);
00497     CHECK(val == 11);
00498 
00499     header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN;
00500     val = sn_coap_builder(buffer, &header);
00501     CHECK(val == 11);
00502 }
00503 
00504 TEST(libCoap_builder, sn_coap_builder_payload_build)
00505 {
00506     sn_coap_hdr_s header;
00507     memset(&header, 0, sizeof(sn_coap_hdr_s));
00508     header.payload_ptr = (uint8_t*)malloc(5);
00509     header.payload_len = 5;
00510     sn_coap_options_list_s opt_list;
00511     memset(&opt_list, 0, sizeof(sn_coap_options_list_s));
00512     header.options_list_ptr = &opt_list;
00513     header.options_list_ptr->accept = COAP_CT_TEXT_PLAIN;
00514     uint16_t val = sn_coap_builder(buffer, &header);
00515     CHECK(val == 17);
00516 
00517     header.content_format = COAP_CT_NONE;
00518     header.options_list_ptr->uri_port = -1;
00519     header.options_list_ptr->observe = COAP_OBSERVE_NONE;
00520     header.options_list_ptr->accept = COAP_CT_NONE;
00521     header.options_list_ptr->block2 = COAP_OPTION_BLOCK_NONE;
00522     header.options_list_ptr->block1 = 13;
00523     header.options_list_ptr->use_size1 = true;
00524     header.options_list_ptr->use_size2 = true;
00525     header.options_list_ptr->max_age = COAP_OPTION_MAX_AGE_DEFAULT;
00526 
00527     val = sn_coap_builder(buffer, &header);
00528     CHECK(val == 16);
00529 
00530     free(header.payload_ptr);
00531 }