1 /* $NetBSD: rdataset_test.c,v 1.3 2014/12/10 04:37:59 christos Exp $ */
2
3 /*
4 * Copyright (C) 2012 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/rdataset.h>
30 #include <dns/rdatastruct.h>
31
32 #include "dnstest.h"
33
34
35 /*
36 * Individual unit tests
37 */
38
39 /* Successful load test */
40 ATF_TC(trimttl);
ATF_TC_HEAD(trimttl,tc)41 ATF_TC_HEAD(trimttl, tc) {
42 atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() loads a "
43 "valid master file and returns success");
44 }
ATF_TC_BODY(trimttl,tc)45 ATF_TC_BODY(trimttl, tc) {
46 isc_result_t result;
47 dns_rdataset_t rdataset, sigrdataset;
48 dns_rdata_rrsig_t rrsig;
49 isc_stdtime_t ttltimenow, ttltimeexpire;
50
51 ttltimenow = 10000000;
52 ttltimeexpire = ttltimenow + 800;
53
54 UNUSED(tc);
55
56 dns_rdataset_init(&rdataset);
57 dns_rdataset_init(&sigrdataset);
58
59 result = dns_test_begin(NULL, ISC_FALSE);
60 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
61
62 rdataset.ttl = 900;
63 sigrdataset.ttl = 1000;
64 rrsig.timeexpire = ttltimeexpire;
65 rrsig.originalttl = 1000;
66
67 dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
68 ISC_TRUE);
69 ATF_REQUIRE_EQ(rdataset.ttl, 800);
70 ATF_REQUIRE_EQ(sigrdataset.ttl, 800);
71
72 rdataset.ttl = 900;
73 sigrdataset.ttl = 1000;
74 rrsig.timeexpire = ttltimenow - 200;
75 rrsig.originalttl = 1000;
76
77 dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
78 ISC_TRUE);
79 ATF_REQUIRE_EQ(rdataset.ttl, 120);
80 ATF_REQUIRE_EQ(sigrdataset.ttl, 120);
81
82 rdataset.ttl = 900;
83 sigrdataset.ttl = 1000;
84 rrsig.timeexpire = ttltimenow - 200;
85 rrsig.originalttl = 1000;
86
87 dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
88 ISC_FALSE);
89 ATF_REQUIRE_EQ(rdataset.ttl, 0);
90 ATF_REQUIRE_EQ(sigrdataset.ttl, 0);
91
92 sigrdataset.ttl = 900;
93 rdataset.ttl = 1000;
94 rrsig.timeexpire = ttltimeexpire;
95 rrsig.originalttl = 1000;
96
97 dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
98 ISC_TRUE);
99 ATF_REQUIRE_EQ(rdataset.ttl, 800);
100 ATF_REQUIRE_EQ(sigrdataset.ttl, 800);
101
102 sigrdataset.ttl = 900;
103 rdataset.ttl = 1000;
104 rrsig.timeexpire = ttltimenow - 200;
105 rrsig.originalttl = 1000;
106
107 dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
108 ISC_TRUE);
109 ATF_REQUIRE_EQ(rdataset.ttl, 120);
110 ATF_REQUIRE_EQ(sigrdataset.ttl, 120);
111
112 sigrdataset.ttl = 900;
113 rdataset.ttl = 1000;
114 rrsig.timeexpire = ttltimenow - 200;
115 rrsig.originalttl = 1000;
116
117 dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
118 ISC_FALSE);
119 ATF_REQUIRE_EQ(rdataset.ttl, 0);
120 ATF_REQUIRE_EQ(sigrdataset.ttl, 0);
121
122 dns_test_end();
123 }
124
125 /*
126 * Main
127 */
ATF_TP_ADD_TCS(tp)128 ATF_TP_ADD_TCS(tp) {
129 ATF_TP_ADD_TC(tp, trimttl);
130
131 return (atf_no_error());
132 }
133
134