• 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 "stats_client_test_mock_object.h"
17 #include "stats_log.h"
18 
19 #include "battery_stats_proxy.h"
20 #include "mock_stats_remote_object.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::PowerMgr;
24 using namespace OHOS;
25 using namespace std;
26 
27 namespace {
28 /**
29  * @tc.name: StatsClientTestMockObject_001
30  * @tc.desc: test BatteryStatsProxy function(IRemoteObject is mock, "SendRequest" function return false)
31  * @tc.type: FUNC
32  * @tc.require: issueI5X13X
33  */
34 HWTEST_F (StatsClientTestMockObject, StatsClientTestMockObject_001, TestSize.Level0)
35 {
36     STATS_HILOGI(LABEL_TEST, "StatsClientTestMockObject_001 start");
37     sptr<MockStatsRemoteObject> sptrRemoteObj = new MockStatsRemoteObject();
38     EXPECT_TRUE(sptrRemoteObj != nullptr);
39     std::shared_ptr<BatteryStatsProxy> sptrStatsProxy = std::make_shared<BatteryStatsProxy>(sptrRemoteObj);
40     EXPECT_TRUE(sptrStatsProxy != nullptr);
41     sptrStatsProxy->ResetIpc();
42     sptrStatsProxy->SetOnBatteryIpc(true);
43     ParcelableBatteryStatsList parcelableEntityList;
44     int32_t tempError;
45     sptrStatsProxy->GetBatteryStatsIpc(parcelableEntityList, tempError);
46     auto infoList = parcelableEntityList.statsList_;
47     EXPECT_TRUE(infoList.empty());
48     int32_t uid = 1004;
49     double appStatsMah;
50     sptrStatsProxy->GetAppStatsMahIpc(uid, appStatsMah, tempError);
51     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, appStatsMah);
52     double appStatsPercent;
53     sptrStatsProxy->GetAppStatsPercentIpc(uid, appStatsPercent, tempError);
54     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, appStatsPercent);
55     BatteryStatsInfo::ConsumptionType consumptionType = BatteryStatsInfo::CONSUMPTION_TYPE_APP;
56     double partStatsMah;
57     sptrStatsProxy->GetPartStatsMahIpc(consumptionType, partStatsMah, tempError);
58     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, partStatsMah);
59     double partStatsPercent;
60     sptrStatsProxy->GetPartStatsPercentIpc(consumptionType, partStatsPercent, tempError);
61     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, partStatsPercent);
62     StatsUtils::StatsType statsType = StatsUtils::STATS_TYPE_PHONE_ACTIVE;
63     uint64_t totalTimeSecond;
64     sptrStatsProxy->GetTotalTimeSecondIpc(statsType, StatsUtils::INVALID_VALUE, totalTimeSecond);
65     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, totalTimeSecond);
66     uint64_t totalDataBytes;
67     sptrStatsProxy->GetTotalDataBytesIpc(statsType, StatsUtils::INVALID_VALUE, totalDataBytes);
68     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, totalDataBytes);
69     STATS_HILOGI(LABEL_TEST, "StatsClientTestMockObject_001 end");
70 }
71 }
72