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_m2mconnectionsecurity_mbedtls.cpp
00001 /* 00002 * Copyright (c) 2015 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_m2mconnectionsecurity_mbedtls.h" 00018 #include "m2mtimerobserver.h" 00019 #include "m2msecurity.h" 00020 #include "m2msecurity_stub.h" 00021 #include "mbedtls_stub.h" 00022 #include "m2mconnectionhandler.h" 00023 #include "mbed-client-mbed-os/m2mconnectionhandlerpimpl.h" 00024 #include "m2mconnectionsecuritypimpl_stub.h" 00025 00026 entropy_cb ent_cb; 00027 00028 class TestObserver : public M2MConnectionObserver { 00029 00030 public: 00031 TestObserver(){} 00032 void data_available(uint8_t*, 00033 uint16_t, 00034 const M2MConnectionObserver::SocketAddress &){} 00035 00036 void socket_error(uint8_t error_code){} 00037 00038 void address_ready(const M2MConnectionObserver::SocketAddress &, 00039 M2MConnectionObserver::ServerType, 00040 const uint16_t){} 00041 00042 void data_sent(){} 00043 }; 00044 00045 Test_M2MConnectionSecurity::Test_M2MConnectionSecurity() 00046 { 00047 mbedtls_stub::clear(); 00048 m2msecurity_stub::clear(); 00049 } 00050 00051 Test_M2MConnectionSecurity::~Test_M2MConnectionSecurity() 00052 { 00053 } 00054 00055 void Test_M2MConnectionSecurity::test_constructor() 00056 { 00057 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00058 } 00059 00060 void Test_M2MConnectionSecurity::test_destructor() 00061 { 00062 M2MConnectionSecurity* impl = new M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00063 delete impl; 00064 //Memory leak detector will report an error if leaks 00065 } 00066 00067 void Test_M2MConnectionSecurity::test_reset() 00068 { 00069 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00070 impl.reset(); 00071 } 00072 00073 void Test_M2MConnectionSecurity::test_init() 00074 { 00075 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00076 m2mconnectionsecuritypimpl_stub::int_value = 7; 00077 CHECK( 7 == impl.init(NULL) ); 00078 } 00079 00080 void Test_M2MConnectionSecurity::test_connect() 00081 { 00082 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00083 m2mconnectionsecuritypimpl_stub::int_value = 7; 00084 CHECK( 7 == impl.connect(NULL)); 00085 } 00086 00087 void Test_M2MConnectionSecurity::test_start_connecting_non_blocking() 00088 { 00089 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00090 m2mconnectionsecuritypimpl_stub::int_value = 7; 00091 CHECK( 7 == impl.start_connecting_non_blocking(NULL)); 00092 } 00093 00094 void Test_M2MConnectionSecurity::test_continue_connecting() 00095 { 00096 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00097 m2mconnectionsecuritypimpl_stub::int_value = 7; 00098 CHECK( 7 == impl.continue_connecting()); 00099 } 00100 00101 void Test_M2MConnectionSecurity::test_send_message() 00102 { 00103 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00104 unsigned char msg[6] = "hello"; 00105 m2mconnectionsecuritypimpl_stub::int_value = 7; 00106 CHECK( 7 == impl.send_message(msg, 5) ); 00107 } 00108 00109 void Test_M2MConnectionSecurity::test_read() 00110 00111 { 00112 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00113 unsigned char msg[50]; 00114 m2mconnectionsecuritypimpl_stub::int_value = 7; 00115 CHECK( 7 == impl.read(msg, 49)); 00116 } 00117 00118 void Test_M2MConnectionSecurity::test_set_random_number_callback() 00119 { 00120 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00121 random_number_cb cb(&test_random_callback); 00122 impl.set_random_number_callback(cb); 00123 00124 } 00125 00126 void Test_M2MConnectionSecurity::test_set_entropy_callback() 00127 { 00128 M2MConnectionSecurity impl = M2MConnectionSecurity(M2MConnectionSecurity::TLS); 00129 impl.set_entropy_callback(ent_cb); 00130 } 00131 00132 uint32_t test_random_callback(void) 00133 { 00134 return 1; 00135 }
Generated on Tue Jul 12 2022 12:28:53 by
