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_object.h"
17 
18 #include "battery_stats_proxy.h"
19 #include "mock_stats_remote_object.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: StatsClientTestMockObject_001
29  * @tc.desc: test BatteryStatsProxy function(IRemoteObject is mock, "SendRequest" function return false)
30  * @tc.type: FUNC
31  * @tc.require: issueI5X13X
32  */
33 HWTEST_F (StatsClientTestMockObject, StatsClientTestMockObject_001, TestSize.Level0)
34 {
35     sptr<MockStatsRemoteObject> sptrRemoteObj = new MockStatsRemoteObject();
36     std::shared_ptr<BatteryStatsProxy> sptrStatsProxy = std::make_shared<BatteryStatsProxy>(sptrRemoteObj);
37     sptrStatsProxy->Reset();
38     sptrStatsProxy->SetOnBattery(true);
39     auto infoList = sptrStatsProxy->GetBatteryStats();
40     EXPECT_TRUE(infoList.empty());
41     int32_t uid = 1004;
42     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, sptrStatsProxy->GetAppStatsMah(uid));
43     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, sptrStatsProxy->GetAppStatsPercent(uid));
44     BatteryStatsInfo::ConsumptionType consumptionType = BatteryStatsInfo::CONSUMPTION_TYPE_APP;
45     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, sptrStatsProxy->GetPartStatsMah(consumptionType));
46     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, sptrStatsProxy->GetPartStatsPercent(consumptionType));
47     StatsUtils::StatsType statsType = StatsUtils::STATS_TYPE_PHONE_ACTIVE;
48     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, sptrStatsProxy->GetTotalTimeSecond(statsType, StatsUtils::INVALID_VALUE));
49     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, sptrStatsProxy->GetTotalDataBytes(statsType, StatsUtils::INVALID_VALUE));
50     std::vector<std::string> dumpArgs;
51     dumpArgs.push_back("-batterystats");
52     EXPECT_EQ("remote error", sptrStatsProxy->ShellDump(dumpArgs, dumpArgs.size()));
53 }
54 }
55