• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "net_stats_info.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 constexpr int64_t TEST_RXBYTES = 15453;
24 constexpr int64_t TEST_TXBYTES = 45115;
25 constexpr int64_t TEST_RXPACKETS = 5646894;
26 constexpr int64_t TEST_TXPACKETS = 7894;
GetNetStatsInfoData()27 NetStatsInfo GetNetStatsInfoData()
28 {
29     NetStatsInfo info;
30     info.rxBytes_ = TEST_RXBYTES;
31     info.rxPackets_ = TEST_RXPACKETS;
32     info.txBytes_ = TEST_TXBYTES;
33     info.txPackets_ = TEST_TXPACKETS;
34     return info;
35 }
36 } // namespace
37 
38 using namespace testing::ext;
39 class NetStatsInfoTest : public testing::Test {
40 public:
41     static void SetUpTestCase();
42     static void TearDownTestCase();
43     void SetUp();
44     void TearDown();
45     uint32_t GetTestTime();
46 };
47 
SetUpTestCase()48 void NetStatsInfoTest::SetUpTestCase() {}
49 
TearDownTestCase()50 void NetStatsInfoTest::TearDownTestCase() {}
51 
SetUp()52 void NetStatsInfoTest::SetUp() {}
53 
TearDown()54 void NetStatsInfoTest::TearDown() {}
55 
56 /**
57  * @tc.name: MarshallingTest001
58  * @tc.desc: Test NetStatsInfo Marshalling.
59  * @tc.type: FUNC
60  */
61 HWTEST_F(NetStatsInfoTest, MarshallingTest001, TestSize.Level1)
62 {
63     Parcel parcel;
64     NetStatsInfo info = GetNetStatsInfoData();
65     EXPECT_TRUE(info.Marshalling(parcel));
66     NetStatsInfo result;
67     EXPECT_TRUE(NetStatsInfo::Unmarshalling(parcel, result));
68     EXPECT_EQ(result.rxBytes_, info.rxBytes_);
69     EXPECT_EQ(result.txBytes_, info.txBytes_);
70     EXPECT_EQ(result.rxPackets_, info.rxPackets_);
71     EXPECT_EQ(result.txPackets_, info.txPackets_);
72 }
73 
74 /**
75  * @tc.name: MarshallingTest002
76  * @tc.desc: Test NetStatsInfo Marshalling.
77  * @tc.type: FUNC
78  */
79 HWTEST_F(NetStatsInfoTest, MarshallingUnmarshallingTest002, TestSize.Level1)
80 {
81     Parcel parcel;
82     NetStatsInfo info = GetNetStatsInfoData();
83     EXPECT_TRUE(NetStatsInfo::Marshalling(parcel, info));
84     NetStatsInfo result;
85     EXPECT_TRUE(NetStatsInfo::Unmarshalling(parcel, result));
86     EXPECT_EQ(result.rxBytes_, info.rxBytes_);
87     EXPECT_EQ(result.txBytes_, info.txBytes_);
88     EXPECT_EQ(result.rxPackets_, info.rxPackets_);
89     EXPECT_EQ(result.txPackets_, info.txPackets_);
90 }
91 
92 /**
93  * @tc.name: MarshallingUnmarshallingTest003
94  * @tc.desc: Test NetStatsInfo Marshalling.
95  * @tc.type: FUNC
96  */
97 HWTEST_F(NetStatsInfoTest, MarshallingUnmarshallingTest003, TestSize.Level1)
98 {
99     Parcel parcel;
100     std::vector<NetStatsInfo> statsInfos;
101     NetStatsInfo infoa = GetNetStatsInfoData();
102     statsInfos.push_back(infoa);
103     NetStatsInfo infob = GetNetStatsInfoData();
104     statsInfos.push_back(infob);
105 
106     EXPECT_TRUE(NetStatsInfo::Marshalling(parcel, statsInfos));
107     std::vector<NetStatsInfo> results;
108     EXPECT_TRUE(NetStatsInfo::Unmarshalling(parcel, results));
109 }
110 
111 /**
112  * @tc.name: NetStatsInfoOperator
113  * @tc.desc: Test NetStatsInfo Operator.
114  * @tc.type: FUNC
115  */
116 HWTEST_F(NetStatsInfoTest, NetStatsInfoOperator, TestSize.Level1)
117 {
118     NetStatsInfo infoa = GetNetStatsInfoData();
119     NetStatsInfo infob = GetNetStatsInfoData();
120     NetStatsInfo infoc = infoa - infob;
121     EXPECT_EQ(infoc.rxBytes_, 0);
122     infoc += infoa;
123     EXPECT_EQ(infoc.rxBytes_, infoa.rxBytes_);
124 }
125 } // namespace NetManagerStandard
126 } // namespace OHOS
127