• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <iostream>
18 
19 #ifdef GTEST_API_
20 #define private public
21 #define protected public
22 #endif
23 
24 #include "common_net_stats_callback_test.h"
25 #include "i_net_stats_callback.h"
26 #include "net_all_capabilities.h"
27 #include "net_push_stats_info.h"
28 #include "net_stats_info_sequence.h"
29 #include "net_stats_network.h"
30 #include "net_stats_service_stub.h"
31 #include "netmanager_base_test_security.h"
32 
33 namespace OHOS {
34 namespace NetManagerStandard {
35 using namespace testing::ext;
36 namespace {
37 constexpr uint64_t OUTOFFRANGECODE = 100;
38 constexpr uint32_t TEST_UINT32_VALUE = 100;
39 constexpr uint64_t TEST_UINT64_VALUE = 100;
40 constexpr const char *TEST_STRING = "test";
41 
42 constexpr uint32_t TEST_UID = 1001;
43 constexpr int32_t TEST_TYPE = 0;
44 constexpr int32_t TEST_SIM_ID = 1;
45 constexpr int64_t TEST_START_TIME = 100;
46 constexpr int64_t TEST_END_TIME = 200;
47 
GetSptrNetworkData()48 sptr<NetStatsNetwork> GetSptrNetworkData()
49 {
50     sptr<NetStatsNetwork> network = new (std::nothrow) NetStatsNetwork();
51     network->type_ = TEST_TYPE;
52     network->startTime_ = TEST_START_TIME;
53     network->endTime_ = TEST_END_TIME;
54     network->simId_ = TEST_SIM_ID;
55     return network;
56 }
57 
58 class MockNetStatsServiceStub : public NetStatsServiceStub {
59 public:
60     MockNetStatsServiceStub() = default;
~MockNetStatsServiceStub()61     ~MockNetStatsServiceStub() {}
62 
GetIfaceRxBytes(uint64_t & stats,const std::string & interfaceName)63     int32_t GetIfaceRxBytes(uint64_t &stats, const std::string &interfaceName) override
64     {
65         return 0;
66     }
67 
GetIfaceTxBytes(uint64_t & stats,const std::string & interfaceName)68     int32_t GetIfaceTxBytes(uint64_t &stats, const std::string &interfaceName) override
69     {
70         return 0;
71     }
72 
GetCellularRxBytes(uint64_t & stats)73     int32_t GetCellularRxBytes(uint64_t &stats) override
74     {
75         return 0;
76     }
77 
GetCellularTxBytes(uint64_t & stats)78     int32_t GetCellularTxBytes(uint64_t &stats) override
79     {
80         return 0;
81     }
82 
GetAllRxBytes(uint64_t & stats)83     int32_t GetAllRxBytes(uint64_t &stats) override
84     {
85         return 0;
86     }
87 
GetAllTxBytes(uint64_t & stats)88     int32_t GetAllTxBytes(uint64_t &stats) override
89     {
90         return 0;
91     }
92 
GetUidRxBytes(uint64_t & stats,uint32_t uid)93     int32_t GetUidRxBytes(uint64_t &stats, uint32_t uid) override
94     {
95         return 0;
96     }
97 
GetUidTxBytes(uint64_t & stats,uint32_t uid)98     int32_t GetUidTxBytes(uint64_t &stats, uint32_t uid) override
99     {
100         return 0;
101     }
102 
GetAllStatsInfo(std::vector<NetStatsInfo> & info)103     int32_t GetAllStatsInfo(std::vector<NetStatsInfo> &info) override
104     {
105         return 0;
106     }
107 
GetAllSimStatsInfo(std::vector<NetStatsInfo> & infos)108     int32_t GetAllSimStatsInfo(std::vector<NetStatsInfo> &infos) override
109     {
110         return 0;
111     }
112 
GetTrafficStatsByNetwork(std::unordered_map<uint32_t,NetStatsInfo> & infos,const sptr<NetStatsNetwork> & network)113     int32_t GetTrafficStatsByNetwork(std::unordered_map<uint32_t, NetStatsInfo> &infos,
114                                      const sptr<NetStatsNetwork> &network) override
115     {
116         return 0;
117     }
118 
GetTrafficStatsByUidNetwork(std::vector<NetStatsInfoSequence> & infos,uint32_t uid,const sptr<NetStatsNetwork> & network)119     int32_t GetTrafficStatsByUidNetwork(std::vector<NetStatsInfoSequence> &infos, uint32_t uid,
120                                         const sptr<NetStatsNetwork> &network) override
121     {
122         return 0;
123     }
124 
SetAppStats(const PushStatsInfo & info)125     int32_t SetAppStats(const PushStatsInfo &info) override
126     {
127         return 0;
128     }
129 
RegisterNetStatsCallback(const sptr<INetStatsCallback> & callback)130     int32_t RegisterNetStatsCallback(const sptr<INetStatsCallback> &callback) override
131     {
132         return 0;
133     }
134 
UnregisterNetStatsCallback(const sptr<INetStatsCallback> & callback)135     int32_t UnregisterNetStatsCallback(const sptr<INetStatsCallback> &callback) override
136     {
137         return 0;
138     }
139 
GetIfaceStatsDetail(const std::string & iface,uint64_t start,uint64_t end,NetStatsInfo & statsInfo)140     int32_t GetIfaceStatsDetail(const std::string &iface, uint64_t start, uint64_t end,
141                                 NetStatsInfo &statsInfo) override
142     {
143         return 0;
144     }
145 
GetUidStatsDetail(const std::string & iface,uint32_t uid,uint64_t start,uint64_t end,NetStatsInfo & statsInfo)146     int32_t GetUidStatsDetail(const std::string &iface, uint32_t uid, uint64_t start, uint64_t end,
147                               NetStatsInfo &statsInfo) override
148     {
149         return 0;
150     }
151 
UpdateIfacesStats(const std::string & iface,uint64_t start,uint64_t end,const NetStatsInfo & stats)152     int32_t UpdateIfacesStats(const std::string &iface, uint64_t start, uint64_t end,
153                                       const NetStatsInfo &stats) override
154     {
155         return 0;
156     }
157 
UpdateStatsData()158     int32_t UpdateStatsData() override
159     {
160         return 0;
161     }
162 
ResetFactory()163     int32_t ResetFactory() override
164     {
165         return 0;
166     }
167 
GetCookieRxBytes(uint64_t & stats,uint64_t cookie)168     int32_t GetCookieRxBytes(uint64_t &stats, uint64_t cookie) override
169     {
170         return 0;
171     }
172 
GetCookieTxBytes(uint64_t & stats,uint64_t cookie)173     int32_t GetCookieTxBytes(uint64_t &stats, uint64_t cookie) override
174     {
175         return 0;
176     }
177 };
178 
179 class TestNetStatsServiceStub : public testing::Test {
180 public:
181     static void SetUpTestCase();
182     static void TearDownTestCase();
183     void SetUp();
184     void TearDown();
185 
186     static inline std::shared_ptr<NetStatsServiceStub> instance_ = std::make_shared<MockNetStatsServiceStub>();
187 };
188 
SetUpTestCase()189 void TestNetStatsServiceStub::SetUpTestCase() {}
190 
TearDownTestCase()191 void TestNetStatsServiceStub::TearDownTestCase() {}
192 
SetUp()193 void TestNetStatsServiceStub::SetUp() {}
194 
TearDown()195 void TestNetStatsServiceStub::TearDown() {}
196 
197 /**
198  * @tc.name: OnRemoteRequestTest001
199  * @tc.desc: Test NetConnCallbackStub OnRemoteRequest.
200  * @tc.type: FUNC
201  */
202 HWTEST_F(TestNetStatsServiceStub, OnRemoteRequestTest001, TestSize.Level1)
203 {
204     MessageParcel data;
205     MessageParcel reply;
206     MessageOption option;
207     int32_t ret = instance_->OnRemoteRequest(OUTOFFRANGECODE, data, reply, option);
208     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_ERR_DESCRIPTOR_MISMATCH);
209 }
210 
211 /**
212  * @tc.name: RegisterNetStatsCallbackTest001
213  * @tc.desc: Test NetConnCallbackStub RegisterNetStatsCallback.
214  * @tc.type: FUNC
215  */
216 HWTEST_F(TestNetStatsServiceStub, RegisterNetStatsCallbackTest001, TestSize.Level1)
217 {
218     NetManagerBaseAccessToken token;
219     MessageParcel data;
220     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
221         return;
222     }
223     sptr<INetStatsCallback> callback = new (std::nothrow) NetStatsCallbackTestCb();
224     if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
225         return;
226     }
227     MessageParcel reply;
228     MessageOption option;
229     int32_t ret = instance_->OnRemoteRequest(
230         static_cast<uint32_t>(StatsInterfaceCode::CMD_NSM_REGISTER_NET_STATS_CALLBACK), data, reply, option);
231     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
232 }
233 
234 /**
235  * @tc.name: UnregisterNetStatsCallbackTest001
236  * @tc.desc: Test NetConnCallbackStub UnregisterNetStatsCallback.
237  * @tc.type: FUNC
238  */
239 HWTEST_F(TestNetStatsServiceStub, UnregisterNetStatsCallbackTest001, TestSize.Level1)
240 {
241     NetManagerBaseAccessToken token;
242     MessageParcel data;
243     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
244         return;
245     }
246     sptr<INetStatsCallback> callback = new (std::nothrow) NetStatsCallbackTestCb();
247     if (!data.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
248         return;
249     }
250     MessageParcel reply;
251     MessageOption option;
252     int32_t ret = instance_->OnRemoteRequest(
253         static_cast<uint32_t>(StatsInterfaceCode::CMD_NSM_UNREGISTER_NET_STATS_CALLBACK), data, reply, option);
254     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
255 }
256 
257 /**
258  * @tc.name: GetIfaceRxBytesTest001
259  * @tc.desc: Test NetConnCallbackStub GetIfaceRxBytes.
260  * @tc.type: FUNC
261  */
262 HWTEST_F(TestNetStatsServiceStub, GetIfaceRxBytesTest001, TestSize.Level1)
263 {
264     MessageParcel data;
265     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
266         return;
267     }
268     if (!data.WriteString(TEST_STRING)) {
269         return;
270     }
271     MessageParcel reply;
272     MessageOption option;
273     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_IFACE_RXBYTES), data,
274                                              reply, option);
275     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
276 }
277 
278 /**
279  * @tc.name: GetIfaceTxBytesTest001
280  * @tc.desc: Test NetConnCallbackStub GetIfaceTxBytes.
281  * @tc.type: FUNC
282  */
283 HWTEST_F(TestNetStatsServiceStub, GetIfaceTxBytesTest001, TestSize.Level1)
284 {
285     MessageParcel data;
286     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
287         return;
288     }
289     if (!data.WriteString(TEST_STRING)) {
290         return;
291     }
292     MessageParcel reply;
293     MessageOption option;
294     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_IFACE_TXBYTES), data,
295                                              reply, option);
296     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
297 }
298 
299 /**
300  * @tc.name: GetCellularRxBytesTest001
301  * @tc.desc: Test NetConnCallbackStub GetCellularRxBytes.
302  * @tc.type: FUNC
303  */
304 HWTEST_F(TestNetStatsServiceStub, GetCellularRxBytesTest001, TestSize.Level1)
305 {
306     MessageParcel data;
307     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
308         return;
309     }
310     MessageParcel reply;
311     MessageOption option;
312     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_CELLULAR_RXBYTES), data,
313                                              reply, option);
314     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
315 }
316 
317 /**
318  * @tc.name: GetCellularTxBytesTest001
319  * @tc.desc: Test NetConnCallbackStub GetCellularTxBytes.
320  * @tc.type: FUNC
321  */
322 HWTEST_F(TestNetStatsServiceStub, GetCellularTxBytesTest001, TestSize.Level1)
323 {
324     MessageParcel data;
325     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
326         return;
327     }
328     MessageParcel reply;
329     MessageOption option;
330     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_CELLULAR_TXBYTES), data,
331                                              reply, option);
332     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
333 }
334 
335 /**
336  * @tc.name: GetAllRxBytesTest001
337  * @tc.desc: Test NetConnCallbackStub GetAllRxBytes.
338  * @tc.type: FUNC
339  */
340 HWTEST_F(TestNetStatsServiceStub, GetAllRxBytesTest001, TestSize.Level1)
341 {
342     MessageParcel data;
343     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
344         return;
345     }
346     MessageParcel reply;
347     MessageOption option;
348     int32_t ret =
349         instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_ALL_RXBYTES), data, reply, option);
350     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
351 }
352 
353 /**
354  * @tc.name: GetAllTxBytesTest001
355  * @tc.desc: Test NetConnCallbackStub GetAllTxBytes.
356  * @tc.type: FUNC
357  */
358 HWTEST_F(TestNetStatsServiceStub, GetAllTxBytesTest001, TestSize.Level1)
359 {
360     MessageParcel data;
361     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
362         return;
363     }
364     MessageParcel reply;
365     MessageOption option;
366     int32_t ret =
367         instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_ALL_TXBYTES), data, reply, option);
368     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
369 }
370 
371 /**
372  * @tc.name: GetUidRxBytesTest001
373  * @tc.desc: Test NetConnCallbackStub GetUidRxBytes.
374  * @tc.type: FUNC
375  */
376 HWTEST_F(TestNetStatsServiceStub, GetUidRxBytesTest001, TestSize.Level1)
377 {
378     MessageParcel data;
379     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
380         return;
381     }
382     if (!data.WriteUint32(TEST_UINT32_VALUE)) {
383         return;
384     }
385     MessageParcel reply;
386     MessageOption option;
387     int32_t ret =
388         instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_UID_RXBYTES), data, reply, option);
389     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
390 }
391 
392 /**
393  * @tc.name: GetUidTxBytesTest001
394  * @tc.desc: Test NetConnCallbackStub GetUidTxBytes.
395  * @tc.type: FUNC
396  */
397 HWTEST_F(TestNetStatsServiceStub, GetUidTxBytesTest001, TestSize.Level1)
398 {
399     MessageParcel data;
400     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
401         return;
402     }
403     if (!data.WriteUint32(TEST_UINT32_VALUE)) {
404         return;
405     }
406     MessageParcel reply;
407     MessageOption option;
408     int32_t ret =
409         instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_UID_TXBYTES), data, reply, option);
410     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
411 }
412 
413 /**
414  * @tc.name: GetIfaceStatsDetailTest001
415  * @tc.desc: Test NetConnCallbackStub GetIfaceStatsDetail.
416  * @tc.type: FUNC
417  */
418 HWTEST_F(TestNetStatsServiceStub, GetIfaceStatsDetailTest001, TestSize.Level1)
419 {
420     NetManagerBaseAccessToken token;
421     MessageParcel data;
422     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
423         return;
424     }
425     if (!data.WriteString(TEST_STRING)) {
426         return;
427     }
428     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
429         return;
430     }
431     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
432         return;
433     }
434     MessageParcel reply;
435     MessageOption option;
436     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_IFACE_STATS_DETAIL),
437                                              data, reply, option);
438     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
439 }
440 
441 /**
442  * @tc.name: GetUidStatsDetailTest001
443  * @tc.desc: Test NetConnCallbackStub GetUidStatsDetail.
444  * @tc.type: FUNC
445  */
446 HWTEST_F(TestNetStatsServiceStub, GetUidStatsDetailTest001, TestSize.Level1)
447 {
448     NetManagerBaseAccessToken token;
449     MessageParcel data;
450     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
451         return;
452     }
453     if (!data.WriteString(TEST_STRING)) {
454         return;
455     }
456     if (!data.WriteUint32(TEST_UINT32_VALUE)) {
457         return;
458     }
459     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
460         return;
461     }
462     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
463         return;
464     }
465     MessageParcel reply;
466     MessageOption option;
467     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_UID_STATS_DETAIL), data,
468                                              reply, option);
469     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
470 }
471 
472 /**
473  * @tc.name: UpdateIfacesStatsTest001
474  * @tc.desc: Test NetConnCallbackStub UpdateIfacesStats.
475  * @tc.type: FUNC
476  */
477 HWTEST_F(TestNetStatsServiceStub, UpdateIfacesStatsTest001, TestSize.Level1)
478 {
479     NetManagerBaseAccessToken token;
480     MessageParcel data;
481     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
482         return;
483     }
484     if (!data.WriteString(TEST_STRING)) {
485         return;
486     }
487     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
488         return;
489     }
490     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
491         return;
492     }
493     NetStatsInfo stats;
494     stats.Marshalling(data);
495     MessageParcel reply;
496     MessageOption option;
497     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_UPDATE_IFACES_STATS), data,
498                                              reply, option);
499     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
500 }
501 
502 /**
503  * @tc.name: UpdateIfacesStatsTest002
504  * @tc.desc: Test NetConnCallbackStub UpdateIfacesStats.
505  * @tc.type: FUNC
506  */
507 HWTEST_F(TestNetStatsServiceStub, UpdateIfacesStatsTest002, TestSize.Level1)
508 {
509     NetManagerBaseNotSystemToken token;
510     MessageParcel data;
511     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
512         return;
513     }
514     if (!data.WriteString(TEST_STRING)) {
515         return;
516     }
517     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
518         return;
519     }
520     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
521         return;
522     }
523     NetStatsInfo stats;
524     stats.Marshalling(data);
525     MessageParcel reply;
526     MessageOption option;
527     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_UPDATE_IFACES_STATS), data,
528                                              reply, option);
529     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_ERR_NOT_SYSTEM_CALL);
530 }
531 
532 /**
533  * @tc.name: UpdateIfacesStatsTest003
534  * @tc.desc: Test NetConnCallbackStub UpdateIfacesStats.
535  * @tc.type: FUNC
536  */
537 HWTEST_F(TestNetStatsServiceStub, UpdateIfacesStatsTest003, TestSize.Level1)
538 {
539     NetManagerBaseNoPermissionToken token;
540     MessageParcel data;
541     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
542         return;
543     }
544     if (!data.WriteString(TEST_STRING)) {
545         return;
546     }
547     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
548         return;
549     }
550     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
551         return;
552     }
553     NetStatsInfo stats;
554     stats.Marshalling(data);
555     MessageParcel reply;
556     MessageOption option;
557     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_UPDATE_IFACES_STATS), data,
558                                              reply, option);
559     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_ERR_PERMISSION_DENIED);
560 }
561 
562 /**
563  * @tc.name: ResetFactoryTest001
564  * @tc.desc: Test NetConnCallbackStub ResetFactory.
565  * @tc.type: FUNC
566  */
567 HWTEST_F(TestNetStatsServiceStub, ResetFactoryTest001, TestSize.Level1)
568 {
569     NetManagerBaseAccessToken token;
570     MessageParcel data;
571     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
572         return;
573     }
574     MessageParcel reply;
575     MessageOption option;
576     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_NSM_RESET_FACTORY), data,
577                                              reply, option);
578     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
579 }
580 
581 /**
582  * @tc.name: ResetFactoryTest002
583  * @tc.desc: Test NetConnCallbackStub ResetFactory.
584  * @tc.type: FUNC
585  */
586 HWTEST_F(TestNetStatsServiceStub, ResetFactoryTest002, TestSize.Level1)
587 {
588     NetManagerBaseNotSystemToken token;
589     MessageParcel data;
590     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
591         return;
592     }
593     MessageParcel reply;
594     MessageOption option;
595     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_NSM_RESET_FACTORY), data,
596                                              reply, option);
597     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_ERR_NOT_SYSTEM_CALL);
598 }
599 
600 /**
601  * @tc.name: ResetFactoryTest003
602  * @tc.desc: Test NetConnCallbackStub ResetFactory.
603  * @tc.type: FUNC
604  */
605 HWTEST_F(TestNetStatsServiceStub, ResetFactoryTest003, TestSize.Level1)
606 {
607     NetManagerBaseNoPermissionToken token;
608     MessageParcel data;
609     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
610         return;
611     }
612     MessageParcel reply;
613     MessageOption option;
614     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_NSM_RESET_FACTORY), data,
615                                              reply, option);
616     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_ERR_PERMISSION_DENIED);
617 }
618 
619 /**
620  * @tc.name: GetAllStatsInfoTest001
621  * @tc.desc: Test NetConnCallbackStub GetAllStatsInfo.
622  * @tc.type: FUNC
623  */
624 HWTEST_F(TestNetStatsServiceStub, GetAllStatsInfoTest001, TestSize.Level1)
625 {
626     NetManagerBaseAccessToken token;
627     MessageParcel data;
628     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
629         return;
630     }
631     MessageParcel reply;
632     MessageOption option;
633     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_ALL_STATS_INFO), data,
634                                              reply, option);
635     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
636 }
637 
638 /**
639  * @tc.name: GetAllSimStatsInfoTest001
640  * @tc.desc: Test NetConnCallbackStub GetAllSimStatsInfo.
641  * @tc.type: FUNC
642  */
643 HWTEST_F(TestNetStatsServiceStub, GetAllSimStatsInfoTest001, TestSize.Level1)
644 {
645     NetManagerBaseAccessToken token;
646     MessageParcel data;
647     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
648         return;
649     }
650     MessageParcel reply;
651     MessageOption option;
652     int32_t ret = instance_->OnRemoteRequest(
653         static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_ALL_SIM_STATS_INFO), data, reply, option);
654     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
655 }
656 
657 /**
658  * @tc.name: GetTrafficStatsByNetworkTest001
659  * @tc.desc: Test NetStatsServiceStub GetTrafficStatsByNetwork.
660  * @tc.type: FUNC
661  */
662 HWTEST_F(TestNetStatsServiceStub, GetTrafficStatsByNetworkTest001, TestSize.Level1)
663 {
664     NetManagerBaseAccessToken token;
665     MessageParcel data;
666     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
667         return;
668     }
669     sptr<NetStatsNetwork> network = GetSptrNetworkData();
670     if (!network->Marshalling(data)) {
671         return;
672     }
673     MessageParcel reply;
674     MessageOption option;
675     int32_t ret = instance_->OnRemoteRequest(
676         static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_TRAFFIC_STATS_BY_NETWORK), data, reply, option);
677     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
678 }
679 
680 /**
681  * @tc.name: GetTrafficStatsByUidNetworkTest001
682  * @tc.desc: Test NetStatsServiceStub GetTrafficStatsByUidNetwork.
683  * @tc.type: FUNC
684  */
685 HWTEST_F(TestNetStatsServiceStub, GetTrafficStatsByUidNetworkTest001, TestSize.Level1)
686 {
687     NetManagerBaseAccessToken token;
688     MessageParcel data;
689     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
690         return;
691     }
692     uint32_t uid = TEST_UID;
693     if (!data.WriteUint32(uid)) {
694         return;
695     }
696     sptr<NetStatsNetwork> network = GetSptrNetworkData();
697     if (!network->Marshalling(data)) {
698         return;
699     }
700     MessageParcel reply;
701     MessageOption option;
702     int32_t ret = instance_->OnRemoteRequest(
703         static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_TRAFFIC_STATS_BY_UID_NETWORK), data, reply, option);
704     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
705 }
706 
707 /**
708  * @tc.name: SetAppStats001
709  * @tc.desc: Test NetStatsServiceStub SetAppStats.
710  * @tc.type: FUNC
711  */
712 HWTEST_F(TestNetStatsServiceStub, SetAppStats001, TestSize.Level1)
713 {
714     NetManagerBaseAccessToken token;
715     MessageParcel data;
716     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
717         return;
718     }
719     PushStatsInfo info;
720     if (!info.Marshalling(data)) {
721         return;
722     }
723     MessageParcel reply;
724     MessageOption option;
725     int32_t ret =
726         instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_SET_APP_STATS), data, reply, option);
727     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
728 }
729 
730 /**
731  * @tc.name: GetCookieRxBytesTest001
732  * @tc.desc: Test NetConnCallbackStub GetCookieRxBytes.
733  * @tc.type: FUNC
734  */
735 HWTEST_F(TestNetStatsServiceStub, GetCookieRxBytesTest001, TestSize.Level1)
736 {
737     MessageParcel data;
738     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
739         return;
740     }
741     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
742         return;
743     }
744     MessageParcel reply;
745     MessageOption option;
746     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_COOKIE_RXBYTES), data,
747                                              reply, option);
748     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
749 }
750 
751 /**
752  * @tc.name: GetCookieTxBytesTest001
753  * @tc.desc: Test NetConnCallbackStub GetCookieTxBytes.
754  * @tc.type: FUNC
755  */
756 HWTEST_F(TestNetStatsServiceStub, GetCookieTxBytesTest001, TestSize.Level1)
757 {
758     MessageParcel data;
759     if (!data.WriteInterfaceToken(NetStatsServiceStub::GetDescriptor())) {
760         return;
761     }
762     if (!data.WriteUint64(TEST_UINT64_VALUE)) {
763         return;
764     }
765     MessageParcel reply;
766     MessageOption option;
767     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_COOKIE_TXBYTES), data,
768                                              reply, option);
769     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
770 }
771 } // namespace
772 } // namespace NetManagerStandard
773 } // namespace OHOS