mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-11-18 20:10:53 +00:00
dns: Verify setting/getting servers in unit test
This commit is contained in:
parent
5b7524e10e
commit
047f3b3306
@ -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
|
||||
|
@ -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
52
test/unit/core/test_dns.c
Normal 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);
|
||||
}
|
8
test/unit/core/test_dns.h
Normal file
8
test/unit/core/test_dns.h
Normal 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
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user