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_stats_network.h"
19
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 constexpr int32_t TEST_TYPE = 0;
24 constexpr int32_t TEST_SIM_ID = 1;
25 constexpr int64_t TEST_START_TIME = 100;
26 constexpr int64_t TEST_END_TIME = 200;
GetNetworkData()27 NetStatsNetwork GetNetworkData()
28 {
29 NetStatsNetwork network;
30 network.type_ = TEST_TYPE;
31 network.startTime_ = TEST_START_TIME;
32 network.endTime_ = TEST_END_TIME;
33 network.simId_ = TEST_SIM_ID;
34 return network;
35 }
GetSptrNetworkData()36 sptr<NetStatsNetwork> GetSptrNetworkData()
37 {
38 sptr<NetStatsNetwork> network = new (std::nothrow) NetStatsNetwork();
39 network->type_ = TEST_TYPE;
40 network->startTime_ = TEST_START_TIME;
41 network->endTime_ = TEST_END_TIME;
42 network->simId_ = TEST_SIM_ID;
43 return network;
44 }
45 } // namespace
46
47 using namespace testing::ext;
48 class NetStatsNetworkTest : public testing::Test {
49 public:
50 static void SetUpTestCase();
51 static void TearDownTestCase();
52 void SetUp();
53 void TearDown();
54 uint32_t GetTestTime();
55 };
56
SetUpTestCase()57 void NetStatsNetworkTest::SetUpTestCase() {}
58
TearDownTestCase()59 void NetStatsNetworkTest::TearDownTestCase() {}
60
SetUp()61 void NetStatsNetworkTest::SetUp() {}
62
TearDown()63 void NetStatsNetworkTest::TearDown() {}
64
65 HWTEST_F(NetStatsNetworkTest, MarshallingAndUnmarshallingTest001, TestSize.Level1)
66 {
67 Parcel parcel;
68 NetStatsNetwork info = GetNetworkData();
69 EXPECT_TRUE(info.Marshalling(parcel));
70 sptr<NetStatsNetwork> result = NetStatsNetwork::Unmarshalling(parcel);
71 EXPECT_EQ(result->type_, info.type_);
72 EXPECT_EQ(result->startTime_, info.startTime_);
73 EXPECT_EQ(result->endTime_, info.endTime_);
74 EXPECT_EQ(result->simId_, info.simId_);
75 }
76
77 HWTEST_F(NetStatsNetworkTest, MarshallingAndUnmarshallingTest002, TestSize.Level1)
78 {
79 Parcel parcel;
80 sptr<NetStatsNetwork> info = GetSptrNetworkData();
81 EXPECT_TRUE(NetStatsNetwork::Marshalling(parcel, info));
82 sptr<NetStatsNetwork> result = NetStatsNetwork::Unmarshalling(parcel);
83 EXPECT_EQ(result->type_, info->type_);
84 EXPECT_EQ(result->startTime_, info->startTime_);
85 EXPECT_EQ(result->endTime_, info->endTime_);
86 EXPECT_EQ(result->simId_, info->simId_);
87 }
88
89 } // namespace NetManagerStandard
90 } // namespace OHOS