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.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
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_process_coap() 00525 { 00526 if( SN_NSDL_FAILURE != sn_grs_process_coap(NULL, NULL, NULL) ){ 00527 return false; 00528 } 00529 00530 sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); 00531 memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); 00532 00533 struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 00534 memset(handle, 0, sizeof(struct nsdl_s)); 00535 00536 retCounter = 1; 00537 //sn_coap_protocol_stub.expectedCoap = NULL; 00538 struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 00539 00540 handle->grs = grs; 00541 00542 sn_coap_hdr_s* hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00543 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00544 00545 sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); 00546 memset(addr, 0, sizeof(sn_nsdl_addr_s)); 00547 00548 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00549 //Let's test first only upper if clause -> 00550 hdr->msg_type = COAP_MSG_TYPE_RESET; 00551 00552 hdr->uri_path_ptr = (uint8_t*)malloc(16); 00553 memcpy(hdr->uri_path_ptr, ".well-known/core", 16); 00554 hdr->uri_path_len = 16; 00555 00556 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00557 hdr->payload_ptr = (uint8_t*)malloc(2); 00558 00559 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00560 return false; 00561 } 00562 00563 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00564 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00565 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00566 hdr->msg_type = COAP_MSG_TYPE_RESET; 00567 hdr->uri_path_ptr = (uint8_t*)malloc(16); 00568 memcpy(hdr->uri_path_ptr, ".well-known/core", 16); 00569 hdr->uri_path_len = 16; 00570 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00571 hdr->payload_ptr = (uint8_t*)malloc(2); 00572 00573 retCounter = 1; 00574 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00575 return false; 00576 } 00577 00578 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00579 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00580 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00581 hdr->msg_type = COAP_MSG_TYPE_RESET; 00582 hdr->uri_path_ptr = (uint8_t*)malloc(16); 00583 memcpy(hdr->uri_path_ptr, ".well-known/core", 16); 00584 hdr->uri_path_len = 16; 00585 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00586 hdr->payload_ptr = (uint8_t*)malloc(2); 00587 00588 sn_nsdl_stub.allocatePayloadPtr = true; 00589 handle->sn_nsdl_alloc = &myMalloc; 00590 retCounter = 3; 00591 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00592 return false; 00593 } 00594 00595 00596 sn_nsdl_stub.allocatePayloadPtr = false; 00597 00598 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00599 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00600 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00601 hdr->msg_type = COAP_MSG_TYPE_RESET; 00602 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00603 hdr->uri_path_len = 2; 00604 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00605 hdr->payload_ptr = (uint8_t*)malloc(2); 00606 00607 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00608 return false; 00609 } 00610 00611 grs->sn_grs_rx_callback = &myRxCallback; 00612 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00613 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00614 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00615 hdr->msg_type = COAP_MSG_TYPE_RESET; 00616 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00617 hdr->uri_path_len = 2; 00618 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00619 hdr->payload_ptr = (uint8_t*)malloc(2); 00620 00621 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00622 return false; 00623 } 00624 00625 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00626 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00627 res->path = (uint8_t*)malloc(2); 00628 res->pathlen = 1; 00629 res->path[0] = 'a'; 00630 res->path[1] = '\0'; 00631 res->mode = SN_GRS_DYNAMIC; 00632 res->sn_grs_dyn_res_callback = &myResCallback; 00633 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00634 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00635 ns_list_add_to_start(&handle->grs->resource_root_list, res); 00636 ++handle->grs->resource_root_count; 00637 00638 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00639 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00640 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00641 hdr->msg_type = COAP_MSG_TYPE_RESET; 00642 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00643 hdr->uri_path_ptr[0] = 'a'; 00644 hdr->uri_path_ptr[1] = '\0'; 00645 hdr->uri_path_len = 1; 00646 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00647 hdr->payload_ptr = (uint8_t*)malloc(2); 00648 00649 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00650 return false; 00651 } 00652 00653 res->access = SN_GRS_GET_ALLOWED; 00654 00655 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00656 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00657 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00658 hdr->msg_type = COAP_MSG_TYPE_RESET; 00659 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00660 hdr->uri_path_ptr[0] = 'a'; 00661 hdr->uri_path_ptr[1] = '\0'; 00662 hdr->uri_path_len = 1; 00663 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00664 hdr->payload_ptr = (uint8_t*)malloc(2); 00665 00666 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00667 return false; 00668 } 00669 00670 res->mode = SN_GRS_STATIC; 00671 00672 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00673 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00674 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00675 hdr->msg_type = COAP_MSG_TYPE_RESET; 00676 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00677 hdr->uri_path_ptr[0] = 'a'; 00678 hdr->uri_path_ptr[1] = '\0'; 00679 hdr->uri_path_len = 1; 00680 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00681 hdr->payload_ptr = (uint8_t*)malloc(2); 00682 00683 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00684 return false; 00685 } 00686 00687 res->access = 0; 00688 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00689 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00690 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00691 hdr->msg_type = COAP_MSG_TYPE_RESET; 00692 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00693 hdr->uri_path_ptr[0] = 'a'; 00694 hdr->uri_path_ptr[1] = '\0'; 00695 hdr->uri_path_len = 1; 00696 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00697 hdr->payload_ptr = (uint8_t*)malloc(2); 00698 00699 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00700 return false; 00701 } 00702 00703 res->access = SN_GRS_POST_ALLOWED; 00704 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00705 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00706 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00707 hdr->msg_type = COAP_MSG_TYPE_RESET; 00708 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00709 hdr->uri_path_ptr[0] = 'a'; 00710 hdr->uri_path_ptr[1] = '\0'; 00711 hdr->uri_path_len = 1; 00712 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00713 hdr->payload_ptr = (uint8_t*)malloc(2); 00714 hdr->payload_len = 2; 00715 00716 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00717 return false; 00718 } 00719 00720 retCounter = 1; 00721 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00722 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00723 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00724 hdr->msg_type = COAP_MSG_TYPE_RESET; 00725 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00726 hdr->uri_path_ptr[0] = 'a'; 00727 hdr->uri_path_ptr[1] = '\0'; 00728 hdr->uri_path_len = 1; 00729 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00730 hdr->payload_ptr = (uint8_t*)malloc(2); 00731 hdr->payload_len = 2; 00732 hdr->content_type_ptr = (uint8_t*)malloc(1); 00733 hdr->content_type_ptr[0] = 1; 00734 hdr->content_type_len = 1; 00735 00736 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00737 return false; 00738 } 00739 00740 res->access = 0; 00741 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00742 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00743 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00744 hdr->msg_type = COAP_MSG_TYPE_RESET; 00745 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00746 hdr->uri_path_ptr[0] = 'a'; 00747 hdr->uri_path_ptr[1] = '\0'; 00748 hdr->uri_path_len = 1; 00749 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00750 hdr->payload_ptr = (uint8_t*)malloc(2); 00751 hdr->payload_len = 2; 00752 00753 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00754 return false; 00755 } 00756 00757 res->access = SN_GRS_PUT_ALLOWED; 00758 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00759 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00760 hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00761 hdr->msg_type = COAP_MSG_TYPE_RESET; 00762 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00763 hdr->uri_path_ptr[0] = 'a'; 00764 hdr->uri_path_ptr[1] = '\0'; 00765 hdr->uri_path_len = 1; 00766 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00767 hdr->payload_ptr = (uint8_t*)malloc(2); 00768 hdr->payload_len = 2; 00769 00770 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00771 return false; 00772 } 00773 00774 retCounter = 1; 00775 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00776 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00777 hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00778 hdr->msg_type = COAP_MSG_TYPE_RESET; 00779 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00780 hdr->uri_path_ptr[0] = 'a'; 00781 hdr->uri_path_ptr[1] = '\0'; 00782 hdr->uri_path_len = 1; 00783 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00784 hdr->payload_ptr = (uint8_t*)malloc(2); 00785 hdr->payload_len = 2; 00786 hdr->content_type_ptr = (uint8_t*)malloc(1); 00787 hdr->content_type_ptr[0] = 1; 00788 hdr->content_type_len = 1; 00789 00790 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00791 return false; 00792 } 00793 00794 res->access = 0; 00795 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00796 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00797 hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00798 hdr->msg_type = COAP_MSG_TYPE_RESET; 00799 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00800 hdr->uri_path_ptr[0] = 'a'; 00801 hdr->uri_path_ptr[1] = '\0'; 00802 hdr->uri_path_len = 1; 00803 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00804 hdr->payload_ptr = (uint8_t*)malloc(2); 00805 hdr->payload_len = 2; 00806 00807 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00808 return false; 00809 } 00810 00811 //default: 00812 res->access = 0; 00813 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00814 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00815 hdr->msg_code = COAP_MSG_CODE_EMPTY; 00816 hdr->msg_type = COAP_MSG_TYPE_RESET; 00817 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00818 hdr->uri_path_ptr[0] = 'a'; 00819 hdr->uri_path_ptr[1] = '\0'; 00820 hdr->uri_path_len = 1; 00821 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00822 hdr->payload_ptr = (uint8_t*)malloc(2); 00823 hdr->payload_len = 2; 00824 00825 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00826 return false; 00827 } 00828 00829 //DELETE 00830 res->access = 0; 00831 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00832 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00833 hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; 00834 hdr->msg_type = COAP_MSG_TYPE_RESET; 00835 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00836 hdr->uri_path_ptr[0] = 'a'; 00837 hdr->uri_path_ptr[1] = '\0'; 00838 hdr->uri_path_len = 1; 00839 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00840 hdr->payload_ptr = (uint8_t*)malloc(2); 00841 hdr->payload_len = 2; 00842 00843 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00844 return false; 00845 } 00846 00847 res->access = SN_GRS_DELETE_ALLOWED; 00848 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00849 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00850 hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; 00851 hdr->msg_type = COAP_MSG_TYPE_RESET; 00852 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00853 hdr->uri_path_ptr[0] = 'a'; 00854 hdr->uri_path_ptr[1] = '\0'; 00855 hdr->uri_path_len = 1; 00856 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00857 hdr->payload_ptr = (uint8_t*)malloc(2); 00858 hdr->payload_len = 2; 00859 00860 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00861 return false; 00862 } 00863 00864 //This tries to test dead code 00865 // res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00866 // memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00867 // res->path = (uint8_t*)malloc(2); 00868 // res->pathlen = 1; 00869 // res->path[0] = 'a'; 00870 // res->path[1] = '\0'; 00871 // res->mode = SN_GRS_STATIC; 00872 // res->sn_grs_dyn_res_callback = &myResCallback; 00873 // res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00874 // res->access = SN_GRS_DELETE_ALLOWED; 00875 // memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00876 // ns_list_add_to_start(&handle->grs->resource_root_list, res); 00877 // ++handle->grs->resource_root_count; 00878 00879 // hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00880 // memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00881 // hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; 00882 // hdr->msg_type = COAP_MSG_TYPE_RESET; 00883 // hdr->uri_path_ptr = (uint8_t*)malloc(2); 00884 // hdr->uri_path_ptr[0] = 'a'; 00885 // hdr->uri_path_ptr[1] = '\0'; 00886 // hdr->uri_path_len = 1; 00887 // hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00888 // hdr->payload_ptr = (uint8_t*)malloc(2); 00889 // hdr->payload_len = 2; 00890 // hdr->content_type_ptr = (uint8_t*)malloc(1); 00891 // hdr->content_type_ptr[0] = 1; 00892 // hdr->content_type_len = 1; 00893 00894 // if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00895 // return false; 00896 // } 00897 00898 //*********************************************** 00899 // Test below if clause -> 00900 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00901 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00902 hdr->msg_code = 999; 00903 hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; 00904 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00905 hdr->uri_path_ptr[0] = 'a'; 00906 hdr->uri_path_ptr[1] = '\0'; 00907 hdr->uri_path_len = 1; 00908 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00909 hdr->payload_ptr = (uint8_t*)malloc(2); 00910 hdr->payload_len = 2; 00911 hdr->content_type_ptr = (uint8_t*)malloc(1); 00912 hdr->content_type_ptr[0] = 1; 00913 hdr->content_type_len = 1; 00914 00915 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00916 return false; 00917 } 00918 00919 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00920 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00921 hdr->msg_code = COAP_MSG_CODE_EMPTY; 00922 hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; 00923 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00924 hdr->uri_path_ptr[0] = 'a'; 00925 hdr->uri_path_ptr[1] = '\0'; 00926 hdr->uri_path_len = 1; 00927 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00928 hdr->payload_ptr = (uint8_t*)malloc(2); 00929 hdr->payload_len = 2; 00930 hdr->content_type_ptr = (uint8_t*)malloc(1); 00931 hdr->content_type_ptr[0] = 1; 00932 hdr->content_type_len = 1; 00933 hdr->token_ptr = (uint8_t*)malloc(1); 00934 hdr->token_len = 1; 00935 00936 retCounter = 1; 00937 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00938 return false; 00939 } 00940 00941 res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00942 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00943 res->path = (uint8_t*)malloc(2); 00944 res->pathlen = 1; 00945 res->path[0] = 'a'; 00946 res->path[1] = '\0'; 00947 res->mode = SN_GRS_STATIC; 00948 res->sn_grs_dyn_res_callback = &myResCallback; 00949 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00950 res->access = SN_GRS_GET_ALLOWED; 00951 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00952 res->resource_parameters_ptr->coap_content_type = 1; 00953 ns_list_add_to_start(&handle->grs->resource_root_list, res); 00954 ++handle->grs->resource_root_count; 00955 00956 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00957 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00958 hdr->msg_code = 999; 00959 hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; 00960 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00961 hdr->uri_path_ptr[0] = 'a'; 00962 hdr->uri_path_ptr[1] = '\0'; 00963 hdr->uri_path_len = 1; 00964 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00965 hdr->payload_ptr = (uint8_t*)malloc(2); 00966 hdr->payload_len = 2; 00967 hdr->content_type_ptr = (uint8_t*)malloc(1); 00968 hdr->content_type_ptr[0] = 1; 00969 hdr->content_type_len = 1; 00970 hdr->token_ptr = (uint8_t*)malloc(1); 00971 hdr->token_len = 1; 00972 00973 retCounter = 1; 00974 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00975 return false; 00976 } 00977 00978 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00979 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00980 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00981 hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; 00982 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00983 hdr->uri_path_ptr[0] = 'a'; 00984 hdr->uri_path_ptr[1] = '\0'; 00985 hdr->uri_path_len = 1; 00986 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00987 hdr->payload_ptr = (uint8_t*)malloc(2); 00988 hdr->payload_len = 2; 00989 hdr->content_type_ptr = (uint8_t*)malloc(1); 00990 hdr->content_type_ptr[0] = 1; 00991 hdr->content_type_len = 1; 00992 hdr->token_ptr = (uint8_t*)malloc(1); 00993 hdr->token_len = 1; 00994 00995 retCounter = 2; 00996 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00997 return false; 00998 } 00999 01000 res->resource = (uint8_t*)malloc(2); 01001 res->resourcelen = 2; 01002 01003 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01004 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01005 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 01006 hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; 01007 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01008 hdr->uri_path_ptr[0] = 'a'; 01009 hdr->uri_path_ptr[1] = '\0'; 01010 hdr->uri_path_len = 1; 01011 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01012 hdr->payload_ptr = (uint8_t*)malloc(2); 01013 hdr->payload_len = 2; 01014 hdr->content_type_ptr = (uint8_t*)malloc(1); 01015 hdr->content_type_ptr[0] = 1; 01016 hdr->content_type_len = 1; 01017 hdr->token_ptr = (uint8_t*)malloc(1); 01018 hdr->token_len = 1; 01019 01020 retCounter = 3; 01021 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 01022 return false; 01023 } 01024 01025 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01026 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01027 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 01028 hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; 01029 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01030 hdr->uri_path_ptr[0] = 'a'; 01031 hdr->uri_path_ptr[1] = '\0'; 01032 hdr->uri_path_len = 1; 01033 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01034 hdr->payload_ptr = (uint8_t*)malloc(2); 01035 hdr->payload_len = 2; 01036 hdr->content_type_ptr = (uint8_t*)malloc(1); 01037 hdr->content_type_ptr[0] = 1; 01038 hdr->content_type_len = 1; 01039 hdr->token_ptr = (uint8_t*)malloc(1); 01040 hdr->token_len = 1; 01041 01042 retCounter = 6; 01043 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 01044 return false; 01045 } 01046 01047 01048 free(sn_coap_protocol_stub.expectedCoap); 01049 sn_coap_protocol_stub.expectedCoap = NULL; 01050 free(addr); 01051 sn_grs_destroy(handle->grs); 01052 free(handle); 01053 return true; 01054 } 01055 01056 bool test_sn_grs_send_coap_message() 01057 { 01058 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(NULL, NULL, NULL) ){ 01059 return false; 01060 } 01061 sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); 01062 memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); 01063 01064 struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 01065 memset(handle, 0, sizeof(struct nsdl_s)); 01066 01067 retCounter = 1; 01068 struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 01069 01070 handle->grs = grs; 01071 01072 // sn_coap_hdr_s* hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01073 // memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01074 01075 // sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); 01076 // memset(addr, 0, sizeof(sn_nsdl_addr_s)); 01077 01078 sn_coap_builder_stub.expectedUint16 = 2; 01079 01080 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01081 return false; 01082 } 01083 01084 retCounter = 1; 01085 sn_coap_protocol_stub.expectedInt16 = -1; 01086 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01087 return false; 01088 } 01089 01090 retCounter = 1; 01091 sn_coap_protocol_stub.expectedInt16 = 2; 01092 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01093 return false; 01094 } 01095 01096 retValUint8 = 1; 01097 retCounter = 1; 01098 sn_coap_protocol_stub.expectedInt16 = 2; 01099 if( SN_NSDL_SUCCESS != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01100 return false; 01101 } 01102 free(sn_coap_protocol_stub.expectedCoap); 01103 sn_coap_protocol_stub.expectedCoap = NULL; 01104 sn_grs_destroy(handle->grs); 01105 free(handle); 01106 return true; 01107 } 01108 01109 01110 bool test_sn_grs_search_resource() 01111 { 01112 if( NULL != sn_grs_search_resource(NULL, 0, NULL, 0) ){ 01113 return false; 01114 } 01115 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 01116 memset(handle, 0, sizeof(struct grs_s)); 01117 handle->sn_grs_alloc = myMalloc; 01118 handle->sn_grs_free = myFree; 01119 01120 uint8_t* path = (uint8_t*)malloc(6); 01121 path[0] = '/'; 01122 path[1] = 'a'; 01123 path[2] = 'b'; 01124 path[3] = 'c'; 01125 path[4] = '/'; 01126 if( NULL != sn_grs_search_resource(handle, 5, path, SN_GRS_SEARCH_METHOD) ){ 01127 return false; 01128 } 01129 01130 handle->resource_root_count = 0; 01131 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01132 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 01133 res->path = (uint8_t*)malloc(4); 01134 res->path[0] = 'a'; 01135 res->path[1] = 'b'; 01136 res->path[2] = 'c'; 01137 res->pathlen = 3; 01138 ns_list_add_to_start(&handle->resource_root_list, res); 01139 ++handle->resource_root_count; 01140 01141 if( NULL == sn_grs_search_resource(handle, 5, path, SN_GRS_SEARCH_METHOD) ){ 01142 return false; 01143 } 01144 01145 res->path[3] = '/'; 01146 res->pathlen = 4; 01147 01148 if( NULL == sn_grs_search_resource(handle, 5, path, SN_GRS_DELETE_METHOD) ){ 01149 return false; 01150 } 01151 01152 free(path); 01153 sn_grs_destroy(handle); 01154 return true; 01155 } 01156 01157 bool test_sn_grs_mark_resources_as_registered() 01158 { 01159 sn_grs_mark_resources_as_registered(NULL); 01160 01161 struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 01162 memset(handle, 0, sizeof(struct nsdl_s)); 01163 01164 retCounter = 1; 01165 struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 01166 handle->grs = grs; 01167 01168 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01169 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 01170 res->path = (uint8_t*)malloc(2); 01171 res->pathlen = 1; 01172 res->path[0] = 'a'; 01173 res->path[1] = '\0'; 01174 res->mode = SN_GRS_DYNAMIC; 01175 res->sn_grs_dyn_res_callback = &myResCallback; 01176 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 01177 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 01178 res->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; 01179 ns_list_add_to_start(&handle->grs->resource_root_list, res); 01180 ++handle->grs->resource_root_count; 01181 01182 sn_grs_mark_resources_as_registered(handle); 01183 if( SN_NDSL_RESOURCE_REGISTERED != res->resource_parameters_ptr->registered ){ 01184 return false; 01185 } 01186 01187 sn_grs_destroy(handle->grs); 01188 free(handle); 01189 return true; 01190 } 01191
Generated on Tue Jul 12 2022 12:28:55 by
