• 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 <sys/time.h>
21 #include <securec.h>
22 #include "graphic_common_c.h"
23 #include "surface_type.h"
24 #include "window.h"
25 #include "GLES/gl.h"
26 #include "buffer_log.h"
27 #include "metadata_helper.h"
28 #include "surface.h"
29 #include "surface_image.h"
30 
31 using namespace testing;
32 using namespace testing::ext;
33 using namespace std;
34 
35 namespace OHOS::Rosen {
36 using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC;
37 constexpr const char* EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland";
38 constexpr const char* EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland";
39 constexpr int32_t EGL_CONTEXT_CLIENT_VERSION_NUM = 2;
40 constexpr char CHARACTER_WHITESPACE = ' ';
41 constexpr const char* CHARACTER_STRING_WHITESPACE = " ";
42 constexpr const char* EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT";
43 constexpr int32_t MATRIX_SIZE = 16;
44 
45 struct TEST_IMAGE {
46     int a;
47     bool b;
48 };
49 
50 typedef struct OH_NativeImage_Tmp {
51     OHOS::sptr<OHOS::SurfaceImage> consumer;
52     OHOS::sptr<OHOS::IBufferProducer> producer;
53     OHOS::sptr<OHOS::Surface> pSurface = nullptr;
54     struct NativeWindow* nativeWindow = nullptr;
55 } OH_NativeImage_Tmp;
56 
CheckEglExtension(const char * extensions,const char * extension)57 static bool CheckEglExtension(const char* extensions, const char* extension)
58 {
59     size_t extlen = strlen(extension);
60     const char* end = extensions + strlen(extensions);
61 
62     while (extensions < end) {
63         size_t n = 0;
64         /* Skip whitespaces, if any */
65         if (*extensions == CHARACTER_WHITESPACE) {
66             extensions++;
67             continue;
68         }
69         n = strcspn(extensions, CHARACTER_STRING_WHITESPACE);
70         /* Compare strings */
71         if (n == extlen && strncmp(extension, extensions, n) == 0) {
72             return true; /* Found */
73         }
74         extensions += n;
75     }
76     /* Not found */
77     return false;
78 }
79 
GetPlatformEglDisplay(EGLenum platform,void * nativeDisplay,const EGLint * attribList)80 static EGLDisplay GetPlatformEglDisplay(EGLenum platform, void* nativeDisplay, const EGLint* attribList)
81 {
82     static GetPlatformDisplayExt eglGetPlatformDisplayExt = NULL;
83 
84     if (!eglGetPlatformDisplayExt) {
85         const char* extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
86         if (extensions &&
87             (CheckEglExtension(extensions, EGL_EXT_PLATFORM_WAYLAND) ||
88                 CheckEglExtension(extensions, EGL_KHR_PLATFORM_WAYLAND))) {
89             eglGetPlatformDisplayExt = (GetPlatformDisplayExt)eglGetProcAddress(EGL_GET_PLATFORM_DISPLAY_EXT);
90         }
91     }
92 
93     if (eglGetPlatformDisplayExt) {
94         return eglGetPlatformDisplayExt(platform, nativeDisplay, attribList);
95     }
96 
97     return eglGetDisplay((EGLNativeDisplayType)nativeDisplay);
98 }
99 
100 class NativeImageTest : public testing::Test {
101 public:
102     static void SetUpTestCase();
103     static void TearDownTestCase();
104 
105     static void InitEglContext();
106     static void Deinit();
107 
108     static inline OH_NativeImage* image = nullptr;
109     static inline OHNativeWindow* nativeWindow = nullptr;
110     static inline GLuint textureId = 0;
111     static inline GLuint textureId2 = 0;
112     static inline EGLDisplay eglDisplay_ = EGL_NO_DISPLAY;
113     static inline EGLContext eglContext_ = EGL_NO_CONTEXT;
114     static inline EGLConfig config_;
115     static void OnFrameAvailable(void *context);
116 };
117 
OnFrameAvailable(void * context)118 void NativeImageTest::OnFrameAvailable(void *context)
119 {
120     (void) context;
121     cout << "OnFrameAvailable is called" << endl;
122 }
123 
SetUpTestCase()124 void NativeImageTest::SetUpTestCase()
125 {
126     image = nullptr;
127     nativeWindow = nullptr;
128     glGenTextures(1, &textureId);
129     glGenTextures(1, &textureId2);
130 }
131 
TearDownTestCase()132 void NativeImageTest::TearDownTestCase()
133 {
134     image = nullptr;
135     nativeWindow = nullptr;
136     Deinit();
137 }
138 
InitEglContext()139 void NativeImageTest::InitEglContext()
140 {
141     if (eglContext_ != EGL_NO_DISPLAY) {
142         return;
143     }
144 
145     BLOGI("Creating EGLContext!!!");
146     eglDisplay_ = GetPlatformEglDisplay(EGL_PLATFORM_OHOS_KHR, EGL_DEFAULT_DISPLAY, NULL);
147     if (eglDisplay_ == EGL_NO_DISPLAY) {
148         BLOGW("Failed to create EGLDisplay gl errno : %{public}x", eglGetError());
149         return;
150     }
151 
152     EGLint major = 0;
153     EGLint minor = 0;
154     if (eglInitialize(eglDisplay_, &major, &minor) == EGL_FALSE) {
155         BLOGE("Failed to initialize EGLDisplay");
156         return;
157     }
158 
159     if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
160         BLOGE("Failed to bind OpenGL ES API");
161         return;
162     }
163 
164     unsigned int ret;
165     EGLint count;
166     EGLint config_attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8,
167         EGL_ALPHA_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, EGL_NONE };
168 
169     ret = eglChooseConfig(eglDisplay_, config_attribs, &config_, 1, &count);
170     if (!(ret && static_cast<unsigned int>(count) >= 1)) {
171         BLOGE("Failed to eglChooseConfig");
172         return;
173     }
174 
175     static const EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, EGL_CONTEXT_CLIENT_VERSION_NUM, EGL_NONE };
176 
177     eglContext_ = eglCreateContext(eglDisplay_, config_, EGL_NO_CONTEXT, context_attribs);
178     if (eglContext_ == EGL_NO_CONTEXT) {
179         BLOGE("Failed to create egl context %{public}x", eglGetError());
180         return;
181     }
182 
183     eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, eglContext_);
184 
185     BLOGW("Create EGL context successfully, version %{public}d.%{public}d", major, minor);
186 }
187 
Deinit()188 void NativeImageTest::Deinit()
189 {
190     if (eglDisplay_ == EGL_NO_DISPLAY) {
191         return;
192     }
193     eglDestroyContext(eglDisplay_, eglContext_);
194     eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
195     eglTerminate(eglDisplay_);
196     eglReleaseThread();
197 
198     eglDisplay_ = EGL_NO_DISPLAY;
199     eglContext_ = EGL_NO_CONTEXT;
200 }
201 
202 /*
203 * Function: OH_NativeImage_Create
204 * Type: Function
205 * Rank: Important(1)
206 * EnvConditions: N/A
207 * CaseDescription: 1. call OH_NativeImage_Create
208 *                  2. check ret
209 * @tc.require: issueI5KG61
210 */
211 HWTEST_F(NativeImageTest, OHNativeImageCreate001, Function | MediumTest | Level1)
212 {
213     image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
214     ASSERT_NE(image, nullptr);
215 }
216 
217 /*
218 * Function: OH_NativeImage_AcquireNativeWindow
219 * Type: Function
220 * Rank: Important(2)
221 * EnvConditions: N/A
222 * CaseDescription: 1. call OH_NativeImage_AcquireNativeWindow by abnormal input
223 *                  2. check ret
224 * @tc.require: issueI5KG61
225 */
226 HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindow001, Function | MediumTest | Level2)
227 {
228     nativeWindow = OH_NativeImage_AcquireNativeWindow(nullptr);
229     ASSERT_EQ(nativeWindow, nullptr);
230 }
231 
232 /*
233 * Function: OH_NativeImage_AcquireNativeWindow
234 * Type: Function
235 * Rank: Important(1)
236 * EnvConditions: N/A
237 * CaseDescription: 1. call OH_NativeImage_AcquireNativeWindow
238 *                  2. check ret
239 * @tc.require: issueI5KG61
240 */
241 HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindow002, Function | MediumTest | Level1)
242 {
243     nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
244     ASSERT_NE(nativeWindow, nullptr);
245 }
246 
247 /*
248 * Function: OH_NativeImage_AttachContext
249 * Type: Function
250 * Rank: Important(2)
251 * EnvConditions: N/A
252 * CaseDescription: 1. call OH_NativeImage_AttachContext by abnormal input
253 *                  2. check ret
254 * @tc.require: issueI5KG61
255 */
256 HWTEST_F(NativeImageTest, OHNativeImageAttachContext001, Function | MediumTest | Level2)
257 {
258     int32_t ret = OH_NativeImage_AttachContext(nullptr, textureId);
259     ASSERT_NE(ret, SURFACE_ERROR_OK);
260 }
261 
262 /*
263 * Function: OH_NativeImage_DetachContext
264 * Type: Function
265 * Rank: Important(2)
266 * EnvConditions: N/A
267 * CaseDescription: 1. call OH_NativeImage_DetachContext by abnormal input
268 *                  2. check ret
269 * @tc.require: issueI5KG61
270 */
271 HWTEST_F(NativeImageTest, OHNativeImageDetachContext001, Function | MediumTest | Level2)
272 {
273     int32_t ret = OH_NativeImage_DetachContext(nullptr);
274     ASSERT_NE(ret, SURFACE_ERROR_OK);
275 }
276 
277 /*
278 * Function: OH_NativeImage_DetachContext
279 * Type: Function
280 * Rank: Important(1)
281 * EnvConditions: N/A
282 * CaseDescription: 1. call OH_NativeImage_DetachContext
283 *                  2. check ret
284 * @tc.require: issueI5KG61
285 */
286 HWTEST_F(NativeImageTest, OHNativeImageDetachContext002, Function | MediumTest | Level1)
287 {
288     int32_t ret = OH_NativeImage_DetachContext(image);
289     ASSERT_EQ(ret, SURFACE_ERROR_EGL_STATE_UNKONW);
290 }
291 
292 /*
293 * Function: OH_NativeImage_DetachContext
294 * Type: Function
295 * Rank: Important(1)
296 * EnvConditions: N/A
297 * CaseDescription: 1. call OH_NativeImage_DetachContext
298 *                  2. check ret
299 * @tc.require: issueI5KG61
300 */
301 HWTEST_F(NativeImageTest, OHNativeImageDetachContext003, Function | MediumTest | Level1)
302 {
303     InitEglContext();
304     int32_t ret = OH_NativeImage_DetachContext(image);
305     ASSERT_EQ(ret, SURFACE_ERROR_OK);
306 }
307 
308 /*
309 * Function: OH_NativeImage_AttachContext
310 * Type: Function
311 * Rank: Important(1)
312 * EnvConditions: N/A
313 * CaseDescription: 1. call OH_NativeImage_AttachContext
314 *                  2. check ret
315 * @tc.require: issueI5KG61
316 */
317 HWTEST_F(NativeImageTest, OHNativeImageAttachContext002, Function | MediumTest | Level1)
318 {
319     int32_t ret = OH_NativeImage_AttachContext(image, textureId);
320     ASSERT_EQ(ret, SURFACE_ERROR_OK);
321 }
322 
323 /*
324 * Function: OH_NativeImage_UpdateSurfaceImage
325 * Type: Function
326 * Rank: Important(2)
327 * EnvConditions: N/A
328 * CaseDescription: 1. call OH_NativeImage_UpdateSurfaceImage by abnormal input
329 *                  2. check ret
330 * @tc.require: issueI5KG61
331 */
332 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage001, Function | MediumTest | Level2)
333 {
334     int32_t ret = OH_NativeImage_UpdateSurfaceImage(nullptr);
335     ASSERT_NE(ret, SURFACE_ERROR_OK);
336 }
337 
338 /*
339 * Function: OH_NativeImage_UpdateSurfaceImage
340 * Type: Function
341 * Rank: Important(1)
342 * EnvConditions: N/A
343 * CaseDescription: 1. call OH_NativeImage_UpdateSurfaceImage
344 *                  2. check ret
345 * @tc.require: issueI5KG61
346 */
347 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage002, Function | MediumTest | Level1)
348 {
349     int32_t ret = OH_NativeImage_UpdateSurfaceImage(image);
350     ASSERT_NE(ret, SURFACE_ERROR_OK);
351 }
352 
353 /*
354 * Function: OH_NativeImage_UpdateSurfaceImage
355 * Type: Function
356 * Rank: Important(1)
357 * EnvConditions: N/A
358 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
359 *                  2. call OH_NativeWindow_NativeWindowFlushBuffer
360 *                  3. OH_NativeImage_UpdateSurfaceImage
361 *                  4. check ret
362 * @tc.require: issueI5KG61
363 */
364 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage003, Function | MediumTest | Level1)
365 {
366     int code = SET_USAGE;
367     uint64_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA;
368     int32_t ret = NativeWindowHandleOpt(nativeWindow, code, usage);
369     if (ret != GSERROR_OK) {
370         std::cout << "NativeWindowHandleOpt SET_USAGE faile" << std::endl;
371     }
372     code = SET_BUFFER_GEOMETRY;
373     int32_t width = 0x100;
374     int32_t height = 0x100;
375     ret = NativeWindowHandleOpt(nativeWindow, code, width, height);
376     if (ret != GSERROR_OK) {
377         std::cout << "NativeWindowHandleOpt SET_BUFFER_GEOMETRY failed" << std::endl;
378     }
379     code = SET_STRIDE;
380     int32_t stride = 0x8;
381     ret = NativeWindowHandleOpt(nativeWindow, code, stride);
382     if (ret != GSERROR_OK) {
383         std::cout << "NativeWindowHandleOpt SET_STRIDE failed" << std::endl;
384     }
385     code = SET_FORMAT;
386     int32_t format = GRAPHIC_PIXEL_FMT_RGBA_8888;
387     ret = NativeWindowHandleOpt(nativeWindow, code, format);
388     if (ret != GSERROR_OK) {
389         std::cout << "NativeWindowHandleOpt SET_FORMAT failed" << std::endl;
390     }
391 
392     NativeWindowBuffer* nativeWindowBuffer = nullptr;
393     int fenceFd = -1;
394     struct Region *region = new Region();
395     struct Region::Rect *rect = new Region::Rect();
396     rect->x = 0x100;
397     rect->y = 0x100;
398     rect->w = 0x100;
399     rect->h = 0x100;
400     region->rects = rect;
401     for (int32_t i = 0; i < 2; i++) {
402         ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
403         ASSERT_EQ(ret, GSERROR_OK);
404         ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
405         ASSERT_EQ(ret, GSERROR_OK);
406 
407         ret = OH_NativeImage_UpdateSurfaceImage(image);
408         ASSERT_EQ(ret, SURFACE_ERROR_OK);
409         ASSERT_EQ(NativeWindowDisconnect(nativeWindow), SURFACE_ERROR_OK);
410     }
411     delete region;
412 }
413 
414 /*
415 * Function: OH_NativeImage_UpdateSurfaceImage
416 * Type: Function
417 * Rank: Important(1)
418 * EnvConditions: N/A
419 * CaseDescription: 1. call OH_NativeImage_UpdateSurfaceImage
420 *                  2. check ret
421 * @tc.require: issueI5KG61
422 */
423 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage006, Function | MediumTest | Level1)
424 {
425     OH_NativeImage* imageNew = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
426     ASSERT_NE(imageNew, nullptr);
427     memset_s(imageNew, sizeof(OH_NativeImage_Tmp), 0, sizeof(OH_NativeImage_Tmp));
428     int32_t ret = OH_NativeImage_UpdateSurfaceImage(imageNew);
429     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
430 
431     OH_NativeImage_Destroy(&imageNew);
432 }
433 
434 /*
435 * Function: OH_NativeImage_GetTimestamp
436 * Type: Function
437 * Rank: Important(2)
438 * EnvConditions: N/A
439 * CaseDescription: 1. call OH_NativeImage_GetTimestamp by abnormal input
440 *                  2. check ret
441 * @tc.require: issueI5KG61
442 */
443 HWTEST_F(NativeImageTest, OHNativeImageGetTimestamp001, Function | MediumTest | Level2)
444 {
445     int64_t timeStamp = OH_NativeImage_GetTimestamp(nullptr);
446     ASSERT_EQ(timeStamp, -1);
447 }
448 
449 /*
450 * Function: OH_NativeImage_GetTimestamp
451 * Type: Function
452 * Rank: Important(1)
453 * EnvConditions: N/A
454 * CaseDescription: 1. call OH_NativeImage_GetTimestamp
455 *                  2. check ret
456 * @tc.require: issueI5KG61
457 */
458 HWTEST_F(NativeImageTest, OHNativeImageGetTimestamp002, Function | MediumTest | Level1)
459 {
460     int64_t timeStamp = OH_NativeImage_GetTimestamp(image);
461     ASSERT_NE(timeStamp, SURFACE_ERROR_ERROR);
462 }
463 
464 /*
465 * Function: OH_NativeImage_GetTimestamp
466 * Type: Function
467 * Rank: Important(1)
468 * EnvConditions: N/A
469 * CaseDescription: 1. call OH_NativeImage_GetTimestamp
470 *                  2. check ret
471 * @tc.require: issueI5KG61
472 */
473 HWTEST_F(NativeImageTest, OHNativeImageGetTimestamp003, Function | MediumTest | Level1)
474 {
475     OH_NativeImage* imageNew = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
476     ASSERT_NE(imageNew, nullptr);
477     memset_s(imageNew, sizeof(OH_NativeImage_Tmp), 0, sizeof(OH_NativeImage_Tmp));
478     int32_t ret = OH_NativeImage_GetTimestamp(imageNew);
479     ASSERT_EQ(ret, -1);
480 
481     OH_NativeImage_Destroy(&imageNew);
482 }
483 
484 /*
485 * Function: OH_NativeImage_GetTransformMatrix
486 * Type: Function
487 * Rank: Important(2)
488 * EnvConditions: N/A
489 * CaseDescription: 1. call OH_NativeImage_GetTransformMatrix by abnormal input
490 *                  2. check ret
491 * @tc.require: issueI5KG61
492 */
493 HWTEST_F(NativeImageTest, OHNativeImageGetTransformMatrix001, Function | MediumTest | Level2)
494 {
495     float matrix[MATRIX_SIZE];
496     int32_t ret = OH_NativeImage_GetTransformMatrix(nullptr, matrix);
497     ASSERT_NE(ret, SURFACE_ERROR_OK);
498 }
499 
500 /*
501 * Function: OH_NativeImage_GetTransformMatrix
502 * Type: Function
503 * Rank: Important(1)
504 * EnvConditions: N/A
505 * CaseDescription: 1. call OH_NativeImage_GetTransformMatrix
506 *                  2. check ret
507 * @tc.require: issueI5KG61
508 */
509 HWTEST_F(NativeImageTest, OHNativeImageGetTransformMatrix002, Function | MediumTest | Level1)
510 {
511     float matrix[MATRIX_SIZE];
512     int32_t ret = OH_NativeImage_GetTransformMatrix(image, matrix);
513     ASSERT_EQ(ret, SURFACE_ERROR_OK);
514 }
515 
CheckMatricIsSame(float matrixOld[MATRIX_SIZE],float matrixNew[MATRIX_SIZE])516 bool CheckMatricIsSame(float matrixOld[MATRIX_SIZE], float matrixNew[MATRIX_SIZE])
517 {
518     for (int32_t i = 0; i < MATRIX_SIZE; i++) {
519         if (fabs(matrixOld[i] - matrixNew[i]) > 1e-6) {
520             return false;
521         }
522     }
523     return true;
524 }
525 
526 int32_t testType[] = {
527     GraphicTransformType::GRAPHIC_ROTATE_NONE, GraphicTransformType::GRAPHIC_ROTATE_90,
528     GraphicTransformType::GRAPHIC_ROTATE_180, GraphicTransformType::GRAPHIC_ROTATE_270,
529     GraphicTransformType::GRAPHIC_FLIP_H, GraphicTransformType::GRAPHIC_FLIP_V,
530     GraphicTransformType::GRAPHIC_FLIP_H_ROT90, GraphicTransformType::GRAPHIC_FLIP_V_ROT90,
531     GraphicTransformType::GRAPHIC_FLIP_H_ROT180, GraphicTransformType::GRAPHIC_FLIP_V_ROT180,
532     GraphicTransformType::GRAPHIC_FLIP_H_ROT270, GraphicTransformType::GRAPHIC_FLIP_V_ROT270,
533 };
534 float matrixArr[][MATRIX_SIZE] = {
535     {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
536     {0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
537     {-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
538     {0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
539     {-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
540     {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
541     {0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
542     {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
543     {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
544     {-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
545     {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
546     {0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
547 };
548 
549 /*
550 * Function: OH_NativeImage_GetTransformMatrix
551 * Type: Function
552 * Rank: Important(1)
553 * EnvConditions: N/A
554 * CaseDescription: 1. call OH_NativeImage_GetTransformMatrix
555 *                  2. check ret
556 * @tc.require: issueI5KG61
557 */
558 HWTEST_F(NativeImageTest, OHNativeImageGetTransformMatrix003, Function | MediumTest | Level1)
559 {
560     if (image == nullptr) {
561         image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
562         ASSERT_NE(image, nullptr);
563     }
564 
565     if (nativeWindow == nullptr) {
566         nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
567         ASSERT_NE(nativeWindow, nullptr);
568     }
569 
570     OH_OnFrameAvailableListener listener;
571     listener.context = this;
572     listener.onFrameAvailable = nullptr;
573     int32_t ret = OH_NativeImage_SetOnFrameAvailableListener(image, listener);
574     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
575 
576     listener.onFrameAvailable = NativeImageTest::OnFrameAvailable;
577     ret = OH_NativeImage_SetOnFrameAvailableListener(image, listener);
578     ASSERT_EQ(ret, GSERROR_OK);
579 
580     NativeWindowBuffer* nativeWindowBuffer = nullptr;
581     int fenceFd = -1;
582     struct Region *region = new Region();
583     struct Region::Rect *rect = new Region::Rect();
584 
585     for (int32_t i = 0; i < sizeof(testType) / sizeof(int32_t); i++) {
586         int code = SET_TRANSFORM;
587         ret = NativeWindowHandleOpt(nativeWindow, code, testType[i]);
588         ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
589         ASSERT_EQ(ret, GSERROR_OK);
590 
591         rect->x = 0x100;
592         rect->y = 0x100;
593         rect->w = 0x100;
594         rect->h = 0x100;
595         region->rects = rect;
596         ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
597         ASSERT_EQ(ret, GSERROR_OK);
598 
599         ret = OH_NativeImage_UpdateSurfaceImage(image);
600         ASSERT_EQ(ret, SURFACE_ERROR_OK);
601 
602         float matrix[16];
603         int32_t ret = OH_NativeImage_GetTransformMatrix(image, matrix);
604         ASSERT_EQ(ret, SURFACE_ERROR_OK);
605 
606         bool bRet = CheckMatricIsSame(matrix, matrixArr[i]);
607         ASSERT_EQ(bRet, true);
608     }
609     delete region;
610 }
611 
612 float matrixArrV2[][MATRIX_SIZE] = {
613     {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1},   // 单位矩阵
614     {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},    // 90度矩阵
615     {-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1},   // 180度矩阵
616     {0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1},  // 270度矩阵
617     {-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1},  // 水平翻转
618     {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},    // 垂直翻转
619     {0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1},   // 水平*90
620     {0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1},   // 垂直*90
621     {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},    // 水平*180
622     {-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1},  // 垂直*180
623     {0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1},   // 水平*270
624     {0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1},   // 垂直*270
625 };
626 
627 /*
628 * Function: OH_NativeImage_GetTransformMatrix
629 * Type: Function
630 * Rank: Important(1)
631 * EnvConditions: N/A
632 * CaseDescription: 1. call OH_NativeImage_GetTransformMatrix
633 *                  2. check ret
634 * @tc.require: issueI5KG61
635 */
636 HWTEST_F(NativeImageTest, OHNativeImageGetTransformMatrix004, Function | MediumTest | Level1)
637 {
638     if (image == nullptr) {
639         image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
640         ASSERT_NE(image, nullptr);
641     }
642 
643     if (nativeWindow == nullptr) {
644         nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
645         ASSERT_NE(nativeWindow, nullptr);
646     }
647 
648     OH_OnFrameAvailableListener listener;
649     listener.context = this;
650     listener.onFrameAvailable = NativeImageTest::OnFrameAvailable;
651     int32_t ret = OH_NativeImage_SetOnFrameAvailableListener(image, listener);
652     ASSERT_EQ(ret, GSERROR_OK);
653 
654     NativeWindowBuffer* nativeWindowBuffer = nullptr;
655     int fenceFd = -1;
656     struct Region *region = new Region();
657     struct Region::Rect *rect = new Region::Rect();
658 
659     for (int32_t i = 0; i < sizeof(testType) / sizeof(int32_t); i++) {
660         int code = SET_TRANSFORM;
661         ret = NativeWindowHandleOpt(nativeWindow, code, testType[i]);
662         ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
663         ASSERT_EQ(ret, GSERROR_OK);
664 
665         rect->x = 0x100;
666         rect->y = 0x100;
667         rect->w = 0x100;
668         rect->h = 0x100;
669         region->rects = rect;
670         ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
671         ASSERT_EQ(ret, GSERROR_OK);
672 
673         ret = OH_NativeImage_UpdateSurfaceImage(image);
674         ASSERT_EQ(ret, SURFACE_ERROR_OK);
675 
676         float matrix[16];
677         int32_t ret = OH_NativeImage_GetTransformMatrixV2(image, matrix);
678         ASSERT_EQ(ret, SURFACE_ERROR_OK);
679 
680         bool bRet = CheckMatricIsSame(matrix, matrixArrV2[i]);
681         ASSERT_EQ(bRet, true);
682     }
683     delete region;
684 }
685 
686 /*
687  * Function: OH_NativeImage_GetBufferMatrix
688  * Type: Function
689  * Rank: Important(1)
690  * EnvConditions: N/A
691  * CaseDescription: 1. test with different transform types and crop regions
692  *                  2. verify matrix calculation with crop
693  * @tc.require: issueI5KG61
694  */
695 HWTEST_F(NativeImageTest, OHNativeImageGetBufferMatrix001, Function | MediumTest | Level1)
696 {
697     if (image == nullptr) {
698         image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
699         ASSERT_NE(image, nullptr);
700     }
701     if (nativeWindow == nullptr) {
702         nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
703         ASSERT_NE(nativeWindow, nullptr);
704     }
705 
706     // Setup frame available listener
707     OH_OnFrameAvailableListener listener;
708     listener.context = this;
709     listener.onFrameAvailable = NativeImageTest::OnFrameAvailable;
710     int32_t ret = OH_NativeImage_SetOnFrameAvailableListener(image, listener);
711     ASSERT_EQ(ret, GSERROR_OK);
712 
713     // Setup buffer and region
714     NativeWindowBuffer* buffer = nullptr;
715     int fenceFd = -1;
716     struct Region *region = new Region();
717     struct Region::Rect *rect = new Region::Rect();
718     rect->x = 0x100;
719     rect->y = 0x100;
720     rect->w = 0x100;
721     rect->h = 0x100;
722     region->rects = rect;
723     int32_t width = 600;
724     int32_t height = 800;
725     ret = NativeWindowHandleOpt(nativeWindow, SET_BUFFER_GEOMETRY, width, height);
726     float bufferMatrix[16] = {
727         0, -0.5, 0, 0,
728         -0.5, 0, 0, 0,
729         0, 0, 1, 0,
730         1, 1, 0, 1
731     };
732     EXPECT_EQ(ret, GSERROR_OK);
733 
734     // Set transform
735     ret = NativeWindowHandleOpt(nativeWindow, SET_TRANSFORM, GraphicTransformType::GRAPHIC_ROTATE_90);
736     ASSERT_EQ(ret, GSERROR_OK);
737 
738     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &buffer, &fenceFd);
739     ASSERT_EQ(ret, GSERROR_OK);
740     using namespace OHOS::HDI::Display::Graphic::Common::V1_0;
741     BufferHandleMetaRegion metaRegion{300, 400, 300, 400};
742     vector<uint8_t> data;
743     MetadataHelper::ConvertMetadataToVec(metaRegion, data);
744     buffer->sfbuffer->SetMetadata(ATTRKEY_CROP_REGION, data);
745     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, buffer, -1, *region);
746     ASSERT_EQ(ret, GSERROR_OK);
747     // Update surface to apply transform and crop
748     ret = OH_NativeImage_UpdateSurfaceImage(image);
749     ASSERT_EQ(ret, SURFACE_ERROR_OK);
750 
751     // Get and verify buffer matrix
752     float matrix[16];
753     ret = OH_NativeImage_GetBufferMatrix(image, matrix);
754     std::cout << "{\n";
755     for (int i = 0; i < 4; i++) {
756         std::cout << "    {";
757         for (int j = 0; j < 4; j++) {
758             std::cout << matrix[i * 4 + j];
759             if (j < 3) std::cout << ", ";
760         }
761         std::cout << "},\n";
762     }
763     std::cout << "}" << std::endl;
764     ASSERT_EQ(ret, GSERROR_OK);
765     BufferHandleMetaRegion crop;
766     if (MetadataHelper::GetCropRectMetadata(buffer->sfbuffer, crop) != GSERROR_OK) {
767         const float initMatrix[] = {
768             0, -1, 0, 0,
769             -1, 0, 0, 0,
770             0, 0, 1, 0,
771             1, 1, 0, 1
772         };
773         std::copy(std::begin(initMatrix), std::end(initMatrix), bufferMatrix);
774     }
775 
776     ASSERT_EQ(CheckMatricIsSame(matrix, bufferMatrix), true);
777     EXPECT_EQ(SURFACE_ERROR_INVALID_PARAM, OH_NativeImage_GetBufferMatrix(nullptr, matrix));
778     EXPECT_EQ(SURFACE_ERROR_INVALID_PARAM, OH_NativeImage_GetBufferMatrix(image, nullptr));
779     delete region;
780 }
781 
782 /*
783 * Function: OH_NativeImage_GetTransformMatrix
784 * Type: Function
785 * Rank: Important(1)
786 * EnvConditions: N/A
787 * CaseDescription: 1. call OH_NativeImage_GetTransformMatrix
788 *                  2. check ret
789 * @tc.require: issueI5KG61
790 */
791 HWTEST_F(NativeImageTest, OHNativeImageGetTransformMatrix005, Function | MediumTest | Level1)
792 {
793     OH_NativeImage* imageNew = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
794     ASSERT_NE(imageNew, nullptr);
795     int32_t ret = OH_NativeImage_GetTransformMatrixV2(nullptr, nullptr);
796     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
797     ret = OH_NativeImage_GetTransformMatrix(imageNew, nullptr);
798     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
799     ret = OH_NativeImage_GetTransformMatrixV2(imageNew, nullptr);
800     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
801     float matrix[16];
802     memset_s(imageNew, sizeof(OH_NativeImage_Tmp), 0, sizeof(OH_NativeImage_Tmp));
803     ret = OH_NativeImage_GetTransformMatrix(imageNew, matrix);
804     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
805     ret = OH_NativeImage_GetTransformMatrixV2(imageNew, matrix);
806     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
807 
808     OH_NativeImage_Destroy(&imageNew);
809 }
810 
811 /*
812 * Function: OH_NativeImage_AttachContext
813 * Type: Function
814 * Rank: Important(1)
815 * EnvConditions: N/A
816 * CaseDescription: 1. call OH_NativeImage_AttachContext with another texture
817 *                  2. check ret
818 * @tc.require: issueI5KG61
819 */
820 HWTEST_F(NativeImageTest, OHNativeImageAttachContext003, Function | MediumTest | Level1)
821 {
822     int32_t ret = OH_NativeImage_AttachContext(image, textureId2);
823     ASSERT_EQ(ret, SURFACE_ERROR_OK);
824 }
825 
826 /*
827 * Function: OH_NativeImage_UpdateSurfaceImage
828 * Type: Function
829 * Rank: Important(1)
830 * EnvConditions: N/A
831 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
832 *                  2. call OH_NativeWindow_NativeWindowFlushBuffer
833 *                  3. OH_NativeImage_UpdateSurfaceImage after the bound OPENGL ES texture changed
834 *                  4. check ret
835 * @tc.require: issueI5KG61
836 */
837 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage004, Function | MediumTest | Level1)
838 {
839     NativeWindowBuffer* nativeWindowBuffer = nullptr;
840     int fenceFd = -1;
841     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
842     ASSERT_EQ(ret, GSERROR_OK);
843 
844     struct Region *region = new Region();
845     struct Region::Rect *rect = new Region::Rect();
846     rect->x = 0x100;
847     rect->y = 0x100;
848     rect->w = 0x100;
849     rect->h = 0x100;
850     region->rects = rect;
851     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
852     ASSERT_EQ(ret, GSERROR_OK);
853     delete region;
854 
855     ret = OH_NativeImage_UpdateSurfaceImage(image);
856     ASSERT_EQ(ret, SURFACE_ERROR_OK);
857 }
858 
859 /*
860 * Function: OH_NativeImage_DetachContext
861 * Type: Function
862 * Rank: Important(1)
863 * EnvConditions: N/A
864 * CaseDescription: 1. call OH_NativeImage_DetachContext
865 *                  2. check ret
866 * @tc.require: issueI5KG61
867 */
868 HWTEST_F(NativeImageTest, OHNativeImageDetachContext004, Function | MediumTest | Level1)
869 {
870     int32_t ret = OH_NativeImage_DetachContext(image);
871     ASSERT_EQ(ret, SURFACE_ERROR_OK);
872 }
873 
874 /*
875 * Function: OH_NativeImage_AttachContext
876 * Type: Function
877 * Rank: Important(1)
878 * EnvConditions: N/A
879 * CaseDescription: 1. call OH_NativeImage_AttachContext after OH_NativeImage_DetachContext
880 *                  2. check ret
881 * @tc.require: issueI5KG61
882 */
883 HWTEST_F(NativeImageTest, OHNativeImageAttachContext004, Function | MediumTest | Level1)
884 {
885     int32_t ret = OH_NativeImage_AttachContext(image, textureId2);
886     ASSERT_EQ(ret, SURFACE_ERROR_OK);
887 }
888 
889 /*
890 * Function: OH_NativeImage_AttachContext
891 * Type: Function
892 * Rank: Important(1)
893 * EnvConditions: N/A
894 * CaseDescription: 1. call OH_NativeImage_AttachContext after OH_NativeImage_DetachContext
895 *                  2. check ret
896 * @tc.require: issueI5KG61
897 */
898 HWTEST_F(NativeImageTest, OHNativeImageAttachContext005, Function | MediumTest | Level1)
899 {
900     OH_NativeImage* imageNew = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
901     ASSERT_NE(imageNew, nullptr);
902     memset_s(imageNew, sizeof(OH_NativeImage_Tmp), 0, sizeof(OH_NativeImage_Tmp));
903     int32_t ret = OH_NativeImage_AttachContext(imageNew, 0);
904     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
905     ret = OH_NativeImage_DetachContext(imageNew);
906     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
907 
908     OH_NativeImage_Destroy(&imageNew);
909 }
910 
911 /*
912 * Function: OH_NativeImage_UpdateSurfaceImage
913 * Type: Function
914 * Rank: Important(1)
915 * EnvConditions: N/A
916 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
917 *                  2. call OH_NativeWindow_NativeWindowFlushBuffer
918 *                  3. OH_NativeImage_UpdateSurfaceImage again
919 *                  4. check ret
920 * @tc.require: issueI5KG61
921 */
922 HWTEST_F(NativeImageTest, OHNativeImageUpdateSurfaceImage005, Function | MediumTest | Level1)
923 {
924     NativeWindowBuffer* nativeWindowBuffer = nullptr;
925     int fenceFd = -1;
926     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
927     ASSERT_EQ(ret, GSERROR_OK);
928 
929     struct Region *region = new Region();
930     struct Region::Rect *rect = new Region::Rect();
931     rect->x = 0x100;
932     rect->y = 0x100;
933     rect->w = 0x100;
934     rect->h = 0x100;
935     region->rects = rect;
936     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
937     ASSERT_EQ(ret, GSERROR_OK);
938     delete region;
939 
940     ret = OH_NativeImage_UpdateSurfaceImage(image);
941     ASSERT_EQ(ret, SURFACE_ERROR_OK);
942 }
943 
944 /*
945 * Function: OH_NativeImage_GetSurfaceId
946 * Type: Function
947 * Rank: Important(1)
948 * EnvConditions: N/A
949 * CaseDescription: 1. create image
950 *                  2. GetSurfaceId
951 *                  2. check ret
952 * @tc.require: issueI86VH2
953 */
954 HWTEST_F(NativeImageTest, OHNativeImageGetSurfaceId001, Function | MediumTest | Level1)
955 {
956     if (image == nullptr) {
957         image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
958         ASSERT_NE(image, nullptr);
959     }
960 
961     uint64_t surfaceId;
962     int32_t ret = OH_NativeImage_GetSurfaceId(image, &surfaceId);
963     ASSERT_EQ(ret, SURFACE_ERROR_OK);
964 }
965 
966 /*
967 * Function: OH_NativeImage_GetSurfaceId
968 * Type: Function
969 * Rank: Important(1)
970 * EnvConditions: N/A
971 * CaseDescription: 1. create image
972 *                  2. GetSurfaceId
973 *                  2. check ret
974 * @tc.require: issueI86VH2
975 */
976 HWTEST_F(NativeImageTest, OHNativeImageGetSurfaceId002, Function | MediumTest | Level1)
977 {
978     uint64_t surfaceId;
979     int32_t ret = OH_NativeImage_GetSurfaceId(nullptr, &surfaceId);
980     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
981 
982     OH_NativeImage* imageNew = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
983     ASSERT_NE(imageNew, nullptr);
984 
985     ret = OH_NativeImage_GetSurfaceId(imageNew, nullptr);
986     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
987 
988     memset_s(imageNew, sizeof(OH_NativeImage_Tmp), 0, sizeof(OH_NativeImage_Tmp));
989     ret = OH_NativeImage_GetSurfaceId(imageNew, &surfaceId);
990     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
991 
992     OH_NativeImage_Destroy(&imageNew);
993 }
994 
995 /*
996 * Function: OH_NativeImage_SetOnFrameAvailableListener
997 * Type: Function
998 * Rank: Important(1)
999 * EnvConditions: N/A
1000 * CaseDescription: 1. check image and nativeWindow
1001 *                  2. call OH_NativeImage_SetOnFrameAvailableListener
1002 *                  3. call OH_NativeWindow_NativeWindowFlushBuffer
1003 *                  4. check OnFrameAvailable is called
1004 * @tc.require: issueI86VH2
1005 */
1006 HWTEST_F(NativeImageTest, OHNativeImageSetOnFrameAvailableListener001, Function | MediumTest | Level1)
1007 {
1008     if (image == nullptr) {
1009         image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
1010         ASSERT_NE(image, nullptr);
1011     }
1012 
1013     if (nativeWindow == nullptr) {
1014         nativeWindow = OH_NativeImage_AcquireNativeWindow(image);
1015         ASSERT_NE(nativeWindow, nullptr);
1016     }
1017 
1018     OH_OnFrameAvailableListener listener;
1019     listener.context = this;
1020     listener.onFrameAvailable = NativeImageTest::OnFrameAvailable;
1021     int32_t ret = OH_NativeImage_SetOnFrameAvailableListener(image, listener);
1022     ASSERT_EQ(ret, GSERROR_OK);
1023 
1024     NativeWindowBuffer* nativeWindowBuffer = nullptr;
1025     int fenceFd = -1;
1026     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1027     ASSERT_EQ(ret, GSERROR_OK);
1028 
1029     struct Region *region = new Region();
1030     struct Region::Rect *rect = new Region::Rect();
1031     rect->x = 0x100;
1032     rect->y = 0x100;
1033     rect->w = 0x100;
1034     rect->h = 0x100;
1035     region->rects = rect;
1036     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
1037     ASSERT_EQ(ret, GSERROR_OK);
1038     delete region;
1039 
1040     ret = OH_NativeImage_UpdateSurfaceImage(image);
1041     ASSERT_EQ(ret, SURFACE_ERROR_OK);
1042 }
1043 
1044 /*
1045 * Function: OH_NativeImage_SetOnFrameAvailableListener
1046 * Type: Function
1047 * Rank: Important(1)
1048 * EnvConditions: N/A
1049 * CaseDescription: 1. check image and nativeWindow
1050 * @tc.require: issueI86VH2
1051 */
1052 HWTEST_F(NativeImageTest, OHNativeImageSetOnFrameAvailableListener002, Function | MediumTest | Level1)
1053 {
1054     OH_OnFrameAvailableListener listener;
1055     int32_t ret = OH_NativeImage_SetOnFrameAvailableListener(nullptr, listener);
1056     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1057 
1058     OH_NativeImage* imageNew = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
1059     ASSERT_NE(imageNew, nullptr);
1060     memset_s(imageNew, sizeof(OH_NativeImage_Tmp), 0, sizeof(OH_NativeImage_Tmp));
1061     ret = OH_NativeImage_SetOnFrameAvailableListener(imageNew, listener);
1062     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1063 
1064     OH_NativeImage_Destroy(&imageNew);
1065 }
1066 
1067 /*
1068 * Function: OH_NativeImage_UnsetOnFrameAvailableListener
1069 * Type: Function
1070 * Rank: Important(1)
1071 * EnvConditions: N/A
1072 * CaseDescription: 1. call OH_NativeImage_UnsetOnFrameAvailableListener
1073 *                  2. check ret
1074 * @tc.require: issueI86VH2
1075 */
1076 HWTEST_F(NativeImageTest, OHNativeImageUnsetOnFrameAvailableListener001, Function | MediumTest | Level1)
1077 {
1078     int32_t ret = OH_NativeImage_UnsetOnFrameAvailableListener(image);
1079     ASSERT_EQ(ret, SURFACE_ERROR_OK);
1080 }
1081 
1082 /*
1083 * Function: OH_NativeImage_UnsetOnFrameAvailableListener
1084 * Type: Function
1085 * Rank: Important(1)
1086 * EnvConditions: N/A
1087 * CaseDescription: 1. call OH_NativeImage_UnsetOnFrameAvailableListener
1088 *                  2. check ret
1089 * @tc.require: issueI86VH2
1090 */
1091 HWTEST_F(NativeImageTest, OHNativeImageUnsetOnFrameAvailableListener002, Function | MediumTest | Level1)
1092 {
1093     int32_t ret = OH_NativeImage_UnsetOnFrameAvailableListener(nullptr);
1094     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1095 
1096     OH_NativeImage* imageNew = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
1097     ASSERT_NE(imageNew, nullptr);
1098     memset_s(imageNew, sizeof(OH_NativeImage_Tmp), 0, sizeof(OH_NativeImage_Tmp));
1099     ret = OH_NativeImage_UnsetOnFrameAvailableListener(imageNew);
1100     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1101 
1102     OH_NativeImage_Destroy(&imageNew);
1103 }
1104 
1105 /*
1106 * Function: OH_NativeImage_Destroy
1107 * Type: Function
1108 * Rank: Important(2)
1109 * EnvConditions: N/A
1110 * CaseDescription: 1. call OH_NativeImage_Destroy by abnormal input
1111 *                  2. check ret
1112 * @tc.require: issueI5KG61
1113 */
1114 HWTEST_F(NativeImageTest, OHNativeImageDestroy001, Function | MediumTest | Level2)
1115 {
1116     OH_NativeImage_Destroy(nullptr);
1117     ASSERT_NE(image, nullptr);
1118 }
1119 
1120 /*
1121 * Function: OH_NativeImage_Destroy
1122 * Type: Function
1123 * Rank: Important(1)
1124 * EnvConditions: N/A
1125 * CaseDescription: 1. call OH_NativeImage_Destroy
1126 *                  2. check ret
1127 * @tc.require: issueI5KG61
1128 */
1129 HWTEST_F(NativeImageTest, OHNativeImageDestroy002, Function | MediumTest | Level1)
1130 {
1131     OH_NativeImage_Destroy(&image);
1132     ASSERT_EQ(image, nullptr);
1133 }
1134 
1135 /*
1136 * Function: OH_NativeImage_AcquireNativeWindowBuffer
1137 * Type: Function
1138 * Rank: Important(1)
1139 * EnvConditions: N/A
1140 * CaseDescription: 1. call OH_NativeImage_AcquireNativeWindowBuffer
1141 *                  2. check ret
1142 *                  3. call OH_NativeImage_ReleaseNativeWindowBuffer
1143 *                  4. check ret
1144 * @tc.require: issueI5KG61
1145 */
1146 HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBuffer001, Function | MediumTest | Level1)
1147 {
1148     int32_t ret = OH_NativeImage_AcquireNativeWindowBuffer(nullptr, nullptr, nullptr);
1149     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1150     OH_NativeImage* newImage1 = OH_NativeImage_Create(0, 0);
1151     ret = OH_NativeImage_AcquireNativeWindowBuffer(newImage1, nullptr, nullptr);
1152     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1153     NativeWindowBuffer* nativeWindowBuffer = nullptr;
1154     ret = OH_NativeImage_AcquireNativeWindowBuffer(newImage1, &nativeWindowBuffer, nullptr);
1155     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1156 
1157     ret = OH_NativeImage_ReleaseNativeWindowBuffer(nullptr, nullptr, 0);
1158     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1159     ret = OH_NativeImage_ReleaseNativeWindowBuffer(newImage1, nullptr, 0);
1160     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1161 
1162     int32_t fenceFd;
1163     memset_s(newImage1, sizeof(OH_NativeImage_Tmp), 0, sizeof(OH_NativeImage_Tmp));
1164     ret = OH_NativeImage_AcquireNativeWindowBuffer(newImage1, &nativeWindowBuffer, &fenceFd);
1165     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1166 
1167     NativeWindowBuffer nativeWindowBufferNew;
1168     ret = OH_NativeImage_ReleaseNativeWindowBuffer(newImage1, &nativeWindowBufferNew, 0);
1169     ASSERT_EQ(ret, SURFACE_ERROR_INVALID_PARAM);
1170 
1171     OH_NativeImage_Destroy(&newImage1);
1172 }
1173 
1174 /*
1175 * Function: OH_NativeImage_AcquireNativeWindowBuffer
1176 * Type: Function
1177 * Rank: Important(1)
1178 * EnvConditions: N/A
1179 * CaseDescription: 1. call OH_NativeImage_AcquireNativeWindowBuffer
1180 *                  2. check ret
1181 *                  3. call OH_NativeImage_ReleaseNativeWindowBuffer
1182 *                  4. check ret
1183 * @tc.require: issueI5KG61
1184 */
1185 HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBuffer002, Function | MediumTest | Level1)
1186 {
1187     OH_NativeImage* newImage = OH_NativeImage_Create(0, 0);
1188     ASSERT_NE(newImage, nullptr);
1189     OHNativeWindow* newNativeWindow = OH_NativeImage_AcquireNativeWindow(newImage);
1190     ASSERT_NE(newNativeWindow, nullptr);
1191 
1192     int32_t code = SET_BUFFER_GEOMETRY;
1193     int32_t width = 0x100;
1194     int32_t height = 0x100;
1195     int32_t ret = NativeWindowHandleOpt(newNativeWindow, code, width, height);
1196     ASSERT_EQ(ret, GSERROR_OK);
1197 
1198     NativeWindowBuffer* nativeWindowBuffer = nullptr;
1199     int fenceFd = -1;
1200     struct Region *region = new Region();
1201     struct Region::Rect *rect = new Region::Rect();
1202     rect->x = 0x100;
1203     rect->y = 0x100;
1204     rect->w = 0x100;
1205     rect->h = 0x100;
1206     region->rects = rect;
1207     for (int32_t i = 0; i < 100; i++) {
1208         ret = OH_NativeWindow_NativeWindowRequestBuffer(newNativeWindow, &nativeWindowBuffer, &fenceFd);
1209         ASSERT_EQ(ret, GSERROR_OK);
1210 
1211         ret = OH_NativeWindow_NativeWindowFlushBuffer(newNativeWindow, nativeWindowBuffer, fenceFd, *region);
1212         ASSERT_EQ(ret, GSERROR_OK);
1213 
1214         nativeWindowBuffer = nullptr;
1215         ret = OH_NativeImage_AcquireNativeWindowBuffer(newImage, &nativeWindowBuffer, &fenceFd);
1216         ASSERT_EQ(ret, GSERROR_OK);
1217         ASSERT_NE(nativeWindowBuffer, nullptr);
1218 
1219         ret = OH_NativeImage_ReleaseNativeWindowBuffer(newImage, nativeWindowBuffer, fenceFd);
1220         ASSERT_EQ(ret, GSERROR_OK);
1221     }
1222 
1223     delete rect;
1224     delete region;
1225     OH_NativeImage_Destroy(&newImage);
1226 }
1227 
1228 /*
1229 * Function: OH_NativeImage_AcquireNativeWindowBuffer
1230 * Type: Function
1231 * Rank: Important(1)
1232 * EnvConditions: N/A
1233 * CaseDescription: 1. call OH_NativeImage_AcquireNativeWindowBuffer
1234 *                  2. check ret
1235 *                  3. call OH_NativeImage_ReleaseNativeWindowBuffer
1236 *                  4. check ret
1237 * @tc.require: issueI5KG61
1238 */
1239 HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBuffer003, Function | MediumTest | Level1)
1240 {
1241     OH_NativeImage* newImage = OH_NativeImage_Create(0, 0);
1242     ASSERT_NE(newImage, nullptr);
1243     OHNativeWindow* newNativeWindow = OH_NativeImage_AcquireNativeWindow(newImage);
1244     ASSERT_NE(newNativeWindow, nullptr);
1245 
1246     int32_t code = SET_BUFFER_GEOMETRY;
1247     int32_t width = 0x100;
1248     int32_t height = 0x100;
1249     int32_t ret = NativeWindowHandleOpt(newNativeWindow, code, width, height);
1250     ASSERT_EQ(ret, GSERROR_OK);
1251     struct Region *region = new Region();
1252     struct Region::Rect *rect = new Region::Rect();
1253     rect->x = 0x100;
1254     rect->y = 0x100;
1255     rect->w = 0x100;
1256     rect->h = 0x100;
1257     region->rects = rect;
1258 
1259     NativeWindowBuffer* nativeWindowBuffer = nullptr;
1260     int fenceFd = -1;
1261 
1262     ret = OH_NativeImage_AcquireNativeWindowBuffer(newImage, &nativeWindowBuffer, &fenceFd);
1263     ASSERT_EQ(ret, SURFACE_ERROR_NO_BUFFER);
1264 
1265     ret = OH_NativeWindow_NativeWindowRequestBuffer(newNativeWindow, &nativeWindowBuffer, &fenceFd);
1266     ASSERT_EQ(ret, GSERROR_OK);
1267 
1268     ret = OH_NativeWindow_NativeWindowFlushBuffer(newNativeWindow, nativeWindowBuffer, fenceFd, *region);
1269     ASSERT_EQ(ret, GSERROR_OK);
1270 
1271     ret = OH_NativeImage_ReleaseNativeWindowBuffer(newImage, nativeWindowBuffer, fenceFd);
1272     ASSERT_EQ(ret, SURFACE_ERROR_BUFFER_STATE_INVALID);
1273 
1274     OH_NativeImage* newImage1 = OH_NativeImage_Create(0, 0);
1275     ASSERT_NE(newImage1, nullptr);
1276     OHNativeWindow* newNativeWindow1 = OH_NativeImage_AcquireNativeWindow(newImage1);
1277     ASSERT_NE(newNativeWindow1, nullptr);
1278     code = SET_BUFFER_GEOMETRY;
1279     width = 0x100;
1280     height = 0x100;
1281     ret = NativeWindowHandleOpt(newNativeWindow1, code, width, height);
1282     ASSERT_EQ(ret, GSERROR_OK);
1283 
1284     NativeWindowBuffer* nativeWindowBuffer1 = nullptr;
1285     ret = OH_NativeWindow_NativeWindowRequestBuffer(newNativeWindow1, &nativeWindowBuffer1, &fenceFd);
1286     ASSERT_EQ(ret, GSERROR_OK);
1287     ret = OH_NativeWindow_NativeWindowFlushBuffer(newNativeWindow1, nativeWindowBuffer1, fenceFd, *region);
1288     ASSERT_EQ(ret, GSERROR_OK);
1289 
1290     ret = OH_NativeImage_AcquireNativeWindowBuffer(newImage1, &nativeWindowBuffer1, &fenceFd);
1291     ASSERT_EQ(ret, GSERROR_OK);
1292     ret = OH_NativeImage_ReleaseNativeWindowBuffer(newImage, nativeWindowBuffer1, fenceFd);
1293     ASSERT_EQ(ret, SURFACE_ERROR_BUFFER_NOT_INCACHE);
1294 
1295     delete rect;
1296     delete region;
1297     OH_NativeImage_Destroy(&newImage);
1298     OH_NativeImage_Destroy(&newImage1);
1299 }
1300 
1301 /*
1302 * Function: OH_NativeImage_AcquireNativeWindowBuffer
1303 * Type: Function
1304 * Rank: Important(1)
1305 * EnvConditions: N/A
1306 * CaseDescription: 1. call OH_NativeImage_AcquireNativeWindowBuffer
1307 *                  2. check ret
1308 *                  3. call OH_NativeImage_ReleaseNativeWindowBuffer
1309 *                  4. check ret
1310 * @tc.require: issueI5KG61
1311 */
1312 HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBuffer004, Function | MediumTest | Level1)
1313 {
1314     OH_NativeImage* newImage = OH_NativeImage_Create(0, 0);
1315     ASSERT_NE(newImage, nullptr);
1316     OHNativeWindow* newNativeWindow = OH_NativeImage_AcquireNativeWindow(newImage);
1317     ASSERT_NE(newNativeWindow, nullptr);
1318 
1319     int32_t code = SET_BUFFER_GEOMETRY;
1320     int32_t width = 0x100;
1321     int32_t height = 0x100;
1322     int32_t ret = NativeWindowHandleOpt(newNativeWindow, code, width, height);
1323     ASSERT_EQ(ret, GSERROR_OK);
1324 
1325     NativeWindowBuffer* nativeWindowBuffer = nullptr;
1326     int fenceFd = -1;
1327     struct Region *region = new Region();
1328     struct Region::Rect *rect = new Region::Rect();
1329     rect->x = 0x100;
1330     rect->y = 0x100;
1331     rect->w = 0x100;
1332     rect->h = 0x100;
1333     region->rects = rect;
1334     struct timeval acquireStartTime;
1335     struct timeval acquireEndTime;
1336     struct timeval releaseStartTime;
1337     struct timeval releaseEndTime;
1338     uint64_t acquireTotalTime = 0;
1339     uint64_t releaseTotalTime = 0;
1340     for (int32_t i = 0; i < 10000; i++) {
1341         ret = OH_NativeWindow_NativeWindowRequestBuffer(newNativeWindow, &nativeWindowBuffer, &fenceFd);
1342         ASSERT_EQ(ret, GSERROR_OK);
1343 
1344         ret = OH_NativeWindow_NativeWindowFlushBuffer(newNativeWindow, nativeWindowBuffer, fenceFd, *region);
1345         ASSERT_EQ(ret, GSERROR_OK);
1346 
1347         nativeWindowBuffer = nullptr;
1348         gettimeofday(&acquireStartTime, nullptr);
1349         ret = OH_NativeImage_AcquireNativeWindowBuffer(newImage, &nativeWindowBuffer, &fenceFd);
1350         gettimeofday(&acquireEndTime, nullptr);
1351         acquireTotalTime += (1000000 * (acquireEndTime.tv_sec - acquireStartTime.tv_sec) +
1352             (acquireEndTime.tv_usec - acquireStartTime.tv_usec));
1353         ASSERT_EQ(ret, GSERROR_OK);
1354         ASSERT_NE(nativeWindowBuffer, nullptr);
1355 
1356         gettimeofday(&releaseStartTime, nullptr);
1357         ret = OH_NativeImage_ReleaseNativeWindowBuffer(newImage, nativeWindowBuffer, fenceFd);
1358         gettimeofday(&releaseEndTime, nullptr);
1359         releaseTotalTime += (1000000 * (releaseEndTime.tv_sec - releaseStartTime.tv_sec) +
1360             (releaseEndTime.tv_usec - releaseStartTime.tv_usec));
1361         ASSERT_EQ(ret, GSERROR_OK);
1362     }
1363     std::cout << "10000 count total time, OH_NativeImage_AcquireNativeWindowBuffer: " << acquireTotalTime << " us" <<
1364         " OH_NativeImage_ReleaseNativeWindowBuffer: " << releaseTotalTime << " us" << std::endl;
1365 
1366     delete rect;
1367     delete region;
1368     OH_NativeImage_Destroy(&newImage);
1369 }
1370 
1371 /*
1372 * Function: OH_ConsumerSurface_Create
1373 * Type: Function
1374 * Rank: Important(1)
1375 * EnvConditions: N/A
1376 * CaseDescription: 1. call OH_ConsumerSurface_Create
1377 *                  2. check ret
1378 * @tc.require: issueI5KG61
1379 */
1380 HWTEST_F(NativeImageTest, OH_ConsumerSurface_Create001, Function | MediumTest | Level1)
1381 {
1382     OH_NativeImage* consumerSurface = OH_ConsumerSurface_Create();
1383     ASSERT_NE(consumerSurface, nullptr);
1384     OHNativeWindow* newNativeWindow = OH_NativeImage_AcquireNativeWindow(consumerSurface);
1385     ASSERT_NE(newNativeWindow, nullptr);
1386 
1387     int32_t code = SET_BUFFER_GEOMETRY;
1388     int32_t width = 0x100;
1389     int32_t height = 0x100;
1390     int32_t ret = NativeWindowHandleOpt(newNativeWindow, code, width, height);
1391     ASSERT_EQ(ret, GSERROR_OK);
1392 
1393     NativeWindowBuffer* nativeWindowBuffer = nullptr;
1394     int fenceFd = -1;
1395     struct Region *region = new Region();
1396     struct Region::Rect *rect = new Region::Rect();
1397     rect->x = 0x100;
1398     rect->y = 0x100;
1399     rect->w = 0x100;
1400     rect->h = 0x100;
1401     region->rects = rect;
1402     for (int32_t i = 0; i < 10000; i++) {
1403         ret = OH_NativeWindow_NativeWindowRequestBuffer(newNativeWindow, &nativeWindowBuffer, &fenceFd);
1404         ASSERT_EQ(ret, GSERROR_OK);
1405 
1406         ret = OH_NativeWindow_NativeWindowFlushBuffer(newNativeWindow, nativeWindowBuffer, fenceFd, *region);
1407         ASSERT_EQ(ret, GSERROR_OK);
1408 
1409         nativeWindowBuffer = nullptr;
1410         ret = OH_NativeImage_AcquireNativeWindowBuffer(consumerSurface, &nativeWindowBuffer, &fenceFd);
1411         ASSERT_EQ(ret, GSERROR_OK);
1412         ASSERT_NE(nativeWindowBuffer, nullptr);
1413 
1414         ret = OH_NativeImage_ReleaseNativeWindowBuffer(consumerSurface, nativeWindowBuffer, fenceFd);
1415         ASSERT_EQ(ret, GSERROR_OK);
1416     }
1417 
1418     delete rect;
1419     delete region;
1420     OH_NativeImage_Destroy(&consumerSurface);
1421 }
1422 
1423 /*
1424 * Function: OH_ConsumerSurface_Create
1425 * Type: Function
1426 * Rank: Important(1)
1427 * EnvConditions: N/A
1428 * CaseDescription: 1. call OH_ConsumerSurface_Create
1429 *                  2. check ret
1430 * @tc.require: issueI5KG61
1431 */
1432 HWTEST_F(NativeImageTest, OH_ConsumerSurface_Create002, Function | MediumTest | Level1)
1433 {
1434     struct timeval startTime;
1435     struct timeval endTime;
1436     uint64_t totalTime = 0;
1437     OH_NativeImage* consumerSurface;
1438     for (int32_t i = 0; i < 10000; i++) {
1439         gettimeofday(&startTime, nullptr);
1440         consumerSurface = OH_ConsumerSurface_Create();
1441         gettimeofday(&endTime, nullptr);
1442         totalTime += (1000000 * (endTime.tv_sec - startTime.tv_sec) + (endTime.tv_usec - startTime.tv_usec));
1443         ASSERT_NE(consumerSurface, nullptr);
1444         OH_NativeImage_Destroy(&consumerSurface);
1445     }
1446     std::cout << "10000 count total time, OH_ConsumerSurface_Create: " << totalTime << " us" << std::endl;
1447 }
1448 
1449 /*
1450 * Function: OH_ConsumerSurface_SetDefaultUsage
1451 * Type: Function
1452 * Rank: Important(1)
1453 * EnvConditions: N/A
1454 * CaseDescription: 1. call OH_ConsumerSurface_SetDefaultUsage
1455 *                  2. check ret
1456 * @tc.require: issueI5KG61
1457 */
1458 HWTEST_F(NativeImageTest, OH_ConsumerSurface_SetDefaultUsage001, Function | MediumTest | Level1)
1459 {
1460     uint64_t usage = BUFFER_USAGE_CPU_READ;
1461     OH_NativeImage* consumerSurface = OH_ConsumerSurface_Create();
1462     ASSERT_NE(consumerSurface, nullptr);
1463     ASSERT_EQ(OH_ConsumerSurface_SetDefaultUsage(nullptr, usage), SURFACE_ERROR_INVALID_PARAM);
1464     ASSERT_EQ(OH_ConsumerSurface_SetDefaultUsage(consumerSurface, usage), GSERROR_OK);
1465     OH_NativeImage_Destroy(&consumerSurface);
1466 }
1467 
1468 /*
1469 * Function: OH_ConsumerSurface_SetDefaultSize
1470 * Type: Function
1471 * Rank: Important(1)
1472 * EnvConditions: N/A
1473 * CaseDescription: 1. call OH_ConsumerSurface_SetDefaultSize
1474 *                  2. check ret
1475 * @tc.require: issueI5KG61
1476 */
1477 HWTEST_F(NativeImageTest, OH_ConsumerSurface_SetDefaultSize001, Function | MediumTest | Level1)
1478 {
1479     int32_t width = 100;
1480     int32_t height = 100;
1481     OH_NativeImage* consumerSurface = OH_ConsumerSurface_Create();
1482     ASSERT_NE(consumerSurface, nullptr);
1483     ASSERT_EQ(OH_ConsumerSurface_SetDefaultSize(nullptr, 1, 1), SURFACE_ERROR_INVALID_PARAM);
1484     ASSERT_EQ(OH_ConsumerSurface_SetDefaultSize(consumerSurface, 0, -1), SURFACE_ERROR_INVALID_PARAM);
1485     ASSERT_EQ(OH_ConsumerSurface_SetDefaultSize(consumerSurface, 1, -1), SURFACE_ERROR_INVALID_PARAM);
1486     ASSERT_EQ(OH_ConsumerSurface_SetDefaultSize(consumerSurface, width, height), GSERROR_OK);
1487     OH_NativeImage_Destroy(&consumerSurface);
1488 }
1489 
1490 /*
1491 * Function: OH_NativeImage_SetDropBufferMode001
1492 * Type: Function
1493 * Rank: Important(1)
1494 * EnvConditions: N/A
1495 * CaseDescription: 1. call OH_NativeImage_SetDropBufferMode
1496 *                  2. check ret
1497 * @tc.require: issueI5KG61
1498 */
1499 HWTEST_F(NativeImageTest, OH_NativeImage_SetDropBufferMode001, Function | MediumTest | Level1)
1500 {
1501     OH_NativeImage* consumerSurface = OH_ConsumerSurface_Create();
1502     ASSERT_NE(consumerSurface, nullptr);
1503     ASSERT_EQ(OH_NativeImage_SetDropBufferMode(nullptr, true), SURFACE_ERROR_INVALID_PARAM);
1504     ASSERT_EQ(OH_NativeImage_SetDropBufferMode(consumerSurface, true), GSERROR_OK);
1505     ASSERT_EQ(OH_NativeImage_SetDropBufferMode(consumerSurface, false), GSERROR_OK);
1506     OH_NativeImage_Destroy(&consumerSurface);
1507 }
1508 }