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