17
17
18
18
#include " gtest/gtest.h"
19
19
#include " features/netsocket/NetworkInterface.h"
20
+ #include " NetworkStack_stub.h"
20
21
21
22
class stubNetworkInterface : public NetworkInterface {
22
23
virtual nsapi_error_t connect ()
@@ -29,8 +30,10 @@ class stubNetworkInterface : public NetworkInterface {
29
30
};
30
31
virtual NetworkStack *get_stack ()
31
32
{
32
- return NULL ;
33
+ return &stack ;
33
34
};
35
+ public:
36
+ NetworkStackstub stack;
34
37
};
35
38
36
39
class TestNetworkInterface : public testing ::Test {
@@ -53,8 +56,79 @@ TEST_F(TestNetworkInterface, constructor)
53
56
EXPECT_TRUE (iface);
54
57
}
55
58
59
+ // get_default_instance is tested along with the implementations of NetworkInterface.
60
+
56
61
TEST_F (TestNetworkInterface, get_mac_address)
57
62
{
58
63
char *n = 0 ;
59
64
EXPECT_EQ (iface->get_mac_address (), n);
60
65
}
66
+
67
+ TEST_F (TestNetworkInterface, get_ip_address)
68
+ {
69
+ char *n = 0 ;
70
+ EXPECT_EQ (iface->get_ip_address (), n);
71
+ }
72
+
73
+ TEST_F (TestNetworkInterface, get_netmask)
74
+ {
75
+ char *n = 0 ;
76
+ EXPECT_EQ (iface->get_netmask (), n);
77
+ }
78
+
79
+ TEST_F (TestNetworkInterface, get_gateway)
80
+ {
81
+ char *n = 0 ;
82
+ EXPECT_EQ (iface->get_gateway (), n);
83
+ }
84
+
85
+ TEST_F (TestNetworkInterface, set_network)
86
+ {
87
+ EXPECT_EQ (iface->set_network (" 127.0.0.1" , " 255.255.0.0" , " 127.0.0.1" ), NSAPI_ERROR_UNSUPPORTED);
88
+ }
89
+
90
+ TEST_F (TestNetworkInterface, set_dhcp)
91
+ {
92
+ EXPECT_EQ (iface->set_dhcp (true ), NSAPI_ERROR_OK);
93
+ EXPECT_EQ (iface->set_dhcp (false ), NSAPI_ERROR_UNSUPPORTED);
94
+ }
95
+
96
+ TEST_F (TestNetworkInterface, gethostbyname)
97
+ {
98
+ SocketAddress a;
99
+ EXPECT_EQ (iface->gethostbyname (" host" , &a, NSAPI_UNSPEC), NSAPI_ERROR_OK);
100
+ }
101
+
102
+
103
+ static bool callback_is_called;
104
+ static void my_callback (nsapi_error_t result, SocketAddress *address)
105
+ {
106
+ (void )result;
107
+ (void )address;
108
+ callback_is_called = true ;
109
+ }
110
+
111
+ TEST_F (TestNetworkInterface, gethostbyname_async)
112
+ {
113
+ SocketAddress a;
114
+ EXPECT_EQ (iface->gethostbyname_async (" host" , mbed::callback (my_callback), NSAPI_UNSPEC), NSAPI_ERROR_OK);
115
+ EXPECT_EQ (iface->gethostbyname_async_cancel (1 ), NSAPI_ERROR_OK);
116
+ }
117
+
118
+ TEST_F (TestNetworkInterface, add_dns_server)
119
+ {
120
+ SocketAddress a (" 127.0.0.1" , 1024 );
121
+ EXPECT_EQ (iface->add_dns_server (a), NSAPI_ERROR_OK);
122
+ }
123
+
124
+ TEST_F (TestNetworkInterface, get_connection_status)
125
+ {
126
+ EXPECT_EQ (iface->get_connection_status (), NSAPI_ERROR_UNSUPPORTED);
127
+ }
128
+
129
+ TEST_F (TestNetworkInterface, set_blocking)
130
+ {
131
+ EXPECT_EQ (iface->set_blocking (true ), NSAPI_ERROR_UNSUPPORTED);
132
+ }
133
+
134
+ // No way to test attach as it doesn't do or return anything.
0 commit comments