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