radix_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 #include <config.h>
00018 
00019 #include <isc/mem.h>
00020 #include <isc/netaddr.h>
00021 #include <isc/radix.h>
00022 #include <isc/result.h>
00023 #include <isc/util.h>
00024 
00025 #include <atf-c.h>
00026 
00027 #include <stdlib.h>
00028 #include <stdint.h>
00029 
00030 #include "isctest.h"
00031 
00032 ATF_TC(isc_radix_search);
00033 ATF_TC_HEAD(isc_radix_search, tc) {
00034         atf_tc_set_md_var(tc, "descr", "test radix seaching");
00035 }
00036 ATF_TC_BODY(isc_radix_search, tc) {
00037         isc_radix_tree_t *radix = NULL;
00038         isc_radix_node_t *node;
00039         isc_prefix_t prefix;
00040         isc_result_t result;
00041         struct in_addr in_addr;
00042         isc_netaddr_t netaddr;
00043 
00044         UNUSED(tc);
00045 
00046         result = isc_test_begin(NULL, ISC_TRUE);
00047         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00048 
00049         result = isc_radix_create(mctx, &radix, 32);
00050         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00051 
00052         in_addr.s_addr = inet_addr("3.3.3.0");
00053         isc_netaddr_fromin(&netaddr, &in_addr);
00054         NETADDR_TO_PREFIX_T(&netaddr, prefix, 24, ISC_FALSE);
00055 
00056         node = NULL;
00057         result = isc_radix_insert(radix, &node, NULL, &prefix);
00058         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00059         node->data[0] = (void *)1;
00060         isc_refcount_destroy(&prefix.refcount);
00061 
00062         in_addr.s_addr = inet_addr("3.3.0.0");
00063         isc_netaddr_fromin(&netaddr, &in_addr);
00064         NETADDR_TO_PREFIX_T(&netaddr, prefix, 16, ISC_FALSE);
00065 
00066         node = NULL;
00067         result = isc_radix_insert(radix, &node, NULL, &prefix);
00068         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00069         node->data[0] = (void *)2;
00070         isc_refcount_destroy(&prefix.refcount);
00071 
00072         in_addr.s_addr = inet_addr("3.3.3.3");
00073         isc_netaddr_fromin(&netaddr, &in_addr);
00074         NETADDR_TO_PREFIX_T(&netaddr, prefix, 22, ISC_FALSE);
00075 
00076         node = NULL;
00077         result = isc_radix_search(radix, &node, &prefix);
00078         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00079         ATF_REQUIRE_EQ(node->data[0], (void *)2);
00080 
00081         isc_refcount_destroy(&prefix.refcount);
00082 
00083         isc_radix_destroy(radix, NULL);
00084 
00085         isc_test_end();
00086 }
00087 
00088 /*
00089  * Main
00090  */
00091 ATF_TP_ADD_TCS(tp) {
00092         ATF_TP_ADD_TC(tp, isc_radix_search);
00093 
00094         return (atf_no_error());
00095 }

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