xref: /minix3/external/bsd/bind/dist/lib/lwres/tests/config_test.c (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1 /*	$NetBSD: config_test.c,v 1.1.1.3 2014/12/10 03:34:46 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <config.h>
20 
21 #include <atf-c.h>
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 
28 #include "../lwconfig.c"
29 
30 static void
setup_test()31 setup_test() {
32 	/*
33 	 * atf-run changes us to a /tmp directory, so tests
34 	 * that access test data files must first chdir to the proper
35 	 * location.
36 	 */
37 	ATF_CHECK(chdir(TESTS) != -1);
38 }
39 
40 ATF_TC(parse_linklocal);
ATF_TC_HEAD(parse_linklocal,tc)41 ATF_TC_HEAD(parse_linklocal, tc) {
42 	atf_tc_set_md_var(tc, "descr", "lwres_conf_parse link-local nameserver");
43 }
ATF_TC_BODY(parse_linklocal,tc)44 ATF_TC_BODY(parse_linklocal, tc) {
45 	lwres_result_t result;
46 	lwres_context_t *ctx = NULL;
47 	unsigned char addr[16] = { 0xfe, 0x80, 0x00, 0x00,
48 				   0x00, 0x00, 0x00, 0x00,
49 				   0x00, 0x00, 0x00, 0x00,
50 				   0x00, 0x00, 0x00, 0x01 };
51 
52 	UNUSED(tc);
53 
54 	setup_test();
55 
56 	lwres_context_create(&ctx, NULL, NULL, NULL,
57 			     LWRES_CONTEXT_USEIPV4 | LWRES_CONTEXT_USEIPV6);
58 	ATF_CHECK_EQ(ctx->confdata.nsnext, 0);
59 	ATF_CHECK_EQ(ctx->confdata.nameservers[0].zone, 0);
60 
61 	result = lwres_conf_parse(ctx, "testdata/link-local.conf");
62 	ATF_CHECK_EQ(result, LWRES_R_SUCCESS);
63 	ATF_CHECK_EQ(ctx->confdata.nsnext, 1);
64 	ATF_CHECK_EQ(ctx->confdata.nameservers[0].zone, 1);
65 	ATF_CHECK_EQ(memcmp(ctx->confdata.nameservers[0].address, addr, 16), 0);
66 	lwres_context_destroy(&ctx);
67 }
68 
69 /*
70  * Main
71  */
ATF_TP_ADD_TCS(tp)72 ATF_TP_ADD_TCS(tp) {
73 	ATF_TP_ADD_TC(tp, parse_linklocal);
74 	return (atf_no_error());
75 }
76