• 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, 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 <gtest/gtest.h>
16 #include <iservice_registry.h>
17 #include <native_image.h>
18 #include <EGL/egl.h>
19 #include <EGL/eglext.h>
20 #include "graphic_common_c.h"
21 #include "surface_type.h"
22 #include "window.h"
23 #include "GLES/gl.h"
24 #include "buffer_log.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace std;
29 
30 namespace OHOS::Rosen {
31 using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC;
32 constexpr const char* EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland";
33 constexpr const char* EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland";
34 constexpr int32_t EGL_CONTEXT_CLIENT_VERSION_NUM = 2;
35 constexpr char CHARACTER_WHITESPACE = ' ';
36 constexpr const char* CHARACTER_STRING_WHITESPACE = " ";
37 constexpr const char* EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT";
38 
39 struct TEST_IMAGE {
40     int a;
41     bool b;
42 };
43 
CheckEglExtension(const char * extensions,const char * extension)44 static bool CheckEglExtension(const char* extensions, const char* extension)
45 {
46     size_t extlen = strlen(extension);
47     const char* end = extensions + strlen(extensions);
48 
49     while (extensions < end) {
50         size_t n = 0;
51         /* Skip whitespaces, if any */
52         if (*extensions == CHARACTER_WHITESPACE) {
53             extensions++;
54             continue;
55         }
56         n = strcspn(extensions, CHARACTER_STRING_WHITESPACE);
57         /* Compare strings */
58         if (n == extlen && strncmp(extension, extensions, n) == 0) {
59             return true; /* Found */
60         }
61         extensions += n;
62     }
63     /* Not found */
64     return false;
65 }
66 
GetPlatformEglDisplay(EGLenum platform,void * native_display,const EGLint * attrib_list)67 static EGLDisplay GetPlatformEglDisplay(EGLenum platform, void* native_display, const EGLint* attrib_list)
68 {
69     static GetPlatformDisplayExt eglGetPlatformDisplayExt = NULL;
70 
71     if (!eglGetPlatformDisplayExt) {
72         const char* extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
73         if (extensions &&
74             (CheckEglExtension(extensions, EGL_EXT_PLATFORM_WAYLAND) ||
75                 CheckEglExtension(extensions, EGL_KHR_PLATFORM_WAYLAND))) {
76             eglGetPlatformDisplayExt = (GetPlatformDisplayExt)eglGetProcAddress(EGL_GET_PLATFORM_DISPLAY_EXT);
77         }
78     }
79 
80     if (eglGetPlatformDisplayExt) {
81         return eglGetPlatformDisplayExt(platform, native_display, attrib_list);
82     }
83 
84     return eglGetDisplay((EGLNativeDisplayType)native_display);
85 }
86 
87 class NativeImageTest : public testing::Test {
88 public:
89     static void SetUpTestCase();
90     static void TearDownTestCase();
91 
92     static void InitEglContext();
93     static void Deinit();
94 
95     static inline OH_NativeImage* image = nullptr;
96     static inline OHNativeWindow* nativeWindow = nullptr;
97     static inline GLuint textureId = 0;
98     static inline GLuint textureId2 = 0;
99     static inline EGLDisplay eglDisplay_ = EGL_NO_DISPLAY;
100     static inline EGLContext eglContext_ = EGL_NO_CONTEXT;
101     static inline EGLConfig config_;
102     static void OnFrameAvailable(void *context);
103 };
104 
OnFrameAvailable(void * context)105 void NativeImageTest::OnFrameAvailable(void *context)
106 {
107     (void) context;
108     cout << "OnFrameAvailable is called" << endl;
109 }
110 
SetUpTestCase()111 void NativeImageTest::SetUpTestCase()
112 {
113     image = nullptr;
114     nativeWindow = nullptr;
115     glGenTextures(1, &textureId);
116     glGenTextures(1, &textureId2);
117 }
118 
TearDownTestCase()119 void NativeImageTest::TearDownTestCase()
120 {
121     image = nullptr;
122     nativeWindow = nullptr;
123     Deinit();
124 }
125 
InitEglContext()126 void NativeImageTest::InitEglContext()
127 {
128     if (eglContext_ != EGL_NO_DISPLAY) {
129         return;
130     }
131 
132     BLOGI("Creating EGLContext!!!");
133     eglDisplay_ = GetPlatformEglDisplay(EGL_PLATFORM_OHOS_KHR, EGL_DEFAULT_DISPLAY, NULL);
134     if (eglDisplay_ == EGL_NO_DISPLAY) {
135         BLOGW("Failed to create EGLDisplay gl errno : %{public}x", eglGetError());
136         return;
137     }
138 
139     EGLint major = 0;
140     EGLint minor = 0;
141     if (eglInitialize(eglDisplay_, &major, &minor) == EGL_FALSE) {
142         BLOGE("Failed to initialize EGLDisplay");
143         return;
144     }
145 
146     if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
147         BLOGE("Failed to bind OpenGL ES API");
148         return;
149     }
150 
151     unsigned int ret;
152     EGLint count;
153     EGLint config_attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8,
154         EGL_ALPHA_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, EGL_NONE };
155 
156     ret = eglChooseConfig(eglDisplay_, config_attribs, &config_, 1, &count);
157     if (!(ret && static_cast<unsigned int>(count) >= 1)) {
158         BLOGE("Failed to eglChooseConfig");
159         return;
160     }
161 
162     static const EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, EGL_CONTEXT_CLIENT_VERSION_NUM, EGL_NONE };
163 
164     eglContext_ = eglCreateContext(eglDisplay_, config_, EGL_NO_CONTEXT, context_attribs);
165     if (eglContext_ == EGL_NO_CONTEXT) {
166         BLOGE("Failed to create egl context %{public}x", eglGetError());
167         return;
168     }
169 
170     eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, eglContext_);
171 
172     BLOGW("Create EGL context successfully, version %{public}d.%{public}d", major, minor);
173 }
174 
Deinit()175 void NativeImageTest::Deinit()
176 {
177     if (eglDisplay_ == EGL_NO_DISPLAY) {
178         return;
179     }
180     eglDestroyContext(eglDisplay_, eglContext_);
181     eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
182     eglTerminate(eglDisplay_);
183     eglReleaseThread();
184 
185     eglDisplay_ = EGL_NO_DISPLAY;
186     eglContext_ = EGL_NO_CONTEXT;
187 }
188 
189 /*
190 * Function: OH_NativeImage_Create
191 * Type: Function
192 * Rank: Important(1)
193 * EnvConditions: N/A
194 * CaseDescription: 1. call OH_NativeImage_Create
195 *                  2. check ret
196 * @tc.require: issueI5KG61
197 */
198 HWTEST_F(NativeImageTest, OHNativeImageCreate001, Function | MediumTest | Level1)
199 {
200     image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
201     ASSERT_NE(image, nullptr);
202 }
203 
204 /*
205 * Function: OH_NativeImage_AcquireNativeWindow
206 * Type: Function
207 * Rank: Important(2)
208 * EnvConditions: N/A
209 * CaseDescription: 1. call OH_NativeImage_AcquireNativeWindow by abnormal input
210 *                  2. check ret
211 * @tc.require: issueI5KG61
212 */
213 HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindow001, Function | MediumTest | Level2)
214 {
215     nativeWindow = OH_NativeImage_AcquireNativeWindow(nullptr);
216     ASSERT_EQ(nativeWindow, nullptr);
217 }
218 
219 /*
220 * Function: OH_NativeImage_AcquireNativeWindow
221 * Type: Function
222 * Rank: Important(1)
223 * EnvConditions: N/A
224 * CaseDescription: 1. call OH_NativeImage_AcquireNativeWindow
225 *                  2. check ret
226 * @tc.require: issueI5KG61
227 */
228 HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindow002, Function | MediumTest | Level1)
229 {
230     nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
231     ASSERT_NE(nativeWindow, nullptr);
232 }
233 
234 /*
235 * Function: OH_NativeImage_AttachContext
236 * Type: Function
237 * Rank: Important(2)
238 * EnvConditions: N/A
239 * CaseDescription: 1. call OH_NativeImage_AttachContext by abnormal input
240 *                  2. check ret
241 * @tc.require: issueI5KG61
242 */
243 HWTEST_F(NativeImageTest, OHNativeImageAttachContext001, Function | MediumTest | Level2)
244 {
245     int32_t ret = OH_NativeImage_AttachContext(nullptr, textureId);
246     ASSERT_NE(ret, SURFACE_ERROR_OK);
247 }
248 
249 /*
250 * Function: OH_NativeImage_DetachContext
251 * Type: Function
252 * Rank: Important(2)
253 * EnvConditions: N/A
254 * CaseDescription: 1. call OH_NativeImage_DetachContext by abnormal input
255 *                  2. check ret
256 * @tc.require: issueI5KG61
257 */
258 HWTEST_F(NativeImageTest, OHNativeImageDetachContext001, Function | MediumTest | Level2)
259 {
260     int32_t ret = OH_NativeImage_DetachContext(nullptr);
261     ASSERT_NE(ret, SURFACE_ERROR_OK);
262 }
263 
264 /*
265 * Function: OH_NativeImage_DetachContext
266 * Type: Function
267 * Rank: Important(1)
268 * EnvConditions: N/A
269 * CaseDescription: 1. call OH_NativeImage_DetachContext
270 *                  2. check ret
271 * @tc.require: issueI5KG61
272 */
273 HWTEST_F(NativeImageTest, OHNativeImageDetachContext002, Function | MediumTest | Level1)
274 {
275     int32_t ret = OH_NativeImage_DetachContext(image);
276     ASSERT_EQ(ret, SURFACE_ERROR_INIT);
277 }
278 
279 /*
280 * Function: OH_NativeImage_DetachContext
281 * Type: Function
282 * Rank: Important(1)
283 * EnvConditions: N/A
284 * CaseDescription: 1. call OH_NativeImage_DetachContext
285 *                  2. check ret
286 * @tc.require: issueI5KG61
287 */
288 HWTEST_F(NativeImageTest, OHNativeImageDetachContext003, Function | MediumTest | Level1)
289 {
290     InitEglContext();
291     int32_t ret = OH_NativeImage_DetachContext(image);
292     ASSERT_EQ(ret, SURFACE_ERROR_OK);
293 }
294 
295 /*
296 * Function: OH_NativeImage_AttachContext
297 * Type: Function
298 * Rank: Important(1)
299 * EnvConditions: N/A
300 * CaseDescription: 1. call OH_NativeImage_AttachContext
301 *                  2. check ret
302 * @tc.require: issueI5KG61
303 */
304 HWTEST_F(NativeImageTest, OHNativeImageAttachContext002, Function | MediumTest | Level1)
305 {
306     int32_t ret = OH_NativeImage_AttachContext(image, textureId);
307     ASSERT_EQ(ret, SURFACE_ERROR_OK);
308 }
309 
310 /*
311 * Function: OH_NativeImage_UpdateSurfaceImage
312 * Type: Function
313 * Rank: Important(2)
314 * EnvConditions: N/A
315 * CaseDescription: 1. call OH_NativeImage_UpdateSurfaceImage by abnormal input
316 *                  2. check ret
317 * @tc.require: issueI5KG61
318 */
319 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage001, Function | MediumTest | Level2)
320 {
321     int32_t ret = OH_NativeImage_UpdateSurfaceImage(nullptr);
322     ASSERT_NE(ret, SURFACE_ERROR_OK);
323 }
324 
325 /*
326 * Function: OH_NativeImage_UpdateSurfaceImage
327 * Type: Function
328 * Rank: Important(1)
329 * EnvConditions: N/A
330 * CaseDescription: 1. call OH_NativeImage_UpdateSurfaceImage
331 *                  2. check ret
332 * @tc.require: issueI5KG61
333 */
334 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage002, Function | MediumTest | Level1)
335 {
336     int32_t ret = OH_NativeImage_UpdateSurfaceImage(image);
337     ASSERT_NE(ret, SURFACE_ERROR_OK);
338 }
339 
340 /*
341 * Function: OH_NativeImage_UpdateSurfaceImage
342 * Type: Function
343 * Rank: Important(1)
344 * EnvConditions: N/A
345 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
346 *                  2. call OH_NativeWindow_NativeWindowFlushBuffer
347 *                  3. OH_NativeImage_UpdateSurfaceImage
348 *                  4. check ret
349 * @tc.require: issueI5KG61
350 */
351 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage003, Function | MediumTest | Level1)
352 {
353     int code = SET_USAGE;
354     uint64_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA;
355     int32_t ret = NativeWindowHandleOpt(nativeWindow, code, usage);
356     if (ret != GSERROR_OK) {
357         std::cout << "NativeWindowHandleOpt SET_USAGE faile" << std::endl;
358     }
359     code = SET_BUFFER_GEOMETRY;
360     int32_t width = 0x100;
361     int32_t height = 0x100;
362     ret = NativeWindowHandleOpt(nativeWindow, code, width, height);
363     if (ret != GSERROR_OK) {
364         std::cout << "NativeWindowHandleOpt SET_BUFFER_GEOMETRY failed" << std::endl;
365     }
366     code = SET_STRIDE;
367     int32_t stride = 0x8;
368     ret = NativeWindowHandleOpt(nativeWindow, code, stride);
369     if (ret != GSERROR_OK) {
370         std::cout << "NativeWindowHandleOpt SET_STRIDE failed" << std::endl;
371     }
372     code = SET_FORMAT;
373     int32_t format = GRAPHIC_PIXEL_FMT_RGBA_8888;
374     ret = NativeWindowHandleOpt(nativeWindow, code, format);
375     if (ret != GSERROR_OK) {
376         std::cout << "NativeWindowHandleOpt SET_FORMAT failed" << std::endl;
377     }
378 
379     NativeWindowBuffer* nativeWindowBuffer = nullptr;
380     int fenceFd = -1;
381     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
382     ASSERT_EQ(ret, GSERROR_OK);
383 
384     struct Region *region = new Region();
385     struct Region::Rect *rect = new Region::Rect();
386     rect->x = 0x100;
387     rect->y = 0x100;
388     rect->w = 0x100;
389     rect->h = 0x100;
390     region->rects = rect;
391     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
392     ASSERT_EQ(ret, GSERROR_OK);
393     delete region;
394 
395     ret = OH_NativeImage_UpdateSurfaceImage(image);
396     ASSERT_EQ(ret, SURFACE_ERROR_OK);
397 }
398 
399 /*
400 * Function: OH_NativeImage_GetTimestamp
401 * Type: Function
402 * Rank: Important(2)
403 * EnvConditions: N/A
404 * CaseDescription: 1. call OH_NativeImage_GetTimestamp by abnormal input
405 *                  2. check ret
406 * @tc.require: issueI5KG61
407 */
408 HWTEST_F(NativeImageTest, OHNativeImageGetTimestamp001, Function | MediumTest | Level2)
409 {
410     int64_t timeStamp = OH_NativeImage_GetTimestamp(nullptr);
411     ASSERT_EQ(timeStamp, SURFACE_ERROR_ERROR);
412 }
413 
414 /*
415 * Function: OH_NativeImage_GetTimestamp
416 * Type: Function
417 * Rank: Important(1)
418 * EnvConditions: N/A
419 * CaseDescription: 1. call OH_NativeImage_GetTimestamp
420 *                  2. check ret
421 * @tc.require: issueI5KG61
422 */
423 HWTEST_F(NativeImageTest, OHNativeImageGetTimestamp002, Function | MediumTest | Level1)
424 {
425     int64_t timeStamp = OH_NativeImage_GetTimestamp(image);
426     ASSERT_NE(timeStamp, SURFACE_ERROR_ERROR);
427 }
428 
429 /*
430 * Function: OH_NativeImage_GetTransformMatrix
431 * Type: Function
432 * Rank: Important(2)
433 * EnvConditions: N/A
434 * CaseDescription: 1. call OH_NativeImage_GetTransformMatrix by abnormal input
435 *                  2. check ret
436 * @tc.require: issueI5KG61
437 */
438 HWTEST_F(NativeImageTest, OHNativeImageGetTransformMatrix001, Function | MediumTest | Level2)
439 {
440     float matrix[16];
441     int32_t ret = OH_NativeImage_GetTransformMatrix(nullptr, matrix);
442     ASSERT_NE(ret, SURFACE_ERROR_OK);
443 }
444 
445 /*
446 * Function: OH_NativeImage_GetTransformMatrix
447 * Type: Function
448 * Rank: Important(1)
449 * EnvConditions: N/A
450 * CaseDescription: 1. call OH_NativeImage_GetTransformMatrix
451 *                  2. check ret
452 * @tc.require: issueI5KG61
453 */
454 HWTEST_F(NativeImageTest, OHNativeImageGetTransformMatrix002, Function | MediumTest | Level1)
455 {
456     float matrix[16];
457     int32_t ret = OH_NativeImage_GetTransformMatrix(image, matrix);
458     ASSERT_EQ(ret, SURFACE_ERROR_OK);
459 }
460 
461 /*
462 * Function: OH_NativeImage_AttachContext
463 * Type: Function
464 * Rank: Important(1)
465 * EnvConditions: N/A
466 * CaseDescription: 1. call OH_NativeImage_AttachContext with another texture
467 *                  2. check ret
468 * @tc.require: issueI5KG61
469 */
470 HWTEST_F(NativeImageTest, OHNativeImageAttachContext003, Function | MediumTest | Level1)
471 {
472     int32_t ret = OH_NativeImage_AttachContext(image, textureId2);
473     ASSERT_EQ(ret, SURFACE_ERROR_OK);
474 }
475 
476 /*
477 * Function: OH_NativeImage_UpdateSurfaceImage
478 * Type: Function
479 * Rank: Important(1)
480 * EnvConditions: N/A
481 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
482 *                  2. call OH_NativeWindow_NativeWindowFlushBuffer
483 *                  3. OH_NativeImage_UpdateSurfaceImage after the bound OPENGL ES texture changed
484 *                  4. check ret
485 * @tc.require: issueI5KG61
486 */
487 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage004, Function | MediumTest | Level1)
488 {
489     NativeWindowBuffer* nativeWindowBuffer = nullptr;
490     int fenceFd = -1;
491     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
492     ASSERT_EQ(ret, GSERROR_OK);
493 
494     struct Region *region = new Region();
495     struct Region::Rect *rect = new Region::Rect();
496     rect->x = 0x100;
497     rect->y = 0x100;
498     rect->w = 0x100;
499     rect->h = 0x100;
500     region->rects = rect;
501     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
502     ASSERT_EQ(ret, GSERROR_OK);
503     delete region;
504 
505     ret = OH_NativeImage_UpdateSurfaceImage(image);
506     ASSERT_EQ(ret, SURFACE_ERROR_OK);
507 }
508 
509 /*
510 * Function: OH_NativeImage_DetachContext
511 * Type: Function
512 * Rank: Important(1)
513 * EnvConditions: N/A
514 * CaseDescription: 1. call OH_NativeImage_DetachContext
515 *                  2. check ret
516 * @tc.require: issueI5KG61
517 */
518 HWTEST_F(NativeImageTest, OHNativeImageDetachContext004, Function | MediumTest | Level1)
519 {
520     int32_t ret = OH_NativeImage_DetachContext(image);
521     ASSERT_EQ(ret, SURFACE_ERROR_OK);
522 }
523 
524 /*
525 * Function: OH_NativeImage_AttachContext
526 * Type: Function
527 * Rank: Important(1)
528 * EnvConditions: N/A
529 * CaseDescription: 1. call OH_NativeImage_AttachContext after OH_NativeImage_DetachContext
530 *                  2. check ret
531 * @tc.require: issueI5KG61
532 */
533 HWTEST_F(NativeImageTest, OHNativeImageAttachContext004, Function | MediumTest | Level1)
534 {
535     int32_t ret = OH_NativeImage_AttachContext(image, textureId2);
536     ASSERT_EQ(ret, SURFACE_ERROR_OK);
537 }
538 
539 /*
540 * Function: OH_NativeImage_UpdateSurfaceImage
541 * Type: Function
542 * Rank: Important(1)
543 * EnvConditions: N/A
544 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
545 *                  2. call OH_NativeWindow_NativeWindowFlushBuffer
546 *                  3. OH_NativeImage_UpdateSurfaceImage again
547 *                  4. check ret
548 * @tc.require: issueI5KG61
549 */
550 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage005, Function | MediumTest | Level1)
551 {
552     NativeWindowBuffer* nativeWindowBuffer = nullptr;
553     int fenceFd = -1;
554     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
555     ASSERT_EQ(ret, GSERROR_OK);
556 
557     struct Region *region = new Region();
558     struct Region::Rect *rect = new Region::Rect();
559     rect->x = 0x100;
560     rect->y = 0x100;
561     rect->w = 0x100;
562     rect->h = 0x100;
563     region->rects = rect;
564     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
565     ASSERT_EQ(ret, GSERROR_OK);
566     delete region;
567 
568     ret = OH_NativeImage_UpdateSurfaceImage(image);
569     ASSERT_EQ(ret, SURFACE_ERROR_OK);
570 }
571 
572 /*
573 * Function: OH_NativeImage_GetSurfaceId
574 * Type: Function
575 * Rank: Important(1)
576 * EnvConditions: N/A
577 * CaseDescription: 1. create image
578 *                  2. GetSurfaceId
579 *                  2. check ret
580 * @tc.require: issueI86VH2
581 */
582 HWTEST_F(NativeImageTest, OHNativeImageGetSurfaceId001, Function | MediumTest | Level1)
583 {
584     if (image == nullptr) {
585         image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
586         ASSERT_NE(image, nullptr);
587     }
588 
589     uint64_t surfaceId;
590     int32_t ret = OH_NativeImage_GetSurfaceId(image, &surfaceId);
591     ASSERT_EQ(ret, SURFACE_ERROR_OK);
592 }
593 
594 /*
595 * Function: OH_NativeImage_SetOnFrameAvailableListener
596 * Type: Function
597 * Rank: Important(1)
598 * EnvConditions: N/A
599 * CaseDescription: 1. check image and nativeWindow
600 *                  2. call OH_NativeImage_SetOnFrameAvailableListener
601 *                  3. call OH_NativeWindow_NativeWindowFlushBuffer
602 *                  4. check OnFrameAvailable is called
603 * @tc.require: issueI86VH2
604 */
605 HWTEST_F(NativeImageTest, OHNativeImageSetOnFrameAvailableListener001, Function | MediumTest | Level1)
606 {
607     if (image == nullptr) {
608         image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
609         ASSERT_NE(image, nullptr);
610     }
611 
612     if (nativeWindow == nullptr) {
613         nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
614         ASSERT_NE(nativeWindow, nullptr);
615     }
616 
617     OH_OnFrameAvailableListener listener;
618     listener.context = this;
619     listener.onFrameAvailable = NativeImageTest::OnFrameAvailable;
620     int32_t ret = OH_NativeImage_SetOnFrameAvailableListener(image, listener);
621     ASSERT_EQ(ret, GSERROR_OK);
622 
623     NativeWindowBuffer* nativeWindowBuffer = nullptr;
624     int fenceFd = -1;
625     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
626     ASSERT_EQ(ret, GSERROR_OK);
627 
628     struct Region *region = new Region();
629     struct Region::Rect *rect = new Region::Rect();
630     rect->x = 0x100;
631     rect->y = 0x100;
632     rect->w = 0x100;
633     rect->h = 0x100;
634     region->rects = rect;
635     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
636     ASSERT_EQ(ret, GSERROR_OK);
637     delete region;
638 
639     ret = OH_NativeImage_UpdateSurfaceImage(image);
640     ASSERT_EQ(ret, SURFACE_ERROR_OK);
641 }
642 
643 /*
644 * Function: OH_NativeImage_UnsetOnFrameAvailableListener
645 * Type: Function
646 * Rank: Important(1)
647 * EnvConditions: N/A
648 * CaseDescription: 1. call OH_NativeImage_UnsetOnFrameAvailableListener
649 *                  2. check ret
650 * @tc.require: issueI86VH2
651 */
652 HWTEST_F(NativeImageTest, OHNativeImageUnsetOnFrameAvailableListener001, Function | MediumTest | Level1)
653 {
654     int32_t ret = OH_NativeImage_UnsetOnFrameAvailableListener(image);
655     ASSERT_EQ(ret, SURFACE_ERROR_OK);
656 }
657 
658 /*
659 * Function: OH_NativeImage_Destroy
660 * Type: Function
661 * Rank: Important(2)
662 * EnvConditions: N/A
663 * CaseDescription: 1. call OH_NativeImage_Destroy by abnormal input
664 *                  2. check ret
665 * @tc.require: issueI5KG61
666 */
667 HWTEST_F(NativeImageTest, OHNativeImageDestroy001, Function | MediumTest | Level2)
668 {
669     OH_NativeImage_Destroy(nullptr);
670     ASSERT_NE(image, nullptr);
671 }
672 
673 /*
674 * Function: OH_NativeImage_Destroy
675 * Type: Function
676 * Rank: Important(1)
677 * EnvConditions: N/A
678 * CaseDescription: 1. call OH_NativeImage_Destroy
679 *                  2. check ret
680 * @tc.require: issueI5KG61
681 */
682 HWTEST_F(NativeImageTest, OHNativeImageDestroy002, Function | MediumTest | Level1)
683 {
684     OH_NativeImage_Destroy(&image);
685     ASSERT_EQ(image, nullptr);
686 }
687 }