• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 "message_parcel.h"
19 #ifdef GTEST_API_
20 #define private public
21 #endif
22 #include "common_net_conn_callback_test.h"
23 #include "i_net_conn_callback.h"
24 #include "net_conn_client.h"
25 #include "net_conn_constants.h"
26 #include "net_conn_types.h"
27 #include "net_factoryreset_callback_stub.h"
28 #include "net_interface_callback_stub.h"
29 #include "net_interface_config.h"
30 #include "net_manager_constants.h"
31 #include "netmanager_base_test_security.h"
32 #include "network.h"
33 
34 namespace OHOS {
35 namespace NetManagerStandard {
36 namespace {
37 using namespace testing::ext;
38 
39 constexpr const char *TEST_IPV4_ADDR = "127.0.0.1";
40 constexpr const char *TEST_IPV6_ADDR = "240C:1:1:1::1";
41 constexpr const char *TEST_DOMAIN1 = ".com";
42 constexpr const char *TEST_DOMAIN2 = "test.com";
43 constexpr const char *TEST_DOMAIN3 = "testcom";
44 constexpr const char *TEST_DOMAIN4 = "com.test";
45 constexpr const char *TEST_DOMAIN5 = "test.co.uk";
46 constexpr const char *TEST_DOMAIN6 = "test.com.com";
47 constexpr const char *TEST_DOMAIN7 = "test1.test2.test3.test4.test5.com";
48 constexpr const char *TEST_DOMAIN8 = "http://www.example.com";
49 constexpr const char *TEST_DOMAIN9 = "https://www.example.com";
50 constexpr const char *TEST_DOMAIN10 = "httpd://www.example.com";
51 constexpr const char *TEST_LONG_HOST =
52     "0123456789qwertyuiopasdfghjklzxcvbnm[]:;<>?!@#$%^&*()qwdqwrtfasfj4897qwe465791qwr87tq4fq7t8qt4654qwr";
53 constexpr const char *TEST_LONG_EXCLUSION_LIST =
54     "www.test0.com,www.test1.com,www.test2.com,www.test3.com,www.test4.com,www.test5.com,www.test6.com,www.test7.com,"
55     "www.test8.com,www.test9.com,www.test10.com,www.test11.com,www.test12.com,www.test12.com,www.test12.com,www.test13."
56     "com,www.test14.com,www.test15.com,www.test16.com,www.test17.com,www.test18.com,www.test19.com,www.test20.com";
57 constexpr const char *TEST_IFACE = "eth0";
58 constexpr const char *PROXY_NAME = "123456789";
59 constexpr const int32_t PROXY_NAME_SIZE = 9;
60 constexpr const int32_t INVALID_VALUE = 100;
61 } // namespace
62 
63 class NetConnClientTest : public testing::Test {
64 public:
65     static void SetUpTestCase();
66     static void TearDownTestCase();
67     void SetUp();
68     void TearDown();
69 };
70 
SetUpTestCase()71 void NetConnClientTest::SetUpTestCase() {}
72 
TearDownTestCase()73 void NetConnClientTest::TearDownTestCase() {}
74 
SetUp()75 void NetConnClientTest::SetUp() {}
76 
TearDown()77 void NetConnClientTest::TearDown() {}
78 
79 class INetFactoryResetCallbackTest : public IRemoteStub<INetFactoryResetCallback> {
80 public:
81     INetFactoryResetCallbackTest() = default;
82 
OnNetFactoryReset()83     int32_t OnNetFactoryReset()
84     {
85         return 0;
86     }
87 };
88 
89 /**
90  * @tc.name: GetDefaultNetTest001
91  * @tc.desc: Test NetConnClient::GetDefaultNet, not applying for
92  * permission,return NETMANAGER_ERR_PERMISSION_DENIED
93  * @tc.type: FUNC
94  */
95 HWTEST_F(NetConnClientTest, GetDefaultNetTest001, TestSize.Level1)
96 {
97     std::cout << "GetDefaultNetTest001 In" << std::endl;
98     NetHandle handle;
99     auto ret = NetConnClient::GetInstance().GetDefaultNet(handle);
100     ASSERT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
101 }
102 
103 /**
104  * @tc.name: GetDefaultNetTest002
105  * @tc.desc: Test NetConnClient::GetDefaultNet, not applying for
106  * permission,return NETMANAGER_SUCCESS
107  * @tc.type: FUNC
108  */
109 HWTEST_F(NetConnClientTest, GetDefaultNetTest002, TestSize.Level1)
110 {
111     std::cout << "GetDefaultNetTest002 In" << std::endl;
112     NetManagerBaseAccessToken token;
113     NetHandle handle;
114     int32_t netId = 0;
115     auto ret = NetConnClient::GetInstance().GetDefaultNet(handle);
116     netId = handle.GetNetId();
117     if (netId == 0) {
118         std::cout << "No network" << std::endl;
119         ASSERT_TRUE(ret == NETMANAGER_SUCCESS);
120     } else if (netId >= 100 && netId <= MAX_NET_ID) {
121         std::cout << "Get default network id:" << netId << std::endl;
122         ASSERT_TRUE(ret == NETMANAGER_SUCCESS);
123     } else {
124         ASSERT_FALSE(ret == NETMANAGER_SUCCESS);
125     }
126 }
127 
128 /**
129  * @tc.name: HasDefaultNetTest001
130  * @tc.desc: Test NetConnClient::HasDefaultNet,not applying for
131  * permission, return NETMANAGER_ERR_PERMISSION_DENIED
132  * @tc.type: FUNC
133  */
134 HWTEST_F(NetConnClientTest, HasDefaultNetTest001, TestSize.Level1)
135 {
136     bool bFlag = false;
137     auto ret = NetConnClient::GetInstance().HasDefaultNet(bFlag);
138     ASSERT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
139 }
140 
141 /**
142  * @tc.name: HasDefaultNetTest002
143  * @tc.desc: Test NetConnClient::HasDefaultNet, applying for
144  * permission, return NETMANAGER_SUCCESS
145  * @tc.type: FUNC
146  */
147 HWTEST_F(NetConnClientTest, HasDefaultNetTest002, TestSize.Level1)
148 {
149     NetManagerBaseAccessToken token;
150     bool bFlag = false;
151     auto ret = NetConnClient::GetInstance().HasDefaultNet(bFlag);
152     ASSERT_TRUE(ret == NETMANAGER_SUCCESS);
153 }
154 
155 /**
156  * @tc.name: GetNetCapabilitiesTest001
157  * @tc.desc: Test NetConnClient::GetNetCapabilities, In the absence of
158  * permission, GetDefaultNet return NETMANAGER_ERR_PERMISSION_DENIED and
159  * GetNetCapabilities return NETMANAGER_ERR_PERMISSION_DENIED
160  * @tc.type: FUNC
161  */
162 HWTEST_F(NetConnClientTest, GetNetCapabilitiesTest001, TestSize.Level1)
163 {
164     NetHandle handle;
165     int32_t ret = NetConnClient::GetInstance().GetDefaultNet(handle);
166     ASSERT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
167 
168     NetAllCapabilities netAllCap;
169     ret = NetConnClient::GetInstance().GetNetCapabilities(handle, netAllCap);
170     ASSERT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
171 }
172 
173 /**
174  * @tc.name: GetNetCapabilitiesTest002
175  * @tc.desc: Test NetConnClient::GetNetCapabilities:In the absence of
176  * permission, GetDefaultNet return NETMANAGER_ERR_PERMISSION_DENIED, and
177  * after add permission GetNetCapabilities return NET_CONN_ERR_INVALID_NETWORK
178  * @tc.type: FUNC
179  */
180 HWTEST_F(NetConnClientTest, GetNetCapabilitiesTest002, TestSize.Level1)
181 {
182     NetHandle handle;
183     int32_t ret = NetConnClient::GetInstance().GetDefaultNet(handle);
184     ASSERT_TRUE(ret == NETMANAGER_ERR_PERMISSION_DENIED);
185 
186     NetManagerBaseAccessToken token;
187     NetAllCapabilities netAllCap;
188     ret = NetConnClient::GetInstance().GetNetCapabilities(handle, netAllCap);
189     ASSERT_TRUE(ret == NET_CONN_ERR_INVALID_NETWORK);
190 }
191 
192 /**
193  * @tc.name: GetNetCapabilitiesTest003
194  * @tc.desc: Test NetConnClient::GetNetCapabilities:Apply for permission at
195  * first, when net is connected,return NET_CONN_SUCCESS, or net is not connected,return
196  * NET_CONN_ERR_INVALID_NETWORK
197  * @tc.type: FUNC
198  */
199 HWTEST_F(NetConnClientTest, GetNetCapabilitiesTest003, TestSize.Level1)
200 {
201     NetManagerBaseAccessToken token;
202     NetHandle handle;
203     int32_t ret = NetConnClient::GetInstance().GetDefaultNet(handle);
204     ASSERT_TRUE(ret == NETMANAGER_SUCCESS);
205 
206     NetAllCapabilities netAllCap;
207     ret = NetConnClient::GetInstance().GetNetCapabilities(handle, netAllCap);
208     ASSERT_TRUE(ret == NETMANAGER_SUCCESS || ret == NET_CONN_ERR_INVALID_NETWORK);
209 }
210 
211 /**
212  * @tc.name: SetAirplaneModeTest001
213  * @tc.desc: Test NetConnClient::SetAirplaneMode
214  * @tc.type: FUNC
215  */
216 HWTEST_F(NetConnClientTest, SetAirplaneModeTest001, TestSize.Level1)
217 {
218     NetManagerBaseAccessToken token;
219     auto ret = NetConnClient::GetInstance().SetAirplaneMode(true);
220     ASSERT_EQ(ret, NETMANAGER_SUCCESS);
221 }
222 
223 /**
224  * @tc.name: SetAirplaneModeTest002
225  * @tc.desc: Test NetConnClient::SetAirplaneMode
226  * @tc.type: FUNC
227  */
228 HWTEST_F(NetConnClientTest, SetAirplaneModeTest002, TestSize.Level1)
229 {
230     NetManagerBaseAccessToken token;
231     auto ret = NetConnClient::GetInstance().SetAirplaneMode(false);
232     ASSERT_EQ(ret, NETMANAGER_SUCCESS);
233 }
234 
235 /**
236  * @tc.name: IsDefaultNetMeteredTest001
237  * @tc.desc: if no permission,NetConnClient::IsDefaultNetMetered return NETMANAGER_ERR_PERMISSION_DENIED
238  * @tc.type: FUNC
239  */
240 HWTEST_F(NetConnClientTest, IsDefaultNetMeteredTest001, TestSize.Level1)
241 {
242     bool bRes = false;
243     auto ret = NetConnClient::GetInstance().IsDefaultNetMetered(bRes);
244     ASSERT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
245     ASSERT_TRUE(bRes == false);
246 }
247 
248 /**
249  * @tc.name: IsDefaultNetMeteredTest002
250  * @tc.desc: Test NetConnClient::IsDefaultNetMetered
251  * @tc.type: FUNC
252  */
253 HWTEST_F(NetConnClientTest, IsDefaultNetMeteredTest002, TestSize.Level1)
254 {
255     NetManagerBaseAccessToken token;
256     bool bRes = false;
257     auto ret = NetConnClient::GetInstance().IsDefaultNetMetered(bRes);
258     ASSERT_TRUE(ret == NETMANAGER_SUCCESS);
259     ASSERT_TRUE(bRes == true);
260 }
261 
262 /**
263  * @tc.name: SetGlobalHttpProxyTest001
264  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
265  * @tc.type: FUNC
266  */
267 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest001, TestSize.Level1)
268 {
269     NetManagerBaseAccessToken token;
270     HttpProxy httpProxy = {"testHttpProxy", 0, {}};
271     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
272     ASSERT_TRUE(ret == NETMANAGER_SUCCESS);
273 }
274 
275 /**
276  * @tc.name: SetGlobalHttpProxyTest002
277  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
278  * @tc.type: FUNC
279  */
280 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest002, TestSize.Level1)
281 {
282     NetManagerBaseAccessToken token;
283     HttpProxy httpProxy = {TEST_DOMAIN1, 8080, {}};
284     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
285     ASSERT_TRUE(ret == NETMANAGER_SUCCESS);
286 }
287 
288 /**
289  * @tc.name: SetGlobalHttpProxyTest003
290  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
291  * @tc.type: FUNC
292  */
293 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest003, TestSize.Level1)
294 {
295     NetManagerBaseAccessToken token;
296     HttpProxy httpProxy = {TEST_DOMAIN2, 8080, {}};
297     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
298     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
299 }
300 
301 /**
302  * @tc.name: SetGlobalHttpProxyTest004
303  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
304  * @tc.type: FUNC
305  */
306 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest004, TestSize.Level1)
307 {
308     NetManagerBaseAccessToken token;
309     HttpProxy httpProxy = {TEST_DOMAIN3, 8080, {}};
310     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
311     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
312 }
313 
314 /**
315  * @tc.name: SetGlobalHttpProxyTest005
316  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
317  * @tc.type: FUNC
318  */
319 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest005, TestSize.Level1)
320 {
321     NetManagerBaseAccessToken token;
322     HttpProxy httpProxy = {TEST_DOMAIN4, 8080, {}};
323     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
324     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
325 }
326 
327 /**
328  * @tc.name: SetGlobalHttpProxyTest006
329  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
330  * @tc.type: FUNC
331  */
332 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest006, TestSize.Level1)
333 {
334     NetManagerBaseAccessToken token;
335     HttpProxy httpProxy = {TEST_DOMAIN5, 8080, {}};
336     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
337     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
338 }
339 
340 /**
341  * @tc.name: SetGlobalHttpProxyTest007
342  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
343  * @tc.type: FUNC
344  */
345 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest007, TestSize.Level1)
346 {
347     NetManagerBaseAccessToken token;
348     HttpProxy httpProxy = {TEST_DOMAIN6, 8080, {}};
349     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
350     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
351 }
352 
353 /**
354  * @tc.name: SetGlobalHttpProxyTest008
355  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
356  * @tc.type: FUNC
357  */
358 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest008, TestSize.Level1)
359 {
360     NetManagerBaseAccessToken token;
361     HttpProxy httpProxy = {TEST_DOMAIN7, 8080, {}};
362     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
363     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
364 }
365 
366 /**
367  * @tc.name: SetGlobalHttpProxyTest09
368  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
369  * @tc.type: FUNC
370  */
371 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest09, TestSize.Level1)
372 {
373     NetManagerBaseAccessToken token;
374     HttpProxy httpProxy = {TEST_DOMAIN8, 8080, {}};
375     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
376     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
377 }
378 
379 /**
380  * @tc.name: SetGlobalHttpProxyTest10
381  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
382  * @tc.type: FUNC
383  */
384 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest10, TestSize.Level1)
385 {
386     NetManagerBaseAccessToken token;
387     HttpProxy httpProxy = {TEST_DOMAIN9, 8080, {}};
388     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
389     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
390 }
391 
392 /**
393  * @tc.name: SetGlobalHttpProxyTest11
394  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
395  * @tc.type: FUNC
396  */
397 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest11, TestSize.Level1)
398 {
399     NetManagerBaseAccessToken token;
400     HttpProxy httpProxy = {TEST_DOMAIN10, 8080, {}};
401     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
402     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
403 }
404 
405 /**
406  * @tc.name: SetGlobalHttpProxyTest012
407  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy.
408  * @tc.type: FUNC
409  */
410 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest012, TestSize.Level1)
411 {
412     NetManagerBaseAccessToken token;
413     HttpProxy httpProxy = {TEST_IPV4_ADDR, 8080, {}};
414     SecureData name;
415     name.append(PROXY_NAME, PROXY_NAME_SIZE);
416     SecureData pwd;
417     pwd.append(PROXY_NAME, PROXY_NAME_SIZE);
418     httpProxy.SetUserName(name);
419     httpProxy.SetPassword(pwd);
420     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
421     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
422 }
423 
424 /**
425  * @tc.name: SetGlobalHttpProxyTest013
426  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy.
427  * @tc.type: FUNC
428  */
429 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest013, TestSize.Level1)
430 {
431     NetManagerBaseAccessToken token;
432     HttpProxy httpProxy = {TEST_IPV6_ADDR, 8080, {}};
433     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
434     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
435 }
436 
437 /**
438  * @tc.name: SetGlobalHttpProxyTest14
439  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy
440  * @tc.type: FUNC
441  */
442 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest14, TestSize.Level1)
443 {
444     NetManagerBaseAccessToken token;
445     HttpProxy httpProxy = {TEST_LONG_HOST, 8080, {TEST_LONG_EXCLUSION_LIST}};
446     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
447     ASSERT_TRUE(ret == NETMANAGER_SUCCESS);
448 }
449 
450 /**
451  * @tc.name: SetGlobalHttpProxyTest015
452  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy.
453  * @tc.type: FUNC
454  */
455 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest015, TestSize.Level1)
456 {
457     NetManagerBaseAccessToken token;
458     HttpProxy httpProxy;
459     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
460     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
461 }
462 
463 /**
464  * @tc.name: SetGlobalHttpProxyTest016
465  * @tc.desc: Test NetConnClient::SetGlobalHttpProxy.not applying for permission,return NETMANAGER_ERR_PERMISSION_DENIED
466  * @tc.type: FUNC
467  */
468 HWTEST_F(NetConnClientTest, SetGlobalHttpProxyTest016, TestSize.Level1)
469 {
470     HttpProxy httpProxy = {TEST_IPV4_ADDR, 8080, {}};
471     SecureData name;
472     SecureData pwd;
473     name.append(PROXY_NAME, PROXY_NAME_SIZE);
474     pwd.append(PROXY_NAME, PROXY_NAME_SIZE);
475     httpProxy.SetUserName(name);
476     httpProxy.SetPassword(pwd);
477     auto ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
478     ASSERT_TRUE(ret == NETMANAGER_ERR_PERMISSION_DENIED);
479 }
480 
481 /**
482  * @tc.name: GetGlobalHttpProxyTest001
483  * @tc.desc: Test NetConnClient::GetGlobalHttpProxy
484  * @tc.type: FUNC
485  */
486 HWTEST_F(NetConnClientTest, GetGlobalHttpProxyTest001, TestSize.Level1)
487 {
488     NetManagerBaseAccessToken token;
489     HttpProxy httpProxy = {TEST_IPV4_ADDR, 8080, {}};
490     int32_t ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
491     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
492 
493     HttpProxy getGlobalHttpProxy;
494     ret = NetConnClient::GetInstance().GetGlobalHttpProxy(getGlobalHttpProxy);
495     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
496     ASSERT_TRUE(getGlobalHttpProxy.GetHost() == TEST_IPV4_ADDR);
497 }
498 
499 /**
500  * @tc.name: GetGlobalHttpProxyTest002
501  * @tc.desc: Test NetConnClient::GetGlobalHttpProxy
502  * @tc.type: FUNC
503  */
504 HWTEST_F(NetConnClientTest, GetGlobalHttpProxyTest002, TestSize.Level1)
505 {
506     NetManagerBaseAccessToken token;
507     HttpProxy httpProxy = {TEST_IPV6_ADDR, 8080, {}};
508     int32_t ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
509     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
510 
511     HttpProxy getGlobalHttpProxy;
512     ret = NetConnClient::GetInstance().GetGlobalHttpProxy(getGlobalHttpProxy);
513     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
514     ASSERT_TRUE(getGlobalHttpProxy.GetHost() == TEST_IPV6_ADDR);
515 }
516 
517 /**
518  * @tc.name: GetGlobalHttpProxyTest003
519  * @tc.desc: Test NetConnClient::GetGlobalHttpProxy
520  * @tc.type: FUNC
521  */
522 HWTEST_F(NetConnClientTest, GetGlobalHttpProxyTest003, TestSize.Level1)
523 {
524     NetManagerBaseAccessToken token;
525     HttpProxy httpProxy = {TEST_DOMAIN2, 8080, {}};
526     int32_t ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
527     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
528 
529     HttpProxy getGlobalHttpProxy;
530     ret = NetConnClient::GetInstance().GetGlobalHttpProxy(getGlobalHttpProxy);
531     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
532     ASSERT_TRUE(getGlobalHttpProxy.GetHost() == TEST_DOMAIN2);
533 }
534 
535 /**
536  * @tc.name: GetGlobalHttpProxyTest004
537  * @tc.desc: Test NetConnClient::GetGlobalHttpProxy
538  * @tc.type: FUNC
539  */
540 HWTEST_F(NetConnClientTest, GetGlobalHttpProxyTest004, TestSize.Level1)
541 {
542     NetManagerBaseAccessToken token;
543     HttpProxy validHttpProxy = {TEST_IPV4_ADDR, 8080, {}};
544     int32_t ret = NetConnClient::GetInstance().SetGlobalHttpProxy(validHttpProxy);
545     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
546 
547     HttpProxy getGlobalHttpProxy;
548     ret = NetConnClient::GetInstance().GetGlobalHttpProxy(getGlobalHttpProxy);
549     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
550     ASSERT_TRUE(getGlobalHttpProxy.GetHost() == TEST_IPV4_ADDR);
551 }
552 
553 /**
554  * @tc.name: GetGlobalHttpProxyTest005
555  * @tc.desc: Test NetConnClient::GetGlobalHttpProxy
556  * @tc.type: FUNC
557  */
558 HWTEST_F(NetConnClientTest, GetGlobalHttpProxyTest005, TestSize.Level1)
559 {
560     NetManagerBaseAccessToken token;
561     HttpProxy httpProxy;
562     int32_t ret = NetConnClient::GetInstance().SetGlobalHttpProxy(httpProxy);
563     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
564 
565     HttpProxy getGlobalHttpProxy;
566     ret = NetConnClient::GetInstance().GetGlobalHttpProxy(getGlobalHttpProxy);
567     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
568     ASSERT_TRUE(getGlobalHttpProxy.GetHost().empty());
569 }
570 
571 /**
572  * @tc.name: GetDefaultHttpProxyTest001
573  * @tc.desc: Test NetConnClient::GetDefaultHttpProxy
574  * @tc.type: FUNC
575  */
576 HWTEST_F(NetConnClientTest, GetDefaultHttpProxyTest001, TestSize.Level1)
577 {
578     NetManagerBaseAccessToken token;
579     HttpProxy validHttpProxy = {TEST_IPV4_ADDR, 8080, {}};
580     int32_t ret = NetConnClient::GetInstance().SetGlobalHttpProxy(validHttpProxy);
581     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
582 
583     HttpProxy defaultHttpProxy;
584     ret = NetConnClient::GetInstance().GetDefaultHttpProxy(defaultHttpProxy);
585     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
586     ASSERT_TRUE(defaultHttpProxy.GetHost() == TEST_IPV4_ADDR);
587 }
588 
589 /**
590  * @tc.name: GetDefaultHttpProxyTest002
591  * @tc.desc: Test NetConnClient::GetDefaultHttpProxy
592  * @tc.type: FUNC
593  */
594 HWTEST_F(NetConnClientTest, GetDefaultHttpProxyTest002, TestSize.Level1)
595 {
596     NetManagerBaseAccessToken token;
597     HttpProxy globalHttpProxy;
598     int32_t ret = NetConnClient::GetInstance().SetGlobalHttpProxy(globalHttpProxy);
599     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
600 
601     HttpProxy defaultHttpProxy;
602     ret = NetConnClient::GetInstance().GetDefaultHttpProxy(defaultHttpProxy);
603     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
604 }
605 
606 /**
607  * @tc.name: GetDefaultHttpProxyTest003
608  * @tc.desc: Test NetConnClient::SetAppNet and NetConnClient::GetDefaultHttpProxy
609  * @tc.type: FUNC
610  */
611 HWTEST_F(NetConnClientTest, GetDefaultHttpProxyTest003, TestSize.Level1)
612 {
613     NetManagerBaseAccessToken token;
614     int32_t netId = 102;
615     int32_t ret = NetConnClient::GetInstance().SetAppNet(netId);
616     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
617     HttpProxy defaultHttpProxy;
618     ret = NetConnClient::GetInstance().GetDefaultHttpProxy(defaultHttpProxy);
619     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
620 
621     int32_t cancelNetId = 0;
622     ret = NetConnClient::GetInstance().SetAppNet(cancelNetId);
623     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
624     ret = NetConnClient::GetInstance().GetDefaultHttpProxy(defaultHttpProxy);
625     ASSERT_TRUE(ret == NET_CONN_SUCCESS);
626 }
627 
628 /**
629  * @tc.name: RegisterNetSupplier001
630  * @tc.desc: Test NetConnClient::RegisterNetSupplier
631  * @tc.type: FUNC
632  */
633 HWTEST_F(NetConnClientTest, RegisterNetSupplier001, TestSize.Level1)
634 {
635     uint32_t supplierId = 100;
636     NetBearType netBearType = BEARER_WIFI;
637     const std::string ident = "";
638     std::set<NetCap> netCaps = {NET_CAPABILITY_INTERNET};
639     auto ret = NetConnClient::GetInstance().RegisterNetSupplier(netBearType, ident, netCaps, supplierId);
640     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
641 }
642 
643 /**
644  * @tc.name: RegisterNetSupplier002
645  * @tc.desc: Test NetConnClient::RegisterNetSupplier
646  * @tc.type: FUNC
647  */
648 HWTEST_F(NetConnClientTest, RegisterNetSupplier002, TestSize.Level1)
649 {
650     NetManagerBaseAccessToken token;
651     uint32_t supplierId = 100;
652     NetBearType netBearType = BEARER_WIFI;
653     const std::string ident = "";
654     std::set<NetCap> netCaps = {NET_CAPABILITY_INTERNET};
655     auto ret = NetConnClient::GetInstance().RegisterNetSupplier(netBearType, ident, netCaps, supplierId);
656     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
657 }
658 
659 /**
660  * @tc.name: UnregisterNetSupplier001
661  * @tc.desc: Test NetConnClient::UnregisterNetSupplier
662  * @tc.type: FUNC
663  */
664 HWTEST_F(NetConnClientTest, UnregisterNetSupplier001, TestSize.Level1)
665 {
666     uint32_t supplierId = 100;
667     auto ret = NetConnClient::GetInstance().UnregisterNetSupplier(supplierId);
668     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
669 }
670 
671 /**
672  * @tc.name: UnregisterNetSupplier002
673  * @tc.desc: Test NetConnClient::UnregisterNetSupplier
674  * @tc.type: FUNC
675  */
676 HWTEST_F(NetConnClientTest, UnregisterNetSupplier002, TestSize.Level1)
677 {
678     NetManagerBaseAccessToken token;
679     uint32_t supplierId = 100;
680     auto ret = NetConnClient::GetInstance().UnregisterNetSupplier(supplierId);
681     EXPECT_EQ(ret, NET_CONN_ERR_NO_SUPPLIER);
682 }
683 
684 /**
685  * @tc.name: RegisterNetSupplierCallbackTest001
686  * @tc.desc: Test NetConnClient::RegisterNetSupplierCallback
687  * @tc.type: FUNC
688  */
689 HWTEST_F(NetConnClientTest, RegisterNetSupplierCallbackTest001, TestSize.Level1)
690 {
691     uint32_t supplierId = 100;
692     sptr<NetSupplierCallbackBase> callback = new (std::nothrow) NetSupplierCallbackBase();
693     ASSERT_NE(callback, nullptr);
694     auto ret = NetConnClient::GetInstance().RegisterNetSupplierCallback(supplierId, callback);
695     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
696 }
697 
698 /**
699  * @tc.name: RegisterNetSupplierCallbackTest002
700  * @tc.desc: Test NetConnClient::RegisterNetSupplierCallback
701  * @tc.type: FUNC
702  */
703 HWTEST_F(NetConnClientTest, RegisterNetSupplierCallbackTest002, TestSize.Level1)
704 {
705     NetManagerBaseAccessToken token;
706     uint32_t supplierId = 100;
707     sptr<NetSupplierCallbackBase> callback = new (std::nothrow) NetSupplierCallbackBase();
708     ASSERT_NE(callback, nullptr);
709     auto ret = NetConnClient::GetInstance().RegisterNetSupplierCallback(supplierId, callback);
710     EXPECT_EQ(ret, NET_CONN_ERR_NO_SUPPLIER);
711 }
712 
713 /**
714  * @tc.name: RegisterNetSupplierCallbackTest003
715  * @tc.desc: Test NetConnClient::RegisterNetSupplierCallback
716  * @tc.type: FUNC
717  */
718 HWTEST_F(NetConnClientTest, RegisterNetSupplierCallbackTest003, TestSize.Level1)
719 {
720     NetManagerBaseAccessToken token;
721     NetBearType bearerType = BEARER_CELLULAR;
722     std::set<NetCap> netCaps{NET_CAPABILITY_INTERNET};
723     std::string ident = "ident";
724     uint32_t supplierId = 0;
725     int32_t result = NetConnClient::GetInstance().RegisterNetSupplier(bearerType, ident, netCaps, supplierId);
726     ASSERT_TRUE(result == NETMANAGER_SUCCESS);
727     sptr<NetSupplierCallbackBase> callback = new (std::nothrow) NetSupplierCallbackBase();
728     ASSERT_NE(callback, nullptr);
729     auto ret = NetConnClient::GetInstance().RegisterNetSupplierCallback(supplierId, callback);
730     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
731 }
732 
733 /**
734  * @tc.name: RegisterNetSupplierCallbackTest004
735  * @tc.desc: Test NetConnClient::RegisterNetSupplierCallback
736  * @tc.type: FUNC
737  */
738 HWTEST_F(NetConnClientTest, RegisterNetSupplierCallbackTest004, TestSize.Level1)
739 {
740     NetManagerBaseAccessToken token;
741     uint32_t supplierId = 0;
742     sptr<NetSupplierCallbackBase> callback;
743     auto ret = NetConnClient::GetInstance().RegisterNetSupplierCallback(supplierId, callback);
744     EXPECT_EQ(ret, NET_CONN_ERR_NO_SUPPLIER);
745 }
746 
747 /**
748  * @tc.name: SetAppNetTest001
749  * @tc.desc: Test NetConnClient::SetAppNet, if param is invalid, SetAppNet return NET_CONN_ERR_INVALID_NETWORK
750  * @tc.type: FUNC
751  */
752 HWTEST_F(NetConnClientTest, SetAppNetTest001, TestSize.Level1)
753 {
754     NetManagerBaseAccessToken token;
755     int32_t netId = 99;
756     auto ret = NetConnClient::GetInstance().SetAppNet(netId);
757     EXPECT_EQ(ret, NET_CONN_ERR_INVALID_NETWORK);
758 }
759 
760 /**
761  * @tc.name: SetAppNetTest002
762  * @tc.desc: Test NetConnClient::SetAppNet, if param is valid, SetAppNet return NETMANAGER_SUCCESS
763  * @tc.type: FUNC
764  */
765 HWTEST_F(NetConnClientTest, SetAppNetTest002, TestSize.Level1)
766 {
767     NetManagerBaseAccessToken token;
768     int32_t netId = 102;
769     auto ret = NetConnClient::GetInstance().SetAppNet(netId);
770     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
771 
772     int32_t cancelNetId = 0;
773     ret = NetConnClient::GetInstance().SetAppNet(cancelNetId);
774     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
775 }
776 
777 /**
778  * @tc.name: GetAppNetTest001
779  * @tc.desc: Test NetConnClient::GetAppNet, return NetId set by SetAppNet
780  * @tc.type: FUNC
781  */
782 HWTEST_F(NetConnClientTest, GetAppNetTest001, TestSize.Level1)
783 {
784     NetManagerBaseAccessToken token;
785     int32_t netId = 102;
786     auto ret = NetConnClient::GetInstance().SetAppNet(netId);
787     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
788 
789     int32_t getNetId = 0;
790     NetConnClient::GetInstance().GetAppNet(getNetId);
791     EXPECT_EQ(getNetId, netId);
792 
793     int32_t cancelNetId = 0;
794     ret = NetConnClient::GetInstance().SetAppNet(cancelNetId);
795     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
796 }
797 
798 /**
799  * @tc.name: RegisterNetConnCallback001
800  * @tc.desc: Test NetConnClient::RegisterNetConnCallback, not applying for
801  * permission,return NETMANAGER_ERR_PERMISSION_DENIED
802  * @tc.type: FUNC
803  */
804 HWTEST_F(NetConnClientTest, RegisterNetConnCallback001, TestSize.Level1)
805 {
806     NetManagerBaseAccessToken token;
807     sptr<INetConnCallbackTest> callback = new (std::nothrow) INetConnCallbackTest();
808     int32_t ret = NetConnClient::GetInstance().RegisterNetConnCallback(callback);
809     ret = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
810     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
811 }
812 
813 /**
814  * @tc.name: RegisterNetConnCallback002
815  * @tc.desc: Test NetConnClient::RegisterNetConnCallback, not applying for
816  * permission,return NETMANAGER_ERR_PERMISSION_DENIED
817  * @tc.type: FUNC
818  */
819 HWTEST_F(NetConnClientTest, RegisterNetConnCallback002, TestSize.Level1)
820 {
821     sptr<NetSpecifier> netSpecifier = nullptr;
822     sptr<INetConnCallbackTest> callback = new (std::nothrow) INetConnCallbackTest();
823     uint32_t timesOut = 1;
824     auto ret = NetConnClient::GetInstance().RegisterNetConnCallback(netSpecifier, callback, timesOut);
825     EXPECT_EQ(ret, NETMANAGER_ERR_PARAMETER_ERROR);
826 }
827 
828 /**
829  * @tc.name: RegisterNetConnCallback002
830  * @tc.desc: Test NetConnClient::RegisterNetConnCallback, not applying for
831  * permission,return NETMANAGER_ERR_PERMISSION_DENIED
832  * @tc.type: FUNC
833  */
834 HWTEST_F(NetConnClientTest, RegisterNetConnCallback003, TestSize.Level1)
835 {
836     sptr<NetSpecifier> netSpecifier = new (std::nothrow) NetSpecifier();
837     sptr<INetConnCallbackTest> callback = new (std::nothrow) INetConnCallbackTest();
838     uint32_t timesOut = 1;
839     auto ret = NetConnClient::GetInstance().RegisterNetConnCallback(netSpecifier, callback, timesOut);
840     EXPECT_EQ(ret, NETMANAGER_ERR_PARAMETER_ERROR);
841 }
842 
843 /**
844  * @tc.name: RegisterNetConnCallback001
845  * @tc.desc: Test NetConnClient::RegisterNetConnCallback, not applying for
846  * permission,return NETMANAGER_ERR_PERMISSION_DENIED
847  * @tc.type: FUNC
848  */
849 HWTEST_F(NetConnClientTest, UnRegisterNetConnCallback001, TestSize.Level1)
850 {
851     sptr<INetConnCallbackTest> callback = new (std::nothrow) INetConnCallbackTest();
852     int32_t ret = NetConnClient::GetInstance().RegisterNetConnCallback(callback);
853     ret = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
854     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
855 }
856 
857 /**
858  * @tc.name: RequestNetConnection001
859  * @tc.desc: Test NetConnClient::RequestNetConnection, not applying for
860  * permission,return NETMANAGER_SUCCESS
861  * @tc.type: FUNC
862  */
863 HWTEST_F(NetConnClientTest, RequestNetConnection001, TestSize.Level1)
864 {
865     NetManagerBaseAccessToken token;
866     sptr<NetSpecifier> netSpecifier = new (std::nothrow) NetSpecifier();
867     netSpecifier->netCapabilities_.bearerTypes_.emplace(NetManagerStandard::BEARER_CELLULAR);
868     netSpecifier->netCapabilities_.netCaps_.emplace(NetManagerStandard::NET_CAPABILITY_INTERNAL_DEFAULT);
869     sptr<INetConnCallbackTest> callback = new (std::nothrow) INetConnCallbackTest();
870     uint32_t timesOut = 0;
871     auto ret = NetConnClient::GetInstance().RequestNetConnection(netSpecifier, callback, timesOut);
872     ret = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
873     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
874 }
875 
876 /**
877  * @tc.name: RequestNetConnection002
878  * @tc.desc: Test NetConnClient::RequestNetConnection, not applying for
879  * permission,return NETMANAGER_ERR_PARAMETER_ERROR
880  * @tc.type: FUNC
881  */
882 HWTEST_F(NetConnClientTest, RequestNetConnection002, TestSize.Level1)
883 {
884     sptr<NetSpecifier> netSpecifier = nullptr;
885     sptr<INetConnCallbackTest> callback = new (std::nothrow) INetConnCallbackTest();
886     uint32_t timesOut = 1;
887     auto ret = NetConnClient::GetInstance().RequestNetConnection(netSpecifier, callback, timesOut);
888     EXPECT_EQ(ret, NETMANAGER_ERR_PARAMETER_ERROR);
889 }
890 
891 /**
892  * @tc.name: RequestNetConnection003
893  * @tc.desc: Test NetConnClient::RequestNetConnection, not applying for
894  * permission,return NETMANAGER_ERR_PARAMETER_ERROR
895  * @tc.type: FUNC
896  */
897 HWTEST_F(NetConnClientTest, RequestNetConnection003, TestSize.Level1)
898 {
899     sptr<NetSpecifier> netSpecifier = new (std::nothrow) NetSpecifier();
900     sptr<INetConnCallbackTest> callback = new (std::nothrow) INetConnCallbackTest();
901     uint32_t timesOut = 1;
902     auto ret = NetConnClient::GetInstance().RequestNetConnection(netSpecifier, callback, timesOut);
903     EXPECT_EQ(ret, NETMANAGER_ERR_PARAMETER_ERROR);
904 }
905 
906 /**
907  * @tc.name: RequestNetConnection004
908  * @tc.desc: Test NetConnClient::RequestNetConnection, not applying for
909  * permission,return NETMANAGER_ERR_PERMISSION_DENIED
910  * @tc.type: FUNC
911  */
912 HWTEST_F(NetConnClientTest, RequestNetConnection004, TestSize.Level1)
913 {
914     sptr<NetSpecifier> netSpecifier = new (std::nothrow) NetSpecifier();
915     netSpecifier->netCapabilities_.bearerTypes_.emplace(NetManagerStandard::BEARER_CELLULAR);
916     netSpecifier->netCapabilities_.netCaps_.emplace(NetManagerStandard::NET_CAPABILITY_INTERNAL_DEFAULT);
917     sptr<INetConnCallbackTest> callback = new (std::nothrow) INetConnCallbackTest();
918     uint32_t timesOut = 0;
919     auto ret = NetConnClient::GetInstance().RequestNetConnection(netSpecifier, callback, timesOut);
920     ret = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
921     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
922 }
923 
924 /**
925  * @tc.name: UpdateNetSupplierInfo001
926  * @tc.desc: Test NetConnClient::UpdateNetSupplierInfo, not applying for
927  * permission,return NETMANAGER_ERR_PERMISSION_DENIED
928  * @tc.type: FUNC
929  */
930 HWTEST_F(NetConnClientTest, UpdateNetSupplierInfo001, TestSize.Level1)
931 {
932     auto &client = NetConnClient::GetInstance();
933     uint32_t supplierId = 1;
934     sptr<NetSupplierInfo> netSupplierInfo = new (std::nothrow) NetSupplierInfo;
935     int32_t ret = client.UpdateNetSupplierInfo(supplierId, netSupplierInfo);
936     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
937 }
938 
939 /**
940  * @tc.name: UpdateNetSupplierInfo002
941  * @tc.desc: Test NetConnClient::UpdateNetSupplierInfo, not applying for
942  * permission,return NETMANAGER_ERR_PERMISSION_DENIED
943  * @tc.type: FUNC
944  */
945 HWTEST_F(NetConnClientTest, UpdateNetSupplierInfo002, TestSize.Level1)
946 {
947     NetManagerBaseAccessToken token;
948     auto &client = NetConnClient::GetInstance();
949     uint32_t supplierId = 1;
950     sptr<NetSupplierInfo> netSupplierInfo = new NetSupplierInfo;
951     netSupplierInfo->isAvailable_ = true;
952     netSupplierInfo->isRoaming_ = true;
953     netSupplierInfo->strength_ = 0x64;
954     netSupplierInfo->frequency_ = 0x10;
955     int32_t ret = client.UpdateNetSupplierInfo(supplierId, netSupplierInfo);
956     EXPECT_EQ(ret, NET_CONN_ERR_NO_SUPPLIER);
957 }
958 
959 /**
960  * @tc.name: GetNetInterfaceConfigurationTest001
961  * @tc.desc: Test NetConnClient::GetNetInterfaceConfiguration
962  * @tc.type: FUNC
963  */
964 HWTEST_F(NetConnClientTest, GetNetInterfaceConfigurationTest001, TestSize.Level1)
965 {
966     NetManagerBaseAccessToken token;
967     NetInterfaceConfiguration config;
968     auto ret = NetConnClient::GetInstance().GetNetInterfaceConfiguration(TEST_IFACE, config);
969     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
970 }
971 
972 /**
973  * @tc.name: GetNetInterfaceConfigurationTest001
974  * @tc.desc: Test NetConnClient::GetNetInterfaceConfiguration
975  * @tc.type: FUNC
976  */
977 HWTEST_F(NetConnClientTest, GetNetInterfaceConfigurationTest002, TestSize.Level1)
978 {
979     NetInterfaceConfiguration config;
980     auto ret = NetConnClient::GetInstance().GetNetInterfaceConfiguration(TEST_IFACE, config);
981     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
982 }
983 
984 /**
985  * @tc.name: RegisterNetInterfaceCallbackTest001
986  * @tc.desc: Test NetConnClient::RegisterNetInterfaceCallback
987  * @tc.type: FUNC
988  */
989 HWTEST_F(NetConnClientTest, RegisterNetInterfaceCallbackTest001, TestSize.Level1)
990 {
991     sptr<INetInterfaceStateCallback> callback = new (std::nothrow) NetInterfaceStateCallbackStub();
992     int32_t ret = NetConnClient::GetInstance().RegisterNetInterfaceCallback(callback);
993     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
994 }
995 
996 /**
997  * @tc.name: RegisterNetInterfaceCallbackTest002
998  * @tc.desc: Test NetConnClient::RegisterNetInterfaceCallback
999  * @tc.type: FUNC
1000  */
1001 HWTEST_F(NetConnClientTest, RegisterNetInterfaceCallbackTest002, TestSize.Level1)
1002 {
1003     NetManagerBaseAccessToken token;
1004     sptr<INetInterfaceStateCallback> callback = new (std::nothrow) NetInterfaceStateCallbackStub();
1005     int32_t ret = NetConnClient::GetInstance().RegisterNetInterfaceCallback(callback);
1006     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1007 }
1008 
1009 /**
1010  * @tc.name: SystemReadyTest002
1011  * @tc.desc: Test NetConnClient::SystemReady
1012  * @tc.type: FUNC
1013  */
1014 HWTEST_F(NetConnClientTest, SystemReadyTest002, TestSize.Level1)
1015 {
1016     NetManagerBaseAccessToken token;
1017     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->SystemReady();
1018     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1019 }
1020 
1021 /**
1022  * @tc.name: UpdateNetLinkInfoTest002
1023  * @tc.desc: Test NetConnClient::UpdateNetLinkInfo
1024  * @tc.type: FUNC
1025  */
1026 HWTEST_F(NetConnClientTest, UpdateNetLinkInfoTest002, TestSize.Level1)
1027 {
1028     NetManagerBaseAccessToken token;
1029     uint32_t supplierId = 1;
1030     sptr<NetLinkInfo> netLinkInfo = std::make_unique<NetLinkInfo>().release();
1031     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->UpdateNetLinkInfo(supplierId, netLinkInfo);
1032     EXPECT_EQ(ret, NET_CONN_ERR_NO_SUPPLIER);
1033 }
1034 
1035 /**
1036  * @tc.name: GetAllNetsTest002
1037  * @tc.desc: Test NetConnClient::GetAllNets
1038  * @tc.type: FUNC
1039  */
1040 HWTEST_F(NetConnClientTest, GetAllNetsTest002, TestSize.Level1)
1041 {
1042     NetManagerBaseAccessToken token;
1043     std::list<sptr<NetHandle>> netList;
1044     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->GetAllNets(netList);
1045     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1046 }
1047 
1048 /**
1049  * @tc.name: GetConnectionPropertiesTest002
1050  * @tc.desc: Test NetConnClient::GetConnectionProperties
1051  * @tc.type: FUNC
1052  */
1053 HWTEST_F(NetConnClientTest, GetConnectionPropertiesTest002, TestSize.Level1)
1054 {
1055     NetManagerBaseAccessToken token;
1056     NetHandle netHandle;
1057     NetLinkInfo info;
1058     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->GetConnectionProperties(netHandle, info);
1059     EXPECT_EQ(ret, NET_CONN_ERR_INVALID_NETWORK);
1060 }
1061 
1062 /**
1063  * @tc.name: GetAddressesByNameTest002
1064  * @tc.desc: Test NetConnClient::GetAddressesByName
1065  * @tc.type: FUNC
1066  */
1067 HWTEST_F(NetConnClientTest, GetAddressesByNameTest002, TestSize.Level1)
1068 {
1069     NetManagerBaseAccessToken token;
1070     const std::string host = "ipaddr";
1071     int32_t netId = 1;
1072     std::vector<INetAddr> addrList = {};
1073     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->GetAddressesByName(host, netId, addrList);
1074     EXPECT_EQ(ret, -1);
1075 }
1076 
1077 /**
1078  * @tc.name: GetAddressByNameTest002
1079  * @tc.desc: Test NetConnClient::GetAddressByName
1080  * @tc.type: FUNC
1081  */
1082 HWTEST_F(NetConnClientTest, GetAddressByNameTest002, TestSize.Level1)
1083 {
1084     NetManagerBaseAccessToken token;
1085     std::string host = "ipaddr";
1086     int32_t netId = 1;
1087     INetAddr addr;
1088     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->GetAddressByName(host, netId, addr);
1089     EXPECT_EQ(ret, -1);
1090 }
1091 
1092 /**
1093  * @tc.name: GetIfaceNameIdentMapsTest001
1094  * @tc.desc: Test NetConnClient::GetIfaceNameIdentMaps
1095  * @tc.type: FUNC
1096  */
1097 HWTEST_F(NetConnClientTest, GetIfaceNameIdentMapsTest001, TestSize.Level1)
1098 {
1099     NetManagerBaseAccessToken token;
1100     SafeMap<std::string, std::string> data;
1101     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->GetIfaceNameIdentMaps(NetBearType::BEARER_CELLULAR,
1102                                                                                         data);
1103     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1104 }
1105 
1106 /**
1107  * @tc.name: BindSocketTest002
1108  * @tc.desc: Test NetConnClient::BindSocket
1109  * @tc.type: FUNC
1110  */
1111 HWTEST_F(NetConnClientTest, BindSocketTest002, TestSize.Level1)
1112 {
1113     NetManagerBaseAccessToken token;
1114     NetConnClient::NetConnDeathRecipient deathRecipient(*DelayedSingleton<NetConnClient>::GetInstance());
1115     sptr<IRemoteObject> remote = nullptr;
1116     deathRecipient.OnRemoteDied(remote);
1117     int32_t socketFd = 0;
1118     int32_t netId = 99;
1119     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->BindSocket(socketFd, netId);
1120     EXPECT_EQ(ret, NET_CONN_ERR_INVALID_NETWORK);
1121     netId = 101;
1122     ret = DelayedSingleton<NetConnClient>::GetInstance()->BindSocket(socketFd, netId);
1123     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1124 }
1125 
1126 /**
1127  * @tc.name: NetDetectionTest002
1128  * @tc.desc: Test NetConnClient::NetDetection
1129  * @tc.type: FUNC
1130  */
1131 HWTEST_F(NetConnClientTest, NetDetectionTest002, TestSize.Level1)
1132 {
1133     NetManagerBaseAccessToken token;
1134     NetHandle netHandle;
1135     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->NetDetection(netHandle);
1136     EXPECT_EQ(ret, NET_CONN_ERR_NETID_NOT_FOUND);
1137 }
1138 
1139 HWTEST_F(NetConnClientTest, NetworkRouteTest001, TestSize.Level1)
1140 {
1141     NetManagerBaseAccessToken token;
1142     int32_t netId = 10;
1143     std::string ifName = "wlan0";
1144     std::string destination = "0.0.0.0/0";
1145     std::string nextHop = "0.0.0.1234";
1146 
1147     int32_t ret = NetConnClient::GetInstance().AddNetworkRoute(netId, ifName, destination, nextHop);
1148     EXPECT_EQ(ret, NETMANAGER_ERROR);
1149     ret = NetConnClient::GetInstance().RemoveNetworkRoute(netId, ifName, destination, nextHop);
1150     EXPECT_EQ(ret, NETMANAGER_ERROR);
1151 }
1152 
1153 HWTEST_F(NetConnClientTest, InterfaceAddressTest001, TestSize.Level1)
1154 {
1155     NetManagerBaseAccessToken token;
1156     std::string ifName = "wlan0";
1157     std::string ipAddr = "0.0.0.1";
1158     int32_t prefixLength = 23;
1159 
1160     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->AddInterfaceAddress(ifName, ipAddr, prefixLength);
1161     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1162     ret = DelayedSingleton<NetConnClient>::GetInstance()->DelInterfaceAddress(ifName, ipAddr, prefixLength);
1163     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1164 }
1165 
1166 HWTEST_F(NetConnClientTest, StaticArpTest001, TestSize.Level1)
1167 {
1168     NetManagerBaseAccessToken token;
1169     std::string ifName = "wlan0";
1170     std::string ipAddr = "123.12.12.123";
1171     std::string macAddr = "12:23:34:12:12:11";
1172     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->AddStaticArp(ipAddr, macAddr, ifName);
1173     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1174 
1175     ipAddr = "1234";
1176     macAddr = "12:23:34:12:12:11";
1177     ret = DelayedSingleton<NetConnClient>::GetInstance()->AddStaticArp(ipAddr, macAddr, ifName);
1178     EXPECT_EQ(ret, NETMANAGER_ERR_PARAMETER_ERROR);
1179 
1180     ipAddr = "123.12.12.123";
1181     macAddr = "12:234:34";
1182     ret = DelayedSingleton<NetConnClient>::GetInstance()->AddStaticArp(ipAddr, macAddr, ifName);
1183     EXPECT_EQ(ret, NETMANAGER_ERR_PARAMETER_ERROR);
1184 }
1185 
1186 HWTEST_F(NetConnClientTest, StaticArpTest002, TestSize.Level1)
1187 {
1188     NetManagerBaseAccessToken token;
1189     std::string ipAddr = "123.12.12.123";
1190     std::string macAddr = "12:23:34:12:12:11";
1191     std::string ifName = "wlan0";
1192     int32_t ret = DelayedSingleton<NetConnClient>::GetInstance()->DelStaticArp(ipAddr, macAddr, ifName);
1193     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1194 
1195     ipAddr = "123.12.12.123";
1196     macAddr = "12:23:34:12:12:11";
1197     ret = DelayedSingleton<NetConnClient>::GetInstance()->DelStaticArp(ipAddr, macAddr, ifName);
1198     EXPECT_EQ(ret, NETMANAGER_ERR_OPERATION_FAILED);
1199 
1200     ipAddr = "123.12.12.1235678";
1201     macAddr = "12:23:34:12:12:11";
1202     ret = DelayedSingleton<NetConnClient>::GetInstance()->DelStaticArp(ipAddr, macAddr, ifName);
1203     EXPECT_EQ(ret, NETMANAGER_ERR_PARAMETER_ERROR);
1204 
1205     ipAddr = "123.12.12.123";
1206     macAddr = "12:23:34:12:12";
1207     ret = DelayedSingleton<NetConnClient>::GetInstance()->DelStaticArp(ipAddr, macAddr, ifName);
1208     EXPECT_EQ(ret, NETMANAGER_ERR_PARAMETER_ERROR);
1209 
1210     ipAddr = "123.12.12.123";
1211     macAddr = "12:23:34:12:12:11";
1212     ifName = "";
1213     ret = DelayedSingleton<NetConnClient>::GetInstance()->DelStaticArp(ipAddr, macAddr, ifName);
1214     EXPECT_EQ(ret, NETMANAGER_ERR_OPERATION_FAILED);
1215 }
1216 
1217 HWTEST_F(NetConnClientTest, NetConnClientBranchTest001, TestSize.Level1)
1218 {
1219     int32_t uid = 0;
1220     uint8_t allow = 0;
1221     auto ret = DelayedSingleton<NetConnClient>::GetInstance()->SetInternetPermission(uid, allow);
1222     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
1223 
1224     uint32_t supplierId = 0;
1225     sptr<NetSupplierInfo> netSupplierInfo = nullptr;
1226     ret = DelayedSingleton<NetConnClient>::GetInstance()->UpdateNetSupplierInfo(supplierId, netSupplierInfo);
1227     EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
1228 
1229     sptr<NetLinkInfo> netLinkInfo = nullptr;
1230     ret = DelayedSingleton<NetConnClient>::GetInstance()->UpdateNetLinkInfo(supplierId, netLinkInfo);
1231     EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
1232 }
1233 
1234 HWTEST_F(NetConnClientTest, SetInternetPermissionTest001, TestSize.Level1)
1235 {
1236     NetManagerBaseAccessToken token;
1237     int32_t uid = 0;
1238     uint8_t allow = 0;
1239     NetConnClient::GetInstance().netPermissionMap_.EnsureInsert(0, 0);
1240     auto ret = NetConnClient::GetInstance().SetInternetPermission(uid, allow);
1241     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1242     EXPECT_EQ(NetConnClient::GetInstance().netPermissionMap_.Size(), 1);
1243 
1244     NetManagerBaseAccessToken access;
1245     ret = NetConnClient::GetInstance().SetInternetPermission(uid, allow);
1246     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1247     EXPECT_EQ(NetConnClient::GetInstance().netPermissionMap_.Size(), 1);
1248 }
1249 
1250 HWTEST_F(NetConnClientTest, RegisterSlotTypeTest002, TestSize.Level1)
1251 {
1252     NetManagerBaseAccessToken token;
1253     NetBearType netBearType = BEARER_CELLULAR;
1254     std::set<NetCap> netCaps{NET_CAPABILITY_INTERNET};
1255     std::string ident = "ident";
1256     uint32_t supplierId = 0;
1257     auto ret = NetConnClient::GetInstance().RegisterNetSupplier(netBearType, ident, netCaps, supplierId);
1258     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1259 
1260     int32_t tech = 2;
1261     ret = NetConnClient::GetInstance().RegisterSlotType(supplierId, tech);
1262     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1263 }
1264 
1265 HWTEST_F(NetConnClientTest, GetPinSetForHostName001, TestSize.Level1)
1266 {
1267     std::string hostname("www.example.com");
1268     std::string pins;
1269     auto ret = NetConnClient::GetInstance().GetPinSetForHostName(hostname, pins);
1270     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1271 }
1272 
1273 HWTEST_F(NetConnClientTest, GetTrustAnchorsForHostName001, TestSize.Level1)
1274 {
1275     std::string hostname("www.example.com");
1276     std::vector<std::string> certs;
1277     auto ret = NetConnClient::GetInstance().GetTrustAnchorsForHostName(hostname, certs);
1278     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1279 }
1280 
1281 /**
1282  * @tc.name: FactoryResetNetworkTest001
1283  * @tc.desc: Test NetConnClient::FactoryResetNetwork
1284  * @tc.type: FUNC
1285  */
1286 HWTEST_F(NetConnClientTest, FactoryResetNetworkTest001, TestSize.Level1)
1287 {
1288     NetManagerBaseAccessToken token;
1289     int32_t ret = NetConnClient::GetInstance().FactoryResetNetwork();
1290     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1291 }
1292 
1293 /**
1294  * @tc.name: RegisterNetFactoryResetCallbackTest001
1295  * @tc.desc: Test NetConnClient::RegisterNetFactoryResetCallback
1296  * @tc.type: FUNC
1297  */
1298 HWTEST_F(NetConnClientTest, RegisterNetFactoryResetCallbackTest001, TestSize.Level1)
1299 {
1300     sptr<INetFactoryResetCallbackTest> callback = new (std::nothrow) INetFactoryResetCallbackTest();
1301     int32_t ret = NetConnClient::GetInstance().RegisterNetFactoryResetCallback(callback);
1302     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
1303 }
1304 
1305 /**
1306  * @tc.name: RegisterNetFactoryResetCallbackTest002
1307  * @tc.desc: Test NetConnClient::RegisterNetFactoryResetCallback
1308  * @tc.type: FUNC
1309  */
1310 HWTEST_F(NetConnClientTest, RegisterNetFactoryResetCallbackTest002, TestSize.Level1)
1311 {
1312     NetManagerBaseAccessToken token;
1313 
1314     sptr<INetFactoryResetCallback> callback = nullptr;
1315     int32_t ret = NetConnClient::GetInstance().RegisterNetFactoryResetCallback(callback);
1316     EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
1317 
1318     callback = new (std::nothrow) INetFactoryResetCallbackTest();
1319     ASSERT_NE(callback, nullptr);
1320     ret = NetConnClient::GetInstance().RegisterNetFactoryResetCallback(callback);
1321     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1322 }
1323 
1324 HWTEST_F(NetConnClientTest, RegisterAppHttpProxyCallback001, TestSize.Level1)
1325 {
1326     std::function<void(const HttpProxy &httpProxy)> callback;
1327     uint32_t callbackid = 0;
1328     NetConnClient::GetInstance().RegisterAppHttpProxyCallback(callback, callbackid);
1329     EXPECT_EQ(callbackid, 0);
1330 
1331     NetConnClient::GetInstance().UnregisterAppHttpProxyCallback(callbackid);
1332 
1333     NetConnClient::GetInstance().RegisterAppHttpProxyCallback(callback, callbackid);
1334     EXPECT_EQ(callbackid, 1);
1335 }
1336 
1337 HWTEST_F(NetConnClientTest, SetAppHttpProxy001, TestSize.Level1)
1338 {
1339     HttpProxy httpProxy;
1340     auto ret = NetConnClient::GetInstance().SetAppHttpProxy(httpProxy);
1341     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1342 }
1343 
1344 HWTEST_F(NetConnClientTest, IsPreferCellularUrl, TestSize.Level1)
1345 {
1346     std::string url = "www.testPreferCellularUrl.com";
1347     bool preferCellular = false;
1348     NetConnClient::GetInstance().IsPreferCellularUrl(url, preferCellular);
1349     EXPECT_FALSE(preferCellular);
1350 }
1351 
1352 HWTEST_F(NetConnClientTest, RegisterPreAirplaneCallback, TestSize.Level1)
1353 {
1354     NetManagerBaseAccessToken token;
1355     sptr<PreAirplaneCallbackTest> callback = new (std::nothrow) PreAirplaneCallbackTest();
1356     int32_t ret = NetConnClient::GetInstance().RegisterPreAirplaneCallback(callback);
1357     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1358 }
1359 
1360 HWTEST_F(NetConnClientTest, RegisterPreAirplaneCallback2, TestSize.Level1)
1361 {
1362     NetManagerBaseAccessToken token;
1363     sptr<PreAirplaneCallbackTest> callback = nullptr;
1364     int32_t ret = NetConnClient::GetInstance().RegisterPreAirplaneCallback(callback);
1365     EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
1366 }
1367 
1368 HWTEST_F(NetConnClientTest, UnregisterPreAirplaneCallback, TestSize.Level1)
1369 {
1370     NetManagerBaseAccessToken token;
1371     sptr<PreAirplaneCallbackTest> callback = new (std::nothrow) PreAirplaneCallbackTest();
1372     int32_t ret = NetConnClient::GetInstance().UnregisterPreAirplaneCallback(callback);
1373     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1374 }
1375 
1376 HWTEST_F(NetConnClientTest, UpdateSupplierScore001, TestSize.Level1)
1377 {
1378     NetManagerBaseAccessToken token;
1379     uint32_t supplierId = 100;
1380     int32_t ret = NetConnClient::GetInstance().UpdateSupplierScore(NetBearType::BEARER_WIFI,
1381         QUALITY_POOR_STATE, supplierId);
1382     NetConnClient::GetInstance().DlCloseRemoveDeathRecipient();
1383     EXPECT_NE(ret, NETMANAGER_ERR_PERMISSION_DENIED);
1384 }
1385 } // namespace NetManagerStandard
1386 } // namespace OHOS
1387