1 /*
2 * Copyright (c) 2023-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 #include <iostream>
18 #include <memory>
19
20 #include "common_net_conn_callback_test.h"
21 #include "i_net_conn_service.h"
22 #include "i_net_detection_callback.h"
23 #include "i_net_factoryreset_callback.h"
24 #include "net_all_capabilities.h"
25 #include "net_conn_service_proxy.h"
26
27 namespace OHOS {
28 namespace NetManagerStandard {
29 using namespace testing::ext;
30 namespace {
31 constexpr int32_t TEST_UID = 1010;
32 constexpr const char *TEST_IDENT = "testIdent";
33 constexpr uint32_t TEST_TIMEOUTMS = 1000;
34 constexpr const char *TEST_HOST = "testHost";
35 constexpr int32_t TEST_NETID = 3;
36 constexpr int32_t TEST_SOCKETFD = 2;
37 constexpr int32_t TEST_SUPPLIERID = 1021;
38
39 uint32_t g_supplierId = 0;
40 class MockNetIRemoteObject : public IRemoteObject {
41 public:
MockNetIRemoteObject()42 MockNetIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {}
~MockNetIRemoteObject()43 ~MockNetIRemoteObject() {}
44
GetObjectRefCount()45 int32_t GetObjectRefCount() override
46 {
47 return 0;
48 }
49
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)50 int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override
51 {
52 reply.WriteInt32(NETMANAGER_SUCCESS);
53 switch (code) {
54 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACE_NAMES):
55 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_NET):
56 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ALL_NETS):
57 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESSES_BY_NAME):
58 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_ID_BY_IDENTIFIER):
59 reply.WriteUint32(NETMANAGER_SUCCESS);
60 break;
61
62 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACENAME_BY_TYPE):
63 reply.WriteString(TEST_HOST);
64 break;
65
66 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GETDEFAULTNETWORK):
67 reply.WriteInt32(TEST_NETID);
68 break;
69
70 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_HASDEFAULTNET):
71 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_DEFAULT_NET_METERED):
72 reply.WriteBool(true);
73 break;
74
75 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_CONNECTION_PROPERTIES): {
76 NetLinkInfo linkInfo;
77 linkInfo.ifaceName_ = "ifacename_test";
78 linkInfo.Marshalling(reply);
79 break;
80 }
81
82 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_CAPABILITIES): {
83 NetAllCapabilities netCap;
84 netCap.Marshalling(reply);
85 break;
86 }
87
88 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESS_BY_NAME): {
89 INetAddr addr;
90 addr.Marshalling(reply);
91 break;
92 }
93
94 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_GLOBAL_HTTP_PROXY):
95 case static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_DEFAULT_HTTP_PROXY): {
96 HttpProxy httpProxy;
97 httpProxy.Marshalling(reply);
98 break;
99 }
100
101 default:
102 reply.WriteUint32(TEST_SUPPLIERID);
103 break;
104 }
105
106 return eCode;
107 }
108
IsProxyObject() const109 bool IsProxyObject() const override
110 {
111 return true;
112 }
113
CheckObjectLegality() const114 bool CheckObjectLegality() const override
115 {
116 return true;
117 }
118
AddDeathRecipient(const sptr<DeathRecipient> & recipient)119 bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override
120 {
121 return true;
122 }
123
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)124 bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override
125 {
126 return true;
127 }
128
Marshalling(Parcel & parcel) const129 bool Marshalling(Parcel &parcel) const override
130 {
131 return true;
132 }
133
AsInterface()134 sptr<IRemoteBroker> AsInterface() override
135 {
136 return nullptr;
137 }
138
Dump(int fd,const std::vector<std::u16string> & args)139 int Dump(int fd, const std::vector<std::u16string> &args) override
140 {
141 return 0;
142 }
143
GetObjectDescriptor() const144 std::u16string GetObjectDescriptor() const
145 {
146 std::u16string descriptor = std::u16string();
147 return descriptor;
148 }
149
SetErrorCode(int errorCode)150 void SetErrorCode(int errorCode)
151 {
152 eCode = errorCode;
153 }
154
155 private:
156 int eCode = NETMANAGER_SUCCESS;
157 };
158
159 class NetDetectionTestCallback : public IRemoteStub<INetDetectionCallback> {
160 public:
OnNetDetectionResultChanged(NetDetectionResultCode resultCode,const std::string & urlRedirect)161 int32_t OnNetDetectionResultChanged(NetDetectionResultCode resultCode, const std::string &urlRedirect) override
162 {
163 return 0;
164 }
165 };
166
167 class NetFactoryResetTestCallback : public IRemoteStub<INetFactoryResetCallback> {
168 public:
OnNetFactoryReset()169 int32_t OnNetFactoryReset() override
170 {
171 return 0;
172 }
173 };
174
175 class NetConnServiceProxyTest : public testing::Test {
176 public:
177 static void SetUpTestCase();
178 static void TearDownTestCase();
179 void SetUp();
180 void TearDown();
181
182 static inline sptr<MockNetIRemoteObject> remoteObj_ = std::make_unique<MockNetIRemoteObject>().release();
183 static inline std::shared_ptr<NetConnServiceProxy> instance_ = std::make_shared<NetConnServiceProxy>(remoteObj_);
184 static inline sptr<INetSupplierCallback> supplierCallback_ = new (std::nothrow) NetSupplierCallbackStub();
185 static inline sptr<INetConnCallback> netConnCallback_ = new (std::nothrow) NetConnCallbackStubCb();
186 static inline sptr<INetDetectionCallback> detectionCallback_ = new (std::nothrow) NetDetectionTestCallback();
187 static inline sptr<INetFactoryResetCallback> netFactoryResetCallback_ =
188 new (std::nothrow) NetFactoryResetTestCallback();
189 };
190
SetUpTestCase()191 void NetConnServiceProxyTest::SetUpTestCase() {}
192
TearDownTestCase()193 void NetConnServiceProxyTest::TearDownTestCase() {}
194
SetUp()195 void NetConnServiceProxyTest::SetUp() {}
196
TearDown()197 void NetConnServiceProxyTest::TearDown() {}
198
199 /**
200 * @tc.name: SystemReadyTest001
201 * @tc.desc: Test NetConnServiceProxy SystemReady.
202 * @tc.type: FUNC
203 */
204 HWTEST_F(NetConnServiceProxyTest, SystemReadyTest001, TestSize.Level1)
205 {
206 int32_t ret = instance_->SystemReady();
207 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
208 }
209
210 /**
211 * @tc.name: SetInternetPermissionTest001
212 * @tc.desc: Test NetConnServiceProxy SetInternetPermission.
213 * @tc.type: FUNC
214 */
215 HWTEST_F(NetConnServiceProxyTest, SetInternetPermissionTest001, TestSize.Level1)
216 {
217 int32_t ret = instance_->SetInternetPermission(TEST_UID, true);
218 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
219 }
220
221 /**
222 * @tc.name: RegisterNetSupplierTest001
223 * @tc.desc: Test NetConnServiceProxy RegisterNetSupplier.
224 * @tc.type: FUNC
225 */
226 HWTEST_F(NetConnServiceProxyTest, RegisterNetSupplierTest001, TestSize.Level1)
227 {
228 std::set<NetCap> netCaps;
229 int32_t ret = instance_->RegisterNetSupplier(NetBearType::BEARER_ETHERNET, TEST_IDENT, netCaps, g_supplierId);
230 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
231 }
232
233 /**
234 * @tc.name: UnregisterNetSupplierTest001
235 * @tc.desc: Test NetConnServiceProxy UnregisterNetSupplier.
236 * @tc.type: FUNC
237 */
238 HWTEST_F(NetConnServiceProxyTest, UnregisterNetSupplierTest001, TestSize.Level1)
239 {
240 int32_t ret = instance_->UnregisterNetSupplier(g_supplierId);
241 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
242 }
243
244 /**
245 * @tc.name: RegisterNetSupplierCallbackTest001
246 * @tc.desc: Test NetConnServiceProxy RegisterNetSupplierCallback.
247 * @tc.type: FUNC
248 */
249 HWTEST_F(NetConnServiceProxyTest, RegisterNetSupplierCallbackTest001, TestSize.Level1)
250 {
251 int32_t ret = instance_->RegisterNetSupplierCallback(g_supplierId, supplierCallback_);
252 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
253 }
254
255 /**
256 * @tc.name: RegisterNetConnCallbackTest001
257 * @tc.desc: Test NetConnServiceProxy RegisterNetConnCallback.
258 * @tc.type: FUNC
259 */
260 HWTEST_F(NetConnServiceProxyTest, RegisterNetConnCallbackTest001, TestSize.Level1)
261 {
262 int32_t ret = instance_->RegisterNetConnCallback(netConnCallback_);
263 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
264 }
265
266 /**
267 * @tc.name: RegisterNetConnCallbackTest002
268 * @tc.desc: Test NetConnServiceProxy RegisterNetConnCallback.
269 * @tc.type: FUNC
270 */
271 HWTEST_F(NetConnServiceProxyTest, RegisterNetConnCallbackTest002, TestSize.Level1)
272 {
273 sptr<NetSpecifier> netSpecifier = new (std::nothrow) NetSpecifier();
274 int32_t ret = instance_->RegisterNetConnCallback(netSpecifier, netConnCallback_, TEST_TIMEOUTMS);
275 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
276 }
277
278 /**
279 * @tc.name: RequestNetConnectionTest001
280 * @tc.desc: Test NetConnServiceProxy RequestNetConnection.
281 * @tc.type: FUNC
282 */
283 HWTEST_F(NetConnServiceProxyTest, RequestNetConnectionTest001, TestSize.Level1)
284 {
285 sptr<NetSpecifier> netSpecifier = new (std::nothrow) NetSpecifier();
286 int32_t ret = instance_->RequestNetConnection(netSpecifier, netConnCallback_, TEST_TIMEOUTMS);
287 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
288 }
289
290 /**
291 * @tc.name: UnregisterNetConnCallbackTest001
292 * @tc.desc: Test NetConnServiceProxy UnregisterNetConnCallback.
293 * @tc.type: FUNC
294 */
295 HWTEST_F(NetConnServiceProxyTest, UnregisterNetConnCallbackTest001, TestSize.Level1)
296 {
297 int32_t ret = instance_->UnregisterNetConnCallback(netConnCallback_);
298 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
299 }
300
301 /**
302 * @tc.name: UpdateNetStateForTest001
303 * @tc.desc: Test NetConnServiceProxy UpdateNetStateForTest.
304 * @tc.type: FUNC
305 */
306 HWTEST_F(NetConnServiceProxyTest, UpdateNetStateForTest001, TestSize.Level1)
307 {
308 int32_t netState = 0;
309 sptr<NetSpecifier> netSpecifier = new (std::nothrow) NetSpecifier();
310 int32_t ret = instance_->UpdateNetStateForTest(netSpecifier, netState);
311 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
312 }
313
314 /**
315 * @tc.name: UpdateNetSupplierInfoTest001
316 * @tc.desc: Test NetConnServiceProxy UpdateNetSupplierInfo.
317 * @tc.type: FUNC
318 */
319 HWTEST_F(NetConnServiceProxyTest, UpdateNetSupplierInfoTest001, TestSize.Level1)
320 {
321 sptr<NetSupplierInfo> netSupplierInfo = new (std::nothrow) NetSupplierInfo();
322 int32_t ret = instance_->UpdateNetSupplierInfo(g_supplierId, netSupplierInfo);
323 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
324 }
325
326 /**
327 * @tc.name: UpdateNetLinkInfoTest001
328 * @tc.desc: Test NetConnServiceProxy UpdateNetLinkInfo.
329 * @tc.type: FUNC
330 */
331 HWTEST_F(NetConnServiceProxyTest, UpdateNetLinkInfoTest001, TestSize.Level1)
332 {
333 sptr<NetLinkInfo> netLinkInfo = new (std::nothrow) NetLinkInfo();
334 int32_t ret = instance_->UpdateNetLinkInfo(g_supplierId, netLinkInfo);
335 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
336 }
337
338 /**
339 * @tc.name: RegisterNetDetectionCallbackTest001
340 * @tc.desc: Test NetConnServiceProxy RegisterNetDetectionCallback.
341 * @tc.type: FUNC
342 */
343 HWTEST_F(NetConnServiceProxyTest, RegisterNetDetectionCallbackTest001, TestSize.Level1)
344 {
345 int32_t ret = instance_->RegisterNetDetectionCallback(TEST_NETID, detectionCallback_);
346 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
347 }
348
349 /**
350 * @tc.name: UnRegisterNetDetectionCallbackTest001
351 * @tc.desc: Test NetConnServiceProxy UnRegisterNetDetectionCallback.
352 * @tc.type: FUNC
353 */
354 HWTEST_F(NetConnServiceProxyTest, UnRegisterNetDetectionCallbackTest001, TestSize.Level1)
355 {
356 int32_t ret = instance_->UnRegisterNetDetectionCallback(TEST_NETID, detectionCallback_);
357 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
358 }
359
360 /**
361 * @tc.name: NetDetectionTest001
362 * @tc.desc: Test NetConnServiceProxy NetDetection.
363 * @tc.type: FUNC
364 */
365 HWTEST_F(NetConnServiceProxyTest, NetDetectionTest001, TestSize.Level1)
366 {
367 int32_t ret = instance_->NetDetection(TEST_NETID);
368 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
369 }
370
371 /**
372 * @tc.name: GetIfaceNamesTest001
373 * @tc.desc: Test NetConnServiceProxy GetIfaceNames.
374 * @tc.type: FUNC
375 */
376 HWTEST_F(NetConnServiceProxyTest, GetIfaceNamesTest001, TestSize.Level1)
377 {
378 std::list<std::string> ifaceNames;
379 int32_t ret = instance_->GetIfaceNames(NetBearType::BEARER_ETHERNET, ifaceNames);
380 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
381 }
382
383 /**
384 * @tc.name: GetIfaceNameByTypeTest001
385 * @tc.desc: Test NetConnServiceProxy GetIfaceNameByType.
386 * @tc.type: FUNC
387 */
388 HWTEST_F(NetConnServiceProxyTest, GetIfaceNameByTypeTest001, TestSize.Level1)
389 {
390 std::string ifaceName;
391 int32_t ret = instance_->GetIfaceNameByType(NetBearType::BEARER_ETHERNET, TEST_IDENT, ifaceName);
392 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
393 }
394
395 /**
396 * @tc.name: GetDefaultNetTest001
397 * @tc.desc: Test NetConnServiceProxy GetDefaultNet.
398 * @tc.type: FUNC
399 */
400 HWTEST_F(NetConnServiceProxyTest, GetDefaultNetTest001, TestSize.Level1)
401 {
402 int32_t netId = 0;
403 int32_t ret = instance_->GetDefaultNet(netId);
404 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
405 }
406
407 /**
408 * @tc.name: HasDefaultNetTest001
409 * @tc.desc: Test NetConnServiceProxy HasDefaultNet.
410 * @tc.type: FUNC
411 */
412 HWTEST_F(NetConnServiceProxyTest, HasDefaultNetTest001, TestSize.Level1)
413 {
414 bool hasDefaultNet = false;
415 int32_t ret = instance_->HasDefaultNet(hasDefaultNet);
416 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
417 EXPECT_EQ(hasDefaultNet, true);
418 }
419
420 /**
421 * @tc.name: GetSpecificNetTest001
422 * @tc.desc: Test NetConnServiceProxy GetSpecificNet.
423 * @tc.type: FUNC
424 */
425 HWTEST_F(NetConnServiceProxyTest, GetSpecificNetTest001, TestSize.Level1)
426 {
427 std::list<int32_t> netIdList;
428 int32_t ret = instance_->GetSpecificNet(NetBearType::BEARER_ETHERNET, netIdList);
429 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
430 }
431
432 /**
433 * @tc.name: GetAllNetsTest001
434 * @tc.desc: Test NetConnServiceProxy GetAllNets.
435 * @tc.type: FUNC
436 */
437 HWTEST_F(NetConnServiceProxyTest, GetAllNetsTest001, TestSize.Level1)
438 {
439 std::list<int32_t> netIdList;
440 int32_t ret = instance_->GetAllNets(netIdList);
441 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
442 }
443
444 /**
445 * @tc.name: GetSpecificUidNetTest001
446 * @tc.desc: Test NetConnServiceProxy GetSpecificUidNet.
447 * @tc.type: FUNC
448 */
449 HWTEST_F(NetConnServiceProxyTest, GetSpecificUidNetTest001, TestSize.Level1)
450 {
451 int32_t netId = 0;
452 int32_t ret = instance_->GetSpecificUidNet(TEST_UID, netId);
453 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
454 }
455
456 /**
457 * @tc.name: GetConnectionPropertiesTest001
458 * @tc.desc: Test NetConnServiceProxy GetConnectionProperties.
459 * @tc.type: FUNC
460 */
461 HWTEST_F(NetConnServiceProxyTest, GetConnectionPropertiesTest001, TestSize.Level1)
462 {
463 NetLinkInfo info;
464 int32_t ret = instance_->GetConnectionProperties(TEST_NETID, info);
465 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
466 }
467
468 /**
469 * @tc.name: GetNetCapabilitiesTest001
470 * @tc.desc: Test NetConnServiceProxy GetNetCapabilities.
471 * @tc.type: FUNC
472 */
473 HWTEST_F(NetConnServiceProxyTest, GetNetCapabilitiesTest001, TestSize.Level1)
474 {
475 NetAllCapabilities netAllCap;
476 int32_t ret = instance_->GetNetCapabilities(TEST_NETID, netAllCap);
477 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
478 }
479
480 /**
481 * @tc.name: GetAddressesByNameTest001
482 * @tc.desc: Test NetConnServiceProxy GetAddressesByName.
483 * @tc.type: FUNC
484 */
485 HWTEST_F(NetConnServiceProxyTest, GetAddressesByNameTest001, TestSize.Level1)
486 {
487 std::string host;
488 std::vector<INetAddr> addrList;
489 int32_t ret = instance_->GetAddressesByName(host, TEST_NETID, addrList);
490 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
491 }
492
493 /**
494 * @tc.name: GetAddressesByNameTest001
495 * @tc.desc: Test NetConnServiceProxy GetAddressesByName.
496 * @tc.type: FUNC
497 */
498 HWTEST_F(NetConnServiceProxyTest, GetAddresseByNameTest001, TestSize.Level1)
499 {
500 std::string host;
501 INetAddr addr;
502 int32_t ret = instance_->GetAddressByName(host, TEST_NETID, addr);
503 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
504 }
505
506 /**
507 * @tc.name: BindSocketTest001
508 * @tc.desc: Test NetConnServiceProxy BindSocket.
509 * @tc.type: FUNC
510 */
511 HWTEST_F(NetConnServiceProxyTest, BindSocketTest001, TestSize.Level1)
512 {
513 int32_t ret = instance_->BindSocket(TEST_SOCKETFD, TEST_NETID);
514 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
515 }
516
517 /**
518 * @tc.name: SetAirplaneModeTest001
519 * @tc.desc: Test NetConnServiceProxy SetAirplaneMode.
520 * @tc.type: FUNC
521 */
522 HWTEST_F(NetConnServiceProxyTest, SetAirplaneModeTest001, TestSize.Level1)
523 {
524 bool airplaneMode = true;
525 int32_t ret = instance_->SetAirplaneMode(airplaneMode);
526 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
527 }
528
529 /**
530 * @tc.name: IsDefaultNetMeteredTest001
531 * @tc.desc: Test NetConnServiceProxy IsDefaultNetMetered.
532 * @tc.type: FUNC
533 */
534 HWTEST_F(NetConnServiceProxyTest, IsDefaultNetMeteredTest001, TestSize.Level1)
535 {
536 bool isMetered;
537 int32_t ret = instance_->IsDefaultNetMetered(isMetered);
538 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
539 }
540
541 /**
542 * @tc.name: SetGlobalHttpProxyTest001
543 * @tc.desc: Test NetConnServiceProxy SetGlobalHttpProxy.
544 * @tc.type: FUNC
545 */
546 HWTEST_F(NetConnServiceProxyTest, SetGlobalHttpProxyTest001, TestSize.Level1)
547 {
548 HttpProxy proxy;
549 proxy.SetHost(TEST_HOST);
550 int32_t ret = instance_->SetGlobalHttpProxy(proxy);
551 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
552 }
553
554 /**
555 * @tc.name: GetGlobalHttpProxyTest001
556 * @tc.desc: Test NetConnServiceProxy GetGlobalHttpProxy.
557 * @tc.type: FUNC
558 */
559 HWTEST_F(NetConnServiceProxyTest, GetGlobalHttpProxyTest001, TestSize.Level1)
560 {
561 HttpProxy proxy;
562 int32_t ret = instance_->GetGlobalHttpProxy(proxy);
563 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
564 }
565
566 /**
567 * @tc.name: GetNetIdByIdentifierTest001
568 * @tc.desc: Test NetConnServiceProxy GetNetIdByIdentifier.
569 * @tc.type: FUNC
570 */
571 HWTEST_F(NetConnServiceProxyTest, GetNetIdByIdentifierTest001, TestSize.Level1)
572 {
573 std::list<int32_t> netIdList;
574 int32_t ret = instance_->GetNetIdByIdentifier(TEST_IDENT, netIdList);
575 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
576 }
577
578 /**
579 * @tc.name: SetAppNetTest001
580 * @tc.desc: Test NetConnServiceProxy SetAppNet.
581 * @tc.type: FUNC
582 */
583 HWTEST_F(NetConnServiceProxyTest, SetAppNetTest001, TestSize.Level1)
584 {
585 int32_t ret = instance_->SetAppNet(TEST_NETID);
586 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
587 }
588
589 /**
590 * @tc.name: FactoryResetNetworkTest001
591 * @tc.desc: Test NetConnServiceProxy FactoryResetNetwork.
592 * @tc.type: FUNC
593 */
594 HWTEST_F(NetConnServiceProxyTest, FactoryResetNetworkTest001, TestSize.Level1)
595 {
596 int32_t ret = instance_->FactoryResetNetwork();
597 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
598 }
599
600 /**
601 * @tc.name: RegisterNetConnCallbackTest001
602 * @tc.desc: Test NetConnServiceProxy RegisterNetFactoryResetCallback.
603 * @tc.type: FUNC
604 */
605 HWTEST_F(NetConnServiceProxyTest, RegisterNetFactoryResetCallbackTest001, TestSize.Level1)
606 {
607 int32_t ret = instance_->RegisterNetFactoryResetCallback(netFactoryResetCallback_);
608 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
609 }
610
611 /**
612 * @tc.name: NetConnServiceProxyBranchTest001
613 * @tc.desc: Test NetConnServiceProxy Branch.
614 * @tc.type: FUNC
615 */
616 HWTEST_F(NetConnServiceProxyTest, NetConnServiceProxyBranchTest001, TestSize.Level1)
617 {
618 sptr<INetSupplierCallback> supplierCallback = nullptr;
619 int32_t ret = instance_->RegisterNetSupplierCallback(g_supplierId, supplierCallback);
620 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
621
622 sptr<INetConnCallback> connCallback = nullptr;
623 ret = instance_->RegisterNetConnCallback(connCallback);
624 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
625
626 sptr<NetSpecifier> netSpecifier = nullptr;
627 uint32_t timeoutMS = 0;
628 ret = instance_->RegisterNetConnCallback(netSpecifier, connCallback, timeoutMS);
629 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
630
631 ret = instance_->RequestNetConnection(netSpecifier, connCallback, timeoutMS);
632 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
633
634 ret = instance_->UnregisterNetConnCallback(connCallback);
635 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
636
637 int32_t netState = 0;
638 ret = instance_->UpdateNetStateForTest(netSpecifier, netState);
639 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
640
641 sptr<INetInterfaceStateCallback> stateCallback = nullptr;
642 ret = instance_->RegisterNetInterfaceCallback(stateCallback);
643 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
644
645 sptr<INetFactoryResetCallback> netFactoryResetCallback = nullptr;
646 ret = instance_->RegisterNetFactoryResetCallback(netFactoryResetCallback);
647 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
648 }
649
650 HWTEST_F(NetConnServiceProxyTest, EnableVnicNetwork001, TestSize.Level1)
651 {
652 sptr<NetManagerStandard::NetLinkInfo> linkInfo = nullptr;
653 std::set<int32_t> uids;
654 int32_t ret = instance_->EnableVnicNetwork(linkInfo, uids);
655 EXPECT_EQ(ret, NETMANAGER_ERR_LOCAL_PTR_NULL);
656 }
657
658 HWTEST_F(NetConnServiceProxyTest, EnableVnicNetwork002, TestSize.Level1)
659 {
660 sptr<NetManagerStandard::NetLinkInfo> linkInfo = nullptr;
661 std::set<int32_t> uids;
662
663 linkInfo = new (std::nothrow) NetManagerStandard::NetLinkInfo();
664 ASSERT_NE(linkInfo, nullptr);
665
666 NetManagerStandard::INetAddr inetAddr;
667 inetAddr.type_ = NetManagerStandard::INetAddr::IpType::IPV4;
668 inetAddr.family_ = 0x01;
669 inetAddr.address_ = "10.0.0.2";
670 inetAddr.netMask_ = "255.255.255.0";
671 inetAddr.hostName_ = "localhost";
672 inetAddr.port_ = 80;
673 inetAddr.prefixlen_ = 24;
674
675 linkInfo->ifaceName_ = "vnic-tun";
676 linkInfo->netAddrList_.push_back(inetAddr);
677 linkInfo->mtu_ = 1500;
678
679 int32_t ret = instance_->EnableVnicNetwork(linkInfo, uids);
680 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
681 }
682
683 HWTEST_F(NetConnServiceProxyTest, DisableVnicNetwork001, TestSize.Level1)
684 {
685 int32_t ret = instance_->DisableVnicNetwork();
686 EXPECT_EQ(ret, NETMANAGER_SUCCESS);
687 }
688 }
689 } // namespace NetManagerStandard
690 } // namespace OHOS
691