dbdiff_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011, 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 #include <stdlib.h>
00027 
00028 #include <dns/db.h>
00029 #include <dns/dbiterator.h>
00030 #include <dns/name.h>
00031 #include <dns/journal.h>
00032 
00033 #include "dnstest.h"
00034 
00035 /*
00036  * Helper functions
00037  */
00038 
00039 #define BUFLEN          255
00040 #define BIGBUFLEN       (64 * 1024)
00041 #define TEST_ORIGIN     "test"
00042 
00043 static void
00044 test_create(const atf_tc_t *tc, dns_db_t **old, dns_db_t **new) {
00045         isc_result_t result;
00046 
00047         result = dns_test_loaddb(old, dns_dbtype_zone, TEST_ORIGIN,
00048                                  atf_tc_get_md_var(tc, "X-old"));
00049         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00050 
00051         result = dns_test_loaddb(new, dns_dbtype_zone, TEST_ORIGIN,
00052                                  atf_tc_get_md_var(tc, "X-new"));
00053         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00054 }
00055 
00056 /*
00057  * Individual unit tests
00058  */
00059 
00060 ATF_TC(diffx_same);
00061 ATF_TC_HEAD(diffx_same, tc) {
00062         atf_tc_set_md_var(tc, "descr", "dns_db_diffx of identical content");
00063         atf_tc_set_md_var(tc, "X-old", "testdata/diff/zone1.data");
00064         atf_tc_set_md_var(tc, "X-new", "testdata/diff/zone1.data"); }
00065 ATF_TC_BODY(diffx_same, tc) {
00066         dns_db_t *new = NULL, *old = NULL;
00067         isc_result_t result;
00068         dns_diff_t diff;
00069 
00070         result = dns_test_begin(NULL, ISC_FALSE);
00071         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00072 
00073         test_create(tc, &old, &new);
00074 
00075         dns_diff_init(mctx, &diff);
00076 
00077         result = dns_db_diffx(&diff, new, NULL, old, NULL, NULL);
00078         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00079 
00080         ATF_REQUIRE_EQ(ISC_LIST_EMPTY(diff.tuples), ISC_TRUE);
00081 
00082         dns_diff_clear(&diff);
00083         dns_db_detach(&new);
00084         dns_db_detach(&old);
00085         dns_test_end();
00086 }
00087 
00088 ATF_TC(diffx_add);
00089 ATF_TC_HEAD(diffx_add, tc) {
00090         atf_tc_set_md_var(tc, "descr",
00091                           "dns_db_diffx of zone with record added");
00092         atf_tc_set_md_var(tc, "X-old", "testdata/diff/zone1.data");
00093         atf_tc_set_md_var(tc, "X-new", "testdata/diff/zone2.data");
00094 }
00095 ATF_TC_BODY(diffx_add, tc) {
00096         dns_db_t *new = NULL, *old = NULL;
00097         dns_difftuple_t *tuple;
00098         isc_result_t result;
00099         dns_diff_t diff;
00100         int count = 0;
00101 
00102         result = dns_test_begin(NULL, ISC_FALSE);
00103         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00104 
00105         test_create(tc, &old, &new);
00106 
00107         dns_diff_init(mctx, &diff);
00108 
00109         result = dns_db_diffx(&diff, new, NULL, old, NULL, NULL);
00110         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00111 
00112         ATF_REQUIRE_EQ(ISC_LIST_EMPTY(diff.tuples), ISC_FALSE);
00113         for (tuple = ISC_LIST_HEAD(diff.tuples); tuple != NULL;
00114              tuple = ISC_LIST_NEXT(tuple, link)) {
00115                 ATF_REQUIRE_EQ(tuple->op, DNS_DIFFOP_ADD);
00116                 count++;
00117         }
00118         ATF_REQUIRE_EQ(count, 1);
00119 
00120         dns_diff_clear(&diff);
00121         dns_db_detach(&new);
00122         dns_db_detach(&old);
00123         dns_test_end();
00124 }
00125 
00126 ATF_TC(diffx_remove);
00127 ATF_TC_HEAD(diffx_remove, tc) {
00128         atf_tc_set_md_var(tc, "descr",
00129                           "dns_db_diffx of zone with record removed");
00130         atf_tc_set_md_var(tc, "X-old", "testdata/diff/zone1.data");
00131         atf_tc_set_md_var(tc, "X-new", "testdata/diff/zone3.data");
00132 }
00133 ATF_TC_BODY(diffx_remove, tc) {
00134         dns_db_t *new = NULL, *old = NULL;
00135         dns_difftuple_t *tuple;
00136         isc_result_t result;
00137         dns_diff_t diff;
00138         int count = 0;
00139 
00140         result = dns_test_begin(NULL, ISC_FALSE);
00141         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00142 
00143         test_create(tc, &old, &new);
00144 
00145         dns_diff_init(mctx, &diff);
00146 
00147         result = dns_db_diffx(&diff, new, NULL, old, NULL, NULL);
00148         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00149 
00150         ATF_REQUIRE_EQ(ISC_LIST_EMPTY(diff.tuples), ISC_FALSE);
00151         for (tuple = ISC_LIST_HEAD(diff.tuples); tuple != NULL;
00152              tuple = ISC_LIST_NEXT(tuple, link)) {
00153                 ATF_REQUIRE_EQ(tuple->op, DNS_DIFFOP_DEL);
00154                 count++;
00155         }
00156         ATF_REQUIRE_EQ(count, 1);
00157 
00158         dns_diff_clear(&diff);
00159         dns_db_detach(&new);
00160         dns_db_detach(&old);
00161         dns_test_end();
00162 }
00163 
00164 /*
00165  * Main
00166  */
00167 ATF_TP_ADD_TCS(tp) {
00168         ATF_TP_ADD_TC(tp, diffx_same);
00169         ATF_TP_ADD_TC(tp, diffx_add);
00170         ATF_TP_ADD_TC(tp, diffx_remove);
00171         return (atf_no_error());
00172 }

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