19762338dSopenharmony_ci/* 29762338dSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 39762338dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 49762338dSopenharmony_ci * you may not use this file except in compliance with the License. 59762338dSopenharmony_ci * You may obtain a copy of the License at 69762338dSopenharmony_ci * 79762338dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 89762338dSopenharmony_ci * 99762338dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 109762338dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 119762338dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129762338dSopenharmony_ci * See the License for the specific language governing permissions and 139762338dSopenharmony_ci * limitations under the License. 149762338dSopenharmony_ci */ 159762338dSopenharmony_ci#include "death_test.h" 169762338dSopenharmony_ci#include <securec.h> 179762338dSopenharmony_ci#include "hdf_base.h" 189762338dSopenharmony_ci#include "hdf_log.h" 199762338dSopenharmony_ci#include "gtest/gtest.h" 209762338dSopenharmony_ci#include "v1_0/display_composer_type.h" 219762338dSopenharmony_ci 229762338dSopenharmony_cinamespace OHOS { 239762338dSopenharmony_cinamespace HDI { 249762338dSopenharmony_cinamespace Display { 259762338dSopenharmony_cinamespace TEST { 269762338dSopenharmony_ciusing namespace OHOS::HDI::Display::Composer::V1_0; 279762338dSopenharmony_ciusing namespace OHOS::HDI::Display::Buffer::V1_0; 289762338dSopenharmony_ciusing namespace testing::ext; 299762338dSopenharmony_ci 309762338dSopenharmony_cistatic bool g_isServiceDead = false; 319762338dSopenharmony_ci 329762338dSopenharmony_civoid BufferDiedRecipient::OnRemoteDied(const OHOS::wptr<OHOS::IRemoteObject>& remote) 339762338dSopenharmony_ci{ 349762338dSopenharmony_ci if (remote == nullptr) { 359762338dSopenharmony_ci return; 369762338dSopenharmony_ci } 379762338dSopenharmony_ci EXPECT_EQ(g_isServiceDead, true); 389762338dSopenharmony_ci} 399762338dSopenharmony_ci 409762338dSopenharmony_ci/** 419762338dSopenharmony_ci * @tc.number: SUB_Driver_Display_Death_0100 429762338dSopenharmony_ci * @tc.name: test_AddDeathRecipient 439762338dSopenharmony_ci * @tc.desc: Allocator_host adds death listening 449762338dSopenharmony_ci * @tc.size: MediumTest 459762338dSopenharmony_ci * @tc.type: Function 469762338dSopenharmony_ci */ 479762338dSopenharmony_ciHWTEST_F(DeathTest, SUB_Driver_Display_Death_0100, TestSize.Level1) 489762338dSopenharmony_ci{ 499762338dSopenharmony_ci displayBuffer_.reset(IDisplayBuffer::Get()); 509762338dSopenharmony_ci ASSERT_TRUE(displayBuffer_ != nullptr); 519762338dSopenharmony_ci sptr<IRemoteObject::DeathRecipient> recipient = new BufferDiedRecipient(); 529762338dSopenharmony_ci ASSERT_TRUE(recipient != nullptr); 539762338dSopenharmony_ci auto ret = displayBuffer_->AddDeathRecipient(recipient); 549762338dSopenharmony_ci EXPECT_EQ(ret, true); 559762338dSopenharmony_ci g_isServiceDead = true; 569762338dSopenharmony_ci system("killall allocator_host"); 579762338dSopenharmony_ci} 589762338dSopenharmony_ci 599762338dSopenharmony_ci/** 609762338dSopenharmony_ci * @tc.number: SUB_Driver_Display_Death_0200 619762338dSopenharmony_ci * @tc.name: test_RemoveDeathRecipient 629762338dSopenharmony_ci * @tc.desc: Allocator_host removes death listening 639762338dSopenharmony_ci * @tc.size: MediumTest 649762338dSopenharmony_ci * @tc.type: Function 659762338dSopenharmony_ci */ 669762338dSopenharmony_ciHWTEST_F(DeathTest, SUB_Driver_Display_Death_0200, TestSize.Level1) 679762338dSopenharmony_ci{ 689762338dSopenharmony_ci displayBuffer_.reset(IDisplayBuffer::Get()); 699762338dSopenharmony_ci ASSERT_TRUE(displayBuffer_ != nullptr); 709762338dSopenharmony_ci sptr<IRemoteObject::DeathRecipient> recipient = new BufferDiedRecipient(); 719762338dSopenharmony_ci ASSERT_TRUE(recipient != nullptr); 729762338dSopenharmony_ci auto ret = displayBuffer_->AddDeathRecipient(recipient); 739762338dSopenharmony_ci EXPECT_EQ(ret, true); 749762338dSopenharmony_ci 759762338dSopenharmony_ci ret = displayBuffer_->RemoveDeathRecipient(); 769762338dSopenharmony_ci EXPECT_EQ(ret, true); 779762338dSopenharmony_ci g_isServiceDead = true; 789762338dSopenharmony_ci system("killall allocator_host"); 799762338dSopenharmony_ci} 809762338dSopenharmony_ci} // OHOS 819762338dSopenharmony_ci} // HDI 829762338dSopenharmony_ci} // DISPLAY 839762338dSopenharmony_ci} // TEST 84