1 /*
2  * Copyright (c) 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 <securec.h>
16 #include <gtest/gtest.h>
17 #include <surface.h>
18 #include <consumer_surface.h>
19 #include <native_window.h>
20 #include "buffer_consumer_listener.h"
21 #include "sync_fence.h"
22 #include <message_option.h>
23 #include <message_parcel.h>
24 #include "transact_surface_delegator_stub.h"
25 #include "buffer_log.h"
26 #include "producer_surface_delegator.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS::Rosen {
32 class TransactSurfaceDelegatorStubTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     static inline sptr<TransactSurfaceDelegatorStub> tsd = nullptr;
37     static inline sptr<ProducerSurfaceDelegator> surfaceDelegator = nullptr;
38 };
39 
SetUpTestCase()40 void TransactSurfaceDelegatorStubTest::SetUpTestCase()
41 {
42     tsd = new TransactSurfaceDelegatorStub();
43     surfaceDelegator = ProducerSurfaceDelegator::Create();
44 }
45 
TearDownTestCase()46 void TransactSurfaceDelegatorStubTest::TearDownTestCase()
47 {
48     tsd = nullptr;
49     surfaceDelegator = nullptr;
50 }
51 
52 /*
53 * Function: SetClient
54 * Type: Function
55 * Rank: Important(2)
56 * EnvConditions: N/A
57 * CaseDescription: 1. call SetClient
58 *                  2. check ret
59  */
60 HWTEST_F(TransactSurfaceDelegatorStubTest, SetClient001, Function | MediumTest | Level2)
61 {
62     bool ret = tsd->SetClient(surfaceDelegator->AsObject());
63     EXPECT_EQ(ret, true);
64 }
65 
66 /*
67 * Function: SendSelfProxy
68 * Type: Function
69 * Rank: Important(2)
70 * EnvConditions: N/A
71 * CaseDescription: 1. call SendSelfProxy
72 *                  2. check ret
73  */
74 HWTEST_F(TransactSurfaceDelegatorStubTest, SendSelfProxy001, Function | MediumTest | Level2)
75 {
76     int ret = tsd->SendSelfProxy();
77     ASSERT_EQ(ret, ERR_NONE);
78 }
79 
80 /*
81 * Function: ReadNativeHandle
82 * Type: Function
83 * Rank: Important(2)
84 * EnvConditions: N/A
85 * CaseDescription: 1. call ReadNativeHandle
86 *                  2. check ret
87  */
88 HWTEST_F(TransactSurfaceDelegatorStubTest, ReadNativeHandle001, Function | MediumTest | Level2)
89 {
90     MessageParcel input;
91     NativeHandleT* buffer = tsd->ReadNativeHandle(input);
92     EXPECT_EQ(buffer, nullptr);
93 }
94 } // namespace OHOS::Rosen