• 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 "system_ability_definition.h"
19 
20 #include "dns_config_client.h"
21 #include "net_manager_constants.h"
22 #define private public
23 #include "netsys_native_service.h"
24 
25 namespace OHOS {
26 namespace NetsysNative {
27 namespace {
28 using namespace NetManagerStandard;
29 using namespace testing::ext;
30 } // namespace
31 
32 class NetsysNativeServiceTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp();
37     void TearDown();
38     static inline auto instance_ = std::make_shared<NetsysNativeService>(COMM_NETSYS_NATIVE_SYS_ABILITY_ID);
39 };
40 
SetUpTestCase()41 void NetsysNativeServiceTest::SetUpTestCase() {}
42 
TearDownTestCase()43 void NetsysNativeServiceTest::TearDownTestCase() {}
44 
SetUp()45 void NetsysNativeServiceTest::SetUp() {}
46 
TearDown()47 void NetsysNativeServiceTest::TearDown() {}
48 
49 HWTEST_F(NetsysNativeServiceTest, DumpTest001, TestSize.Level1)
50 {
51     instance_->Init();
52     int32_t testFd = 11;
53     int32_t ret = instance_->Dump(testFd, {});
54     EXPECT_LE(ret, NETMANAGER_SUCCESS);
55 }
56 
57 HWTEST_F(NetsysNativeServiceTest, SetResolverConfigTest001, TestSize.Level1)
58 {
59     uint16_t testNetId = 154;
60     uint16_t baseTimeoutMsec = 200;
61     uint8_t retryCount = 3;
62     int32_t ret = instance_->SetResolverConfig(testNetId, baseTimeoutMsec, retryCount, {}, {});
63     EXPECT_EQ(ret, 0);
64 }
65 
66 HWTEST_F(NetsysNativeServiceTest, GetResolverConfigTest001, TestSize.Level1)
67 {
68     uint16_t testNetId = 154;
69     uint16_t baseTimeoutMsec = 200;
70     uint8_t retryCount = 3;
71     std::vector<std::string> servers;
72     std::vector<std::string> domains;
73     int32_t ret = instance_->GetResolverConfig(testNetId, servers, domains, baseTimeoutMsec, retryCount);
74     EXPECT_EQ(ret, 0);
75 }
76 
77 HWTEST_F(NetsysNativeServiceTest, CreateNetworkCacheTest001, TestSize.Level1)
78 {
79     uint16_t testNetId = 154;
80     int32_t ret = instance_->CreateNetworkCache(testNetId);
81     EXPECT_EQ(ret, 0);
82 }
83 
84 HWTEST_F(NetsysNativeServiceTest, DestroyNetworkCacheTest001, TestSize.Level1)
85 {
86     uint16_t testNetId = 154;
87     int32_t ret = instance_->DestroyNetworkCache(testNetId);
88     EXPECT_LE(ret, NETMANAGER_SUCCESS);
89 }
90 
91 HWTEST_F(NetsysNativeServiceTest, NetworkAddRouteTest001, TestSize.Level1)
92 {
93     uint16_t testNetId = 154;
94     std::string interfaceName = "eth1";
95     std::string destination = "";
96     std::string nextHop = "";
97     int32_t ret = instance_->NetworkAddRoute(testNetId, interfaceName, destination, nextHop);
98     EXPECT_LE(ret, NETMANAGER_SUCCESS);
99 }
100 
101 HWTEST_F(NetsysNativeServiceTest, NetworkAddRouteParcelTest001, TestSize.Level1)
102 {
103     uint16_t testNetId = 154;
104     RouteInfoParcel routeInfo;
105     int32_t ret = instance_->NetworkAddRouteParcel(testNetId, routeInfo);
106     EXPECT_LE(ret, NETMANAGER_SUCCESS);
107 }
108 
109 HWTEST_F(NetsysNativeServiceTest, NetworkRemoveRouteParcelTest001, TestSize.Level1)
110 {
111     uint16_t testNetId = 154;
112     RouteInfoParcel routeInfo;
113     int32_t ret = instance_->NetworkRemoveRouteParcel(testNetId, routeInfo);
114     EXPECT_LE(ret, NETMANAGER_SUCCESS);
115 }
116 
117 HWTEST_F(NetsysNativeServiceTest, NetworkSetDefaultTest001, TestSize.Level1)
118 {
119     uint16_t testNetId = 154;
120     int32_t ret = instance_->NetworkSetDefault(testNetId);
121     EXPECT_GE(ret, NETMANAGER_SUCCESS);
122 }
123 
124 HWTEST_F(NetsysNativeServiceTest, NetworkGetDefaultTest001, TestSize.Level1)
125 {
126     int32_t ret = instance_->NetworkGetDefault();
127     EXPECT_LE(ret, 154);
128 }
129 
130 HWTEST_F(NetsysNativeServiceTest, NetworkClearDefaultTest001, TestSize.Level1)
131 {
132     int32_t ret = instance_->NetworkClearDefault();
133     EXPECT_LE(ret, NETMANAGER_SUCCESS);
134 }
135 
136 HWTEST_F(NetsysNativeServiceTest, GetProcSysNetTest001, TestSize.Level1)
137 {
138     int32_t ipversion = 45;
139     int32_t which = 14;
140     std::string ifname = "testifname";
141     std::string paramete = "testparamete";
142     std::string value = "testvalue";
143     int32_t ret = instance_->GetProcSysNet(ipversion, which, ifname, paramete, value);
144     EXPECT_LE(ret, NETMANAGER_SUCCESS);
145 }
146 
147 HWTEST_F(NetsysNativeServiceTest, SetProcSysNetTest001, TestSize.Level1)
148 {
149     int32_t ipversion = 45;
150     int32_t which = 14;
151     std::string ifname = "testifname";
152     std::string paramete = "testparamete";
153     std::string value = "testvalue";
154     int32_t ret = instance_->SetProcSysNet(ipversion, which, ifname, paramete, value);
155     EXPECT_LE(ret, NETMANAGER_SUCCESS);
156 }
157 } // namespace NetsysNative
158 } // namespace OHOS