• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "death_test.h"
16 #include <securec.h>
17 #include "hdf_base.h"
18 #include "hdf_log.h"
19 #include "gtest/gtest.h"
20 #include "v1_0/display_composer_type.h"
21 
22 namespace OHOS {
23 namespace HDI {
24 namespace Display {
25 namespace TEST {
26 using namespace OHOS::HDI::Display::Composer::V1_0;
27 using namespace OHOS::HDI::Display::Buffer::V1_0;
28 using namespace testing::ext;
29 
30 static bool g_isServiceDead = false;
31 
OnRemoteDied(const OHOS::wptr<OHOS::IRemoteObject> & remote)32 void BufferDiedRecipient::OnRemoteDied(const OHOS::wptr<OHOS::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_0100
42  * @tc.name: test_AddDeathRecipient
43  * @tc.desc: Allocator_host adds death listening
44  * @tc.size: MediumTest
45  * @tc.type: Function
46  */
47 HWTEST_F(DeathTest, SUB_Driver_Display_Death_0100, TestSize.Level1)
48 {
49     displayBuffer_.reset(IDisplayBuffer::Get());
50     ASSERT_TRUE(displayBuffer_ != nullptr);
51     sptr<IRemoteObject::DeathRecipient> recipient = new BufferDiedRecipient();
52     ASSERT_TRUE(recipient != nullptr);
53     auto ret = displayBuffer_->AddDeathRecipient(recipient);
54     EXPECT_EQ(ret, true);
55     g_isServiceDead = true;
56     system("killall allocator_host");
57 }
58 
59 /**
60  * @tc.number: SUB_Driver_Display_Death_0200
61  * @tc.name: test_RemoveDeathRecipient
62  * @tc.desc: Allocator_host removes death listening
63  * @tc.size: MediumTest
64  * @tc.type: Function
65  */
66 HWTEST_F(DeathTest, SUB_Driver_Display_Death_0200, TestSize.Level1)
67 {
68     displayBuffer_.reset(IDisplayBuffer::Get());
69     ASSERT_TRUE(displayBuffer_ != nullptr);
70     sptr<IRemoteObject::DeathRecipient> recipient = new BufferDiedRecipient();
71     ASSERT_TRUE(recipient != nullptr);
72     auto ret = displayBuffer_->AddDeathRecipient(recipient);
73     EXPECT_EQ(ret, true);
74 
75     ret = displayBuffer_->RemoveDeathRecipient();
76     EXPECT_EQ(ret, true);
77     g_isServiceDead = true;
78     system("killall allocator_host");
79 }
80 } // OHOS
81 } // HDI
82 } // DISPLAY
83 } // TEST
84