• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "net_push_stats_info.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 constexpr int32_t TEST_UID = 20011212;
24 constexpr int32_t TEST_SIM_ID = 1;
25 constexpr int32_t TEST_TYPE = 0;
26 constexpr int32_t TEST_BEGIN_TIME = 179122111;
27 constexpr int32_t TEST_END_TIME = 179123233;
28 constexpr int32_t TEST_RX_BYTES = 7894;
29 constexpr int32_t TEST_TX_BYTES = 8923;
GetPushStatsInfo()30 PushStatsInfo GetPushStatsInfo()
31 {
32     PushStatsInfo info;
33     info.uid_ = TEST_UID;
34     info.simId_ = TEST_SIM_ID;
35     info.netBearType_ = TEST_TYPE;
36     info.beginTime_ = TEST_BEGIN_TIME;
37     info.endTime_ = TEST_END_TIME;
38     info.rxBytes_ = TEST_RX_BYTES;
39     info.txBytes_ = TEST_TX_BYTES;
40     return info;
41 }
42 } // namespace
43 
44 using namespace testing::ext;
45 class PushStatsInfoTest : public testing::Test {
46 public:
47     static void SetUpTestCase();
48     static void TearDownTestCase();
49     void SetUp();
50     void TearDown();
51     uint32_t GetTestTime();
52 };
53 
SetUpTestCase()54 void PushStatsInfoTest::SetUpTestCase() {}
55 
TearDownTestCase()56 void PushStatsInfoTest::TearDownTestCase() {}
57 
SetUp()58 void PushStatsInfoTest::SetUp() {}
59 
TearDown()60 void PushStatsInfoTest::TearDown() {}
61 
62 /**
63  * @tc.name: MarshallingUnmarshallingTest001
64  * @tc.desc: Test NetStatsInfo Marshalling and Unmarshalling.
65  * @tc.type: FUNC
66  */
67 HWTEST_F(PushStatsInfoTest, MarshallingUnmarshallingTest001, TestSize.Level1)
68 {
69     Parcel parcel;
70     PushStatsInfo info = GetPushStatsInfo();
71     EXPECT_TRUE(info.Marshalling(parcel));
72     PushStatsInfo result;
73     EXPECT_TRUE(PushStatsInfo::Unmarshalling(parcel, result));
74     EXPECT_EQ(result.uid_, info.uid_);
75     EXPECT_EQ(result.iface_, info.iface_);
76     EXPECT_EQ(result.simId_, info.simId_);
77     EXPECT_EQ(result.netBearType_, info.netBearType_);
78     EXPECT_EQ(result.beginTime_, info.beginTime_);
79     EXPECT_EQ(result.endTime_, info.endTime_);
80     EXPECT_EQ(result.rxBytes_, info.rxBytes_);
81     EXPECT_EQ(result.txBytes_, info.txBytes_);
82 }
83 
84 /**
85  * @tc.name: MarshallingUnmarshallingTest002
86  * @tc.desc: Test NetStatsInfo Marshalling and Unmarshalling.
87  * @tc.type: FUNC
88  */
89 HWTEST_F(PushStatsInfoTest, MarshallingUnmarshallingTest002, TestSize.Level1)
90 {
91     Parcel parcel;
92     PushStatsInfo info = GetPushStatsInfo();
93     EXPECT_TRUE(PushStatsInfo::Marshalling(parcel, info));
94     PushStatsInfo result;
95     EXPECT_TRUE(PushStatsInfo::Unmarshalling(parcel, result));
96     EXPECT_EQ(result.uid_, info.uid_);
97     EXPECT_EQ(result.iface_, info.iface_);
98     EXPECT_EQ(result.simId_, info.simId_);
99     EXPECT_EQ(result.netBearType_, info.netBearType_);
100     EXPECT_EQ(result.beginTime_, info.beginTime_);
101     EXPECT_EQ(result.endTime_, info.endTime_);
102     EXPECT_EQ(result.rxBytes_, info.rxBytes_);
103     EXPECT_EQ(result.txBytes_, info.txBytes_);
104 }
105 } // namespace NetManagerStandard
106 } // namespace OHOS