1 /* 2 * Copyright (c) 2022-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 "power_mgr_service_death_test.h" 17 18 #include "mock_power_remote_object.h" 19 #include "power_mgr_client.h" 20 #include "power_log.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: PowerMgrServiceDeathTest_001 30 * @tc.desc: test OnRemoteDied function(Input remoteObj is nullptr, function don't reset proxy) 31 * @tc.type: FUNC 32 * @tc.require: issueI650CX 33 */ 34 HWTEST_F (PowerMgrServiceDeathTest, PowerMgrServiceDeathTest_001, TestSize.Level1) 35 { 36 GTEST_LOG_(INFO) << "PowerMgrServiceDeathTest_001 start."; 37 POWER_HILOGI(LABEL_TEST, "PowerMgrServiceDeathTest_001 function start!"); 38 auto& powerMgrClient = PowerMgrClient::GetInstance(); 39 EXPECT_TRUE(powerMgrClient.GetPowerMgrProxy() != nullptr); 40 41 std::shared_ptr<IRemoteObject::DeathRecipient> deathRecipient = 42 std::make_shared<PowerMgrClient::PowerMgrDeathRecipient>(powerMgrClient); 43 wptr<IRemoteObject> remoteObj = nullptr; 44 EXPECT_NE(deathRecipient, nullptr); 45 deathRecipient->OnRemoteDied(remoteObj); 46 EXPECT_NE(powerMgrClient.proxy_, nullptr); 47 POWER_HILOGI(LABEL_TEST, "PowerMgrServiceDeathTest_001 function end!"); 48 GTEST_LOG_(INFO) << "PowerMgrServiceDeathTest_001 end."; 49 } 50 51 /** 52 * @tc.name: PowerMgrServiceDeathTest_002 53 * @tc.desc: test OnRemoteDied function(Input remoteObj is not nullptr, function don't reset proxy) 54 * @tc.type: FUNC 55 * @tc.require: issueI650CX 56 */ 57 HWTEST_F (PowerMgrServiceDeathTest, PowerMgrServiceDeathTest_002, TestSize.Level1) 58 { 59 GTEST_LOG_(INFO) << "PowerMgrServiceDeathTest_002 start."; 60 POWER_HILOGI(LABEL_TEST, "PowerMgrServiceDeathTest_002 function start!"); 61 auto& powerMgrClient = PowerMgrClient::GetInstance(); 62 EXPECT_TRUE(powerMgrClient.GetPowerMgrProxy() != nullptr); 63 64 std::shared_ptr<IRemoteObject::DeathRecipient> deathRecipient = 65 std::make_shared<PowerMgrClient::PowerMgrDeathRecipient>(powerMgrClient); 66 EXPECT_NE(deathRecipient, nullptr); 67 sptr<IRemoteObject> sptrRemoteObj = new MockPowerRemoteObject(); 68 EXPECT_FALSE(sptrRemoteObj == nullptr); 69 deathRecipient->OnRemoteDied(sptrRemoteObj); 70 EXPECT_NE(powerMgrClient.proxy_, nullptr); 71 POWER_HILOGI(LABEL_TEST, "PowerMgrServiceDeathTest_002 function end!"); 72 GTEST_LOG_(INFO) << "PowerMgrServiceDeathTest_002 end."; 73 } 74 }