1 /*
2 * Copyright (c) 2023 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 #define private public
19 #include "i_netsys_service.h"
20 #include "net_manager_constants.h"
21 #include "netsys_native_service_stub.h"
22 #undef private
23 #include "notify_callback_stub.h"
24
25 namespace OHOS {
26 namespace NetsysNative {
27 namespace {
28 using namespace testing::ext;
29 #define DTEST_LOG std::cout << __func__ << ":" << __LINE__ << ":"
30 }
31
32 class TestNotifyCallback : public NotifyCallbackStub {
33 public:
34 TestNotifyCallback() = default;
~TestNotifyCallback()35 ~TestNotifyCallback() override {};
OnInterfaceAddressUpdated(const std::string & addr,const std::string & ifName,int flags,int scope)36 int32_t OnInterfaceAddressUpdated(const std::string &addr, const std::string &ifName, int flags,
37 int scope) override
38 {
39 return 0;
40 }
41
OnInterfaceAddressRemoved(const std::string & addr,const std::string & ifName,int flags,int scope)42 int32_t OnInterfaceAddressRemoved(const std::string &addr, const std::string &ifName, int flags,
43 int scope) override
44 {
45 return 0;
46 }
47
OnInterfaceAdded(const std::string & ifName)48 int32_t OnInterfaceAdded(const std::string &ifName) override
49 {
50 return 0;
51 }
52
OnInterfaceRemoved(const std::string & ifName)53 int32_t OnInterfaceRemoved(const std::string &ifName) override
54 {
55 return 0;
56 }
57
OnInterfaceChanged(const std::string & ifName,bool up)58 int32_t OnInterfaceChanged(const std::string &ifName, bool up) override
59 {
60 return 0;
61 }
62
OnInterfaceLinkStateChanged(const std::string & ifName,bool up)63 int32_t OnInterfaceLinkStateChanged(const std::string &ifName, bool up) override
64 {
65 return 0;
66 }
67
OnRouteChanged(bool updated,const std::string & route,const std::string & gateway,const std::string & ifName)68 int32_t OnRouteChanged(bool updated, const std::string &route, const std::string &gateway,
69 const std::string &ifName) override
70 {
71 return 0;
72 }
73
OnDhcpSuccess(sptr<OHOS::NetsysNative::DhcpResultParcel> & dhcpResult)74 int32_t OnDhcpSuccess(sptr<OHOS::NetsysNative::DhcpResultParcel> &dhcpResult) override
75 {
76 return 0;
77 }
78
OnBandwidthReachedLimit(const std::string & limitName,const std::string & iface)79 int32_t OnBandwidthReachedLimit(const std::string &limitName, const std::string &iface) override
80 {
81 return 0;
82 }
83 };
84
85 class TestNetsysNativeServiceStub : public NetsysNativeServiceStub {
86 public:
87 TestNetsysNativeServiceStub() = default;
~TestNetsysNativeServiceStub()88 ~TestNetsysNativeServiceStub() override {};
89
SetInternetPermission(uint32_t uid,uint8_t allow)90 int32_t SetInternetPermission(uint32_t uid, uint8_t allow) override
91 {
92 return 0;
93 }
94
SetResolverConfig(uint16_t netId,uint16_t baseTimeoutMsec,uint8_t retryCount,const std::vector<std::string> & servers,const std::vector<std::string> & domains)95 int32_t SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
96 const std::vector<std::string> &servers,
97 const std::vector<std::string> &domains) override
98 {
99 return 0;
100 }
101
GetResolverConfig(uint16_t netId,std::vector<std::string> & servers,std::vector<std::string> & domains,uint16_t & baseTimeoutMsec,uint8_t & retryCount)102 int32_t GetResolverConfig(uint16_t netId, std::vector<std::string> &servers,
103 std::vector<std::string> &domains, uint16_t &baseTimeoutMsec,
104 uint8_t &retryCount) override
105 {
106 return 0;
107 }
108
CreateNetworkCache(uint16_t netId)109 int32_t CreateNetworkCache(uint16_t netId) override
110 {
111 return 0;
112 }
113
DestroyNetworkCache(uint16_t netId)114 int32_t DestroyNetworkCache(uint16_t netId) override
115 {
116 return 0;
117 }
118
GetAddrInfo(const std::string & hostName,const std::string & serverName,const AddrInfo & hints,uint16_t netId,std::vector<AddrInfo> & res)119 int32_t GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints,
120 uint16_t netId, std::vector<AddrInfo> &res) override
121 {
122 return 0;
123 }
124
SetInterfaceMtu(const std::string & interfaceName,int mtu)125 int32_t SetInterfaceMtu(const std::string &interfaceName, int mtu) override
126 {
127 return 0;
128 }
129
GetInterfaceMtu(const std::string & interfaceName)130 int32_t GetInterfaceMtu(const std::string &interfaceName) override
131 {
132 return 0;
133 }
134
RegisterNotifyCallback(sptr<INotifyCallback> & callback)135 int32_t RegisterNotifyCallback(sptr<INotifyCallback> &callback) override
136 {
137 return 0;
138 }
139
UnRegisterNotifyCallback(sptr<INotifyCallback> & callback)140 int32_t UnRegisterNotifyCallback(sptr<INotifyCallback> &callback) override
141 {
142 return 0;
143 }
144
NetworkAddRoute(int32_t netId,const std::string & interfaceName,const std::string & destination,const std::string & nextHop)145 int32_t NetworkAddRoute(int32_t netId, const std::string &interfaceName, const std::string &destination,
146 const std::string &nextHop) override
147 {
148 return 0;
149 }
150
NetworkRemoveRoute(int32_t netId,const std::string & interfaceName,const std::string & destination,const std::string & nextHop)151 int32_t NetworkRemoveRoute(int32_t netId, const std::string &interfaceName, const std::string &destination,
152 const std::string &nextHop) override
153 {
154 return 0;
155 }
156
NetworkAddRouteParcel(int32_t netId,const RouteInfoParcel & routeInfo)157 int32_t NetworkAddRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) override
158 {
159 return 0;
160 }
161
NetworkRemoveRouteParcel(int32_t netId,const RouteInfoParcel & routeInfo)162 int32_t NetworkRemoveRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) override
163 {
164 return 0;
165 }
166
NetworkSetDefault(int32_t netId)167 int32_t NetworkSetDefault(int32_t netId) override
168 {
169 return 0;
170 }
171
NetworkGetDefault()172 int32_t NetworkGetDefault() override
173 {
174 return 0;
175 }
176
NetworkClearDefault()177 int32_t NetworkClearDefault() override
178 {
179 return 0;
180 }
181
GetProcSysNet(int32_t family,int32_t which,const std::string & ifname,const std::string & parameter,std::string & value)182 int32_t GetProcSysNet(int32_t family, int32_t which, const std::string &ifname,
183 const std::string ¶meter, std::string &value) override
184 {
185 return 0;
186 }
187
SetProcSysNet(int32_t family,int32_t which,const std::string & ifname,const std::string & parameter,std::string & value)188 int32_t SetProcSysNet(int32_t family, int32_t which, const std::string &ifname,
189 const std::string ¶meter, std::string &value) override
190 {
191 return 0;
192 }
193
NetworkCreatePhysical(int32_t netId,int32_t permission)194 int32_t NetworkCreatePhysical(int32_t netId, int32_t permission) override
195 {
196 return 0;
197 }
198
NetworkCreateVirtual(int32_t netId,bool hasDns)199 int32_t NetworkCreateVirtual(int32_t netId, bool hasDns) override
200 {
201 return 0;
202 }
203
NetworkAddUids(int32_t netId,const std::vector<UidRange> & uidRanges)204 int32_t NetworkAddUids(int32_t netId, const std::vector<UidRange> &uidRanges) override
205 {
206 return 0;
207 }
208
NetworkDelUids(int32_t netId,const std::vector<UidRange> & uidRanges)209 int32_t NetworkDelUids(int32_t netId, const std::vector<UidRange> &uidRanges) override
210 {
211 return 0;
212 }
213
AddInterfaceAddress(const std::string & interfaceName,const std::string & addrString,int32_t prefixLength)214 int32_t AddInterfaceAddress(const std::string &interfaceName, const std::string &addrString,
215 int32_t prefixLength) override
216 {
217 return 0;
218 }
219
DelInterfaceAddress(const std::string & interfaceName,const std::string & addrString,int32_t prefixLength)220 int32_t DelInterfaceAddress(const std::string &interfaceName, const std::string &addrString,
221 int32_t prefixLength) override
222 {
223 return 0;
224 }
225
InterfaceSetIpAddress(const std::string & ifaceName,const std::string & ipAddress)226 int32_t InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress) override
227 {
228 return 0;
229 }
230
InterfaceSetIffUp(const std::string & ifaceName)231 int32_t InterfaceSetIffUp(const std::string &ifaceName) override
232 {
233 return 0;
234 }
235
NetworkAddInterface(int32_t netId,const std::string & iface)236 int32_t NetworkAddInterface(int32_t netId, const std::string &iface) override
237 {
238 return 0;
239 }
240
NetworkRemoveInterface(int32_t netId,const std::string & iface)241 int32_t NetworkRemoveInterface(int32_t netId, const std::string &iface) override
242 {
243 return 0;
244 }
245
NetworkDestroy(int32_t netId)246 int32_t NetworkDestroy(int32_t netId) override
247 {
248 return 0;
249 }
250
GetFwmarkForNetwork(int32_t netId,MarkMaskParcel & markMaskParcel)251 int32_t GetFwmarkForNetwork(int32_t netId, MarkMaskParcel &markMaskParcel) override
252 {
253 return 0;
254 }
255
SetInterfaceConfig(const InterfaceConfigurationParcel & cfg)256 int32_t SetInterfaceConfig(const InterfaceConfigurationParcel &cfg) override
257 {
258 return 0;
259 }
260
GetInterfaceConfig(InterfaceConfigurationParcel & cfg)261 int32_t GetInterfaceConfig(InterfaceConfigurationParcel &cfg) override
262 {
263 return 0;
264 }
265
InterfaceGetList(std::vector<std::string> & ifaces)266 int32_t InterfaceGetList(std::vector<std::string> &ifaces) override
267 {
268 return 0;
269 }
270
StartDhcpClient(const std::string & iface,bool bIpv6)271 int32_t StartDhcpClient(const std::string &iface, bool bIpv6) override
272 {
273 return 0;
274 }
275
StopDhcpClient(const std::string & iface,bool bIpv6)276 int32_t StopDhcpClient(const std::string &iface, bool bIpv6) override
277 {
278 return 0;
279 }
280
StartDhcpService(const std::string & iface,const std::string & ipv4addr)281 int32_t StartDhcpService(const std::string &iface, const std::string &ipv4addr) override
282 {
283 return 0;
284 }
285
StopDhcpService(const std::string & iface)286 int32_t StopDhcpService(const std::string &iface) override
287 {
288 return 0;
289 }
290
IpEnableForwarding(const std::string & requestor)291 int32_t IpEnableForwarding(const std::string &requestor) override
292 {
293 return 0;
294 }
295
IpDisableForwarding(const std::string & requestor)296 int32_t IpDisableForwarding(const std::string &requestor) override
297 {
298 return 0;
299 }
300
EnableNat(const std::string & downstreamIface,const std::string & upstreamIface)301 int32_t EnableNat(const std::string &downstreamIface, const std::string &upstreamIface) override
302 {
303 return 0;
304 }
305
DisableNat(const std::string & downstreamIface,const std::string & upstreamIface)306 int32_t DisableNat(const std::string &downstreamIface, const std::string &upstreamIface) override
307 {
308 return 0;
309 }
310
IpfwdAddInterfaceForward(const std::string & fromIface,const std::string & toIface)311 int32_t IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface) override
312 {
313 return 0;
314 }
315
IpfwdRemoveInterfaceForward(const std::string & fromIface,const std::string & toIface)316 int32_t IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface) override
317 {
318 return 0;
319 }
320
BandwidthAddAllowedList(uint32_t uid)321 int32_t BandwidthAddAllowedList(uint32_t uid) override
322 {
323 return 0;
324 }
325
BandwidthRemoveAllowedList(uint32_t uid)326 int32_t BandwidthRemoveAllowedList(uint32_t uid) override
327 {
328 return 0;
329 }
330
BandwidthEnableDataSaver(bool enable)331 int32_t BandwidthEnableDataSaver(bool enable) override
332 {
333 return 0;
334 }
335
BandwidthSetIfaceQuota(const std::string & ifName,int64_t bytes)336 int32_t BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes) override
337 {
338 return 0;
339 }
340
BandwidthAddDeniedList(uint32_t uid)341 int32_t BandwidthAddDeniedList(uint32_t uid) override
342 {
343 return 0;
344 }
345
BandwidthRemoveDeniedList(uint32_t uid)346 int32_t BandwidthRemoveDeniedList(uint32_t uid) override
347 {
348 return 0;
349 }
350
BandwidthRemoveIfaceQuota(const std::string & ifName)351 int32_t BandwidthRemoveIfaceQuota(const std::string &ifName) override
352 {
353 return 0;
354 }
355
FirewallSetUidsAllowedListChain(uint32_t chain,const std::vector<uint32_t> & uids)356 int32_t FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids) override
357 {
358 return 0;
359 }
360
FirewallSetUidsDeniedListChain(uint32_t chain,const std::vector<uint32_t> & uids)361 int32_t FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids) override
362 {
363 return 0;
364 }
365
FirewallEnableChain(uint32_t chain,bool enable)366 int32_t FirewallEnableChain(uint32_t chain, bool enable) override
367 {
368 return 0;
369 }
370
FirewallSetUidRule(uint32_t chain,const std::vector<uint32_t> & uids,uint32_t firewallRule)371 int32_t FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids, uint32_t firewallRule) override
372 {
373 return 0;
374 }
375
ShareDnsSet(uint16_t netId)376 int32_t ShareDnsSet(uint16_t netId) override
377 {
378 return 0;
379 }
380
StartDnsProxyListen()381 int32_t StartDnsProxyListen() override
382 {
383 return 0;
384 }
385
StopDnsProxyListen()386 int32_t StopDnsProxyListen() override
387 {
388 return 0;
389 }
390
GetNetworkSharingTraffic(const std::string & downIface,const std::string & upIface,NetworkSharingTraffic & traffic)391 int32_t GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface,
392 NetworkSharingTraffic &traffic) override
393 {
394 return 0;
395 }
396
GetTotalStats(uint64_t & stats,uint32_t type)397 int32_t GetTotalStats(uint64_t &stats, uint32_t type) override
398 {
399 return 0;
400 }
401
GetUidStats(uint64_t & stats,uint32_t type,uint32_t uid)402 int32_t GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid) override
403 {
404 return 0;
405 }
406
GetIfaceStats(uint64_t & stats,uint32_t type,const std::string & interfaceName)407 int32_t GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName) override
408 {
409 return 0;
410 }
411
GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> & stats)412 int32_t GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats) override
413 {
414 return 0;
415 }
416
SetIptablesCommandForRes(const std::string & cmd,std::string & respond)417 int32_t SetIptablesCommandForRes(const std::string &cmd, std::string &respond) override
418 {
419 return 0;
420 }
421 };
422
423 class NetsysNativeServiceStubTest : public testing::Test {
424 public:
425 static void SetUpTestCase();
426 static void TearDownTestCase();
427 void SetUp();
428 void TearDown();
429
430 static inline std::shared_ptr<NetsysNativeServiceStub> notifyStub_ = nullptr;
431 };
432
SetUpTestCase()433 void NetsysNativeServiceStubTest::SetUpTestCase()
434 {
435 notifyStub_ = std::make_shared<TestNetsysNativeServiceStub>();
436 }
437
TearDownTestCase()438 void NetsysNativeServiceStubTest::TearDownTestCase() {}
439
SetUp()440 void NetsysNativeServiceStubTest::SetUp() {}
441
TearDown()442 void NetsysNativeServiceStubTest::TearDown() {}
443
444 HWTEST_F(NetsysNativeServiceStubTest, CmdSetResolverConfig001, TestSize.Level1)
445 {
446 uint16_t netId = 1001;
447 uint16_t baseTimeoutMsec = 0;
448 uint8_t retryCount = 0;
449 int32_t vServerSize = 2;
450 std::string strServer = "TestServer";
451
452 int32_t vDomainSize = 1;
453 std::string strDomain = "TestDomain";
454
455 MessageParcel data;
456 EXPECT_TRUE(data.WriteUint16(netId));
457 EXPECT_TRUE(data.WriteUint16(baseTimeoutMsec));
458 EXPECT_TRUE(data.WriteUint16(retryCount));
459 EXPECT_TRUE(data.WriteUint32(vServerSize));
460 EXPECT_TRUE(data.WriteString(strServer));
461 EXPECT_TRUE(data.WriteUint32(vDomainSize));
462 EXPECT_TRUE(data.WriteString(strDomain));
463 MessageParcel reply;
464 int32_t ret = notifyStub_->CmdSetResolverConfig(data, reply);
465 EXPECT_EQ(ret, ERR_FLATTEN_OBJECT);
466 }
467
468 HWTEST_F(NetsysNativeServiceStubTest, CmdSetResolverConfig002, TestSize.Level1)
469 {
470 uint16_t netId = 1001;
471 uint16_t baseTimeoutMsec = 0;
472 uint8_t retryCount = 0;
473 int32_t vServerSize = 0;
474 int32_t vDomainSize = 0;
475 MessageParcel data;
476 EXPECT_TRUE(data.WriteUint16(netId));
477 EXPECT_TRUE(data.WriteUint16(baseTimeoutMsec));
478 EXPECT_TRUE(data.WriteUint8(retryCount));
479 EXPECT_TRUE(data.WriteUint32(vServerSize));
480 EXPECT_TRUE(data.WriteUint32(vDomainSize));
481 MessageParcel reply;
482 int32_t ret = notifyStub_->CmdSetResolverConfig(data, reply);
483 DTEST_LOG << "CmdSetResolverConfig002" << ret << std::endl;
484 EXPECT_EQ(ret, ERR_NONE);
485 }
486
487 HWTEST_F(NetsysNativeServiceStubTest, CmdSetResolverConfig003, TestSize.Level1)
488 {
489 uint16_t netId = 1001;
490 uint16_t baseTimeoutMsec = 0;
491 uint8_t retryCount = 0;
492 int32_t vServerSize = 2;
493 std::string server = "testserver";
494 int32_t vDomainSize = 2;
495 std::string domain = "testdomain";
496 MessageParcel data;
497 EXPECT_TRUE(data.WriteUint16(netId));
498 EXPECT_TRUE(data.WriteUint16(baseTimeoutMsec));
499 EXPECT_TRUE(data.WriteUint8(retryCount));
500 EXPECT_TRUE(data.WriteUint32(vServerSize));
501 for (int32_t i = 0; i < vServerSize; i++) {
502 EXPECT_TRUE(data.WriteString(server));
503 }
504
505 EXPECT_TRUE(data.WriteUint32(vDomainSize));
506 for (int32_t i = 0; i < vDomainSize; i++) {
507 EXPECT_TRUE(data.WriteString(domain));
508 }
509 MessageParcel reply;
510 int32_t ret = notifyStub_->CmdSetResolverConfig(data, reply);
511 DTEST_LOG << "CmdSetResolverConfig003" << ret << std::endl;
512 EXPECT_EQ(ret, ERR_NONE);
513 }
514
IsDataParemerVaild(MessageParcel & data)515 bool IsDataParemerVaild(MessageParcel &data)
516 {
517 uint16_t netId = 1001;
518 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
519 return false;
520 }
521 if (!data.WriteUint16(netId)) {
522 return false;
523 }
524 return true;
525 }
526
527 HWTEST_F(NetsysNativeServiceStubTest, CmdGetResolverConfig001, TestSize.Level1)
528 {
529 MessageParcel data;
530 MessageParcel reply;
531 if (!IsDataParemerVaild(data)) {
532 return;
533 }
534 int32_t ret = notifyStub_->CmdGetResolverConfig(data, reply);
535 EXPECT_EQ(ret, ERR_NONE);
536 }
537
538 HWTEST_F(NetsysNativeServiceStubTest, CmdCreateNetworkCache001, TestSize.Level1)
539 {
540 MessageParcel data;
541 if (!IsDataParemerVaild(data)) {
542 return;
543 }
544 MessageParcel reply;
545 int32_t ret = notifyStub_->CmdCreateNetworkCache(data, reply);
546 EXPECT_EQ(ret, ERR_NONE);
547 }
548
549 HWTEST_F(NetsysNativeServiceStubTest, CmdDestroyNetworkCache001, TestSize.Level1)
550 {
551 MessageParcel data;
552 if (!IsDataParemerVaild(data)) {
553 return;
554 }
555 MessageParcel reply;
556 int32_t ret = notifyStub_->CmdDestroyNetworkCache(data, reply);
557 EXPECT_EQ(ret, ERR_NONE);
558 }
559
560 HWTEST_F(NetsysNativeServiceStubTest, CmdGetAddrInfo001, TestSize.Level1)
561 {
562 std::string hostName = "TestHostName";
563 std::string serverName = "TestServerName";
564
565 struct AddrInfo addrInfo;
566 addrInfo.aiFlags = 0;
567 addrInfo.aiFamily = AF_INET;
568
569 uint16_t netId = 1001;
570
571 MessageParcel data;
572 EXPECT_TRUE(data.WriteString(hostName));
573 EXPECT_TRUE(data.WriteString(serverName));
574 EXPECT_TRUE(data.WriteRawData(&addrInfo, sizeof(AddrInfo)));
575 EXPECT_TRUE(data.WriteUint16(netId));
576 MessageParcel reply;
577 int32_t ret = notifyStub_->CmdGetAddrInfo(data, reply);
578 EXPECT_EQ(ret, ERR_NONE);
579 }
580
581 HWTEST_F(NetsysNativeServiceStubTest, CmdGetAddrInfo002, TestSize.Level1)
582 {
583 std::string hostName = "TestHostName";
584 std::string serverName = "TestServerName";
585
586 struct AddrInfo addrInfo;
587 addrInfo.aiFlags = 0;
588 addrInfo.aiFamily = 9999;
589 uint16_t netId = 1001;
590
591 MessageParcel data;
592 if (!data.WriteString(hostName)) {
593 return;
594 }
595 if (!data.WriteString(serverName)) {
596 return;
597 }
598 if (!data.WriteRawData(&addrInfo, sizeof(AddrInfo))) {
599 return;
600 }
601 if (!data.WriteUint16(netId)) {
602 return;
603 }
604 MessageParcel reply;
605 int32_t ret = notifyStub_->CmdGetAddrInfo(data, reply);
606 EXPECT_EQ(ret, ERR_NONE);
607 }
608
609 HWTEST_F(NetsysNativeServiceStubTest, CmdSetInterfaceMtu001, TestSize.Level1)
610 {
611 std::string ifName = "ifName";
612 int32_t mtu = 0;
613
614 MessageParcel data;
615 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
616 return;
617 }
618 if (!data.WriteString(ifName)) {
619 return;
620 }
621 if (!data.WriteUint32(mtu)) {
622 return;
623 }
624
625 MessageParcel reply;
626 int32_t ret = notifyStub_->CmdSetInterfaceMtu(data, reply);
627 EXPECT_EQ(ret, ERR_NONE);
628 }
629
630 HWTEST_F(NetsysNativeServiceStubTest, CmdGetInterfaceMtu001, TestSize.Level1)
631 {
632 std::string ifName = "ifName";
633
634 MessageParcel data;
635 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
636 return;
637 }
638 if (!data.WriteString(ifName)) {
639 return;
640 }
641
642 MessageParcel reply;
643 int32_t ret = notifyStub_->CmdGetInterfaceMtu(data, reply);
644 EXPECT_EQ(ret, ERR_NONE);
645 }
646
647 HWTEST_F(NetsysNativeServiceStubTest, CmdRegisterNotifyCallback001, TestSize.Level1)
648 {
649 std::string ifName = "ifName";
650 sptr<INotifyCallback> callback = new (std::nothrow) TestNotifyCallback();
651 MessageParcel data;
652 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
653 return;
654 }
655 if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
656 return;
657 }
658
659 MessageParcel reply;
660 int32_t ret = notifyStub_->CmdRegisterNotifyCallback(data, reply);
661 EXPECT_EQ(ret, -1);
662 MessageParcel data2;
663 EXPECT_TRUE(data2.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor()));
664 EXPECT_TRUE(data2.WriteRemoteObject(callback->AsObject().GetRefPtr()));
665 ret = notifyStub_->CmdUnRegisterNotifyCallback(data2, reply);
666 EXPECT_EQ(ret, -1);
667 }
668
669 HWTEST_F(NetsysNativeServiceStubTest, CmdRegisterNotifyCallback002, TestSize.Level1)
670 {
671 std::string ifName = "ifName";
672 sptr<INotifyCallback> callback = new (std::nothrow) TestNotifyCallback();
673 MessageParcel data;
674 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject().GetRefPtr()));
675
676 MessageParcel reply;
677 int32_t ret = notifyStub_->CmdRegisterNotifyCallback(data, reply);
678 EXPECT_EQ(ret, ERR_NONE);
679 MessageParcel data2;
680 EXPECT_TRUE(data2.WriteRemoteObject(callback->AsObject().GetRefPtr()));
681 ret = notifyStub_->CmdUnRegisterNotifyCallback(data2, reply);
682 EXPECT_EQ(ret, ERR_NONE);
683 }
684
685 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkRouteParcel001, TestSize.Level1)
686 {
687 uint16_t netId = 1001;
688 std::string ifName = "ifName";
689 std::string destination = "destination";
690 std::string nextHop = "nextHop";
691
692 MessageParcel data;
693 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
694 return;
695 }
696 if (!data.WriteUint16(netId)) {
697 return;
698 }
699 if (!data.WriteString(ifName)) {
700 return;
701 }
702 if (!data.WriteString(destination)) {
703 return;
704 }
705 if (!data.WriteString(nextHop)) {
706 return;
707 }
708
709 MessageParcel reply;
710 int32_t ret = notifyStub_->CmdNetworkAddRouteParcel(data, reply);
711 EXPECT_EQ(ret, ERR_NONE);
712
713 ret = notifyStub_->CmdNetworkRemoveRouteParcel(data, reply);
714 EXPECT_EQ(ret, ERR_NONE);
715 }
716
717 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkDefault001, TestSize.Level1)
718 {
719 uint16_t netId = 1001;
720 MessageParcel data;
721 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
722 return;
723 }
724 if (!data.WriteUint16(netId)) {
725 return;
726 }
727
728 MessageParcel reply;
729 int32_t ret = notifyStub_->CmdNetworkSetDefault(data, reply);
730 EXPECT_EQ(ret, ERR_NONE);
731
732 ret = notifyStub_->CmdNetworkGetDefault(data, reply);
733 EXPECT_EQ(ret, ERR_NONE);
734
735 ret = notifyStub_->CmdNetworkClearDefault(data, reply);
736 EXPECT_EQ(ret, ERR_NONE);
737 }
738
739 HWTEST_F(NetsysNativeServiceStubTest, CmdProcSysNet001, TestSize.Level1)
740 {
741 int32_t family = 0;
742 int32_t which = 0;
743 std::string ifName = "TestIfName";
744 std::string parameter = "TestParameter";
745
746 MessageParcel data;
747 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
748 return;
749 }
750 if (!data.WriteUint32(family)) {
751 return;
752 }
753 if (!data.WriteUint32(which)) {
754 return;
755 }
756 if (!data.WriteString(ifName)) {
757 return;
758 }
759 if (!data.WriteString(parameter)) {
760 return;
761 }
762
763 MessageParcel reply;
764 int32_t ret = notifyStub_->CmdGetProcSysNet(data, reply);
765 EXPECT_EQ(ret, ERR_NONE);
766
767 std::string value = "TestValue";
768 if (!data.WriteString(value)) {
769 return;
770 }
771
772 ret = notifyStub_->CmdSetProcSysNet(data, reply);
773 EXPECT_EQ(ret, ERR_NONE);
774 }
775
776 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkCreatePhysical001, TestSize.Level1)
777 {
778 int32_t netId = 1001;
779 int32_t permission = 0;
780
781 MessageParcel data;
782 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
783 return;
784 }
785 if (!data.WriteUint32(netId)) {
786 return;
787 }
788 if (!data.WriteUint32(permission)) {
789 return;
790 }
791
792 MessageParcel reply;
793 int32_t ret = notifyStub_->CmdNetworkCreatePhysical(data, reply);
794 EXPECT_EQ(ret, ERR_NONE);
795 }
796
797 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceAddress001, TestSize.Level1)
798 {
799 std::string interfaceName = "testInterfaceName";
800 std::string ipAddr = "testIpAddr";
801 int32_t prefixLength = 10;
802
803 MessageParcel data;
804 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
805 return;
806 }
807 if (!data.WriteString(interfaceName)) {
808 return;
809 }
810 if (!data.WriteString(ipAddr)) {
811 return;
812 }
813 if (!data.WriteUint32(prefixLength)) {
814 return;
815 }
816
817 MessageParcel reply;
818 int32_t ret = notifyStub_->CmdAddInterfaceAddress(data, reply);
819 EXPECT_EQ(ret, ERR_NONE);
820
821 ret = notifyStub_->CmdDelInterfaceAddress(data, reply);
822 EXPECT_EQ(ret, ERR_NONE);
823 }
824
825 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceSetIpAddress001, TestSize.Level1)
826 {
827 std::string interfaceName = "testInterfaceName";
828 std::string ipAddress = "testIpAddr";
829
830 MessageParcel data;
831 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
832 return;
833 }
834 if (!data.WriteString(interfaceName)) {
835 return;
836 }
837 if (!data.WriteString(ipAddress)) {
838 return;
839 }
840
841 MessageParcel reply;
842 int32_t ret = notifyStub_->CmdInterfaceSetIpAddress(data, reply);
843 EXPECT_EQ(ret, ERR_NONE);
844 }
845
846 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceSetIffUp001, TestSize.Level1)
847 {
848 std::string interfaceName = "testInterfaceName";
849
850 MessageParcel data;
851 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
852 return;
853 }
854 if (!data.WriteString(interfaceName)) {
855 return;
856 }
857
858 MessageParcel reply;
859 int32_t ret = notifyStub_->CmdInterfaceSetIffUp(data, reply);
860 EXPECT_EQ(ret, ERR_NONE);
861 }
862
863 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkInterface001, TestSize.Level1)
864 {
865 int32_t netId = 1001;
866 std::string interfaceName = "testInterfaceName";
867
868 MessageParcel data;
869 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
870 return;
871 }
872 if (!data.WriteString(interfaceName)) {
873 return;
874 }
875 if (!data.WriteUint32(netId)) {
876 return;
877 }
878
879 MessageParcel reply;
880 int32_t ret = notifyStub_->CmdNetworkAddInterface(data, reply);
881 EXPECT_EQ(ret, ERR_NONE);
882
883 notifyStub_->CmdNetworkRemoveInterface(data, reply);
884 EXPECT_EQ(ret, ERR_NONE);
885 }
886
887 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkDestroy001, TestSize.Level1)
888 {
889 int32_t netId = 1001;
890
891 MessageParcel data;
892 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
893 return;
894 }
895 if (!data.WriteUint32(netId)) {
896 return;
897 }
898
899 MessageParcel reply;
900 int32_t ret = notifyStub_->CmdNetworkDestroy(data, reply);
901 EXPECT_EQ(ret, ERR_NONE);
902 }
903
904 HWTEST_F(NetsysNativeServiceStubTest, CmdGetFwmarkForNetwork001, TestSize.Level1)
905 {
906 int32_t netId = 1001;
907 int32_t mark = 0;
908 int32_t mask = 0;
909 MessageParcel data;
910 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
911 return;
912 }
913 if (!data.WriteUint32(netId)) {
914 return;
915 }
916 if (!data.WriteUint32(mark)) {
917 return;
918 }
919 if (!data.WriteUint32(mask)) {
920 return;
921 }
922
923 MessageParcel reply;
924 int32_t ret = notifyStub_->CmdGetFwmarkForNetwork(data, reply);
925 EXPECT_EQ(ret, ERR_NONE);
926 }
927
928 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceConfig001, TestSize.Level1)
929 {
930 std::string ifName = "testIfName";
931 std::string hwAddr = "testHwAddr";
932 std::string ipv4Addr = "testIpv4Addr";
933 uint32_t prefixLength = 0;
934 uint32_t vServerSize = 1;
935 std::string flag = "testFlag";
936
937 MessageParcel data;
938 EXPECT_TRUE(data.WriteString(ifName));
939 EXPECT_TRUE(data.WriteString(hwAddr));
940 EXPECT_TRUE(data.WriteString(ipv4Addr));
941 EXPECT_TRUE(data.WriteUint32(prefixLength));
942 EXPECT_TRUE(data.WriteUint32(vServerSize));
943 EXPECT_TRUE(data.WriteString(flag));
944
945 MessageParcel reply;
946 int32_t ret = notifyStub_->CmdSetInterfaceConfig(data, reply);
947 EXPECT_EQ(ret, ERR_NONE);
948
949 ret = notifyStub_->CmdGetInterfaceConfig(data, reply);
950 EXPECT_EQ(ret, ERR_NONE);
951 }
952
953 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceGetList001, TestSize.Level1)
954 {
955 MessageParcel data;
956 MessageParcel reply;
957 int32_t ret = notifyStub_->CmdInterfaceGetList(data, reply);
958 EXPECT_EQ(ret, ERR_NONE);
959 }
960
961 HWTEST_F(NetsysNativeServiceStubTest, CmdDhcpClient001, TestSize.Level1)
962 {
963 std::string iface = "testIface";
964 bool bIpv6 = true;
965 MessageParcel data;
966 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
967 return;
968 }
969 if (!data.WriteString(iface)) {
970 return;
971 }
972 if (!data.WriteBool(bIpv6)) {
973 return;
974 }
975
976 MessageParcel reply;
977 int32_t ret = notifyStub_->CmdStartDhcpClient(data, reply);
978 EXPECT_EQ(ret, ERR_NONE);
979
980 ret = notifyStub_->CmdStopDhcpClient(data, reply);
981 EXPECT_EQ(ret, ERR_NONE);
982 }
983
984 HWTEST_F(NetsysNativeServiceStubTest, CmdDhcpService001, TestSize.Level1)
985 {
986 std::string iface = "testIface";
987 std::string ipv4addr = "testIpv4addr";
988
989 MessageParcel data;
990 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
991 return;
992 }
993 if (!data.WriteString(iface)) {
994 return;
995 }
996 if (!data.WriteString(ipv4addr)) {
997 return;
998 }
999
1000 MessageParcel reply;
1001 int32_t ret = notifyStub_->CmdStartDhcpService(data, reply);
1002 EXPECT_EQ(ret, ERR_NONE);
1003
1004 ret = notifyStub_->CmdStopDhcpService(data, reply);
1005 EXPECT_EQ(ret, ERR_NONE);
1006 }
1007
1008 HWTEST_F(NetsysNativeServiceStubTest, CmdIpForwarding001, TestSize.Level1)
1009 {
1010 std::string requester = "testRequester";
1011
1012 MessageParcel data;
1013 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1014 return;
1015 }
1016 if (!data.WriteString(requester)) {
1017 return;
1018 }
1019
1020 MessageParcel reply;
1021 int32_t ret = notifyStub_->CmdIpEnableForwarding(data, reply);
1022 EXPECT_EQ(ret, ERR_NONE);
1023
1024 ret = notifyStub_->CmdIpDisableForwarding(data, reply);
1025 EXPECT_EQ(ret, ERR_NONE);
1026 }
1027
1028 HWTEST_F(NetsysNativeServiceStubTest, CmdNat001, TestSize.Level1)
1029 {
1030 std::string downstreamIface = "testDownstreamIface";
1031 std::string upstreamIface = "testUpstreamIface";
1032
1033 MessageParcel data;
1034 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1035 return;
1036 }
1037 if (!data.WriteString(downstreamIface)) {
1038 return;
1039 }
1040 if (!data.WriteString(upstreamIface)) {
1041 return;
1042 }
1043
1044 MessageParcel reply;
1045 int32_t ret = notifyStub_->CmdEnableNat(data, reply);
1046 EXPECT_EQ(ret, ERR_NONE);
1047
1048 ret = notifyStub_->CmdDisableNat(data, reply);
1049 EXPECT_EQ(ret, ERR_NONE);
1050 }
1051
1052 HWTEST_F(NetsysNativeServiceStubTest, CmdIpfwdInterfaceForward001, TestSize.Level1)
1053 {
1054 std::string fromIface = "testFromIface";
1055 std::string toIface = "testToIface";
1056
1057 MessageParcel data;
1058 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1059 return;
1060 }
1061 if (!data.WriteString(fromIface)) {
1062 return;
1063 }
1064 if (!data.WriteString(toIface)) {
1065 return;
1066 }
1067
1068 MessageParcel reply;
1069 int32_t ret = notifyStub_->CmdIpfwdAddInterfaceForward(data, reply);
1070 EXPECT_EQ(ret, ERR_NONE);
1071
1072 ret = notifyStub_->CmdIpfwdRemoveInterfaceForward(data, reply);
1073 EXPECT_EQ(ret, ERR_NONE);
1074 }
1075
1076 HWTEST_F(NetsysNativeServiceStubTest, CmdBandwidthEnableDataSaver001, TestSize.Level1)
1077 {
1078 bool enable = true;
1079
1080 MessageParcel data;
1081 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1082 return;
1083 }
1084 if (!data.WriteBool(enable)) {
1085 return;
1086 }
1087
1088 MessageParcel reply;
1089 int32_t ret = notifyStub_->CmdBandwidthEnableDataSaver(data, reply);
1090 EXPECT_EQ(ret, ERR_NONE);
1091 }
1092
1093 HWTEST_F(NetsysNativeServiceStubTest, CmdBandwidthIfaceQuota001, TestSize.Level1)
1094 {
1095 std::string ifName = "testIfName";
1096
1097 MessageParcel data;
1098 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1099 return;
1100 }
1101 if (!data.WriteString(ifName)) {
1102 return;
1103 }
1104
1105 MessageParcel reply;
1106 int32_t ret = notifyStub_->CmdBandwidthSetIfaceQuota(data, reply);
1107 EXPECT_EQ(ret, ERR_NONE);
1108
1109 ret = notifyStub_->CmdBandwidthRemoveIfaceQuota(data, reply);
1110 EXPECT_EQ(ret, ERR_NONE);
1111 }
1112
1113 HWTEST_F(NetsysNativeServiceStubTest, CmdBandwidthList001, TestSize.Level1)
1114 {
1115 uint32_t uid = 1001;
1116
1117 MessageParcel data;
1118 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1119 return;
1120 }
1121 if (!data.WriteUint32(uid)) {
1122 return;
1123 }
1124
1125 MessageParcel reply;
1126 int32_t ret = notifyStub_->CmdBandwidthAddDeniedList(data, reply);
1127 EXPECT_EQ(ret, ERR_NONE);
1128
1129 ret = notifyStub_->CmdBandwidthRemoveDeniedList(data, reply);
1130 EXPECT_EQ(ret, ERR_NONE);
1131
1132 ret = notifyStub_->CmdBandwidthAddAllowedList(data, reply);
1133 EXPECT_EQ(ret, ERR_NONE);
1134
1135 ret = notifyStub_->CmdBandwidthRemoveAllowedList(data, reply);
1136 EXPECT_EQ(ret, ERR_NONE);
1137 }
1138
1139 HWTEST_F(NetsysNativeServiceStubTest, CmdFirewallSetUidsListChain001, TestSize.Level1)
1140 {
1141 uint32_t chain = 0;
1142 uint32_t uidSize = 1;
1143 uint32_t uid = 1001;
1144
1145 MessageParcel data;
1146 if (!data.WriteUint32(chain)) {
1147 return;
1148 }
1149 if (!data.WriteUint32(uidSize)) {
1150 return;
1151 }
1152 if (!data.WriteUint32(uid)) {
1153 return;
1154 }
1155
1156 MessageParcel reply;
1157 int32_t ret = notifyStub_->CmdFirewallSetUidsAllowedListChain(data, reply);
1158 EXPECT_EQ(ret, ERR_NONE);
1159
1160 ret = notifyStub_->CmdFirewallSetUidsDeniedListChain(data, reply);
1161 EXPECT_EQ(ret, ERR_NONE);
1162 }
1163
1164 HWTEST_F(NetsysNativeServiceStubTest, CmdFirewallEnableChain001, TestSize.Level1)
1165 {
1166 uint32_t chain = 0;
1167 bool enable = true;
1168
1169 MessageParcel data;
1170 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1171 return;
1172 }
1173 if (!data.WriteUint32(chain)) {
1174 return;
1175 }
1176 if (!data.WriteBool(enable)) {
1177 return;
1178 }
1179
1180 MessageParcel reply;
1181 int32_t ret = notifyStub_->CmdFirewallEnableChain(data, reply);
1182 EXPECT_EQ(ret, ERR_NONE);
1183 }
1184
1185 HWTEST_F(NetsysNativeServiceStubTest, CmdFirewallSetUidRule001, TestSize.Level1)
1186 {
1187 uint32_t chain = 0;
1188 uint32_t uid = 1001;
1189 uint32_t firewallRule = 1;
1190
1191 MessageParcel data;
1192 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1193 return;
1194 }
1195 if (!data.WriteUint32(chain)) {
1196 return;
1197 }
1198 if (!data.WriteUint32(uid)) {
1199 return;
1200 }
1201 if (!data.WriteUint32(firewallRule)) {
1202 return;
1203 }
1204
1205 MessageParcel reply;
1206 int32_t ret = notifyStub_->CmdFirewallSetUidRule(data, reply);
1207 EXPECT_EQ(ret, ERR_NONE);
1208 }
1209
1210 HWTEST_F(NetsysNativeServiceStubTest, CmdShareDnsSet001, TestSize.Level1)
1211 {
1212 uint16_t netId = 0;
1213
1214 MessageParcel data;
1215 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1216 return;
1217 }
1218 if (!data.WriteUint16(netId)) {
1219 return;
1220 }
1221
1222 MessageParcel reply;
1223 int32_t ret = notifyStub_->CmdShareDnsSet(data, reply);
1224 EXPECT_EQ(ret, ERR_NONE);
1225 }
1226
1227 HWTEST_F(NetsysNativeServiceStubTest, CmdDnsProxyListen001, TestSize.Level1)
1228 {
1229 MessageParcel data;
1230 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1231 return;
1232 }
1233
1234 MessageParcel reply;
1235 int32_t ret = notifyStub_->CmdStartDnsProxyListen(data, reply);
1236 EXPECT_EQ(ret, ERR_NONE);
1237
1238 ret = notifyStub_->CmdStopDnsProxyListen(data, reply);
1239 EXPECT_EQ(ret, ERR_NONE);
1240 }
1241
1242 HWTEST_F(NetsysNativeServiceStubTest, CmdGetNetworkSharingTraffic001, TestSize.Level1)
1243 {
1244 std::string downIface = "testDownIface";
1245 std::string upIface = "testUpIface ";
1246
1247 MessageParcel data;
1248 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1249 return;
1250 }
1251 if (!data.WriteString(downIface)) {
1252 return;
1253 }
1254 if (!data.WriteString(upIface)) {
1255 return;
1256 }
1257
1258 MessageParcel reply;
1259 int32_t ret = notifyStub_->CmdGetNetworkSharingTraffic(data, reply);
1260 EXPECT_EQ(ret, ERR_NONE);
1261 }
1262
1263 HWTEST_F(NetsysNativeServiceStubTest, CmdGetTotalStats001, TestSize.Level1)
1264 {
1265 uint32_t type = 0;
1266 MessageParcel data;
1267 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1268 return;
1269 }
1270 if (!data.WriteInt32(type)) {
1271 return;
1272 }
1273
1274 MessageParcel reply;
1275 int32_t ret = notifyStub_->CmdGetTotalStats(data, reply);
1276 EXPECT_EQ(ret, ERR_NONE);
1277 }
1278
1279 HWTEST_F(NetsysNativeServiceStubTest, CmdGetUidStats001, TestSize.Level1)
1280 {
1281 uint32_t type = 0;
1282 uint32_t uId = 2020;
1283 MessageParcel data;
1284 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1285 return;
1286 }
1287 if (!data.WriteInt32(type)) {
1288 return;
1289 }
1290 if (!data.WriteInt32(uId)) {
1291 return;
1292 }
1293
1294 MessageParcel reply;
1295 int32_t ret = notifyStub_->CmdGetUidStats(data, reply);
1296 EXPECT_EQ(ret, ERR_NONE);
1297 }
1298
1299 HWTEST_F(NetsysNativeServiceStubTest, CmdGetIfaceStats001, TestSize.Level1)
1300 {
1301 uint32_t type = 0;
1302 std::string Iface = "wlan0";
1303
1304 MessageParcel data;
1305 if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1306 return;
1307 }
1308 if (!data.WriteInt32(type)) {
1309 return;
1310 }
1311 if (!data.WriteString(Iface)) {
1312 return;
1313 }
1314
1315 MessageParcel reply;
1316 int32_t ret = notifyStub_->CmdGetIfaceStats(data, reply);
1317 EXPECT_EQ(ret, ERR_NONE);
1318 }
1319
1320 HWTEST_F(NetsysNativeServiceStubTest, CmdGetAllStatsInfo001, TestSize.Level1)
1321 {
1322 MessageParcel data;
1323 MessageParcel reply;
1324 int32_t ret = notifyStub_->CmdGetAllStatsInfo(data, reply);
1325 EXPECT_EQ(ret, ERR_NONE);
1326 }
1327
1328 HWTEST_F(NetsysNativeServiceStubTest, NetsysFreeAddrinfoTest001, TestSize.Level1)
1329 {
1330 addrinfo *ai = nullptr;
1331 int32_t ret = notifyStub_->NetsysFreeAddrinfo(ai);
1332 EXPECT_EQ(ret, ERR_NONE);
1333 }
1334
1335 HWTEST_F(NetsysNativeServiceStubTest, CmdSetInternetPermissionTest001, TestSize.Level1)
1336 {
1337 MessageParcel data;
1338 MessageParcel reply;
1339 uint32_t uid = 0;
1340 uint8_t allow = 1;
1341 ASSERT_TRUE(data.WriteUint32(uid));
1342 ASSERT_TRUE(data.WriteUint8(allow));
1343 int32_t ret = notifyStub_->CmdSetInternetPermission(data, reply);
1344 EXPECT_EQ(ret, ERR_NONE);
1345 }
1346
1347 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkCreateVirtualTest001, TestSize.Level1)
1348 {
1349 MessageParcel data;
1350 MessageParcel reply;
1351 data.WriteInt32(0);
1352 data.WriteBool(false);
1353 int32_t ret = notifyStub_->CmdNetworkCreateVirtual(data, reply);
1354 EXPECT_EQ(ret, ERR_NONE);
1355 }
1356
1357 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkAddUidsTest001, TestSize.Level1)
1358 {
1359 MessageParcel data;
1360 MessageParcel reply;
1361 data.WriteInt32(0);
1362 data.WriteInt32(0);
1363 int32_t ret = notifyStub_->CmdNetworkAddUids(data, reply);
1364 EXPECT_EQ(ret, ERR_NONE);
1365 }
1366
1367 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkDelUidsTest001, TestSize.Level1)
1368 {
1369 MessageParcel data;
1370 MessageParcel reply;
1371 data.WriteInt32(0);
1372 data.WriteInt32(0);
1373 int32_t ret = notifyStub_->CmdNetworkDelUids(data, reply);
1374 EXPECT_EQ(ret, ERR_NONE);
1375 }
1376
1377 HWTEST_F(NetsysNativeServiceStubTest, CmdSetIptablesCommandForResTest001, TestSize.Level1)
1378 {
1379 MessageParcel data;
1380 MessageParcel reply;
1381 int32_t ret = notifyStub_->CmdSetIptablesCommandForRes(data, reply);
1382 EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
1383 }
1384
1385 HWTEST_F(NetsysNativeServiceStubTest, OnRemoteRequestTest001, TestSize.Level1)
1386 {
1387 uint32_t errcode = 9999;
1388 MessageParcel data;
1389 MessageParcel reply;
1390 MessageOption option;
1391 auto result = notifyStub_->OnRemoteRequest(errcode, data, reply, option);
1392 EXPECT_EQ(result, IPC_STUB_UNKNOW_TRANS_ERR);
1393 uint32_t code = 10;
1394 result = notifyStub_->OnRemoteRequest(code, data, reply, option);
1395 EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
1396 auto descriptor = NetsysNativeServiceStub::GetDescriptor();
1397 data.WriteInterfaceToken(descriptor);
1398 code = 8;
1399 result = notifyStub_->OnRemoteRequest(code, data, reply, option);
1400 EXPECT_EQ(result, ERR_NONE);
1401 }
1402 } // namespace NetsysNative
1403 } // namespace OHOS