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_service_death_test.h"
17
18 #include "battery_stats_client.h"
19 #include "battery_stats_parser.h"
20 #include "battery_stats_service.h"
21 #include "config_policy_utils.h"
22
23 using namespace testing::ext;
24 using namespace OHOS::PowerMgr;
25 using namespace OHOS;
26 using namespace std;
27
GetOneCfgFile(const char * pathSuffix,char * buf,unsigned int bufLength)28 char* GetOneCfgFile(const char *pathSuffix, char *buf, unsigned int bufLength)
29 {
30 std::string path = " ";
31 char* ret = (char*)path.c_str();
32 return ret;
33 }
34
35 namespace {
36 /**
37 * @tc.name: StatsServiceDeathTest_001
38 * @tc.desc: test OnRemoteDied function(Input remoteObj is nullptr, function don't reset proxy)
39 * @tc.type: FUNC
40 * @tc.require: issueI63PI8
41 */
42 HWTEST_F (StatsServiceDeathTest, StatsServiceDeathTest_001, TestSize.Level0)
43 {
44 auto& statsClient = BatteryStatsClient::GetInstance();
45 EXPECT_EQ(statsClient.Connect(), ERR_OK);
46
47 std::shared_ptr<IRemoteObject::DeathRecipient> deathRecipient =
48 std::make_shared<BatteryStatsClient::BatteryStatsDeathRecipient>();
49 wptr<IRemoteObject> remoteObj = nullptr;
50 EXPECT_NE(deathRecipient, nullptr);
51 deathRecipient->OnRemoteDied(remoteObj);
52 EXPECT_NE(statsClient.proxy_, nullptr);
53 }
54
55 /**
56 * @tc.name: StatsParserTest_001
57 * @tc.desc: test Init
58 * @tc.type: FUNC
59 */
60 HWTEST_F (StatsServiceDeathTest, StatsParserTest_001, TestSize.Level0)
61 {
62 auto parser = std::make_shared<BatteryStatsParser>();
63 bool ret = parser->Init();
64 EXPECT_FALSE(ret);
65 }
66
67 /**
68 * @tc.name: StatsServiceTest_001
69 * @tc.desc: test OnStart
70 * @tc.type: FUNC
71 */
72 HWTEST_F (StatsServiceDeathTest, StatsServiceTest_001, TestSize.Level0)
73 {
74 auto statsService = BatteryStatsService::GetInstance();
75 statsService->OnStart();
76 bool ret = statsService->IsServiceReady();
77 EXPECT_FALSE(ret);
78 }
79 }
80