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 "power_mgr_service_death_test.h" 17 18 #include "mock_power_remote_object.h" 19 #include "power_mgr_client.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: PowerMgrServiceDeathTest_001 29 * @tc.desc: test OnRemoteDied function(Input remoteObj is nullptr, function don't reset proxy) 30 * @tc.type: FUNC 31 * @tc.require: issueI650CX 32 */ 33 HWTEST_F (PowerMgrServiceDeathTest, PowerMgrServiceDeathTest_001, TestSize.Level0) 34 { 35 auto& powerMgrClient = PowerMgrClient::GetInstance(); 36 EXPECT_EQ(powerMgrClient.Connect(), ERR_OK); 37 38 std::shared_ptr<IRemoteObject::DeathRecipient> deathRecipient = 39 std::make_shared<PowerMgrClient::PowerMgrDeathRecipient>(); 40 wptr<IRemoteObject> remoteObj = nullptr; 41 EXPECT_NE(deathRecipient, nullptr); 42 deathRecipient->OnRemoteDied(remoteObj); 43 EXPECT_NE(powerMgrClient.proxy_, nullptr); 44 } 45 46 /** 47 * @tc.name: PowerMgrServiceDeathTest_002 48 * @tc.desc: test OnRemoteDied function(Input remoteObj is not nullptr, function don't reset proxy) 49 * @tc.type: FUNC 50 * @tc.require: issueI650CX 51 */ 52 HWTEST_F (PowerMgrServiceDeathTest, PowerMgrServiceDeathTest_002, TestSize.Level0) 53 { 54 auto& powerMgrClient = PowerMgrClient::GetInstance(); 55 EXPECT_EQ(powerMgrClient.Connect(), ERR_OK); 56 57 std::shared_ptr<IRemoteObject::DeathRecipient> deathRecipient = 58 std::make_shared<PowerMgrClient::PowerMgrDeathRecipient>(); 59 EXPECT_NE(deathRecipient, nullptr); 60 sptr<IRemoteObject> sptrRemoteObj = new MockPowerRemoteObject(); 61 EXPECT_FALSE(sptrRemoteObj == nullptr); 62 deathRecipient->OnRemoteDied(sptrRemoteObj); 63 EXPECT_NE(powerMgrClient.proxy_, nullptr); 64 } 65 }