peer_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 /*! \file */
00018 
00019 #include <config.h>
00020 
00021 #include <atf-c.h>
00022 
00023 #include <unistd.h>
00024 
00025 #include <dns/peer.h>
00026 
00027 #include "dnstest.h"
00028 
00029 /*
00030  * Individual unit tests
00031  */
00032 ATF_TC(dscp);
00033 ATF_TC_HEAD(dscp, tc) {
00034         atf_tc_set_md_var(tc, "descr",
00035                           "Test DSCP set/get functions");
00036 }
00037 ATF_TC_BODY(dscp, tc) {
00038         isc_result_t result;
00039         isc_netaddr_t netaddr;
00040         struct in_addr ina;
00041         dns_peer_t *peer = NULL;
00042         isc_dscp_t dscp;
00043 
00044         result = dns_test_begin(NULL, ISC_TRUE);
00045         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00046 
00047         /*
00048          * Create peer structure for the loopback address.
00049          */
00050         ina.s_addr = INADDR_LOOPBACK;
00051         isc_netaddr_fromin(&netaddr, &ina);
00052         result = dns_peer_new(mctx, &netaddr, &peer);
00053         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00054 
00055         /*
00056          * All should be not set on creation.
00057          * 'dscp' should remain unchanged.
00058          */
00059         dscp = 100;
00060         result = dns_peer_getquerydscp(peer, &dscp);
00061         ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
00062         ATF_REQUIRE_EQ(dscp, 100);
00063 
00064         result = dns_peer_getnotifydscp(peer, &dscp);
00065         ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
00066         ATF_REQUIRE_EQ(dscp, 100);
00067 
00068         result = dns_peer_gettransferdscp(peer, &dscp);
00069         ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
00070         ATF_REQUIRE_EQ(dscp, 100);
00071 
00072         /*
00073          * Test that setting query dscp does not affect the other
00074          * dscp values.  'dscp' should remain unchanged until
00075          * dns_peer_getquerydscp is called.
00076          */
00077         dscp = 100;
00078         result = dns_peer_setquerydscp(peer, 1);
00079         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00080 
00081         result = dns_peer_getnotifydscp(peer, &dscp);
00082         ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
00083         ATF_REQUIRE_EQ(dscp, 100);
00084 
00085         result = dns_peer_gettransferdscp(peer, &dscp);
00086         ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
00087         ATF_REQUIRE_EQ(dscp, 100);
00088 
00089         result = dns_peer_getquerydscp(peer, &dscp);
00090         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00091         ATF_REQUIRE_EQ(dscp, 1);
00092 
00093         /*
00094          * Test that setting notify dscp does not affect the other
00095          * dscp values.  'dscp' should remain unchanged until
00096          * dns_peer_getquerydscp is called then should change again
00097          * on dns_peer_getnotifydscp.
00098          */
00099         dscp = 100;
00100         result = dns_peer_setnotifydscp(peer, 2);
00101         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00102 
00103         result = dns_peer_gettransferdscp(peer, &dscp);
00104         ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
00105         ATF_REQUIRE_EQ(dscp, 100);
00106 
00107         result = dns_peer_getquerydscp(peer, &dscp);
00108         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00109         ATF_REQUIRE_EQ(dscp, 1);
00110 
00111         result = dns_peer_getnotifydscp(peer, &dscp);
00112         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00113         ATF_REQUIRE_EQ(dscp, 2);
00114 
00115         /*
00116          * Test that setting notify dscp does not affect the other
00117          * dscp values.  Check that appropriate values are returned.
00118          */
00119         dscp = 100;
00120         result = dns_peer_settransferdscp(peer, 3);
00121         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00122 
00123         result = dns_peer_getquerydscp(peer, &dscp);
00124         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00125         ATF_REQUIRE_EQ(dscp, 1);
00126 
00127         result = dns_peer_getnotifydscp(peer, &dscp);
00128         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00129         ATF_REQUIRE_EQ(dscp, 2);
00130 
00131         result = dns_peer_gettransferdscp(peer, &dscp);
00132         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00133         ATF_REQUIRE_EQ(dscp, 3);
00134 
00135         dns_peer_detach(&peer);
00136         dns_test_end();
00137 }
00138 
00139 /*
00140  * Main
00141  */
00142 ATF_TP_ADD_TCS(tp) {
00143         ATF_TP_ADD_TC(tp, dscp);
00144         return (atf_no_error());
00145 }

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