• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
41   * @tc.number: test_AddDeathRecipient
42   * @tc.name: SUB_DriverSystem_DisplayComposerDeath_0010
43   * @tc.desc:
44   */
45 HWTEST_F(DeathTest, SUB_DriverSystem_DisplayComposerDeath_0010, TestSize.Level1)
46 {
47     displayComposer_ = IDisplayComposerInterface::Get();
48     ASSERT_TRUE(displayComposer_ != nullptr);
49     sptr<IRemoteObject::DeathRecipient> recipient = new ComposerDiedRecipient();
50     ASSERT_TRUE(recipient != nullptr);
51     auto ret = displayComposer_->AddDeathRecipient(recipient);
52     EXPECT_EQ(ret, true);
53     g_isServiceDead = true;
54     system("killall composer_host");
55 }
56 
57 /**
58   * @tc.number: test_RemoveDeathRecipient
59   * @tc.name: SUB_DriverSystem_DisplayComposerDeath_0010
60   * @tc.desc:
61   */
62 HWTEST_F(DeathTest, SUB_DriverSystem_DisplayComposerDeath_0020, TestSize.Level1)
63 {
64     displayComposer_ = IDisplayComposerInterface::Get();
65     ASSERT_TRUE(displayComposer_ != nullptr);
66     sptr<IRemoteObject::DeathRecipient> recipient = new ComposerDiedRecipient();
67     ASSERT_TRUE(recipient != nullptr);
68     auto ret = displayComposer_->AddDeathRecipient(recipient);
69     EXPECT_EQ(ret, true);
70     ret = displayComposer_->RemoveDeathRecipient();
71     EXPECT_EQ(ret, true);
72     g_isServiceDead = true;
73     system("killall composer_host");
74 }