• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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, Hardware
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 <gtest/gtest.h>
17 
18 #include "EGL/egl_wrapper_display.h"
19 
20 #include "egl_defs.h"
21 #include "thread_private_data_ctl.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS::Rosen {
27 class EglWrapperDisplayTest : public testing::Test {
28 public:
SetUpTestCase()29     static void SetUpTestCase() {}
TearDownTestCase()30     static void TearDownTestCase() {}
SetUp()31     void SetUp() {}
TearDown()32     void TearDown() {}
33 };
34 
35 /**
36  * @tc.name: GetWrapperDisplay001
37  * @tc.desc:
38  * @tc.type: FUNC
39  */
HWTEST_F(EglWrapperDisplayTest,GetWrapperDisplay001,Level1)40 HWTEST_F(EglWrapperDisplayTest, GetWrapperDisplay001, Level1)
41 {
42     auto result = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
43     ASSERT_NE(nullptr, result);
44 }
45 
46 /**
47  * @tc.name: GetWrapperDisplay002
48  * @tc.desc:
49  * @tc.type: FUNC
50  */
HWTEST_F(EglWrapperDisplayTest,GetWrapperDisplay002,Level2)51 HWTEST_F(EglWrapperDisplayTest, GetWrapperDisplay002, Level2)
52 {
53     auto result = EglWrapperDisplay::GetWrapperDisplay(nullptr);
54     ASSERT_EQ(nullptr, result);
55 }
56 
57 /**
58  * @tc.name: MakeCurrent001
59  * @tc.desc:
60  * @tc.type: FUNC
61  */
HWTEST_F(EglWrapperDisplayTest,MakeCurrent001,Level1)62 HWTEST_F(EglWrapperDisplayTest, MakeCurrent001, Level1)
63 {
64     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
65     EGLSurface draw = EGL_NO_SURFACE;
66     EGLSurface read = EGL_NO_SURFACE;
67     EGLContext ctx = EGL_NO_CONTEXT;
68 
69     auto result = eglWrapperDisplay->MakeCurrent(draw, read, ctx);
70     ASSERT_EQ(EGL_TRUE, result);
71 }
72 
73 /**
74  * @tc.name: CreateEglContext001
75  * @tc.desc:
76  * @tc.type: FUNC
77  */
HWTEST_F(EglWrapperDisplayTest,CreateEglContext001,Level1)78 HWTEST_F(EglWrapperDisplayTest, CreateEglContext001, Level1)
79 {
80     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
81 
82     auto temp = gWrapperHook.isLoad;
83     gWrapperHook.isLoad = false;
84 
85     auto result = eglWrapperDisplay->CreateEglContext(nullptr, nullptr, 0);
86     ASSERT_EQ(EGL_NO_CONTEXT, result);
87     gWrapperHook.isLoad = temp;
88 }
89 
90 /**
91  * @tc.name: CreateEglContext002
92  * @tc.desc:
93  * @tc.type: FUNC
94  */
HWTEST_F(EglWrapperDisplayTest,CreateEglContext002,Level2)95 HWTEST_F(EglWrapperDisplayTest, CreateEglContext002, Level2)
96 {
97     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
98 
99     auto temp = gWrapperHook.isLoad;
100     gWrapperHook.isLoad = false;
101 
102     auto result = eglWrapperDisplay->CreateEglContext(nullptr, EGL_NO_CONTEXT, 0);
103     ASSERT_EQ(EGL_NO_CONTEXT, result);
104     gWrapperHook.isLoad = temp;
105 }
106 
107 /**
108  * @tc.name: CreateEglSurface001
109  * @tc.desc:
110  * @tc.type: FUNC
111  */
HWTEST_F(EglWrapperDisplayTest,CreateEglSurface001,Level1)112 HWTEST_F(EglWrapperDisplayTest, CreateEglSurface001, Level1)
113 {
114     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
115 
116     auto result = eglWrapperDisplay->CreateEglSurface(nullptr, 0, 0);
117     ASSERT_EQ(EGL_NO_SURFACE, result);
118 }
119 
120 /**
121  * @tc.name: CreateEglSurface002
122  * @tc.desc:
123  * @tc.type: FUNC
124  */
HWTEST_F(EglWrapperDisplayTest,CreateEglSurface002,Level1)125 HWTEST_F(EglWrapperDisplayTest, CreateEglSurface002, Level1)
126 {
127     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
128 
129     auto temp = gWrapperHook.isLoad;
130     gWrapperHook.isLoad = false;
131 
132     NativeWindowType window = nullptr;
133     auto result = eglWrapperDisplay->CreateEglSurface(nullptr, window, 0);
134     ASSERT_EQ(EGL_NO_SURFACE, result);
135     gWrapperHook.isLoad = temp;
136 }
137 
138 /**
139  * @tc.name: CreatePixmapSurface001
140  * @tc.desc:
141  * @tc.type: FUNC
142  */
HWTEST_F(EglWrapperDisplayTest,CreatePixmapSurface001,Level1)143 HWTEST_F(EglWrapperDisplayTest, CreatePixmapSurface001, Level1)
144 {
145     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
146 
147     auto result = eglWrapperDisplay->CreatePixmapSurface(nullptr, 0, 0);
148     ASSERT_EQ(EGL_NO_SURFACE, result);
149 }
150 
151 /**
152  * @tc.name: CreatePixmapSurface002
153  * @tc.desc:
154  * @tc.type: FUNC
155  */
HWTEST_F(EglWrapperDisplayTest,CreatePixmapSurface002,Level2)156 HWTEST_F(EglWrapperDisplayTest, CreatePixmapSurface002, Level2)
157 {
158     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
159 
160     auto temp = gWrapperHook.isLoad;
161     gWrapperHook.isLoad = false;
162 
163     EGLNativePixmapType window = nullptr;
164     auto result = eglWrapperDisplay->CreatePixmapSurface(nullptr, window, 0);
165     ASSERT_EQ(EGL_NO_SURFACE, result);
166     gWrapperHook.isLoad = temp;
167 }
168 
169 /**
170  * @tc.name: CreatePbufferFromClientBuffer001
171  * @tc.desc:
172  * @tc.type: FUNC
173  */
HWTEST_F(EglWrapperDisplayTest,CreatePbufferFromClientBuffer001,Level1)174 HWTEST_F(EglWrapperDisplayTest, CreatePbufferFromClientBuffer001, Level1)
175 {
176     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
177 
178     auto temp = gWrapperHook.isLoad;
179     gWrapperHook.isLoad = false;
180 
181     auto result = eglWrapperDisplay->CreatePbufferFromClientBuffer(0, nullptr, nullptr, 0);
182     ASSERT_EQ(EGL_NO_SURFACE, result);
183     gWrapperHook.isLoad = temp;
184 }
185 
186 /**
187  * @tc.name: CreateImage001
188  * @tc.desc:
189  * @tc.type: FUNC
190  */
HWTEST_F(EglWrapperDisplayTest,CreateImage001,Level1)191 HWTEST_F(EglWrapperDisplayTest, CreateImage001, Level1)
192 {
193     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
194 
195     auto temp = gWrapperHook.isLoad;
196     gWrapperHook.isLoad = false;
197 
198     auto result = eglWrapperDisplay->CreateImage(EGL_NO_CONTEXT, 0, nullptr, nullptr);
199     ASSERT_EQ(EGL_NO_IMAGE_KHR, result);
200     gWrapperHook.isLoad = temp;
201 }
202 
203 /**
204  * @tc.name: CreatePlatformWindowSurface001
205  * @tc.desc:
206  * @tc.type: FUNC
207  */
HWTEST_F(EglWrapperDisplayTest,CreatePlatformWindowSurface001,Level1)208 HWTEST_F(EglWrapperDisplayTest, CreatePlatformWindowSurface001, Level1)
209 {
210     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
211 
212     auto result = eglWrapperDisplay->CreatePlatformWindowSurface(nullptr, nullptr, 0);
213     ASSERT_EQ(EGL_NO_SURFACE, result);
214 }
215 
216 /**
217  * @tc.name: CreatePlatformWindowSurface002
218  * @tc.desc:
219  * @tc.type: FUNC
220  */
HWTEST_F(EglWrapperDisplayTest,CreatePlatformWindowSurface002,Level2)221 HWTEST_F(EglWrapperDisplayTest, CreatePlatformWindowSurface002, Level2)
222 {
223     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
224 
225     auto temp = gWrapperHook.isLoad;
226     gWrapperHook.isLoad = false;
227 
228     auto result = eglWrapperDisplay->CreatePlatformWindowSurface(nullptr, &gWrapperHook, 0);
229     ASSERT_EQ(EGL_NO_SURFACE, result);
230     gWrapperHook.isLoad = temp;
231 }
232 
233 /**
234  * @tc.name: CreatePlatformPixmapSurface001
235  * @tc.desc:
236  * @tc.type: FUNC
237  */
HWTEST_F(EglWrapperDisplayTest,CreatePlatformPixmapSurface001,Level1)238 HWTEST_F(EglWrapperDisplayTest, CreatePlatformPixmapSurface001, Level1)
239 {
240     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
241 
242     auto result = eglWrapperDisplay->CreatePlatformPixmapSurface(nullptr, nullptr, 0);
243     ASSERT_EQ(EGL_NO_SURFACE, result);
244 }
245 
246 /**
247  * @tc.name: CreatePlatformPixmapSurface002
248  * @tc.desc:
249  * @tc.type: FUNC
250  */
HWTEST_F(EglWrapperDisplayTest,CreatePlatformPixmapSurface002,Level2)251 HWTEST_F(EglWrapperDisplayTest, CreatePlatformPixmapSurface002, Level2)
252 {
253     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
254 
255     auto temp = gWrapperHook.isLoad;
256     gWrapperHook.isLoad = false;
257 
258     auto result = eglWrapperDisplay->CreatePlatformPixmapSurface(nullptr, &gWrapperHook, 0);
259     ASSERT_EQ(EGL_NO_SURFACE, result);
260     gWrapperHook.isLoad = temp;
261 }
262 
263 /**
264  * @tc.name: LockSurfaceKHR001
265  * @tc.desc:
266  * @tc.type: FUNC
267  */
HWTEST_F(EglWrapperDisplayTest,LockSurfaceKHR001,Level1)268 HWTEST_F(EglWrapperDisplayTest, LockSurfaceKHR001, Level1)
269 {
270     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
271 
272     auto result = eglWrapperDisplay->LockSurfaceKHR(nullptr, 0);
273     ASSERT_EQ(EGL_FALSE, result);
274 }
275 
276 /**
277  * @tc.name: UnlockSurfaceKHR001
278  * @tc.desc:
279  * @tc.type: FUNC
280  */
HWTEST_F(EglWrapperDisplayTest,UnlockSurfaceKHR001,Level1)281 HWTEST_F(EglWrapperDisplayTest, UnlockSurfaceKHR001, Level1)
282 {
283     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
284 
285     auto temp = gWrapperHook.isLoad;
286     gWrapperHook.isLoad = false;
287 
288     auto result = eglWrapperDisplay->UnlockSurfaceKHR(nullptr);
289     ASSERT_EQ(EGL_FALSE, result);
290     gWrapperHook.isLoad = temp;
291 }
292 
293 /**
294  * @tc.name: CreateImageKHR001
295  * @tc.desc:
296  * @tc.type: FUNC
297  */
HWTEST_F(EglWrapperDisplayTest,CreateImageKHR001,Level1)298 HWTEST_F(EglWrapperDisplayTest, CreateImageKHR001, Level1)
299 {
300     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
301 
302     auto temp = gWrapperHook.isLoad;
303     gWrapperHook.isLoad = false;
304 
305     auto result = eglWrapperDisplay->CreateImageKHR(nullptr, 0, nullptr, nullptr);
306     ASSERT_EQ(EGL_NO_IMAGE_KHR, result);
307     gWrapperHook.isLoad = temp;
308 }
309 
310 /**
311  * @tc.name: DestroyImageKHR001
312  * @tc.desc:
313  * @tc.type: FUNC
314  */
HWTEST_F(EglWrapperDisplayTest,DestroyImageKHR001,Level1)315 HWTEST_F(EglWrapperDisplayTest, DestroyImageKHR001, Level1)
316 {
317     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
318 
319     auto temp = gWrapperHook.isLoad;
320     gWrapperHook.isLoad = false;
321 
322     auto result = eglWrapperDisplay->DestroyImageKHR(nullptr);
323     ASSERT_EQ(EGL_FALSE, result);
324     gWrapperHook.isLoad = temp;
325 }
326 
327 /**
328  * @tc.name: CreateStreamProducerSurfaceKHR001
329  * @tc.desc:
330  * @tc.type: FUNC
331  */
HWTEST_F(EglWrapperDisplayTest,CreateStreamProducerSurfaceKHR001,Level1)332 HWTEST_F(EglWrapperDisplayTest, CreateStreamProducerSurfaceKHR001, Level1)
333 {
334     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
335 
336     auto temp = gWrapperHook.isLoad;
337     gWrapperHook.isLoad = false;
338 
339     auto result = eglWrapperDisplay->CreateStreamProducerSurfaceKHR(nullptr, nullptr, 0);
340     ASSERT_EQ(EGL_NO_SURFACE, result);
341     gWrapperHook.isLoad = temp;
342 }
343 
344 /**
345  * @tc.name: SwapBuffersWithDamageKHR001
346  * @tc.desc:
347  * @tc.type: FUNC
348  */
HWTEST_F(EglWrapperDisplayTest,SwapBuffersWithDamageKHR001,Level1)349 HWTEST_F(EglWrapperDisplayTest, SwapBuffersWithDamageKHR001, Level1)
350 {
351     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
352 
353     auto result = eglWrapperDisplay->SwapBuffersWithDamageKHR(nullptr, 0, 0);
354     ASSERT_EQ(EGL_FALSE, result);
355 }
356 
357 /**
358  * @tc.name: SetDamageRegionKHR001
359  * @tc.desc:
360  * @tc.type: FUNC
361  */
HWTEST_F(EglWrapperDisplayTest,SetDamageRegionKHR001,Level1)362 HWTEST_F(EglWrapperDisplayTest, SetDamageRegionKHR001, Level1)
363 {
364     auto eglWrapperDisplay = EglWrapperDisplay::GetWrapperDisplay((EGLDisplay)&EglWrapperDisplay::wrapperDisp_);
365 
366     auto result = eglWrapperDisplay->SetDamageRegionKHR(nullptr, 0, 0);
367     ASSERT_EQ(EGL_FALSE, result);
368 }
369 } // OHOS::Rosen