• 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 #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 HWTEST_F(DeathTest, test_AddDeathRecipient, TestSize.Level1)
41 {
42     displayBuffer_.reset(IDisplayBuffer::Get());
43     ASSERT_TRUE(displayBuffer_ != nullptr);
44     sptr<IRemoteObject::DeathRecipient> recipient = new BufferDiedRecipient();
45     ASSERT_TRUE(recipient != nullptr);
46     auto ret = displayBuffer_->AddDeathRecipient(recipient);
47     EXPECT_EQ(ret, true);
48     g_isServiceDead = true;
49     system("killall allocator_host");
50 }
51 
52 HWTEST_F(DeathTest, test_RemoveDeathRecipient, TestSize.Level1)
53 {
54     displayBuffer_.reset(IDisplayBuffer::Get());
55     ASSERT_TRUE(displayBuffer_ != nullptr);
56     sptr<IRemoteObject::DeathRecipient> recipient = new BufferDiedRecipient();
57     ASSERT_TRUE(recipient != nullptr);
58     auto ret = displayBuffer_->AddDeathRecipient(recipient);
59     EXPECT_EQ(ret, true);
60 
61     ret = displayBuffer_->RemoveDeathRecipient();
62     EXPECT_EQ(ret, true);
63     g_isServiceDead = true;
64     system("killall allocator_host");
65 }
66 } // OHOS
67 } // HDI
68 } // DISPLAY
69 } // TEST