dns: Verify setting/getting servers in unit test

This commit is contained in:
Erik Ekman 2020-07-04 18:31:36 +02:00
parent 5b7524e10e
commit 047f3b3306
5 changed files with 64 additions and 0 deletions

View File

@ -18,6 +18,7 @@ set(LWIP_TESTFILES
${LWIP_TESTDIR}/api/test_sockets.c
${LWIP_TESTDIR}/arch/sys_arch.c
${LWIP_TESTDIR}/core/test_def.c
${LWIP_TESTDIR}/core/test_dns.c
${LWIP_TESTDIR}/core/test_mem.c
${LWIP_TESTDIR}/core/test_netif.c
${LWIP_TESTDIR}/core/test_pbuf.c

View File

@ -34,6 +34,7 @@ TESTFILES=$(TESTDIR)/lwip_unittests.c \
$(TESTDIR)/api/test_sockets.c \
$(TESTDIR)/arch/sys_arch.c \
$(TESTDIR)/core/test_def.c \
$(TESTDIR)/core/test_dns.c \
$(TESTDIR)/core/test_mem.c \
$(TESTDIR)/core/test_netif.c \
$(TESTDIR)/core/test_pbuf.c \

52
test/unit/core/test_dns.c Normal file
View File

@ -0,0 +1,52 @@
#include "test_dns.h"
#include "lwip/dns.h"
/* Setups/teardown functions */
static void
dns_setup(void)
{
}
static void
dns_teardown(void)
{
}
/* Test functions */
START_TEST(test_dns_set_get_server)
{
int i;
LWIP_UNUSED_ARG(_i);
for (i = 0; i < 256; i++) {
ip_addr_t server;
/* Should return a zeroed address for any index */
fail_unless(dns_getserver(i));
fail_unless(ip_addr_isany(dns_getserver(i)));
/* Should accept setting address for any index, and ignore if out of range */
IP_ADDR4(&server, 10, 0, 0, i);
dns_setserver(i, &server);
fail_unless(dns_getserver(i));
if (i < DNS_MAX_SERVERS) {
/* ip_addr_cmp returns 1 if they match. */
fail_unless(ip_addr_cmp(dns_getserver(i), &server) == 1);
} else {
fail_unless(ip_addr_isany(dns_getserver(i)));
}
}
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
dns_suite(void)
{
testfunc tests[] = {
TESTFUNC(test_dns_set_get_server)
};
return create_suite("DNS", tests, sizeof(tests)/sizeof(testfunc), dns_setup, dns_teardown);
}

View File

@ -0,0 +1,8 @@
#ifndef LWIP_HDR_TEST_DNS_H
#define LWIP_HDR_TEST_DNS_H
#include "../lwip_check.h"
Suite *dns_suite(void);
#endif

View File

@ -6,6 +6,7 @@
#include "tcp/test_tcp.h"
#include "tcp/test_tcp_oos.h"
#include "core/test_def.h"
#include "core/test_dns.h"
#include "core/test_mem.h"
#include "core/test_netif.h"
#include "core/test_pbuf.h"
@ -78,6 +79,7 @@ int main(void)
tcp_suite,
tcp_oos_suite,
def_suite,
dns_suite,
mem_suite,
netif_suite,
pbuf_suite,