Skip to content

Commit d9e37e7

Browse files
Unittests fixed not to use deprecated string-based API
1 parent f21b8c7 commit d9e37e7

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

UNITTESTS/features/netsocket/PPPInterface/test_PPPInterface.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,21 @@ TEST_F(TestPPPInterface, disconnect)
178178

179179
TEST_F(TestPPPInterface, set_network)
180180
{
181-
char ipAddress[NSAPI_IPv4_SIZE] = "127.0.0.1";
182-
char netmask[NSAPI_IPv4_SIZE] = "255.255.0.0";
183-
char gateway[NSAPI_IPv4_SIZE] = "127.0.0.2";
181+
SocketAddress ipAddress("127.0.0.1");
182+
SocketAddress netmask("255.255.0.0");
183+
SocketAddress gateway("127.0.0.2");
184184

185185
const char *ipAddressArg;
186186
const char *netmaskArg;
187187
const char *gatewayArg;
188188

189-
EXPECT_EQ(0, iface->get_ip_address());
190-
EXPECT_EQ(0, iface->get_netmask());
191-
EXPECT_EQ(0, iface->get_gateway());
189+
SocketAddress ipAddr;
190+
SocketAddress netmaskAddr;
191+
SocketAddress gatewayAddr;
192+
193+
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_ip_address(&ipAddr));
194+
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_netmask(&netmaskAddr));
195+
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_gateway(&gatewayAddr));
192196

193197
EXPECT_CALL(*pppMock, set_stream(_));
194198
EXPECT_CALL(*pppMock, set_ip_stack(_));
@@ -213,25 +217,28 @@ TEST_F(TestPPPInterface, set_network)
213217
Return(NSAPI_ERROR_OK)));
214218
EXPECT_EQ(NSAPI_ERROR_OK, iface->connect());
215219
// Check the contents of the stored pointer arguments.
216-
EXPECT_TRUE(0 == strcmp(ipAddress, ipAddressArg));
217-
EXPECT_TRUE(0 == strcmp(netmask, netmaskArg));
218-
EXPECT_TRUE(0 == strcmp(gateway, gatewayArg));
220+
EXPECT_TRUE(0 == strcmp(ipAddress.get_ip_address(), ipAddressArg));
221+
EXPECT_TRUE(0 == strcmp(netmask.get_ip_address(), netmaskArg));
222+
EXPECT_TRUE(0 == strcmp(gateway.get_ip_address(), gatewayArg));
219223

220224
// Testing the getters makes sense now.
221-
EXPECT_CALL(*netStackIface, get_ip_address(_, _))
225+
EXPECT_CALL(*netStackIface, get_ip_address(_))
222226
.Times(1)
223-
.WillOnce(DoAll(SetArgPointee<0>(*ipAddress), Return(ipAddress)));
224-
EXPECT_EQ(std::string(ipAddress), std::string(iface->get_ip_address()));
227+
.WillOnce(DoAll(SetArgPointee<0>(ipAddress), Return(NSAPI_ERROR_OK)));
228+
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_ip_address(&ipAddr));
229+
EXPECT_EQ(ipAddress, ipAddr);
225230

226-
EXPECT_CALL(*netStackIface, get_netmask(_, _))
231+
EXPECT_CALL(*netStackIface, get_netmask(_))
227232
.Times(1)
228-
.WillOnce(DoAll(SetArgPointee<0>(*netmask), Return(netmask)));
229-
EXPECT_EQ(std::string(netmask), std::string(iface->get_netmask()));
233+
.WillOnce(DoAll(SetArgPointee<0>(netmask), Return(NSAPI_ERROR_OK)));
234+
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_netmask(&netmaskAddr));
235+
EXPECT_EQ(netmask, netmaskAddr);
230236

231-
EXPECT_CALL(*netStackIface, get_gateway(_, _))
237+
EXPECT_CALL(*netStackIface, get_gateway(_))
232238
.Times(1)
233-
.WillOnce(DoAll(SetArgPointee<0>(*gateway), Return(gateway)));
234-
EXPECT_EQ(std::string(gateway), std::string(iface->get_gateway()));
239+
.WillOnce(DoAll(SetArgPointee<0>(gateway), Return(NSAPI_ERROR_OK)));
240+
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_gateway(&gatewayAddr));
241+
EXPECT_EQ(gateway, gatewayAddr);
235242
}
236243

237244
TEST_F(TestPPPInterface, get_connection_status)

UNITTESTS/features/netsocket/PPPInterface/unittest.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ set(unittest-test-sources
3232
stubs/mbed_shared_queues_stub.cpp
3333
stubs/nsapi_dns_stub.cpp
3434
stubs/EventFlags_stub.cpp
35-
stubs/stoip4_stub.c
36-
stubs/ip4tos_stub.c
3735
stubs/NetworkStack_stub.cpp
3836
stubs/NetworkInterfaceDefaults_stub.cpp
3937
stubs/SocketStats_Stub.cpp

UNITTESTS/stubs/AT_CellularStack_stub.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ nsapi_error_t AT_CellularStack::get_ip_address(SocketAddress* address)
3636
return NSAPI_ERROR_UNSUPPORTED;
3737
}
3838

39-
const char *AT_CellularStack::get_ip_address()
40-
{
41-
return NULL;
42-
}
43-
4439
nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
4540
{
4641
return NSAPI_ERROR_OK;

UNITTESTS/stubs/OnboardNetworkStack_mock.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class OnboardNetworkStackMock : public OnboardNetworkStack {
8282
MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t());
8383
MOCK_METHOD1(get_interface_name, char *(char *buf));
8484
MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen));
85-
MOCK_METHOD2(get_ip_address, char *(char *buf, nsapi_size_t buflen));
8685
MOCK_METHOD1(get_ip_address, nsapi_error_t (SocketAddress *address));
8786
MOCK_METHOD1(get_ipv6_link_local_address, nsapi_error_t(SocketAddress *address));
8887
MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen));

0 commit comments

Comments
 (0)