• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #ifdef GTEST_API_
19 #define private public
20 #define protected public
21 #endif
22 #include "common_net_diag_callback_test.h"
23 #include "common_notify_callback_test.h"
24 #include "i_netsys_service.h"
25 #include "net_dns_health_callback_stub.h"
26 #include "net_dns_result_callback_stub.h"
27 #include "netnative_log_wrapper.h"
28 #include "netsys_native_service_stub.h"
29 
30 namespace OHOS {
31 namespace NetsysNative {
32 namespace {
33 using namespace testing::ext;
34 #define DTEST_LOG std::cout << __func__ << ":" << __LINE__ << ":"
35 } // namespace
36 static constexpr uint64_t TEST_COOKIE = 1;
37 static constexpr uint64_t TEST_UID = 1;
38 
39 class TestNetDnsResultCallback : public NetDnsResultCallbackStub {
40 public:
41     TestNetDnsResultCallback() = default;
~TestNetDnsResultCallback()42     ~TestNetDnsResultCallback() override{};
43 
OnDnsResultReport(uint32_t size,const std::list<NetDnsResultReport>)44     int32_t OnDnsResultReport(uint32_t size, const std::list<NetDnsResultReport>) override
45     {
46         return 0;
47     }
48 };
49 
50 class TestNetDnsHealthCallback : public NetDnsHealthCallbackStub {
51 public:
52     TestNetDnsHealthCallback() = default;
~TestNetDnsHealthCallback()53     ~TestNetDnsHealthCallback() override{};
54 
OnDnsHealthReport(const NetDnsHealthReport & dnsHealthReport)55     int32_t OnDnsHealthReport(const NetDnsHealthReport &dnsHealthReport) override
56     {
57         return 0;
58     }
59 };
60 
61 class TestNetsysNativeServiceStub : public NetsysNativeServiceStub {
62 public:
63     TestNetsysNativeServiceStub() = default;
~TestNetsysNativeServiceStub()64     ~TestNetsysNativeServiceStub() override{};
65 
SetInternetPermission(uint32_t uid,uint8_t allow,uint8_t isBroker)66     int32_t SetInternetPermission(uint32_t uid, uint8_t allow, uint8_t isBroker) override
67     {
68         return 0;
69     }
70 
SetResolverConfig(uint16_t netId,uint16_t baseTimeoutMsec,uint8_t retryCount,const std::vector<std::string> & servers,const std::vector<std::string> & domains)71     int32_t SetResolverConfig(uint16_t netId, uint16_t baseTimeoutMsec, uint8_t retryCount,
72                               const std::vector<std::string> &servers, const std::vector<std::string> &domains) override
73     {
74         return 0;
75     }
76 
GetResolverConfig(uint16_t netId,std::vector<std::string> & servers,std::vector<std::string> & domains,uint16_t & baseTimeoutMsec,uint8_t & retryCount)77     int32_t GetResolverConfig(uint16_t netId, std::vector<std::string> &servers, std::vector<std::string> &domains,
78                               uint16_t &baseTimeoutMsec, uint8_t &retryCount) override
79     {
80         return 0;
81     }
82 
CreateNetworkCache(uint16_t netId)83     int32_t CreateNetworkCache(uint16_t netId) override
84     {
85         return 0;
86     }
87 
DestroyNetworkCache(uint16_t netId)88     int32_t DestroyNetworkCache(uint16_t netId) override
89     {
90         return 0;
91     }
92 
GetAddrInfo(const std::string & hostName,const std::string & serverName,const AddrInfo & hints,uint16_t netId,std::vector<AddrInfo> & res)93     int32_t GetAddrInfo(const std::string &hostName, const std::string &serverName, const AddrInfo &hints,
94                         uint16_t netId, std::vector<AddrInfo> &res) override
95     {
96         return 0;
97     }
98 
SetInterfaceMtu(const std::string & interfaceName,int mtu)99     int32_t SetInterfaceMtu(const std::string &interfaceName, int mtu) override
100     {
101         return 0;
102     }
103 
SetTcpBufferSizes(const std::string & tcpBufferSizes)104     int32_t SetTcpBufferSizes(const std::string &tcpBufferSizes) override
105     {
106         return 0;
107     }
108 
GetInterfaceMtu(const std::string & interfaceName)109     int32_t GetInterfaceMtu(const std::string &interfaceName) override
110     {
111         return 0;
112     }
113 
RegisterNotifyCallback(sptr<INotifyCallback> & callback)114     int32_t RegisterNotifyCallback(sptr<INotifyCallback> &callback) override
115     {
116         return 0;
117     }
118 
UnRegisterNotifyCallback(sptr<INotifyCallback> & callback)119     int32_t UnRegisterNotifyCallback(sptr<INotifyCallback> &callback) override
120     {
121         return 0;
122     }
123 
NetworkAddRoute(int32_t netId,const std::string & interfaceName,const std::string & destination,const std::string & nextHop)124     int32_t NetworkAddRoute(int32_t netId, const std::string &interfaceName, const std::string &destination,
125                             const std::string &nextHop) override
126     {
127         return 0;
128     }
129 
NetworkRemoveRoute(int32_t netId,const std::string & interfaceName,const std::string & destination,const std::string & nextHop)130     int32_t NetworkRemoveRoute(int32_t netId, const std::string &interfaceName, const std::string &destination,
131                                const std::string &nextHop) override
132     {
133         return 0;
134     }
135 
NetworkAddRouteParcel(int32_t netId,const RouteInfoParcel & routeInfo)136     int32_t NetworkAddRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) override
137     {
138         return 0;
139     }
140 
NetworkRemoveRouteParcel(int32_t netId,const RouteInfoParcel & routeInfo)141     int32_t NetworkRemoveRouteParcel(int32_t netId, const RouteInfoParcel &routeInfo) override
142     {
143         return 0;
144     }
145 
NetworkSetDefault(int32_t netId)146     int32_t NetworkSetDefault(int32_t netId) override
147     {
148         return 0;
149     }
150 
NetworkGetDefault()151     int32_t NetworkGetDefault() override
152     {
153         return 0;
154     }
155 
NetworkClearDefault()156     int32_t NetworkClearDefault() override
157     {
158         return 0;
159     }
160 
GetProcSysNet(int32_t family,int32_t which,const std::string & ifname,const std::string & parameter,std::string & value)161     int32_t GetProcSysNet(int32_t family, int32_t which, const std::string &ifname, const std::string &parameter,
162                           std::string &value) override
163     {
164         return 0;
165     }
166 
SetProcSysNet(int32_t family,int32_t which,const std::string & ifname,const std::string & parameter,std::string & value)167     int32_t SetProcSysNet(int32_t family, int32_t which, const std::string &ifname, const std::string &parameter,
168                           std::string &value) override
169     {
170         return 0;
171     }
172 
NetworkCreatePhysical(int32_t netId,int32_t permission)173     int32_t NetworkCreatePhysical(int32_t netId, int32_t permission) override
174     {
175         return 0;
176     }
177 
NetworkCreateVirtual(int32_t netId,bool hasDns)178     int32_t NetworkCreateVirtual(int32_t netId, bool hasDns) override
179     {
180         return 0;
181     }
182 
NetworkAddUids(int32_t netId,const std::vector<UidRange> & uidRanges)183     int32_t NetworkAddUids(int32_t netId, const std::vector<UidRange> &uidRanges) override
184     {
185         return 0;
186     }
187 
NetworkDelUids(int32_t netId,const std::vector<UidRange> & uidRanges)188     int32_t NetworkDelUids(int32_t netId, const std::vector<UidRange> &uidRanges) override
189     {
190         return 0;
191     }
192 
AddInterfaceAddress(const std::string & interfaceName,const std::string & addrString,int32_t prefixLength)193     int32_t AddInterfaceAddress(const std::string &interfaceName, const std::string &addrString,
194                                 int32_t prefixLength) override
195     {
196         return 0;
197     }
198 
DelInterfaceAddress(const std::string & interfaceName,const std::string & addrString,int32_t prefixLength)199     int32_t DelInterfaceAddress(const std::string &interfaceName, const std::string &addrString,
200                                 int32_t prefixLength) override
201     {
202         return 0;
203     }
204 
DelInterfaceAddress(const std::string & interfaceName,const std::string & addrString,int32_t prefixLength,const std::string & netCapabilities)205     int32_t DelInterfaceAddress(const std::string &interfaceName, const std::string &addrString,
206                                 int32_t prefixLength, const std::string &netCapabilities) override
207     {
208         return 0;
209     }
210 
InterfaceSetIpAddress(const std::string & ifaceName,const std::string & ipAddress)211     int32_t InterfaceSetIpAddress(const std::string &ifaceName, const std::string &ipAddress) override
212     {
213         return 0;
214     }
215 
InterfaceSetIffUp(const std::string & ifaceName)216     int32_t InterfaceSetIffUp(const std::string &ifaceName) override
217     {
218         return 0;
219     }
220 
NetworkAddInterface(int32_t netId,const std::string & iface,NetBearType netBearerType)221     int32_t NetworkAddInterface(int32_t netId, const std::string &iface, NetBearType netBearerType) override
222     {
223         return 0;
224     }
225 
NetworkRemoveInterface(int32_t netId,const std::string & iface)226     int32_t NetworkRemoveInterface(int32_t netId, const std::string &iface) override
227     {
228         return 0;
229     }
230 
NetworkDestroy(int32_t netId)231     int32_t NetworkDestroy(int32_t netId) override
232     {
233         return 0;
234     }
235 
CreateVnic(uint16_t mtu,const std::string & tunAddr,int32_t prefix,const std::set<int32_t> & uids)236     int32_t CreateVnic(uint16_t mtu, const std::string &tunAddr, int32_t prefix,
237                        const std::set<int32_t> &uids) override
238     {
239         return 0;
240     }
241 
DestroyVnic()242     int32_t DestroyVnic() override
243     {
244         return 0;
245     }
246 
GetFwmarkForNetwork(int32_t netId,MarkMaskParcel & markMaskParcel)247     int32_t GetFwmarkForNetwork(int32_t netId, MarkMaskParcel &markMaskParcel) override
248     {
249         return 0;
250     }
251 
SetInterfaceConfig(const InterfaceConfigurationParcel & cfg)252     int32_t SetInterfaceConfig(const InterfaceConfigurationParcel &cfg) override
253     {
254         return 0;
255     }
256 
GetInterfaceConfig(InterfaceConfigurationParcel & cfg)257     int32_t GetInterfaceConfig(InterfaceConfigurationParcel &cfg) override
258     {
259         return 0;
260     }
261 
InterfaceGetList(std::vector<std::string> & ifaces)262     int32_t InterfaceGetList(std::vector<std::string> &ifaces) override
263     {
264         return 0;
265     }
266 
StartDhcpClient(const std::string & iface,bool bIpv6)267     int32_t StartDhcpClient(const std::string &iface, bool bIpv6) override
268     {
269         return 0;
270     }
271 
StopDhcpClient(const std::string & iface,bool bIpv6)272     int32_t StopDhcpClient(const std::string &iface, bool bIpv6) override
273     {
274         return 0;
275     }
276 
StartDhcpService(const std::string & iface,const std::string & ipv4addr)277     int32_t StartDhcpService(const std::string &iface, const std::string &ipv4addr) override
278     {
279         return 0;
280     }
281 
StopDhcpService(const std::string & iface)282     int32_t StopDhcpService(const std::string &iface) override
283     {
284         return 0;
285     }
286 
IpEnableForwarding(const std::string & requestor)287     int32_t IpEnableForwarding(const std::string &requestor) override
288     {
289         return 0;
290     }
291 
IpDisableForwarding(const std::string & requestor)292     int32_t IpDisableForwarding(const std::string &requestor) override
293     {
294         return 0;
295     }
296 
EnableNat(const std::string & downstreamIface,const std::string & upstreamIface)297     int32_t EnableNat(const std::string &downstreamIface, const std::string &upstreamIface) override
298     {
299         return 0;
300     }
301 
DisableNat(const std::string & downstreamIface,const std::string & upstreamIface)302     int32_t DisableNat(const std::string &downstreamIface, const std::string &upstreamIface) override
303     {
304         return 0;
305     }
306 
IpfwdAddInterfaceForward(const std::string & fromIface,const std::string & toIface)307     int32_t IpfwdAddInterfaceForward(const std::string &fromIface, const std::string &toIface) override
308     {
309         return 0;
310     }
311 
IpfwdRemoveInterfaceForward(const std::string & fromIface,const std::string & toIface)312     int32_t IpfwdRemoveInterfaceForward(const std::string &fromIface, const std::string &toIface) override
313     {
314         return 0;
315     }
316 
BandwidthAddAllowedList(uint32_t uid)317     int32_t BandwidthAddAllowedList(uint32_t uid) override
318     {
319         return 0;
320     }
321 
BandwidthRemoveAllowedList(uint32_t uid)322     int32_t BandwidthRemoveAllowedList(uint32_t uid) override
323     {
324         return 0;
325     }
326 
BandwidthEnableDataSaver(bool enable)327     int32_t BandwidthEnableDataSaver(bool enable) override
328     {
329         return 0;
330     }
331 
BandwidthSetIfaceQuota(const std::string & ifName,int64_t bytes)332     int32_t BandwidthSetIfaceQuota(const std::string &ifName, int64_t bytes) override
333     {
334         return 0;
335     }
336 
BandwidthAddDeniedList(uint32_t uid)337     int32_t BandwidthAddDeniedList(uint32_t uid) override
338     {
339         return 0;
340     }
341 
BandwidthRemoveDeniedList(uint32_t uid)342     int32_t BandwidthRemoveDeniedList(uint32_t uid) override
343     {
344         return 0;
345     }
346 
BandwidthRemoveIfaceQuota(const std::string & ifName)347     int32_t BandwidthRemoveIfaceQuota(const std::string &ifName) override
348     {
349         return 0;
350     }
351 
FirewallSetUidsAllowedListChain(uint32_t chain,const std::vector<uint32_t> & uids)352     int32_t FirewallSetUidsAllowedListChain(uint32_t chain, const std::vector<uint32_t> &uids) override
353     {
354         return 0;
355     }
356 
FirewallSetUidsDeniedListChain(uint32_t chain,const std::vector<uint32_t> & uids)357     int32_t FirewallSetUidsDeniedListChain(uint32_t chain, const std::vector<uint32_t> &uids) override
358     {
359         return 0;
360     }
361 
FirewallEnableChain(uint32_t chain,bool enable)362     int32_t FirewallEnableChain(uint32_t chain, bool enable) override
363     {
364         return 0;
365     }
366 
FirewallSetUidRule(uint32_t chain,const std::vector<uint32_t> & uids,uint32_t firewallRule)367     int32_t FirewallSetUidRule(uint32_t chain, const std::vector<uint32_t> &uids, uint32_t firewallRule) override
368     {
369         return 0;
370     }
371 
ShareDnsSet(uint16_t netId)372     int32_t ShareDnsSet(uint16_t netId) override
373     {
374         return 0;
375     }
376 
StartDnsProxyListen()377     int32_t StartDnsProxyListen() override
378     {
379         return 0;
380     }
381 
StopDnsProxyListen()382     int32_t StopDnsProxyListen() override
383     {
384         return 0;
385     }
386 
GetNetworkSharingTraffic(const std::string & downIface,const std::string & upIface,NetworkSharingTraffic & traffic)387     int32_t GetNetworkSharingTraffic(const std::string &downIface, const std::string &upIface,
388                                      NetworkSharingTraffic &traffic) override
389     {
390         return 0;
391     }
392 
GetTotalStats(uint64_t & stats,uint32_t type)393     int32_t GetTotalStats(uint64_t &stats, uint32_t type) override
394     {
395         return 0;
396     }
397 
GetUidStats(uint64_t & stats,uint32_t type,uint32_t uid)398     int32_t GetUidStats(uint64_t &stats, uint32_t type, uint32_t uid) override
399     {
400         return 0;
401     }
402 
GetIfaceStats(uint64_t & stats,uint32_t type,const std::string & interfaceName)403     int32_t GetIfaceStats(uint64_t &stats, uint32_t type, const std::string &interfaceName) override
404     {
405         return 0;
406     }
407 
GetAllSimStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> & stats)408     int32_t GetAllSimStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats) override
409     {
410         return 0;
411     }
412 
DeleteSimStatsInfo(uint32_t uid)413     int32_t DeleteSimStatsInfo(uint32_t uid) override
414     {
415         return 0;
416     }
417 
GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> & stats)418     int32_t GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats) override
419     {
420         return 0;
421     }
422 
DeleteStatsInfo(uint32_t uid)423     int32_t DeleteStatsInfo(uint32_t uid) override
424     {
425         return 0;
426     }
427 
SetIptablesCommandForRes(const std::string & cmd,std::string & respond,IptablesType ipType)428     int32_t SetIptablesCommandForRes(const std::string &cmd, std::string &respond, IptablesType ipType) override
429     {
430         return 0;
431     }
432 
NetDiagPingHost(const NetDiagPingOption & pingOption,const sptr<INetDiagCallback> & callback)433     int32_t NetDiagPingHost(const NetDiagPingOption &pingOption, const sptr<INetDiagCallback> &callback) override
434     {
435         return 0;
436     }
437 
NetDiagGetRouteTable(std::list<NetDiagRouteTable> & routeTables)438     int32_t NetDiagGetRouteTable(std::list<NetDiagRouteTable> &routeTables) override
439     {
440         return 0;
441     }
442 
NetDiagGetSocketsInfo(NetDiagProtocolType socketType,NetDiagSocketsInfo & socketsInfo)443     int32_t NetDiagGetSocketsInfo(NetDiagProtocolType socketType, NetDiagSocketsInfo &socketsInfo) override
444     {
445         return 0;
446     }
447 
NetDiagGetInterfaceConfig(std::list<NetDiagIfaceConfig> & configs,const std::string & ifaceName)448     int32_t NetDiagGetInterfaceConfig(std::list<NetDiagIfaceConfig> &configs, const std::string &ifaceName) override
449     {
450         return 0;
451     }
452 
NetDiagUpdateInterfaceConfig(const NetDiagIfaceConfig & config,const std::string & ifaceName,bool add)453     int32_t NetDiagUpdateInterfaceConfig(const NetDiagIfaceConfig &config, const std::string &ifaceName,
454                                          bool add) override
455     {
456         return 0;
457     }
458 
NetDiagSetInterfaceActiveState(const std::string & ifaceName,bool up)459     int32_t NetDiagSetInterfaceActiveState(const std::string &ifaceName, bool up) override
460     {
461         return 0;
462     }
463 
AddStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)464     int32_t AddStaticArp(const std::string &ipAddr, const std::string &macAddr, const std::string &ifName) override
465     {
466         return 0;
467     }
468 
DelStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)469     int32_t DelStaticArp(const std::string &ipAddr, const std::string &macAddr, const std::string &ifName) override
470     {
471         return 0;
472     }
473 
RegisterDnsResultCallback(const sptr<INetDnsResultCallback> & callback,uint32_t delay)474     int32_t RegisterDnsResultCallback(const sptr<INetDnsResultCallback> &callback, uint32_t delay) override
475     {
476         return 0;
477     }
478 
UnregisterDnsResultCallback(const sptr<INetDnsResultCallback> & callback)479     int32_t UnregisterDnsResultCallback(const sptr<INetDnsResultCallback> &callback) override
480     {
481         return 0;
482     }
483 
RegisterDnsHealthCallback(const sptr<INetDnsHealthCallback> & callback)484     int32_t RegisterDnsHealthCallback(const sptr<INetDnsHealthCallback> &callback) override
485     {
486         return 0;
487     }
488 
UnregisterDnsHealthCallback(const sptr<INetDnsHealthCallback> & callback)489     int32_t UnregisterDnsHealthCallback(const sptr<INetDnsHealthCallback> &callback) override
490     {
491         return 0;
492     }
493 
GetCookieStats(uint64_t & stats,uint32_t type,uint64_t cookie)494     int32_t GetCookieStats(uint64_t &stats, uint32_t type, uint64_t cookie) override
495     {
496         return 0;
497     }
498 
GetNetworkSharingType(std::set<uint32_t> & sharingTypeIsOn)499     int32_t GetNetworkSharingType(std::set<uint32_t>& sharingTypeIsOn) override
500     {
501         return 0;
502     }
503 
UpdateNetworkSharingType(uint32_t type,bool isOpen)504     int32_t UpdateNetworkSharingType(uint32_t type, bool isOpen) override
505     {
506         return 0;
507     }
508 
SetIpv6PrivacyExtensions(const std::string & interfaceName,const uint32_t on)509     int32_t SetIpv6PrivacyExtensions(const std::string &interfaceName, const uint32_t on) override
510     {
511         return 0;
512     }
513 
SetEnableIpv6(const std::string & interfaceName,const uint32_t on)514     int32_t SetEnableIpv6(const std::string &interfaceName, const uint32_t on) override
515     {
516         return 0;
517     }
518 
SetNetworkAccessPolicy(uint32_t uid,NetworkAccessPolicy policy,bool reconfirmFlag,bool isBroker)519     int32_t SetNetworkAccessPolicy(uint32_t uid, NetworkAccessPolicy policy, bool reconfirmFlag, bool isBroker) override
520     {
521         return 0;
522     }
523 
DeleteNetworkAccessPolicy(uint32_t uid)524     int32_t DeleteNetworkAccessPolicy(uint32_t uid) override
525     {
526         return 0;
527     }
528 
NotifyNetBearerTypeChange(std::set<NetBearType> bearerTypes)529     int32_t NotifyNetBearerTypeChange(std::set<NetBearType> bearerTypes) override
530     {
531         return 0;
532     }
533 
StartClat(const std::string & interfaceName,int32_t netId,const std::string & nat64PrefixStr)534     int32_t StartClat(const std::string &interfaceName, int32_t netId, const std::string &nat64PrefixStr) override
535     {
536         return 0;
537     }
538 
StopClat(const std::string & interfaceName)539     int32_t StopClat(const std::string &interfaceName) override
540     {
541         return 0;
542     }
543 
ClearFirewallAllRules()544     int32_t ClearFirewallAllRules() override
545     {
546         return 0;
547     }
548 
SetNicTrafficAllowed(const std::vector<std::string> & ifaceNames,bool status)549     int32_t SetNicTrafficAllowed(const std::vector<std::string> &ifaceNames, bool status) override
550     {
551         return 0;
552     }
553 };
554 
555 class NetsysNativeServiceStubTest : public testing::Test {
556 public:
557     static void SetUpTestCase();
558     static void TearDownTestCase();
559     void SetUp();
560     void TearDown();
561 
562     static inline std::shared_ptr<NetsysNativeServiceStub> notifyStub_ = nullptr;
563     sptr<NetDiagCallbackStubTest> ptrCallback = new NetDiagCallbackStubTest();
564 };
565 
SetUpTestCase()566 void NetsysNativeServiceStubTest::SetUpTestCase()
567 {
568     notifyStub_ = std::make_shared<TestNetsysNativeServiceStub>();
569 }
570 
TearDownTestCase()571 void NetsysNativeServiceStubTest::TearDownTestCase() {}
572 
SetUp()573 void NetsysNativeServiceStubTest::SetUp() {}
574 
TearDown()575 void NetsysNativeServiceStubTest::TearDown() {}
576 
577 HWTEST_F(NetsysNativeServiceStubTest, CmdSetResolverConfig001, TestSize.Level1)
578 {
579     uint16_t netId = 1001;
580     uint16_t baseTimeoutMsec = 0;
581     uint8_t retryCount = 0;
582     int32_t vServerSize = 2;
583     std::string strServer = "TestServer";
584 
585     int32_t vDomainSize = 1;
586     std::string strDomain = "TestDomain";
587 
588     MessageParcel data;
589     EXPECT_TRUE(data.WriteUint16(netId));
590     EXPECT_TRUE(data.WriteUint16(baseTimeoutMsec));
591     EXPECT_TRUE(data.WriteUint16(retryCount));
592     EXPECT_TRUE(data.WriteUint32(vServerSize));
593     EXPECT_TRUE(data.WriteString(strServer));
594     EXPECT_TRUE(data.WriteUint32(vDomainSize));
595     EXPECT_TRUE(data.WriteString(strDomain));
596     MessageParcel reply;
597     int32_t ret = notifyStub_->CmdSetResolverConfig(data, reply);
598     EXPECT_EQ(ret, ERR_FLATTEN_OBJECT);
599 }
600 
601 HWTEST_F(NetsysNativeServiceStubTest, CmdSetResolverConfig002, TestSize.Level1)
602 {
603     uint16_t netId = 1001;
604     uint16_t baseTimeoutMsec = 0;
605     uint8_t retryCount = 0;
606     int32_t vServerSize = 0;
607     int32_t vDomainSize = 0;
608     MessageParcel data;
609     EXPECT_TRUE(data.WriteUint16(netId));
610     EXPECT_TRUE(data.WriteUint16(baseTimeoutMsec));
611     EXPECT_TRUE(data.WriteUint8(retryCount));
612     EXPECT_TRUE(data.WriteUint32(vServerSize));
613     EXPECT_TRUE(data.WriteUint32(vDomainSize));
614     MessageParcel reply;
615     int32_t ret = notifyStub_->CmdSetResolverConfig(data, reply);
616     DTEST_LOG << "CmdSetResolverConfig002" << ret << std::endl;
617     EXPECT_EQ(ret, ERR_NONE);
618 }
619 
620 HWTEST_F(NetsysNativeServiceStubTest, CmdSetResolverConfig003, TestSize.Level1)
621 {
622     uint16_t netId = 1001;
623     uint16_t baseTimeoutMsec = 0;
624     uint8_t retryCount = 0;
625     int32_t vServerSize = 2;
626     std::string server = "testserver";
627     int32_t vDomainSize = 2;
628     std::string domain = "testdomain";
629     MessageParcel data;
630     EXPECT_TRUE(data.WriteUint16(netId));
631     EXPECT_TRUE(data.WriteUint16(baseTimeoutMsec));
632     EXPECT_TRUE(data.WriteUint8(retryCount));
633     EXPECT_TRUE(data.WriteUint32(vServerSize));
634     for (int32_t i = 0; i < vServerSize; i++) {
635         EXPECT_TRUE(data.WriteString(server));
636     }
637 
638     EXPECT_TRUE(data.WriteUint32(vDomainSize));
639     for (int32_t i = 0; i < vDomainSize; i++) {
640         EXPECT_TRUE(data.WriteString(domain));
641     }
642     MessageParcel reply;
643     int32_t ret = notifyStub_->CmdSetResolverConfig(data, reply);
644     DTEST_LOG << "CmdSetResolverConfig003" << ret << std::endl;
645     EXPECT_EQ(ret, ERR_NONE);
646 }
647 
IsDataParemerVaild(MessageParcel & data)648 bool IsDataParemerVaild(MessageParcel &data)
649 {
650     uint16_t netId = 1001;
651     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
652         return false;
653     }
654     if (!data.WriteUint16(netId)) {
655         return false;
656     }
657     return true;
658 }
659 
660 HWTEST_F(NetsysNativeServiceStubTest, CmdGetResolverConfig001, TestSize.Level1)
661 {
662     MessageParcel data;
663     MessageParcel reply;
664     if (!IsDataParemerVaild(data)) {
665         return;
666     }
667     int32_t ret = notifyStub_->CmdGetResolverConfig(data, reply);
668     EXPECT_EQ(ret, ERR_NONE);
669 }
670 
671 HWTEST_F(NetsysNativeServiceStubTest, CmdCreateNetworkCache001, TestSize.Level1)
672 {
673     MessageParcel data;
674     if (!IsDataParemerVaild(data)) {
675         return;
676     }
677     MessageParcel reply;
678     int32_t ret = notifyStub_->CmdCreateNetworkCache(data, reply);
679     EXPECT_EQ(ret, ERR_NONE);
680 }
681 
682 HWTEST_F(NetsysNativeServiceStubTest, CmdDestroyNetworkCache001, TestSize.Level1)
683 {
684     MessageParcel data;
685     if (!IsDataParemerVaild(data)) {
686         return;
687     }
688     MessageParcel reply;
689     int32_t ret = notifyStub_->CmdDestroyNetworkCache(data, reply);
690     EXPECT_EQ(ret, ERR_NONE);
691 }
692 
693 HWTEST_F(NetsysNativeServiceStubTest, CmdGetAddrInfo001, TestSize.Level1)
694 {
695     std::string hostName = "TestHostName";
696     std::string serverName = "TestServerName";
697 
698     struct AddrInfo addrInfo;
699     addrInfo.aiFlags = 0;
700     addrInfo.aiFamily = AF_INET;
701 
702     uint16_t netId = 1001;
703 
704     MessageParcel data;
705     EXPECT_TRUE(data.WriteString(hostName));
706     EXPECT_TRUE(data.WriteString(serverName));
707     EXPECT_TRUE(data.WriteRawData(&addrInfo, sizeof(AddrInfo)));
708     EXPECT_TRUE(data.WriteUint16(netId));
709     MessageParcel reply;
710     int32_t ret = notifyStub_->CmdGetAddrInfo(data, reply);
711     EXPECT_EQ(ret, ERR_NONE);
712 }
713 
714 HWTEST_F(NetsysNativeServiceStubTest, CmdGetAddrInfo002, TestSize.Level1)
715 {
716     std::string hostName = "TestHostName";
717     std::string serverName = "TestServerName";
718 
719     struct AddrInfo addrInfo;
720     addrInfo.aiFlags = 0;
721     addrInfo.aiFamily = 9999;
722     uint16_t netId = 1001;
723 
724     MessageParcel data;
725     if (!data.WriteString(hostName)) {
726         return;
727     }
728     if (!data.WriteString(serverName)) {
729         return;
730     }
731     if (!data.WriteRawData(&addrInfo, sizeof(AddrInfo))) {
732         return;
733     }
734     if (!data.WriteUint16(netId)) {
735         return;
736     }
737     MessageParcel reply;
738     int32_t ret = notifyStub_->CmdGetAddrInfo(data, reply);
739     EXPECT_EQ(ret, ERR_NONE);
740 }
741 
742 HWTEST_F(NetsysNativeServiceStubTest, CmdSetInterfaceMtu001, TestSize.Level1)
743 {
744     std::string ifName = "ifName";
745     int32_t mtu = 0;
746 
747     MessageParcel data;
748     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
749         return;
750     }
751     if (!data.WriteString(ifName)) {
752         return;
753     }
754     if (!data.WriteUint32(mtu)) {
755         return;
756     }
757 
758     MessageParcel reply;
759     int32_t ret = notifyStub_->CmdSetInterfaceMtu(data, reply);
760     EXPECT_EQ(ret, ERR_NONE);
761 }
762 
763 HWTEST_F(NetsysNativeServiceStubTest, CmdGetInterfaceMtu001, TestSize.Level1)
764 {
765     std::string ifName = "ifName";
766 
767     MessageParcel data;
768     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
769         return;
770     }
771     if (!data.WriteString(ifName)) {
772         return;
773     }
774 
775     MessageParcel reply;
776     int32_t ret = notifyStub_->CmdGetInterfaceMtu(data, reply);
777     EXPECT_EQ(ret, ERR_NONE);
778 }
779 
780 HWTEST_F(NetsysNativeServiceStubTest, CmdRegisterNotifyCallback001, TestSize.Level1)
781 {
782     std::string ifName = "ifName";
783     sptr<INotifyCallback> callback = new (std::nothrow) NotifyCallbackTest();
784     MessageParcel data;
785     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
786         return;
787     }
788     if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
789         return;
790     }
791 
792     MessageParcel reply;
793     int32_t ret = notifyStub_->CmdRegisterNotifyCallback(data, reply);
794     EXPECT_EQ(ret, -1);
795     MessageParcel data2;
796     EXPECT_TRUE(data2.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor()));
797     EXPECT_TRUE(data2.WriteRemoteObject(callback->AsObject().GetRefPtr()));
798     ret = notifyStub_->CmdUnRegisterNotifyCallback(data2, reply);
799     EXPECT_EQ(ret, -1);
800 }
801 
802 HWTEST_F(NetsysNativeServiceStubTest, CmdRegisterNotifyCallback002, TestSize.Level1)
803 {
804     std::string ifName = "ifName";
805     sptr<INotifyCallback> callback = new (std::nothrow) NotifyCallbackTest();
806     MessageParcel data;
807     EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject().GetRefPtr()));
808 
809     MessageParcel reply;
810     int32_t ret = notifyStub_->CmdRegisterNotifyCallback(data, reply);
811     EXPECT_EQ(ret, ERR_NONE);
812     MessageParcel data2;
813     EXPECT_TRUE(data2.WriteRemoteObject(callback->AsObject().GetRefPtr()));
814     ret = notifyStub_->CmdUnRegisterNotifyCallback(data2, reply);
815     EXPECT_EQ(ret, ERR_NONE);
816 }
817 
818 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkRouteParcel001, TestSize.Level1)
819 {
820     uint16_t netId = 1001;
821     std::string ifName = "ifName";
822     std::string destination = "destination";
823     std::string nextHop = "nextHop";
824 
825     MessageParcel data;
826     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
827         return;
828     }
829     if (!data.WriteUint16(netId)) {
830         return;
831     }
832     if (!data.WriteString(ifName)) {
833         return;
834     }
835     if (!data.WriteString(destination)) {
836         return;
837     }
838     if (!data.WriteString(nextHop)) {
839         return;
840     }
841 
842     MessageParcel reply;
843     int32_t ret = notifyStub_->CmdNetworkAddRouteParcel(data, reply);
844     EXPECT_EQ(ret, ERR_NONE);
845 
846     ret = notifyStub_->CmdNetworkRemoveRouteParcel(data, reply);
847     EXPECT_EQ(ret, ERR_NONE);
848 }
849 
850 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkDefault001, TestSize.Level1)
851 {
852     uint16_t netId = 1001;
853     MessageParcel data;
854     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
855         return;
856     }
857     if (!data.WriteUint16(netId)) {
858         return;
859     }
860 
861     MessageParcel reply;
862     int32_t ret = notifyStub_->CmdNetworkSetDefault(data, reply);
863     EXPECT_EQ(ret, ERR_NONE);
864 
865     ret = notifyStub_->CmdNetworkGetDefault(data, reply);
866     EXPECT_EQ(ret, ERR_NONE);
867 
868     ret = notifyStub_->CmdNetworkClearDefault(data, reply);
869     EXPECT_EQ(ret, ERR_NONE);
870 }
871 
872 HWTEST_F(NetsysNativeServiceStubTest, CmdProcSysNet001, TestSize.Level1)
873 {
874     int32_t family = 0;
875     int32_t which = 0;
876     std::string ifName = "TestIfName";
877     std::string parameter = "TestParameter";
878 
879     MessageParcel data;
880     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
881         return;
882     }
883     if (!data.WriteUint32(family)) {
884         return;
885     }
886     if (!data.WriteUint32(which)) {
887         return;
888     }
889     if (!data.WriteString(ifName)) {
890         return;
891     }
892     if (!data.WriteString(parameter)) {
893         return;
894     }
895 
896     MessageParcel reply;
897     int32_t ret = notifyStub_->CmdGetProcSysNet(data, reply);
898     EXPECT_EQ(ret, ERR_NONE);
899 
900     std::string value = "TestValue";
901     if (!data.WriteString(value)) {
902         return;
903     }
904 
905     ret = notifyStub_->CmdSetProcSysNet(data, reply);
906     EXPECT_EQ(ret, ERR_NONE);
907 }
908 
909 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkCreatePhysical001, TestSize.Level1)
910 {
911     int32_t netId = 1001;
912     int32_t permission = 0;
913 
914     MessageParcel data;
915     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
916         return;
917     }
918     if (!data.WriteUint32(netId)) {
919         return;
920     }
921     if (!data.WriteUint32(permission)) {
922         return;
923     }
924 
925     MessageParcel reply;
926     int32_t ret = notifyStub_->CmdNetworkCreatePhysical(data, reply);
927     EXPECT_EQ(ret, ERR_NONE);
928 }
929 
930 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceAddress001, TestSize.Level1)
931 {
932     std::string interfaceName = "testInterfaceName";
933     std::string ipAddr = "testIpAddr";
934     int32_t prefixLength = 10;
935 
936     MessageParcel data;
937     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
938         return;
939     }
940     if (!data.WriteString(interfaceName)) {
941         return;
942     }
943     if (!data.WriteString(ipAddr)) {
944         return;
945     }
946     if (!data.WriteUint32(prefixLength)) {
947         return;
948     }
949 
950     MessageParcel reply;
951     int32_t ret = notifyStub_->CmdAddInterfaceAddress(data, reply);
952     EXPECT_EQ(ret, ERR_NONE);
953 
954     ret = notifyStub_->CmdDelInterfaceAddress(data, reply);
955     EXPECT_EQ(ret, ERR_NONE);
956 }
957 
958 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceSetIpAddress001, TestSize.Level1)
959 {
960     std::string interfaceName = "testInterfaceName";
961     std::string ipAddress = "testIpAddr";
962 
963     MessageParcel data;
964     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
965         return;
966     }
967     if (!data.WriteString(interfaceName)) {
968         return;
969     }
970     if (!data.WriteString(ipAddress)) {
971         return;
972     }
973 
974     MessageParcel reply;
975     int32_t ret = notifyStub_->CmdInterfaceSetIpAddress(data, reply);
976     EXPECT_EQ(ret, ERR_NONE);
977 }
978 
979 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceSetIffUp001, TestSize.Level1)
980 {
981     std::string interfaceName = "testInterfaceName";
982 
983     MessageParcel data;
984     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
985         return;
986     }
987     if (!data.WriteString(interfaceName)) {
988         return;
989     }
990 
991     MessageParcel reply;
992     int32_t ret = notifyStub_->CmdInterfaceSetIffUp(data, reply);
993     EXPECT_EQ(ret, ERR_NONE);
994 }
995 
996 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkInterface001, TestSize.Level1)
997 {
998     int32_t netId = 1001;
999     std::string interfaceName = "testInterfaceName";
1000     NetBearType bearerType = BEARER_DEFAULT;
1001 
1002     MessageParcel data;
1003     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1004         return;
1005     }
1006     if (!data.WriteString(interfaceName)) {
1007         return;
1008     }
1009     if (!data.WriteUint32(netId)) {
1010         return;
1011     }
1012     if (!data.WriteUint8(bearerType)) {
1013         return;
1014     }
1015 
1016     MessageParcel reply;
1017     int32_t ret = notifyStub_->CmdNetworkAddInterface(data, reply);
1018     EXPECT_EQ(ret, ERR_NONE);
1019 
1020     notifyStub_->CmdNetworkRemoveInterface(data, reply);
1021     EXPECT_EQ(ret, ERR_NONE);
1022 }
1023 
1024 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkDestroy001, TestSize.Level1)
1025 {
1026     int32_t netId = 1001;
1027 
1028     MessageParcel data;
1029     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1030         return;
1031     }
1032     if (!data.WriteUint32(netId)) {
1033         return;
1034     }
1035 
1036     MessageParcel reply;
1037     int32_t ret = notifyStub_->CmdNetworkDestroy(data, reply);
1038     EXPECT_EQ(ret, ERR_NONE);
1039 }
1040 
1041 HWTEST_F(NetsysNativeServiceStubTest, CmdGetFwmarkForNetwork001, TestSize.Level1)
1042 {
1043     int32_t netId = 1001;
1044     int32_t mark = 0;
1045     int32_t mask = 0;
1046     MessageParcel data;
1047     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1048         return;
1049     }
1050     if (!data.WriteUint32(netId)) {
1051         return;
1052     }
1053     if (!data.WriteUint32(mark)) {
1054         return;
1055     }
1056     if (!data.WriteUint32(mask)) {
1057         return;
1058     }
1059 
1060     MessageParcel reply;
1061     int32_t ret = notifyStub_->CmdGetFwmarkForNetwork(data, reply);
1062     EXPECT_EQ(ret, ERR_NONE);
1063 }
1064 
1065 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceConfig001, TestSize.Level1)
1066 {
1067     std::string ifName = "testIfName";
1068     std::string hwAddr = "testHwAddr";
1069     std::string ipv4Addr = "testIpv4Addr";
1070     uint32_t prefixLength = 0;
1071     uint32_t vServerSize = 1;
1072     std::string flag = "testFlag";
1073 
1074     MessageParcel data;
1075     EXPECT_TRUE(data.WriteString(ifName));
1076     EXPECT_TRUE(data.WriteString(hwAddr));
1077     EXPECT_TRUE(data.WriteString(ipv4Addr));
1078     EXPECT_TRUE(data.WriteUint32(prefixLength));
1079     EXPECT_TRUE(data.WriteUint32(vServerSize));
1080     EXPECT_TRUE(data.WriteString(flag));
1081 
1082     MessageParcel reply;
1083     int32_t ret = notifyStub_->CmdSetInterfaceConfig(data, reply);
1084     EXPECT_EQ(ret, ERR_NONE);
1085 
1086     ret = notifyStub_->CmdGetInterfaceConfig(data, reply);
1087     EXPECT_EQ(ret, ERR_NONE);
1088 }
1089 
1090 HWTEST_F(NetsysNativeServiceStubTest, CmdInterfaceGetList001, TestSize.Level1)
1091 {
1092     MessageParcel data;
1093     MessageParcel reply;
1094     int32_t ret = notifyStub_->CmdInterfaceGetList(data, reply);
1095     EXPECT_EQ(ret, ERR_NONE);
1096 }
1097 
1098 HWTEST_F(NetsysNativeServiceStubTest, CmdDhcpClient001, TestSize.Level1)
1099 {
1100     std::string iface = "testIface";
1101     bool bIpv6 = true;
1102     MessageParcel data;
1103     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1104         return;
1105     }
1106     if (!data.WriteString(iface)) {
1107         return;
1108     }
1109     if (!data.WriteBool(bIpv6)) {
1110         return;
1111     }
1112 
1113     MessageParcel reply;
1114     int32_t ret = notifyStub_->CmdStartDhcpClient(data, reply);
1115     EXPECT_EQ(ret, ERR_NONE);
1116 
1117     ret = notifyStub_->CmdStopDhcpClient(data, reply);
1118     EXPECT_EQ(ret, ERR_NONE);
1119 }
1120 
1121 HWTEST_F(NetsysNativeServiceStubTest, CmdDhcpService001, TestSize.Level1)
1122 {
1123     std::string iface = "testIface";
1124     std::string ipv4addr = "testIpv4addr";
1125 
1126     MessageParcel data;
1127     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1128         return;
1129     }
1130     if (!data.WriteString(iface)) {
1131         return;
1132     }
1133     if (!data.WriteString(ipv4addr)) {
1134         return;
1135     }
1136 
1137     MessageParcel reply;
1138     int32_t ret = notifyStub_->CmdStartDhcpService(data, reply);
1139     EXPECT_EQ(ret, ERR_NONE);
1140 
1141     ret = notifyStub_->CmdStopDhcpService(data, reply);
1142     EXPECT_EQ(ret, ERR_NONE);
1143 }
1144 
1145 HWTEST_F(NetsysNativeServiceStubTest, CmdIpForwarding001, TestSize.Level1)
1146 {
1147     std::string requester = "testRequester";
1148 
1149     MessageParcel data;
1150     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1151         return;
1152     }
1153     if (!data.WriteString(requester)) {
1154         return;
1155     }
1156 
1157     MessageParcel reply;
1158     int32_t ret = notifyStub_->CmdIpEnableForwarding(data, reply);
1159     EXPECT_EQ(ret, ERR_NONE);
1160 
1161     ret = notifyStub_->CmdIpDisableForwarding(data, reply);
1162     EXPECT_EQ(ret, ERR_NONE);
1163 }
1164 
1165 HWTEST_F(NetsysNativeServiceStubTest, CmdNat001, TestSize.Level1)
1166 {
1167     std::string downstreamIface = "testDownstreamIface";
1168     std::string upstreamIface = "testUpstreamIface";
1169 
1170     MessageParcel data;
1171     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1172         return;
1173     }
1174     if (!data.WriteString(downstreamIface)) {
1175         return;
1176     }
1177     if (!data.WriteString(upstreamIface)) {
1178         return;
1179     }
1180 
1181     MessageParcel reply;
1182     int32_t ret = notifyStub_->CmdEnableNat(data, reply);
1183     EXPECT_EQ(ret, ERR_NONE);
1184 
1185     ret = notifyStub_->CmdDisableNat(data, reply);
1186     EXPECT_EQ(ret, ERR_NONE);
1187 }
1188 
1189 HWTEST_F(NetsysNativeServiceStubTest, CmdIpfwdInterfaceForward001, TestSize.Level1)
1190 {
1191     std::string fromIface = "testFromIface";
1192     std::string toIface = "testToIface";
1193 
1194     MessageParcel data;
1195     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1196         return;
1197     }
1198     if (!data.WriteString(fromIface)) {
1199         return;
1200     }
1201     if (!data.WriteString(toIface)) {
1202         return;
1203     }
1204 
1205     MessageParcel reply;
1206     int32_t ret = notifyStub_->CmdIpfwdAddInterfaceForward(data, reply);
1207     EXPECT_EQ(ret, ERR_NONE);
1208 
1209     ret = notifyStub_->CmdIpfwdRemoveInterfaceForward(data, reply);
1210     EXPECT_EQ(ret, ERR_NONE);
1211 }
1212 
1213 HWTEST_F(NetsysNativeServiceStubTest, CmdBandwidthEnableDataSaver001, TestSize.Level1)
1214 {
1215     bool enable = true;
1216 
1217     MessageParcel data;
1218     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1219         return;
1220     }
1221     if (!data.WriteBool(enable)) {
1222         return;
1223     }
1224 
1225     MessageParcel reply;
1226     int32_t ret = notifyStub_->CmdBandwidthEnableDataSaver(data, reply);
1227     EXPECT_EQ(ret, ERR_NONE);
1228 }
1229 
1230 HWTEST_F(NetsysNativeServiceStubTest, CmdBandwidthIfaceQuota001, TestSize.Level1)
1231 {
1232     std::string ifName = "testIfName";
1233 
1234     MessageParcel data;
1235     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1236         return;
1237     }
1238     if (!data.WriteString(ifName)) {
1239         return;
1240     }
1241 
1242     MessageParcel reply;
1243     int32_t ret = notifyStub_->CmdBandwidthSetIfaceQuota(data, reply);
1244     EXPECT_EQ(ret, ERR_NONE);
1245 
1246     ret = notifyStub_->CmdBandwidthRemoveIfaceQuota(data, reply);
1247     EXPECT_EQ(ret, ERR_NONE);
1248 }
1249 
1250 HWTEST_F(NetsysNativeServiceStubTest, CmdBandwidthList001, TestSize.Level1)
1251 {
1252     uint32_t uid = 1001;
1253 
1254     MessageParcel data;
1255     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1256         return;
1257     }
1258     if (!data.WriteUint32(uid)) {
1259         return;
1260     }
1261 
1262     MessageParcel reply;
1263     int32_t ret = notifyStub_->CmdBandwidthAddDeniedList(data, reply);
1264     EXPECT_EQ(ret, ERR_NONE);
1265 
1266     ret = notifyStub_->CmdBandwidthRemoveDeniedList(data, reply);
1267     EXPECT_EQ(ret, ERR_NONE);
1268 
1269     ret = notifyStub_->CmdBandwidthAddAllowedList(data, reply);
1270     EXPECT_EQ(ret, ERR_NONE);
1271 
1272     ret = notifyStub_->CmdBandwidthRemoveAllowedList(data, reply);
1273     EXPECT_EQ(ret, ERR_NONE);
1274 }
1275 
1276 HWTEST_F(NetsysNativeServiceStubTest, CmdFirewallSetUidsListChain001, TestSize.Level1)
1277 {
1278     uint32_t chain = 0;
1279     uint32_t uidSize = 1;
1280     uint32_t uid = 1001;
1281 
1282     MessageParcel data;
1283     if (!data.WriteUint32(chain)) {
1284         return;
1285     }
1286     if (!data.WriteUint32(uidSize)) {
1287         return;
1288     }
1289     if (!data.WriteUint32(uid)) {
1290         return;
1291     }
1292 
1293     MessageParcel reply;
1294     int32_t ret = notifyStub_->CmdFirewallSetUidsAllowedListChain(data, reply);
1295     EXPECT_EQ(ret, ERR_NONE);
1296 
1297     ret = notifyStub_->CmdFirewallSetUidsDeniedListChain(data, reply);
1298     EXPECT_EQ(ret, ERR_NONE);
1299 }
1300 
1301 HWTEST_F(NetsysNativeServiceStubTest, CmdFirewallEnableChain001, TestSize.Level1)
1302 {
1303     uint32_t chain = 0;
1304     bool enable = true;
1305 
1306     MessageParcel data;
1307     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1308         return;
1309     }
1310     if (!data.WriteUint32(chain)) {
1311         return;
1312     }
1313     if (!data.WriteBool(enable)) {
1314         return;
1315     }
1316 
1317     MessageParcel reply;
1318     int32_t ret = notifyStub_->CmdFirewallEnableChain(data, reply);
1319     EXPECT_EQ(ret, ERR_NONE);
1320 }
1321 
1322 HWTEST_F(NetsysNativeServiceStubTest, CmdFirewallSetUidRule001, TestSize.Level1)
1323 {
1324     uint32_t chain = 0;
1325     uint32_t uid = 1001;
1326     uint32_t firewallRule = 1;
1327 
1328     MessageParcel data;
1329     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1330         return;
1331     }
1332     if (!data.WriteUint32(chain)) {
1333         return;
1334     }
1335     if (!data.WriteUint32(uid)) {
1336         return;
1337     }
1338     if (!data.WriteUint32(firewallRule)) {
1339         return;
1340     }
1341 
1342     MessageParcel reply;
1343     int32_t ret = notifyStub_->CmdFirewallSetUidRule(data, reply);
1344     EXPECT_EQ(ret, ERR_NONE);
1345 }
1346 
1347 HWTEST_F(NetsysNativeServiceStubTest, CmdClearFirewallAllRules001, TestSize.Level1)
1348 {
1349     uint32_t chain = 0;
1350     bool enable = true;
1351 
1352     MessageParcel data;
1353     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1354         return;
1355     }
1356 
1357     MessageParcel reply;
1358     int32_t ret = notifyStub_->CmdClearFirewallAllRules(data, reply);
1359     EXPECT_EQ(ret, ERR_NONE);
1360 }
1361 
1362 HWTEST_F(NetsysNativeServiceStubTest, CmdShareDnsSet001, TestSize.Level1)
1363 {
1364     uint16_t netId = 0;
1365 
1366     MessageParcel data;
1367     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1368         return;
1369     }
1370     if (!data.WriteUint16(netId)) {
1371         return;
1372     }
1373 
1374     MessageParcel reply;
1375     int32_t ret = notifyStub_->CmdShareDnsSet(data, reply);
1376     EXPECT_EQ(ret, ERR_NONE);
1377 }
1378 
1379 HWTEST_F(NetsysNativeServiceStubTest, CmdDnsProxyListen001, TestSize.Level1)
1380 {
1381     MessageParcel data;
1382     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1383         return;
1384     }
1385 
1386     MessageParcel reply;
1387     int32_t ret = notifyStub_->CmdStartDnsProxyListen(data, reply);
1388     EXPECT_EQ(ret, ERR_NONE);
1389 
1390     ret = notifyStub_->CmdStopDnsProxyListen(data, reply);
1391     EXPECT_EQ(ret, ERR_NONE);
1392 }
1393 
1394 HWTEST_F(NetsysNativeServiceStubTest, CmdGetNetworkSharingTraffic001, TestSize.Level1)
1395 {
1396     std::string downIface = "testDownIface";
1397     std::string upIface = "testUpIface ";
1398 
1399     MessageParcel data;
1400     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1401         return;
1402     }
1403     if (!data.WriteString(downIface)) {
1404         return;
1405     }
1406     if (!data.WriteString(upIface)) {
1407         return;
1408     }
1409 
1410     MessageParcel reply;
1411     int32_t ret = notifyStub_->CmdGetNetworkSharingTraffic(data, reply);
1412     EXPECT_EQ(ret, ERR_NONE);
1413 }
1414 
1415 HWTEST_F(NetsysNativeServiceStubTest, CmdGetTotalStats001, TestSize.Level1)
1416 {
1417     uint32_t type = 0;
1418     MessageParcel data;
1419     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1420         return;
1421     }
1422     if (!data.WriteInt32(type)) {
1423         return;
1424     }
1425 
1426     MessageParcel reply;
1427     int32_t ret = notifyStub_->CmdGetTotalStats(data, reply);
1428     EXPECT_EQ(ret, ERR_NONE);
1429 }
1430 
1431 HWTEST_F(NetsysNativeServiceStubTest, CmdGetUidStats001, TestSize.Level1)
1432 {
1433     uint32_t type = 0;
1434     uint32_t uId = 2020;
1435     MessageParcel data;
1436     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1437         return;
1438     }
1439     if (!data.WriteInt32(type)) {
1440         return;
1441     }
1442     if (!data.WriteInt32(uId)) {
1443         return;
1444     }
1445 
1446     MessageParcel reply;
1447     int32_t ret = notifyStub_->CmdGetUidStats(data, reply);
1448     EXPECT_EQ(ret, ERR_NONE);
1449 }
1450 
1451 HWTEST_F(NetsysNativeServiceStubTest, CmdGetIfaceStats001, TestSize.Level1)
1452 {
1453     uint32_t type = 0;
1454     std::string Iface = "wlan0";
1455 
1456     MessageParcel data;
1457     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1458         return;
1459     }
1460     if (!data.WriteInt32(type)) {
1461         return;
1462     }
1463     if (!data.WriteString(Iface)) {
1464         return;
1465     }
1466 
1467     MessageParcel reply;
1468     int32_t ret = notifyStub_->CmdGetIfaceStats(data, reply);
1469     EXPECT_EQ(ret, ERR_NONE);
1470 }
1471 
1472 HWTEST_F(NetsysNativeServiceStubTest, CmdGetAllStatsInfo001, TestSize.Level1)
1473 {
1474     MessageParcel data;
1475     MessageParcel reply;
1476     int32_t ret = notifyStub_->CmdGetAllStatsInfo(data, reply);
1477     EXPECT_EQ(ret, ERR_NONE);
1478 }
1479 
1480 HWTEST_F(NetsysNativeServiceStubTest, CmdDeleteStatsInfoTest001, TestSize.Level1)
1481 {
1482     MessageParcel data;
1483     EXPECT_TRUE(data.WriteUint32(TEST_UID));
1484     MessageParcel reply;
1485     int32_t ret = notifyStub_->CmdDeleteStatsInfo(data, reply);
1486     EXPECT_EQ(ret, ERR_NONE);
1487 }
1488 
1489 HWTEST_F(NetsysNativeServiceStubTest, CmdGetAllSimStatsInfoTest001, TestSize.Level1)
1490 {
1491     MessageParcel data;
1492     MessageParcel reply;
1493     int32_t ret = notifyStub_->CmdGetAllSimStatsInfo(data, reply);
1494     EXPECT_EQ(ret, ERR_NONE);
1495 }
1496 
1497 HWTEST_F(NetsysNativeServiceStubTest, CmdDeleteSimStatsInfoTest001, TestSize.Level1)
1498 {
1499     MessageParcel data;
1500     EXPECT_TRUE(data.WriteUint32(TEST_UID));
1501     MessageParcel reply;
1502     int32_t ret = notifyStub_->CmdDeleteSimStatsInfo(data, reply);
1503     EXPECT_EQ(ret, ERR_NONE);
1504 }
1505 
1506 HWTEST_F(NetsysNativeServiceStubTest, NetsysFreeAddrinfoTest001, TestSize.Level1)
1507 {
1508     addrinfo *ai = nullptr;
1509     int32_t ret = notifyStub_->NetsysFreeAddrinfo(ai);
1510     EXPECT_EQ(ret, ERR_NONE);
1511 }
1512 
1513 HWTEST_F(NetsysNativeServiceStubTest, CmdSetInternetPermissionTest001, TestSize.Level1)
1514 {
1515     MessageParcel data;
1516     MessageParcel reply;
1517     uint32_t uid = 0;
1518     uint8_t allow = 1;
1519     ASSERT_TRUE(data.WriteUint32(uid));
1520     ASSERT_TRUE(data.WriteUint8(allow));
1521     int32_t ret = notifyStub_->CmdSetInternetPermission(data, reply);
1522     EXPECT_EQ(ret, ERR_NONE);
1523 }
1524 
1525 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkCreateVirtualTest001, TestSize.Level1)
1526 {
1527     MessageParcel data;
1528     MessageParcel reply;
1529     data.WriteInt32(0);
1530     data.WriteBool(false);
1531     int32_t ret = notifyStub_->CmdNetworkCreateVirtual(data, reply);
1532     EXPECT_EQ(ret, ERR_NONE);
1533 }
1534 
1535 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkAddUidsTest001, TestSize.Level1)
1536 {
1537     MessageParcel data;
1538     MessageParcel reply;
1539     data.WriteInt32(0);
1540     data.WriteInt32(0);
1541     int32_t ret = notifyStub_->CmdNetworkAddUids(data, reply);
1542     EXPECT_EQ(ret, ERR_NONE);
1543 }
1544 
1545 HWTEST_F(NetsysNativeServiceStubTest, CmdNetworkDelUidsTest001, TestSize.Level1)
1546 {
1547     MessageParcel data;
1548     MessageParcel reply;
1549     data.WriteInt32(0);
1550     data.WriteInt32(0);
1551     int32_t ret = notifyStub_->CmdNetworkDelUids(data, reply);
1552     EXPECT_EQ(ret, ERR_NONE);
1553 }
1554 
1555 HWTEST_F(NetsysNativeServiceStubTest, CmdSetIptablesCommandForResTest001, TestSize.Level1)
1556 {
1557     MessageParcel data;
1558     MessageParcel reply;
1559     int32_t ret = notifyStub_->CmdSetIptablesCommandForRes(data, reply);
1560     EXPECT_EQ(ret, NETMANAGER_ERR_PERMISSION_DENIED);
1561 }
1562 
1563 HWTEST_F(NetsysNativeServiceStubTest, OnRemoteRequestTest001, TestSize.Level1)
1564 {
1565     uint32_t errcode = 9999;
1566     MessageParcel data;
1567     MessageParcel reply;
1568     MessageOption option;
1569     auto result = notifyStub_->OnRemoteRequest(errcode, data, reply, option);
1570     EXPECT_EQ(result, IPC_STUB_UNKNOW_TRANS_ERR);
1571     uint32_t code = 10;
1572     result = notifyStub_->OnRemoteRequest(code, data, reply, option);
1573     EXPECT_EQ(result, IPC_STUB_INVALID_DATA_ERR);
1574     auto descriptor = NetsysNativeServiceStub::GetDescriptor();
1575     data.WriteInterfaceToken(descriptor);
1576     code = 8;
1577     result = notifyStub_->OnRemoteRequest(code, data, reply, option);
1578     EXPECT_EQ(result, ERR_NONE);
1579 }
1580 
1581 HWTEST_F(NetsysNativeServiceStubTest, CmdNetDiagPingHostCommandForResTest001, TestSize.Level1)
1582 {
1583     NetDiagPingOption pingOption;
1584     MessageParcel data;
1585 
1586     pingOption.Marshalling(data);
1587     MessageParcel reply;
1588 
1589     int32_t ret = notifyStub_->CmdNetDiagPingHost(data, reply);
1590     EXPECT_EQ(ret, IPC_STUB_ERR);
1591 
1592     pingOption.Marshalling(data);
1593     data.WriteRemoteObject(ptrCallback->AsObject().GetRefPtr());
1594     ret = notifyStub_->CmdNetDiagPingHost(data, reply);
1595     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1596 }
1597 
1598 HWTEST_F(NetsysNativeServiceStubTest, CmdNetDiagGetRouteTableCommandForResTest001, TestSize.Level1)
1599 {
1600     MessageParcel data;
1601     MessageParcel reply;
1602 
1603     int32_t ret = notifyStub_->CmdNetDiagGetRouteTable(data, reply);
1604     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1605 }
1606 
1607 HWTEST_F(NetsysNativeServiceStubTest, CmdNetDiagGetSocketsInfoCommandForResTest001, TestSize.Level1)
1608 {
1609     MessageParcel data;
1610     MessageParcel reply;
1611     data.WriteUint8(NetDiagProtocolType::PROTOCOL_TYPE_ALL);
1612     int32_t ret = notifyStub_->CmdNetDiagGetSocketsInfo(data, reply);
1613     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1614 
1615     data.WriteUint8(NetDiagProtocolType::PROTOCOL_TYPE_TCP);
1616     ret = notifyStub_->CmdNetDiagGetSocketsInfo(data, reply);
1617     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1618 
1619     data.WriteUint8(NetDiagProtocolType::PROTOCOL_TYPE_UDP);
1620     ret = notifyStub_->CmdNetDiagGetSocketsInfo(data, reply);
1621     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1622 
1623     data.WriteUint8(NetDiagProtocolType::PROTOCOL_TYPE_UNIX);
1624     ret = notifyStub_->CmdNetDiagGetSocketsInfo(data, reply);
1625     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1626 
1627     data.WriteUint8(NetDiagProtocolType::PROTOCOL_TYPE_RAW);
1628     ret = notifyStub_->CmdNetDiagGetSocketsInfo(data, reply);
1629     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1630 }
1631 
1632 HWTEST_F(NetsysNativeServiceStubTest, CmdNetDiagSetInterfaceActiveStateCommandForResTest001, TestSize.Level1)
1633 {
1634     MessageParcel data;
1635     MessageParcel reply;
1636     data.WriteString("eth0");
1637     data.WriteBool(true);
1638     int32_t ret = notifyStub_->CmdNetDiagSetInterfaceActiveState(data, reply);
1639     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1640 
1641     data.WriteString("eth0");
1642     data.WriteBool(false);
1643     ret = notifyStub_->CmdNetDiagSetInterfaceActiveState(data, reply);
1644     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1645 }
1646 
1647 HWTEST_F(NetsysNativeServiceStubTest, CmdNetDiagUpdateInterfaceConfigCommandForResTest001, TestSize.Level1)
1648 {
1649     MessageParcel data;
1650     MessageParcel reply;
1651 
1652     NetDiagIfaceConfig config;
1653     config.ifaceName_ = "eth0";
1654     const std::string ifaceName = "eth0";
1655     config.ipv4Addr_ = "192.168.222.234";
1656     config.mtu_ = 1000;
1657     config.ipv4Mask_ = "255.255.255.0";
1658     config.ipv4Bcast_ = "255.255.255.0";
1659     config.txQueueLen_ = 1000;
1660     config.Marshalling(data);
1661     data.WriteString("eth0");
1662     data.WriteBool(true);
1663     int32_t ret = notifyStub_->CmdNetDiagUpdateInterfaceConfig(data, reply);
1664     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1665 }
1666 
1667 HWTEST_F(NetsysNativeServiceStubTest, CmdNetDiagGetInterfaceConfigCommandForResTest001, TestSize.Level1)
1668 {
1669     MessageParcel data;
1670     MessageParcel reply;
1671     data.WriteString("eth0");
1672     int32_t ret = notifyStub_->CmdNetDiagGetInterfaceConfig(data, reply);
1673     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
1674 
1675     MessageParcel data1;
1676     MessageParcel reply1;
1677     data1.WriteString("eth1");
1678     int32_t ret1 = notifyStub_->CmdNetDiagGetInterfaceConfig(data1, reply1);
1679     EXPECT_EQ(ret1, NETMANAGER_SUCCESS);
1680 }
1681 
1682 HWTEST_F(NetsysNativeServiceStubTest, CmdAddStaticArp001, TestSize.Level1)
1683 {
1684     std::string ipAddr = "192.168.1.100";
1685     std::string macAddr = "aa:bb:cc:dd:ee:ff";
1686     std::string ifName = "wlan0";
1687 
1688     MessageParcel data;
1689     if (!data.WriteString(ipAddr)) {
1690         return;
1691     }
1692     if (!data.WriteString(macAddr)) {
1693         return;
1694     }
1695     if (!data.WriteString(ifName)) {
1696         return;
1697     }
1698 
1699     MessageParcel reply;
1700     int32_t ret = notifyStub_->CmdAddStaticArp(data, reply);
1701     EXPECT_EQ(ret, ERR_NONE);
1702 }
1703 
1704 HWTEST_F(NetsysNativeServiceStubTest, CmdDelStaticArp001, TestSize.Level1)
1705 {
1706     std::string ipAddrTest = "192.168.1.100";
1707     std::string macAddrTest = "aa:bb:cc:dd:ee:ff";
1708     std::string ifNameTest = "wlan0";
1709 
1710     MessageParcel data;
1711     if (!data.WriteString(ipAddrTest)) {
1712         return;
1713     }
1714     if (!data.WriteString(macAddrTest)) {
1715         return;
1716     }
1717     if (!data.WriteString(ifNameTest)) {
1718         return;
1719     }
1720 
1721     MessageParcel reply;
1722     auto ret = notifyStub_->CmdDelStaticArp(data, reply);
1723     EXPECT_EQ(ret, ERR_NONE);
1724 }
1725 
1726 HWTEST_F(NetsysNativeServiceStubTest, CmdGetCookieStats001, TestSize.Level1)
1727 {
1728     uint32_t type = 0;
1729     MessageParcel data;
1730     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1731         return;
1732     }
1733     if (!data.WriteUint32(type)) {
1734         return;
1735     }
1736     if (!data.WriteUint64(TEST_COOKIE)) {
1737         return;
1738     }
1739 
1740     MessageParcel reply;
1741     int32_t ret = notifyStub_->CmdGetCookieStats(data, reply);
1742     EXPECT_EQ(ret, ERR_NONE);
1743 }
1744 
1745 HWTEST_F(NetsysNativeServiceStubTest, CmdRegisterDnsResultListener001, TestSize.Level1)
1746 {
1747     MessageParcel data;
1748     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1749         return;
1750     }
1751     sptr<INetDnsResultCallback> callback = new (std::nothrow) TestNetDnsResultCallback();
1752     if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
1753         return;
1754     }
1755     uint32_t timeStep = 1;
1756     if (!data.WriteUint32(timeStep)) {
1757         return;
1758     }
1759     MessageParcel reply;
1760     int32_t ret = notifyStub_->CmdRegisterDnsResultListener(data, reply);
1761     EXPECT_EQ(ret, IPC_STUB_ERR);
1762 }
1763 
1764 HWTEST_F(NetsysNativeServiceStubTest, CmdUnregisterDnsResultListener001, TestSize.Level1)
1765 {
1766     MessageParcel data;
1767     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1768         return;
1769     }
1770     sptr<INetDnsResultCallback> callback = new (std::nothrow) TestNetDnsResultCallback();
1771     if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
1772         return;
1773     }
1774 
1775     MessageParcel reply;
1776     int32_t ret = notifyStub_->CmdUnregisterDnsResultListener(data, reply);
1777     EXPECT_EQ(ret, IPC_STUB_ERR);
1778 }
1779 
1780 HWTEST_F(NetsysNativeServiceStubTest, CmdRegisterDnsHealthListener001, TestSize.Level1)
1781 {
1782     MessageParcel data;
1783     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1784         return;
1785     }
1786     sptr<INetDnsHealthCallback> callback = new (std::nothrow) TestNetDnsHealthCallback();
1787     if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
1788         return;
1789     }
1790 
1791     MessageParcel reply;
1792     int32_t ret = notifyStub_->CmdRegisterDnsHealthListener(data, reply);
1793     EXPECT_EQ(ret, IPC_STUB_ERR);
1794 }
1795 
1796 HWTEST_F(NetsysNativeServiceStubTest, CmdUnregisterDnsHealthListener001, TestSize.Level1)
1797 {
1798     MessageParcel data;
1799     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1800         return;
1801     }
1802     sptr<INetDnsHealthCallback> callback = new (std::nothrow) TestNetDnsHealthCallback();
1803     if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
1804         return;
1805     }
1806 
1807     MessageParcel reply;
1808     int32_t ret = notifyStub_->CmdUnregisterDnsHealthListener(data, reply);
1809     EXPECT_EQ(ret, IPC_STUB_ERR);
1810 }
1811 
1812 HWTEST_F(NetsysNativeServiceStubTest, CmdGetNetworkSharingType001, TestSize.Level1)
1813 {
1814     MessageParcel data;
1815     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1816         return;
1817     }
1818 
1819     MessageParcel reply;
1820     int32_t ret = notifyStub_->CmdGetNetworkSharingType(data, reply);
1821     EXPECT_EQ(ret, ERR_NONE);
1822 }
1823 
1824 HWTEST_F(NetsysNativeServiceStubTest, CmdUpdateNetworkSharingType001, TestSize.Level1)
1825 {
1826     uint32_t type = 0;
1827     bool isOpen = true;
1828     MessageParcel data;
1829     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1830         return;
1831     }
1832     if (!data.WriteUint32(type)) {
1833         return;
1834     }
1835     if (!data.WriteBool(isOpen)) {
1836         return;
1837     }
1838 
1839     MessageParcel reply;
1840     int32_t ret = notifyStub_->CmdUpdateNetworkSharingType(data, reply);
1841     EXPECT_EQ(ret, ERR_NONE);
1842 }
1843 
1844 HWTEST_F(NetsysNativeServiceStubTest, CmdSetIpv6PrivacyExtensions001, TestSize.Level1)
1845 {
1846     std::string interface = "wlan0";
1847 
1848     MessageParcel data;
1849     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1850     return;
1851     }
1852     if (!data.WriteString(interface)) {
1853     return;
1854     }
1855     if (!data.WriteUint32(0)) {
1856     return;
1857     }
1858     MessageParcel reply;
1859     int32_t ret = notifyStub_->CmdSetIpv6PrivacyExtensions(data, reply);
1860     EXPECT_EQ(ret, ERR_NONE);
1861 
1862     ret = notifyStub_->CmdSetIpv6Enable(data, reply);
1863     EXPECT_EQ(ret, ERR_NONE);
1864 }
1865 
1866 HWTEST_F(NetsysNativeServiceStubTest, CmdSetNetworkAccessPolicy001, TestSize.Level1)
1867 {
1868     uint32_t uid = 0;
1869     NetworkAccessPolicy netAccessPolicy;
1870     netAccessPolicy.wifiAllow = false;
1871     netAccessPolicy.cellularAllow = false;
1872     bool reconfirmFlag = true;
1873     bool isBroker = false;
1874     MessageParcel data;
1875     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1876         return;
1877     }
1878     if (!data.WriteUint32(uid)) {
1879         return;
1880     }
1881 
1882     if (!data.WriteUint8(netAccessPolicy.wifiAllow)) {
1883         return;
1884     }
1885 
1886     if (!data.WriteUint8(netAccessPolicy.cellularAllow)) {
1887         return;
1888     }
1889 
1890     if (!data.WriteBool(reconfirmFlag)) {
1891         return;
1892     }
1893 
1894     if (!data.WriteBool(isBroker)) {
1895         return;
1896     }
1897 
1898     MessageParcel reply;
1899     int32_t ret = notifyStub_->CmdSetNetworkAccessPolicy(data, reply);
1900     EXPECT_EQ(ret, ERR_NONE);
1901 }
1902 
1903 HWTEST_F(NetsysNativeServiceStubTest, CmdDeleteNetworkAccessPolicy001, TestSize.Level1)
1904 {
1905     uint32_t uid = 0;
1906     MessageParcel data;
1907     if (!data.WriteInterfaceToken(NetsysNativeServiceStub::GetDescriptor())) {
1908         return;
1909     }
1910     if (!data.WriteUint32(uid)) {
1911         return;
1912     }
1913 
1914     MessageParcel reply;
1915     int32_t ret = notifyStub_->CmdDelNetworkAccessPolicy(data, reply);
1916     EXPECT_EQ(ret, ERR_NONE);
1917 }
1918 
1919 HWTEST_F(NetsysNativeServiceStubTest, CmdNotifyNetBearerTypeChange001, TestSize.Level1)
1920 {
1921     std::set<NetManagerStandard::NetBearType> bearerTypes;
1922     bearerTypes.clear();
1923     bearerTypes.insert(NetManagerStandard::NetBearType::BEARER_CELLULAR);
1924     MessageParcel data;
1925 
1926     uint32_t size = static_cast<uint32_t>(bearerTypes.size());
1927     if (!data.WriteUint32(size)) {
1928         return;
1929     }
1930 
1931     for (auto bearerType : bearerTypes) {
1932         if (!data.WriteUint32(static_cast<uint32_t>(bearerType))) {
1933             return;
1934         }
1935     }
1936 
1937     MessageParcel reply;
1938     int32_t ret = notifyStub_->CmdNotifyNetBearerTypeChange(data, reply);
1939     EXPECT_EQ(ret, ERR_NONE);
1940 }
1941 
1942 HWTEST_F(NetsysNativeServiceStubTest, CmdCreateVnic001, TestSize.Level1)
1943 {
1944     MessageParcel data;
1945     uint16_t mtu = 1500;
1946     std::string tunAddr = "192.168.1.100";
1947     int32_t prefix = 24;
1948     std::set<int32_t> uids;
1949 
1950     if (!data.WriteUint16(mtu)) {
1951         return;
1952     }
1953 
1954     if (!data.WriteString(tunAddr)) {
1955         return;
1956     }
1957 
1958     if (!data.WriteInt32(prefix)) {
1959         return;
1960     }
1961 
1962     if (!data.WriteInt32(uids.size())) {
1963         return;
1964     }
1965 
1966     for (const auto &uid: uids) {
1967         if (!data.WriteInt32(uid)) {
1968             return;
1969         }
1970     }
1971 
1972     MessageParcel reply;
1973     int32_t ret = notifyStub_->CmdCreateVnic(data, reply);
1974     EXPECT_EQ(ret, ERR_NONE);
1975 }
1976 
1977 HWTEST_F(NetsysNativeServiceStubTest, CmdDestroyVnic001, TestSize.Level1)
1978 {
1979     MessageParcel data;
1980     MessageParcel reply;
1981     int32_t ret = notifyStub_->CmdDestroyVnic(data, reply);
1982     EXPECT_EQ(ret, ERR_NONE);
1983 }
1984 } // namespace NetsysNative
1985 } // namespace OHOS
1986