1 /*
2 * Copyright (c) 2023-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 "hdi_death_test.h"
17 #include <chrono>
18 #include <cinttypes>
19 #include <algorithm>
20 #include "display_test.h"
21 #include "display_test_utils.h"
22 #include "hdi_test_device.h"
23 #include "hdi_test_device_common.h"
24 #include "hdi_test_display.h"
25
26 using namespace OHOS::HDI::Display::Composer::V1_0;
27 using namespace OHOS::HDI::Display::TEST;
28 using namespace testing::ext;
29
30 static bool g_isServiceDead = false;
31
OnRemoteDied(const wptr<IRemoteObject>& remote)32 void ComposerDiedRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
33 {
34 if (remote == nullptr) {
35 return;
36 }
37 EXPECT_EQ(g_isServiceDead, true);
38 }
39
40 /**
41 * @tc.number: SUB_Driver_Display_Death_0300
42 * @tc.name: test_AddDeathRecipient
43 * @tc.desc: Composer_host adds death listening
44 * @tc.size: MediumTest
45 * @tc.type: Function
46 */
HWTEST_F(DeathTest, SUB_Driver_Display_Death_0300, TestSize.Level1)47 HWTEST_F(DeathTest, SUB_Driver_Display_Death_0300, TestSize.Level1)
48 {
49 displayComposer_ = Composer::V1_2::IDisplayComposerInterface::Get();
50 ASSERT_TRUE(displayComposer_ != nullptr);
51 sptr<IRemoteObject::DeathRecipient> recipient = new ComposerDiedRecipient();
52 ASSERT_TRUE(recipient != nullptr);
53 auto ret = displayComposer_->AddDeathRecipient(recipient);
54 EXPECT_EQ(ret, true);
55 g_isServiceDead = true;
56 system("killall composer_host");
57 }
58
59 /**
60 * @tc.number: SUB_Driver_Display_Death_0400
61 * @tc.name: test_RemoveDeathRecipient
62 * @tc.desc: Composer_host removes death listening
63 * @tc.size: MediumTest
64 * @tc.type: Function
65 */
HWTEST_F(DeathTest, SUB_Driver_Display_Death_0400, TestSize.Level1)66 HWTEST_F(DeathTest, SUB_Driver_Display_Death_0400, TestSize.Level1)
67 {
68 displayComposer_ = Composer::V1_2::IDisplayComposerInterface::Get();
69 ASSERT_TRUE(displayComposer_ != nullptr);
70 sptr<IRemoteObject::DeathRecipient> recipient = new ComposerDiedRecipient();
71 ASSERT_TRUE(recipient != nullptr);
72 auto ret = displayComposer_->AddDeathRecipient(recipient);
73 EXPECT_EQ(ret, true);
74 ret = displayComposer_->RemoveDeathRecipient();
75 EXPECT_EQ(ret, true);
76 g_isServiceDead = true;
77 system("killall composer_host");
78 }