@@ -66,7 +66,7 @@ static int teardown(void **state)
66
66
return 0 ;
67
67
}
68
68
69
- static void test_res_query (void * * state )
69
+ static void test_res_nquery (void * * state )
70
70
{
71
71
int rv ;
72
72
struct __res_state dnsstate ;
@@ -102,7 +102,36 @@ static void test_res_query(void **state)
102
102
res_nclose (& dnsstate );
103
103
}
104
104
105
- static void test_res_search (void * * state )
105
+ static void test_res_query (void * * state )
106
+ {
107
+ int rv ;
108
+ unsigned char answer [ANSIZE ];
109
+ char addr [INET_ADDRSTRLEN ];
110
+ ns_msg handle ;
111
+ ns_rr rr ; /* expanded resource record */
112
+
113
+ (void ) state ; /* unused */
114
+
115
+ rv = res_query ("www.cwrap.org" , ns_c_in , ns_t_a ,
116
+ answer , sizeof (answer ));
117
+ assert_int_not_equal (rv , -1 );
118
+
119
+ ns_initparse (answer , sizeof (answer ), & handle );
120
+ /*
121
+ * The query must finish w/o an error, have one answer and the answer
122
+ * must be a parseable RR of type A and have the address that our
123
+ * test server sends.
124
+ */
125
+ assert_int_equal (ns_msg_getflag (handle , ns_f_rcode ), ns_r_noerror );
126
+ assert_int_equal (ns_msg_count (handle , ns_s_an ), 1 );
127
+ assert_int_equal (ns_parserr (& handle , ns_s_an , 0 , & rr ), 0 );
128
+ assert_int_equal (ns_rr_type (rr ), ns_t_a );
129
+ assert_non_null (inet_ntop (AF_INET , ns_rr_rdata (rr ),
130
+ addr , sizeof (addr )));
131
+ assert_string_equal (addr , "127.0.10.10" );
132
+ }
133
+
134
+ static void test_res_nsearch (void * * state )
106
135
{
107
136
int rv ;
108
137
struct __res_state dnsstate ;
@@ -137,14 +166,48 @@ static void test_res_search(void **state)
137
166
res_nclose (& dnsstate );
138
167
}
139
168
169
+ static void test_res_search (void * * state )
170
+ {
171
+ int rv ;
172
+ unsigned char answer [ANSIZE ];
173
+ char addr [INET_ADDRSTRLEN ];
174
+ ns_msg handle ;
175
+ ns_rr rr ; /* expanded resource record */
176
+
177
+ (void ) state ; /* unused */
178
+
179
+ rv = res_search ("www.cwrap.org" , ns_c_in , ns_t_a ,
180
+ answer , sizeof (answer ));
181
+ assert_int_not_equal (rv , -1 );
182
+
183
+ ns_initparse (answer , sizeof (answer ), & handle );
184
+ /* The query must finish w/o an error, have one answer and the answer
185
+ * must be a parseable RR of type A and have the address that our
186
+ * test server sends
187
+ */
188
+ assert_int_equal (ns_msg_getflag (handle , ns_f_rcode ), ns_r_noerror );
189
+ assert_int_equal (ns_msg_count (handle , ns_s_an ), 1 );
190
+ assert_int_equal (ns_parserr (& handle , ns_s_an , 0 , & rr ), 0 );
191
+ assert_int_equal (ns_rr_type (rr ), ns_t_a );
192
+ assert_non_null (inet_ntop (AF_INET , ns_rr_rdata (rr ),
193
+ addr , sizeof (addr )));
194
+ assert_string_equal (addr , "127.0.10.10" );
195
+ }
196
+
140
197
int main (void )
141
198
{
142
199
int rc ;
143
200
144
201
const struct CMUnitTest res_tests [] = {
202
+ cmocka_unit_test_setup_teardown (test_res_nquery ,
203
+ setup_dns_srv_ipv4 ,
204
+ teardown ),
145
205
cmocka_unit_test_setup_teardown (test_res_query ,
146
206
setup_dns_srv_ipv4 ,
147
207
teardown ),
208
+ cmocka_unit_test_setup_teardown (test_res_nsearch ,
209
+ setup_dns_srv_ipv4 ,
210
+ teardown ),
148
211
cmocka_unit_test_setup_teardown (test_res_search ,
149
212
setup_dns_srv_ipv4 ,
150
213
teardown ),
0 commit comments