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: TYBLE16_simple_data_logger TYBLE16_MP3_Air
test_coap_service_api.c
00001 /* 00002 * Copyright (c) 2015-2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include "test_coap_service_api.h" 00018 #include <string.h> 00019 #include "coap_service_api.h" 00020 #include "nsdynmemLIB_stub.h" 00021 #include "coap_connection_handler_stub.h" 00022 #include "coap_message_handler_stub.h" 00023 #include "eventOS_event_stub.h" 00024 #include "eventOS_event.h" 00025 #include "net_interface.h" 00026 #include "coap_service_api.c" 00027 00028 int sec_done_cb_test(int8_t service_id, uint8_t address[static 16], uint8_t keyblock[static 40]) 00029 { 00030 return 2; 00031 } 00032 00033 int sec_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t *pw, uint8_t *pw_len) 00034 { 00035 return 0; 00036 } 00037 00038 int request_recv_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *request_ptr) 00039 { 00040 return 2; 00041 } 00042 00043 int virtual_sock_send_cb(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port, const uint8_t *data_ptr, uint16_t data_len) 00044 { 00045 return 2; 00046 } 00047 00048 int msg_prevalidate_cb(int8_t interface_id, uint8_t address[static 16]) 00049 { 00050 return 1; 00051 } 00052 00053 bool test_coap_service_initialize() 00054 { 00055 if (-1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00056 return false; 00057 } 00058 00059 00060 nsdynmemlib_stub.returnCounter = 1; 00061 thread_conn_handler_stub.handler_obj = NULL; 00062 if (-1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00063 return false; 00064 } 00065 00066 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00067 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00068 coap_message_handler_stub.coap_ptr = NULL; 00069 00070 nsdynmemlib_stub.returnCounter = 1; 00071 thread_conn_handler_stub.int_value = -1; 00072 if (-1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00073 return false; 00074 } 00075 00076 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00077 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00078 nsdynmemlib_stub.returnCounter = 1; 00079 thread_conn_handler_stub.int_value = 0; 00080 00081 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00082 return false; 00083 } 00084 00085 nsdynmemlib_stub.returnCounter = 1; 00086 if (2 != coap_service_initialize(3, 4, 0, NULL, NULL)) { 00087 return false; 00088 } 00089 00090 coap_service_delete(2); 00091 coap_service_delete(1); 00092 00093 free(thread_conn_handler_stub.handler_obj); 00094 thread_conn_handler_stub.handler_obj = NULL; 00095 return true; 00096 } 00097 00098 bool test_coap_service_delete() 00099 { 00100 coap_service_delete(1); 00101 00102 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00103 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00104 nsdynmemlib_stub.returnCounter = 1; 00105 coap_message_handler_stub.coap_ptr = NULL; 00106 00107 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00108 return false; 00109 } 00110 00111 coap_service_delete(1); 00112 00113 free(thread_conn_handler_stub.handler_obj); 00114 thread_conn_handler_stub.handler_obj = NULL; 00115 00116 return true; 00117 } 00118 00119 bool test_coap_service_virtual_socket_recv() 00120 { 00121 uint8_t buf[16]; 00122 if (-1 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0)) { 00123 return false; 00124 } 00125 00126 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00127 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00128 nsdynmemlib_stub.returnCounter = 1; 00129 coap_message_handler_stub.coap_ptr = NULL; 00130 00131 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00132 return false; 00133 } 00134 00135 thread_conn_handler_stub.int_value = 5; 00136 if (5 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0)) { 00137 return false; 00138 } 00139 00140 coap_service_delete(1); 00141 00142 free(thread_conn_handler_stub.handler_obj); 00143 thread_conn_handler_stub.handler_obj = NULL; 00144 00145 thread_conn_handler_stub.int_value = 0; 00146 00147 return true; 00148 } 00149 00150 bool test_coap_service_virtual_socket_set_cb() 00151 { 00152 if (-1 != coap_service_virtual_socket_set_cb(1, NULL)) { 00153 return false; 00154 } 00155 00156 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00157 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00158 nsdynmemlib_stub.returnCounter = 1; 00159 coap_message_handler_stub.coap_ptr = NULL; 00160 00161 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00162 return false; 00163 } 00164 00165 if (0 != coap_service_virtual_socket_set_cb(1, NULL)) { 00166 return false; 00167 } 00168 00169 coap_service_delete(1); 00170 00171 free(thread_conn_handler_stub.handler_obj); 00172 thread_conn_handler_stub.handler_obj = NULL; 00173 00174 return true; 00175 } 00176 00177 bool test_coap_service_register_uri() 00178 { 00179 if (-1 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) { 00180 return false; 00181 } 00182 00183 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00184 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00185 nsdynmemlib_stub.returnCounter = 1; 00186 coap_message_handler_stub.coap_ptr = NULL; 00187 00188 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00189 return false; 00190 } 00191 00192 if (-2 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) { 00193 return false; 00194 } 00195 00196 nsdynmemlib_stub.returnCounter = 1; 00197 if (-2 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) { 00198 return false; 00199 } 00200 00201 nsdynmemlib_stub.returnCounter = 2; 00202 if (0 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) { 00203 return false; 00204 } 00205 00206 coap_service_delete(1); 00207 00208 free(thread_conn_handler_stub.handler_obj); 00209 thread_conn_handler_stub.handler_obj = NULL; 00210 00211 return true; 00212 } 00213 00214 bool test_coap_service_unregister_uri() 00215 { 00216 if (-1 != coap_service_unregister_uri(1, "as")) { 00217 return false; 00218 } 00219 00220 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00221 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00222 nsdynmemlib_stub.returnCounter = 1; 00223 coap_message_handler_stub.coap_ptr = NULL; 00224 thread_conn_handler_stub.int_value = 0; 00225 00226 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00227 return false; 00228 } 00229 00230 nsdynmemlib_stub.returnCounter = 2; 00231 if (0 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) { 00232 return false; 00233 } 00234 00235 if (-2 != coap_service_unregister_uri(1, "ts")) { 00236 return false; 00237 } 00238 00239 if (0 != coap_service_unregister_uri(1, "as")) { 00240 return false; 00241 } 00242 00243 coap_service_delete(1); 00244 00245 free(thread_conn_handler_stub.handler_obj); 00246 thread_conn_handler_stub.handler_obj = NULL; 00247 00248 return true; 00249 } 00250 00251 bool test_coap_service_request_send() 00252 { 00253 uint8_t buf[16]; 00254 coap_message_handler_stub.uint16_value = 6; 00255 if (6 != coap_service_request_send(0, 0, &buf, 0, 0, 0, NULL, 0, NULL, 0, NULL)) { 00256 return false; 00257 } 00258 return true; 00259 } 00260 00261 bool test_coap_service_request_delete() 00262 { 00263 if (0 != coap_service_request_delete(NULL, 0)) { 00264 return false; 00265 } 00266 return true; 00267 } 00268 00269 bool test_coap_service_request_delete_by_service_id() 00270 { 00271 coap_service_request_delete_by_service_id(0); 00272 return true; 00273 } 00274 00275 bool test_coap_service_response_send() 00276 { 00277 uint8_t buf[16]; 00278 coap_message_handler_stub.int8_value = 6; 00279 if (6 != coap_service_response_send(0, 0, NULL, 65, 0, NULL, 0)) { 00280 return false; 00281 } 00282 return true; 00283 } 00284 00285 bool test_coap_callbacks() 00286 { 00287 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00288 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00289 nsdynmemlib_stub.returnCounter = 1; 00290 coap_message_handler_stub.coap_ptr = (coap_msg_handler_t *)malloc(sizeof(coap_msg_handler_t)); 00291 memset(coap_message_handler_stub.coap_ptr, 0, sizeof(coap_msg_handler_t)); 00292 00293 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00294 return false; 00295 } 00296 00297 if (0 != coap_message_handler_stub.coap_ptr->sn_coap_service_malloc(0)) { 00298 return false; 00299 } 00300 00301 nsdynmemlib_stub.returnCounter = 1; 00302 void *handle = coap_message_handler_stub.coap_ptr->sn_coap_service_malloc(5); 00303 if (0 == handle) { 00304 return false; 00305 } 00306 00307 coap_message_handler_stub.coap_ptr->sn_coap_service_free(handle); 00308 00309 //coap_tx_function 00310 uint8_t data[14]; 00311 memset(&data, 3, 14); 00312 sn_nsdl_addr_s addr; 00313 addr.addr_len = 2; 00314 addr.port = 4; 00315 addr.addr_ptr = &data; 00316 if (0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(NULL, 0, &addr, NULL)) { 00317 return false; 00318 } 00319 00320 coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t)); 00321 memset(tr, 0, sizeof(coap_transaction_t)); 00322 00323 if (0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) { 00324 return false; 00325 } 00326 00327 tr->service_id = 1; 00328 thread_conn_handler_stub.int_value = -2; 00329 if (0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) { 00330 return false; 00331 } 00332 00333 nsdynmemlib_stub.returnCounter = 1; 00334 if (0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 2, &addr, tr)) { 00335 return false; 00336 } 00337 00338 free(tr->data_ptr); 00339 free(tr); 00340 00341 coap_service_delete(1); 00342 00343 free(coap_message_handler_stub.coap_ptr); 00344 coap_message_handler_stub.coap_ptr = NULL; 00345 coap_service_handle = NULL; 00346 00347 free(thread_conn_handler_stub.handler_obj); 00348 thread_conn_handler_stub.handler_obj = NULL; 00349 00350 return true; 00351 } 00352 00353 #define COAP_TICK_TIMER 0xf1 //MUST BE SAME AS IN coap_service_api.c 00354 bool test_eventOS_callbacks() 00355 { 00356 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00357 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00358 nsdynmemlib_stub.returnCounter = 1; 00359 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00360 return false; 00361 } 00362 00363 if (eventOs_event_stub.event_ptr) { 00364 arm_event_s event; 00365 event.event_type = ARM_LIB_TASKLET_INIT_EVENT; 00366 eventOs_event_stub.event_ptr(&event); 00367 00368 event.event_type = ARM_LIB_SYSTEM_TIMER_EVENT; 00369 event.event_id = COAP_TICK_TIMER; 00370 eventOs_event_stub.event_ptr(&event); 00371 } 00372 00373 coap_service_delete(1); 00374 free(thread_conn_handler_stub.handler_obj); 00375 thread_conn_handler_stub.handler_obj = NULL; 00376 return true; 00377 } 00378 00379 bool test_conn_handler_callbacks() 00380 { 00381 uint8_t buf[16]; 00382 uint8_t local_addr[16] = {0}; 00383 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00384 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00385 nsdynmemlib_stub.returnCounter = 1; 00386 if (1 != coap_service_initialize(1, 2, COAP_SERVICE_OPTIONS_SECURE_BYPASS, &sec_start_cb, &sec_done_cb_test)) { 00387 return false; 00388 } 00389 00390 if (thread_conn_handler_stub.send_to_sock_cb) { 00391 thread_conn_handler_stub.bool_value = true; 00392 coap_service_virtual_socket_set_cb(1, &virtual_sock_send_cb); 00393 if (2 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0)) { 00394 return false; 00395 } 00396 thread_conn_handler_stub.bool_value = false; 00397 if (-1 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0)) { 00398 return false; 00399 } 00400 } 00401 00402 if (thread_conn_handler_stub.receive_from_sock_cb) { 00403 coap_message_handler_stub.int16_value = 2; 00404 if (-1 != thread_conn_handler_stub.receive_from_sock_cb(1, 2, buf, 12, NULL, NULL, 0)) { 00405 return false; 00406 } 00407 00408 nsdynmemlib_stub.returnCounter = 1; 00409 uint8_t *ptr = ns_dyn_mem_alloc(5); 00410 memset(ptr, 3, 5); 00411 nsdynmemlib_stub.returnCounter = 1; 00412 if (2 != thread_conn_handler_stub.receive_from_sock_cb(1, 2, buf, 12, NULL, ptr, 5)) { 00413 return false; 00414 } 00415 ns_dyn_mem_free(ptr); 00416 coap_message_handler_stub.int16_value = 0; 00417 00418 //This could be moved to own test function, 00419 //but thread_conn_handler_stub.receive_from_sock_cb must be called successfully 00420 if (coap_message_handler_stub.msg_process_cb) { 00421 if (-1 != coap_message_handler_stub.msg_process_cb(1, 1, NULL, NULL, local_addr)) { 00422 return false; 00423 } 00424 00425 sn_coap_hdr_s *coap = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 00426 memset(coap, 0, sizeof(sn_coap_hdr_s)); 00427 00428 uint8_t uri[2] = "as"; 00429 coap->uri_path_ptr = &uri; 00430 coap->uri_path_len = 2; 00431 00432 if (-1 != coap_message_handler_stub.msg_process_cb(1, 1, coap, NULL, local_addr)) { 00433 return false; 00434 } 00435 00436 thread_conn_handler_stub.bool_value = true; 00437 nsdynmemlib_stub.returnCounter = 2; 00438 if (0 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) { 00439 return false; 00440 } 00441 00442 if (-1 != coap_message_handler_stub.msg_process_cb(1, 1, coap, NULL, local_addr)) { 00443 return false; 00444 } 00445 00446 coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t)); 00447 memset(tr, 0, sizeof(coap_transaction_t)); 00448 tr->local_address[0] = 2; 00449 00450 if (0 != coap_service_msg_prevalidate_callback_set(2, msg_prevalidate_cb)) { 00451 return false; 00452 } 00453 00454 if (-1 != coap_message_handler_stub.msg_process_cb(1, 1, coap, tr, local_addr)) { 00455 return false; 00456 } 00457 00458 if (0 != coap_service_msg_prevalidate_callback_set(2, NULL)) { 00459 return false; 00460 } 00461 00462 if (2 != coap_message_handler_stub.msg_process_cb(1, 1, coap, tr, local_addr)) { 00463 return false; 00464 } 00465 00466 free(tr); 00467 tr = NULL; 00468 00469 thread_conn_handler_stub.bool_value = false; 00470 free(coap); 00471 coap = NULL; 00472 } 00473 } 00474 00475 if (thread_conn_handler_stub.get_passwd_cb) { 00476 coap_security_keys_t security_ptr; 00477 memset(&security_ptr, 0, sizeof(coap_security_keys_t)); 00478 nsdynmemlib_stub.returnCounter = 1; 00479 thread_conn_handler_stub.bool_value = true; 00480 if (0 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, &security_ptr)) { 00481 return false; 00482 } 00483 free(security_ptr._key); 00484 thread_conn_handler_stub.bool_value = false; 00485 if (-1 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, NULL)) { 00486 return false; 00487 } 00488 } 00489 00490 if (thread_conn_handler_stub.sec_done_cb) { 00491 uint8_t block[40]; 00492 thread_conn_handler_stub.bool_value = true; 00493 00494 coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t)); 00495 memset(tr, 0, sizeof(coap_transaction_t)); 00496 nsdynmemlib_stub.returnCounter = 1; 00497 tr->data_ptr = ns_dyn_mem_alloc(1); 00498 tr->data_len = 1; 00499 coap_message_handler_stub.coap_tx_ptr = tr; 00500 00501 thread_conn_handler_stub.sec_done_cb(1, buf, 12, block); 00502 00503 free(tr); 00504 coap_message_handler_stub.coap_tx_ptr = NULL; 00505 00506 thread_conn_handler_stub.bool_value = false; 00507 00508 } 00509 00510 coap_service_delete(1); 00511 free(thread_conn_handler_stub.handler_obj); 00512 thread_conn_handler_stub.handler_obj = NULL; 00513 00514 return true; 00515 } 00516 00517 bool test_certificate_set() 00518 { 00519 /* Service not found, return failure */ 00520 if (-1 != coap_service_certificate_set(1, NULL, 0, NULL, 0)) { 00521 return false; 00522 } 00523 00524 /* Init service */ 00525 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00526 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00527 00528 nsdynmemlib_stub.returnCounter = 1; 00529 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00530 return false; 00531 } 00532 00533 /* Allocation fails */ 00534 if (-1 != coap_service_certificate_set(1, NULL, 0, NULL, 0)) { 00535 return false; 00536 } 00537 00538 /* All OK */ 00539 nsdynmemlib_stub.returnCounter = 1; 00540 if (0 != coap_service_certificate_set(1, NULL, 0, NULL, 0)) { 00541 return false; 00542 } 00543 00544 /* Teardown */ 00545 coap_service_delete(1); 00546 free(thread_conn_handler_stub.handler_obj->security_keys); 00547 free(thread_conn_handler_stub.handler_obj); 00548 00549 return true; 00550 } 00551 00552 bool test_handshake_timeout_set() 00553 { 00554 /* Service not found, return failure */ 00555 if (-1 != coap_service_set_handshake_timeout(1, 0, 0)) { 00556 return false; 00557 } 00558 00559 /* Init service */ 00560 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00561 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00562 00563 nsdynmemlib_stub.returnCounter = 1; 00564 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00565 return false; 00566 } 00567 00568 /* All OK */ 00569 nsdynmemlib_stub.returnCounter = 1; 00570 if (0 != coap_service_set_handshake_timeout(1, 0, 0)) { 00571 return false; 00572 } 00573 00574 /* Teardown */ 00575 coap_service_delete(1); 00576 free(thread_conn_handler_stub.handler_obj->security_keys); 00577 free(thread_conn_handler_stub.handler_obj); 00578 00579 return true; 00580 } 00581 00582 bool test_coap_duplcate_msg_buffer_set() 00583 { 00584 bool ret = true; 00585 /* no coap handle - return failure */ 00586 if (-1 != coap_service_set_duplicate_message_buffer(0, 0)) { 00587 return false; 00588 } 00589 00590 /* Init service */ 00591 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00592 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00593 coap_message_handler_stub.coap_ptr = (coap_msg_handler_t *)malloc(sizeof(coap_msg_handler_t)); 00594 memset(coap_message_handler_stub.coap_ptr, 0, sizeof(coap_msg_handler_t)); 00595 00596 nsdynmemlib_stub.returnCounter = 1; 00597 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00598 ret = false; 00599 } 00600 00601 /* All OK */ 00602 if (0 != coap_service_set_duplicate_message_buffer(0, 0)) { 00603 ret = false; 00604 } 00605 00606 /* Teardown */ 00607 coap_service_delete(1); 00608 free(coap_message_handler_stub.coap_ptr); 00609 coap_message_handler_stub.coap_ptr = NULL; 00610 coap_service_handle = NULL; 00611 free(thread_conn_handler_stub.handler_obj); 00612 thread_conn_handler_stub.handler_obj = NULL; 00613 00614 return ret; 00615 } 00616 00617 bool test_coap_service_get_internal_timer_ticks() 00618 { 00619 coap_service_get_internal_timer_ticks(); 00620 return true; 00621 } 00622 00623 bool test_coap_service_if_find_by_socket() 00624 { 00625 /* No service ID - return failure */ 00626 if (0 != coap_service_id_find_by_socket(1)) { 00627 return false; 00628 } 00629 00630 /* Init service */ 00631 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00632 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00633 00634 nsdynmemlib_stub.returnCounter = 1; 00635 thread_conn_handler_stub.bool_value = 0; 00636 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00637 return false; 00638 } 00639 00640 /* No matching service ID - return false */ 00641 if (0 != coap_service_id_find_by_socket(1)) { 00642 return false; 00643 } 00644 00645 thread_conn_handler_stub.bool_value = 1; 00646 /* All OK */ 00647 if (1 != coap_service_id_find_by_socket(1)) { 00648 return false; 00649 } 00650 00651 /* Teardown */ 00652 coap_service_delete(1); 00653 free(thread_conn_handler_stub.handler_obj); 00654 thread_conn_handler_stub.handler_obj = NULL; 00655 00656 return true; 00657 } 00658 00659 bool test_coap_service_handshake_limit_set() 00660 { 00661 if (0 != coap_service_handshake_limits_set(2, 2)) { 00662 return false; 00663 } 00664 00665 return true; 00666 } 00667 00668 bool test_coap_service_msg_prevalidate_cb_read_and_set() 00669 { 00670 /* No valid socket port - return failure */ 00671 if (0 == coap_service_msg_prevalidate_callback_set(99, msg_prevalidate_cb)) { 00672 return false; 00673 } 00674 00675 /* Init service */ 00676 thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t)); 00677 memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t)); 00678 00679 nsdynmemlib_stub.returnCounter = 1; 00680 thread_conn_handler_stub.bool_value = 0; 00681 if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) { 00682 return false; 00683 } 00684 00685 if (0 != coap_service_msg_prevalidate_callback_set(2, msg_prevalidate_cb)) { 00686 return false; 00687 } 00688 00689 if (0 != coap_service_msg_prevalidate_callback_set(2, NULL)) { 00690 return false; 00691 } 00692 00693 /* Teardown */ 00694 coap_service_delete(1); 00695 free(thread_conn_handler_stub.handler_obj); 00696 thread_conn_handler_stub.handler_obj = NULL; 00697 00698 return true; 00699 }
Generated on Tue Jul 12 2022 13:54:55 by
1.7.2