rdataset_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id$ */
00018 
00019 /*! \file */
00020 
00021 #include <config.h>
00022 
00023 #include <atf-c.h>
00024 
00025 #include <unistd.h>
00026 
00027 #include <dns/rdataset.h>
00028 #include <dns/rdatastruct.h>
00029 
00030 #include "dnstest.h"
00031 
00032 
00033 /*
00034  * Individual unit tests
00035  */
00036 
00037 /* Successful load test */
00038 ATF_TC(trimttl);
00039 ATF_TC_HEAD(trimttl, tc) {
00040         atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() loads a "
00041                                        "valid master file and returns success");
00042 }
00043 ATF_TC_BODY(trimttl, tc) {
00044         isc_result_t result;
00045         dns_rdataset_t rdataset, sigrdataset;
00046         dns_rdata_rrsig_t rrsig;
00047         isc_stdtime_t ttltimenow, ttltimeexpire;
00048 
00049         ttltimenow = 10000000;
00050         ttltimeexpire = ttltimenow + 800;
00051 
00052         UNUSED(tc);
00053 
00054         dns_rdataset_init(&rdataset);
00055         dns_rdataset_init(&sigrdataset);
00056 
00057         result = dns_test_begin(NULL, ISC_FALSE);
00058         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00059 
00060         rdataset.ttl = 900;
00061         sigrdataset.ttl = 1000;
00062         rrsig.timeexpire = ttltimeexpire;
00063         rrsig.originalttl = 1000;
00064 
00065         dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
00066                              ISC_TRUE);
00067         ATF_REQUIRE_EQ(rdataset.ttl, 800);
00068         ATF_REQUIRE_EQ(sigrdataset.ttl, 800);
00069 
00070         rdataset.ttl = 900;
00071         sigrdataset.ttl = 1000;
00072         rrsig.timeexpire = ttltimenow - 200;
00073         rrsig.originalttl = 1000;
00074 
00075         dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
00076                              ISC_TRUE);
00077         ATF_REQUIRE_EQ(rdataset.ttl, 120);
00078         ATF_REQUIRE_EQ(sigrdataset.ttl, 120);
00079 
00080         rdataset.ttl = 900;
00081         sigrdataset.ttl = 1000;
00082         rrsig.timeexpire = ttltimenow - 200;
00083         rrsig.originalttl = 1000;
00084 
00085         dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
00086                              ISC_FALSE);
00087         ATF_REQUIRE_EQ(rdataset.ttl, 0);
00088         ATF_REQUIRE_EQ(sigrdataset.ttl, 0);
00089 
00090         sigrdataset.ttl = 900;
00091         rdataset.ttl = 1000;
00092         rrsig.timeexpire = ttltimeexpire;
00093         rrsig.originalttl = 1000;
00094 
00095         dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
00096                              ISC_TRUE);
00097         ATF_REQUIRE_EQ(rdataset.ttl, 800);
00098         ATF_REQUIRE_EQ(sigrdataset.ttl, 800);
00099 
00100         sigrdataset.ttl = 900;
00101         rdataset.ttl = 1000;
00102         rrsig.timeexpire = ttltimenow - 200;
00103         rrsig.originalttl = 1000;
00104 
00105         dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
00106                              ISC_TRUE);
00107         ATF_REQUIRE_EQ(rdataset.ttl, 120);
00108         ATF_REQUIRE_EQ(sigrdataset.ttl, 120);
00109 
00110         sigrdataset.ttl = 900;
00111         rdataset.ttl = 1000;
00112         rrsig.timeexpire = ttltimenow - 200;
00113         rrsig.originalttl = 1000;
00114 
00115         dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
00116                              ISC_FALSE);
00117         ATF_REQUIRE_EQ(rdataset.ttl, 0);
00118         ATF_REQUIRE_EQ(sigrdataset.ttl, 0);
00119 
00120         dns_test_end();
00121 }
00122 
00123 /*
00124  * Main
00125  */
00126 ATF_TP_ADD_TCS(tp) {
00127         ATF_TP_ADD_TC(tp, trimttl);
00128 
00129         return (atf_no_error());
00130 }
00131 

Generated on Tue Apr 28 17:41:02 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha