• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* MIT License
2  *
3  * Copyright (c) The c-ares project and its contributors
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  * SPDX-License-Identifier: MIT
25  */
26 #ifndef ARES_TEST_AI_H
27 #define ARES_TEST_AI_H
28 
29 #include <utility>
30 #include "gtest/gtest.h"
31 #include "gmock/gmock.h"
32 #include "ares-test.h"
33 
34 namespace ares {
35 namespace test {
36 
37 class MockChannelTestAI
38   : public MockChannelOptsTest,
39     public ::testing::WithParamInterface<std::pair<int, bool>> {
40 public:
MockChannelTestAI()41   MockChannelTestAI()
42     : MockChannelOptsTest(1, GetParam().first, GetParam().second, false,
43                           nullptr, 0)
44   {
45   }
46 };
47 
48 class MockUDPChannelTestAI : public MockChannelOptsTest,
49                              public ::testing::WithParamInterface<int> {
50 public:
MockUDPChannelTestAI()51   MockUDPChannelTestAI()
52     : MockChannelOptsTest(1, GetParam(), false, false, nullptr, 0)
53   {
54   }
55 };
56 
57 class MockTCPChannelTestAI : public MockChannelOptsTest,
58                              public ::testing::WithParamInterface<int> {
59 public:
MockTCPChannelTestAI()60   MockTCPChannelTestAI()
61     : MockChannelOptsTest(1, GetParam(), true, false, nullptr, 0)
62   {
63   }
64 };
65 
66 // Test fixture that uses a default channel.
67 class DefaultChannelTestAI : public LibraryTest {
68 public:
DefaultChannelTestAI()69   DefaultChannelTestAI() : channel_(nullptr)
70   {
71     EXPECT_EQ(ARES_SUCCESS, ares_init(&channel_));
72     EXPECT_NE(nullptr, channel_);
73   }
74 
~DefaultChannelTestAI()75   ~DefaultChannelTestAI()
76   {
77     ares_destroy(channel_);
78     channel_ = nullptr;
79   }
80 
81   // Process all pending work on ares-owned file descriptors.
82   void Process();
83 
84 protected:
85   ares_channel_t *channel_;
86 };
87 
88 }  // namespace test
89 }  // namespace ares
90 
91 #endif
92