• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "dns_manager.h"
19 #include "dns_config_client.h"
20 
21 namespace OHOS {
22 namespace nmd {
23 namespace {
24 using namespace testing::ext;
25 std::string INTERFACE_NAME = "interface_name";
26 std::string INFO = "info";
27 const uint16_t NET_ID = 2;
28 uint16_t BASE_TIMEOUT_MILLIS = 2000;
29 uint8_t RETRY_COUNT = 3;
30 } // namespace
31 
32 class DnsManagerTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp();
37     void TearDown();
38 };
39 
SetUpTestCase()40 void DnsManagerTest::SetUpTestCase() {}
41 
TearDownTestCase()42 void DnsManagerTest::TearDownTestCase() {}
43 
SetUp()44 void DnsManagerTest::SetUp() {}
45 
TearDown()46 void DnsManagerTest::TearDown() {}
47 
48 HWTEST_F(DnsManagerTest, InterfaceTest001, TestSize.Level1)
49 {
50     DnsManager dnsManager;
51     std::vector<std::string> servers;
52     std::vector<std::string> domains;
53     int32_t ret = dnsManager.SetResolverConfig(NET_ID, BASE_TIMEOUT_MILLIS, RETRY_COUNT, servers, domains);
54     EXPECT_NE(ret, 0);
55 
56     ret = dnsManager.GetResolverConfig(NET_ID, servers, domains, BASE_TIMEOUT_MILLIS, RETRY_COUNT);
57     EXPECT_NE(ret, 0);
58 
59     ret = dnsManager.CreateNetworkCache(NET_ID);
60     EXPECT_EQ(ret, 0);
61 
62     dnsManager.SetDefaultNetwork(NET_ID);
63 
64     dnsManager.ShareDnsSet(NET_ID);
65 
66     dnsManager.StartDnsProxyListen();
67 
68     dnsManager.StopDnsProxyListen();
69 
70     dnsManager.GetDumpInfo(INFO);
71 
72     ret = dnsManager.DestroyNetworkCache(NET_ID);
73     EXPECT_EQ(ret, 0);
74 
75     std::string hostName = "www.baidu.com";
76     std::string serverName;
77     AddrInfo hints;
78     std::vector<AddrInfo> res;
79     dnsManager.GetAddrInfo(hostName, serverName, hints, NET_ID, res);
80 }
81 } // namespace nmd
82 } // namespace OHOS
83