Skip to content

Commit 1aa3b8f

Browse files
authored
Merge pull request #12344 from michalpasztamobica/unittests_dns
Unittests for DNS improvements
2 parents d063902 + 03fcc3a commit 1aa3b8f

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

UNITTESTS/MODULETESTS/features/netsocket/IfaceDnsSocket/test_IfaceDnsSocket.cpp renamed to UNITTESTS/moduletests/features/netsocket/IfaceDnsSocket/moduletest.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,19 +287,6 @@ TEST_F(Test_IfaceDnsSocket, single_query_ip6)
287287
EXPECT_FALSE(strncmp(addr.get_ip_address(), "102:304:506:708:90a:b0c:d0e:f10", sizeof("102:304:506:708:90a:b0c:d0e:f10")));
288288
}
289289

290-
// Imitate the getaddrinfo to make the example more real-life.
291-
int getaddrinfo(NetworkStack *stack, const char *hostname, SocketAddress hints, SocketAddress **res)
292-
{
293-
SocketAddress *tmp = new SocketAddress[5];
294-
int num = nsapi_dns_query_multiple(stack, hostname, tmp, 5, NULL);
295-
*res = new SocketAddress[num];
296-
for (int i = 0; i < num; i++) {
297-
(*res)[i].set_addr(tmp[i].get_addr());
298-
}
299-
delete[] tmp;
300-
return num;
301-
}
302-
303290
TEST_F(Test_IfaceDnsSocket, multiple_queries)
304291
{
305292
// Make sure socket opens successfully
@@ -320,7 +307,7 @@ TEST_F(Test_IfaceDnsSocket, multiple_queries)
320307

321308
SocketAddress *addr;
322309
SocketAddress hints{{NSAPI_UNSPEC}, 443};
323-
EXPECT_EQ(3, getaddrinfo(&stackMock(), "www.google.com", hints, &addr));
310+
EXPECT_EQ(3, iface->getaddrinfo("www.google.com", &hints, &addr));
324311

325312
EXPECT_EQ(addr[0].get_ip_version(), NSAPI_IPv4);
326313
EXPECT_FALSE(strncmp(addr[0].get_ip_address(), "216.58.207.238", sizeof("216.58.207.238")));
@@ -332,7 +319,7 @@ TEST_F(Test_IfaceDnsSocket, multiple_queries)
332319

333320
SocketAddress *addr_cache;
334321
// Cache will only raturn one address.
335-
EXPECT_EQ(3, getaddrinfo(&stackMock(), "www.google.com", hints, &addr_cache));
322+
EXPECT_EQ(3, iface->getaddrinfo("www.google.com", &hints, &addr_cache));
336323

337324
EXPECT_EQ(addr_cache[0].get_ip_version(), NSAPI_IPv4);
338325
EXPECT_FALSE(strncmp(addr_cache[0].get_ip_address(), "216.58.207.238", sizeof("216.58.207.238")));
@@ -420,6 +407,7 @@ TEST_F(Test_IfaceDnsSocket, simultaneous_query_async)
420407
}
421408

422409
// Imitate the getaddrinfo to make the example more real-life.
410+
// No way to replace this with NetworkInterface:getaddrinfo_async, because we can't pass a call_in cb.
423411
int getaddrinfo_async(NetworkStack *stack, const char *hostname, NetworkStack::hostbyname_cb_t cb)
424412
{
425413
return nsapi_dns_query_multiple_async(stack, hostname, cb, 5, &Test_IfaceDnsSocket::call_in, NULL);

UNITTESTS/MODULETESTS/features/netsocket/IfaceDnsSocket/unittest.cmake renamed to UNITTESTS/moduletests/features/netsocket/IfaceDnsSocket/unittest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ set(unittest-sources
2626
)
2727

2828
set(unittest-test-sources
29-
MODULETESTS/features/netsocket/IfaceDnsSocket/test_IfaceDnsSocket.cpp
29+
moduletests/features/netsocket/IfaceDnsSocket/moduletest.cpp
3030
stubs/MeshInterface_stub.cpp
3131
stubs/CellularInterface_stub.cpp
3232
stubs/Mutex_stub.cpp

0 commit comments

Comments
 (0)