• 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_peer.h"
17 #include "stats_log.h"
18 
19 #include "battery_stats_client.h"
20 #include "battery_stats_proxy.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: StatsClientTestMockPeer_001
30  * @tc.desc: test BatteryStatsClient function(remoteObject is null)
31  * @tc.type: FUNC
32  * @tc.require: issueI5X13X
33  */
34 HWTEST_F (StatsClientTestMockPeer, StatsClientTestMockPeer_001, TestSize.Level0)
35 {
36     STATS_HILOGI(LABEL_TEST, "StatsClientTestMockPeer_001 start");
37     auto& statsClient = BatteryStatsClient::GetInstance();
38     statsClient.Reset();
39     statsClient.SetOnBattery(true);
40     auto infoList = statsClient.GetBatteryStats();
41     EXPECT_TRUE(infoList.empty());
42     int32_t uid = 1004;
43     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetAppStatsMah(uid));
44     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetAppStatsPercent(uid));
45     BatteryStatsInfo::ConsumptionType consumptionType = BatteryStatsInfo::CONSUMPTION_TYPE_APP;
46     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetPartStatsMah(consumptionType));
47     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetPartStatsPercent(consumptionType));
48     StatsUtils::StatsType statsType = StatsUtils::STATS_TYPE_PHONE_ACTIVE;
49     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetTotalTimeSecond(statsType));
50     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetTotalDataBytes(statsType));
51     std::vector<std::string> dumpArgs;
52     dumpArgs.push_back("-batterystats");
53     EXPECT_EQ("can't connect service", statsClient.Dump(dumpArgs));
54     STATS_HILOGI(LABEL_TEST, "StatsClientTestMockPeer_001 end");
55 }
56 }
57