Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: blinky_max32630fthr
test_sn_grs.c
00001 /* 00002 * Copyright (c) 2015 ARM. All rights reserved. 00003 */ 00004 #include "test_sn_grs.h" 00005 #include <string.h> 00006 #include <inttypes.h> 00007 #include "sn_coap_header.h" 00008 #include "sn_nsdl.h" 00009 #include "sn_nsdl_lib.h" 00010 #include "sn_grs.h" 00011 #include "ns_list.h" 00012 00013 #include "sn_nsdl_stub.h" 00014 #include "sn_coap_protocol_stub.h" 00015 #include "sn_coap_builder_stub.h" 00016 00017 int retCounter = 0; 00018 uint8_t retValUint8 = 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 uint8_t myTxCallback(struct nsdl_s *a, sn_nsdl_capab_e b, uint8_t *c, uint16_t d, 00035 sn_nsdl_addr_s *e) 00036 { 00037 return retValUint8; 00038 } 00039 00040 int8_t myRxCallback(struct nsdl_s *a, sn_coap_hdr_s *b, sn_nsdl_addr_s *c) 00041 { 00042 return 0; 00043 } 00044 00045 uint8_t myResCallback(struct nsdl_s *a, sn_coap_hdr_s *b, sn_nsdl_addr_s *c, sn_nsdl_capab_e d) 00046 { 00047 00048 } 00049 00050 00051 bool test_sn_grs_destroy() 00052 { 00053 if( SN_NSDL_SUCCESS != sn_grs_destroy(NULL)){ 00054 return false; 00055 } 00056 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 00057 memset(handle, 0, sizeof(struct grs_s)); 00058 handle->sn_grs_alloc = myMalloc; 00059 handle->sn_grs_free = myFree; 00060 00061 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00062 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00063 ns_list_add_to_start(&handle->resource_root_list, res); 00064 ++handle->resource_root_count; 00065 00066 if( SN_NSDL_SUCCESS != sn_grs_destroy(handle)){ 00067 return false; 00068 } 00069 00070 return true; 00071 } 00072 00073 bool test_sn_grs_init() 00074 { 00075 if( NULL != sn_grs_init(NULL, NULL, NULL, NULL) ){ 00076 return false; 00077 } 00078 00079 if( NULL != sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree) ){ 00080 return false; 00081 } 00082 00083 retCounter = 1; 00084 sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); 00085 memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); 00086 00087 struct grs_s* handle = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 00088 if( handle == NULL ){ 00089 return false; 00090 } 00091 00092 struct nsdl_s* h = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 00093 memset(h, 0, sizeof(struct nsdl_s)); 00094 h->grs = handle; 00095 00096 if( 0 != sn_coap_protocol_stub.expectedCoap->sn_coap_rx_callback(NULL, NULL, NULL) ){ 00097 return false; 00098 } 00099 00100 h->sn_nsdl_rx_callback = &myRxCallback; 00101 if( 0 != sn_coap_protocol_stub.expectedCoap->sn_coap_rx_callback(NULL, NULL, h) ){ 00102 return false; 00103 } 00104 00105 if( 0 != sn_coap_protocol_stub.expectedCoap->sn_coap_tx_callback(NULL, 0, NULL, NULL)){ 00106 return false; 00107 } 00108 00109 retValUint8 = 0; 00110 if( 0 != sn_coap_protocol_stub.expectedCoap->sn_coap_tx_callback(NULL, 0, NULL, h)){ 00111 return false; 00112 } 00113 00114 free(sn_coap_protocol_stub.expectedCoap); 00115 sn_coap_protocol_stub.expectedCoap = NULL; 00116 00117 sn_grs_destroy(handle); 00118 h->grs = NULL; 00119 free(h); 00120 00121 return true; 00122 } 00123 00124 bool test_sn_grs_list_resource() 00125 { 00126 if( NULL != sn_grs_list_resource(NULL, 0, NULL) ){ 00127 return false; 00128 } 00129 00130 retCounter = 1; 00131 struct grs_s* handle = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 00132 00133 uint8_t* path = (uint8_t*)malloc(5); 00134 if( NULL != sn_grs_list_resource(handle, 5, path) ){ 00135 return false; 00136 } 00137 00138 handle->resource_root_count = 1; 00139 retCounter = 1; 00140 if( NULL != sn_grs_list_resource(handle, 5, path) ){ 00141 return false; 00142 } 00143 00144 handle->resource_root_count = 0; 00145 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00146 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00147 res->path = (uint8_t*)malloc(5); 00148 res->pathlen = 5; 00149 ns_list_add_to_start(&handle->resource_root_list, res); 00150 ++handle->resource_root_count; 00151 sn_nsdl_resource_info_s* res2 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00152 memset(res2, 0, sizeof(sn_nsdl_resource_info_s)); 00153 res2->path = (uint8_t*)malloc(4); 00154 res2->pathlen = 4; 00155 ns_list_add_to_start(&handle->resource_root_list, res2); 00156 ++handle->resource_root_count; 00157 retCounter = 2; 00158 if( NULL != sn_grs_list_resource(handle, 5, path) ){ 00159 return false; 00160 } 00161 00162 retCounter = 4; 00163 sn_grs_resource_list_s *list_ptr = sn_grs_list_resource(handle, 5, path); 00164 if( NULL == list_ptr ){ 00165 return false; 00166 } 00167 00168 sn_grs_free_resource_list(handle, list_ptr); 00169 00170 free(path); 00171 sn_grs_destroy(handle); 00172 return true; 00173 } 00174 00175 bool test_sn_grs_free_resource_list() 00176 { 00177 sn_grs_free_resource_list(NULL, NULL); 00178 00179 retCounter = 1; 00180 struct grs_s* handle = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 00181 00182 sn_grs_resource_list_s *grs_resource_list_ptr = (sn_grs_resource_list_s*)malloc(sizeof(sn_grs_resource_list_s)); 00183 memset(grs_resource_list_ptr, 0, sizeof(sn_grs_resource_list_s)); 00184 grs_resource_list_ptr->res_count = 1; 00185 grs_resource_list_ptr->res = (sn_grs_resource_s*)malloc(sizeof(sn_grs_resource_s)); 00186 grs_resource_list_ptr->res[0].path = (uint8_t*)malloc(2); 00187 grs_resource_list_ptr->res[0].pathlen = 2; 00188 00189 sn_grs_free_resource_list(handle, grs_resource_list_ptr); 00190 00191 sn_grs_destroy(handle); 00192 return true; 00193 } 00194 00195 bool test_sn_grs_get_first_resource() 00196 { 00197 if( NULL != sn_grs_get_first_resource(NULL) ){ 00198 return false; 00199 } 00200 00201 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 00202 memset(handle, 0, sizeof(struct grs_s)); 00203 handle->sn_grs_alloc = myMalloc; 00204 handle->sn_grs_free = myFree; 00205 00206 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00207 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00208 ns_list_add_to_start(&handle->resource_root_list, res); 00209 ++handle->resource_root_count; 00210 00211 if( NULL == sn_grs_get_first_resource(handle) ){ 00212 return false; 00213 } 00214 00215 sn_grs_destroy(handle); 00216 return true; 00217 } 00218 00219 bool test_sn_grs_get_next_resource() 00220 { 00221 if( NULL != sn_grs_get_next_resource(NULL, NULL) ){ 00222 return false; 00223 } 00224 00225 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 00226 memset(handle, 0, sizeof(struct grs_s)); 00227 handle->sn_grs_alloc = myMalloc; 00228 handle->sn_grs_free = myFree; 00229 00230 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00231 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00232 ns_list_add_to_start(&handle->resource_root_list, res); 00233 ++handle->resource_root_count; 00234 sn_nsdl_resource_info_s* res2 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00235 memset(res2, 0, sizeof(sn_nsdl_resource_info_s)); 00236 ns_list_add_to_start(&handle->resource_root_list, res2); 00237 ++handle->resource_root_count; 00238 00239 if( NULL != sn_grs_get_next_resource(handle, NULL) ){ 00240 return false; 00241 } 00242 00243 if( NULL == sn_grs_get_next_resource(handle, res2) ){ 00244 return false; 00245 } 00246 00247 sn_grs_destroy(handle); 00248 return true; 00249 } 00250 00251 bool test_sn_grs_delete_resource() 00252 { 00253 if( SN_NSDL_FAILURE != sn_grs_delete_resource(NULL, 0, NULL) ){ 00254 return false; 00255 } 00256 00257 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 00258 memset(handle, 0, sizeof(struct grs_s)); 00259 handle->sn_grs_alloc = myMalloc; 00260 handle->sn_grs_free = myFree; 00261 00262 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00263 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00264 res->path = (uint8_t*)malloc(2); 00265 res->pathlen = 1; 00266 res->path[0] = 'a'; 00267 res->path[1] = '\0'; 00268 ns_list_add_to_start(&handle->resource_root_list, res); 00269 ++handle->resource_root_count; 00270 00271 sn_nsdl_resource_info_s* res2 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00272 memset(res2, 0, sizeof(sn_nsdl_resource_info_s)); 00273 res2->path = (uint8_t*)malloc(4); 00274 res2->pathlen = 3; 00275 res2->path[0] = 'a'; 00276 res2->path[1] = '/'; 00277 res2->path[2] = '1'; 00278 res2->path[3] = '\0'; 00279 ns_list_add_to_start(&handle->resource_root_list, res2); 00280 ++handle->resource_root_count; 00281 00282 uint8_t path[2] = {'a', '\0'}; 00283 if( SN_NSDL_SUCCESS != sn_grs_delete_resource(handle, 1, &path) ){ 00284 return false; 00285 } 00286 00287 if (handle->resource_root_count != 0) { 00288 return false; 00289 } 00290 00291 sn_nsdl_resource_info_s* res3 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00292 memset(res3, 0, sizeof(sn_nsdl_resource_info_s)); 00293 res3->path = (uint8_t*)malloc(2); 00294 res3->pathlen = 1; 00295 res3->path[0] = 'a'; 00296 res3->path[1] = '\0'; 00297 ns_list_add_to_start(&handle->resource_root_list, res3); 00298 ++handle->resource_root_count; 00299 00300 /* a/1 */ 00301 sn_nsdl_resource_info_s* res4 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00302 memset(res4, 0, sizeof(sn_nsdl_resource_info_s)); 00303 res4->path = (uint8_t*)malloc(4); 00304 res4->pathlen = 3; 00305 res4->path[0] = 'a'; 00306 res4->path[1] = '/'; 00307 res4->path[2] = '1'; 00308 res4->path[3] = '\0'; 00309 ns_list_add_to_start(&handle->resource_root_list, res4); 00310 ++handle->resource_root_count; 00311 00312 /* a/1/0 */ 00313 sn_nsdl_resource_info_s* res5 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00314 memset(res5, 0, sizeof(sn_nsdl_resource_info_s)); 00315 res5->path = (uint8_t*)malloc(6); 00316 res5->pathlen = 5; 00317 res5->path[0] = 'a'; 00318 res5->path[1] = '/'; 00319 res5->path[2] = '1'; 00320 res5->path[3] = '/'; 00321 res5->path[4] = '0'; 00322 res5->path[5] = '\0'; 00323 ns_list_add_to_start(&handle->resource_root_list, res5); 00324 ++handle->resource_root_count; 00325 00326 /* a/10 */ 00327 sn_nsdl_resource_info_s* res6 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00328 memset(res6, 0, sizeof(sn_nsdl_resource_info_s)); 00329 res6->path = (uint8_t*)malloc(5); 00330 res6->pathlen = 4; 00331 res6->path[0] = 'a'; 00332 res6->path[1] = '/'; 00333 res6->path[2] = '1'; 00334 res6->path[3] = '0'; 00335 res6->path[4] = '\0'; 00336 ns_list_add_to_start(&handle->resource_root_list, res6); 00337 ++handle->resource_root_count; 00338 00339 00340 /* a/10/0 */ 00341 sn_nsdl_resource_info_s* res7 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00342 memset(res7, 0, sizeof(sn_nsdl_resource_info_s)); 00343 res7->path = (uint8_t*)malloc(7); 00344 res7->pathlen = 6; 00345 res7->path[0] = 'a'; 00346 res7->path[1] = '/'; 00347 res7->path[2] = '1'; 00348 res7->path[3] = '0'; 00349 res7->path[4] = '/'; 00350 res7->path[5] = '0'; 00351 res7->path[6] = '\0'; 00352 ns_list_add_to_start(&handle->resource_root_list, res7); 00353 ++handle->resource_root_count; 00354 00355 uint8_t path2[4] = {'a', '/', '1', '\0'}; 00356 if( SN_NSDL_SUCCESS != sn_grs_delete_resource(handle, 3, &path2) ){ 00357 return false; 00358 } 00359 00360 // "a/1" and "a/1/0" removed 00361 if (handle->resource_root_count != 3) { 00362 return false; 00363 } 00364 00365 uint8_t path3[5] = {'a', '/', '1', '0', '\0'}; 00366 if( SN_NSDL_SUCCESS != sn_grs_delete_resource(handle, 4, &path3) ){ 00367 return false; 00368 } 00369 00370 if (handle->resource_root_count != 1) { 00371 return false; 00372 } 00373 00374 if( SN_NSDL_SUCCESS != sn_grs_delete_resource(handle, 1, &path) ){ 00375 return false; 00376 } 00377 00378 if (handle->resource_root_count != 0) { 00379 return false; 00380 } 00381 00382 sn_grs_destroy(handle); 00383 return true; 00384 } 00385 00386 bool test_sn_grs_update_resource() 00387 { 00388 if( SN_NSDL_FAILURE != sn_grs_update_resource(NULL, NULL) ){ 00389 return false; 00390 } 00391 00392 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 00393 memset(handle, 0, sizeof(struct grs_s)); 00394 handle->sn_grs_alloc = myMalloc; 00395 handle->sn_grs_free = myFree; 00396 00397 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00398 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00399 res->path = (uint8_t*)malloc(2); 00400 res->pathlen = 1; 00401 res->path[0] = 'a'; 00402 res->path[1] = '\0'; 00403 res->resource = (uint8_t*)malloc(2); 00404 res->resourcelen = 2; 00405 ns_list_add_to_start(&handle->resource_root_list, res); 00406 ++handle->resource_root_count; 00407 sn_nsdl_resource_info_s* res2 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00408 memset(res2, 0, sizeof(sn_nsdl_resource_info_s)); 00409 res2->path = (uint8_t*)malloc(2); 00410 res2->pathlen = 1; 00411 res2->path[0] = 'b'; 00412 res2->path[1] = '\0'; 00413 ns_list_add_to_start(&handle->resource_root_list, res2); 00414 ++handle->resource_root_count; 00415 00416 sn_nsdl_resource_info_s* res3 = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00417 memset(res3, 0, sizeof(sn_nsdl_resource_info_s)); 00418 res3->path = (uint8_t*)malloc(2); 00419 res3->pathlen = 1; 00420 res3->path[0] = 't'; 00421 res3->path[1] = '\0'; 00422 00423 if( SN_NSDL_FAILURE != sn_grs_update_resource(handle, res3) ){ 00424 return false; 00425 } 00426 00427 if( SN_NSDL_FAILURE != sn_grs_update_resource(handle, res) ){ 00428 return false; 00429 } 00430 00431 retCounter = 1; 00432 res3->path[0] = 'a'; 00433 res3->resource = (uint8_t*)malloc(2); 00434 res3->resourcelen = 2; 00435 if( SN_NSDL_SUCCESS != sn_grs_update_resource(handle, res3) ){ 00436 return false; 00437 } 00438 free(res3->resource); 00439 free(res3->path); 00440 free(res3); 00441 00442 sn_grs_destroy(handle); 00443 return true; 00444 } 00445 00446 bool test_sn_grs_create_resource() 00447 { 00448 if( SN_NSDL_FAILURE != sn_grs_create_resource(NULL, NULL) ){ 00449 return false; 00450 } 00451 00452 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 00453 memset(handle, 0, sizeof(struct grs_s)); 00454 handle->sn_grs_alloc = myMalloc; 00455 handle->sn_grs_free = myFree; 00456 00457 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00458 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00459 res->pathlen = 1; 00460 00461 if( SN_GRS_INVALID_PATH != sn_grs_create_resource(handle, res) ){ 00462 return false; 00463 } 00464 00465 res->path = (uint8_t*)malloc(2); 00466 res->path[0] = 'a'; 00467 res->path[1] = '\0'; 00468 res->resource = (uint8_t*)malloc(2); 00469 res->resource[0] = 'a'; 00470 res->resource[1] = '\0'; 00471 res->resourcelen = 1; 00472 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00473 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00474 00475 res->resource_parameters_ptr->resource_type_ptr = (uint8_t*)malloc(2); 00476 memset(res->resource_parameters_ptr->resource_type_ptr, 0, 2); 00477 00478 res->resource_parameters_ptr->interface_description_ptr = (uint8_t*)malloc(2); 00479 memset(res->resource_parameters_ptr->interface_description_ptr, 0, 2); 00480 00481 if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ 00482 return false; 00483 } 00484 00485 retCounter = 1; 00486 if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ 00487 return false; 00488 } 00489 00490 retCounter = 2; 00491 if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ 00492 return false; 00493 } 00494 00495 retCounter = 3; 00496 if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ 00497 return false; 00498 } 00499 00500 retCounter = 4; 00501 if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ 00502 return false; 00503 } 00504 00505 retCounter = 5; 00506 if( SN_GRS_LIST_ADDING_FAILURE != sn_grs_create_resource(handle, res) ){ 00507 return false; 00508 } 00509 00510 retCounter = 6; 00511 if( SN_NSDL_SUCCESS != sn_grs_create_resource(handle, res) ){ 00512 return false; 00513 } 00514 00515 if( SN_GRS_RESOURCE_ALREADY_EXISTS != sn_grs_create_resource(handle, res) ){ 00516 return false; 00517 } 00518 00519 ns_list_add_to_start(&handle->resource_root_list, res); 00520 sn_grs_destroy(handle); 00521 return true; 00522 } 00523 00524 bool test_sn_grs_put_resource() 00525 { 00526 if( SN_NSDL_FAILURE != sn_grs_put_resource(NULL, NULL) ){ 00527 return false; 00528 } 00529 00530 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 00531 memset(handle, 0, sizeof(struct grs_s)); 00532 handle->sn_grs_alloc = myMalloc; 00533 handle->sn_grs_free = myFree; 00534 00535 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00536 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00537 res->pathlen = 1; 00538 00539 if( SN_GRS_INVALID_PATH != sn_grs_put_resource(handle, res) ){ 00540 return false; 00541 } 00542 00543 uint8_t pa[2] = "a\0"; 00544 res->path = &pa; 00545 uint8_t re[2] = "a\0"; 00546 res->resource = &re; 00547 res->resourcelen = 1; 00548 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00549 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00550 00551 uint8_t rt[2]; 00552 res->resource_parameters_ptr->resource_type_ptr = &rt; 00553 00554 uint8_t ifp[2]; 00555 res->resource_parameters_ptr->interface_description_ptr = &ifp; 00556 00557 if( SN_NSDL_SUCCESS != sn_grs_put_resource(handle, res) ){ 00558 return false; 00559 } 00560 00561 if( SN_GRS_RESOURCE_ALREADY_EXISTS != sn_grs_put_resource(handle, res) ){ 00562 return false; 00563 } 00564 00565 00566 sn_grs_destroy(handle); 00567 00568 return true; 00569 } 00570 00571 bool test_sn_grs_process_coap() 00572 { 00573 if( SN_NSDL_FAILURE != sn_grs_process_coap(NULL, NULL, NULL) ){ 00574 return false; 00575 } 00576 00577 sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); 00578 memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); 00579 00580 struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 00581 memset(handle, 0, sizeof(struct nsdl_s)); 00582 00583 retCounter = 1; 00584 //sn_coap_protocol_stub.expectedCoap = NULL; 00585 struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 00586 00587 handle->grs = grs; 00588 00589 sn_coap_hdr_s* hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00590 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00591 00592 sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); 00593 memset(addr, 0, sizeof(sn_nsdl_addr_s)); 00594 00595 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00596 //Let's test first only upper if clause -> 00597 hdr->msg_type = COAP_MSG_TYPE_RESET; 00598 00599 hdr->uri_path_ptr = (uint8_t*)malloc(16); 00600 memcpy(hdr->uri_path_ptr, ".well-known/core", 16); 00601 hdr->uri_path_len = 16; 00602 00603 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00604 hdr->payload_ptr = (uint8_t*)malloc(2); 00605 00606 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00607 return false; 00608 } 00609 00610 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00611 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00612 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00613 hdr->msg_type = COAP_MSG_TYPE_RESET; 00614 hdr->uri_path_ptr = (uint8_t*)malloc(16); 00615 memcpy(hdr->uri_path_ptr, ".well-known/core", 16); 00616 hdr->uri_path_len = 16; 00617 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00618 hdr->payload_ptr = (uint8_t*)malloc(2); 00619 00620 retCounter = 1; 00621 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00622 return false; 00623 } 00624 00625 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00626 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00627 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00628 hdr->msg_type = COAP_MSG_TYPE_RESET; 00629 hdr->uri_path_ptr = (uint8_t*)malloc(16); 00630 memcpy(hdr->uri_path_ptr, ".well-known/core", 16); 00631 hdr->uri_path_len = 16; 00632 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00633 hdr->payload_ptr = (uint8_t*)malloc(2); 00634 00635 sn_nsdl_stub.allocatePayloadPtr = true; 00636 handle->sn_nsdl_alloc = &myMalloc; 00637 retCounter = 3; 00638 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00639 return false; 00640 } 00641 00642 00643 sn_nsdl_stub.allocatePayloadPtr = false; 00644 00645 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00646 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00647 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00648 hdr->msg_type = COAP_MSG_TYPE_RESET; 00649 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00650 hdr->uri_path_len = 2; 00651 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00652 hdr->payload_ptr = (uint8_t*)malloc(2); 00653 00654 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00655 return false; 00656 } 00657 00658 grs->sn_grs_rx_callback = &myRxCallback; 00659 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00660 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00661 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00662 hdr->msg_type = COAP_MSG_TYPE_RESET; 00663 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00664 hdr->uri_path_len = 2; 00665 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00666 hdr->payload_ptr = (uint8_t*)malloc(2); 00667 00668 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00669 return false; 00670 } 00671 00672 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00673 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00674 res->path = (uint8_t*)malloc(2); 00675 res->pathlen = 1; 00676 res->path[0] = 'a'; 00677 res->path[1] = '\0'; 00678 res->mode = SN_GRS_DYNAMIC; 00679 res->sn_grs_dyn_res_callback = &myResCallback; 00680 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00681 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00682 ns_list_add_to_start(&handle->grs->resource_root_list, res); 00683 ++handle->grs->resource_root_count; 00684 00685 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00686 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00687 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00688 hdr->msg_type = COAP_MSG_TYPE_RESET; 00689 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00690 hdr->uri_path_ptr[0] = 'a'; 00691 hdr->uri_path_ptr[1] = '\0'; 00692 hdr->uri_path_len = 1; 00693 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00694 hdr->payload_ptr = (uint8_t*)malloc(2); 00695 00696 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00697 return false; 00698 } 00699 00700 res->access = SN_GRS_GET_ALLOWED; 00701 00702 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00703 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00704 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00705 hdr->msg_type = COAP_MSG_TYPE_RESET; 00706 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00707 hdr->uri_path_ptr[0] = 'a'; 00708 hdr->uri_path_ptr[1] = '\0'; 00709 hdr->uri_path_len = 1; 00710 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00711 hdr->payload_ptr = (uint8_t*)malloc(2); 00712 00713 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00714 return false; 00715 } 00716 00717 res->mode = SN_GRS_STATIC; 00718 00719 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00720 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00721 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00722 hdr->msg_type = COAP_MSG_TYPE_RESET; 00723 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00724 hdr->uri_path_ptr[0] = 'a'; 00725 hdr->uri_path_ptr[1] = '\0'; 00726 hdr->uri_path_len = 1; 00727 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00728 hdr->payload_ptr = (uint8_t*)malloc(2); 00729 00730 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00731 return false; 00732 } 00733 00734 res->access = 0; 00735 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00736 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00737 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00738 hdr->msg_type = COAP_MSG_TYPE_RESET; 00739 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00740 hdr->uri_path_ptr[0] = 'a'; 00741 hdr->uri_path_ptr[1] = '\0'; 00742 hdr->uri_path_len = 1; 00743 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00744 hdr->payload_ptr = (uint8_t*)malloc(2); 00745 00746 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00747 return false; 00748 } 00749 00750 res->access = SN_GRS_POST_ALLOWED; 00751 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00752 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00753 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00754 hdr->msg_type = COAP_MSG_TYPE_RESET; 00755 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00756 hdr->uri_path_ptr[0] = 'a'; 00757 hdr->uri_path_ptr[1] = '\0'; 00758 hdr->uri_path_len = 1; 00759 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00760 hdr->payload_ptr = (uint8_t*)malloc(2); 00761 hdr->payload_len = 2; 00762 00763 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00764 return false; 00765 } 00766 00767 retCounter = 1; 00768 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00769 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00770 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00771 hdr->msg_type = COAP_MSG_TYPE_RESET; 00772 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00773 hdr->uri_path_ptr[0] = 'a'; 00774 hdr->uri_path_ptr[1] = '\0'; 00775 hdr->uri_path_len = 1; 00776 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00777 hdr->payload_ptr = (uint8_t*)malloc(2); 00778 hdr->payload_len = 2; 00779 hdr->content_format = COAP_CT_TEXT_PLAIN; 00780 00781 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00782 return false; 00783 } 00784 00785 res->access = 0; 00786 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00787 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00788 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00789 hdr->msg_type = COAP_MSG_TYPE_RESET; 00790 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00791 hdr->uri_path_ptr[0] = 'a'; 00792 hdr->uri_path_ptr[1] = '\0'; 00793 hdr->uri_path_len = 1; 00794 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00795 hdr->payload_ptr = (uint8_t*)malloc(2); 00796 hdr->payload_len = 2; 00797 00798 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00799 return false; 00800 } 00801 00802 res->access = SN_GRS_PUT_ALLOWED; 00803 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00804 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00805 hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00806 hdr->msg_type = COAP_MSG_TYPE_RESET; 00807 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00808 hdr->uri_path_ptr[0] = 'a'; 00809 hdr->uri_path_ptr[1] = '\0'; 00810 hdr->uri_path_len = 1; 00811 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00812 hdr->payload_ptr = (uint8_t*)malloc(2); 00813 hdr->payload_len = 2; 00814 00815 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00816 return false; 00817 } 00818 00819 retCounter = 1; 00820 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00821 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00822 hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00823 hdr->msg_type = COAP_MSG_TYPE_RESET; 00824 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00825 hdr->uri_path_ptr[0] = 'a'; 00826 hdr->uri_path_ptr[1] = '\0'; 00827 hdr->uri_path_len = 1; 00828 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00829 hdr->payload_ptr = (uint8_t*)malloc(2); 00830 hdr->payload_len = 2; 00831 hdr->content_format = 1; 00832 00833 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00834 return false; 00835 } 00836 00837 res->access = 0; 00838 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00839 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00840 hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00841 hdr->msg_type = COAP_MSG_TYPE_RESET; 00842 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00843 hdr->uri_path_ptr[0] = 'a'; 00844 hdr->uri_path_ptr[1] = '\0'; 00845 hdr->uri_path_len = 1; 00846 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00847 hdr->payload_ptr = (uint8_t*)malloc(2); 00848 hdr->payload_len = 2; 00849 00850 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00851 return false; 00852 } 00853 00854 //default: 00855 res->access = 0; 00856 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00857 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00858 hdr->msg_code = COAP_MSG_CODE_EMPTY; 00859 hdr->msg_type = COAP_MSG_TYPE_RESET; 00860 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00861 hdr->uri_path_ptr[0] = 'a'; 00862 hdr->uri_path_ptr[1] = '\0'; 00863 hdr->uri_path_len = 1; 00864 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00865 hdr->payload_ptr = (uint8_t*)malloc(2); 00866 hdr->payload_len = 2; 00867 00868 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00869 return false; 00870 } 00871 00872 //DELETE 00873 res->access = 0; 00874 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00875 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00876 hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; 00877 hdr->msg_type = COAP_MSG_TYPE_RESET; 00878 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00879 hdr->uri_path_ptr[0] = 'a'; 00880 hdr->uri_path_ptr[1] = '\0'; 00881 hdr->uri_path_len = 1; 00882 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00883 hdr->payload_ptr = (uint8_t*)malloc(2); 00884 hdr->payload_len = 2; 00885 00886 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00887 return false; 00888 } 00889 00890 res->access = SN_GRS_DELETE_ALLOWED; 00891 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00892 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00893 hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; 00894 hdr->msg_type = COAP_MSG_TYPE_RESET; 00895 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00896 hdr->uri_path_ptr[0] = 'a'; 00897 hdr->uri_path_ptr[1] = '\0'; 00898 hdr->uri_path_len = 1; 00899 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00900 hdr->payload_ptr = (uint8_t*)malloc(2); 00901 hdr->payload_len = 2; 00902 00903 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00904 return false; 00905 } 00906 00907 //This tries to test dead code 00908 // res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00909 // memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00910 // res->path = (uint8_t*)malloc(2); 00911 // res->pathlen = 1; 00912 // res->path[0] = 'a'; 00913 // res->path[1] = '\0'; 00914 // res->mode = SN_GRS_STATIC; 00915 // res->sn_grs_dyn_res_callback = &myResCallback; 00916 // res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00917 // res->access = SN_GRS_DELETE_ALLOWED; 00918 // memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00919 // ns_list_add_to_start(&handle->grs->resource_root_list, res); 00920 // ++handle->grs->resource_root_count; 00921 00922 // hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00923 // memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00924 // hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; 00925 // hdr->msg_type = COAP_MSG_TYPE_RESET; 00926 // hdr->uri_path_ptr = (uint8_t*)malloc(2); 00927 // hdr->uri_path_ptr[0] = 'a'; 00928 // hdr->uri_path_ptr[1] = '\0'; 00929 // hdr->uri_path_len = 1; 00930 // hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00931 // hdr->payload_ptr = (uint8_t*)malloc(2); 00932 // hdr->payload_len = 2; 00933 // hdr->content_format = 1; 00934 // 00935 00936 // if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00937 // return false; 00938 // } 00939 00940 //*********************************************** 00941 // Test below if clause -> 00942 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00943 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00944 hdr->msg_code = 999; 00945 hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; 00946 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00947 hdr->uri_path_ptr[0] = 'a'; 00948 hdr->uri_path_ptr[1] = '\0'; 00949 hdr->uri_path_len = 1; 00950 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00951 hdr->payload_ptr = (uint8_t*)malloc(2); 00952 hdr->payload_len = 2; 00953 hdr->content_format = 1; 00954 00955 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00956 return false; 00957 } 00958 00959 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00960 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00961 hdr->msg_code = COAP_MSG_CODE_EMPTY; 00962 hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; 00963 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00964 hdr->uri_path_ptr[0] = 'a'; 00965 hdr->uri_path_ptr[1] = '\0'; 00966 hdr->uri_path_len = 1; 00967 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00968 hdr->payload_ptr = (uint8_t*)malloc(2); 00969 hdr->payload_len = 2; 00970 hdr->content_format = 1; 00971 00972 hdr->token_ptr = (uint8_t*)malloc(1); 00973 hdr->token_len = 1; 00974 00975 retCounter = 1; 00976 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00977 return false; 00978 } 00979 00980 res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00981 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00982 res->path = (uint8_t*)malloc(2); 00983 res->pathlen = 1; 00984 res->path[0] = 'a'; 00985 res->path[1] = '\0'; 00986 res->mode = SN_GRS_STATIC; 00987 res->sn_grs_dyn_res_callback = &myResCallback; 00988 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00989 res->access = SN_GRS_GET_ALLOWED; 00990 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00991 res->resource_parameters_ptr->coap_content_type = 1; 00992 ns_list_add_to_start(&handle->grs->resource_root_list, res); 00993 ++handle->grs->resource_root_count; 00994 00995 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00996 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00997 hdr->msg_code = 999; 00998 hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; 00999 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01000 hdr->uri_path_ptr[0] = 'a'; 01001 hdr->uri_path_ptr[1] = '\0'; 01002 hdr->uri_path_len = 1; 01003 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01004 hdr->payload_ptr = (uint8_t*)malloc(2); 01005 hdr->payload_len = 2; 01006 hdr->content_format = 1; 01007 01008 hdr->token_ptr = (uint8_t*)malloc(1); 01009 hdr->token_len = 1; 01010 01011 retCounter = 1; 01012 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 01013 return false; 01014 } 01015 01016 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01017 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01018 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 01019 hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; 01020 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01021 hdr->uri_path_ptr[0] = 'a'; 01022 hdr->uri_path_ptr[1] = '\0'; 01023 hdr->uri_path_len = 1; 01024 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01025 hdr->payload_ptr = (uint8_t*)malloc(2); 01026 hdr->payload_len = 2; 01027 hdr->content_format = 1; 01028 01029 hdr->token_ptr = (uint8_t*)malloc(1); 01030 hdr->token_len = 1; 01031 01032 retCounter = 3; 01033 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 01034 return false; 01035 } 01036 01037 res->resource = (uint8_t*)malloc(2); 01038 res->resourcelen = 2; 01039 01040 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01041 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01042 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 01043 hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; 01044 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01045 hdr->uri_path_ptr[0] = 'a'; 01046 hdr->uri_path_ptr[1] = '\0'; 01047 hdr->uri_path_len = 1; 01048 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01049 hdr->payload_ptr = (uint8_t*)malloc(2); 01050 hdr->payload_len = 2; 01051 hdr->content_format = 1; 01052 hdr->token_ptr = (uint8_t*)malloc(1); 01053 hdr->token_len = 1; 01054 01055 retCounter = 2; 01056 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 01057 return false; 01058 } 01059 01060 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01061 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01062 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 01063 hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; 01064 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01065 hdr->uri_path_ptr[0] = 'a'; 01066 hdr->uri_path_ptr[1] = '\0'; 01067 hdr->uri_path_len = 1; 01068 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01069 hdr->payload_ptr = (uint8_t*)malloc(2); 01070 hdr->payload_len = 2; 01071 hdr->content_format = 1; 01072 01073 hdr->token_ptr = (uint8_t*)malloc(1); 01074 hdr->token_len = 1; 01075 01076 retCounter = 6; 01077 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 01078 return false; 01079 } 01080 01081 01082 free(sn_coap_protocol_stub.expectedCoap); 01083 sn_coap_protocol_stub.expectedCoap = NULL; 01084 free(addr); 01085 sn_grs_destroy(handle->grs); 01086 free(handle); 01087 return true; 01088 } 01089 01090 bool test_sn_grs_send_coap_message() 01091 { 01092 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(NULL, NULL, NULL) ){ 01093 return false; 01094 } 01095 sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); 01096 memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); 01097 01098 struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 01099 memset(handle, 0, sizeof(struct nsdl_s)); 01100 01101 retCounter = 1; 01102 struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 01103 01104 handle->grs = grs; 01105 01106 // sn_coap_hdr_s* hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01107 // memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01108 01109 // sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); 01110 // memset(addr, 0, sizeof(sn_nsdl_addr_s)); 01111 01112 sn_coap_builder_stub.expectedUint16 = 2; 01113 01114 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01115 return false; 01116 } 01117 01118 retCounter = 1; 01119 sn_coap_protocol_stub.expectedInt16 = -1; 01120 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01121 return false; 01122 } 01123 01124 retCounter = 1; 01125 sn_coap_protocol_stub.expectedInt16 = 2; 01126 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01127 return false; 01128 } 01129 01130 retValUint8 = 1; 01131 retCounter = 1; 01132 sn_coap_protocol_stub.expectedInt16 = 2; 01133 if( SN_NSDL_SUCCESS != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01134 return false; 01135 } 01136 free(sn_coap_protocol_stub.expectedCoap); 01137 sn_coap_protocol_stub.expectedCoap = NULL; 01138 sn_grs_destroy(handle->grs); 01139 free(handle); 01140 return true; 01141 } 01142 01143 01144 bool test_sn_grs_search_resource() 01145 { 01146 if( NULL != sn_grs_search_resource(NULL, 0, NULL, 0) ){ 01147 return false; 01148 } 01149 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 01150 memset(handle, 0, sizeof(struct grs_s)); 01151 handle->sn_grs_alloc = myMalloc; 01152 handle->sn_grs_free = myFree; 01153 01154 uint8_t* path = (uint8_t*)malloc(6); 01155 path[0] = '/'; 01156 path[1] = 'a'; 01157 path[2] = 'b'; 01158 path[3] = 'c'; 01159 path[4] = '/'; 01160 if( NULL != sn_grs_search_resource(handle, 5, path, SN_GRS_SEARCH_METHOD) ){ 01161 return false; 01162 } 01163 01164 handle->resource_root_count = 0; 01165 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01166 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 01167 res->path = (uint8_t*)malloc(4); 01168 res->path[0] = 'a'; 01169 res->path[1] = 'b'; 01170 res->path[2] = 'c'; 01171 res->pathlen = 3; 01172 ns_list_add_to_start(&handle->resource_root_list, res); 01173 ++handle->resource_root_count; 01174 01175 if( NULL == sn_grs_search_resource(handle, 5, path, SN_GRS_SEARCH_METHOD) ){ 01176 return false; 01177 } 01178 01179 res->path[3] = '/'; 01180 res->pathlen = 4; 01181 01182 if( NULL == sn_grs_search_resource(handle, 5, path, SN_GRS_DELETE_METHOD) ){ 01183 return false; 01184 } 01185 01186 free(path); 01187 sn_grs_destroy(handle); 01188 return true; 01189 } 01190 01191 bool test_sn_grs_mark_resources_as_registered() 01192 { 01193 sn_grs_mark_resources_as_registered(NULL); 01194 01195 struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 01196 memset(handle, 0, sizeof(struct nsdl_s)); 01197 01198 retCounter = 1; 01199 struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 01200 handle->grs = grs; 01201 01202 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01203 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 01204 res->path = (uint8_t*)malloc(2); 01205 res->pathlen = 1; 01206 res->path[0] = 'a'; 01207 res->path[1] = '\0'; 01208 res->mode = SN_GRS_DYNAMIC; 01209 res->sn_grs_dyn_res_callback = &myResCallback; 01210 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 01211 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 01212 res->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; 01213 ns_list_add_to_start(&handle->grs->resource_root_list, res); 01214 ++handle->grs->resource_root_count; 01215 01216 sn_grs_mark_resources_as_registered(handle); 01217 if( SN_NDSL_RESOURCE_REGISTERED != res->resource_parameters_ptr->registered ){ 01218 return false; 01219 } 01220 01221 sn_grs_destroy(handle->grs); 01222 free(handle); 01223 return true; 01224 } 01225
Generated on Tue Jul 12 2022 14:21:23 by
1.7.2