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_NetworkInterface.cpp
00001 /* 00002 * Copyright (c) 2018, 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 00018 #include "gtest/gtest.h" 00019 #include "features/netsocket/NetworkInterface.h" 00020 #include "NetworkStack_stub.h" 00021 00022 class stubNetworkInterface : public NetworkInterface { 00023 virtual nsapi_error_t connect() 00024 { 00025 return NSAPI_ERROR_OK ; 00026 }; 00027 virtual nsapi_error_t disconnect() 00028 { 00029 return NSAPI_ERROR_OK ; 00030 }; 00031 virtual NetworkStack *get_stack() 00032 { 00033 return &stack; 00034 }; 00035 public: 00036 NetworkStackstub stack; 00037 }; 00038 00039 class TestNetworkInterface : public testing::Test { 00040 protected: 00041 NetworkInterface *iface; 00042 00043 virtual void SetUp() 00044 { 00045 iface = new stubNetworkInterface(); 00046 } 00047 00048 virtual void TearDown() 00049 { 00050 delete iface; 00051 } 00052 }; 00053 00054 TEST_F(TestNetworkInterface, constructor) 00055 { 00056 EXPECT_TRUE(iface); 00057 } 00058 00059 // get_default_instance is tested along with the implementations of NetworkInterface. 00060 00061 TEST_F(TestNetworkInterface, get_mac_address) 00062 { 00063 char *n = 0; 00064 EXPECT_EQ(iface->get_mac_address(), n); 00065 } 00066 00067 TEST_F(TestNetworkInterface, get_ip_address) 00068 { 00069 char *n = 0; 00070 EXPECT_EQ(iface->get_ip_address(), n); 00071 } 00072 00073 TEST_F(TestNetworkInterface, get_netmask) 00074 { 00075 char *n = 0; 00076 EXPECT_EQ(iface->get_netmask(), n); 00077 } 00078 00079 TEST_F(TestNetworkInterface, get_gateway) 00080 { 00081 char *n = 0; 00082 EXPECT_EQ(iface->get_gateway(), n); 00083 } 00084 00085 TEST_F(TestNetworkInterface, set_network) 00086 { 00087 EXPECT_EQ(iface->set_network("127.0.0.1", "255.255.0.0", "127.0.0.1"), NSAPI_ERROR_UNSUPPORTED ); 00088 } 00089 00090 TEST_F(TestNetworkInterface, set_dhcp) 00091 { 00092 EXPECT_EQ(iface->set_dhcp(true), NSAPI_ERROR_OK ); 00093 EXPECT_EQ(iface->set_dhcp(false), NSAPI_ERROR_UNSUPPORTED ); 00094 } 00095 00096 TEST_F(TestNetworkInterface, gethostbyname) 00097 { 00098 SocketAddress a; 00099 EXPECT_EQ(iface->gethostbyname("host", &a, NSAPI_UNSPEC ), NSAPI_ERROR_OK ); 00100 } 00101 00102 00103 static bool callback_is_called; 00104 static void my_callback(nsapi_error_t result, SocketAddress *address) 00105 { 00106 (void)result; 00107 (void)address; 00108 callback_is_called = true; 00109 } 00110 00111 TEST_F(TestNetworkInterface, gethostbyname_async) 00112 { 00113 SocketAddress a; 00114 EXPECT_EQ(iface->gethostbyname_async("host", mbed::callback(my_callback), NSAPI_UNSPEC ), NSAPI_ERROR_OK ); 00115 EXPECT_EQ(iface->gethostbyname_async_cancel(1), NSAPI_ERROR_OK ); 00116 } 00117 00118 TEST_F(TestNetworkInterface, add_dns_server) 00119 { 00120 SocketAddress a("127.0.0.1", 1024); 00121 EXPECT_EQ(iface->add_dns_server(a), NSAPI_ERROR_OK ); 00122 } 00123 00124 TEST_F(TestNetworkInterface, get_connection_status) 00125 { 00126 EXPECT_EQ(iface->get_connection_status(), NSAPI_ERROR_UNSUPPORTED ); 00127 } 00128 00129 TEST_F(TestNetworkInterface, set_blocking) 00130 { 00131 EXPECT_EQ(iface->set_blocking(true), NSAPI_ERROR_UNSUPPORTED ); 00132 } 00133 00134 // No way to test attach as it doesn't do or return anything.
Generated on Tue Aug 9 2022 00:37:22 by
1.7.2