Skip to content

Commit 68e0336

Browse files
Improve doxygen and unittest coverage for API
Mainly focusing on hardening the tests for return values.
1 parent 6176205 commit 68e0336

19 files changed

+562
-139
lines changed

UNITTESTS/features/netsocket/EthernetInterface/test_EthernetInterface.cpp

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ MBED_WEAK EMAC &EMAC::get_default_instance()
5353
return MockEMAC::get_instance();
5454
}
5555

56-
57-
5856
OnboardNetworkStack &OnboardNetworkStack::get_default_instance()
5957
{
6058
return OnboardNetworkStackMock::get_instance();
@@ -119,6 +117,15 @@ class TestEthernetInterface: public testing::Test {
119117
TEST_F(TestEthernetInterface, constructor_default)
120118
{
121119
EXPECT_TRUE(iface);
120+
121+
// Test that this clas presents itself correctly
122+
EXPECT_NE(nullptr, iface->ethInterface());
123+
EXPECT_NE(nullptr, iface->emacInterface());
124+
125+
EXPECT_EQ(nullptr, iface->wifiInterface());
126+
EXPECT_EQ(nullptr, iface->cellularBase());
127+
EXPECT_EQ(nullptr, iface->cellularInterface());
128+
EXPECT_EQ(nullptr, iface->meshInterface());
122129
}
123130

124131
TEST_F(TestEthernetInterface, constructor_getter)
@@ -161,11 +168,15 @@ TEST_F(TestEthernetInterface, set_network)
161168
char ipAddress[NSAPI_IPv4_SIZE] = "127.0.0.1";
162169
char netmask[NSAPI_IPv4_SIZE] = "255.255.0.0";
163170
char gateway[NSAPI_IPv4_SIZE] = "127.0.0.2";
171+
char macAddress[NSAPI_MAC_SIZE];
164172

165173
const char *ipAddressArg;
166174
const char *netmaskArg;
167175
const char *gatewayArg;
168176

177+
// Before connecting return NULL
178+
EXPECT_EQ(NULL, iface->get_mac_address());
179+
169180
EXPECT_EQ(0, iface->get_ip_address());
170181
EXPECT_EQ(0, iface->get_netmask());
171182
EXPECT_EQ(0, iface->get_gateway());
@@ -194,6 +205,11 @@ TEST_F(TestEthernetInterface, set_network)
194205
EXPECT_TRUE(0 == strcmp(gateway, gatewayArg));
195206

196207
// Testing the getters makes sense now.
208+
EXPECT_CALL(*netStackIface, get_mac_address(_, _))
209+
.Times(1)
210+
.WillOnce(DoAll(SetArrayArgument<0>(macAddress, macAddress+NSAPI_MAC_SIZE), Return(macAddress)));
211+
EXPECT_EQ(std::string(macAddress), std::string(iface->get_mac_address()));
212+
197213
EXPECT_CALL(*netStackIface, get_ip_address(_, _))
198214
.Times(1)
199215
.WillOnce(DoAll(SetArgPointee<0>(*ipAddress), Return(ipAddress)));
@@ -230,6 +246,45 @@ TEST_F(TestEthernetInterface, attach)
230246
iface->attach(cb);
231247
}
232248

249+
250+
TEST_F(TestEthernetInterface, get_interface_name)
251+
{
252+
char name[100] = "eth0";
253+
EXPECT_EQ(NULL, iface->get_interface_name(name));
254+
255+
doConnect();
256+
257+
// The parameter will be an internal variable.
258+
EXPECT_CALL(*netStackIface, get_interface_name(_))
259+
.Times(1)
260+
.WillOnce(Return(name));
261+
EXPECT_EQ(std::string(name), std::string(iface->get_interface_name(name)));
262+
}
263+
264+
TEST_F(TestEthernetInterface, get_ipv6_link_local_address)
265+
{
266+
SocketAddress addr("4.3.2.1");
267+
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_ipv6_link_local_address(&addr));
268+
EXPECT_NE(std::string(addr.get_ip_address()), std::string("4.3.2.1"));
269+
doConnect();
270+
271+
// The parameter will be an internal variable.
272+
EXPECT_CALL(*netStackIface, get_ipv6_link_local_address(&addr))
273+
.Times(1)
274+
.WillOnce(Return(NSAPI_ERROR_OK));
275+
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_ipv6_link_local_address(&addr));
276+
}
277+
278+
TEST_F(TestEthernetInterface, set_as_default)
279+
{
280+
doConnect();
281+
282+
EXPECT_CALL(*stackMock, set_default_interface(netStackIface))
283+
.Times(1);
284+
iface->set_as_default();
285+
}
286+
287+
233288
TEST_F(TestEthernetInterface, set_dhcp)
234289
{
235290
EXPECT_EQ(NSAPI_ERROR_OK, iface->set_dhcp(false));

UNITTESTS/features/netsocket/NetworkInterface/test_NetworkInterface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ TEST_F(TestNetworkInterface, set_blocking)
148148
EXPECT_EQ(iface->set_blocking(true), NSAPI_ERROR_UNSUPPORTED);
149149
}
150150

151+
TEST_F(TestNetworkInterface, get_ipv6_link_local_address)
152+
{
153+
SocketAddress a;
154+
EXPECT_EQ(iface->get_ipv6_link_local_address(&a), NSAPI_ERROR_UNSUPPORTED);
155+
}
156+
151157
void my_iface_callback(nsapi_event_t e, intptr_t i)
152158
{
153159
(void)e;

0 commit comments

Comments
 (0)