1 /* $NetBSD: peer_test.c,v 1.1.1.3 2014/12/10 03:34:43 christos Exp $ */
2
3 /*
4 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /*! \file */
20
21 #include <config.h>
22
23 #include <atf-c.h>
24
25 #include <unistd.h>
26
27 #include <dns/peer.h>
28
29 #include "dnstest.h"
30
31 /*
32 * Individual unit tests
33 */
34 ATF_TC(dscp);
ATF_TC_HEAD(dscp,tc)35 ATF_TC_HEAD(dscp, tc) {
36 atf_tc_set_md_var(tc, "descr",
37 "Test DSCP set/get functions");
38 }
ATF_TC_BODY(dscp,tc)39 ATF_TC_BODY(dscp, tc) {
40 isc_result_t result;
41 isc_netaddr_t netaddr;
42 struct in_addr ina;
43 dns_peer_t *peer = NULL;
44 isc_dscp_t dscp;
45
46 result = dns_test_begin(NULL, ISC_TRUE);
47 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
48
49 /*
50 * Create peer structure for the loopback address.
51 */
52 ina.s_addr = INADDR_LOOPBACK;
53 isc_netaddr_fromin(&netaddr, &ina);
54 result = dns_peer_new(mctx, &netaddr, &peer);
55 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
56
57 /*
58 * All should be not set on creation.
59 * 'dscp' should remain unchanged.
60 */
61 dscp = 100;
62 result = dns_peer_getquerydscp(peer, &dscp);
63 ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
64 ATF_REQUIRE_EQ(dscp, 100);
65
66 result = dns_peer_getnotifydscp(peer, &dscp);
67 ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
68 ATF_REQUIRE_EQ(dscp, 100);
69
70 result = dns_peer_gettransferdscp(peer, &dscp);
71 ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
72 ATF_REQUIRE_EQ(dscp, 100);
73
74 /*
75 * Test that setting query dscp does not affect the other
76 * dscp values. 'dscp' should remain unchanged until
77 * dns_peer_getquerydscp is called.
78 */
79 dscp = 100;
80 result = dns_peer_setquerydscp(peer, 1);
81 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
82
83 result = dns_peer_getnotifydscp(peer, &dscp);
84 ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
85 ATF_REQUIRE_EQ(dscp, 100);
86
87 result = dns_peer_gettransferdscp(peer, &dscp);
88 ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
89 ATF_REQUIRE_EQ(dscp, 100);
90
91 result = dns_peer_getquerydscp(peer, &dscp);
92 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
93 ATF_REQUIRE_EQ(dscp, 1);
94
95 /*
96 * Test that setting notify dscp does not affect the other
97 * dscp values. 'dscp' should remain unchanged until
98 * dns_peer_getquerydscp is called then should change again
99 * on dns_peer_getnotifydscp.
100 */
101 dscp = 100;
102 result = dns_peer_setnotifydscp(peer, 2);
103 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
104
105 result = dns_peer_gettransferdscp(peer, &dscp);
106 ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
107 ATF_REQUIRE_EQ(dscp, 100);
108
109 result = dns_peer_getquerydscp(peer, &dscp);
110 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
111 ATF_REQUIRE_EQ(dscp, 1);
112
113 result = dns_peer_getnotifydscp(peer, &dscp);
114 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
115 ATF_REQUIRE_EQ(dscp, 2);
116
117 /*
118 * Test that setting notify dscp does not affect the other
119 * dscp values. Check that appropriate values are returned.
120 */
121 dscp = 100;
122 result = dns_peer_settransferdscp(peer, 3);
123 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
124
125 result = dns_peer_getquerydscp(peer, &dscp);
126 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
127 ATF_REQUIRE_EQ(dscp, 1);
128
129 result = dns_peer_getnotifydscp(peer, &dscp);
130 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
131 ATF_REQUIRE_EQ(dscp, 2);
132
133 result = dns_peer_gettransferdscp(peer, &dscp);
134 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
135 ATF_REQUIRE_EQ(dscp, 3);
136
137 dns_peer_detach(&peer);
138 dns_test_end();
139 }
140
141 /*
142 * Main
143 */
ATF_TP_ADD_TCS(tp)144 ATF_TP_ADD_TCS(tp) {
145 ATF_TP_ADD_TC(tp, dscp);
146 return (atf_no_error());
147 }
148