1 /* $NetBSD: name_test.c,v 1.1.1.1 2015/07/08 15:38:04 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 /* Id */
20
21 /*! \file */
22
23 #include <config.h>
24
25 #include <atf-c.h>
26
27 #include <unistd.h>
28
29 #include <dns/name.h>
30 #include <dns/fixedname.h>
31 #include "dnstest.h"
32
33 /*
34 * Individual unit tests
35 */
36
37 ATF_TC(fullcompare);
ATF_TC_HEAD(fullcompare,tc)38 ATF_TC_HEAD(fullcompare, tc) {
39 atf_tc_set_md_var(tc, "descr", "dns_name_fullcompare test");
40 }
ATF_TC_BODY(fullcompare,tc)41 ATF_TC_BODY(fullcompare, tc) {
42 dns_fixedname_t fixed1;
43 dns_fixedname_t fixed2;
44 dns_name_t *name1;
45 dns_name_t *name2;
46 dns_namereln_t relation;
47 int i;
48 isc_result_t result;
49 struct {
50 const char *name1;
51 const char *name2;
52 dns_namereln_t relation;
53 int order;
54 unsigned int nlabels;
55 } data[] = {
56 /* relative */
57 { "", "", dns_namereln_equal, 0, 0 },
58 { "foo", "", dns_namereln_subdomain, 1, 0 },
59 { "", "foo", dns_namereln_contains, -1, 0 },
60 { "foo", "bar", dns_namereln_none, 4, 0 },
61 { "bar", "foo", dns_namereln_none, -4, 0 },
62 { "bar.foo", "foo", dns_namereln_subdomain, 1, 1 },
63 { "foo", "bar.foo", dns_namereln_contains, -1, 1 },
64 { "baz.bar.foo", "bar.foo", dns_namereln_subdomain, 1, 2 },
65 { "bar.foo", "baz.bar.foo", dns_namereln_contains, -1, 2 },
66 { "foo.example", "bar.example", dns_namereln_commonancestor,
67 4, 1 },
68
69 /* absolute */
70 { ".", ".", dns_namereln_equal, 0, 1 },
71 { "foo.", "bar.", dns_namereln_commonancestor, 4, 1 },
72 { "bar.", "foo.", dns_namereln_commonancestor, -4, 1 },
73 { "foo.example.", "bar.example.", dns_namereln_commonancestor,
74 4, 2 },
75 { "bar.foo.", "foo.", dns_namereln_subdomain, 1, 2 },
76 { "foo.", "bar.foo.", dns_namereln_contains, -1, 2 },
77 { "baz.bar.foo.", "bar.foo.", dns_namereln_subdomain, 1, 3 },
78 { "bar.foo.", "baz.bar.foo.", dns_namereln_contains, -1, 3 },
79 { NULL, NULL, dns_namereln_none, 0, 0 }
80 };
81
82 UNUSED(tc);
83
84 dns_fixedname_init(&fixed1);
85 name1 = dns_fixedname_name(&fixed1);
86 dns_fixedname_init(&fixed2);
87 name2 = dns_fixedname_name(&fixed2);
88 for (i = 0; data[i].name1 != NULL; i++) {
89 int order = 3000;
90 unsigned int nlabels = 3000;
91
92 if (data[i].name1[0] == 0) {
93 dns_fixedname_init(&fixed1);
94 } else {
95 result = dns_name_fromstring2(name1, data[i].name1,
96 NULL, 0, NULL);
97 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
98 }
99 if (data[i].name2[0] == 0) {
100 dns_fixedname_init(&fixed2);
101 } else {
102 result = dns_name_fromstring2(name2, data[i].name2,
103 NULL, 0, NULL);
104 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
105 }
106 relation = dns_name_fullcompare(name1, name1, &order, &nlabels);
107 ATF_REQUIRE_EQ(relation, dns_namereln_equal);
108 ATF_REQUIRE_EQ(order, 0);
109 ATF_REQUIRE_EQ(nlabels, name1->labels);
110
111 /* Some random initializer */
112 order = 3001;
113 nlabels = 3001;
114
115 relation = dns_name_fullcompare(name1, name2, &order, &nlabels);
116 ATF_REQUIRE_EQ(relation, data[i].relation);
117 ATF_REQUIRE_EQ(order, data[i].order);
118 ATF_REQUIRE_EQ(nlabels, data[i].nlabels);
119 }
120 }
121
122 /*
123 * Main
124 */
ATF_TP_ADD_TCS(tp)125 ATF_TP_ADD_TCS(tp) {
126 ATF_TP_ADD_TC(tp, fullcompare);
127
128 return (atf_no_error());
129 }
130
131