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 "thermal_service_death_test.h"
17
18 #include "mock_thermal_remote_object.h"
19 #include "thermal_mgr_client.h"
20 #include "thermal_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: ThermalServiceDeathTest_001
30 * @tc.desc: test OnRemoteDied function(Input remoteObj is nullptr, function don't reset proxy)
31 * @tc.type: FUNC
32 * @tc.require: issueI63SZ4
33 */
HWTEST_F(ThermalServiceDeathTest, ThermalServiceDeathTest_001, TestSize.Level0)34 HWTEST_F (ThermalServiceDeathTest, ThermalServiceDeathTest_001, TestSize.Level0)
35 {
36 THERMAL_HILOGD(LABEL_TEST, "ThermalServiceDeathTest_001 start");
37 auto& thermalClient = ThermalMgrClient::GetInstance();
38 EXPECT_EQ(thermalClient.Connect(), ERR_OK);
39
40 std::shared_ptr<IRemoteObject::DeathRecipient> deathRecipient =
41 std::make_shared<ThermalMgrClient::ThermalMgrDeathRecipient>(thermalClient);
42 wptr<IRemoteObject> remoteObj = nullptr;
43 EXPECT_NE(deathRecipient, nullptr);
44 deathRecipient->OnRemoteDied(remoteObj);
45 EXPECT_NE(thermalClient.thermalSrv_, nullptr);
46 THERMAL_HILOGD(LABEL_TEST, "ThermalServiceDeathTest_001 end");
47 }
48
49 /**
50 * @tc.name: ThermalServiceDeathTest_002
51 * @tc.desc: test OnRemoteDied function(Input remoteObj is not nullptr, function don't reset proxy)
52 * @tc.type: FUNC
53 * @tc.require: issueI64U2R
54 */
HWTEST_F(ThermalServiceDeathTest, ThermalServiceDeathTest_002, TestSize.Level0)55 HWTEST_F (ThermalServiceDeathTest, ThermalServiceDeathTest_002, TestSize.Level0)
56 {
57 THERMAL_HILOGD(LABEL_TEST, "ThermalServiceDeathTest_002 start");
58 auto& thermalClient = ThermalMgrClient::GetInstance();
59 EXPECT_EQ(thermalClient.Connect(), ERR_OK);
60
61 std::shared_ptr<IRemoteObject::DeathRecipient> deathRecipient =
62 std::make_shared<ThermalMgrClient::ThermalMgrDeathRecipient>(thermalClient);
63 EXPECT_NE(deathRecipient, nullptr);
64 sptr<IRemoteObject> sptrRemoteObj = new MockThermalRemoteObject();
65 EXPECT_FALSE(sptrRemoteObj == nullptr);
66 deathRecipient->OnRemoteDied(sptrRemoteObj);
67 EXPECT_NE(thermalClient.thermalSrv_, nullptr);
68 THERMAL_HILOGD(LABEL_TEST, "ThermalServiceDeathTest_002 end");
69 }
70 }