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.
test_m2mconnectionhandlerpimpl_classic.cpp
00001 /* 00002 * Copyright (c) 2016 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "CppUTest/TestHarness.h" 00017 #include "test_m2mconnectionhandlerpimpl_classic.h" 00018 #include "mbed-client-classic/m2mconnectionhandlerpimpl.h" 00019 #include "mbed-client/m2mconnectionhandler.h" 00020 #include "m2mconnectionobserver.h" 00021 #include "m2msecurity.h" 00022 #include "m2mconnectionsecurity_stub.h" 00023 #include "m2msecurity_stub.h" 00024 #include "eventOS_stub.h" 00025 #include "pal_network_stub.h" 00026 #include "eventOS_event.h" 00027 #include <limits.h> 00028 00029 class M2MConnection_TestObserver : public M2MConnectionObserver { 00030 00031 public: 00032 M2MConnection_TestObserver(): 00033 obj(NULL){} 00034 00035 virtual ~M2MConnection_TestObserver(){} 00036 00037 void set_class_object(M2MConnectionHandlerPimpl *impl) {obj = impl;} 00038 void data_available(uint8_t*, 00039 uint16_t, 00040 const M2MConnectionObserver::SocketAddress &){ 00041 dataAvailable = true; 00042 if(obj) { 00043 //obj->_receive_data = false; 00044 } 00045 00046 } 00047 00048 void socket_error(uint8_t error_code, bool retry){error = true;} 00049 00050 void address_ready(const M2MConnectionObserver::SocketAddress &, 00051 M2MConnectionObserver::ServerType, 00052 const uint16_t){addressReady = true;} 00053 00054 void data_sent(){dataSent = true;} 00055 00056 bool dataAvailable; 00057 bool error; 00058 bool addressReady; 00059 bool dataSent; 00060 M2MSecurity* sec; 00061 00062 M2MConnectionHandlerPimpl *obj; 00063 00064 }; 00065 00066 Test_M2MConnectionHandlerPimpl_classic::Test_M2MConnectionHandlerPimpl_classic() 00067 { 00068 observer = new M2MConnection_TestObserver(); 00069 m2mconnectionsecurityimpl_stub::clear(); 00070 pal_network_stub::void_value = NULL; 00071 pal_network_stub::change_status_count = 0; 00072 00073 handler = new M2MConnectionHandlerPimpl(NULL, *observer, NULL , M2MInterface::NOT_SET, M2MInterface::Uninitialized); 00074 00075 sec = new M2MSecurity(M2MSecurity::M2MServer); 00076 M2MConnectionSecurity* sec1 = new M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00077 M2MConnectionSecurity* sec2 = new M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00078 M2MConnectionSecurity* sec3 = new M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00079 M2MConnectionSecurity* sec4 = new M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00080 00081 udp4_unsec = new M2MConnectionHandlerPimpl(NULL, *observer, NULL , M2MInterface::UDP, M2MInterface::LwIP_IPv4); 00082 udp4_sec = new M2MConnectionHandlerPimpl(NULL, *observer, sec1 , M2MInterface::UDP, M2MInterface::LwIP_IPv4); 00083 tcp4_unsec = new M2MConnectionHandlerPimpl(NULL, *observer, NULL , M2MInterface::TCP, M2MInterface::LwIP_IPv4); 00084 tcp4_sec = new M2MConnectionHandlerPimpl(NULL, *observer, sec2 , M2MInterface::TCP, M2MInterface::LwIP_IPv4); 00085 udp6_unsec = new M2MConnectionHandlerPimpl(NULL, *observer, NULL , M2MInterface::UDP, M2MInterface::LwIP_IPv6); 00086 udp6_sec = new M2MConnectionHandlerPimpl(NULL, *observer, sec3 , M2MInterface::UDP, M2MInterface::LwIP_IPv6); 00087 tcp6_unsec = new M2MConnectionHandlerPimpl(NULL, *observer, NULL , M2MInterface::TCP, M2MInterface::LwIP_IPv6); 00088 tcp6_sec = new M2MConnectionHandlerPimpl(NULL, *observer, sec4 , M2MInterface::TCP, M2MInterface::LwIP_IPv6); 00089 00090 } 00091 00092 Test_M2MConnectionHandlerPimpl_classic::~Test_M2MConnectionHandlerPimpl_classic() 00093 { 00094 delete handler; 00095 delete observer; 00096 delete udp4_unsec; 00097 delete tcp4_unsec; 00098 delete udp6_unsec; 00099 delete tcp6_unsec; 00100 delete udp4_sec; 00101 delete tcp4_sec; 00102 delete udp6_sec; 00103 delete tcp6_sec; 00104 delete sec; 00105 } 00106 00107 void Test_M2MConnectionHandlerPimpl_classic::test_bind_connection() 00108 { 00109 CHECK( handler->bind_connection(7) == true); 00110 } 00111 00112 void Test_M2MConnectionHandlerPimpl_classic::test_resolve_server_address() 00113 { 00114 00115 eventOS_stub::int8_value = 1; 00116 CHECK(handler->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL) == false); 00117 eventOS_stub::int8_value = 0; 00118 CHECK(handler->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL) == true); 00119 00120 } 00121 00122 void Test_M2MConnectionHandlerPimpl_classic::test_dns_handler() 00123 { 00124 00125 pal_network_stub::status = PAL_SUCCESS; 00126 observer->addressReady = false; 00127 pal_network_stub::uint32_value = 1; 00128 00129 udp4_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00130 udp4_unsec->dns_handler(); 00131 CHECK(observer->addressReady == true); 00132 00133 observer->addressReady = false; 00134 udp6_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00135 udp6_unsec->dns_handler(); 00136 CHECK(observer->addressReady == true); 00137 00138 observer->addressReady = false; 00139 tcp4_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00140 tcp4_unsec->dns_handler(); 00141 CHECK(observer->addressReady == true); 00142 00143 observer->addressReady = false; 00144 tcp6_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00145 tcp6_unsec->dns_handler(); 00146 CHECK(observer->addressReady == true); 00147 00148 observer->addressReady = false; 00149 m2msecurity_stub::int_value = M2MSecurity::Psk; 00150 m2mconnectionsecurityimpl_stub::use_inc_int = true; 00151 m2mconnectionsecurityimpl_stub::inc_int_value = 0; 00152 udp4_sec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, sec); 00153 udp4_sec->dns_handler(); 00154 CHECK(observer->addressReady == false); 00155 CHECK(udp4_sec->is_handshake_ongoing()); 00156 00157 /* error cases */ 00158 00159 observer->addressReady = false; 00160 observer->error = false; 00161 m2msecurity_stub::int_value = M2MSecurity::Psk; 00162 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00163 m2mconnectionsecurityimpl_stub::int_value = 0; 00164 m2mconnectionsecurityimpl_stub::int_value2 = -123; 00165 udp4_sec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, sec); 00166 udp4_sec->dns_handler(); 00167 CHECK(observer->error); 00168 CHECK(observer->addressReady == false); 00169 CHECK(!udp4_sec->is_handshake_ongoing()); 00170 00171 M2MConnectionSecurity *connection_security; 00172 00173 observer->error = false; 00174 observer->addressReady = false; 00175 m2msecurity_stub::int_value = M2MSecurity::Psk; 00176 connection_security = udp4_sec->_security_impl; 00177 udp4_sec->_security_impl = NULL; 00178 udp4_sec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, sec); 00179 udp4_sec->dns_handler(); 00180 CHECK(observer->addressReady == false); 00181 CHECK(observer->error); 00182 udp4_sec->_security_impl = connection_security; 00183 00184 observer->error = false; 00185 observer->addressReady = false; 00186 m2msecurity_stub::int_value = M2MSecurity::Psk; 00187 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00188 m2mconnectionsecurityimpl_stub::int_value = 1; 00189 udp4_sec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, sec); 00190 udp4_sec->dns_handler(); 00191 CHECK(observer->addressReady == false); 00192 CHECK(observer->error); 00193 00194 pal_network_stub::uint32_value = 0; 00195 00196 observer->error = false; 00197 udp4_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00198 udp4_unsec->dns_handler(); 00199 CHECK(observer->addressReady == false); 00200 CHECK(observer->error); 00201 00202 pal_network_stub::uint32_value = 1; 00203 00204 udp4_unsec->_network_stack = (M2MInterface::NetworkStack)123; 00205 udp4_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00206 udp4_unsec->dns_handler(); 00207 CHECK(observer->addressReady == false); 00208 udp4_unsec->_network_stack = M2MInterface::LwIP_IPv4; 00209 00210 observer->error = false; 00211 pal_network_stub::status = PAL_SUCCESS; 00212 pal_network_stub::new_status = PAL_ERR_GENERIC_FAILURE; 00213 pal_network_stub::change_status_count = 1; 00214 udp4_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00215 udp4_unsec->dns_handler(); 00216 CHECK(observer->addressReady == false); 00217 CHECK(observer->error); 00218 00219 observer->error = false; 00220 pal_network_stub::status = PAL_SUCCESS; 00221 pal_network_stub::new_status = PAL_ERR_GENERIC_FAILURE; 00222 pal_network_stub::change_status_count = 2; 00223 udp4_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00224 udp4_unsec->dns_handler(); 00225 CHECK(observer->addressReady == false); 00226 CHECK(observer->error); 00227 00228 observer->error = false; 00229 pal_network_stub::status = PAL_SUCCESS; 00230 pal_network_stub::new_status = PAL_ERR_GENERIC_FAILURE; 00231 pal_network_stub::change_status_count = 3; 00232 udp4_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00233 udp4_unsec->dns_handler(); 00234 CHECK(observer->addressReady == false); 00235 CHECK(observer->error); 00236 00237 observer->error = false; 00238 pal_network_stub::status = PAL_SUCCESS; 00239 pal_network_stub::new_status = PAL_ERR_GENERIC_FAILURE; 00240 pal_network_stub::change_status_count = 4; 00241 udp4_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00242 udp4_unsec->dns_handler(); 00243 CHECK(observer->addressReady == false); 00244 CHECK(observer->error); 00245 00246 observer->error = false; 00247 pal_network_stub::status = PAL_SUCCESS; 00248 pal_network_stub::new_status = PAL_ERR_GENERIC_FAILURE; 00249 pal_network_stub::change_status_count = 3; 00250 tcp6_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00251 tcp6_unsec->dns_handler(); 00252 CHECK(observer->addressReady == false); 00253 CHECK(observer->error); 00254 00255 observer->error = false; 00256 pal_network_stub::status = PAL_SUCCESS; 00257 pal_network_stub::new_status = PAL_ERR_GENERIC_FAILURE; 00258 pal_network_stub::change_status_count = 8; 00259 tcp6_unsec->resolve_server_address("1", 12345, M2MConnectionObserver::LWM2MServer, NULL); 00260 tcp6_unsec->dns_handler(); 00261 CHECK(observer->addressReady == false); 00262 CHECK(observer->error); 00263 00264 pal_network_stub::change_status_count = 0; 00265 00266 } 00267 00268 void Test_M2MConnectionHandlerPimpl_classic::test_send_data() 00269 { 00270 sn_nsdl_addr_s* addr = (sn_nsdl_addr_s*)malloc(sizeof(sn_nsdl_addr_s)); 00271 memset(addr, 0, sizeof(sn_nsdl_addr_s)); 00272 uint8_t* data = (uint8_t*)malloc(5); 00273 00274 eventOS_stub::int8_value = 0; 00275 CHECK(false == handler->send_data(data, 5 , NULL)); 00276 00277 CHECK(false == handler->send_data(data, 0 , addr)); 00278 00279 CHECK(false == handler->send_data(NULL, 5 , addr)); 00280 00281 handler->_running = false; 00282 CHECK(false == handler->send_data(data, 5 , addr)); 00283 handler->_running = true; 00284 00285 CHECK(true == handler->send_data(data, 5 , addr)); 00286 00287 eventOS_stub::int8_value = 1; 00288 CHECK(false == handler->send_data(data, 5 , addr)); 00289 00290 free(data); 00291 free(addr); 00292 } 00293 00294 void Test_M2MConnectionHandlerPimpl_classic::test_send_socket_data() 00295 { 00296 00297 uint8_t data[5] = {1}; 00298 00299 pal_network_stub::status = PAL_SUCCESS; 00300 00301 udp4_unsec->_running = true; 00302 tcp4_unsec->_running = true; 00303 udp4_sec->_running = true; 00304 tcp4_sec->_running = true; 00305 00306 observer->dataSent = false; 00307 udp4_unsec->send_socket_data(data, sizeof(data)); 00308 CHECK(observer->dataSent); 00309 00310 observer->dataSent = false; 00311 tcp4_unsec->send_socket_data(data, sizeof(data)); 00312 CHECK(observer->dataSent); 00313 00314 00315 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00316 m2mconnectionsecurityimpl_stub::int_value = 5; 00317 00318 observer->dataSent = false; 00319 tcp4_sec->_use_secure_connection = true; 00320 tcp4_sec->send_socket_data(data, sizeof(data)); 00321 CHECK(observer->dataSent); 00322 00323 pal_network_stub::status = PAL_ERR_GENERIC_FAILURE; 00324 00325 observer->dataSent = false; 00326 udp4_unsec->send_socket_data(data, sizeof(data)); 00327 CHECK(!observer->dataSent); 00328 00329 observer->dataSent = false; 00330 tcp4_unsec->send_socket_data(data, sizeof(data)); 00331 CHECK(!observer->dataSent); 00332 00333 pal_network_stub::status = PAL_SUCCESS; 00334 00335 observer->dataSent = false; 00336 tcp4_unsec->send_socket_data(NULL, sizeof(data)); 00337 CHECK(!observer->dataSent); 00338 00339 observer->dataSent = false; 00340 tcp4_unsec->send_socket_data(data, 0); 00341 CHECK(!observer->dataSent); 00342 00343 udp4_unsec->_running = false; 00344 observer->dataSent = false; 00345 udp4_unsec->send_socket_data(data, sizeof(data)); 00346 CHECK(!observer->dataSent); 00347 udp4_unsec->_running = true; 00348 00349 } 00350 00351 void Test_M2MConnectionHandlerPimpl_classic::test_start_listening_for_data() 00352 { 00353 handler->start_listening_for_data(); 00354 } 00355 00356 void Test_M2MConnectionHandlerPimpl_classic::test_receive_handler() 00357 { 00358 00359 uint8_t data[5] = {0,0,0,1,123}; 00360 pal_network_stub::size = 5; 00361 00362 udp4_unsec->_running = true; 00363 tcp4_unsec->_running = true; 00364 udp4_sec->_running = true; 00365 tcp4_sec->_running = true; 00366 00367 udp4_unsec->start_listening_for_data(); 00368 tcp4_unsec->start_listening_for_data(); 00369 00370 pal_network_stub::status = PAL_SUCCESS; 00371 pal_network_stub::new_status = PAL_ERR_SOCKET_WOULD_BLOCK; 00372 pal_network_stub::change_status_count = 1; 00373 observer->dataAvailable = false; 00374 udp4_unsec->receive_handler(); 00375 CHECK(observer->dataAvailable); 00376 00377 pal_network_stub::status = PAL_SUCCESS; 00378 pal_network_stub::new_status = PAL_ERR_SOCKET_WOULD_BLOCK; 00379 pal_network_stub::change_status_count = 1; 00380 observer->dataAvailable = false; 00381 pal_network_stub::void_value = data; 00382 tcp4_unsec->receive_handler(); 00383 CHECK(observer->dataAvailable); 00384 00385 pal_network_stub::status = PAL_ERR_GENERIC_FAILURE; 00386 observer->dataAvailable = false; 00387 observer->error = 0; 00388 udp4_unsec->receive_handler(); 00389 CHECK(!observer->dataAvailable); 00390 CHECK(observer->error); 00391 00392 pal_network_stub::status = PAL_ERR_SOCKET_WOULD_BLOCK; 00393 observer->dataAvailable = false; 00394 observer->error = 0; 00395 udp4_unsec->receive_handler(); 00396 CHECK(!observer->dataAvailable); 00397 CHECK(!observer->error); 00398 00399 pal_network_stub::status = PAL_SUCCESS; 00400 pal_network_stub::new_status = PAL_ERR_SOCKET_WOULD_BLOCK; 00401 pal_network_stub::change_status_count = 1; 00402 observer->error = 0; 00403 pal_network_stub::size = 3; 00404 observer->dataAvailable = false; 00405 pal_network_stub::void_value = data; 00406 tcp4_unsec->receive_handler(); 00407 CHECK(!observer->dataAvailable); 00408 CHECK(observer->error); 00409 00410 pal_network_stub::status = PAL_SUCCESS; 00411 pal_network_stub::new_status = PAL_ERR_SOCKET_WOULD_BLOCK; 00412 pal_network_stub::change_status_count = 1; 00413 observer->dataAvailable = false; 00414 data[3] = 2; 00415 tcp4_unsec->receive_handler(); 00416 CHECK(!observer->dataAvailable); 00417 00418 udp4_sec->_use_secure_connection = true; 00419 observer->error = 0; 00420 observer->dataAvailable = false; 00421 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00422 m2mconnectionsecurityimpl_stub::int_value = M2MConnectionHandler::CONNECTION_ERROR_WANTS_READ; 00423 udp4_sec->receive_handler(); 00424 CHECK(!observer->dataAvailable); 00425 CHECK(!observer->error); 00426 00427 udp4_sec->_use_secure_connection = true; 00428 observer->error = 0; 00429 observer->dataAvailable = false; 00430 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00431 m2mconnectionsecurityimpl_stub::int_value = (-123); 00432 udp4_sec->receive_handler(); 00433 CHECK(!observer->dataAvailable); 00434 CHECK(observer->error); 00435 00436 udp4_sec->_is_handshaking = true; 00437 observer->error = 0; 00438 observer->dataAvailable = false; 00439 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00440 m2mconnectionsecurityimpl_stub::int_value = M2MConnectionHandler::CONNECTION_ERROR_WANTS_READ; 00441 udp4_sec->receive_handler(); 00442 CHECK(!observer->dataAvailable); 00443 CHECK(!observer->error); 00444 00445 udp4_sec->_is_handshaking = false; 00446 udp4_sec->_running = true; 00447 observer->error = 0; 00448 observer->dataAvailable = false; 00449 m2mconnectionsecurityimpl_stub::use_inc_int = true; 00450 m2mconnectionsecurityimpl_stub::inc_int_value = INT_MAX; 00451 udp4_sec->receive_handler(); 00452 CHECK(observer->dataAvailable); 00453 CHECK(observer->error); 00454 00455 udp4_sec->_is_handshaking = false; 00456 udp4_sec->_listening = false; 00457 observer->error = 0; 00458 observer->dataAvailable = false; 00459 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00460 m2mconnectionsecurityimpl_stub::int_value = M2MConnectionHandler::CONNECTION_ERROR_WANTS_READ; 00461 udp4_sec->receive_handler(); 00462 CHECK(!observer->dataAvailable); 00463 CHECK(!observer->error); 00464 udp4_sec->_listening = true; 00465 00466 udp4_sec->_is_handshaking = false; 00467 udp4_sec->_running = false; 00468 observer->error = 0; 00469 observer->dataAvailable = false; 00470 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00471 m2mconnectionsecurityimpl_stub::int_value = M2MConnectionHandler::CONNECTION_ERROR_WANTS_READ; 00472 udp4_sec->receive_handler(); 00473 CHECK(!observer->dataAvailable); 00474 CHECK(!observer->error); 00475 udp4_sec->_running = true; 00476 00477 } 00478 00479 00480 void Test_M2MConnectionHandlerPimpl_classic::test_stop_listening() 00481 { 00482 handler->stop_listening(); 00483 } 00484 00485 void Test_M2MConnectionHandlerPimpl_classic::test_send_to_socket() 00486 { 00487 const char buf[] = "hello"; 00488 handler->send_to_socket((unsigned char *)&buf, 5); 00489 00490 pal_network_stub::status = PAL_SUCCESS; 00491 pal_network_stub::size = 5; 00492 00493 udp4_unsec->_running = true; 00494 tcp4_unsec->_running = true; 00495 00496 CHECK(udp4_unsec->send_to_socket((unsigned char *)&buf, 5) == 5); 00497 00498 CHECK(tcp4_unsec->send_to_socket((unsigned char *)&buf, 5) == 5); 00499 00500 udp4_unsec->_running = false; 00501 CHECK(udp4_unsec->send_to_socket((unsigned char *)&buf, 5) < 0); 00502 udp4_unsec->_running = true; 00503 00504 pal_network_stub::status = PAL_ERR_GENERIC_FAILURE; 00505 00506 CHECK(udp4_unsec->send_to_socket((unsigned char *)&buf, 5) < 0); 00507 00508 CHECK(tcp4_unsec->send_to_socket((unsigned char *)&buf, 5) < 0); 00509 00510 } 00511 00512 void Test_M2MConnectionHandlerPimpl_classic::test_receive_from_socket() 00513 { 00514 unsigned char *buf = (unsigned char *)malloc(6); 00515 00516 pal_network_stub::status = PAL_SUCCESS; 00517 pal_network_stub::size = 5; 00518 00519 udp4_unsec->_running = true; 00520 tcp4_unsec->_running = true; 00521 00522 CHECK(udp4_unsec->receive_from_socket(buf, 5) == 5); 00523 00524 CHECK(tcp4_unsec->receive_from_socket(buf, 5) == 5); 00525 00526 udp4_unsec->_running = false; 00527 CHECK(udp4_unsec->receive_from_socket(buf, 5) < 0); 00528 udp4_unsec->_running = true; 00529 00530 pal_network_stub::status = PAL_ERR_GENERIC_FAILURE; 00531 00532 CHECK(udp4_unsec->receive_from_socket(buf, 5) < 0); 00533 00534 CHECK(tcp4_unsec->receive_from_socket(buf, 5) < 0); 00535 00536 pal_network_stub::status = PAL_ERR_SOCKET_WOULD_BLOCK; 00537 00538 CHECK(udp4_unsec->receive_from_socket(buf, 5) == M2MConnectionHandler::CONNECTION_ERROR_WANTS_READ); 00539 00540 CHECK(tcp4_unsec->receive_from_socket(buf, 5) == M2MConnectionHandler::CONNECTION_ERROR_WANTS_READ); 00541 00542 free(buf); 00543 } 00544 00545 void Test_M2MConnectionHandlerPimpl_classic::test_handle_connection_error() 00546 { 00547 handler->handle_connection_error(4); 00548 CHECK(observer->error == true); 00549 } 00550 00551 extern "C" void connection_event_handler(arm_event_s *event); 00552 00553 void Test_M2MConnectionHandlerPimpl_classic::test_connection_event_handler() 00554 { 00555 arm_event_s event; 00556 00557 event.data_ptr = malloc(1); 00558 event.event_data = 1; 00559 00560 event.event_type = M2MConnectionHandlerPimpl::ESocketReadytoRead; 00561 connection_event_handler(&event); 00562 00563 event.event_type = M2MConnectionHandlerPimpl::ESocketDnsHandler; 00564 connection_event_handler(&event); 00565 00566 event.event_type = M2MConnectionHandlerPimpl::ESocketSend; 00567 connection_event_handler(&event); 00568 00569 event.event_type = 1234; 00570 connection_event_handler(&event); 00571 00572 } 00573 00574 void Test_M2MConnectionHandlerPimpl_classic::test_set_platform_network_handler() 00575 { 00576 pal_network_stub::status = PAL_SUCCESS; 00577 handler->set_platform_network_handler((void*)1); 00578 00579 pal_network_stub::status = PAL_ERR_GENERIC_FAILURE; 00580 handler->set_platform_network_handler((void*)1); 00581 } 00582 00583 void Test_M2MConnectionHandlerPimpl_classic::test_receive_handshake_handler() 00584 { 00585 00586 udp4_sec->_is_handshaking = true; 00587 observer->error = 0; 00588 observer->addressReady = 0; 00589 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00590 m2mconnectionsecurityimpl_stub::int_value = M2MConnectionHandler::CONNECTION_ERROR_WANTS_READ; 00591 udp4_sec->receive_handshake_handler(); 00592 CHECK(!observer->error); 00593 CHECK(!observer->addressReady); 00594 00595 udp4_sec->_is_handshaking = true; 00596 observer->error = 0; 00597 observer->addressReady = 0; 00598 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00599 m2mconnectionsecurityimpl_stub::int_value = 0; 00600 udp4_sec->receive_handshake_handler(); 00601 CHECK(!observer->error); 00602 CHECK(observer->addressReady); 00603 00604 udp4_sec->_is_handshaking = true; 00605 observer->error = 0; 00606 observer->addressReady = 0; 00607 m2mconnectionsecurityimpl_stub::use_inc_int = false; 00608 m2mconnectionsecurityimpl_stub::int_value = (-123); 00609 udp4_sec->receive_handshake_handler(); 00610 CHECK(observer->error); 00611 CHECK(!observer->addressReady); 00612 00613 } 00614 00615 void Test_M2MConnectionHandlerPimpl_classic::test_claim_mutex() 00616 { 00617 00618 handler->claim_mutex(); 00619 00620 } 00621 00622 void Test_M2MConnectionHandlerPimpl_classic::test_release_mutex() 00623 { 00624 00625 handler->release_mutex(); 00626 00627 } 00628 00629
Generated on Tue Jul 12 2022 21:20:29 by
