1 /*
2 * Copyright (c) 2023 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 HWTEST_F(DeathTest, test_AddDeathRecipient, TestSize.Level1)
41 {
42 displayComposer_ = IDisplayComposerInterface::Get();
43 ASSERT_TRUE(displayComposer_ != nullptr);
44 sptr<IRemoteObject::DeathRecipient> recipient = new ComposerDiedRecipient();
45 ASSERT_TRUE(recipient != nullptr);
46 auto ret = displayComposer_->AddDeathRecipient(recipient);
47 EXPECT_EQ(ret, true);
48 g_isServiceDead = true;
49 system("killall composer_host");
50 }
51
52 HWTEST_F(DeathTest, test_RemoveDeathRecipient, TestSize.Level1)
53 {
54 displayComposer_ = IDisplayComposerInterface::Get();
55 ASSERT_TRUE(displayComposer_ != nullptr);
56 sptr<IRemoteObject::DeathRecipient> recipient = new ComposerDiedRecipient();
57 ASSERT_TRUE(recipient != nullptr);
58 auto ret = displayComposer_->AddDeathRecipient(recipient);
59 EXPECT_EQ(ret, true);
60 ret = displayComposer_->RemoveDeathRecipient();
61 EXPECT_EQ(ret, true);
62 g_isServiceDead = true;
63 system("killall composer_host");
64 }