1 /*
2  * Copyright (c) 2022 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 
18 #include "battery_stats_client.h"
19 #include "battery_stats_proxy.h"
20 
21 using namespace testing::ext;
22 using namespace OHOS::PowerMgr;
23 using namespace OHOS;
24 using namespace std;
25 
26 namespace {
27 /**
28  * @tc.name: StatsClientTestMockPeer_001
29  * @tc.desc: test BatteryStatsClient function(remoteObject is null)
30  * @tc.type: FUNC
31  * @tc.require: issueI5X13X
32  */
33 HWTEST_F (StatsClientTestMockPeer, StatsClientTestMockPeer_001, TestSize.Level0)
34 {
35     auto& statsClient = BatteryStatsClient::GetInstance();
36     statsClient.Reset();
37     statsClient.SetOnBattery(true);
38     auto infoList = statsClient.GetBatteryStats();
39     EXPECT_TRUE(infoList.empty());
40     int32_t uid = 1004;
41     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetAppStatsMah(uid));
42     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetAppStatsPercent(uid));
43     BatteryStatsInfo::ConsumptionType consumptionType = BatteryStatsInfo::CONSUMPTION_TYPE_APP;
44     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetPartStatsMah(consumptionType));
45     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetPartStatsPercent(consumptionType));
46     StatsUtils::StatsType statsType = StatsUtils::STATS_TYPE_PHONE_ACTIVE;
47     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetTotalTimeSecond(statsType));
48     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, statsClient.GetTotalDataBytes(statsType));
49     std::vector<std::string> dumpArgs;
50     dumpArgs.push_back("-batterystats");
51     EXPECT_EQ("can't connect service", statsClient.Dump(dumpArgs));
52 }
53 }
54