@@ -53,8 +53,6 @@ MBED_WEAK EMAC &EMAC::get_default_instance()
53
53
return MockEMAC::get_instance ();
54
54
}
55
55
56
-
57
-
58
56
OnboardNetworkStack &OnboardNetworkStack::get_default_instance ()
59
57
{
60
58
return OnboardNetworkStackMock::get_instance ();
@@ -119,6 +117,15 @@ class TestEthernetInterface: public testing::Test {
119
117
TEST_F (TestEthernetInterface, constructor_default)
120
118
{
121
119
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 ());
122
129
}
123
130
124
131
TEST_F (TestEthernetInterface, constructor_getter)
@@ -161,11 +168,15 @@ TEST_F(TestEthernetInterface, set_network)
161
168
char ipAddress[NSAPI_IPv4_SIZE] = " 127.0.0.1" ;
162
169
char netmask[NSAPI_IPv4_SIZE] = " 255.255.0.0" ;
163
170
char gateway[NSAPI_IPv4_SIZE] = " 127.0.0.2" ;
171
+ char macAddress[NSAPI_MAC_SIZE];
164
172
165
173
const char *ipAddressArg;
166
174
const char *netmaskArg;
167
175
const char *gatewayArg;
168
176
177
+ // Before connecting return NULL
178
+ EXPECT_EQ (NULL , iface->get_mac_address ());
179
+
169
180
EXPECT_EQ (0 , iface->get_ip_address ());
170
181
EXPECT_EQ (0 , iface->get_netmask ());
171
182
EXPECT_EQ (0 , iface->get_gateway ());
@@ -194,6 +205,11 @@ TEST_F(TestEthernetInterface, set_network)
194
205
EXPECT_TRUE (0 == strcmp (gateway, gatewayArg));
195
206
196
207
// 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
+
197
213
EXPECT_CALL (*netStackIface, get_ip_address (_, _))
198
214
.Times (1 )
199
215
.WillOnce (DoAll (SetArgPointee<0 >(*ipAddress), Return (ipAddress)));
@@ -230,6 +246,45 @@ TEST_F(TestEthernetInterface, attach)
230
246
iface->attach (cb);
231
247
}
232
248
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
+
233
288
TEST_F (TestEthernetInterface, set_dhcp)
234
289
{
235
290
EXPECT_EQ (NSAPI_ERROR_OK, iface->set_dhcp (false ));
0 commit comments