1 /*
2 * Copyright (c) 2021 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
16 #include "hdi_framebuffer_surface.h"
17 #include "surface_buffer_impl.h"
18 #include <gtest/gtest.h>
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 class HdiFramebufferSurfaceTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29
30 static inline sptr<HdiFramebufferSurface> hdiFramebufferSurface_ = nullptr;
31 };
32
SetUpTestCase()33 void HdiFramebufferSurfaceTest::SetUpTestCase()
34 {
35 hdiFramebufferSurface_ = HdiFramebufferSurface::CreateFramebufferSurface();
36 hdiFramebufferSurface_->OnBufferAvailable();
37 }
38
TearDownTestCase()39 void HdiFramebufferSurfaceTest::TearDownTestCase()
40 {
41 hdiFramebufferSurface_ = nullptr;
42 }
43
44 namespace {
45 /*
46 * Function: ReleaseFramebuffer001
47 * Type: Function
48 * Rank: Important(3)
49 * EnvConditions: N/A
50 * CaseDescription: 1. call ReleaseFramebuffer
51 * 2. check ret
52 */
53 HWTEST_F(HdiFramebufferSurfaceTest, ReleaseFramebuffer001, Function | MediumTest| Level3)
54 {
55 sptr<SurfaceBuffer> buffer = nullptr;
56 sptr<SyncFence> fence = new SyncFence(10);
57 ASSERT_EQ(hdiFramebufferSurface_->ReleaseFramebuffer(buffer, fence), 0);
58 buffer = new SurfaceBufferImpl();
59 ASSERT_NE(hdiFramebufferSurface_->ReleaseFramebuffer(buffer, fence), 0);
60 }
61
62 /*
63 * Function: GetBufferQueueSize001
64 * Type: Function
65 * Rank: Important(3)
66 * EnvConditions: N/A
67 * CaseDescription: 1. call GetBufferQueueSize
68 * 2. check ret
69 */
70 HWTEST_F(HdiFramebufferSurfaceTest, GetBufferQueueSize001, Function | MediumTest| Level3)
71 {
72 ASSERT_EQ(hdiFramebufferSurface_->GetBufferQueueSize(), HdiFramebufferSurface::MAX_BUFFER_SIZE);
73 }
74
75 /*
76 * Function: SetBufferQueueSize001
77 * Type: Function
78 * Rank: Important(3)
79 * EnvConditions: N/A
80 * CaseDescription: 1. call SetBufferQueueSize
81 * 2. check ret and no crash
82 */
83 HWTEST_F(HdiFramebufferSurfaceTest, SetBufferQueueSize001, Function | MediumTest| Level3)
84 {
85 // create a HdiFramebufferSurface obj without consumer
86 sptr<HdiFramebufferSurface> fbSurface = new HdiFramebufferSurface();
87
88 // no consumer, should fail with error code(SURFACE_ERROR_NO_CONSUMER)
89 ASSERT_EQ(fbSurface->SetBufferQueueSize(1), SURFACE_ERROR_NO_CONSUMER);
90 }
91
92 /*
93 * Function: ReleaseFramebuffer002
94 * Type: Function
95 * Rank: Important(3)
96 * EnvConditions: N/A
97 * CaseDescription: 1. call ReleaseFramebuffer
98 * 2. check ret and no crash
99 */
100 HWTEST_F(HdiFramebufferSurfaceTest, ReleaseFramebuffer002, Function | MediumTest| Level3)
101 {
102 // create a HdiFramebufferSurface obj without consumer
103 sptr<HdiFramebufferSurface> fbSurface = new HdiFramebufferSurface();
104
105 // no consumer, call ReleaseFramebuffer should not be crash
106 sptr<SurfaceBuffer> buffer = nullptr;
107 sptr<SyncFence> fence = new SyncFence(10);
108 ASSERT_EQ(fbSurface->ReleaseFramebuffer(buffer, fence), 0);
109
110 // no consumer, call ReleaseFramebuffer should not be crash
111 buffer = new SurfaceBufferImpl();
112 ASSERT_EQ(fbSurface->ReleaseFramebuffer(buffer, fence), 0);
113 }
114
115 /*
116 * Function: OnBufferAvailable001
117 * Type: Function
118 * Rank: Important(3)
119 * EnvConditions: N/A
120 * CaseDescription: 1. call OnBufferAvailable
121 * 2. check ret and no crash
122 */
123 HWTEST_F(HdiFramebufferSurfaceTest, OnBufferAvailable001, Function | MediumTest| Level3)
124 {
125 // create a HdiFramebufferSurface obj without consumer
126 sptr<HdiFramebufferSurface> fbSurface = new HdiFramebufferSurface();
127 fbSurface->OnBufferAvailable(); // no crash
128 }
129 }
130 } // namespace Rosen
131 } // namespace OHOS