/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include "buffer_consumer_listener.h" #include "sync_fence.h" #include #include #include "transact_surface_delegator_stub.h" #include "consumer_surface.h" #include "producer_surface_delegator.h" #include "buffer_queue_producer.h" using namespace testing; using namespace testing::ext; namespace OHOS::Rosen { class ProducerSurfaceDelegatorTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); static inline sptr csurf = nullptr; static inline sptr qwe = nullptr; static inline sptr producer = nullptr; static inline sptr pSurface = nullptr; static inline sptr pBuffer = nullptr; static inline sptr cBuffer = nullptr; }; class IRemoteObjectMocker : public IRemoteObject { public: IRemoteObjectMocker() : IRemoteObject{u"IRemoteObjectMocker"} {} ~IRemoteObjectMocker() {} int32_t GetObjectRefCount() { return 0; } int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { return 0; } bool IsProxyObject() const { return true; } bool CheckObjectLegality() const { return true; } bool AddDeathRecipient(const sptr &recipient) { return true; } bool RemoveDeathRecipient(const sptr &recipient) { return true; } sptr AsInterface() { return nullptr; } int Dump(int fd, const std::vector &args) { return 0; } }; void ProducerSurfaceDelegatorTest::SetUpTestCase() { csurf = IConsumerSurface::Create(); sptr listener = new BufferConsumerListener(); csurf->RegisterConsumerListener(listener); producer = csurf->GetProducer(); pSurface = Surface::CreateSurfaceAsProducer(producer); qwe = new ProducerSurfaceDelegator(); sptr remoteObjectMocker = new IRemoteObjectMocker(); qwe->SetClient(remoteObjectMocker); pBuffer = SurfaceBuffer::Create(); } void ProducerSurfaceDelegatorTest::TearDownTestCase() { pSurface->UnRegisterReleaseListener(); qwe = nullptr; csurf = nullptr; producer = nullptr; pSurface = nullptr; pBuffer = nullptr; } /* * Function: QueueBuffer * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call QueueBuffer * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, QueueBuffer002, Function | MediumTest | Level2) { int32_t slot = 1; int32_t acquireFence = 3; sptr aSurface = Surface::CreateSurfaceAsProducer(producer); qwe->SetSurface(aSurface); GSError ret = qwe->QueueBuffer(slot, acquireFence); ASSERT_EQ(ret, GSERROR_OK); } /* * Function: DequeueBuffer * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call DequeueBuffer * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, DequeueBuffer002, Function | MediumTest | Level2) { int32_t slot = 1; qwe->SetSurface(pSurface); GSError ret = qwe->DequeueBuffer(slot, pBuffer); ASSERT_EQ(ret, GSERROR_OK); } /* * Function: QueueBuffer * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call QueueBuffer * 2. check SendMessage ret */ HWTEST_F(ProducerSurfaceDelegatorTest, QueueBuffer003, Function | MediumTest | Level2) { int32_t slot = 1; int32_t acquireFence = 3; qwe->SetSurface(pSurface); GSError ret = qwe->QueueBuffer(slot, acquireFence); ASSERT_EQ(ret, GSERROR_OK); } /* * Function: ReleaseBuffer * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call ReleaseBuffer * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, ReleaseBuffer001, Function | MediumTest | Level2) { sptr fence = SyncFence::INVALID_FENCE; GSError ret = qwe->ReleaseBuffer(pBuffer, fence); ASSERT_EQ(ret, GSERROR_OK); } /* * Function: DetachBuffer * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call DetachBuffer * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, DetachBuffer001, Function | MediumTest | Level2) { int32_t slot = -1; GSError ret = qwe->DetachBuffer(slot); ASSERT_EQ(ret, GSERROR_OK); } /* * Function: CancelBuffer * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call CancelBuffer * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, CancelBuffer001, Function | MediumTest | Level2) { int32_t slot = -1; int32_t fenceFd = -1; GSError ret = qwe->CancelBuffer(slot, fenceFd); ASSERT_EQ(ret, GSERROR_OK); } /* * Function: ClearBufferSlot * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call ClearBufferSlot * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, ClearBufferSlot001, Function | MediumTest | Level2) { int32_t slot = -1; GSError ret = qwe->ClearBufferSlot(slot); ASSERT_EQ(ret, GSERROR_OK); } /* * Function: OnRemoteRequest * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call OnRemoteRequest * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, OnRemoteRequest001, Function | MediumTest | Level2) { uint32_t code = 1; // QUEUEBUFFER MessageParcel reply; MessageOption option; MessageParcel dataQueue; dataQueue.WriteInt32(10); dataQueue.WriteFileDescriptor(20); int ret2 = qwe->OnRemoteRequest(code, dataQueue, reply, option); ASSERT_EQ(ret2, ERR_NONE); } /* * Function: ClearAllBuffers * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call ClearAllBuffers * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, ClearAllBuffers001, Function | MediumTest | Level2) { GSError ret = qwe->ClearAllBuffers(); ASSERT_EQ(ret, GSERROR_OK); } /* * Function: AddBufferLocked * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call AddBufferLocked * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, AddBufferLocked001, Function | MediumTest | Level2) { ASSERT_NO_FATAL_FAILURE({ qwe->AddBufferLocked(nullptr, 0); }); } /* * Function: GetBufferLocked * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call GetBufferLocked * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, GetBufferLocked001, Function | MediumTest | Level2) { ASSERT_EQ(qwe->GetBufferLocked(0), nullptr); } /* * Function: GetSlotLocked * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call GetSlotLocked * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, GetSlotLocked001, Function | MediumTest | Level2) { ASSERT_EQ(qwe->GetSlotLocked(nullptr), 0); } /* * Function: RetryFlushBuffer * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call RetryFlushBuffer * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, RetryFlushBuffer001, Function | MediumTest | Level2) { BufferFlushConfig config = { .damage = { .x = 0, .y = 0, .w = 0, .h = 0, }, .timestamp = 0 }; GSError ret = qwe->RetryFlushBuffer(pBuffer, 0, config); ASSERT_EQ(ret, GSERROR_OK); } /* * Function: OnSetDataspace * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call OnSetDataspace * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, SetDataspace001, Function | MediumTest | Level2) { MessageParcel reply; MessageParcel data; data.WriteUint32(1); ASSERT_EQ(qwe->OnSetDataspace(data, reply), 0); } /* * Function: HasSlotInSet * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call HasSlotInSet * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, HasSlotInSet, Function | MediumTest | Level2) { sptr delegator = new ProducerSurfaceDelegator(); bool ret = delegator->HasSlotInSet(0); ASSERT_EQ(ret, false); delegator->InsertSlotIntoSet(0); ret = delegator->HasSlotInSet(0); ASSERT_EQ(ret, true); } /* * Function: InsertSlotIntoSet * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call InsertSlotIntoSet * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, InsertSlotIntoSet, Function | MediumTest | Level2) { sptr delegator = new ProducerSurfaceDelegator(); delegator->InsertSlotIntoSet(0); delegator->InsertSlotIntoSet(1); ASSERT_EQ(delegator->HasSlotInSet(0), true); ASSERT_EQ(delegator->HasSlotInSet(1), true); ASSERT_EQ(delegator->HasSlotInSet(2), false); } /* * Function: EraseSlotFromSet * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call EraseSlotFromSet * 2. check ret */ HWTEST_F(ProducerSurfaceDelegatorTest, EraseSlotFromSet, Function | MediumTest | Level2) { sptr delegator = new ProducerSurfaceDelegator(); delegator->InsertSlotIntoSet(0); ASSERT_EQ(delegator->HasSlotInSet(0), true); delegator->EraseSlotFromSet(0); ASSERT_EQ(delegator->HasSlotInSet(0), false); } } // namespace OHOS::Rosen