12 using testing::InvokeWithoutArgs;
18 TEST_P(MockChannelTest, Basic) {
19 std::vector<byte> reply = {
21 0x84, // response + query + AA + not-TC + not-RD
22 0x00, // not-RA + not-Z + not-AD + not-CD + rc=NoError
23 0x00, 0x01, // 1 question
24 0x00, 0x01, // 1 answer RRs
25 0x00, 0x00, // 0 authority RRs
26 0x00, 0x00, // 0 additional RRs
29 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
33 0x00, 0x01, // class IN
36 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
40 0x00, 0x01, // class IN
41 0x00, 0x00, 0x01, 0x00, // TTL
42 0x00, 0x04, // rdata length
43 0x01, 0x02, 0x03, 0x04
46 ON_CALL(server_, OnRequest("www.google.com", T_A))
47 .WillByDefault(SetReplyData(&server_, reply));
50 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
52 EXPECT_TRUE(result.done_);
55 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
58 // UDP only so mock server doesn't get confused by concatenated requests
59 TEST_P(MockUDPChannelTest, GetHostByNameParallelLookups) {
61 rsp1.set_response().set_aa()
62 .add_question(new DNSQuestion("www.google.com", T_A))
63 .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
64 ON_CALL(server_, OnRequest("www.google.com", T_A))
65 .WillByDefault(SetReply(&server_, &rsp1));
67 rsp2.set_response().set_aa()
68 .add_question(new DNSQuestion("www.example.com", T_A))
69 .add_answer(new DNSARR("www.example.com", 100, {1, 2, 3, 4}));
70 ON_CALL(server_, OnRequest("www.example.com", T_A))
71 .WillByDefault(SetReply(&server_, &rsp2));
74 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result1);
76 ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result2);
78 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result3);
80 EXPECT_TRUE(result1.done_);
81 EXPECT_TRUE(result2.done_);
82 EXPECT_TRUE(result3.done_);
83 std::stringstream ss1;
85 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss1.str());
86 std::stringstream ss2;
88 EXPECT_EQ("{'www.example.com' aliases=[] addrs=[1.2.3.4]}", ss2.str());
89 std::stringstream ss3;
91 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss3.str());
94 // UDP to TCP specific test
95 TEST_P(MockUDPChannelTest, TruncationRetry) {
96 DNSPacket rsptruncated;
97 rsptruncated.set_response().set_aa().set_tc()
98 .add_question(new DNSQuestion("www.google.com", T_A));
101 .add_question(new DNSQuestion("www.google.com", T_A))
102 .add_answer(new DNSARR("www.google.com", 100, {1, 2, 3, 4}));
103 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
104 .WillOnce(SetReply(&server_, &rsptruncated))
105 .WillOnce(SetReply(&server_, &rspok));
107 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
109 EXPECT_TRUE(result.done_);
110 std::stringstream ss;
112 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
115 static int sock_cb_count = 0;
116 static int SocketConnectCallback(ares_socket_t fd, int type, void *data) {
117 int rc = *(int*)data;
118 if (verbose) std::cerr << "SocketConnectCallback(" << fd << ") invoked" << std::endl;
123 TEST_P(MockChannelTest, SockCallback) {
125 rsp.set_response().set_aa()
126 .add_question(new DNSQuestion("www.google.com", T_A))
127 .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
128 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
129 .WillOnce(SetReply(&server_, &rsp));
131 // Get notified of new sockets
132 int rc = ARES_SUCCESS;
133 ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
137 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
139 EXPECT_EQ(1, sock_cb_count);
140 EXPECT_TRUE(result.done_);
141 std::stringstream ss;
143 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
146 TEST_P(MockChannelTest, SockFailCallback) {
147 // Notification of new sockets gives an error.
149 ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
153 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
155 EXPECT_LT(1, sock_cb_count);
156 EXPECT_TRUE(result.done_);
157 EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
160 static int sock_config_cb_count = 0;
161 static int SocketConfigureCallback(ares_socket_t fd, int type, void *data) {
162 int rc = *(int*)data;
163 if (verbose) std::cerr << "SocketConfigureCallback(" << fd << ") invoked" << std::endl;
164 sock_config_cb_count++;
168 TEST_P(MockChannelTest, SockConfigureCallback) {
170 rsp.set_response().set_aa()
171 .add_question(new DNSQuestion("www.google.com", T_A))
172 .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
173 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
174 .WillOnce(SetReply(&server_, &rsp));
176 // Get notified of new sockets
177 int rc = ARES_SUCCESS;
178 ares_set_socket_configure_callback(channel_, SocketConfigureCallback, &rc);
181 sock_config_cb_count = 0;
182 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
184 EXPECT_EQ(1, sock_config_cb_count);
185 EXPECT_TRUE(result.done_);
186 std::stringstream ss;
188 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
191 TEST_P(MockChannelTest, SockConfigureFailCallback) {
192 // Notification of new sockets gives an error.
194 ares_set_socket_configure_callback(channel_, SocketConfigureCallback, &rc);
197 sock_config_cb_count = 0;
198 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
200 EXPECT_LT(1, sock_config_cb_count);
201 EXPECT_TRUE(result.done_);
202 EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
205 // TCP only to prevent retries
206 TEST_P(MockTCPChannelTest, MalformedResponse) {
207 std::vector<byte> one = {0x01};
208 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
209 .WillOnce(SetReplyData(&server_, one));
212 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
214 EXPECT_TRUE(result.done_);
215 EXPECT_EQ(ARES_ETIMEOUT, result.status_);
218 TEST_P(MockTCPChannelTest, FormErrResponse) {
220 rsp.set_response().set_aa()
221 .add_question(new DNSQuestion("www.google.com", T_A));
222 rsp.set_rcode(FORMERR);
223 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
224 .WillOnce(SetReply(&server_, &rsp));
226 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
228 EXPECT_TRUE(result.done_);
229 EXPECT_EQ(ARES_EFORMERR, result.status_);
232 TEST_P(MockTCPChannelTest, ServFailResponse) {
234 rsp.set_response().set_aa()
235 .add_question(new DNSQuestion("www.google.com", T_A));
236 rsp.set_rcode(SERVFAIL);
237 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
238 .WillOnce(SetReply(&server_, &rsp));
240 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
242 EXPECT_TRUE(result.done_);
243 // ARES_FLAG_NOCHECKRESP not set, so SERVFAIL consumed
244 EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
247 TEST_P(MockTCPChannelTest, NotImplResponse) {
249 rsp.set_response().set_aa()
250 .add_question(new DNSQuestion("www.google.com", T_A));
251 rsp.set_rcode(NOTIMP);
252 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
253 .WillOnce(SetReply(&server_, &rsp));
255 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
257 EXPECT_TRUE(result.done_);
258 // ARES_FLAG_NOCHECKRESP not set, so NOTIMP consumed
259 EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
262 TEST_P(MockTCPChannelTest, RefusedResponse) {
264 rsp.set_response().set_aa()
265 .add_question(new DNSQuestion("www.google.com", T_A));
266 rsp.set_rcode(REFUSED);
267 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
268 .WillOnce(SetReply(&server_, &rsp));
270 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
272 EXPECT_TRUE(result.done_);
273 // ARES_FLAG_NOCHECKRESP not set, so REFUSED consumed
274 EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
277 TEST_P(MockTCPChannelTest, YXDomainResponse) {
279 rsp.set_response().set_aa()
280 .add_question(new DNSQuestion("www.google.com", T_A));
281 rsp.set_rcode(YXDOMAIN);
282 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
283 .WillOnce(SetReply(&server_, &rsp));
285 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
287 EXPECT_TRUE(result.done_);
288 EXPECT_EQ(ARES_ENODATA, result.status_);
291 class MockExtraOptsTest
292 : public MockChannelOptsTest,
293 public ::testing::WithParamInterface< std::pair<int, bool> > {
296 : MockChannelOptsTest(1, GetParam().first, GetParam().second,
298 ARES_OPT_SOCK_SNDBUF|ARES_OPT_SOCK_RCVBUF) {}
299 static struct ares_options* FillOptions(struct ares_options * opts) {
300 memset(opts, 0, sizeof(struct ares_options));
301 // Set a few options that affect socket communications
302 opts->socket_send_buffer_size = 514;
303 opts->socket_receive_buffer_size = 514;
307 struct ares_options opts_;
310 TEST_P(MockExtraOptsTest, SimpleQuery) {
311 ares_set_local_ip4(channel_, 0x7F000001);
312 byte addr6[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
314 ares_set_local_ip6(channel_, addr6);
315 ares_set_local_dev(channel_, "dummy");
318 rsp.set_response().set_aa()
319 .add_question(new DNSQuestion("www.google.com", T_A))
320 .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
321 ON_CALL(server_, OnRequest("www.google.com", T_A))
322 .WillByDefault(SetReply(&server_, &rsp));
325 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
327 EXPECT_TRUE(result.done_);
328 std::stringstream ss;
330 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
333 class MockFlagsChannelOptsTest
334 : public MockChannelOptsTest,
335 public ::testing::WithParamInterface< std::pair<int, bool> > {
337 MockFlagsChannelOptsTest(int flags)
338 : MockChannelOptsTest(1, GetParam().first, GetParam().second,
339 FillOptions(&opts_, flags), ARES_OPT_FLAGS) {}
340 static struct ares_options* FillOptions(struct ares_options * opts, int flags) {
341 memset(opts, 0, sizeof(struct ares_options));
346 struct ares_options opts_;
349 class MockNoCheckRespChannelTest : public MockFlagsChannelOptsTest {
351 MockNoCheckRespChannelTest() : MockFlagsChannelOptsTest(ARES_FLAG_NOCHECKRESP) {}
354 TEST_P(MockNoCheckRespChannelTest, ServFailResponse) {
356 rsp.set_response().set_aa()
357 .add_question(new DNSQuestion("www.google.com", T_A));
358 rsp.set_rcode(SERVFAIL);
359 ON_CALL(server_, OnRequest("www.google.com", T_A))
360 .WillByDefault(SetReply(&server_, &rsp));
362 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
364 EXPECT_TRUE(result.done_);
365 EXPECT_EQ(ARES_ESERVFAIL, result.status_);
368 TEST_P(MockNoCheckRespChannelTest, NotImplResponse) {
370 rsp.set_response().set_aa()
371 .add_question(new DNSQuestion("www.google.com", T_A));
372 rsp.set_rcode(NOTIMP);
373 ON_CALL(server_, OnRequest("www.google.com", T_A))
374 .WillByDefault(SetReply(&server_, &rsp));
376 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
378 EXPECT_TRUE(result.done_);
379 EXPECT_EQ(ARES_ENOTIMP, result.status_);
382 TEST_P(MockNoCheckRespChannelTest, RefusedResponse) {
384 rsp.set_response().set_aa()
385 .add_question(new DNSQuestion("www.google.com", T_A));
386 rsp.set_rcode(REFUSED);
387 ON_CALL(server_, OnRequest("www.google.com", T_A))
388 .WillByDefault(SetReply(&server_, &rsp));
390 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
392 EXPECT_TRUE(result.done_);
393 EXPECT_EQ(ARES_EREFUSED, result.status_);
396 class MockEDNSChannelTest : public MockFlagsChannelOptsTest {
398 MockEDNSChannelTest() : MockFlagsChannelOptsTest(ARES_FLAG_EDNS) {}
401 TEST_P(MockEDNSChannelTest, RetryWithoutEDNS) {
403 rspfail.set_response().set_aa().set_rcode(FORMERR)
404 .add_question(new DNSQuestion("www.google.com", T_A));
407 .add_question(new DNSQuestion("www.google.com", T_A))
408 .add_answer(new DNSARR("www.google.com", 100, {1, 2, 3, 4}));
409 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
410 .WillOnce(SetReply(&server_, &rspfail))
411 .WillOnce(SetReply(&server_, &rspok));
413 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
415 EXPECT_TRUE(result.done_);
416 std::stringstream ss;
418 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
421 TEST_P(MockChannelTest, SearchDomains) {
423 nofirst.set_response().set_aa().set_rcode(NXDOMAIN)
424 .add_question(new DNSQuestion("www.first.com", T_A));
425 ON_CALL(server_, OnRequest("www.first.com", T_A))
426 .WillByDefault(SetReply(&server_, &nofirst));
428 nosecond.set_response().set_aa().set_rcode(NXDOMAIN)
429 .add_question(new DNSQuestion("www.second.org", T_A));
430 ON_CALL(server_, OnRequest("www.second.org", T_A))
431 .WillByDefault(SetReply(&server_, &nosecond));
433 yesthird.set_response().set_aa()
434 .add_question(new DNSQuestion("www.third.gov", T_A))
435 .add_answer(new DNSARR("www.third.gov", 0x0200, {2, 3, 4, 5}));
436 ON_CALL(server_, OnRequest("www.third.gov", T_A))
437 .WillByDefault(SetReply(&server_, &yesthird));
440 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
442 EXPECT_TRUE(result.done_);
443 std::stringstream ss;
445 EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str());
448 // Relies on retries so is UDP-only
449 TEST_P(MockUDPChannelTest, SearchDomainsWithResentReply) {
451 nofirst.set_response().set_aa().set_rcode(NXDOMAIN)
452 .add_question(new DNSQuestion("www.first.com", T_A));
453 EXPECT_CALL(server_, OnRequest("www.first.com", T_A))
454 .WillOnce(SetReply(&server_, &nofirst));
456 nosecond.set_response().set_aa().set_rcode(NXDOMAIN)
457 .add_question(new DNSQuestion("www.second.org", T_A));
458 EXPECT_CALL(server_, OnRequest("www.second.org", T_A))
459 .WillOnce(SetReply(&server_, &nosecond));
461 yesthird.set_response().set_aa()
462 .add_question(new DNSQuestion("www.third.gov", T_A))
463 .add_answer(new DNSARR("www.third.gov", 0x0200, {2, 3, 4, 5}));
464 // Before sending the real answer, resend an earlier reply
465 EXPECT_CALL(server_, OnRequest("www.third.gov", T_A))
466 .WillOnce(DoAll(SetReply(&server_, &nofirst),
467 SetReplyQID(&server_, 123)))
468 .WillOnce(DoAll(SetReply(&server_, &yesthird),
469 SetReplyQID(&server_, -1)));
472 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
474 EXPECT_TRUE(result.done_);
475 std::stringstream ss;
477 EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str());
480 TEST_P(MockChannelTest, SearchDomainsBare) {
482 nofirst.set_response().set_aa().set_rcode(NXDOMAIN)
483 .add_question(new DNSQuestion("www.first.com", T_A));
484 ON_CALL(server_, OnRequest("www.first.com", T_A))
485 .WillByDefault(SetReply(&server_, &nofirst));
487 nosecond.set_response().set_aa().set_rcode(NXDOMAIN)
488 .add_question(new DNSQuestion("www.second.org", T_A));
489 ON_CALL(server_, OnRequest("www.second.org", T_A))
490 .WillByDefault(SetReply(&server_, &nosecond));
492 nothird.set_response().set_aa().set_rcode(NXDOMAIN)
493 .add_question(new DNSQuestion("www.third.gov", T_A));
494 ON_CALL(server_, OnRequest("www.third.gov", T_A))
495 .WillByDefault(SetReply(&server_, ¬hird));
497 yesbare.set_response().set_aa()
498 .add_question(new DNSQuestion("www", T_A))
499 .add_answer(new DNSARR("www", 0x0200, {2, 3, 4, 5}));
500 ON_CALL(server_, OnRequest("www", T_A))
501 .WillByDefault(SetReply(&server_, &yesbare));
504 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
506 EXPECT_TRUE(result.done_);
507 std::stringstream ss;
509 EXPECT_EQ("{'www' aliases=[] addrs=[2.3.4.5]}", ss.str());
512 TEST_P(MockChannelTest, SearchNoDataThenSuccess) {
513 // First two search domains recognize the name but have no A records.
515 nofirst.set_response().set_aa()
516 .add_question(new DNSQuestion("www.first.com", T_A));
517 ON_CALL(server_, OnRequest("www.first.com", T_A))
518 .WillByDefault(SetReply(&server_, &nofirst));
520 nosecond.set_response().set_aa()
521 .add_question(new DNSQuestion("www.second.org", T_A));
522 ON_CALL(server_, OnRequest("www.second.org", T_A))
523 .WillByDefault(SetReply(&server_, &nosecond));
525 yesthird.set_response().set_aa()
526 .add_question(new DNSQuestion("www.third.gov", T_A))
527 .add_answer(new DNSARR("www.third.gov", 0x0200, {2, 3, 4, 5}));
528 ON_CALL(server_, OnRequest("www.third.gov", T_A))
529 .WillByDefault(SetReply(&server_, &yesthird));
532 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
534 EXPECT_TRUE(result.done_);
535 std::stringstream ss;
537 EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str());
540 TEST_P(MockChannelTest, SearchNoDataThenNoDataBare) {
541 // First two search domains recognize the name but have no A records.
543 nofirst.set_response().set_aa()
544 .add_question(new DNSQuestion("www.first.com", T_A));
545 ON_CALL(server_, OnRequest("www.first.com", T_A))
546 .WillByDefault(SetReply(&server_, &nofirst));
548 nosecond.set_response().set_aa()
549 .add_question(new DNSQuestion("www.second.org", T_A));
550 ON_CALL(server_, OnRequest("www.second.org", T_A))
551 .WillByDefault(SetReply(&server_, &nosecond));
553 nothird.set_response().set_aa()
554 .add_question(new DNSQuestion("www.third.gov", T_A));
555 ON_CALL(server_, OnRequest("www.third.gov", T_A))
556 .WillByDefault(SetReply(&server_, ¬hird));
558 nobare.set_response().set_aa()
559 .add_question(new DNSQuestion("www", T_A));
560 ON_CALL(server_, OnRequest("www", T_A))
561 .WillByDefault(SetReply(&server_, &nobare));
564 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
566 EXPECT_TRUE(result.done_);
567 EXPECT_EQ(ARES_ENODATA, result.status_);
570 TEST_P(MockChannelTest, SearchNoDataThenFail) {
571 // First two search domains recognize the name but have no A records.
573 nofirst.set_response().set_aa()
574 .add_question(new DNSQuestion("www.first.com", T_A));
575 ON_CALL(server_, OnRequest("www.first.com", T_A))
576 .WillByDefault(SetReply(&server_, &nofirst));
578 nosecond.set_response().set_aa()
579 .add_question(new DNSQuestion("www.second.org", T_A));
580 ON_CALL(server_, OnRequest("www.second.org", T_A))
581 .WillByDefault(SetReply(&server_, &nosecond));
583 nothird.set_response().set_aa()
584 .add_question(new DNSQuestion("www.third.gov", T_A));
585 ON_CALL(server_, OnRequest("www.third.gov", T_A))
586 .WillByDefault(SetReply(&server_, ¬hird));
588 nobare.set_response().set_aa().set_rcode(NXDOMAIN)
589 .add_question(new DNSQuestion("www", T_A));
590 ON_CALL(server_, OnRequest("www", T_A))
591 .WillByDefault(SetReply(&server_, &nobare));
594 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
596 EXPECT_TRUE(result.done_);
597 EXPECT_EQ(ARES_ENODATA, result.status_);
600 TEST_P(MockChannelTest, SearchAllocFailure) {
603 ares_search(channel_, "fully.qualified.", C_IN, T_A, SearchCallback, &result);
605 EXPECT_TRUE(result.done_);
606 EXPECT_EQ(ARES_ENOMEM, result.status_);
609 TEST_P(MockChannelTest, SearchHighNdots) {
611 nobare.set_response().set_aa().set_rcode(NXDOMAIN)
612 .add_question(new DNSQuestion("a.b.c.w.w.w", T_A));
613 ON_CALL(server_, OnRequest("a.b.c.w.w.w", T_A))
614 .WillByDefault(SetReply(&server_, &nobare));
616 yesfirst.set_response().set_aa()
617 .add_question(new DNSQuestion("a.b.c.w.w.w.first.com", T_A))
618 .add_answer(new DNSARR("a.b.c.w.w.w.first.com", 0x0200, {2, 3, 4, 5}));
619 ON_CALL(server_, OnRequest("a.b.c.w.w.w.first.com", T_A))
620 .WillByDefault(SetReply(&server_, &yesfirst));
623 ares_search(channel_, "a.b.c.w.w.w", C_IN, T_A, SearchCallback, &result);
625 EXPECT_TRUE(result.done_);
626 EXPECT_EQ(ARES_SUCCESS, result.status_);
627 std::stringstream ss;
628 ss << PacketToString(result.data_);
629 EXPECT_EQ("RSP QRY AA NOERROR Q:{'a.b.c.w.w.w.first.com' IN A} "
630 "A:{'a.b.c.w.w.w.first.com' IN A TTL=512 2.3.4.5}",
634 TEST_P(MockChannelTest, UnspecifiedFamilyV6) {
636 rsp6.set_response().set_aa()
637 .add_question(new DNSQuestion("example.com", T_AAAA))
638 .add_answer(new DNSAaaaRR("example.com", 100,
639 {0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
640 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03}));
641 ON_CALL(server_, OnRequest("example.com", T_AAAA))
642 .WillByDefault(SetReply(&server_, &rsp6));
645 rsp4.set_response().set_aa()
646 .add_question(new DNSQuestion("example.com", T_A));
647 ON_CALL(server_, OnRequest("example.com", T_A))
648 .WillByDefault(SetReply(&server_, &rsp4));
651 ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
653 EXPECT_TRUE(result.done_);
654 std::stringstream ss;
656 // Default to IPv6 when both are available.
657 EXPECT_EQ("{'example.com' aliases=[] addrs=[2121:0000:0000:0000:0000:0000:0000:0303]}", ss.str());
660 TEST_P(MockChannelTest, UnspecifiedFamilyV4) {
662 rsp6.set_response().set_aa()
663 .add_question(new DNSQuestion("example.com", T_AAAA));
664 ON_CALL(server_, OnRequest("example.com", T_AAAA))
665 .WillByDefault(SetReply(&server_, &rsp6));
667 rsp4.set_response().set_aa()
668 .add_question(new DNSQuestion("example.com", T_A))
669 .add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5}));
670 ON_CALL(server_, OnRequest("example.com", T_A))
671 .WillByDefault(SetReply(&server_, &rsp4));
674 ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
676 EXPECT_TRUE(result.done_);
677 std::stringstream ss;
679 EXPECT_EQ("{'example.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
682 TEST_P(MockChannelTest, UnspecifiedFamilyNoData) {
684 rsp6.set_response().set_aa()
685 .add_question(new DNSQuestion("example.com", T_AAAA))
686 .add_answer(new DNSCnameRR("example.com", 100, "elsewhere.com"));
687 ON_CALL(server_, OnRequest("example.com", T_AAAA))
688 .WillByDefault(SetReply(&server_, &rsp6));
690 rsp4.set_response().set_aa()
691 .add_question(new DNSQuestion("example.com", T_A));
692 ON_CALL(server_, OnRequest("example.com", T_A))
693 .WillByDefault(SetReply(&server_, &rsp4));
696 ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
698 EXPECT_TRUE(result.done_);
699 std::stringstream ss;
701 EXPECT_EQ("{'' aliases=[] addrs=[]}", ss.str());
704 TEST_P(MockChannelTest, UnspecifiedFamilyCname6A4) {
706 rsp6.set_response().set_aa()
707 .add_question(new DNSQuestion("example.com", T_AAAA))
708 .add_answer(new DNSCnameRR("example.com", 100, "elsewhere.com"));
709 ON_CALL(server_, OnRequest("example.com", T_AAAA))
710 .WillByDefault(SetReply(&server_, &rsp6));
712 rsp4.set_response().set_aa()
713 .add_question(new DNSQuestion("example.com", T_A))
714 .add_answer(new DNSARR("example.com", 100, {1, 2, 3, 4}));
715 ON_CALL(server_, OnRequest("example.com", T_A))
716 .WillByDefault(SetReply(&server_, &rsp4));
719 ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
721 EXPECT_TRUE(result.done_);
722 std::stringstream ss;
724 EXPECT_EQ("{'example.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
727 TEST_P(MockChannelTest, ExplicitIP) {
729 ares_gethostbyname(channel_, "1.2.3.4", AF_INET, HostCallback, &result);
730 EXPECT_TRUE(result.done_); // Immediate return
731 EXPECT_EQ(ARES_SUCCESS, result.status_);
732 std::stringstream ss;
734 EXPECT_EQ("{'1.2.3.4' aliases=[] addrs=[1.2.3.4]}", ss.str());
737 TEST_P(MockChannelTest, ExplicitIPAllocFail) {
739 SetAllocSizeFail(strlen("1.2.3.4") + 1);
740 ares_gethostbyname(channel_, "1.2.3.4", AF_INET, HostCallback, &result);
741 EXPECT_TRUE(result.done_); // Immediate return
742 EXPECT_EQ(ARES_ENOMEM, result.status_);
745 TEST_P(MockChannelTest, SortListV4) {
747 rsp.set_response().set_aa()
748 .add_question(new DNSQuestion("example.com", T_A))
749 .add_answer(new DNSARR("example.com", 100, {22, 23, 24, 25}))
750 .add_answer(new DNSARR("example.com", 100, {12, 13, 14, 15}))
751 .add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5}));
752 ON_CALL(server_, OnRequest("example.com", T_A))
753 .WillByDefault(SetReply(&server_, &rsp));
756 EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "12.13.0.0/255.255.0.0 1234::5678"));
758 ares_gethostbyname(channel_, "example.com.", AF_INET, HostCallback, &result);
760 EXPECT_TRUE(result.done_);
761 std::stringstream ss;
763 EXPECT_EQ("{'example.com' aliases=[] addrs=[12.13.14.15, 22.23.24.25, 2.3.4.5]}", ss.str());
766 EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "2.3.0.0/16 130.140.150.160/26"));
768 ares_gethostbyname(channel_, "example.com.", AF_INET, HostCallback, &result);
770 EXPECT_TRUE(result.done_);
771 std::stringstream ss;
773 EXPECT_EQ("{'example.com' aliases=[] addrs=[2.3.4.5, 22.23.24.25, 12.13.14.15]}", ss.str());
775 struct ares_options options;
776 memset(&options, 0, sizeof(options));
778 EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &options, &optmask));
779 EXPECT_TRUE((optmask & ARES_OPT_SORTLIST) == ARES_OPT_SORTLIST);
780 ares_destroy_options(&options);
783 TEST_P(MockChannelTest, SortListV6) {
785 rsp.set_response().set_aa()
786 .add_question(new DNSQuestion("example.com", T_AAAA))
787 .add_answer(new DNSAaaaRR("example.com", 100,
788 {0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
789 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02}))
790 .add_answer(new DNSAaaaRR("example.com", 100,
791 {0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
792 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03}));
793 ON_CALL(server_, OnRequest("example.com", T_AAAA))
794 .WillByDefault(SetReply(&server_, &rsp));
797 ares_set_sortlist(channel_, "1111::/16 2.3.0.0/255.255.0.0");
799 ares_gethostbyname(channel_, "example.com.", AF_INET6, HostCallback, &result);
801 EXPECT_TRUE(result.done_);
802 std::stringstream ss;
804 EXPECT_EQ("{'example.com' aliases=[] addrs=[1111:0000:0000:0000:0000:0000:0000:0202, "
805 "2121:0000:0000:0000:0000:0000:0000:0303]}", ss.str());
808 ares_set_sortlist(channel_, "2121::/8");
810 ares_gethostbyname(channel_, "example.com.", AF_INET6, HostCallback, &result);
812 EXPECT_TRUE(result.done_);
813 std::stringstream ss;
815 EXPECT_EQ("{'example.com' aliases=[] addrs=[2121:0000:0000:0000:0000:0000:0000:0303, "
816 "1111:0000:0000:0000:0000:0000:0000:0202]}", ss.str());
820 // Relies on retries so is UDP-only
821 TEST_P(MockUDPChannelTest, SearchDomainsAllocFail) {
823 nofirst.set_response().set_aa().set_rcode(NXDOMAIN)
824 .add_question(new DNSQuestion("www.first.com", T_A));
825 ON_CALL(server_, OnRequest("www.first.com", T_A))
826 .WillByDefault(SetReply(&server_, &nofirst));
828 nosecond.set_response().set_aa().set_rcode(NXDOMAIN)
829 .add_question(new DNSQuestion("www.second.org", T_A));
830 ON_CALL(server_, OnRequest("www.second.org", T_A))
831 .WillByDefault(SetReply(&server_, &nosecond));
833 yesthird.set_response().set_aa()
834 .add_question(new DNSQuestion("www.third.gov", T_A))
835 .add_answer(new DNSARR("www.third.gov", 0x0200, {2, 3, 4, 5}));
836 ON_CALL(server_, OnRequest("www.third.gov", T_A))
837 .WillByDefault(SetReply(&server_, &yesthird));
839 // Fail a variety of different memory allocations, and confirm
840 // that the operation either fails with ENOMEM or succeeds
841 // with the expected result.
842 const int kCount = 34;
843 HostResult results[kCount];
844 for (int ii = 1; ii <= kCount; ii++) {
845 HostResult* result = &(results[ii - 1]);
848 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, result);
850 EXPECT_TRUE(result->done_);
851 if (result->status_ == ARES_SUCCESS) {
852 std::stringstream ss;
854 EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str()) << " failed alloc #" << ii;
855 if (verbose) std::cerr << "Succeeded despite failure of alloc #" << ii << std::endl;
859 // Explicitly destroy the channel now, so that the HostResult objects
860 // are still valid (in case any pending work refers to them).
861 ares_destroy(channel_);
865 // Relies on retries so is UDP-only
866 TEST_P(MockUDPChannelTest, Resend) {
867 std::vector<byte> nothing;
869 reply.set_response().set_aa()
870 .add_question(new DNSQuestion("www.google.com", T_A))
871 .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
873 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
874 .WillOnce(SetReplyData(&server_, nothing))
875 .WillOnce(SetReplyData(&server_, nothing))
876 .WillOnce(SetReply(&server_, &reply));
879 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
881 EXPECT_TRUE(result.done_);
882 EXPECT_EQ(2, result.timeouts_);
883 std::stringstream ss;
885 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
888 TEST_P(MockChannelTest, CancelImmediate) {
890 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
891 ares_cancel(channel_);
892 EXPECT_TRUE(result.done_);
893 EXPECT_EQ(ARES_ECANCELLED, result.status_);
894 EXPECT_EQ(0, result.timeouts_);
897 TEST_P(MockChannelTest, CancelImmediateGetHostByAddr) {
900 addr.s_addr = htonl(0x08080808);
902 ares_gethostbyaddr(channel_, &addr, sizeof(addr), AF_INET, HostCallback, &result);
903 ares_cancel(channel_);
904 EXPECT_TRUE(result.done_);
905 EXPECT_EQ(ARES_ECANCELLED, result.status_);
906 EXPECT_EQ(0, result.timeouts_);
909 // Relies on retries so is UDP-only
910 TEST_P(MockUDPChannelTest, CancelLater) {
911 std::vector<byte> nothing;
913 // On second request, cancel the channel.
914 EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
915 .WillOnce(SetReplyData(&server_, nothing))
916 .WillOnce(CancelChannel(&server_, channel_));
919 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
921 EXPECT_TRUE(result.done_);
922 EXPECT_EQ(ARES_ECANCELLED, result.status_);
923 EXPECT_EQ(0, result.timeouts_);
926 TEST_P(MockChannelTest, GetHostByNameDestroyAbsolute) {
928 ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
930 ares_destroy(channel_);
933 EXPECT_TRUE(result.done_); // Synchronous
934 EXPECT_EQ(ARES_EDESTRUCTION, result.status_);
935 EXPECT_EQ(0, result.timeouts_);
938 TEST_P(MockChannelTest, GetHostByNameDestroyRelative) {
940 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
942 ares_destroy(channel_);
945 EXPECT_TRUE(result.done_); // Synchronous
946 EXPECT_EQ(ARES_EDESTRUCTION, result.status_);
947 EXPECT_EQ(0, result.timeouts_);
950 TEST_P(MockChannelTest, GetHostByNameCNAMENoData) {
952 response.set_response().set_aa()
953 .add_question(new DNSQuestion("cname.first.com", T_A))
954 .add_answer(new DNSCnameRR("cname.first.com", 100, "a.first.com"));
955 ON_CALL(server_, OnRequest("cname.first.com", T_A))
956 .WillByDefault(SetReply(&server_, &response));
959 ares_gethostbyname(channel_, "cname.first.com.", AF_INET, HostCallback, &result);
961 EXPECT_TRUE(result.done_);
962 EXPECT_EQ(ARES_ENODATA, result.status_);
965 TEST_P(MockChannelTest, GetHostByAddrDestroy) {
966 unsigned char gdns_addr4[4] = {0x08, 0x08, 0x08, 0x08};
968 ares_gethostbyaddr(channel_, gdns_addr4, sizeof(gdns_addr4), AF_INET, HostCallback, &result);
970 ares_destroy(channel_);
973 EXPECT_TRUE(result.done_); // Synchronous
974 EXPECT_EQ(ARES_EDESTRUCTION, result.status_);
975 EXPECT_EQ(0, result.timeouts_);
979 TEST_P(MockChannelTest, HostAlias) {
981 reply.set_response().set_aa()
982 .add_question(new DNSQuestion("www.google.com", T_A))
983 .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
984 ON_CALL(server_, OnRequest("www.google.com", T_A))
985 .WillByDefault(SetReply(&server_, &reply));
987 TempFile aliases("\n\n# www commentedout\nwww www.google.com\n");
988 EnvValue with_env("HOSTALIASES", aliases.filename());
991 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
993 EXPECT_TRUE(result.done_);
994 std::stringstream ss;
996 EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
999 TEST_P(MockChannelTest, HostAliasMissing) {
1001 yesfirst.set_response().set_aa()
1002 .add_question(new DNSQuestion("www.first.com", T_A))
1003 .add_answer(new DNSARR("www.first.com", 0x0200, {2, 3, 4, 5}));
1004 ON_CALL(server_, OnRequest("www.first.com", T_A))
1005 .WillByDefault(SetReply(&server_, &yesfirst));
1007 TempFile aliases("\n\n# www commentedout\nww www.google.com\n");
1008 EnvValue with_env("HOSTALIASES", aliases.filename());
1010 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
1012 EXPECT_TRUE(result.done_);
1013 std::stringstream ss;
1015 EXPECT_EQ("{'www.first.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
1018 TEST_P(MockChannelTest, HostAliasMissingFile) {
1020 yesfirst.set_response().set_aa()
1021 .add_question(new DNSQuestion("www.first.com", T_A))
1022 .add_answer(new DNSARR("www.first.com", 0x0200, {2, 3, 4, 5}));
1023 ON_CALL(server_, OnRequest("www.first.com", T_A))
1024 .WillByDefault(SetReply(&server_, &yesfirst));
1026 EnvValue with_env("HOSTALIASES", "bogus.mcfile");
1028 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
1030 EXPECT_TRUE(result.done_);
1031 std::stringstream ss;
1033 EXPECT_EQ("{'www.first.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
1036 TEST_P(MockChannelTest, HostAliasUnreadable) {
1037 TempFile aliases("www www.google.com\n");
1038 EXPECT_EQ(chmod(aliases.filename(), 0), 0);
1040 /* Perform OS sanity checks. We are observing on Debian after the chmod(fn, 0)
1041 * that we are still able to fopen() the file which is unexpected. Skip the
1042 * test if we observe this behavior */
1044 EXPECT_EQ(stat(aliases.filename(), &st), 0);
1045 EXPECT_EQ(st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO), 0);
1046 FILE *fp = fopen(aliases.filename(), "r");
1048 if (verbose) std::cerr << "Skipping Test due to OS incompatibility (open file caching)" << std::endl;
1053 EnvValue with_env("HOSTALIASES", aliases.filename());
1056 ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
1058 EXPECT_TRUE(result.done_);
1059 EXPECT_EQ(ARES_EFILE, result.status_);
1060 chmod(aliases.filename(), 0777);
1064 class MockMultiServerChannelTest
1065 : public MockChannelOptsTest,
1066 public ::testing::WithParamInterface< std::pair<int, bool> > {
1068 MockMultiServerChannelTest(bool rotate)
1069 : MockChannelOptsTest(3, GetParam().first, GetParam().second, nullptr, rotate ? ARES_OPT_ROTATE : ARES_OPT_NOROTATE) {}
1070 void CheckExample() {
1072 ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result);
1074 EXPECT_TRUE(result.done_);
1075 std::stringstream ss;
1077 EXPECT_EQ("{'www.example.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
1081 class RotateMultiMockTest : public MockMultiServerChannelTest {
1083 RotateMultiMockTest() : MockMultiServerChannelTest(true) {}
1086 class NoRotateMultiMockTest : public MockMultiServerChannelTest {
1088 NoRotateMultiMockTest() : MockMultiServerChannelTest(false) {}
1092 TEST_P(RotateMultiMockTest, ThirdServer) {
1093 struct ares_options opts = {0};
1095 EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &opts, &optmask));
1096 EXPECT_EQ(0, (optmask & ARES_OPT_NOROTATE));
1097 ares_destroy_options(&opts);
1099 DNSPacket servfailrsp;
1100 servfailrsp.set_response().set_aa().set_rcode(SERVFAIL)
1101 .add_question(new DNSQuestion("www.example.com", T_A));
1102 DNSPacket notimplrsp;
1103 notimplrsp.set_response().set_aa().set_rcode(NOTIMP)
1104 .add_question(new DNSQuestion("www.example.com", T_A));
1106 okrsp.set_response().set_aa()
1107 .add_question(new DNSQuestion("www.example.com", T_A))
1108 .add_answer(new DNSARR("www.example.com", 100, {2,3,4,5}));
1110 EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
1111 .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
1112 EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
1113 .WillOnce(SetReply(servers_[1].get(), ¬implrsp));
1114 EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
1115 .WillOnce(SetReply(servers_[2].get(), &okrsp));
1118 // Second time around, starts from server [1].
1119 EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
1120 .WillOnce(SetReply(servers_[1].get(), &servfailrsp));
1121 EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
1122 .WillOnce(SetReply(servers_[2].get(), ¬implrsp));
1123 EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
1124 .WillOnce(SetReply(servers_[0].get(), &okrsp));
1127 // Third time around, starts from server [2].
1128 EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
1129 .WillOnce(SetReply(servers_[2].get(), &servfailrsp));
1130 EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
1131 .WillOnce(SetReply(servers_[0].get(), ¬implrsp));
1132 EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
1133 .WillOnce(SetReply(servers_[1].get(), &okrsp));
1137 TEST_P(NoRotateMultiMockTest, ThirdServer) {
1138 struct ares_options opts = {0};
1140 EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &opts, &optmask));
1141 EXPECT_EQ(ARES_OPT_NOROTATE, (optmask & ARES_OPT_NOROTATE));
1142 ares_destroy_options(&opts);
1144 DNSPacket servfailrsp;
1145 servfailrsp.set_response().set_aa().set_rcode(SERVFAIL)
1146 .add_question(new DNSQuestion("www.example.com", T_A));
1147 DNSPacket notimplrsp;
1148 notimplrsp.set_response().set_aa().set_rcode(NOTIMP)
1149 .add_question(new DNSQuestion("www.example.com", T_A));
1151 okrsp.set_response().set_aa()
1152 .add_question(new DNSQuestion("www.example.com", T_A))
1153 .add_answer(new DNSARR("www.example.com", 100, {2,3,4,5}));
1155 EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
1156 .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
1157 EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
1158 .WillOnce(SetReply(servers_[1].get(), ¬implrsp));
1159 EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
1160 .WillOnce(SetReply(servers_[2].get(), &okrsp));
1163 // Second time around, still starts from server [0].
1164 EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
1165 .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
1166 EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
1167 .WillOnce(SetReply(servers_[1].get(), ¬implrsp));
1168 EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
1169 .WillOnce(SetReply(servers_[2].get(), &okrsp));
1172 // Third time around, still starts from server [0].
1173 EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
1174 .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
1175 EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
1176 .WillOnce(SetReply(servers_[1].get(), ¬implrsp));
1177 EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
1178 .WillOnce(SetReply(servers_[2].get(), &okrsp));
1182 INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockChannelTest, ::testing::ValuesIn(ares::test::families_modes));
1184 INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockUDPChannelTest, ::testing::ValuesIn(ares::test::families));
1186 INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockTCPChannelTest, ::testing::ValuesIn(ares::test::families));
1188 INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockExtraOptsTest, ::testing::ValuesIn(ares::test::families_modes));
1190 INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockNoCheckRespChannelTest, ::testing::ValuesIn(ares::test::families_modes));
1192 INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockEDNSChannelTest, ::testing::ValuesIn(ares::test::families_modes));
1194 INSTANTIATE_TEST_SUITE_P(TransportModes, RotateMultiMockTest, ::testing::ValuesIn(ares::test::families_modes));
1196 INSTANTIATE_TEST_SUITE_P(TransportModes, NoRotateMultiMockTest, ::testing::ValuesIn(ares::test::families_modes));