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
20 namespace OHOS {
21 namespace nmd {
22 namespace {
23 using namespace testing::ext;
24 std::string INTERFACE_NAME = "interface_name";
25 std::string INFO = "info";
26 const uint16_t NET_ID = 2;
27 uint16_t BASE_TIMEOUT_MILLIS = 2000;
28 uint8_t RETRY_COUNT = 3;
29 } // namespace
30
31 class DnsManagerTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37 };
38
SetUpTestCase()39 void DnsManagerTest::SetUpTestCase() {}
40
TearDownTestCase()41 void DnsManagerTest::TearDownTestCase() {}
42
SetUp()43 void DnsManagerTest::SetUp() {}
44
TearDown()45 void DnsManagerTest::TearDown() {}
46
47 HWTEST_F(DnsManagerTest, InterfaceTest001, TestSize.Level1)
48 {
49 DnsManager dnsManager;
50 std::vector<std::string> servers;
51 std::vector<std::string> domains;
52 int32_t ret = dnsManager.SetResolverConfig(NET_ID, BASE_TIMEOUT_MILLIS,
53 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 } // namespace nmd
76 } // namespace OHOS
77