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
27using namespace testing;
28using namespace testing::ext;
29using namespace std;
30
31namespace OHOS::Rosen {
32using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC;
33constexpr const char* EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland";
34constexpr const char* EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland";
35constexpr int32_t EGL_CONTEXT_CLIENT_VERSION_NUM = 2;
36constexpr char CHARACTER_WHITESPACE = ' ';
37constexpr const char* CHARACTER_STRING_WHITESPACE = " ";
38constexpr const char* EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT";
39constexpr int32_t MATRIX_SIZE = 16;
40
41struct TEST_IMAGE {
42    int a;
43    bool b;
44};
45
46static 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
69static 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
89class NativeImageTest : public testing::Test {
90public:
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
107void NativeImageTest::OnFrameAvailable(void *context)
108{
109    (void) context;
110    cout << "OnFrameAvailable is called" << endl;
111}
112
113void NativeImageTest::SetUpTestCase()
114{
115    image = nullptr;
116    nativeWindow = nullptr;
117    glGenTextures(1, &textureId);
118    glGenTextures(1, &textureId2);
119}
120
121void NativeImageTest::TearDownTestCase()
122{
123    image = nullptr;
124    nativeWindow = nullptr;
125    Deinit();
126}
127
128void 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
179void 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 */
200HWTEST_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 */
213HWTEST_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 */
226HWTEST_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 */
239HWTEST_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 */
252HWTEST_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 */
265HWTEST_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 */
278HWTEST_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 */
292HWTEST_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 */
305HWTEST_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 */
318HWTEST_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 */
331HWTEST_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 */
386HWTEST_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 */
399HWTEST_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 */
412HWTEST_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 */
426HWTEST_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
433bool 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
443int32_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};
451float 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 */
473HWTEST_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
523float 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*/
547HWTEST_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 */
604HWTEST_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 */
617HWTEST_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 */
646HWTEST_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 */
659HWTEST_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 */
672HWTEST_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 */
701HWTEST_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 */
720HWTEST_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 */
765HWTEST_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 */
777HWTEST_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 */
790HWTEST_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
804HWTEST_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 */
846HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBuffer4KBoundary, Function | MediumTest | Level1) {
847    if (image == nullptr) {
848        image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
849        ASSERT_NE(image, nullptr);
850    }
851    OHNativeWindow *nativewindow = OH_NativeImage_AcquireNativeWindow(image);
852    ASSERT_NE(nativewindow, nullptr);
853    int code = SET_BUFFER_GEOMETRY;
854    int32_t width = 4096;
855    int32_t height = 2160;
856    int32_t res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, width, height);
857    ASSERT_EQ(res, NATIVE_ERROR_OK);
858    code = SET_USAGE;
859    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
860    res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, usage);
861    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
862    int fenceFd = -1;
863    int32_t retq = OH_NativeWindow_NativeWindowRequestBuffer(nativewindow, &nativeWindowBuffer, &fenceFd);
864    struct Region *region = new Region();
865    struct Region::Rect *rect = new Region::Rect();
866    rect->x = 0x100;
867    rect->y = 0x100;
868    rect->w = 0x100;
869    rect->h = 0x100;
870    region->rects = rect;
871    retq = OH_NativeWindow_NativeWindowFlushBuffer(nativewindow, nativeWindowBuffer, fenceFd, *region);
872    int32_t ret = OH_NativeImage_AcquireNativeWindowBuffer(image, &nativeWindowBuffer, &fenceFd);
873    int32_t ret1 = OH_NativeImage_ReleaseNativeWindowBuffer(image, nativeWindowBuffer, fenceFd);
874    ASSERT_EQ(ret, NATIVE_ERROR_OK);
875    ASSERT_EQ(ret1, NATIVE_ERROR_OK);
876    OH_NativeImage_Destroy(&image);
877    OH_NativeWindow_DestroyNativeWindow(nativewindow);
878}
879
880/*
881 * @tc.name: OHNativeImageAcquireNativeWindowBufferCalls
882 * @tc.desc: test for Calls OH_NativeImage_AcquireNativeWindowBuffer and check ret.
883 * @tc.size  : MediumTest
884 * @tc.type  : Function
885 * @tc.level : Level 2
886 */
887HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBufferCalls, Function | MediumTest | Level2)
888{
889    if (image == nullptr) {
890        image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
891        ASSERT_NE(image, nullptr);
892    }
893    OHNativeWindow* nativewindow = OH_NativeImage_AcquireNativeWindow(image);
894    ASSERT_NE(nativewindow, nullptr);
895    int code = SET_BUFFER_GEOMETRY;
896    int32_t width = 0x100;
897    int32_t height = 0x100;
898    int32_t res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, width, height);
899    ASSERT_EQ(res, NATIVE_ERROR_OK);
900    code = SET_USAGE;
901    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
902    res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, usage);
903    OHNativeWindowBuffer* nativeWindowBuffer = nullptr;
904    int fenceFd = -1;
905    int32_t retq = OH_NativeWindow_NativeWindowRequestBuffer(nativewindow, &nativeWindowBuffer, &fenceFd);
906    struct Region *region = new Region();
907    struct Region::Rect *rect = new Region::Rect();
908    rect->x = 0x100;
909    rect->y = 0x100;
910    rect->w = 0x100;
911    rect->h = 0x100;
912    region->rects = rect;
913    retq = OH_NativeWindow_NativeWindowFlushBuffer(nativewindow, nativeWindowBuffer, fenceFd, *region);
914    int32_t ret0;
915    for (int i = 0; i < 10; i++) {
916        ret0 = OH_NativeImage_AcquireNativeWindowBuffer(image, &nativeWindowBuffer, &fenceFd);
917    }
918    int32_t ret = OH_NativeImage_AcquireNativeWindowBuffer(image, &nativeWindowBuffer, &fenceFd);
919    int32_t ret1 = OH_NativeImage_ReleaseNativeWindowBuffer(image, nativeWindowBuffer, fenceFd);
920    ASSERT_EQ(ret0, NATIVE_ERROR_NO_BUFFER);
921    ASSERT_EQ(ret, NATIVE_ERROR_NO_BUFFER);
922    ASSERT_EQ(ret1, NATIVE_ERROR_OK);
923    OH_NativeImage_Destroy(&image);
924    OH_NativeWindow_DestroyNativeWindow(nativewindow);
925}
926/*
927 * @tc.name: OHNativeImageReleaseNativeWindowBufferAbnormal001
928 * @tc.desc: test for Abnormal OH_NativeImage_AcquireNativeWindowBuffer and check ret.
929 * @tc.size  : MediumTest
930 * @tc.type  : Function
931 * @tc.level : Level 3
932 */
933HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBufferAbnormal001, Function | MediumTest | Level3)
934{
935    if (image == nullptr) {
936        image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
937        ASSERT_NE(image, nullptr);
938    }
939    OHNativeWindow* nativewindow = OH_NativeImage_AcquireNativeWindow(image);
940    ASSERT_NE(nativewindow, nullptr);
941    int code = SET_BUFFER_GEOMETRY;
942    int32_t width = 0x100;
943    int32_t height = 0x100;
944    int32_t res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, width, height);
945    ASSERT_EQ(res, NATIVE_ERROR_OK);
946    code = SET_USAGE;
947    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
948    res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, usage);
949    OHNativeWindowBuffer* nativeWindowBuffer = 0;
950    int fenceFd = -1;
951    int32_t retq = OH_NativeWindow_NativeWindowRequestBuffer(nativewindow, &nativeWindowBuffer, &fenceFd);
952    struct Region *region = new Region();
953    struct Region::Rect *rect = new Region::Rect();
954    rect->x = 0x100;
955    rect->y = 0x100;
956    rect->w = 0x100;
957    rect->h = 0x100;
958    region->rects = rect;
959    retq = OH_NativeWindow_NativeWindowFlushBuffer(nativewindow, nativeWindowBuffer, fenceFd, *region);
960    int32_t ret = OH_NativeImage_AcquireNativeWindowBuffer(image, &nativeWindowBuffer, &fenceFd);
961    int32_t ret1 = OH_NativeImage_ReleaseNativeWindowBuffer(image, 0, fenceFd);
962    ASSERT_EQ(ret, NATIVE_ERROR_OK);
963    ASSERT_EQ(ret1, NATIVE_ERROR_INVALID_ARGUMENTS);
964    delete region;
965    OH_NativeImage_Destroy(&image);
966    OH_NativeWindow_DestroyNativeWindow(nativewindow);
967}
968/*
969 * @tc.name: OHNativeImageReleaseNativeWindowBufferAbnormal002
970 * @tc.desc: test for Abnormal OH_NativeImage_AcquireNativeWindowBuffer and check ret.
971 * @tc.size  : MediumTest
972 * @tc.type  : Function
973 * @tc.level : Level 3
974 */
975HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBufferAbnormal002, Function | MediumTest | Level3)
976{
977    if (image == nullptr) {
978        image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
979        ASSERT_NE(image, nullptr);
980    }
981    OHNativeWindow* nativewindow = OH_NativeImage_AcquireNativeWindow(image);
982    ASSERT_NE(nativewindow, nullptr);
983    int code = SET_BUFFER_GEOMETRY;
984    int32_t width = 0x100;
985    int32_t height = 0x100;
986    int32_t res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, width, height);
987    ASSERT_EQ(res, NATIVE_ERROR_OK);
988    code = SET_USAGE;
989    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
990    res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, usage);
991    OHNativeWindowBuffer* nativeWindowBuffer = nullptr;
992    int fenceFd = -1;
993    int32_t retq = OH_NativeWindow_NativeWindowRequestBuffer(nativewindow, &nativeWindowBuffer, &fenceFd);
994    struct Region *region = new Region();
995    struct Region::Rect *rect = new Region::Rect();
996    rect->x = 0x100;
997    rect->y = 0x100;
998    rect->w = 0x100;
999    rect->h = 0x100;
1000    region->rects = rect;
1001    retq = OH_NativeWindow_NativeWindowFlushBuffer(nativewindow, nativeWindowBuffer, fenceFd, *region);
1002    image = nullptr;
1003    int32_t ret2 = OH_NativeImage_AcquireNativeWindowBuffer(image, &nativeWindowBuffer, &fenceFd);
1004    int32_t ret3 = OH_NativeImage_ReleaseNativeWindowBuffer(image, nativeWindowBuffer, fenceFd);
1005    ASSERT_EQ(ret2, NATIVE_ERROR_INVALID_ARGUMENTS);
1006    ASSERT_EQ(ret3, NATIVE_ERROR_INVALID_ARGUMENTS);
1007    delete region;
1008    OH_NativeImage_Destroy(&image);
1009    OH_NativeWindow_DestroyNativeWindow(nativewindow);
1010}
1011/*
1012 * @tc.name: OHNativeImageReleaseNativeWindowBufferAbnormal003
1013 * @tc.desc: test for Abnormal OH_NativeImage_AcquireNativeWindowBuffer and check ret.
1014 * @tc.size  : MediumTest
1015 * @tc.type  : Function
1016 * @tc.level : Level 3
1017 */
1018HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBufferAbnormal003, Function | MediumTest | Level3)
1019{
1020    if (image == nullptr) {
1021        image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
1022        ASSERT_NE(image, nullptr);
1023    }
1024    OHNativeWindow* nativewindow = OH_NativeImage_AcquireNativeWindow(image);
1025    ASSERT_NE(nativewindow, nullptr);
1026    int code = SET_BUFFER_GEOMETRY;
1027    int32_t width = 0x100;
1028    int32_t height = 0x100;
1029    int32_t res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, width, height);
1030    ASSERT_EQ(res, NATIVE_ERROR_OK);
1031    code = SET_USAGE;
1032    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
1033    res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, usage);
1034    OHNativeWindowBuffer* nativeWindowBuffer = nullptr;
1035    int fenceFd = -1;
1036    int32_t retq = OH_NativeWindow_NativeWindowRequestBuffer(nativewindow, &nativeWindowBuffer, &fenceFd);
1037    struct Region *region = new Region();
1038    struct Region::Rect *rect = new Region::Rect();
1039    rect->x = 0x100;
1040    rect->y = 0x100;
1041    rect->w = 0x100;
1042    rect->h = 0x100;
1043    region->rects = rect;
1044    retq = OH_NativeWindow_NativeWindowFlushBuffer(nativewindow, nativeWindowBuffer, fenceFd, *region);
1045    image = 0;
1046    int32_t ret4 = OH_NativeImage_AcquireNativeWindowBuffer(image, &nativeWindowBuffer, &fenceFd);
1047    int32_t ret5 = OH_NativeImage_ReleaseNativeWindowBuffer(image, nativeWindowBuffer, fenceFd);
1048    ASSERT_EQ(ret4, NATIVE_ERROR_INVALID_ARGUMENTS);
1049    ASSERT_EQ(ret5, NATIVE_ERROR_INVALID_ARGUMENTS);
1050    delete region;
1051    OH_NativeImage_Destroy(&image);
1052    OH_NativeWindow_DestroyNativeWindow(nativewindow);
1053}
1054/*
1055 * @tc.name: OHNativeImageReleaseNativeWindowBufferAbnormal004
1056 * @tc.desc: test for Abnormal OH_NativeImage_AcquireNativeWindowBuffer and check ret.
1057 * @tc.size  : MediumTest
1058 * @tc.type  : Function
1059 * @tc.level : Level 3
1060 */
1061HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBufferAbnormal004, Function | MediumTest | Level3)
1062{
1063    if (image == nullptr) {
1064        image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
1065        ASSERT_NE(image, nullptr);
1066    }
1067    OHNativeWindow* nativewindow = OH_NativeImage_AcquireNativeWindow(image);
1068    ASSERT_NE(nativewindow, nullptr);
1069    int code = SET_BUFFER_GEOMETRY;
1070    int32_t width = 0x100;
1071    int32_t height = 0x100;
1072    int32_t res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, width, height);
1073    ASSERT_EQ(res, NATIVE_ERROR_OK);
1074    code = SET_USAGE;
1075    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
1076    res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, usage);
1077    OHNativeWindowBuffer* nativeWindowBuffer = nullptr;
1078    int fenceFd = 0;
1079    int32_t retq = OH_NativeWindow_NativeWindowRequestBuffer(nativewindow, &nativeWindowBuffer, &fenceFd);
1080    struct Region *region = new Region();
1081    struct Region::Rect *rect = new Region::Rect();
1082    rect->x = 0x100;
1083    rect->y = 0x100;
1084    rect->w = 0x100;
1085    rect->h = 0x100;
1086    region->rects = rect;
1087    retq = OH_NativeWindow_NativeWindowFlushBuffer(nativewindow, nativeWindowBuffer, fenceFd, *region);
1088    int32_t ret6 = OH_NativeImage_AcquireNativeWindowBuffer(image, &nativeWindowBuffer, 0);
1089    int32_t ret7 = OH_NativeImage_AcquireNativeWindowBuffer(image, &nativeWindowBuffer, &fenceFd);
1090    ret7 = OH_NativeImage_ReleaseNativeWindowBuffer(image, nativeWindowBuffer, 0);
1091    ASSERT_EQ(ret6, NATIVE_ERROR_INVALID_ARGUMENTS);
1092    ASSERT_EQ(ret7, NATIVE_ERROR_OK);
1093    delete region;
1094    OH_NativeImage_Destroy(&image);
1095    OH_NativeWindow_DestroyNativeWindow(nativewindow);
1096}
1097/*
1098 * @tc.name: OHNativeImageReleaseNativeWindowBufferAbnormal005
1099 * @tc.desc: test for Abnormal OH_NativeImage_AcquireNativeWindowBuffer and check ret.
1100 * @tc.size  : MediumTest
1101 * @tc.type  : Function
1102 * @tc.level : Level 3
1103 */
1104HWTEST_F(NativeImageTest, OHNativeImageAcquireNativeWindowBufferAbnormal005, Function | MediumTest | Level3)
1105{
1106    if (image == nullptr) {
1107        image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
1108        ASSERT_NE(image, nullptr);
1109    }
1110    OHNativeWindow* nativewindow = OH_NativeImage_AcquireNativeWindow(image);
1111    ASSERT_NE(nativewindow, nullptr);
1112    int code = SET_BUFFER_GEOMETRY;
1113    int32_t width = 0x100;
1114    int32_t height = 0x100;
1115    int32_t res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, width, height);
1116    ASSERT_EQ(res, NATIVE_ERROR_OK);
1117    code = SET_USAGE;
1118    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
1119    res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, usage);
1120    OHNativeWindowBuffer* nativeWindowBuffer = nullptr;
1121    int fenceFd = -1;
1122    int32_t retq = OH_NativeWindow_NativeWindowRequestBuffer(nativewindow, &nativeWindowBuffer, &fenceFd);
1123    struct Region *region = new Region();
1124    struct Region::Rect *rect = new Region::Rect();
1125    rect->x = 0x100;
1126    rect->y = 0x100;
1127    rect->w = 0x100;
1128    rect->h = 0x100;
1129    region->rects = rect;
1130    retq = OH_NativeWindow_NativeWindowFlushBuffer(nativewindow, nativeWindowBuffer, fenceFd, *region);
1131    int32_t ret8 = OH_NativeImage_ReleaseNativeWindowBuffer(image, nativeWindowBuffer, fenceFd);
1132    int32_t ret9 = OH_NativeImage_AcquireNativeWindowBuffer(image, &nativeWindowBuffer, &fenceFd);
1133    ASSERT_EQ(ret8, NATIVE_ERROR_BUFFER_STATE_INVALID);
1134    ASSERT_EQ(ret9, NATIVE_ERROR_OK);
1135    delete region;
1136    OH_NativeImage_Destroy(&image);
1137    OH_NativeWindow_DestroyNativeWindow(nativewindow);
1138}
1139/*
1140 * @tc.name: OHNativeImageReleaseNativeWindowBufferAbnormal006
1141 * @tc.desc: test for Abnormal OH_NativeImage_ReleaseNativeWindowBuffer and check ret.
1142 * @tc.size  : MediumTest
1143 * @tc.type  : Function
1144 * @tc.level : Level 3
1145 */
1146HWTEST_F(NativeImageTest, OHNativeImageReleaseNativeWindowBufferAbnormal006, Function | MediumTest | Level3)
1147{
1148    if (image == nullptr) {
1149        image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
1150        ASSERT_NE(image, nullptr);
1151    }
1152    OHNativeWindow* nativewindow = OH_NativeImage_AcquireNativeWindow(image);
1153    ASSERT_NE(nativewindow, nullptr);
1154    int code = SET_BUFFER_GEOMETRY;
1155    int32_t width = 0x100;
1156    int32_t height = 0x100;
1157    int32_t res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, width, height);
1158    ASSERT_EQ(res, NATIVE_ERROR_OK);
1159    code = SET_USAGE;
1160    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
1161    res = OH_NativeWindow_NativeWindowHandleOpt(nativewindow, code, usage);
1162    OHNativeWindowBuffer* nativeWindowBuffer = nullptr;
1163    int fenceFd = -1;
1164    int32_t retq = OH_NativeWindow_NativeWindowRequestBuffer(nativewindow, &nativeWindowBuffer, &fenceFd);
1165    struct Region *region = new Region();
1166    struct Region::Rect *rect = new Region::Rect();
1167    rect->x = 0x100;
1168    rect->y = 0x100;
1169    rect->w = 0x100;
1170    rect->h = 0x100;
1171    region->rects = rect;
1172    retq = OH_NativeWindow_NativeWindowFlushBuffer(nativewindow, nativeWindowBuffer, fenceFd, *region);
1173    int32_t ret12 = OH_NativeImage_ReleaseNativeWindowBuffer(image, nativeWindowBuffer, fenceFd);
1174    ASSERT_EQ(ret12, NATIVE_ERROR_BUFFER_STATE_INVALID);
1175    delete region;
1176    OH_NativeImage_Destroy(&image);
1177    OH_NativeWindow_DestroyNativeWindow(nativewindow);
1178}
1179/*
1180 * @tc.name: OHConsumerSurfaceCreateNormal
1181 * @tc.desc: test for call OH_ConsumerSurface_Create and check ret.
1182 * @tc.size  : MediumTest
1183 * @tc.type  : Function
1184 * @tc.level : Level 1
1185 */
1186HWTEST_F(NativeImageTest, OHConsumerSurfaceCreateNormal, Function | MediumTest | Level1)
1187{
1188    OH_NativeImage* newImage = nullptr;
1189    newImage = OH_ConsumerSurface_Create();
1190    ASSERT_NE(newImage, nullptr);
1191    OHNativeWindow* newNativeWindow = OH_NativeImage_AcquireNativeWindow(newImage);
1192    ASSERT_NE(newNativeWindow, nullptr);
1193    int code = SET_BUFFER_GEOMETRY;
1194    int32_t width = 0x100;
1195    int32_t height = 0x100;
1196    int32_t res = OH_NativeWindow_NativeWindowHandleOpt(newNativeWindow, code, width, height);
1197    ASSERT_EQ(res, NATIVE_ERROR_OK);
1198    code = SET_USAGE;
1199    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
1200    res = OH_NativeWindow_NativeWindowHandleOpt(newNativeWindow, code, usage);
1201    OHNativeWindowBuffer* newNativeWindowBuffer = nullptr;
1202    int fenceFd;
1203    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(newNativeWindow, &newNativeWindowBuffer, &fenceFd);
1204    struct Region *region = new Region();
1205    struct Region::Rect *rect = new Region::Rect();
1206    rect->x = 0x100;
1207    rect->y = 0x100;
1208    rect->w = 0x100;
1209    rect->h = 0x100;
1210    region->rects = rect;
1211    ret = OH_NativeWindow_NativeWindowFlushBuffer(newNativeWindow, newNativeWindowBuffer, fenceFd, *region);
1212    ret = OH_NativeImage_AcquireNativeWindowBuffer(newImage, &newNativeWindowBuffer, &fenceFd);
1213    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1214    ASSERT_NE(newNativeWindowBuffer, nullptr);
1215    ret = OH_NativeImage_ReleaseNativeWindowBuffer(newImage, newNativeWindowBuffer, fenceFd);
1216    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1217    uint64_t surfaceId = 999999999;
1218    ret = OH_NativeImage_GetSurfaceId(newImage, &surfaceId);
1219    ASSERT_NE(surfaceId, 999999999);
1220    OH_OnFrameAvailableListener listener;
1221    listener.context = this;
1222    listener.onFrameAvailable = NativeImageTest::OnFrameAvailable;
1223    ret = OH_NativeImage_SetOnFrameAvailableListener(newImage, listener);
1224    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1225    ret = OH_NativeImage_UnsetOnFrameAvailableListener(newImage);
1226    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1227    OH_NativeImage_Destroy(&newImage);
1228    ASSERT_EQ(newImage, nullptr);
1229    OH_NativeWindow_DestroyNativeWindow(newNativeWindow);
1230}
1231
1232/*
1233 * @tc.name: OHConsumerSurfaceCreateMuch
1234 * @tc.desc: test for call OH_ConsumerSurface_Create and check ret.
1235 * @tc.size  : MediumTest
1236 * @tc.type  : Function
1237 * @tc.level : Level 1
1238 */
1239HWTEST_F(NativeImageTest, OHConsumerSurfaceCreateMuch, Function | MediumTest | Level1)
1240{
1241    OH_NativeImage* newImage[500];
1242    for (int i = 0; i < 500; i++) {
1243        newImage[i] = nullptr;
1244        newImage[i] = OH_ConsumerSurface_Create();
1245        ASSERT_NE(newImage[i], nullptr);
1246    }
1247    for (int i = 0; i < 500; i++) {
1248        OH_NativeImage_Destroy(&newImage[i]);
1249        ASSERT_EQ(newImage[i], nullptr);
1250    }
1251}
1252/*
1253 * @tc.name: OHConsumerSurfaceSetDefaultUsageNormal
1254 * @tc.desc: test for Normal OH_ConsumerSuface_SetDefaultUsage and check ret.
1255 * @tc.size  : MediumTest
1256 * @tc.type  : Function
1257 * @tc.level : Level 1
1258 */
1259HWTEST_F(NativeImageTest, OHConsumerSurfaceSetDefaultUsageNormal, Function | MediumTest | Level1)
1260{
1261    OH_NativeImage* image = nullptr;
1262    image = OH_ConsumerSurface_Create();
1263    ASSERT_NE(image, nullptr);
1264    int32_t ret = OH_ConsumerSurface_SetDefaultUsage(image, 0);
1265    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1266    int32_t ret1 = OH_ConsumerSurface_SetDefaultUsage(image, 1000);
1267    ASSERT_EQ(ret1, NATIVE_ERROR_OK);
1268    int32_t ret2 = OH_ConsumerSurface_SetDefaultUsage(image, UINT64_MAX - 1);
1269    ASSERT_EQ(ret2, NATIVE_ERROR_OK);
1270
1271    uint64_t usage[] = {0, 1000, UINT64_MAX - 1};
1272    for (int i = 0; i < 3; i++) {
1273        usage[i] += 1;
1274        int32_t ret3 = OH_ConsumerSurface_SetDefaultUsage(image, usage[i]);
1275        ASSERT_EQ(ret3, NATIVE_ERROR_OK);
1276    }
1277    for (int i = 0; i < 100000; i++) {
1278        int32_t ret4 = OH_ConsumerSurface_SetDefaultUsage(image, 100);
1279        ASSERT_EQ(ret4, NATIVE_ERROR_OK);
1280    }
1281    OH_NativeImage_Destroy(&image);
1282}
1283/*
1284 * @tc.name: OHConsumerSurfaceSetDefaultUsageAbnormal
1285 * @tc.desc: test for AbNormal OH_ConsumerSuface_SetDefaultUsage and check ret.
1286 * @tc.size  : MediumTest
1287 * @tc.type  : Function
1288 * @tc.level : Level 3
1289 */
1290HWTEST_F(NativeImageTest, OHConsumerSurfaceSetDefaultUsageAbnormal, Function | MediumTest | Level3)
1291{
1292    OH_NativeImage* image = nullptr;
1293    image = OH_ConsumerSurface_Create();
1294    ASSERT_NE(image, nullptr);
1295    int32_t ret = OH_ConsumerSurface_SetDefaultUsage(image, -1);
1296    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1297    int32_t ret1 = OH_ConsumerSurface_SetDefaultUsage(image, -1000);
1298    ASSERT_EQ(ret1, NATIVE_ERROR_OK);
1299    int32_t ret2 = OH_ConsumerSurface_SetDefaultUsage(image, UINT64_MAX);
1300    ASSERT_EQ(ret2, NATIVE_ERROR_OK);
1301    int32_t ret3 = OH_ConsumerSurface_SetDefaultUsage(image, -UINT64_MAX);
1302    ASSERT_EQ(ret3, NATIVE_ERROR_OK);
1303    int32_t ret4 = OH_ConsumerSurface_SetDefaultUsage(nullptr, 100);
1304    ASSERT_EQ(ret4, NATIVE_ERROR_INVALID_ARGUMENTS);
1305    OH_NativeImage_Destroy(&image);
1306}
1307/*
1308 * @tc.name: OHConsumerSurfaceSetDefaultSizeNormal
1309 * @tc.desc: test for Normal OH_ConsumerSuface_SetDefaultSize and check ret.
1310 * @tc.size  : MediumTest
1311 * @tc.type  : Function
1312 * @tc.level : Level 1
1313 */
1314HWTEST_F(NativeImageTest, OHConsumerSurfaceSetDefaultSizeNormal, Function | MediumTest | Level1)
1315{
1316    OH_NativeImage* image = nullptr;
1317    image = OH_ConsumerSurface_Create();
1318    ASSERT_NE(image, nullptr);
1319    int32_t res = 1 << 16;
1320    int32_t ret = OH_ConsumerSurface_SetDefaultSize(image, 1, 1);
1321    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1322    int32_t ret1 = OH_ConsumerSurface_SetDefaultSize(image, 1, res - 1);
1323    ASSERT_EQ(ret1, NATIVE_ERROR_OK);
1324    int32_t ret2 = OH_ConsumerSurface_SetDefaultSize(image, res - 1, 1);
1325    ASSERT_EQ(ret2, NATIVE_ERROR_OK);
1326    int32_t ret3 = OH_ConsumerSurface_SetDefaultSize(image, 100, 100);
1327    ASSERT_EQ(ret3, NATIVE_ERROR_OK);
1328    int32_t ret4 = OH_ConsumerSurface_SetDefaultSize(image, 10000, 10000);
1329    ASSERT_EQ(ret4, NATIVE_ERROR_OK);
1330    int32_t ret5 = OH_ConsumerSurface_SetDefaultSize(image, res - 1, res - 1);
1331    ASSERT_EQ(ret5, NATIVE_ERROR_OK);
1332
1333    int32_t w[] = {1, 100, 10000};
1334    int32_t h[] = {1, 100, 10000};
1335    for (int i = 0; i < 3; i++) {
1336        w[i] += 1;
1337        h[i] += 1;
1338        int32_t ret6 = OH_ConsumerSurface_SetDefaultSize(image, w[i], h[i]);
1339        ASSERT_EQ(ret6, NATIVE_ERROR_OK);
1340    }
1341    for (int i = 0; i < 100000; i++) {
1342        int32_t ret7 = OH_ConsumerSurface_SetDefaultSize(image, 1, 1);
1343        ASSERT_EQ(ret7, NATIVE_ERROR_OK);
1344    }
1345    OH_NativeImage_Destroy(&image);
1346}
1347/*
1348 * @tc.name: OHConsumerSurfaceSetDefaultSizeAbNormal
1349 * @tc.desc: test for AbNormal OH_ConsumerSuface_SetDefaultSize and check ret.
1350 * @tc.size  : MediumTest
1351 * @tc.type  : Function
1352 * @tc.level : Level 3
1353 */
1354HWTEST_F(NativeImageTest, OHConsumerSurfaceSetDefaultSizeAbNormal, Function | MediumTest | Level3)
1355{
1356    OH_NativeImage* image = nullptr;
1357    image = OH_ConsumerSurface_Create();
1358    ASSERT_NE(image, nullptr);
1359    int32_t res = 1 << 16;
1360    int32_t ret = OH_ConsumerSurface_SetDefaultSize(image, 1, 0);
1361    ASSERT_EQ(ret, NATIVE_ERROR_INVALID_ARGUMENTS);
1362    int32_t ret1 = OH_ConsumerSurface_SetDefaultSize(image, -1, 0);
1363    ASSERT_EQ(ret1, NATIVE_ERROR_INVALID_ARGUMENTS);
1364    int32_t ret2 = OH_ConsumerSurface_SetDefaultSize(image, 0, -1);
1365    ASSERT_EQ(ret2, NATIVE_ERROR_INVALID_ARGUMENTS);
1366    int32_t ret3 = OH_ConsumerSurface_SetDefaultSize(image, -1000, -1000);
1367    ASSERT_EQ(ret3, NATIVE_ERROR_INVALID_ARGUMENTS);
1368    int32_t ret4 = OH_ConsumerSurface_SetDefaultSize(image, 1000, -1000);
1369    ASSERT_EQ(ret4, NATIVE_ERROR_INVALID_ARGUMENTS);
1370    int32_t ret5 = OH_ConsumerSurface_SetDefaultSize(image, -res, 100);
1371    ASSERT_EQ(ret5, NATIVE_ERROR_INVALID_ARGUMENTS);
1372    int32_t ret6 = OH_ConsumerSurface_SetDefaultSize(image, -100, res - 1);
1373    ASSERT_EQ(ret6, NATIVE_ERROR_INVALID_ARGUMENTS);
1374    int32_t ret7 = OH_ConsumerSurface_SetDefaultSize(image, -res, -res);
1375    ASSERT_EQ(ret7, NATIVE_ERROR_INVALID_ARGUMENTS);
1376    int32_t ret8 = OH_ConsumerSurface_SetDefaultSize(image, res + 1, res + 1);
1377    ASSERT_EQ(ret8, NATIVE_ERROR_OK);
1378    int32_t ret9 = OH_ConsumerSurface_SetDefaultSize(nullptr, 100, 100);
1379    ASSERT_EQ(ret9, NATIVE_ERROR_INVALID_ARGUMENTS);
1380    OH_NativeImage_Destroy(&image);
1381}
1382}
1383