Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: blinky_max32630fthr
test_sn_nsdl.c
00001 /* 00002 * Copyright (c) 2015 ARM. All rights reserved. 00003 */ 00004 #include "test_sn_nsdl.h" 00005 #include <string.h> 00006 #include <inttypes.h> 00007 00008 #include "sn_coap_header.h" 00009 #include "sn_nsdl.h" 00010 #include "sn_nsdl_lib.h" 00011 #include "sn_grs.h" 00012 00013 #include "sn_grs_stub.h" 00014 #include "sn_coap_builder_stub.h" 00015 #include "sn_coap_protocol_stub.h" 00016 00017 int retCounter = 0; 00018 uint8_t rxRetVal = 0; 00019 00020 void* myMalloc(uint16_t size) 00021 { 00022 if( retCounter > 0 ){ 00023 retCounter--; 00024 return malloc(size); 00025 }else { 00026 return NULL; 00027 } 00028 } 00029 00030 void myFree(void* ptr){ 00031 free(ptr); 00032 } 00033 00034 void myBootstrapCallback(sn_nsdl_oma_server_info_t *server_info_ptr){ 00035 00036 } 00037 00038 void myBootstrapCallbackHandle(sn_nsdl_oma_server_info_t *server_info_ptr, struct nsdl_s *a){ 00039 00040 } 00041 00042 uint8_t nsdl_tx_callback(struct nsdl_s *a, sn_nsdl_capab_e b, uint8_t *c, uint16_t d, sn_nsdl_addr_s *e) 00043 { 00044 00045 } 00046 00047 uint8_t nsdl_rx_callback(struct nsdl_s *a, sn_coap_hdr_s *b, sn_nsdl_addr_s *c) 00048 { 00049 return rxRetVal; 00050 } 00051 00052 bool test_sn_nsdl_destroy() 00053 { 00054 if( SN_NSDL_FAILURE != sn_nsdl_destroy(NULL) ){ 00055 return false; 00056 } 00057 00058 struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 00059 handle->sn_nsdl_alloc = myMalloc; 00060 handle->sn_nsdl_free = myFree; 00061 handle->oma_bs_address_ptr = (uint8_t*)malloc(5); 00062 00063 handle->ep_information_ptr = (sn_nsdl_ep_parameters_s *)malloc(sizeof(sn_nsdl_ep_parameters_s)); 00064 memset(handle->ep_information_ptr,0,sizeof(sn_nsdl_ep_parameters_s)); 00065 handle->ep_information_ptr->endpoint_name_ptr = (uint8_t*)malloc(5); 00066 handle->ep_information_ptr->domain_name_ptr = (uint8_t*)malloc(5); 00067 handle->ep_information_ptr->type_ptr = (uint8_t*)malloc(5); 00068 handle->ep_information_ptr->lifetime_ptr = (uint8_t*)malloc(5); 00069 handle->ep_information_ptr->location_ptr = (uint8_t*)malloc(5); 00070 00071 handle->nsp_address_ptr = (sn_nsdl_oma_server_info_t *)malloc(sizeof(sn_nsdl_oma_server_info_t)); 00072 handle->nsp_address_ptr->omalw_address_ptr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); 00073 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(5); 00074 00075 handle->grs = (struct grs_s *)malloc(sizeof(struct grs_s)); 00076 00077 int8_t ret = sn_nsdl_destroy(handle); 00078 return ret == SN_NSDL_SUCCESS; 00079 } 00080 00081 bool test_sn_nsdl_init() 00082 { 00083 if( NULL != sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, NULL) ){ 00084 return false; 00085 } 00086 00087 retCounter = 0; 00088 if( NULL != sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree) ){ 00089 return false; 00090 } 00091 00092 retCounter = 1; 00093 if( NULL != sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree) ){ 00094 return false; 00095 } 00096 00097 sn_grs_stub.retNull = true; 00098 retCounter = 2; 00099 if( NULL != sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree) ){ 00100 return false; 00101 } 00102 00103 sn_grs_stub.retNull = false; 00104 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); //gets deleted during call 00105 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 00106 retCounter = 4; 00107 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 00108 sn_grs_stub.expectedGrs = NULL; 00109 if( NULL == handle ){ 00110 return false; 00111 } 00112 sn_nsdl_destroy(handle); 00113 00114 return true; 00115 } 00116 00117 bool test_sn_nsdl_register_endpoint() 00118 { 00119 if( 0 != sn_nsdl_register_endpoint(NULL, NULL) ){ 00120 return false; 00121 } 00122 sn_grs_stub.retNull = false; 00123 retCounter = 5; 00124 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 00125 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 00126 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 00127 sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); 00128 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; 00129 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; 00130 sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; 00131 sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; 00132 00133 sn_nsdl_ep_parameters_s *eptr = (sn_nsdl_ep_parameters_s*)malloc(sizeof(sn_nsdl_ep_parameters_s)); 00134 memset(eptr, 0, sizeof(sn_nsdl_ep_parameters_s)); 00135 00136 if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ 00137 return false; 00138 } 00139 00140 retCounter = 0; 00141 if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ 00142 return false; 00143 } 00144 00145 retCounter = 1; 00146 if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ 00147 return false; 00148 } 00149 00150 bool ret = true; 00151 00152 retCounter = 2; 00153 eptr->endpoint_name_ptr = (uint8_t*)malloc(2); 00154 eptr->endpoint_name_ptr[0] = 'a'; 00155 eptr->endpoint_name_ptr[1] = '\0'; 00156 eptr->endpoint_name_len = 1; 00157 eptr->type_ptr = (uint8_t*)malloc(2); 00158 eptr->type_ptr[0] = 'a'; 00159 eptr->type_ptr[1] = '\0'; 00160 eptr->type_len = 1; 00161 eptr->lifetime_ptr = (uint8_t*)malloc(2); 00162 eptr->lifetime_ptr[0] = 'a'; 00163 eptr->lifetime_ptr[1] = '\0'; 00164 eptr->lifetime_len = 1; 00165 eptr->domain_name_ptr = (uint8_t*)malloc(2); 00166 eptr->domain_name_ptr[0] = 'a'; 00167 eptr->domain_name_ptr[1] = '\0'; 00168 eptr->domain_name_len = 1; 00169 eptr->binding_and_mode = 0x07; 00170 00171 if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ 00172 ret = false; 00173 goto end; 00174 } 00175 00176 //Test validateParameters here --> 00177 ret = true; 00178 00179 retCounter = 2; 00180 eptr->endpoint_name_ptr[0] = '&'; 00181 eptr->endpoint_name_ptr[1] = '\0'; 00182 eptr->endpoint_name_len = 1; 00183 eptr->type_ptr[0] = 'a'; 00184 eptr->type_ptr[1] = '\0'; 00185 eptr->type_len = 1; 00186 eptr->lifetime_ptr[0] = 'a'; 00187 eptr->lifetime_ptr[1] = '\0'; 00188 eptr->lifetime_len = 1; 00189 eptr->domain_name_ptr[0] = 'a'; 00190 eptr->domain_name_ptr[1] = '\0'; 00191 eptr->domain_name_len = 1; 00192 eptr->binding_and_mode = 0x07; 00193 00194 if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ 00195 ret = false; 00196 goto end; 00197 } 00198 00199 ret = true; 00200 00201 retCounter = 2; 00202 eptr->endpoint_name_ptr[0] = 'a'; 00203 eptr->endpoint_name_ptr[1] = '\0'; 00204 eptr->endpoint_name_len = 1; 00205 eptr->type_ptr[0] = '&'; 00206 eptr->type_ptr[1] = '\0'; 00207 eptr->type_len = 1; 00208 eptr->lifetime_ptr[0] = 'a'; 00209 eptr->lifetime_ptr[1] = '\0'; 00210 eptr->lifetime_len = 1; 00211 eptr->domain_name_ptr[0] = 'a'; 00212 eptr->domain_name_ptr[1] = '\0'; 00213 eptr->domain_name_len = 1; 00214 eptr->binding_and_mode = 0x07; 00215 00216 if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ 00217 ret = false; 00218 goto end; 00219 } 00220 00221 ret = true; 00222 00223 retCounter = 2; 00224 eptr->endpoint_name_ptr[0] = 'a'; 00225 eptr->endpoint_name_ptr[1] = '\0'; 00226 eptr->endpoint_name_len = 1; 00227 eptr->type_ptr[0] = 'a'; 00228 eptr->type_ptr[1] = '\0'; 00229 eptr->type_len = 1; 00230 eptr->lifetime_ptr[0] = '&'; 00231 eptr->lifetime_ptr[1] = '\0'; 00232 eptr->lifetime_len = 1; 00233 eptr->domain_name_ptr[0] = 'a'; 00234 eptr->domain_name_ptr[1] = '\0'; 00235 eptr->domain_name_len = 1; 00236 eptr->binding_and_mode = 0x07; 00237 00238 if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ 00239 ret = false; 00240 goto end; 00241 } 00242 00243 ret = true; 00244 00245 retCounter = 2; 00246 eptr->endpoint_name_ptr[0] = 'a'; 00247 eptr->endpoint_name_ptr[1] = '\0'; 00248 eptr->endpoint_name_len = 1; 00249 eptr->type_ptr[0] = 'a'; 00250 eptr->type_ptr[1] = '\0'; 00251 eptr->type_len = 1; 00252 eptr->lifetime_ptr[0] = 'a'; 00253 eptr->lifetime_ptr[1] = '\0'; 00254 eptr->lifetime_len = 1; 00255 eptr->domain_name_ptr[0] = '&'; 00256 eptr->domain_name_ptr[1] = '\0'; 00257 eptr->domain_name_len = 1; 00258 eptr->binding_and_mode = 0x07; 00259 00260 if( 0 != sn_nsdl_register_endpoint(handle, eptr) ){ 00261 ret = false; 00262 goto end; 00263 } 00264 eptr->domain_name_ptr[0] = 'a'; 00265 //<-- Test validateParameters here 00266 00267 eptr->binding_and_mode = 0x07; 00268 retCounter = 3; 00269 sn_grs_stub.infoRetCounter = 2; 00270 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00271 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00272 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00273 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; 00274 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); 00275 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; 00276 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; 00277 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00278 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; 00279 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; 00280 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; 00281 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00282 00283 sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); 00284 sn_grs_stub.expectedInfo->path[0] = 'a'; 00285 sn_grs_stub.expectedInfo->path[1] = '\0'; 00286 sn_grs_stub.expectedInfo->pathlen = 1; 00287 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); 00288 sn_grs_stub.expectedInfo->resource[0] = 'a'; 00289 sn_grs_stub.expectedInfo->resource[1] = '\0'; 00290 sn_grs_stub.expectedInfo->resourcelen = 1; 00291 sn_grs_stub.expectedInfo->publish_uri = 1; 00292 //sn_nsdl_build_registration_body == SN_NSDL_FAILURE 00293 int8_t val = sn_nsdl_register_endpoint(handle, eptr); 00294 00295 free(sn_grs_stub.expectedInfo->resource); 00296 free(sn_grs_stub.expectedInfo->path); 00297 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); 00298 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); 00299 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00300 free(sn_grs_stub.expectedInfo); 00301 sn_grs_stub.expectedInfo = NULL; 00302 if( 0 != val ){ 00303 ret = false; 00304 goto end; 00305 } 00306 00307 //creates payload 00308 sn_grs_stub.info2ndRetCounter = 0; 00309 sn_grs_stub.infoRetCounter = 1; 00310 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00311 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00312 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00313 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00314 sn_grs_stub.expectedInfo->publish_uri = 1; 00315 eptr->binding_and_mode = 0x06; 00316 retCounter = 4; 00317 //set_endpoint_info == -1 00318 val = sn_nsdl_register_endpoint(handle, eptr); 00319 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00320 free(sn_grs_stub.expectedInfo); 00321 00322 if( 0 != val ){ 00323 ret = false; 00324 goto end; 00325 } 00326 00327 00328 handle->ep_information_ptr->domain_name_ptr = (uint8_t*)malloc(3); 00329 handle->ep_information_ptr->endpoint_name_ptr = (uint8_t*)malloc(3); 00330 eptr->binding_and_mode = 0x06; 00331 retCounter = 4; 00332 //set_endpoint_info == -1 00333 val = sn_nsdl_register_endpoint(handle, eptr); 00334 if( 0 != val ){ 00335 ret = false; 00336 goto end; 00337 } 00338 00339 //creates payload 00340 sn_grs_stub.info2ndRetCounter = 2; 00341 sn_grs_stub.infoRetCounter = 2; 00342 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00343 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00344 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00345 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; 00346 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); 00347 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; 00348 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; 00349 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00350 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; 00351 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; 00352 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; 00353 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00354 00355 sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); 00356 sn_grs_stub.expectedInfo->path[0] = 'a'; 00357 sn_grs_stub.expectedInfo->path[1] = '\0'; 00358 sn_grs_stub.expectedInfo->pathlen = 1; 00359 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); 00360 sn_grs_stub.expectedInfo->resource[0] = 'a'; 00361 sn_grs_stub.expectedInfo->resource[1] = '\0'; 00362 sn_grs_stub.expectedInfo->resourcelen = 1; 00363 sn_grs_stub.expectedInfo->publish_uri = 1; 00364 eptr->binding_and_mode = 0x06; 00365 retCounter = 7; 00366 00367 sn_coap_builder_stub.expectedUint16 = 1; 00368 sn_coap_protocol_stub.expectedInt16 = 1; 00369 //passes 00370 val = sn_nsdl_register_endpoint(handle, eptr); 00371 free(sn_grs_stub.expectedInfo->resource); 00372 free(sn_grs_stub.expectedInfo->path); 00373 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); 00374 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); 00375 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00376 free(sn_grs_stub.expectedInfo); 00377 00378 if( 0 != val ){ 00379 ret = false; 00380 goto end; 00381 } 00382 00383 //test resource_type_len overflow 00384 sn_grs_stub.info2ndRetCounter = 2; 00385 sn_grs_stub.infoRetCounter = 2; 00386 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00387 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00388 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00389 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = UINT16_MAX; 00390 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(UINT16_MAX); 00391 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; 00392 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; 00393 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00394 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; 00395 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; 00396 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; 00397 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00398 00399 sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); 00400 sn_grs_stub.expectedInfo->path[0] = 'a'; 00401 sn_grs_stub.expectedInfo->path[1] = '\0'; 00402 sn_grs_stub.expectedInfo->pathlen = 1; 00403 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); 00404 sn_grs_stub.expectedInfo->resource[0] = 'a'; 00405 sn_grs_stub.expectedInfo->resource[1] = '\0'; 00406 sn_grs_stub.expectedInfo->resourcelen = 1; 00407 sn_grs_stub.expectedInfo->publish_uri = 1; 00408 eptr->binding_and_mode = 0x06; 00409 retCounter = 7; 00410 00411 sn_coap_builder_stub.expectedUint16 = 1; 00412 sn_coap_protocol_stub.expectedInt16 = 1; 00413 //passes 00414 val = sn_nsdl_register_endpoint(handle, eptr); 00415 free(sn_grs_stub.expectedInfo->resource); 00416 free(sn_grs_stub.expectedInfo->path); 00417 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); 00418 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); 00419 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00420 free(sn_grs_stub.expectedInfo); 00421 00422 if( 0 != val ){ 00423 ret = false; 00424 goto end; 00425 } 00426 00427 //test interface len overflow 00428 sn_grs_stub.info2ndRetCounter = 2; 00429 sn_grs_stub.infoRetCounter = 2; 00430 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00431 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00432 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00433 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; 00434 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); 00435 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; 00436 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; 00437 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00438 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; 00439 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; 00440 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; 00441 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00442 00443 sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); 00444 sn_grs_stub.expectedInfo->path[0] = 'a'; 00445 sn_grs_stub.expectedInfo->path[1] = '\0'; 00446 sn_grs_stub.expectedInfo->pathlen = UINT16_MAX; 00447 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); 00448 sn_grs_stub.expectedInfo->resource[0] = 'a'; 00449 sn_grs_stub.expectedInfo->resource[1] = '\0'; 00450 sn_grs_stub.expectedInfo->resourcelen = 1; 00451 sn_grs_stub.expectedInfo->publish_uri = 1; 00452 eptr->binding_and_mode = 0x06; 00453 retCounter = 7; 00454 00455 sn_coap_builder_stub.expectedUint16 = 1; 00456 sn_coap_protocol_stub.expectedInt16 = 1; 00457 //passes 00458 val = sn_nsdl_register_endpoint(handle, eptr); 00459 free(sn_grs_stub.expectedInfo->resource); 00460 free(sn_grs_stub.expectedInfo->path); 00461 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); 00462 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); 00463 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00464 free(sn_grs_stub.expectedInfo); 00465 00466 if( 0 != val ){ 00467 ret = false; 00468 goto end; 00469 } 00470 00471 //test coap content overflow 00472 sn_grs_stub.info2ndRetCounter = 2; 00473 sn_grs_stub.infoRetCounter = 2; 00474 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00475 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00476 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00477 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; 00478 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); 00479 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; 00480 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; 00481 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00482 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; 00483 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; 00484 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = UINT16_MAX - 20; 00485 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00486 sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = UINT8_MAX; 00487 00488 sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); 00489 sn_grs_stub.expectedInfo->path[0] = 'a'; 00490 sn_grs_stub.expectedInfo->path[1] = '\0'; 00491 sn_grs_stub.expectedInfo->pathlen = 1; 00492 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); 00493 sn_grs_stub.expectedInfo->resource[0] = 'a'; 00494 sn_grs_stub.expectedInfo->resource[1] = '\0'; 00495 sn_grs_stub.expectedInfo->resourcelen = 1; 00496 sn_grs_stub.expectedInfo->publish_uri = 1; 00497 eptr->binding_and_mode = 0x06; 00498 retCounter = 7; 00499 00500 sn_coap_builder_stub.expectedUint16 = 1; 00501 sn_coap_protocol_stub.expectedInt16 = 1; 00502 //passes 00503 val = sn_nsdl_register_endpoint(handle, eptr); 00504 free(sn_grs_stub.expectedInfo->resource); 00505 free(sn_grs_stub.expectedInfo->path); 00506 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); 00507 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); 00508 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00509 free(sn_grs_stub.expectedInfo); 00510 00511 if( 0 != val ){ 00512 ret = false; 00513 goto end; 00514 } 00515 00516 //test observe len overflow 00517 sn_grs_stub.info2ndRetCounter = 2; 00518 sn_grs_stub.infoRetCounter = 2; 00519 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00520 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00521 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00522 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; 00523 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); 00524 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; 00525 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; 00526 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00527 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; 00528 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; 00529 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = UINT16_MAX - 25; 00530 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00531 sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 1; 00532 00533 sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); 00534 sn_grs_stub.expectedInfo->path[0] = 'a'; 00535 sn_grs_stub.expectedInfo->path[1] = '\0'; 00536 sn_grs_stub.expectedInfo->pathlen = 1; 00537 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); 00538 sn_grs_stub.expectedInfo->resource[0] = 'a'; 00539 sn_grs_stub.expectedInfo->resource[1] = '\0'; 00540 sn_grs_stub.expectedInfo->resourcelen = 1; 00541 sn_grs_stub.expectedInfo->publish_uri = 1; 00542 eptr->binding_and_mode = 0x06; 00543 retCounter = 7; 00544 00545 sn_coap_builder_stub.expectedUint16 = 1; 00546 sn_coap_protocol_stub.expectedInt16 = 1; 00547 //passes 00548 val = sn_nsdl_register_endpoint(handle, eptr); 00549 free(sn_grs_stub.expectedInfo->resource); 00550 free(sn_grs_stub.expectedInfo->path); 00551 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); 00552 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); 00553 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00554 free(sn_grs_stub.expectedInfo); 00555 00556 if( 0 != val ){ 00557 ret = false; 00558 goto end; 00559 } 00560 00561 //test observe len overflow 00562 sn_grs_stub.info2ndRetCounter = 2; 00563 sn_grs_stub.infoRetCounter = 2; 00564 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00565 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00566 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00567 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; 00568 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); 00569 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; 00570 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; 00571 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00572 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; 00573 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; 00574 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = UINT16_MAX - 28; 00575 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00576 sn_grs_stub.expectedInfo->resource_parameters_ptr->coap_content_type = 1; 00577 00578 sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); 00579 sn_grs_stub.expectedInfo->path[0] = 'a'; 00580 sn_grs_stub.expectedInfo->path[1] = '\0'; 00581 sn_grs_stub.expectedInfo->pathlen = 1; 00582 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); 00583 sn_grs_stub.expectedInfo->resource[0] = 'a'; 00584 sn_grs_stub.expectedInfo->resource[1] = '\0'; 00585 sn_grs_stub.expectedInfo->resourcelen = 1; 00586 sn_grs_stub.expectedInfo->publish_uri = 1; 00587 eptr->binding_and_mode = 0x06; 00588 retCounter = 7; 00589 00590 sn_coap_builder_stub.expectedUint16 = 1; 00591 sn_coap_protocol_stub.expectedInt16 = 1; 00592 //passes 00593 val = sn_nsdl_register_endpoint(handle, eptr); 00594 free(sn_grs_stub.expectedInfo->resource); 00595 free(sn_grs_stub.expectedInfo->path); 00596 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); 00597 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); 00598 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00599 free(sn_grs_stub.expectedInfo); 00600 00601 if( 0 != val ){ 00602 ret = false; 00603 goto end; 00604 } 00605 00606 sn_grs_stub.info2ndRetCounter = 2; 00607 sn_grs_stub.infoRetCounter = 2; 00608 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00609 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00610 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00611 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; 00612 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); 00613 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; 00614 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; 00615 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00616 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; 00617 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; 00618 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; 00619 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00620 sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); 00621 sn_grs_stub.expectedInfo->path[0] = 'a'; 00622 sn_grs_stub.expectedInfo->path[1] = '\0'; 00623 sn_grs_stub.expectedInfo->pathlen = 1; 00624 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); 00625 sn_grs_stub.expectedInfo->resource[0] = 'a'; 00626 sn_grs_stub.expectedInfo->resource[1] = '\0'; 00627 sn_grs_stub.expectedInfo->resourcelen = 1; 00628 sn_grs_stub.expectedInfo->publish_uri = 1; 00629 eptr->binding_and_mode = 0x06; 00630 retCounter = 4; 00631 sn_coap_builder_stub.expectedUint16 = 1; 00632 sn_coap_protocol_stub.expectedInt16 = 1; 00633 //set_endpoint_info == -1 00634 val = sn_nsdl_register_endpoint(handle, eptr); 00635 free(sn_grs_stub.expectedInfo->resource); 00636 free(sn_grs_stub.expectedInfo->path); 00637 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); 00638 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); 00639 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00640 free(sn_grs_stub.expectedInfo); 00641 00642 if( 0 != val ){ 00643 ret = false; 00644 goto end; 00645 } 00646 00647 end: 00648 free(sn_grs_stub.expectedGrs->coap); 00649 free(eptr->domain_name_ptr); 00650 free(eptr->lifetime_ptr); 00651 free(eptr->type_ptr); 00652 free(eptr->endpoint_name_ptr); 00653 00654 free(eptr); 00655 sn_nsdl_destroy(handle); 00656 return true; 00657 } 00658 00659 bool test_sn_nsdl_unregister_endpoint() 00660 { 00661 if( 0 != sn_nsdl_unregister_endpoint(NULL) ){ 00662 return false; 00663 } 00664 00665 sn_grs_stub.retNull = false; 00666 retCounter = 5; 00667 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 00668 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 00669 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 00670 sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); 00671 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; 00672 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; 00673 sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; 00674 sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; 00675 00676 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00677 return false; 00678 } 00679 00680 handle->sn_nsdl_endpoint_registered = 1; 00681 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00682 return false; 00683 } 00684 00685 retCounter = 0; 00686 handle->sn_nsdl_endpoint_registered = 1; 00687 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00688 return false; 00689 } 00690 00691 retCounter = 1; 00692 handle->sn_nsdl_endpoint_registered = 1; 00693 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00694 return false; 00695 } 00696 00697 retCounter = 2; 00698 handle->sn_nsdl_endpoint_registered = 1; 00699 sn_coap_builder_stub.expectedUint16 = 0; 00700 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00701 return false; 00702 } 00703 00704 //Following tests will test sn_nsdl_internal_coap_send() + stuff 00705 retCounter = 2; 00706 handle->sn_nsdl_endpoint_registered = 1; 00707 sn_coap_builder_stub.expectedUint16 = 1; 00708 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00709 return false; 00710 } 00711 00712 retCounter = 3; 00713 handle->sn_nsdl_endpoint_registered = 1; 00714 sn_coap_builder_stub.expectedUint16 = 1; 00715 sn_coap_protocol_stub.expectedInt16 = -1; 00716 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00717 return false; 00718 } 00719 00720 retCounter = 3; 00721 handle->sn_nsdl_endpoint_registered = 1; 00722 sn_coap_builder_stub.expectedUint16 = 1; 00723 sn_coap_protocol_stub.expectedInt16 = 1; 00724 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00725 return false; 00726 } 00727 00728 u_int8_t loc[] = {"location"}; 00729 00730 handle->ep_information_ptr->location_ptr = (uint8_t*)malloc(sizeof(loc)); 00731 handle->ep_information_ptr->location_len = (uint8_t)sizeof(loc); 00732 00733 retCounter = 1; 00734 handle->sn_nsdl_endpoint_registered = 1; 00735 sn_coap_builder_stub.expectedUint16 = 1; 00736 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00737 return false; 00738 } 00739 00740 retCounter = 2; 00741 handle->sn_nsdl_endpoint_registered = 1; 00742 sn_coap_builder_stub.expectedUint16 = 1; 00743 sn_coap_protocol_stub.expectedInt16 = -1; 00744 if( 0 != sn_nsdl_unregister_endpoint(handle) ){ 00745 return false; 00746 } 00747 free(sn_grs_stub.expectedGrs->coap); 00748 sn_nsdl_destroy(handle); 00749 return true; 00750 } 00751 00752 bool test_sn_nsdl_update_registration() 00753 { 00754 if( 0 != sn_nsdl_update_registration(NULL, NULL, 0) ){ 00755 return false; 00756 } 00757 00758 sn_grs_stub.retNull = false; 00759 retCounter = 4; 00760 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 00761 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 00762 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 00763 sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); 00764 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; 00765 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; 00766 sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; 00767 sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; 00768 00769 if( 0 != sn_nsdl_update_registration(handle, NULL, 0) ){ 00770 return false; 00771 } 00772 00773 handle->sn_nsdl_endpoint_registered = 1; 00774 if( 0 != sn_nsdl_update_registration(handle, NULL, 0) ){ 00775 return false; 00776 } 00777 00778 retCounter = 1; 00779 if( 0 != sn_nsdl_update_registration(handle, NULL, 0) ){ 00780 return false; 00781 } 00782 00783 retCounter = 2; 00784 if( 0 != sn_nsdl_update_registration(handle, NULL, 0) ){ 00785 return false; 00786 } 00787 00788 retCounter = 4; 00789 sn_grs_stub.infoRetCounter = 2; 00790 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00791 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00792 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00793 sn_grs_stub.expectedInfo->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERED; 00794 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_len = 1; 00795 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); 00796 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[0] = 'a'; 00797 sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr[1] = '\0'; 00798 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00799 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[0] = 'a'; 00800 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr[1] = '\0'; 00801 sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_len = 1; 00802 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00803 00804 sn_grs_stub.expectedInfo->path = (uint8_t*)malloc(2); 00805 sn_grs_stub.expectedInfo->path[0] = 'a'; 00806 sn_grs_stub.expectedInfo->path[1] = '\0'; 00807 sn_grs_stub.expectedInfo->pathlen = 1; 00808 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(2); 00809 sn_grs_stub.expectedInfo->resource[0] = 'a'; 00810 sn_grs_stub.expectedInfo->resource[1] = '\0'; 00811 sn_grs_stub.expectedInfo->resourcelen = 1; 00812 sn_grs_stub.expectedInfo->publish_uri = 1; 00813 00814 sn_coap_builder_stub.expectedUint16 = 1; 00815 int8_t val = sn_nsdl_update_registration(handle, NULL, 0); 00816 00817 free(sn_grs_stub.expectedInfo->resource); 00818 free(sn_grs_stub.expectedInfo->path); 00819 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->interface_description_ptr); 00820 free(sn_grs_stub.expectedInfo->resource_parameters_ptr->resource_type_ptr); 00821 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00822 free(sn_grs_stub.expectedInfo); 00823 sn_grs_stub.expectedInfo = NULL; 00824 00825 if( 0 != val ){ 00826 return false; 00827 } 00828 00829 sn_grs_stub.info2ndRetCounter = 1; 00830 sn_grs_stub.infoRetCounter = 1; 00831 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00832 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00833 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00834 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00835 sn_grs_stub.expectedInfo->publish_uri = 1; 00836 retCounter = 3; 00837 //set_endpoint_info == -1 00838 //sn_nsdl_build_registration_body == SN_NSDL_FAILURE 00839 val = sn_nsdl_update_registration(handle, NULL, 0); 00840 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00841 free(sn_grs_stub.expectedInfo); 00842 00843 if( 0 != val ){ 00844 return false; 00845 } 00846 00847 sn_grs_stub.info2ndRetCounter = 2; 00848 sn_grs_stub.infoRetCounter = 2; 00849 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00850 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00851 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00852 memset( sn_grs_stub.expectedInfo->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00853 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00854 sn_grs_stub.expectedInfo->publish_uri = 1; 00855 retCounter = 4; 00856 sn_grs_stub.expectedInfo->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; 00857 //set_endpoint_info == -1 00858 val = sn_nsdl_update_registration(handle, NULL, 0); 00859 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00860 free(sn_grs_stub.expectedInfo); 00861 00862 if( 0 != val ){ 00863 return false; 00864 } 00865 00866 u_int8_t loc[] = {"location"}; 00867 00868 handle->ep_information_ptr->location_ptr = (uint8_t*)malloc(sizeof(loc)); 00869 handle->ep_information_ptr->location_len = (uint8_t)sizeof(loc); 00870 00871 sn_grs_stub.info2ndRetCounter = 1; 00872 sn_grs_stub.infoRetCounter = 1; 00873 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00874 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00875 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00876 memset( sn_grs_stub.expectedInfo->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00877 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00878 sn_grs_stub.expectedInfo->publish_uri = 1; 00879 retCounter = 1; 00880 sn_grs_stub.expectedInfo->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; 00881 //set_endpoint_info == -1 00882 val = sn_nsdl_update_registration(handle, NULL, 0); 00883 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00884 free(sn_grs_stub.expectedInfo); 00885 00886 if( 0 != val ){ 00887 return false; 00888 } 00889 00890 sn_grs_stub.info2ndRetCounter = 2; 00891 sn_grs_stub.infoRetCounter = 2; 00892 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00893 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 00894 sn_grs_stub.expectedInfo->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00895 memset( sn_grs_stub.expectedInfo->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00896 sn_grs_stub.expectedInfo->resource_parameters_ptr->observable = 1; 00897 sn_grs_stub.expectedInfo->publish_uri = 1; 00898 retCounter = 2; 00899 sn_grs_stub.expectedInfo->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; 00900 //set_endpoint_info == -1 00901 val = sn_nsdl_update_registration(handle, NULL, 0); 00902 free(sn_grs_stub.expectedInfo->resource_parameters_ptr); 00903 free(sn_grs_stub.expectedInfo); 00904 00905 if( 0 != val ){ 00906 return false; 00907 } 00908 free(sn_grs_stub.expectedGrs->coap); 00909 sn_nsdl_destroy(handle); 00910 return true; 00911 } 00912 00913 bool test_sn_nsdl_set_endpoint_location() 00914 { 00915 00916 u_int8_t loc[] = {"location"}; 00917 00918 uint8_t* location_ptr = (uint8_t*)malloc(sizeof(loc)); 00919 uint8_t location_len = (uint8_t)sizeof(loc); 00920 00921 sn_grs_stub.retNull = false; 00922 retCounter = 4; 00923 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 00924 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 00925 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 00926 00927 00928 if(sn_nsdl_set_endpoint_location(NULL,location_ptr,location_len) != -1){ 00929 return false; 00930 } 00931 00932 if(sn_nsdl_set_endpoint_location(NULL,NULL,location_len) != -1){ 00933 return false; 00934 } 00935 00936 if(sn_nsdl_set_endpoint_location(handle,NULL,location_len) != -1){ 00937 return false; 00938 } 00939 00940 if(sn_nsdl_set_endpoint_location(handle,location_ptr,0) != -1){ 00941 return false; 00942 } 00943 00944 if(sn_nsdl_set_endpoint_location(NULL,location_ptr,0) != -1){ 00945 return false; 00946 } 00947 00948 retCounter = 1; 00949 00950 if(sn_nsdl_set_endpoint_location(handle,location_ptr,location_len) != 0){ 00951 return false; 00952 } 00953 00954 sn_nsdl_destroy(handle); 00955 free(location_ptr); 00956 00957 return true; 00958 } 00959 00960 bool test_sn_nsdl_nsp_lost() 00961 { 00962 sn_nsdl_nsp_lost(NULL); 00963 00964 sn_grs_stub.retNull = false; 00965 retCounter = 4; 00966 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 00967 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 00968 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 00969 00970 bool ret = true; 00971 sn_nsdl_nsp_lost(handle); 00972 if( SN_NSDL_ENDPOINT_NOT_REGISTERED != handle->sn_nsdl_endpoint_registered ){ 00973 ret = false; 00974 } 00975 sn_nsdl_destroy(handle); 00976 return ret; 00977 } 00978 00979 bool test_sn_nsdl_is_ep_registered() 00980 { 00981 if( SN_NSDL_FAILURE != sn_nsdl_is_ep_registered(NULL)){ 00982 return false; 00983 } 00984 sn_grs_stub.retNull = false; 00985 retCounter = 4; 00986 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 00987 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 00988 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 00989 handle->sn_nsdl_endpoint_registered = 1; 00990 00991 bool ret = sn_nsdl_is_ep_registered(handle) == 1; 00992 00993 sn_nsdl_destroy(handle); 00994 return ret; 00995 } 00996 00997 bool test_sn_nsdl_send_observation_notification() 00998 { 00999 if( 0 != sn_nsdl_send_observation_notification(NULL, NULL, 0,NULL,0,0,0,0) ){ 01000 return false; 01001 } 01002 sn_grs_stub.retNull = false; 01003 sn_grs_stub.expectedInt8 = SN_NSDL_SUCCESS; 01004 retCounter = 5; 01005 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 01006 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 01007 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 01008 sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); 01009 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; 01010 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; 01011 sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; 01012 sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; 01013 01014 if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,0) ){ 01015 return false; 01016 } 01017 01018 retCounter = 0; 01019 if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,0) ){ 01020 return false; 01021 } 01022 01023 retCounter = 1; 01024 if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,0) ){ 01025 return false; 01026 } 01027 01028 retCounter = 2; 01029 if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,1) ){ 01030 return false; 01031 } 01032 01033 retCounter = 2; 01034 if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,1) ){ 01035 return false; 01036 } 01037 01038 retCounter = 2; 01039 sn_grs_stub.int8SuccessCounter = 0; 01040 sn_grs_stub.expectedInt8 = SN_NSDL_FAILURE; 01041 if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,0,0,1) ){ 01042 return false; 01043 } 01044 free(sn_grs_stub.expectedGrs->coap); 01045 sn_nsdl_destroy(handle); 01046 return true; 01047 } 01048 01049 bool test_sn_nsdl_send_observation_notification_with_uri_path() 01050 { 01051 if( 0 != sn_nsdl_send_observation_notification_with_uri_path(NULL, NULL, 0,NULL,0,0,0,0, NULL,0) ){ 01052 return false; 01053 } 01054 sn_grs_stub.retNull = false; 01055 retCounter = 5; 01056 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 01057 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 01058 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 01059 sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); 01060 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; 01061 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; 01062 sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; 01063 sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; 01064 01065 u_int8_t path[] = {"13/0/1"}; 01066 uint8_t* uri_path_ptr = (uint8_t*)malloc(sizeof(path)); 01067 uint8_t uri_path_len = (uint8_t)sizeof(path); 01068 if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,0,uri_path_ptr,uri_path_len) ){ 01069 return false; 01070 } 01071 01072 retCounter = 0; 01073 if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,0,uri_path_ptr,uri_path_len) ){ 01074 return false; 01075 } 01076 01077 retCounter = 1; 01078 if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,0,uri_path_ptr,uri_path_len) ){ 01079 return false; 01080 } 01081 01082 retCounter = 2; 01083 if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,1,uri_path_ptr,uri_path_len) ){ 01084 return false; 01085 } 01086 01087 retCounter = 2; 01088 if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,1,uri_path_ptr,uri_path_len) ){ 01089 return false; 01090 } 01091 01092 retCounter = 2; 01093 if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,1,uri_path_ptr,uri_path_len) ){ 01094 return false; 01095 } 01096 01097 retCounter = 2; 01098 sn_grs_stub.int8SuccessCounter = 0; 01099 sn_grs_stub.expectedInt8 = SN_NSDL_FAILURE; 01100 if( 0 != sn_nsdl_send_observation_notification_with_uri_path(handle, NULL, 0,NULL,0,0,0,1,NULL,0) ){ 01101 return false; 01102 } 01103 free(sn_grs_stub.expectedGrs->coap); 01104 free(uri_path_ptr); 01105 sn_nsdl_destroy(handle); 01106 return true; 01107 } 01108 01109 bool test_sn_nsdl_oma_bootstrap() 01110 { 01111 if( 0 != sn_nsdl_oma_bootstrap(NULL, NULL, NULL, NULL)){ 01112 return false; 01113 } 01114 sn_grs_stub.retNull = false; 01115 retCounter = 5; 01116 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 01117 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 01118 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 01119 sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); 01120 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; 01121 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; 01122 sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; 01123 sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; 01124 01125 sn_nsdl_addr_s *addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); 01126 memset(addr, 0, sizeof(sn_nsdl_addr_s)); 01127 sn_nsdl_ep_parameters_s *param = (sn_nsdl_ep_parameters_s*)malloc(sizeof(sn_nsdl_ep_parameters_s)); 01128 memset(param, 0, sizeof(sn_nsdl_ep_parameters_s)); 01129 sn_nsdl_bs_ep_info_t *info = (sn_nsdl_bs_ep_info_t*)malloc(sizeof(sn_nsdl_bs_ep_info_t)); 01130 memset(info, 0, sizeof(sn_nsdl_bs_ep_info_t)); 01131 01132 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01133 return false; 01134 } 01135 01136 info->device_object = (sn_nsdl_oma_device_t*)malloc(sizeof(sn_nsdl_oma_device_t)); 01137 memset(info->device_object, 0, sizeof(sn_nsdl_oma_device_t)); 01138 01139 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01140 return false; 01141 } 01142 01143 retCounter = 0; 01144 sn_grs_stub.expectedInt8 = -1; 01145 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01146 return false; 01147 } 01148 01149 retCounter = 1; 01150 sn_grs_stub.expectedInt8 = -1; 01151 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01152 return false; 01153 } 01154 01155 retCounter = 1; 01156 sn_grs_stub.expectedInt8 = -1; 01157 sn_grs_stub.int8SuccessCounter = 1; 01158 param->binding_and_mode = 0; 01159 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01160 return false; 01161 } 01162 01163 retCounter = 1; 01164 sn_grs_stub.int8SuccessCounter = 2; 01165 param->binding_and_mode = 3; 01166 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01167 return false; 01168 } 01169 01170 retCounter = 1; 01171 sn_grs_stub.int8SuccessCounter = 3; 01172 param->binding_and_mode = 6; 01173 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01174 return false; 01175 } 01176 01177 retCounter = 2; 01178 sn_grs_stub.int8SuccessCounter = 3; 01179 param->binding_and_mode = 6; 01180 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01181 return false; 01182 } 01183 01184 retCounter = 3; 01185 sn_grs_stub.int8SuccessCounter = 3; 01186 param->binding_and_mode = 6; 01187 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01188 return false; 01189 } 01190 01191 retCounter = 6; 01192 sn_grs_stub.expectedInt8 = 0; 01193 sn_grs_stub.int8SuccessCounter = 3; 01194 param->binding_and_mode = 6; 01195 sn_coap_builder_stub.expectedUint16 = 1; 01196 if( 0 != sn_nsdl_oma_bootstrap(handle, addr, param, info)){ 01197 return false; 01198 } 01199 01200 free(info->device_object); 01201 free(info); 01202 free(param); 01203 free(addr); 01204 free(sn_grs_stub.expectedGrs->coap); 01205 retCounter = 1; 01206 sn_nsdl_destroy(handle); 01207 return true; 01208 } 01209 01210 bool test_sn_nsdl_get_certificates() 01211 { 01212 if( 0 != sn_nsdl_get_certificates(NULL)){ 01213 return false; 01214 } 01215 sn_grs_stub.retNull = false; 01216 retCounter = 4; 01217 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 01218 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 01219 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 01220 01221 if( 0 != sn_nsdl_get_certificates(handle)){ 01222 return false; 01223 } 01224 01225 retCounter = 1; 01226 sn_grs_stub.retNull = true; 01227 if( 0 != sn_nsdl_get_certificates(handle)){ 01228 return false; 01229 } 01230 01231 retCounter = 1; 01232 sn_grs_stub.retNull = false; 01233 sn_grs_stub.infoRetCounter = 1; 01234 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01235 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 01236 if( 0 != sn_nsdl_get_certificates(handle)){ 01237 return false; 01238 } 01239 01240 retCounter = 1; 01241 sn_grs_stub.retNull = false; 01242 sn_grs_stub.infoRetCounter = 2; 01243 if( 0 != sn_nsdl_get_certificates(handle)){ 01244 return false; 01245 } 01246 01247 retCounter = 1; 01248 sn_grs_stub.retNull = false; 01249 sn_grs_stub.infoRetCounter = 3; 01250 omalw_certificate_list_t* list = sn_nsdl_get_certificates(handle); 01251 if( 0 == list ){ 01252 return false; 01253 } 01254 free(list); 01255 free(sn_grs_stub.expectedInfo); 01256 01257 sn_nsdl_destroy(handle); 01258 return true; 01259 } 01260 01261 bool test_sn_nsdl_update_certificates() 01262 { 01263 if( -1 != sn_nsdl_update_certificates(NULL, NULL, 0) ){ 01264 return false; 01265 } 01266 sn_grs_stub.retNull = false; 01267 retCounter = 4; 01268 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 01269 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 01270 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 01271 01272 omalw_certificate_list_t* list = (omalw_certificate_list_t*)malloc(sizeof(omalw_certificate_list_t)); 01273 memset( list, 0, sizeof(omalw_certificate_list_t)); 01274 01275 sn_grs_stub.retNull = true; 01276 if( -1 != sn_nsdl_update_certificates(handle, list, 0) ){ 01277 return false; 01278 } 01279 01280 sn_grs_stub.retNull = false; 01281 sn_grs_stub.infoRetCounter = 1; 01282 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01283 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 01284 if( -1 != sn_nsdl_update_certificates(handle, list, 0) ){ 01285 return false; 01286 } 01287 01288 sn_grs_stub.retNull = false; 01289 sn_grs_stub.infoRetCounter = 2; 01290 if( -1 != sn_nsdl_update_certificates(handle, list, 0) ){ 01291 return false; 01292 } 01293 01294 sn_grs_stub.retNull = false; 01295 sn_grs_stub.infoRetCounter = 3; 01296 if( 0 != sn_nsdl_update_certificates(handle, list, 0) ){ 01297 return false; 01298 } 01299 01300 free(sn_grs_stub.expectedInfo); 01301 free(list); 01302 sn_nsdl_destroy(handle); 01303 return true; 01304 } 01305 01306 bool test_sn_nsdl_create_oma_device_object() 01307 { 01308 if( -1 != sn_nsdl_create_oma_device_object(NULL, NULL) ){ 01309 return false; 01310 } 01311 sn_grs_stub.retNull = false; 01312 retCounter = 4; 01313 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 01314 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 01315 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 01316 01317 sn_nsdl_oma_device_t *device = (sn_nsdl_oma_device_t*)malloc(sizeof(sn_nsdl_oma_device_t)); 01318 memset( device, 0, sizeof(sn_nsdl_oma_device_t)); 01319 01320 sn_grs_stub.retNull = true; 01321 if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ 01322 return false; 01323 } 01324 01325 sn_grs_stub.retNull = false; 01326 sn_grs_stub.infoRetCounter = 1; 01327 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01328 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 01329 01330 sn_grs_stub.useMockedPath = true; 01331 sn_grs_stub.mockedPath[0] = '9'; 01332 sn_grs_stub.mockedPath[1] = '9'; 01333 sn_grs_stub.mockedPath[2] = '9'; 01334 sn_grs_stub.mockedPath[3] = '9'; 01335 sn_grs_stub.mockedPath[4] = '9'; 01336 sn_grs_stub.mockedPath[5] = '9'; 01337 sn_grs_stub.mockedPath[6] = '9'; 01338 sn_grs_stub.mockedPath[7] = '9'; 01339 sn_grs_stub.mockedPathLen = 8; 01340 01341 if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ 01342 return false; 01343 } 01344 01345 sn_grs_stub.infoRetCounter = 1; 01346 sn_grs_stub.useMockedPath = true; 01347 sn_grs_stub.mockedPath[0] = '1'; 01348 sn_grs_stub.mockedPath[1] = '1'; 01349 sn_grs_stub.mockedPath[2] = '1'; 01350 sn_grs_stub.mockedPath[3] = '1'; 01351 sn_grs_stub.mockedPath[4] = '1'; 01352 sn_grs_stub.mockedPath[5] = '1'; 01353 sn_grs_stub.mockedPath[6] = '1'; 01354 sn_grs_stub.mockedPath[7] = '1'; 01355 sn_grs_stub.mockedPathLen = 8; 01356 01357 if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ 01358 return false; 01359 } 01360 01361 sn_grs_stub.useMockedPath = false; 01362 sn_grs_stub.infoRetCounter = 1; 01363 01364 sn_grs_stub.expectedInfo->resource = (uint8_t*)malloc(4); 01365 *sn_grs_stub.expectedInfo->resource = 0; 01366 01367 if( SN_NSDL_SUCCESS != sn_nsdl_create_oma_device_object(handle, device) ){ 01368 return false; 01369 } 01370 01371 sn_grs_stub.infoRetCounter = 1; 01372 *sn_grs_stub.expectedInfo->resource = 1; 01373 if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ 01374 return false; 01375 } 01376 01377 free( sn_grs_stub.expectedInfo->resource ); 01378 01379 retCounter = 1; 01380 if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ 01381 return false; 01382 } 01383 01384 retCounter = 2; 01385 if( -1 != sn_nsdl_create_oma_device_object(handle, device) ){ 01386 return false; 01387 } 01388 01389 retCounter = 3; 01390 if( SN_NSDL_SUCCESS != sn_nsdl_create_oma_device_object(handle, device) ){ 01391 return false; 01392 } 01393 01394 free(sn_grs_stub.expectedInfo); 01395 free(device); 01396 sn_nsdl_destroy(handle); 01397 return true; 01398 } 01399 01400 bool test_sn_nsdl_get_version() 01401 { 01402 char* ret = sn_nsdl_get_version(); 01403 if( strcmp(ret, "0.0.0") != 0 ){ 01404 return false; 01405 } 01406 01407 return true; 01408 } 01409 01410 bool test_sn_nsdl_process_coap() 01411 { 01412 if( -1 != sn_nsdl_process_coap(NULL, NULL, 0, NULL) ){ 01413 return false; 01414 } 01415 sn_grs_stub.retNull = false; 01416 retCounter = 4; 01417 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 01418 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 01419 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 01420 01421 sn_coap_protocol_stub.expectedHeader = NULL; 01422 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ 01423 return false; 01424 } 01425 01426 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01427 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01428 sn_grs_stub.expectedGrs->coap = (struct coap_s *)malloc(sizeof(struct coap_s)); 01429 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_free = myFree; 01430 sn_grs_stub.expectedGrs->coap->sn_coap_protocol_malloc = myMalloc; 01431 sn_grs_stub.expectedGrs->coap->sn_coap_rx_callback = nsdl_rx_callback; 01432 sn_grs_stub.expectedGrs->coap->sn_coap_tx_callback = nsdl_tx_callback; 01433 sn_grs_stub.expectedGrs->coap->sn_coap_block_data_size = 1; 01434 01435 sn_coap_protocol_stub.expectedHeader->coap_status = 2; // != 0 && != 6 01436 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ 01437 return false; 01438 } 01439 01440 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01441 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01442 sn_coap_protocol_stub.expectedHeader->coap_status = 0; 01443 sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 01444 memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); 01445 sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_len = 2; 01446 sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(2); 01447 memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_ptr, 0, 2); 01448 01449 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ 01450 return false; 01451 } 01452 01453 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01454 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01455 sn_coap_protocol_stub.expectedHeader->coap_status = 0; 01456 sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 01457 memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); 01458 sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_len = 2; 01459 sn_coap_protocol_stub.expectedHeader->options_list_ptr->proxy_uri_ptr = (uint8_t*)malloc(2); 01460 01461 sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01462 memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01463 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ 01464 return false; 01465 } 01466 sn_coap_builder_stub.expectedHeader = NULL; 01467 01468 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01469 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01470 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01471 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; 01472 sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); 01473 01474 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ 01475 return false; 01476 } 01477 01478 sn_nsdl_addr_s *addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); 01479 memset(addr, 0, sizeof(sn_nsdl_addr_s)); 01480 01481 //Test sn_nsdl_local_rx_function fully here 01482 sn_coap_builder_stub.expectedHeader = NULL; 01483 01484 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01485 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01486 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01487 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; 01488 sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); 01489 sn_coap_protocol_stub.expectedHeader->msg_id = 5; 01490 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; 01491 handle->register_msg_id = 5; 01492 handle->unregister_msg_id = 5; 01493 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01494 return false; 01495 } 01496 01497 sn_coap_builder_stub.expectedHeader = NULL; 01498 01499 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01500 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01501 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01502 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; 01503 sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); 01504 sn_coap_protocol_stub.expectedHeader->msg_id = 5; 01505 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; 01506 sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 01507 memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); 01508 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(2); 01509 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 2; 01510 handle->register_msg_id = 5; 01511 01512 if( 0 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01513 return false; 01514 } 01515 01516 sn_coap_builder_stub.expectedHeader = NULL; 01517 01518 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01519 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01520 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01521 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; 01522 sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); 01523 sn_coap_protocol_stub.expectedHeader->msg_id = 5; 01524 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; 01525 sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 01526 memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); 01527 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); 01528 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; 01529 01530 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[0] = '/'; 01531 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[1] = '/'; 01532 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[2] = '/'; 01533 handle->register_msg_id = 5; 01534 01535 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01536 return false; 01537 } 01538 01539 sn_coap_builder_stub.expectedHeader = NULL; 01540 01541 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01542 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01543 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01544 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; 01545 sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); 01546 sn_coap_protocol_stub.expectedHeader->msg_id = 5; 01547 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; 01548 sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 01549 memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); 01550 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); 01551 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; 01552 01553 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[0] = '/'; 01554 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[1] = '/'; 01555 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[2] = '/'; 01556 handle->register_msg_id = 5; 01557 01558 retCounter = 1; 01559 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01560 return false; 01561 } 01562 01563 sn_coap_builder_stub.expectedHeader = NULL; 01564 01565 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01566 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01567 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01568 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; 01569 sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); 01570 sn_coap_protocol_stub.expectedHeader->msg_id = 5; 01571 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CREATED; 01572 sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 01573 memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); 01574 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); 01575 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; 01576 01577 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[0] = '/'; 01578 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[1] = '/'; 01579 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[2] = '/'; 01580 01581 handle->register_msg_id = 5; 01582 retCounter = 2; 01583 if( 0 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01584 return false; 01585 } 01586 free(handle->ep_information_ptr->endpoint_name_ptr); 01587 handle->ep_information_ptr->endpoint_name_ptr = NULL; 01588 free(handle->ep_information_ptr->domain_name_ptr); 01589 handle->ep_information_ptr->domain_name_ptr = NULL; 01590 01591 sn_coap_builder_stub.expectedHeader = NULL; 01592 01593 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01594 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01595 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01596 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; 01597 sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); 01598 sn_coap_protocol_stub.expectedHeader->msg_id = 5; 01599 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; 01600 sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 01601 memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); 01602 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); 01603 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; 01604 01605 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[0] = '/'; 01606 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[1] = '/'; 01607 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr[2] = '/'; 01608 01609 handle->register_msg_id = 0; 01610 handle->unregister_msg_id = 0; 01611 handle->update_register_msg_id = 5; 01612 01613 retCounter = 2; 01614 if( 0 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01615 return false; 01616 } 01617 free(handle->ep_information_ptr->endpoint_name_ptr); 01618 handle->ep_information_ptr->endpoint_name_ptr = NULL; 01619 free(handle->ep_information_ptr->domain_name_ptr); 01620 handle->ep_information_ptr->domain_name_ptr = NULL; 01621 01622 sn_coap_builder_stub.expectedHeader = NULL; 01623 01624 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01625 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01626 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01627 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_REQUEST_DELETE + 1; 01628 sn_coap_protocol_stub.expectedHeader->payload_ptr = (uint8_t*)malloc(2); 01629 sn_coap_protocol_stub.expectedHeader->msg_id = 5; 01630 sn_coap_protocol_stub.expectedHeader->msg_code = COAP_MSG_CODE_RESPONSE_DELETED; 01631 sn_coap_protocol_stub.expectedHeader->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); 01632 memset(sn_coap_protocol_stub.expectedHeader->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); 01633 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_ptr = (uint8_t*)malloc(3); 01634 sn_coap_protocol_stub.expectedHeader->options_list_ptr->location_path_len = 3; 01635 handle->register_msg_id = 5; 01636 handle->unregister_msg_id = 5; 01637 01638 handle->ep_information_ptr->endpoint_name_ptr = (uint8_t*)malloc(2); 01639 handle->ep_information_ptr->domain_name_ptr = (uint8_t*)malloc(2); 01640 01641 if( 0 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01642 return false; 01643 } 01644 01645 // <-- Test sn_nsdl_local_rx_function fully here 01646 01647 sn_coap_builder_stub.expectedHeader = NULL; 01648 01649 01650 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01651 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01652 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01653 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01654 sn_grs_stub.expectedInt8 = -1; 01655 01656 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, NULL) ){ 01657 return false; 01658 } 01659 // sn_coap_protocol_stub.expectedHeader is not deleted 01660 01661 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01662 return false; 01663 } 01664 01665 01666 sn_grs_stub.expectedInt8 = 0; 01667 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01668 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01669 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01670 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01671 sn_coap_protocol_stub.expectedHeader->content_format = 9; 01672 01673 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01674 return false; 01675 } 01676 01677 uint8_t * payload_ptr = (uint8_t*)malloc(40); 01678 memset(payload_ptr, 0, 40); 01679 01680 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01681 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01682 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01683 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01684 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01685 01686 payload_ptr[0] = 0x20; 01687 payload_ptr[1] = 0x00; 01688 payload_ptr[2] = 0x01; 01689 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01690 sn_coap_protocol_stub.expectedHeader->payload_len = 3; 01691 01692 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01693 return false; 01694 } 01695 01696 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01697 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01698 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01699 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01700 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01701 01702 payload_ptr[0] = 0x18; 01703 payload_ptr[1] = 0x00; 01704 payload_ptr[2] = 0x00; 01705 payload_ptr[3] = 0x01; 01706 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01707 sn_coap_protocol_stub.expectedHeader->payload_len = 4; 01708 01709 if( -1 != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01710 return false; 01711 } 01712 01713 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01714 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01715 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01716 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01717 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01718 01719 payload_ptr[0] = 0x08; 01720 payload_ptr[1] = 0x01; 01721 sn_coap_protocol_stub.expectedHeader->payload_len = 2; 01722 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01723 01724 sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01725 memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01726 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01727 return false; 01728 } 01729 sn_coap_builder_stub.expectedHeader = NULL; 01730 01731 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01732 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01733 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01734 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01735 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01736 01737 payload_ptr[0] = 0x10; 01738 payload_ptr[1] = 0x00; 01739 payload_ptr[2] = 0x01; 01740 sn_coap_protocol_stub.expectedHeader->payload_len = 3; 01741 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01742 01743 sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01744 memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01745 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01746 return false; 01747 } 01748 sn_coap_builder_stub.expectedHeader = NULL; 01749 01750 //Test sn_nsdl_process_oma_tlv switches with failing 01751 01752 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01753 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01754 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01755 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01756 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01757 01758 payload_ptr[0] = 0xC0; 01759 payload_ptr[1] = 0x00; 01760 payload_ptr[2] = 0xC0; 01761 payload_ptr[3] = 0x00; 01762 sn_coap_protocol_stub.expectedHeader->payload_len = 4; 01763 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01764 sn_grs_stub.int8SuccessCounter = 1; 01765 sn_grs_stub.expectedInt8 = -1; 01766 01767 sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01768 memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01769 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01770 return false; 01771 } 01772 sn_coap_builder_stub.expectedHeader = NULL; 01773 01774 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01775 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01776 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01777 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01778 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01779 01780 payload_ptr[0] = 0xC0; 01781 payload_ptr[1] = 0x02; 01782 payload_ptr[2] = 0xC0; 01783 payload_ptr[3] = 0x02; 01784 sn_coap_protocol_stub.expectedHeader->payload_len = 4; 01785 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01786 sn_grs_stub.int8SuccessCounter = 1; 01787 sn_grs_stub.expectedInt8 = -1; 01788 01789 sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01790 memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01791 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01792 return false; 01793 } 01794 sn_coap_builder_stub.expectedHeader = NULL; 01795 01796 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01797 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01798 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01799 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01800 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01801 01802 payload_ptr[0] = 0xC0; 01803 payload_ptr[1] = 0x03; 01804 payload_ptr[2] = 0xC0; 01805 payload_ptr[3] = 0x03; 01806 sn_coap_protocol_stub.expectedHeader->payload_len = 4; 01807 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01808 sn_grs_stub.int8SuccessCounter = 1; 01809 sn_grs_stub.expectedInt8 = -1; 01810 01811 sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01812 memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01813 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01814 return false; 01815 } 01816 sn_coap_builder_stub.expectedHeader = NULL; 01817 01818 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01819 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01820 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01821 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01822 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01823 01824 payload_ptr[0] = 0xC0; 01825 payload_ptr[1] = 0x04; 01826 payload_ptr[2] = 0xC0; 01827 payload_ptr[3] = 0x04; 01828 sn_coap_protocol_stub.expectedHeader->payload_len = 4; 01829 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01830 sn_grs_stub.int8SuccessCounter = 1; 01831 sn_grs_stub.expectedInt8 = -1; 01832 01833 sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01834 memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01835 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01836 return false; 01837 } 01838 sn_coap_builder_stub.expectedHeader = NULL; 01839 01840 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01841 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01842 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01843 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01844 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01845 01846 payload_ptr[0] = 0xC0; 01847 payload_ptr[1] = 0x05; 01848 payload_ptr[2] = 0xC0; 01849 payload_ptr[3] = 0x05; 01850 sn_coap_protocol_stub.expectedHeader->payload_len = 4; 01851 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01852 sn_grs_stub.int8SuccessCounter = 1; 01853 sn_grs_stub.expectedInt8 = -1; 01854 01855 if( SN_NSDL_FAILURE != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01856 return false; 01857 } 01858 01859 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01860 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01861 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01862 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01863 sn_coap_protocol_stub.expectedHeader->content_format = 99; 01864 01865 payload_ptr[0] = 0xC0; 01866 payload_ptr[1] = 0x01; 01867 sn_coap_protocol_stub.expectedHeader->payload_len = 2; 01868 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01869 sn_grs_stub.int8SuccessCounter = 1; 01870 sn_grs_stub.expectedInt8 = -1; 01871 01872 if( SN_NSDL_FAILURE != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01873 return false; 01874 } 01875 01876 // Content type 97 tests 01877 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01878 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01879 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01880 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01881 sn_coap_protocol_stub.expectedHeader->content_format = 97; 01882 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 01883 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '2'; 01884 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 01885 01886 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01887 return false; 01888 } 01889 01890 // --> 01891 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01892 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01893 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01894 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01895 sn_coap_protocol_stub.expectedHeader->content_format = 97; 01896 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 01897 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '2'; 01898 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 01899 sn_grs_stub.infoRetCounter = 3; 01900 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01901 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 01902 01903 handle->nsp_address_ptr->omalw_address_ptr->type = 1; 01904 01905 payload_ptr[0] = '2'; 01906 payload_ptr[1] = '\0'; 01907 sn_coap_protocol_stub.expectedHeader->payload_len = 1; 01908 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01909 01910 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 01911 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 01912 01913 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01914 return false; 01915 } 01916 01917 free(sn_grs_stub.expectedInfo); 01918 sn_grs_stub.expectedInfo = NULL; 01919 01920 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01921 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01922 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01923 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01924 sn_coap_protocol_stub.expectedHeader->content_format = 97; 01925 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 01926 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '2'; 01927 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 01928 sn_grs_stub.infoRetCounter = 3; 01929 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01930 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 01931 handle->nsp_address_ptr->omalw_server_security = CERTIFICATE; 01932 handle->nsp_address_ptr->omalw_address_ptr->type = 1; 01933 01934 payload_ptr[0] = 'a'; 01935 payload_ptr[1] = 'F'; 01936 sn_coap_protocol_stub.expectedHeader->payload_len = 2; 01937 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01938 01939 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 01940 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 01941 01942 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01943 return false; 01944 } 01945 01946 free(sn_grs_stub.expectedInfo); 01947 sn_grs_stub.expectedInfo = NULL; 01948 01949 handle->nsp_address_ptr->omalw_server_security = 0; 01950 // <-- 01951 01952 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01953 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01954 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01955 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01956 sn_coap_protocol_stub.expectedHeader->content_format = 97; 01957 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 01958 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 01959 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 01960 01961 payload_ptr[0] = 0xC0; 01962 payload_ptr[1] = 0x01; 01963 sn_coap_protocol_stub.expectedHeader->payload_len = 1; 01964 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01965 01966 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01967 return false; 01968 } 01969 01970 //TODO: test rest of sn_nsdl_resolve_lwm2m_address here 01971 01972 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01973 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01974 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01975 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01976 sn_coap_protocol_stub.expectedHeader->content_format = 97; 01977 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 01978 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 01979 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 01980 01981 payload_ptr[0] = 0xC0; 01982 payload_ptr[1] = 0x01; 01983 sn_coap_protocol_stub.expectedHeader->payload_len = 2; 01984 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 01985 01986 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 01987 return false; 01988 } 01989 01990 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01991 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 01992 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 01993 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 01994 sn_coap_protocol_stub.expectedHeader->content_format = 97; 01995 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 01996 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 01997 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 01998 01999 payload_ptr[0] = 0xC0; 02000 payload_ptr[1] = 0x01; 02001 sn_coap_protocol_stub.expectedHeader->payload_len = 2; 02002 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02003 02004 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02005 return false; 02006 } 02007 02008 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02009 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02010 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02011 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02012 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02013 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02014 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02015 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02016 02017 payload_ptr[0] = '/'; 02018 payload_ptr[1] = '/'; 02019 sn_coap_protocol_stub.expectedHeader->payload_len = 2; 02020 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02021 02022 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02023 return false; 02024 } 02025 02026 // --> Test IPv6 parsing here 02027 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02028 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02029 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02030 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02031 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02032 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02033 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02034 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02035 02036 payload_ptr[0] = '/'; 02037 payload_ptr[1] = '/'; 02038 payload_ptr[2] = ':'; 02039 payload_ptr[3] = ':'; 02040 payload_ptr[4] = 'A'; 02041 payload_ptr[5] = ':'; 02042 payload_ptr[6] = 'd'; 02043 payload_ptr[7] = ':'; 02044 payload_ptr[8] = '7'; 02045 sn_coap_protocol_stub.expectedHeader->payload_len = 9; 02046 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02047 02048 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02049 return false; 02050 } 02051 02052 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02053 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02054 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02055 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02056 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02057 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02058 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02059 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02060 02061 payload_ptr[0] = '/'; 02062 payload_ptr[1] = '/'; 02063 payload_ptr[2] = '['; 02064 payload_ptr[3] = ':'; 02065 payload_ptr[4] = 'A'; 02066 payload_ptr[5] = ':'; 02067 payload_ptr[6] = 'd'; 02068 payload_ptr[7] = '7'; 02069 payload_ptr[8] = ':'; 02070 payload_ptr[9] = ':'; 02071 payload_ptr[10] = ']'; 02072 sn_coap_protocol_stub.expectedHeader->payload_len = 11; 02073 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02074 02075 retCounter = 0; 02076 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02077 return false; 02078 } 02079 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02080 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02081 02082 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02083 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02084 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02085 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02086 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02087 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02088 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02089 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02090 02091 payload_ptr[0] = '/'; 02092 payload_ptr[1] = '/'; 02093 payload_ptr[2] = '['; 02094 payload_ptr[3] = '1'; 02095 payload_ptr[4] = ':'; 02096 payload_ptr[5] = 'A'; 02097 payload_ptr[6] = '7'; 02098 payload_ptr[7] = ':'; 02099 payload_ptr[8] = 'd'; 02100 payload_ptr[9] = '7'; 02101 payload_ptr[10] = '7'; 02102 payload_ptr[11] = ':'; 02103 payload_ptr[12] = 'd'; 02104 payload_ptr[13] = 'E'; 02105 payload_ptr[14] = '7'; 02106 payload_ptr[15] = '7'; 02107 payload_ptr[16] = ':'; 02108 payload_ptr[17] = ':'; 02109 payload_ptr[18] = ']'; 02110 payload_ptr[19] = ':'; 02111 payload_ptr[20] = '3'; 02112 sn_coap_protocol_stub.expectedHeader->payload_len = 21; 02113 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02114 02115 retCounter = 1; 02116 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02117 return false; 02118 } 02119 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02120 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02121 02122 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02123 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02124 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02125 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02126 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02127 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02128 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02129 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02130 02131 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(3); 02132 02133 payload_ptr[0] = '/'; 02134 payload_ptr[1] = '/'; 02135 payload_ptr[2] = '['; 02136 payload_ptr[3] = ':'; 02137 payload_ptr[4] = ':'; 02138 payload_ptr[5] = 'A'; 02139 payload_ptr[6] = '7'; 02140 payload_ptr[7] = ':'; 02141 payload_ptr[8] = 'd'; 02142 payload_ptr[9] = '7'; 02143 payload_ptr[10] = '7'; 02144 payload_ptr[11] = ':'; 02145 payload_ptr[12] = 'd'; 02146 payload_ptr[13] = 'E'; 02147 payload_ptr[14] = '7'; 02148 payload_ptr[15] = '7'; 02149 payload_ptr[16] = ':'; 02150 payload_ptr[17] = '1'; 02151 payload_ptr[18] = ']'; 02152 payload_ptr[19] = ':'; 02153 payload_ptr[20] = '3'; 02154 payload_ptr[21] = '/'; 02155 sn_coap_protocol_stub.expectedHeader->payload_len = 22; 02156 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02157 02158 retCounter = 1; 02159 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02160 return false; 02161 } 02162 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02163 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02164 02165 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02166 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02167 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02168 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02169 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02170 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02171 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02172 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02173 02174 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(3); 02175 02176 payload_ptr[0] = '/'; 02177 payload_ptr[1] = '/'; 02178 payload_ptr[2] = '['; 02179 payload_ptr[3] = '2'; 02180 payload_ptr[4] = ':'; 02181 payload_ptr[5] = 'A'; 02182 payload_ptr[6] = '7'; 02183 payload_ptr[7] = ':'; 02184 payload_ptr[8] = ':'; 02185 payload_ptr[9] = '7'; 02186 payload_ptr[10] = '7'; 02187 payload_ptr[11] = ':'; 02188 payload_ptr[12] = 'd'; 02189 payload_ptr[13] = 'E'; 02190 payload_ptr[14] = '7'; 02191 payload_ptr[15] = '7'; 02192 payload_ptr[16] = ':'; 02193 payload_ptr[17] = '1'; 02194 payload_ptr[18] = ']'; 02195 payload_ptr[19] = ':'; 02196 payload_ptr[20] = '3'; 02197 payload_ptr[21] = '/'; 02198 sn_coap_protocol_stub.expectedHeader->payload_len = 22; 02199 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02200 02201 retCounter = 1; 02202 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02203 return false; 02204 } 02205 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02206 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02207 02208 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02209 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02210 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02211 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02212 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02213 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02214 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02215 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02216 02217 payload_ptr[0] = '/'; 02218 payload_ptr[1] = '/'; 02219 payload_ptr[2] = '['; 02220 payload_ptr[3] = ':'; 02221 payload_ptr[4] = ':'; 02222 payload_ptr[5] = ']'; 02223 payload_ptr[6] = ':'; 02224 payload_ptr[7] = '5'; 02225 payload_ptr[8] = '/'; 02226 sn_coap_protocol_stub.expectedHeader->payload_len = 9; 02227 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02228 02229 retCounter = 1; 02230 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02231 return false; 02232 } 02233 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02234 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02235 // <-- 02236 02237 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02238 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02239 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02240 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02241 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02242 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02243 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02244 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02245 02246 payload_ptr[0] = '/'; 02247 payload_ptr[1] = '/'; 02248 payload_ptr[2] = ':'; 02249 sn_coap_protocol_stub.expectedHeader->payload_len = 3; 02250 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02251 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 02252 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 02253 02254 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(3); 02255 02256 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02257 return false; 02258 } 02259 02260 //Test IPv4 here --> 02261 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02262 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02263 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02264 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02265 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02266 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02267 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02268 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02269 02270 payload_ptr[0] = '/'; 02271 payload_ptr[1] = '/'; 02272 payload_ptr[2] = '1'; 02273 payload_ptr[3] = '.'; 02274 payload_ptr[4] = '2'; 02275 payload_ptr[5] = '.'; 02276 payload_ptr[6] = '3'; 02277 payload_ptr[7] = '.'; 02278 payload_ptr[8] = '4'; 02279 payload_ptr[9] = ':'; 02280 payload_ptr[10] = '6'; 02281 sn_coap_protocol_stub.expectedHeader->payload_len = 11; 02282 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02283 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 02284 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 02285 02286 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02287 return false; 02288 } 02289 02290 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02291 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02292 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02293 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02294 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02295 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02296 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02297 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02298 02299 payload_ptr[0] = '/'; 02300 payload_ptr[1] = '/'; 02301 payload_ptr[2] = '1'; 02302 payload_ptr[3] = '.'; 02303 payload_ptr[4] = '2'; 02304 payload_ptr[5] = '.'; 02305 payload_ptr[6] = '3'; 02306 payload_ptr[7] = '.'; 02307 payload_ptr[8] = '4'; 02308 payload_ptr[9] = ':'; 02309 payload_ptr[10] = '6'; 02310 payload_ptr[11] = '6'; 02311 sn_coap_protocol_stub.expectedHeader->payload_len = 12; 02312 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02313 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 02314 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 02315 02316 02317 retCounter = 1; 02318 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02319 return false; 02320 } 02321 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02322 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02323 02324 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02325 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02326 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02327 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02328 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02329 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02330 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02331 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02332 02333 payload_ptr[0] = '/'; 02334 payload_ptr[1] = '/'; 02335 payload_ptr[2] = '1'; 02336 payload_ptr[3] = '.'; 02337 payload_ptr[4] = '2'; 02338 payload_ptr[5] = '.'; 02339 payload_ptr[6] = '3'; 02340 payload_ptr[7] = '.'; 02341 payload_ptr[8] = '4'; 02342 payload_ptr[9] = ':'; 02343 payload_ptr[10] = '6'; 02344 payload_ptr[11] = '6'; 02345 payload_ptr[12] = '/'; 02346 sn_coap_protocol_stub.expectedHeader->payload_len = 13; 02347 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02348 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 02349 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 02350 02351 retCounter = 1; 02352 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02353 return false; 02354 } 02355 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02356 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02357 02358 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02359 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02360 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02361 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02362 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02363 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02364 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02365 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02366 02367 payload_ptr[0] = '/'; 02368 payload_ptr[1] = '/'; 02369 payload_ptr[2] = 's'; 02370 payload_ptr[3] = '.'; 02371 payload_ptr[4] = 't'; 02372 payload_ptr[5] = '.'; 02373 payload_ptr[6] = 'u'; 02374 payload_ptr[7] = '.'; 02375 payload_ptr[8] = 'v'; 02376 payload_ptr[9] = ':'; 02377 payload_ptr[10] = '6'; 02378 sn_coap_protocol_stub.expectedHeader->payload_len = 11; 02379 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02380 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 02381 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 02382 02383 retCounter = 1; 02384 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02385 return false; 02386 } 02387 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02388 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02389 02390 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02391 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02392 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02393 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02394 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02395 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02396 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02397 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02398 02399 payload_ptr[0] = '/'; 02400 payload_ptr[1] = '/'; 02401 payload_ptr[2] = 's'; 02402 payload_ptr[3] = '.'; 02403 payload_ptr[4] = 't'; 02404 payload_ptr[5] = '.'; 02405 payload_ptr[6] = 'u'; 02406 payload_ptr[7] = '.'; 02407 payload_ptr[8] = 'v'; 02408 payload_ptr[9] = ':'; 02409 payload_ptr[10] = '6'; 02410 sn_coap_protocol_stub.expectedHeader->payload_len = 11; 02411 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02412 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 02413 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 02414 handle->handle_bootstrap_msg = false; 02415 02416 retCounter = 1; 02417 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02418 return false; 02419 } 02420 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02421 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02422 handle->handle_bootstrap_msg = true; 02423 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02424 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02425 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02426 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02427 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02428 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02429 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02430 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02431 02432 payload_ptr[0] = '/'; 02433 payload_ptr[1] = '/'; 02434 payload_ptr[2] = 's'; 02435 payload_ptr[3] = '.'; 02436 payload_ptr[4] = 't'; 02437 payload_ptr[5] = '.'; 02438 payload_ptr[6] = 'u'; 02439 payload_ptr[7] = '.'; 02440 payload_ptr[8] = 'v'; 02441 payload_ptr[9] = '.'; 02442 payload_ptr[10] = 'w'; 02443 payload_ptr[11] = ':'; 02444 payload_ptr[12] = '6'; 02445 payload_ptr[13] = '/'; 02446 sn_coap_protocol_stub.expectedHeader->payload_len = 14; 02447 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02448 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 02449 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 02450 02451 retCounter = 1; 02452 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02453 return false; 02454 } 02455 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02456 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02457 02458 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02459 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02460 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02461 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02462 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02463 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02464 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02465 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02466 02467 payload_ptr[0] = '/'; 02468 payload_ptr[1] = '/'; 02469 payload_ptr[2] = 's'; 02470 payload_ptr[3] = '.'; 02471 payload_ptr[4] = 't'; 02472 payload_ptr[5] = '.'; 02473 payload_ptr[6] = 'u'; 02474 payload_ptr[7] = '.'; 02475 payload_ptr[8] = 'v'; 02476 payload_ptr[9] = '.'; 02477 payload_ptr[10] = 'w'; 02478 payload_ptr[11] = ':'; 02479 payload_ptr[12] = '6'; 02480 sn_coap_protocol_stub.expectedHeader->payload_len = 13; 02481 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02482 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 02483 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 02484 02485 retCounter = 1; 02486 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02487 return false; 02488 } 02489 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02490 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02491 02492 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02493 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02494 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02495 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02496 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02497 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02498 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02499 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02500 02501 free( payload_ptr ); 02502 payload_ptr = malloc(276); 02503 memset(payload_ptr, 1, 276); 02504 payload_ptr[0] = '/'; 02505 payload_ptr[1] = '/'; 02506 payload_ptr[2] = 's'; 02507 payload_ptr[3] = '.'; 02508 payload_ptr[4] = 't'; 02509 payload_ptr[5] = '.'; 02510 payload_ptr[6] = 'u'; 02511 payload_ptr[7] = '.'; 02512 payload_ptr[8] = 'v'; 02513 payload_ptr[9] = '.'; 02514 payload_ptr[10] = 'w'; 02515 payload_ptr[11] = ':'; 02516 payload_ptr[12] = '6'; 02517 sn_coap_protocol_stub.expectedHeader->payload_len = 276; 02518 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02519 handle->sn_nsdl_oma_bs_done_cb = myBootstrapCallback; 02520 handle->sn_nsdl_oma_bs_done_cb_handle = myBootstrapCallbackHandle; 02521 02522 retCounter = 1; 02523 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02524 return false; 02525 } 02526 free( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr ); //Investigate why would leak if removed? 02527 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02528 // <-- 02529 02530 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02531 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02532 sn_coap_protocol_stub.expectedHeader->coap_status = 6; 02533 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02534 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02535 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02536 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02537 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02538 02539 payload_ptr[0] = '/'; 02540 payload_ptr[1] = '/'; 02541 payload_ptr[2] = ':'; 02542 payload_ptr[3] = ':'; 02543 sn_coap_protocol_stub.expectedHeader->payload_len = 4; 02544 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02545 02546 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02547 return false; 02548 } 02549 02550 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02551 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02552 sn_coap_protocol_stub.expectedHeader->coap_status = 3; 02553 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02554 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02555 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02556 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02557 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02558 02559 payload_ptr[0] = '/'; 02560 payload_ptr[1] = '/'; 02561 payload_ptr[2] = ':'; 02562 payload_ptr[3] = ':'; 02563 sn_coap_protocol_stub.expectedHeader->payload_len = 4; 02564 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02565 02566 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02567 return false; 02568 } 02569 02570 sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02571 memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); 02572 sn_coap_protocol_stub.expectedHeader->coap_status = 3; 02573 sn_coap_protocol_stub.expectedHeader->msg_code = 0; 02574 sn_coap_protocol_stub.expectedHeader->content_format = 97; 02575 sn_coap_protocol_stub.expectedHeader->uri_path_ptr = (uint8_t*)malloc(1); 02576 sn_coap_protocol_stub.expectedHeader->uri_path_ptr[0] = '0'; 02577 sn_coap_protocol_stub.expectedHeader->uri_path_len = 1; 02578 02579 payload_ptr[0] = '/'; 02580 payload_ptr[1] = '/'; 02581 payload_ptr[2] = ':'; 02582 payload_ptr[3] = ':'; 02583 sn_coap_protocol_stub.expectedHeader->payload_len = 4; 02584 sn_coap_protocol_stub.expectedHeader->payload_ptr = payload_ptr; 02585 02586 sn_grs_stub.expectedInfo = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 02587 memset( sn_grs_stub.expectedInfo, 0, sizeof(sn_nsdl_resource_info_s)); 02588 sn_grs_stub.expectedInfo->external_memory_block = 1; 02589 if( SN_NSDL_SUCCESS != sn_nsdl_process_coap(handle, NULL, 0, addr) ){ 02590 return false; 02591 } 02592 free(sn_grs_stub.expectedInfo); 02593 sn_grs_stub.expectedInfo = NULL; 02594 free(sn_grs_stub.expectedGrs->coap); 02595 free(payload_ptr); 02596 free(addr); 02597 sn_nsdl_destroy(handle); 02598 return true; 02599 } 02600 02601 bool test_sn_nsdl_exec() 02602 { 02603 if( -1 != sn_nsdl_exec(NULL, NULL) ){ 02604 return false; 02605 } 02606 02607 retCounter = 4; 02608 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02609 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02610 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02611 sn_coap_protocol_stub.expectedInt8 = 0; 02612 02613 if( 0 != sn_nsdl_exec(handle,0) ){ 02614 return false; 02615 } 02616 02617 sn_nsdl_destroy(handle); 02618 return true; 02619 } 02620 02621 bool test_sn_nsdl_get_resource() 02622 { 02623 if( NULL != sn_nsdl_get_resource(NULL, 0, NULL) ){ 02624 return false; 02625 } 02626 sn_grs_stub.retNull = false; 02627 retCounter = 4; 02628 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02629 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02630 02631 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02632 02633 sn_nsdl_get_resource(handle, 0, NULL); 02634 02635 sn_nsdl_destroy(handle); 02636 return true; 02637 } 02638 02639 bool test_set_NSP_address() 02640 { 02641 if( SN_NSDL_FAILURE != set_NSP_address(NULL, NULL, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){ 02642 return false; 02643 } 02644 sn_grs_stub.retNull = false; 02645 retCounter = 4; 02646 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02647 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02648 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02649 02650 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(2); 02651 memset( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, 0, 2 ); 02652 02653 uint8_t* addr = (uint8_t*)malloc(2); 02654 memset(addr, 0, 2); 02655 02656 if( SN_NSDL_FAILURE != set_NSP_address(handle, addr, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){ 02657 return false; 02658 } 02659 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02660 02661 retCounter = 1; 02662 if( SN_NSDL_SUCCESS != set_NSP_address(handle, addr, 0, SN_NSDL_ADDRESS_TYPE_IPV4) ){ 02663 return false; 02664 } 02665 free(handle->nsp_address_ptr->omalw_address_ptr->addr_ptr); 02666 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02667 02668 if( SN_NSDL_FAILURE != set_NSP_address(handle, addr, 0, SN_NSDL_ADDRESS_TYPE_IPV6) ){ 02669 return false; 02670 } 02671 02672 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = NULL; 02673 handle->nsp_address_ptr->omalw_address_ptr->addr_ptr = (uint8_t*)malloc(2); 02674 memset( handle->nsp_address_ptr->omalw_address_ptr->addr_ptr, 0, 2 ); 02675 02676 retCounter = 1; 02677 if( SN_NSDL_SUCCESS != set_NSP_address(handle, addr, 0, SN_NSDL_ADDRESS_TYPE_IPV6) ){ 02678 return false; 02679 } 02680 02681 free(addr); 02682 sn_nsdl_destroy(handle); 02683 return true; 02684 } 02685 02686 bool test_sn_nsdl_list_resource() 02687 { 02688 if( NULL != sn_nsdl_list_resource(NULL, 0, NULL) ){ 02689 return false; 02690 } 02691 sn_grs_stub.retNull = false; 02692 retCounter = 4; 02693 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02694 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02695 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02696 02697 if( NULL != sn_nsdl_list_resource(handle, 0, NULL) ){ 02698 return false; 02699 } 02700 02701 sn_nsdl_destroy(handle); 02702 return true; 02703 } 02704 02705 bool test_sn_nsdl_free_resource_list() 02706 { 02707 sn_nsdl_free_resource_list(NULL, NULL); 02708 02709 sn_grs_stub.retNull = false; 02710 retCounter = 4; 02711 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02712 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02713 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02714 02715 sn_grs_resource_list_s* list = (sn_grs_resource_list_s*)malloc(sizeof(sn_grs_resource_list_s)); 02716 sn_nsdl_free_resource_list(handle, list); //mem leak or pass 02717 02718 sn_nsdl_destroy(handle); 02719 return true; 02720 } 02721 02722 bool test_sn_nsdl_update_resource() 02723 { 02724 if( SN_NSDL_FAILURE != sn_nsdl_update_resource(NULL, NULL) ){ 02725 return false; 02726 } 02727 sn_grs_stub.retNull = false; 02728 retCounter = 4; 02729 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02730 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02731 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02732 02733 if( 0 != sn_nsdl_update_resource(handle, NULL) ){ 02734 return false; 02735 } 02736 02737 sn_nsdl_destroy(handle); 02738 return true; 02739 } 02740 02741 bool test_sn_nsdl_send_coap_message() 02742 { 02743 if( SN_NSDL_FAILURE != sn_nsdl_send_coap_message(NULL, NULL, NULL) ){ 02744 return false; 02745 } 02746 sn_grs_stub.retNull = false; 02747 retCounter = 4; 02748 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02749 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02750 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02751 02752 if( 0 != sn_nsdl_send_coap_message(handle, NULL, NULL) ){ 02753 return false; 02754 } 02755 02756 sn_nsdl_destroy(handle); 02757 return true; 02758 } 02759 02760 bool test_sn_nsdl_create_resource() 02761 { 02762 if( SN_NSDL_FAILURE != sn_nsdl_create_resource(NULL, NULL) ){ 02763 return false; 02764 } 02765 sn_grs_stub.retNull = false; 02766 retCounter = 4; 02767 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02768 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02769 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02770 02771 if( 0 != sn_nsdl_create_resource(handle, NULL) ){ 02772 return false; 02773 } 02774 02775 sn_nsdl_destroy(handle); 02776 return true; 02777 } 02778 02779 bool test_sn_nsdl_put_resource() 02780 { 02781 if( SN_NSDL_FAILURE != sn_nsdl_put_resource(NULL, NULL) ){ 02782 return false; 02783 } 02784 sn_grs_stub.retNull = false; 02785 retCounter = 4; 02786 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02787 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02788 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02789 02790 if( 0 != sn_nsdl_put_resource(handle, NULL) ){ 02791 return false; 02792 } 02793 02794 sn_nsdl_destroy(handle); 02795 return true; 02796 } 02797 02798 bool test_sn_nsdl_delete_resource() 02799 { 02800 if( SN_NSDL_FAILURE != sn_nsdl_delete_resource(NULL, 0, NULL) ){ 02801 return false; 02802 } 02803 sn_grs_stub.retNull = false; 02804 retCounter = 4; 02805 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02806 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02807 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02808 02809 if( 0 != sn_nsdl_delete_resource(handle, 0, NULL) ){ 02810 return false; 02811 } 02812 02813 sn_nsdl_destroy(handle); 02814 return true; 02815 } 02816 02817 bool test_sn_nsdl_get_first_resource() 02818 { 02819 if( NULL != sn_nsdl_get_first_resource(NULL) ){ 02820 return false; 02821 } 02822 sn_grs_stub.retNull = false; 02823 retCounter = 4; 02824 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02825 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02826 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02827 02828 if( NULL != sn_nsdl_get_first_resource(handle) ){ 02829 return false; 02830 } 02831 02832 sn_nsdl_destroy(handle); 02833 return true; 02834 } 02835 02836 bool test_sn_nsdl_get_next_resource() 02837 { 02838 if( NULL != sn_nsdl_get_next_resource(NULL, NULL) ){ 02839 return false; 02840 } 02841 sn_grs_stub.retNull = false; 02842 retCounter = 4; 02843 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02844 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02845 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02846 02847 if( NULL != sn_nsdl_get_next_resource(handle, NULL) ){ 02848 return false; 02849 } 02850 02851 sn_nsdl_destroy(handle); 02852 return true; 02853 } 02854 02855 bool test_sn_nsdl_build_response() 02856 { 02857 if( NULL != sn_nsdl_build_response(NULL, NULL, 0) ){ 02858 return false; 02859 } 02860 sn_grs_stub.retNull = false; 02861 retCounter = 4; 02862 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02863 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02864 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02865 02866 if( NULL != sn_nsdl_build_response(handle, NULL, 0) ){ 02867 return false; 02868 } 02869 02870 sn_nsdl_destroy(handle); 02871 return true; 02872 } 02873 02874 bool test_sn_nsdl_release_allocated_coap_msg_mem() 02875 { 02876 sn_nsdl_release_allocated_coap_msg_mem(NULL, NULL); 02877 sn_grs_stub.retNull = false; 02878 retCounter = 4; 02879 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02880 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02881 struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02882 02883 sn_coap_hdr_s* list = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 02884 02885 sn_nsdl_release_allocated_coap_msg_mem(handle, list); //mem leak or pass 02886 02887 sn_nsdl_destroy(handle); 02888 return true; 02889 } 02890 02891 bool test_sn_nsdl_set_retransmission_parameters() 02892 { 02893 struct nsdl_s* handle = NULL; 02894 if (sn_nsdl_set_retransmission_parameters(handle, 10, 10) == 0){ 02895 return false; 02896 } 02897 retCounter = 4; 02898 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02899 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02900 handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02901 sn_coap_protocol_stub.expectedInt8 = 0; 02902 02903 if (sn_nsdl_set_retransmission_parameters(handle, 10, 10) != 0){ 02904 return false; 02905 } 02906 sn_nsdl_destroy(handle); 02907 return true; 02908 } 02909 02910 bool test_sn_nsdl_set_retransmission_buffer() 02911 { 02912 struct nsdl_s* handle = NULL; 02913 if (sn_nsdl_set_retransmission_buffer(handle,3,3 ) == 0){ 02914 return false; 02915 } 02916 retCounter = 4; 02917 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02918 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02919 handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02920 sn_coap_protocol_stub.expectedInt8 = 0; 02921 02922 if (sn_nsdl_set_retransmission_buffer(handle,3,3 ) != 0){ 02923 return false; 02924 } 02925 sn_nsdl_destroy(handle); 02926 return true; 02927 } 02928 02929 bool test_sn_nsdl_set_block_size() 02930 { 02931 struct nsdl_s* handle = NULL; 02932 if (sn_nsdl_set_block_size(handle,16) == 0){ 02933 return false; 02934 } 02935 retCounter = 4; 02936 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02937 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02938 handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02939 sn_coap_protocol_stub.expectedInt8 = 0; 02940 02941 if (sn_nsdl_set_block_size(handle,16) != 0){ 02942 return false; 02943 } 02944 sn_nsdl_destroy(handle); 02945 return true; 02946 } 02947 02948 bool test_sn_nsdl_set_duplicate_buffer_size() 02949 { 02950 struct nsdl_s* handle = NULL; 02951 if (sn_nsdl_set_duplicate_buffer_size(handle,999) == 0){ 02952 return false; 02953 } 02954 retCounter = 4; 02955 sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s)); 02956 memset(sn_grs_stub.expectedGrs,0, sizeof(struct grs_s)); 02957 handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree); 02958 sn_coap_protocol_stub.expectedInt8 = 0; 02959 02960 if (sn_nsdl_set_duplicate_buffer_size(handle,999) != 0){ 02961 return false; 02962 } 02963 sn_nsdl_destroy(handle); 02964 return true; 02965 }
Generated on Tue Jul 12 2022 14:21:23 by
1.7.2