Unittests fixed not to use deprecated string-based API

pull/11942/head
Michal Paszta 2020-01-08 18:36:22 +02:00
parent f21b8c7fc1
commit d9e37e7212
4 changed files with 25 additions and 26 deletions

View File

@ -178,17 +178,21 @@ TEST_F(TestPPPInterface, disconnect)
TEST_F(TestPPPInterface, set_network)
{
char ipAddress[NSAPI_IPv4_SIZE] = "127.0.0.1";
char netmask[NSAPI_IPv4_SIZE] = "255.255.0.0";
char gateway[NSAPI_IPv4_SIZE] = "127.0.0.2";
SocketAddress ipAddress("127.0.0.1");
SocketAddress netmask("255.255.0.0");
SocketAddress gateway("127.0.0.2");
const char *ipAddressArg;
const char *netmaskArg;
const char *gatewayArg;
EXPECT_EQ(0, iface->get_ip_address());
EXPECT_EQ(0, iface->get_netmask());
EXPECT_EQ(0, iface->get_gateway());
SocketAddress ipAddr;
SocketAddress netmaskAddr;
SocketAddress gatewayAddr;
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_ip_address(&ipAddr));
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_netmask(&netmaskAddr));
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_gateway(&gatewayAddr));
EXPECT_CALL(*pppMock, set_stream(_));
EXPECT_CALL(*pppMock, set_ip_stack(_));
@ -213,25 +217,28 @@ TEST_F(TestPPPInterface, set_network)
Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->connect());
// Check the contents of the stored pointer arguments.
EXPECT_TRUE(0 == strcmp(ipAddress, ipAddressArg));
EXPECT_TRUE(0 == strcmp(netmask, netmaskArg));
EXPECT_TRUE(0 == strcmp(gateway, gatewayArg));
EXPECT_TRUE(0 == strcmp(ipAddress.get_ip_address(), ipAddressArg));
EXPECT_TRUE(0 == strcmp(netmask.get_ip_address(), netmaskArg));
EXPECT_TRUE(0 == strcmp(gateway.get_ip_address(), gatewayArg));
// Testing the getters makes sense now.
EXPECT_CALL(*netStackIface, get_ip_address(_, _))
EXPECT_CALL(*netStackIface, get_ip_address(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(*ipAddress), Return(ipAddress)));
EXPECT_EQ(std::string(ipAddress), std::string(iface->get_ip_address()));
.WillOnce(DoAll(SetArgPointee<0>(ipAddress), Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_ip_address(&ipAddr));
EXPECT_EQ(ipAddress, ipAddr);
EXPECT_CALL(*netStackIface, get_netmask(_, _))
EXPECT_CALL(*netStackIface, get_netmask(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(*netmask), Return(netmask)));
EXPECT_EQ(std::string(netmask), std::string(iface->get_netmask()));
.WillOnce(DoAll(SetArgPointee<0>(netmask), Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_netmask(&netmaskAddr));
EXPECT_EQ(netmask, netmaskAddr);
EXPECT_CALL(*netStackIface, get_gateway(_, _))
EXPECT_CALL(*netStackIface, get_gateway(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(*gateway), Return(gateway)));
EXPECT_EQ(std::string(gateway), std::string(iface->get_gateway()));
.WillOnce(DoAll(SetArgPointee<0>(gateway), Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_gateway(&gatewayAddr));
EXPECT_EQ(gateway, gatewayAddr);
}
TEST_F(TestPPPInterface, get_connection_status)

View File

@ -32,8 +32,6 @@ set(unittest-test-sources
stubs/mbed_shared_queues_stub.cpp
stubs/nsapi_dns_stub.cpp
stubs/EventFlags_stub.cpp
stubs/stoip4_stub.c
stubs/ip4tos_stub.c
stubs/NetworkStack_stub.cpp
stubs/NetworkInterfaceDefaults_stub.cpp
stubs/SocketStats_Stub.cpp

View File

@ -36,11 +36,6 @@ nsapi_error_t AT_CellularStack::get_ip_address(SocketAddress* address)
return NSAPI_ERROR_UNSUPPORTED;
}
const char *AT_CellularStack::get_ip_address()
{
return NULL;
}
nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
{
return NSAPI_ERROR_OK;

View File

@ -82,7 +82,6 @@ public:
MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t());
MOCK_METHOD1(get_interface_name, char *(char *buf));
MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen));
MOCK_METHOD2(get_ip_address, char *(char *buf, nsapi_size_t buflen));
MOCK_METHOD1(get_ip_address, nsapi_error_t (SocketAddress *address));
MOCK_METHOD1(get_ipv6_link_local_address, nsapi_error_t(SocketAddress *address));
MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen));