name_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2014  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/name.h>
00028 #include <dns/fixedname.h>
00029 #include "dnstest.h"
00030 
00031 /*
00032  * Individual unit tests
00033  */
00034 
00035 ATF_TC(fullcompare);
00036 ATF_TC_HEAD(fullcompare, tc) {
00037         atf_tc_set_md_var(tc, "descr", "dns_name_fullcompare test");
00038 }
00039 ATF_TC_BODY(fullcompare, tc) {
00040         dns_fixedname_t fixed1;
00041         dns_fixedname_t fixed2;
00042         dns_name_t *name1;
00043         dns_name_t *name2;
00044         dns_namereln_t relation;
00045         int i;
00046         isc_result_t result;
00047         struct {
00048                 const char *name1;
00049                 const char *name2;
00050                 dns_namereln_t relation;
00051                 int order;
00052                 unsigned int nlabels;
00053         } data[] = {
00054                 /* relative */
00055                 { "", "", dns_namereln_equal, 0, 0 },
00056                 { "foo", "", dns_namereln_subdomain, 1, 0 },
00057                 { "", "foo", dns_namereln_contains, -1, 0 },
00058                 { "foo", "bar", dns_namereln_none, 4, 0 },
00059                 { "bar", "foo", dns_namereln_none, -4, 0 },
00060                 { "bar.foo", "foo", dns_namereln_subdomain, 1, 1 },
00061                 { "foo", "bar.foo", dns_namereln_contains, -1, 1 },
00062                 { "baz.bar.foo", "bar.foo", dns_namereln_subdomain, 1, 2 },
00063                 { "bar.foo", "baz.bar.foo", dns_namereln_contains, -1, 2 },
00064                 { "foo.example", "bar.example", dns_namereln_commonancestor,
00065                   4, 1 },
00066 
00067                 /* absolute */
00068                 { ".", ".", dns_namereln_equal, 0, 1 },
00069                 { "foo.", "bar.", dns_namereln_commonancestor, 4, 1 },
00070                 { "bar.", "foo.", dns_namereln_commonancestor, -4, 1 },
00071                 { "foo.example.", "bar.example.", dns_namereln_commonancestor,
00072                   4, 2 },
00073                 { "bar.foo.", "foo.", dns_namereln_subdomain, 1, 2 },
00074                 { "foo.", "bar.foo.", dns_namereln_contains, -1, 2 },
00075                 { "baz.bar.foo.", "bar.foo.", dns_namereln_subdomain, 1, 3 },
00076                 { "bar.foo.", "baz.bar.foo.", dns_namereln_contains, -1, 3 },
00077                 { NULL, NULL, dns_namereln_none, 0, 0 }
00078         };
00079 
00080         UNUSED(tc);
00081 
00082         dns_fixedname_init(&fixed1);
00083         name1 = dns_fixedname_name(&fixed1);
00084         dns_fixedname_init(&fixed2);
00085         name2 = dns_fixedname_name(&fixed2);
00086         for (i = 0; data[i].name1 != NULL; i++) {
00087                 int order = 3000;
00088                 unsigned int nlabels = 3000;
00089 
00090                 if (data[i].name1[0] == 0) {
00091                         dns_fixedname_init(&fixed1);
00092                 } else {
00093                         result = dns_name_fromstring2(name1, data[i].name1,
00094                                                       NULL, 0, NULL);
00095                         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00096                 }
00097                 if (data[i].name2[0] == 0) {
00098                         dns_fixedname_init(&fixed2);
00099                 } else {
00100                         result = dns_name_fromstring2(name2, data[i].name2,
00101                                                       NULL, 0, NULL);
00102                         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00103                 }
00104                 relation = dns_name_fullcompare(name1, name1, &order, &nlabels);
00105                 ATF_REQUIRE_EQ(relation, dns_namereln_equal);
00106                 ATF_REQUIRE_EQ(order, 0);
00107                 ATF_REQUIRE_EQ(nlabels, name1->labels);
00108 
00109                 /* Some random initializer */
00110                 order = 3001;
00111                 nlabels = 3001;
00112 
00113                 relation = dns_name_fullcompare(name1, name2, &order, &nlabels);
00114                 ATF_REQUIRE_EQ(relation, data[i].relation);
00115                 ATF_REQUIRE_EQ(order, data[i].order);
00116                 ATF_REQUIRE_EQ(nlabels, data[i].nlabels);
00117         }
00118 }
00119 
00120 /*
00121  * Main
00122  */
00123 ATF_TP_ADD_TCS(tp) {
00124         ATF_TP_ADD_TC(tp, fullcompare);
00125 
00126         return (atf_no_error());
00127 }
00128 

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