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_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*)calloc(2, 1); 00650 hdr->uri_path_len = 2; 00651 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00652 hdr->payload_ptr = (uint8_t*)calloc(2, 1); 00653 hdr->payload_len = 2; 00654 00655 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00656 return false; 00657 } 00658 00659 grs->sn_grs_rx_callback = &myRxCallback; 00660 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00661 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00662 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00663 hdr->msg_type = COAP_MSG_TYPE_RESET; 00664 hdr->uri_path_ptr = (uint8_t*)calloc(2, 1); 00665 hdr->uri_path_len = 2; 00666 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00667 hdr->payload_ptr = (uint8_t*)malloc(2); 00668 hdr->payload_len = 2; 00669 00670 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00671 return false; 00672 } 00673 00674 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00675 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00676 res->path = (uint8_t*)malloc(2); 00677 res->pathlen = 1; 00678 res->path[0] = 'a'; 00679 res->path[1] = '\0'; 00680 res->mode = SN_GRS_DYNAMIC; 00681 res->sn_grs_dyn_res_callback = &myResCallback; 00682 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00683 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00684 ns_list_add_to_start(&handle->grs->resource_root_list, res); 00685 ++handle->grs->resource_root_count; 00686 00687 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00688 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00689 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00690 hdr->msg_type = COAP_MSG_TYPE_RESET; 00691 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00692 hdr->uri_path_ptr[0] = 'a'; 00693 hdr->uri_path_ptr[1] = '\0'; 00694 hdr->uri_path_len = 1; 00695 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00696 hdr->payload_ptr = (uint8_t*)malloc(2); 00697 00698 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00699 return false; 00700 } 00701 00702 res->access = SN_GRS_GET_ALLOWED; 00703 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_GET; 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 00715 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00716 return false; 00717 } 00718 00719 res->mode = SN_GRS_STATIC; 00720 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_GET; 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 00732 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00733 return false; 00734 } 00735 00736 res->access = 0; 00737 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00738 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00739 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 00740 hdr->msg_type = COAP_MSG_TYPE_RESET; 00741 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00742 hdr->uri_path_ptr[0] = 'a'; 00743 hdr->uri_path_ptr[1] = '\0'; 00744 hdr->uri_path_len = 1; 00745 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00746 hdr->payload_ptr = (uint8_t*)malloc(2); 00747 00748 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00749 return false; 00750 } 00751 00752 res->access = SN_GRS_POST_ALLOWED; 00753 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00754 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00755 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00756 hdr->msg_type = COAP_MSG_TYPE_RESET; 00757 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00758 hdr->uri_path_ptr[0] = 'a'; 00759 hdr->uri_path_ptr[1] = '\0'; 00760 hdr->uri_path_len = 1; 00761 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00762 hdr->payload_ptr = (uint8_t*)malloc(2); 00763 hdr->payload_len = 2; 00764 00765 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00766 return false; 00767 } 00768 00769 retCounter = 1; 00770 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00771 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00772 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00773 hdr->msg_type = COAP_MSG_TYPE_RESET; 00774 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00775 hdr->uri_path_ptr[0] = 'a'; 00776 hdr->uri_path_ptr[1] = '\0'; 00777 hdr->uri_path_len = 1; 00778 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00779 hdr->payload_ptr = (uint8_t*)malloc(2); 00780 hdr->payload_len = 2; 00781 hdr->content_format = COAP_CT_TEXT_PLAIN; 00782 00783 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00784 return false; 00785 } 00786 00787 res->access = 0; 00788 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00789 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00790 hdr->msg_code = COAP_MSG_CODE_REQUEST_POST; 00791 hdr->msg_type = COAP_MSG_TYPE_RESET; 00792 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00793 hdr->uri_path_ptr[0] = 'a'; 00794 hdr->uri_path_ptr[1] = '\0'; 00795 hdr->uri_path_len = 1; 00796 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00797 hdr->payload_ptr = (uint8_t*)malloc(2); 00798 hdr->payload_len = 2; 00799 00800 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00801 return false; 00802 } 00803 00804 res->access = SN_GRS_PUT_ALLOWED; 00805 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00806 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00807 hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00808 hdr->msg_type = COAP_MSG_TYPE_RESET; 00809 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00810 hdr->uri_path_ptr[0] = 'a'; 00811 hdr->uri_path_ptr[1] = '\0'; 00812 hdr->uri_path_len = 1; 00813 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00814 hdr->payload_ptr = (uint8_t*)malloc(2); 00815 hdr->payload_len = 2; 00816 00817 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00818 return false; 00819 } 00820 00821 retCounter = 1; 00822 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00823 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00824 hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00825 hdr->msg_type = COAP_MSG_TYPE_RESET; 00826 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00827 hdr->uri_path_ptr[0] = 'a'; 00828 hdr->uri_path_ptr[1] = '\0'; 00829 hdr->uri_path_len = 1; 00830 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00831 hdr->payload_ptr = (uint8_t*)malloc(2); 00832 hdr->payload_len = 2; 00833 hdr->content_format = 1; 00834 00835 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00836 return false; 00837 } 00838 00839 res->access = 0; 00840 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00841 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00842 hdr->msg_code = COAP_MSG_CODE_REQUEST_PUT; 00843 hdr->msg_type = COAP_MSG_TYPE_RESET; 00844 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00845 hdr->uri_path_ptr[0] = 'a'; 00846 hdr->uri_path_ptr[1] = '\0'; 00847 hdr->uri_path_len = 1; 00848 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00849 hdr->payload_ptr = (uint8_t*)malloc(2); 00850 hdr->payload_len = 2; 00851 00852 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00853 return false; 00854 } 00855 00856 //default: 00857 res->access = 0; 00858 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00859 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00860 hdr->msg_code = COAP_MSG_CODE_EMPTY; 00861 hdr->msg_type = COAP_MSG_TYPE_RESET; 00862 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00863 hdr->uri_path_ptr[0] = 'a'; 00864 hdr->uri_path_ptr[1] = '\0'; 00865 hdr->uri_path_len = 1; 00866 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00867 hdr->payload_ptr = (uint8_t*)malloc(2); 00868 hdr->payload_len = 2; 00869 00870 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00871 return false; 00872 } 00873 00874 //DELETE 00875 res->access = 0; 00876 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00877 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00878 hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; 00879 hdr->msg_type = COAP_MSG_TYPE_RESET; 00880 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00881 hdr->uri_path_ptr[0] = 'a'; 00882 hdr->uri_path_ptr[1] = '\0'; 00883 hdr->uri_path_len = 1; 00884 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00885 hdr->payload_ptr = (uint8_t*)malloc(2); 00886 hdr->payload_len = 2; 00887 00888 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00889 return false; 00890 } 00891 00892 res->access = SN_GRS_DELETE_ALLOWED; 00893 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00894 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00895 hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; 00896 hdr->msg_type = COAP_MSG_TYPE_RESET; 00897 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00898 hdr->uri_path_ptr[0] = 'a'; 00899 hdr->uri_path_ptr[1] = '\0'; 00900 hdr->uri_path_len = 1; 00901 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00902 hdr->payload_ptr = (uint8_t*)malloc(2); 00903 hdr->payload_len = 2; 00904 00905 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00906 return false; 00907 } 00908 00909 //This tries to test dead code 00910 // res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00911 // memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00912 // res->path = (uint8_t*)malloc(2); 00913 // res->pathlen = 1; 00914 // res->path[0] = 'a'; 00915 // res->path[1] = '\0'; 00916 // res->mode = SN_GRS_STATIC; 00917 // res->sn_grs_dyn_res_callback = &myResCallback; 00918 // res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00919 // res->access = SN_GRS_DELETE_ALLOWED; 00920 // memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00921 // ns_list_add_to_start(&handle->grs->resource_root_list, res); 00922 // ++handle->grs->resource_root_count; 00923 00924 // hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00925 // memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00926 // hdr->msg_code = COAP_MSG_CODE_REQUEST_DELETE; 00927 // hdr->msg_type = COAP_MSG_TYPE_RESET; 00928 // hdr->uri_path_ptr = (uint8_t*)malloc(2); 00929 // hdr->uri_path_ptr[0] = 'a'; 00930 // hdr->uri_path_ptr[1] = '\0'; 00931 // hdr->uri_path_len = 1; 00932 // hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00933 // hdr->payload_ptr = (uint8_t*)malloc(2); 00934 // hdr->payload_len = 2; 00935 // hdr->content_format = 1; 00936 // 00937 00938 // if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 00939 // return false; 00940 // } 00941 00942 //*********************************************** 00943 // Test below if clause -> 00944 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00945 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00946 hdr->msg_code = 999; 00947 hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; 00948 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00949 hdr->uri_path_ptr[0] = 'a'; 00950 hdr->uri_path_ptr[1] = '\0'; 00951 hdr->uri_path_len = 1; 00952 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00953 hdr->payload_ptr = (uint8_t*)malloc(2); 00954 hdr->payload_len = 2; 00955 hdr->content_format = 1; 00956 00957 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00958 return false; 00959 } 00960 00961 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00962 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00963 hdr->msg_code = COAP_MSG_CODE_EMPTY; 00964 hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; 00965 hdr->uri_path_ptr = (uint8_t*)malloc(2); 00966 hdr->uri_path_ptr[0] = 'a'; 00967 hdr->uri_path_ptr[1] = '\0'; 00968 hdr->uri_path_len = 1; 00969 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 00970 hdr->payload_ptr = (uint8_t*)malloc(2); 00971 hdr->payload_len = 2; 00972 hdr->content_format = 1; 00973 00974 hdr->token_ptr = (uint8_t*)malloc(1); 00975 hdr->token_len = 1; 00976 00977 retCounter = 1; 00978 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 00979 return false; 00980 } 00981 00982 res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 00983 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 00984 res->path = (uint8_t*)malloc(2); 00985 res->pathlen = 1; 00986 res->path[0] = 'a'; 00987 res->path[1] = '\0'; 00988 res->mode = SN_GRS_STATIC; 00989 res->sn_grs_dyn_res_callback = &myResCallback; 00990 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 00991 res->access = SN_GRS_GET_ALLOWED; 00992 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 00993 res->resource_parameters_ptr->coap_content_type = 1; 00994 ns_list_add_to_start(&handle->grs->resource_root_list, res); 00995 ++handle->grs->resource_root_count; 00996 00997 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 00998 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 00999 hdr->msg_code = 999; 01000 hdr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE; 01001 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01002 hdr->uri_path_ptr[0] = 'a'; 01003 hdr->uri_path_ptr[1] = '\0'; 01004 hdr->uri_path_len = 1; 01005 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01006 hdr->payload_ptr = (uint8_t*)malloc(2); 01007 hdr->payload_len = 2; 01008 hdr->content_format = 1; 01009 01010 hdr->token_ptr = (uint8_t*)malloc(1); 01011 hdr->token_len = 1; 01012 01013 retCounter = 1; 01014 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 01015 return false; 01016 } 01017 01018 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01019 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01020 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 01021 hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; 01022 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01023 hdr->uri_path_ptr[0] = 'a'; 01024 hdr->uri_path_ptr[1] = '\0'; 01025 hdr->uri_path_len = 1; 01026 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01027 hdr->payload_ptr = (uint8_t*)malloc(2); 01028 hdr->payload_len = 2; 01029 hdr->content_format = 1; 01030 01031 hdr->token_ptr = (uint8_t*)malloc(1); 01032 hdr->token_len = 1; 01033 01034 retCounter = 3; 01035 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 01036 return false; 01037 } 01038 01039 res->resource = (uint8_t*)malloc(2); 01040 res->resourcelen = 2; 01041 01042 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01043 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01044 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 01045 hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; 01046 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01047 hdr->uri_path_ptr[0] = 'a'; 01048 hdr->uri_path_ptr[1] = '\0'; 01049 hdr->uri_path_len = 1; 01050 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01051 hdr->payload_ptr = (uint8_t*)malloc(2); 01052 hdr->payload_len = 2; 01053 hdr->content_format = 1; 01054 hdr->token_ptr = (uint8_t*)malloc(1); 01055 hdr->token_len = 1; 01056 01057 retCounter = 2; 01058 if( SN_NSDL_FAILURE != sn_grs_process_coap(handle, hdr, addr) ){ 01059 return false; 01060 } 01061 01062 hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01063 memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01064 hdr->msg_code = COAP_MSG_CODE_REQUEST_GET; 01065 hdr->msg_type = COAP_MSG_TYPE_CONFIRMABLE; 01066 hdr->uri_path_ptr = (uint8_t*)malloc(2); 01067 hdr->uri_path_ptr[0] = 'a'; 01068 hdr->uri_path_ptr[1] = '\0'; 01069 hdr->uri_path_len = 1; 01070 hdr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED; 01071 hdr->payload_ptr = (uint8_t*)malloc(2); 01072 hdr->payload_len = 2; 01073 hdr->content_format = 1; 01074 01075 hdr->token_ptr = (uint8_t*)malloc(1); 01076 hdr->token_len = 1; 01077 01078 retCounter = 6; 01079 if( SN_NSDL_SUCCESS != sn_grs_process_coap(handle, hdr, addr) ){ 01080 return false; 01081 } 01082 01083 01084 free(sn_coap_protocol_stub.expectedCoap); 01085 sn_coap_protocol_stub.expectedCoap = NULL; 01086 free(addr); 01087 sn_grs_destroy(handle->grs); 01088 free(handle); 01089 return true; 01090 } 01091 01092 bool test_sn_grs_send_coap_message() 01093 { 01094 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(NULL, NULL, NULL) ){ 01095 return false; 01096 } 01097 sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); 01098 memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); 01099 01100 struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 01101 memset(handle, 0, sizeof(struct nsdl_s)); 01102 01103 retCounter = 1; 01104 struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 01105 01106 handle->grs = grs; 01107 01108 // sn_coap_hdr_s* hdr = (sn_coap_hdr_s*)malloc(sizeof(sn_coap_hdr_s)); 01109 // memset(hdr, 0, sizeof(sn_coap_hdr_s)); 01110 01111 // sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); 01112 // memset(addr, 0, sizeof(sn_nsdl_addr_s)); 01113 01114 sn_coap_builder_stub.expectedUint16 = 2; 01115 01116 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01117 return false; 01118 } 01119 01120 retCounter = 1; 01121 sn_coap_protocol_stub.expectedInt16 = -1; 01122 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01123 return false; 01124 } 01125 01126 retCounter = 1; 01127 sn_coap_protocol_stub.expectedInt16 = 2; 01128 if( SN_NSDL_FAILURE != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01129 return false; 01130 } 01131 01132 retValUint8 = 1; 01133 retCounter = 1; 01134 sn_coap_protocol_stub.expectedInt16 = 2; 01135 if( SN_NSDL_SUCCESS != sn_grs_send_coap_message(handle, NULL, NULL) ){ 01136 return false; 01137 } 01138 free(sn_coap_protocol_stub.expectedCoap); 01139 sn_coap_protocol_stub.expectedCoap = NULL; 01140 sn_grs_destroy(handle->grs); 01141 free(handle); 01142 return true; 01143 } 01144 01145 01146 bool test_sn_grs_search_resource() 01147 { 01148 if( NULL != sn_grs_search_resource(NULL, 0, NULL, 0) ){ 01149 return false; 01150 } 01151 struct grs_s* handle = (struct grs_s*)malloc(sizeof(struct grs_s)); 01152 memset(handle, 0, sizeof(struct grs_s)); 01153 handle->sn_grs_alloc = myMalloc; 01154 handle->sn_grs_free = myFree; 01155 01156 uint8_t* path = (uint8_t*)malloc(6); 01157 path[0] = '/'; 01158 path[1] = 'a'; 01159 path[2] = 'b'; 01160 path[3] = 'c'; 01161 path[4] = '/'; 01162 if( NULL != sn_grs_search_resource(handle, 5, path, SN_GRS_SEARCH_METHOD) ){ 01163 return false; 01164 } 01165 01166 handle->resource_root_count = 0; 01167 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01168 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 01169 res->path = (uint8_t*)malloc(4); 01170 res->path[0] = 'a'; 01171 res->path[1] = 'b'; 01172 res->path[2] = 'c'; 01173 res->pathlen = 3; 01174 ns_list_add_to_start(&handle->resource_root_list, res); 01175 ++handle->resource_root_count; 01176 01177 if( NULL == sn_grs_search_resource(handle, 5, path, SN_GRS_SEARCH_METHOD) ){ 01178 return false; 01179 } 01180 01181 res->path[3] = '/'; 01182 res->pathlen = 4; 01183 01184 if( NULL == sn_grs_search_resource(handle, 5, path, SN_GRS_DELETE_METHOD) ){ 01185 return false; 01186 } 01187 01188 free(path); 01189 sn_grs_destroy(handle); 01190 return true; 01191 } 01192 01193 bool test_sn_grs_mark_resources_as_registered() 01194 { 01195 sn_grs_mark_resources_as_registered(NULL); 01196 01197 struct nsdl_s* handle = (struct nsdl_s*)malloc(sizeof(struct nsdl_s)); 01198 memset(handle, 0, sizeof(struct nsdl_s)); 01199 01200 retCounter = 1; 01201 struct grs_s* grs = sn_grs_init(&myTxCallback, &myRxCallback, &myMalloc, &myFree); 01202 handle->grs = grs; 01203 01204 sn_nsdl_resource_info_s* res = (sn_nsdl_resource_info_s*)malloc(sizeof(sn_nsdl_resource_info_s)); 01205 memset(res, 0, sizeof(sn_nsdl_resource_info_s)); 01206 res->path = (uint8_t*)malloc(2); 01207 res->pathlen = 1; 01208 res->path[0] = 'a'; 01209 res->path[1] = '\0'; 01210 res->mode = SN_GRS_DYNAMIC; 01211 res->sn_grs_dyn_res_callback = &myResCallback; 01212 res->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)malloc(sizeof(sn_nsdl_resource_parameters_s)); 01213 memset(res->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); 01214 res->resource_parameters_ptr->registered = SN_NDSL_RESOURCE_REGISTERING; 01215 ns_list_add_to_start(&handle->grs->resource_root_list, res); 01216 ++handle->grs->resource_root_count; 01217 01218 sn_grs_mark_resources_as_registered(handle); 01219 if( SN_NDSL_RESOURCE_REGISTERED != res->resource_parameters_ptr->registered ){ 01220 return false; 01221 } 01222 01223 sn_grs_destroy(handle->grs); 01224 free(handle); 01225 return true; 01226 } 01227
Generated on Tue Jul 12 2022 11:02:55 by
