1/*
2 * Copyright (c) 2023 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
16//
17// Created on 2024/8/7.
18//
19// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
20// please include "napi/native_api.h".
21
22#include "napi/native_api.h"
23#include <bits/alltypes.h>
24#include <GLES2/gl2.h>
25#include <multimedia/player_framework/native_avcodec_base.h>
26#include <native_image/native_image.h>
27#include <native_window/external_window.h>
28#include <native_buffer/native_buffer.h>
29#include "ace/xcomponent/native_interface_xcomponent.h"
30#include <string>
31
32#define SUCCESS 0
33#define FAIL (-1)
34
35#define CONSTANT_2147483647 2147483647
36#define CONSTANT_2147483648 2147483648
37#define CONSTANT_NEG_2147483647 (-2147483647)
38#define CONSTANT_NEG_2147483648 (-2147483648)
39#define CONSTANT_NEG_9223372036854775807 (9223372036854775807)
40#define CONSTANT_NEG_9223372036854775808 (-9223372036854775808)
41
42
43#define CONSTANT_0 0
44#define CONSTANT_1 1
45#define CONSTANT_2 2
46#define CONSTANT_3 3
47#define CONSTANT_4 4
48#define CONSTANT_5 5
49#define CONSTANT_6 6
50#define CONSTANT_7 7
51#define CONSTANT_8 8
52#define CONSTANT_60 60
53#define CONSTANT_2999 2999
54#define CONSTANT_3000 3000
55#define CONSTANT_3001 3001
56
57#define CONSTANT_100 100
58#define CONSTANT_1000 1000
59#define CONSTANT_10000 10000
60#define CONSTANT_100000 100000
61#define CONSTANT_1000000 1000000
62#define CONSTANT_10000000 10000000
63#define CONSTANT_100000000 100000000
64#define CONSTANT_1000000000 1000000000
65
66#define CONSTANT_1999999 1999999
67#define CONSTANT_99999999 99999999
68#define CONSTANT_99999999999999999 99999999999999999
69#define CONSTANT_999999999999999999 999999999999999999
70
71#define CONSTANT_40001000 40001000
72#define CONSTANT_50002000 50002000
73#define CONSTANT_50102000 50102000
74
75struct result {
76    OH_NativeImage *image;
77    OHNativeWindow *nativeWindow;
78};
79
80static result InitNativeWindow()
81{
82    struct result result1;
83    GLuint textureId;
84    glGenTextures(1, &textureId);
85    auto _image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
86    result1.image = _image;
87    OHNativeWindow *_nativeWindow = OH_NativeImage_AcquireNativeWindow(_image);
88    result1.nativeWindow = _nativeWindow;
89    int code = SET_BUFFER_GEOMETRY;
90    int32_t width_ = 0x100;
91    int32_t height_ = 0x100;
92    int32_t ret = OH_NativeWindow_NativeWindowHandleOpt(_nativeWindow, code, width_, height_);
93    code = SET_USAGE;
94    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
95    ret = OH_NativeWindow_NativeWindowHandleOpt(_nativeWindow, code, usage);
96    return result1;
97}
98
99static void DestroyNativeWindowImage(OH_NativeImage *image, OHNativeWindow *window)
100{
101    OH_NativeImage_Destroy(&image);
102    OH_NativeWindow_DestroyNativeWindow(window);
103}
104
105napi_value testNativeWindowNativeWindowHandleOptSetGetFormatNormal(napi_env env, napi_callback_info info)
106{
107    napi_value result = nullptr;
108    struct result result1 = InitNativeWindow();
109    OH_NativeImage *image = result1.image;
110    OHNativeWindow *nativeWindow = result1.nativeWindow;
111
112    OH_NativeBuffer_Format arr[] = {
113        NATIVEBUFFER_PIXEL_FMT_CLUT8,        NATIVEBUFFER_PIXEL_FMT_CLUT1,        NATIVEBUFFER_PIXEL_FMT_CLUT4,
114        NATIVEBUFFER_PIXEL_FMT_RGB_565,      NATIVEBUFFER_PIXEL_FMT_RGBA_5658,    NATIVEBUFFER_PIXEL_FMT_RGBX_4444,
115        NATIVEBUFFER_PIXEL_FMT_RGBA_4444,    NATIVEBUFFER_PIXEL_FMT_RGB_444,      NATIVEBUFFER_PIXEL_FMT_RGBX_5551,
116        NATIVEBUFFER_PIXEL_FMT_RGBA_5551,    NATIVEBUFFER_PIXEL_FMT_RGB_555,      NATIVEBUFFER_PIXEL_FMT_RGBX_8888,
117        NATIVEBUFFER_PIXEL_FMT_RGBA_8888,    NATIVEBUFFER_PIXEL_FMT_RGB_888,      NATIVEBUFFER_PIXEL_FMT_BGR_565,
118        NATIVEBUFFER_PIXEL_FMT_BGRX_4444,    NATIVEBUFFER_PIXEL_FMT_BGRA_4444,    NATIVEBUFFER_PIXEL_FMT_BGRX_5551,
119        NATIVEBUFFER_PIXEL_FMT_BGRA_5551,    NATIVEBUFFER_PIXEL_FMT_BGRX_8888,    NATIVEBUFFER_PIXEL_FMT_BGRA_8888,
120        NATIVEBUFFER_PIXEL_FMT_YUV_422_I,    NATIVEBUFFER_PIXEL_FMT_YCBCR_422_SP, NATIVEBUFFER_PIXEL_FMT_YCRCB_422_SP,
121        NATIVEBUFFER_PIXEL_FMT_YCBCR_420_SP, NATIVEBUFFER_PIXEL_FMT_YCRCB_420_SP, NATIVEBUFFER_PIXEL_FMT_YCBCR_422_P,
122        NATIVEBUFFER_PIXEL_FMT_YCRCB_422_P,  NATIVEBUFFER_PIXEL_FMT_YCBCR_420_P,  NATIVEBUFFER_PIXEL_FMT_YCRCB_420_P,
123        NATIVEBUFFER_PIXEL_FMT_YUYV_422_PKG, NATIVEBUFFER_PIXEL_FMT_UYVY_422_PKG, NATIVEBUFFER_PIXEL_FMT_YVYU_422_PKG,
124        NATIVEBUFFER_PIXEL_FMT_VYUY_422_PKG, NATIVEBUFFER_PIXEL_FMT_RGBA_1010102, NATIVEBUFFER_PIXEL_FMT_YCBCR_P010,
125        NATIVEBUFFER_PIXEL_FMT_YCRCB_P010,   NATIVEBUFFER_PIXEL_FMT_RAW10,        NATIVEBUFFER_PIXEL_FMT_VENDER_MASK,
126        NATIVEBUFFER_PIXEL_FMT_BUTT};
127
128    for (int i = 0; i < sizeof(arr) / sizeof(OH_NativeBuffer_Format); ++i) {
129        auto flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_FORMAT, arr[i]);
130        if (flag != 0) {
131            napi_create_int32(env, CONSTANT_1, &result);
132            return result;
133        }
134        int32_t format;
135        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_FORMAT, &format);
136        if (flag != 0) {
137            napi_create_int32(env, CONSTANT_2, &result);
138            return result;
139        }
140        if (format != arr[i]) {
141            napi_create_int32(env, CONSTANT_3, &result);
142            return result;
143        }
144    }
145
146    DestroyNativeWindowImage(image, nativeWindow);
147    napi_create_int32(env, SUCCESS, &result);
148    return result;
149}
150
151napi_value testNativeWindowNativeWindowHandleOptSetGetFormatAbnormal(napi_env env, napi_callback_info info)
152{
153    napi_value result = nullptr;
154    struct result result1 = InitNativeWindow();
155    OH_NativeImage *image = result1.image;
156    OHNativeWindow *nativeWindow = result1.nativeWindow;
157    int32_t flag;
158    int32_t arr[] = {-CONSTANT_2147483648, -CONSTANT_2147483647, -CONSTANT_1000000, -CONSTANT_100,      -CONSTANT_1,
159                     CONSTANT_0,           CONSTANT_1,           CONSTANT_100000,   CONSTANT_2147483647};
160
161    for (int i = 0; i < sizeof(arr) / sizeof(OH_NativeBuffer_Format); ++i) {
162        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_FORMAT, arr[i]);
163        if (flag != 0) {
164            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_1, &result);
165            return result;
166        }
167        int32_t format;
168        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_FORMAT, &format);
169        if (flag != 0) {
170            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_2, &result);
171            return result;
172        }
173        if (format != arr[i]) {
174            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_3, &result);
175            return result;
176        }
177    }
178
179    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_FORMAT, "ab%^!#8c");
180    if (flag != 0) { // 应为非0
181        napi_create_int32(env, CONSTANT_100000 + CONSTANT_1, &result);
182        return result;
183    }
184    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_FORMAT, NULL);
185    if (flag != 0) { // 应为成功
186        napi_create_int32(env, CONSTANT_100000 + CONSTANT_2, &result);
187        return result;
188    }
189    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_FORMAT);
190    if (flag != 0) { // 应为成功
191        napi_create_int32(env, CONSTANT_100000 + CONSTANT_3, &result);
192        return result;
193    }
194    DestroyNativeWindowImage(image, nativeWindow);
195    napi_create_int32(env, SUCCESS, &result);
196    return result;
197}
198
199napi_value testNativeWindowNativeWindowHandleOptSetGetUsageNormal(napi_env env, napi_callback_info info)
200{
201    napi_value result = nullptr;
202    struct result result1 = InitNativeWindow();
203    OH_NativeImage *image = result1.image;
204    OHNativeWindow *nativeWindow = result1.nativeWindow;
205    int32_t flag;
206    int32_t arr[] = {-CONSTANT_2147483648, -CONSTANT_1000, -CONSTANT_1,        CONSTANT_0,
207                     CONSTANT_1,           CONSTANT_1000,  CONSTANT_100000000, CONSTANT_2147483647};
208
209    for (int i = 0; i < sizeof(arr) / sizeof(OH_NativeBuffer_Usage); ++i) {
210        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_USAGE, arr[i]);
211        if (flag != 0) {
212            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_1, &result);
213            return result;
214        }
215        int32_t usage;
216        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_USAGE, &usage);
217        if (flag != 0) {
218            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_2, &result);
219            return result;
220        }
221        if (usage != arr[i]) {
222            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_3, &result);
223            return result;
224        }
225    }
226
227    DestroyNativeWindowImage(image, nativeWindow);
228    napi_create_int32(env, SUCCESS, &result);
229    return result;
230}
231
232napi_value testNativeWindowNativeWindowHandleOptSetGetUsageAbnormal(napi_env env, napi_callback_info info)
233{
234    napi_value result = nullptr;
235    struct result result1 = InitNativeWindow();
236    OH_NativeImage *image = result1.image;
237    OHNativeWindow *nativeWindow = result1.nativeWindow;
238    int32_t flag;
239    long long arr[] = {-CONSTANT_999999999999999999, CONSTANT_999999999999999999};
240
241    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
242        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_USAGE, arr[i]);
243        if (flag != 0) {
244            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_1, &result);
245            return result;
246        }
247        int32_t usage;
248        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_USAGE, &usage);
249        if (flag != 0) {
250            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_2, &result);
251            return result;
252        }
253        if (usage == arr[i]) { // 不应相同
254            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_3, &result);
255            return result;
256        }
257    }
258
259    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_USAGE, "");
260    if (flag != 0) {
261        napi_create_int32(env, CONSTANT_100000 + CONSTANT_1, &result);
262        return result;
263    }
264    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_USAGE, NULL);
265    if (flag != 0) {
266        napi_create_int32(env, CONSTANT_2 * CONSTANT_100000 + CONSTANT_1, &result);
267        return result;
268    }
269    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_USAGE);
270    if (flag != 0) {
271        napi_create_int32(env, CONSTANT_3 * CONSTANT_100000 + CONSTANT_1, &result);
272        return result;
273    }
274    DestroyNativeWindowImage(image, nativeWindow);
275    napi_create_int32(env, SUCCESS, &result);
276    return result;
277}
278
279
280napi_value testNativeWindowNativeWindowHandleOptSetGetStrideNormal(napi_env env, napi_callback_info info)
281{
282    napi_value result = nullptr;
283
284    int32_t flag;
285    struct result result1 = InitNativeWindow();
286    OH_NativeImage *image = result1.image;
287    OHNativeWindow *nativeWindow = result1.nativeWindow;
288    int32_t arr[] = {-CONSTANT_2147483647, -CONSTANT_1000, -CONSTANT_1,        CONSTANT_0,
289                     CONSTANT_1,           CONSTANT_1000,  CONSTANT_2147483647};
290    for (int i = 0; i < sizeof(arr) / sizeof(int32_t); ++i) {
291        int32_t stride;
292        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_STRIDE, arr[i]);
293        if (flag != 0) {
294            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
295            return result;
296        }
297        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_STRIDE, &stride);
298        if (flag != 0) {
299            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
300            return result;
301        }
302        if (arr[i] != stride) {
303            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
304            return result;
305        }
306    }
307
308    DestroyNativeWindowImage(image, nativeWindow);
309    napi_create_int32(env, SUCCESS, &result);
310    return result;
311}
312
313napi_value testNativeWindowNativeWindowHandleOptSetGetStrideAbnormal(napi_env env, napi_callback_info info)
314{
315    napi_value result = nullptr;
316    int32_t flag;
317    int32_t stride;
318    struct result result1 = InitNativeWindow();
319    OH_NativeImage *image = result1.image;
320    OHNativeWindow *nativeWindow = result1.nativeWindow;
321
322    long long arr[] = {-CONSTANT_999999999999999999, static_cast<long long>(CONSTANT_999999999999999999), 1LL << 63};
323    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
324        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_STRIDE, arr[i]);
325        if (flag != 0) {
326            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
327            return result;
328        }
329        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_STRIDE, &stride);
330        if (flag != 0) {
331            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
332            return result;
333        }
334        if (arr[i] == stride) {
335            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
336            return result;
337        }
338    }
339    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_STRIDE, NULL);
340    if (flag != 0) {
341        napi_create_int32(env, CONSTANT_100000 + CONSTANT_1, &result);
342        return result;
343    }
344    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_STRIDE, "sdasda213!");
345    if (flag != 0) {
346        napi_create_int32(env, CONSTANT_2 * CONSTANT_100000 + CONSTANT_1, &result);
347        return result;
348    }
349    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_STRIDE);
350    if (flag != 0) {
351        napi_create_int32(env, CONSTANT_3 * CONSTANT_100000 + CONSTANT_1, &result);
352        return result;
353    }
354    DestroyNativeWindowImage(image, nativeWindow);
355    napi_create_int32(env, SUCCESS, &result);
356    return result;
357}
358
359
360napi_value testNativeWindowNativeWindowHandleOptSetGetSwapIntervalNormal(napi_env env, napi_callback_info info)
361{
362    napi_value result = nullptr;
363
364    int32_t flag;
365    struct result result1 = InitNativeWindow();
366    OH_NativeImage *image = result1.image;
367    OHNativeWindow *nativeWindow = result1.nativeWindow;
368
369    int32_t arr[] = {CONSTANT_0,          CONSTANT_100,        CONSTANT_1000,     CONSTANT_10000,    CONSTANT_1000000,
370                     CONSTANT_1000000000, CONSTANT_2147483647, -CONSTANT_1999999, -CONSTANT_99999999};
371    for (int i = 0; i < sizeof(arr) / sizeof(int32_t); ++i) {
372        int32_t interval;
373        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SWAP_INTERVAL, arr[i]);
374        if (flag != 0) {
375            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
376            return result;
377        }
378        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_SWAP_INTERVAL, &interval);
379        if (flag != 0) {
380            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
381            return result;
382        }
383        if (arr[i] != interval) {
384            napi_create_int32(env, i, &result);
385            return result;
386        }
387    }
388
389    DestroyNativeWindowImage(image, nativeWindow);
390    napi_create_int32(env, SUCCESS, &result);
391    return result;
392}
393
394napi_value testNativeWindowNativeWindowHandleOptSetGetSwapIntervalAbnormal(napi_env env, napi_callback_info info)
395{
396    napi_value result = nullptr;
397    int32_t flag;
398    int32_t stride;
399    struct result result1 = InitNativeWindow();
400    OH_NativeImage *image = result1.image;
401    OHNativeWindow *nativeWindow = result1.nativeWindow;
402
403    long long arr[] = {-CONSTANT_99999999999999999, static_cast<long long>(CONSTANT_99999999999999999), 1LL << 63};
404    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
405        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_STRIDE, arr[i]);
406        if (flag != 0) {
407            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
408            return result;
409        }
410        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_STRIDE, &stride);
411        if (flag != 0) {
412            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
413            return result;
414        }
415        if (arr[i] == stride) {
416            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
417            return result;
418        }
419    }
420    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_STRIDE, NULL);
421    if (flag != 0) {
422        napi_create_int32(env, CONSTANT_100000 + CONSTANT_1, &result);
423        return result;
424    }
425    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_STRIDE, "sdasda213!");
426    if (flag != 0) {
427        napi_create_int32(env, CONSTANT_2 * CONSTANT_100000 + CONSTANT_1, &result);
428        return result;
429    }
430    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_STRIDE);
431    if (flag != 0) {
432        napi_create_int32(env, CONSTANT_3 * CONSTANT_100000 + CONSTANT_1, &result);
433        return result;
434    }
435    DestroyNativeWindowImage(image, nativeWindow);
436    napi_create_int32(env, SUCCESS, &result);
437    return result;
438}
439
440
441napi_value testNativeWindowNativeWindowHandleOptSetGetColorGamutNormal(napi_env env, napi_callback_info info)
442{
443    napi_value result = nullptr;
444
445    int32_t flag;
446    struct result result1 = InitNativeWindow();
447    OH_NativeImage *image = result1.image;
448    OHNativeWindow *nativeWindow = result1.nativeWindow;
449    int32_t arr[] = {-CONSTANT_2147483647, -CONSTANT_1000, -CONSTANT_1,        CONSTANT_0,
450                     CONSTANT_1,           CONSTANT_1000,  CONSTANT_2147483647};
451    for (int i = 0; i < sizeof(arr) / sizeof(int32_t); ++i) {
452        int32_t gamut;
453        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_COLOR_GAMUT, arr[i]);
454        if (flag != 0) {
455            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
456            return result;
457        }
458        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_COLOR_GAMUT, &gamut);
459        if (flag != 0) {
460            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
461            return result;
462        }
463        if (arr[i] != gamut) {
464            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
465            return result;
466        }
467    }
468
469    DestroyNativeWindowImage(image, nativeWindow);
470    napi_create_int32(env, SUCCESS, &result);
471    return result;
472}
473
474napi_value testNativeWindowNativeWindowHandleOptSetGetColorGamutAbnormal(napi_env env, napi_callback_info info)
475{
476    napi_value result = nullptr;
477    int32_t flag;
478    int32_t gamut;
479    struct result result1 = InitNativeWindow();
480    OH_NativeImage *image = result1.image;
481    OHNativeWindow *nativeWindow = result1.nativeWindow;
482
483    long long arr[] = {-CONSTANT_99999999999999999, static_cast<long long>(CONSTANT_99999999999999999), 1LL << 63};
484    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
485        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_COLOR_GAMUT, arr[i]);
486        if (flag != 0) {
487            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
488            return result;
489        }
490        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_COLOR_GAMUT, &gamut);
491        if (flag != 0) {
492            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
493            return result;
494        }
495        if (arr[i] == gamut) {
496            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
497            return result;
498        }
499    }
500    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_COLOR_GAMUT, NULL);
501    if (flag != 0) {
502        napi_create_int32(env, CONSTANT_100000 + CONSTANT_1, &result);
503        return result;
504    }
505    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_COLOR_GAMUT, "sdasda213!");
506    if (flag != 0) {
507        napi_create_int32(env, CONSTANT_2 * CONSTANT_100000 + CONSTANT_1, &result);
508        return result;
509    }
510    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_COLOR_GAMUT);
511    if (flag != 0) {
512        napi_create_int32(env, CONSTANT_3 * CONSTANT_100000 + CONSTANT_1, &result);
513        return result;
514    }
515    DestroyNativeWindowImage(image, nativeWindow);
516    napi_create_int32(env, SUCCESS, &result);
517    return result;
518}
519
520
521napi_value testNativeWindowNativeWindowHandleOptSetGetTransformNormal(napi_env env, napi_callback_info info)
522{
523    napi_value result = nullptr;
524
525    int32_t flag;
526    struct result result1 = InitNativeWindow();
527    OH_NativeImage *image = result1.image;
528    OHNativeWindow *nativeWindow = result1.nativeWindow;
529    int32_t arr[] = {-CONSTANT_2147483647, -CONSTANT_1000, -CONSTANT_1,        CONSTANT_0,
530                     CONSTANT_1,           CONSTANT_1000,  CONSTANT_2147483647};
531    for (int i = 0; i < sizeof(arr) / sizeof(int32_t); ++i) {
532        int32_t transform;
533        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_TRANSFORM, arr[i]);
534        if (flag != 0) {
535            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
536            return result;
537        }
538        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_TRANSFORM, &transform);
539        if (flag != 0) {
540            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
541            return result;
542        }
543        if (arr[i] != transform) {
544            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
545            return result;
546        }
547    }
548
549    DestroyNativeWindowImage(image, nativeWindow);
550    napi_create_int32(env, SUCCESS, &result);
551    return result;
552}
553
554napi_value testNativeWindowNativeWindowHandleOptSetGetTransformAbnormal(napi_env env, napi_callback_info info)
555{
556    napi_value result = nullptr;
557    int32_t flag;
558    int32_t gamut;
559    struct result result1 = InitNativeWindow();
560    OH_NativeImage *image = result1.image;
561    OHNativeWindow *nativeWindow = result1.nativeWindow;
562
563    long long arr[] = {-CONSTANT_99999999999999999, static_cast<long long>(CONSTANT_99999999999999999), 1LL << 63};
564    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
565        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_TRANSFORM, arr[i]);
566        if (flag != 0) {
567            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
568            return result;
569        }
570        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_TRANSFORM, &gamut);
571        if (flag != 0) {
572            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
573            return result;
574        }
575        if (arr[i] == gamut) {
576            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
577            return result;
578        }
579    }
580    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_TRANSFORM, NULL);
581    if (flag != 0) {
582        napi_create_int32(env, CONSTANT_100000 + CONSTANT_1, &result);
583        return result;
584    }
585    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_TRANSFORM, "sdasda213!");
586    if (flag != 0) {
587        napi_create_int32(env, CONSTANT_2 * CONSTANT_100000 + CONSTANT_1, &result);
588        return result;
589    }
590    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_TRANSFORM);
591    if (flag != 0) {
592        napi_create_int32(env, CONSTANT_3 * CONSTANT_100000 + CONSTANT_1, &result);
593        return result;
594    }
595    DestroyNativeWindowImage(image, nativeWindow);
596    napi_create_int32(env, SUCCESS, &result);
597    return result;
598}
599
600
601napi_value testNativeWindowNativeWindowHandleOptSetUiTimeStampNormal(napi_env env, napi_callback_info info)
602{
603    napi_value result = nullptr;
604
605    int32_t flag;
606    struct result result1 = InitNativeWindow();
607    OH_NativeImage *image = result1.image;
608    OHNativeWindow *nativeWindow = result1.nativeWindow;
609    uint64_t arr[] = {CONSTANT_0, CONSTANT_1, CONSTANT_1000, 1ULL << 63, CONSTANT_999999999999999999};
610    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
611        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_UI_TIMESTAMP, arr[i]);
612        if (flag != 0) {
613            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
614            return result;
615        }
616    }
617
618    DestroyNativeWindowImage(image, nativeWindow);
619    napi_create_int32(env, SUCCESS, &result);
620    return result;
621}
622
623napi_value testNativeWindowNativeWindowHandleOptSetUiTimeStampAbnormal(napi_env env, napi_callback_info info)
624{
625    napi_value result = nullptr;
626
627    int32_t flag;
628    struct result result1 = InitNativeWindow();
629    OH_NativeImage *image = result1.image;
630    OHNativeWindow *nativeWindow = result1.nativeWindow;
631    int64_t arr[] = {-CONSTANT_1, -CONSTANT_1000, -CONSTANT_1000000};
632    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
633        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_UI_TIMESTAMP, arr[i]);
634        if (flag != 0) {
635            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
636            return result;
637        }
638    }
639    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_UI_TIMESTAMP, "sdasda213!");
640    if (flag != 0) {
641        napi_create_int32(env, CONSTANT_100000 + CONSTANT_1, &result);
642        return result;
643    }
644    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_UI_TIMESTAMP, NULL);
645    if (flag != 0) {
646        napi_create_int32(env, CONSTANT_2 * CONSTANT_100000 + CONSTANT_1, &result);
647        return result;
648    }
649    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_UI_TIMESTAMP);
650    if (flag != 0) {
651        napi_create_int32(env, CONSTANT_3 * CONSTANT_100000 + CONSTANT_1, &result);
652        return result;
653    }
654    DestroyNativeWindowImage(image, nativeWindow);
655    napi_create_int32(env, SUCCESS, &result);
656    return result;
657}
658
659
660napi_value testNativeWindowNativeWindowHandleOptGetBufferQueueSize(napi_env env, napi_callback_info info)
661{
662    napi_value result = nullptr;
663    struct result result1 = InitNativeWindow();
664    OH_NativeImage *image = result1.image;
665    OHNativeWindow *nativeWindow = result1.nativeWindow;
666    int32_t size;
667
668    int32_t flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_BUFFERQUEUE_SIZE, &size);
669    if (flag != 0) {
670        napi_create_int32(env, CONSTANT_1, &result);
671        return result;
672    }
673    if (size != CONSTANT_3) {
674        napi_create_int32(env, CONSTANT_2, &result);
675        return result;
676    }
677
678    DestroyNativeWindowImage(image, nativeWindow);
679    napi_create_int32(env, SUCCESS, &result);
680    return result;
681}
682
683
684napi_value testNativeWindowNativeWindowHandleOptSetHdrWhitePointBrightnessNormal(napi_env env,
685                                                                                 napi_callback_info info)
686{
687    napi_value result = nullptr;
688    struct result result1 = InitNativeWindow();
689    OH_NativeImage *image = result1.image;
690    OHNativeWindow *nativeWindow = result1.nativeWindow;
691    int32_t brightness;
692
693    float arr[] = {0.0f, 0.00001f, 0.5f, 0.123456f, 0.99999f, 1.0f};
694    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
695        int32_t flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_HDR_WHITE_POINT_BRIGHTNESS, brightness);
696        if (flag != 0) {
697            napi_create_int32(env, i + 1, &result);
698            return result;
699        }
700    }
701
702    DestroyNativeWindowImage(image, nativeWindow);
703    napi_create_int32(env, SUCCESS, &result);
704    return result;
705}
706
707
708napi_value testNativeWindowNativeWindowHandleOptSetHdrWhitePointBrightnessAbnormal(napi_env env,
709                                                                                   napi_callback_info info)
710{
711    napi_value result = nullptr;
712    struct result result1 = InitNativeWindow();
713    OH_NativeImage *image = result1.image;
714    OHNativeWindow *nativeWindow = result1.nativeWindow;
715    int32_t brightness;
716
717    float arr[] = {-0.1f, 1.1f, -CONSTANT_100, 0, CONSTANT_100};
718    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
719        int32_t flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_HDR_WHITE_POINT_BRIGHTNESS, brightness);
720        if (flag != 0) {
721            napi_create_int32(env, i + 1, &result);
722            return result;
723        }
724    }
725    int32_t flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_HDR_WHITE_POINT_BRIGHTNESS, "test123@@#");
726    if (flag != 0) {
727        napi_create_int32(env, CONSTANT_1000 + CONSTANT_1, &result);
728        return result;
729    }
730    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_HDR_WHITE_POINT_BRIGHTNESS);
731    if (flag != 0) {
732        napi_create_int32(env, CONSTANT_1000 + CONSTANT_2, &result);
733        return result;
734    }
735    DestroyNativeWindowImage(image, nativeWindow);
736    napi_create_int32(env, SUCCESS, &result);
737    return result;
738}
739
740
741napi_value testNativeWindowNativeWindowHandleOptSetSdrWhitePointBrightnessNormal(napi_env env,
742                                                                                 napi_callback_info info)
743{
744    napi_value result = nullptr;
745    struct result result1 = InitNativeWindow();
746    OH_NativeImage *image = result1.image;
747    OHNativeWindow *nativeWindow = result1.nativeWindow;
748    int32_t brightness;
749
750    float arr[] = {0.0f, 0.00001f, 0.5f, 0.123456f, 0.99999f, 1.0f};
751    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
752        int32_t flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SDR_WHITE_POINT_BRIGHTNESS, brightness);
753        if (flag != 0) {
754            napi_create_int32(env, i + 1, &result);
755            return result;
756        }
757    }
758
759    DestroyNativeWindowImage(image, nativeWindow);
760    napi_create_int32(env, SUCCESS, &result);
761    return result;
762}
763
764
765napi_value testNativeWindowNativeWindowHandleOptSetSdrWhitePointBrightnessAbnormal(napi_env env,
766                                                                                   napi_callback_info info)
767{
768    napi_value result = nullptr;
769    struct result result1 = InitNativeWindow();
770    OH_NativeImage *image = result1.image;
771    OHNativeWindow *nativeWindow = result1.nativeWindow;
772    int32_t brightness;
773
774    float arr[] = {-0.1f, 1.1f, -CONSTANT_100, 0, CONSTANT_100};
775    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
776        int32_t flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SDR_WHITE_POINT_BRIGHTNESS, brightness);
777        if (flag != 0) {
778            napi_create_int32(env, i + 1, &result);
779            return result;
780        }
781    }
782    int32_t flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SDR_WHITE_POINT_BRIGHTNESS, "test123@@#");
783    if (flag != 0) {
784        napi_create_int32(env, CONSTANT_1000 + CONSTANT_1, &result);
785        return result;
786    }
787    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SDR_WHITE_POINT_BRIGHTNESS);
788    if (flag != 0) {
789        napi_create_int32(env, CONSTANT_1000 + CONSTANT_2, &result);
790        return result;
791    }
792    DestroyNativeWindowImage(image, nativeWindow);
793    napi_create_int32(env, SUCCESS, &result);
794    return result;
795}
796
797
798napi_value testNativeWindowNativeWindowHandleOptSetGetSourceTypeNormal(napi_env env, napi_callback_info info)
799{
800    napi_value result = nullptr;
801    struct result result1 = InitNativeWindow();
802    OH_NativeImage *image = result1.image;
803    OHNativeWindow *nativeWindow = result1.nativeWindow;
804    int32_t sourceType;
805    int32_t flag;
806    for (int i = 0; i < sizeof(OHSurfaceSource); ++i) {
807        OHSurfaceSource surfaceSource = static_cast<OHSurfaceSource>(i);
808        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SOURCE_TYPE, surfaceSource);
809        if (flag != 0) {
810            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
811            return result;
812        }
813        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_SOURCE_TYPE, &sourceType);
814        if (flag != 0) {
815            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
816            return result;
817        }
818        if (sourceType != surfaceSource) {
819            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
820            return result;
821        }
822    }
823
824    DestroyNativeWindowImage(image, nativeWindow);
825    napi_create_int32(env, SUCCESS, &result);
826    return result;
827}
828
829
830napi_value testNativeWindowNativeWindowHandleOptSetGetSourceTypeAbnormal(napi_env env, napi_callback_info info)
831{
832    napi_value result = nullptr;
833
834    int32_t flag;
835    struct result result1 = InitNativeWindow();
836    OH_NativeImage *image = result1.image;
837    OHNativeWindow *nativeWindow = result1.nativeWindow;
838    int64_t arr[] = {-CONSTANT_100, -CONSTANT_1, 0, CONSTANT_1000};
839    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
840        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SOURCE_TYPE, arr[i]);
841        if (flag != 0) {
842            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
843            return result;
844        }
845        int32_t sourceType;
846        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_SOURCE_TYPE, &sourceType);
847        if (flag != 0) {
848            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
849            return result;
850        }
851        if (sourceType != arr[i]) {
852            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
853            return result;
854        }
855    }
856    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SOURCE_TYPE, CONSTANT_999999999999999999);
857    if (flag != 0) {
858        napi_create_int32(env, CONSTANT_100000 + CONSTANT_1, &result);
859        return result;
860    }
861    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SOURCE_TYPE, "sdasda213!");
862    if (flag != 0) {
863        napi_create_int32(env, CONSTANT_100000 + CONSTANT_2, &result);
864        return result;
865    }
866    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SOURCE_TYPE, NULL);
867    if (flag != 0) {
868        napi_create_int32(env, CONSTANT_100000 + CONSTANT_3, &result);
869        return result;
870    }
871    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_SOURCE_TYPE);
872    if (flag != 0) {
873        napi_create_int32(env, CONSTANT_100000 + CONSTANT_4, &result);
874        return result;
875    }
876
877    DestroyNativeWindowImage(image, nativeWindow);
878    napi_create_int32(env, SUCCESS, &result);
879    return result;
880}
881
882
883napi_value testNativeWindowNativeWindowHandleOptSetGetAppFrameworkTypeNormal(napi_env env, napi_callback_info info)
884{
885    napi_value result = nullptr;
886    int32_t flag;
887    char *frameworkType;
888    struct result result1 = InitNativeWindow();
889    OH_NativeImage *image = result1.image;
890    OHNativeWindow *nativeWindow = result1.nativeWindow;
891
892    const char *arr[] = {NULL,       "",     "   ",      "0123",
893                         "应用框架", "Test", "!@#$%&*(", "这里一共是二十一个汉字这里一共是二十一个汉"};
894
895    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
896        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_APP_FRAMEWORK_TYPE, arr[i]);
897        if (flag != 0) {
898            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
899            return result;
900        }
901        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_APP_FRAMEWORK_TYPE, &frameworkType);
902        if (flag != 0) {
903            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
904            return result;
905        }
906        if (arr[i] == frameworkType) {
907            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
908            return result;
909        }
910    }
911
912    DestroyNativeWindowImage(image, nativeWindow);
913    napi_create_int32(env, SUCCESS, &result);
914    return result;
915}
916
917
918napi_value testNativeWindowNativeWindowHandleOptSetGetAppFrameworkTypeAbnormal(napi_env env, napi_callback_info info)
919{
920    napi_value result = nullptr;
921    int32_t flag;
922    char *frameworkType;
923    struct result result1 = InitNativeWindow();
924    OH_NativeImage *image = result1.image;
925    OHNativeWindow *nativeWindow = result1.nativeWindow;
926
927    const char *arr[] = {"这里一共是二十二个汉字这里一共是二十二个汉字",
928                         "64test64!@#$%&*64test64test64aaa64test64!@#$%&*64test64test64aaa",
929                         "63test63!@#$%&*63test63test63aaa63test63!@#$%&*63test63test63aa",
930                         "65test65!@#$%&*65test65test65aaa65test65!@#$%&*65test65test65aaaa"};
931    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
932        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_APP_FRAMEWORK_TYPE, arr[i]);
933        if (flag == 0) {
934            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
935            return result;
936        }
937        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_APP_FRAMEWORK_TYPE, &frameworkType);
938        if (flag != 0) {
939            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
940            return result;
941        }
942    }
943
944    DestroyNativeWindowImage(image, nativeWindow);
945    napi_create_int32(env, SUCCESS, &result);
946    return result;
947}
948
949
950napi_value testNativeWindowNativeWindowSetSetScalingModeV2Nullptr(napi_env env, napi_callback_info info)
951{
952    napi_value result = nullptr;
953    struct result result1 = InitNativeWindow();
954    OH_NativeImage *image = result1.image;
955    OHNativeWindow *nativeWindow = result1.nativeWindow;
956
957    int32_t flag = OH_NativeWindow_NativeWindowSetScalingModeV2(nullptr, OH_SCALING_MODE_FREEZE_V2);
958    if (flag == 0) {
959        napi_create_int32(env, CONSTANT_1, &result);
960        return result;
961    }
962    flag = OH_NativeWindow_NativeWindowSetScalingModeV2(nativeWindow, static_cast<OHScalingModeV2>(CONSTANT_100));
963    if (flag == 0) {
964        napi_create_int32(env, CONSTANT_2, &result);
965        return result;
966    }
967
968    DestroyNativeWindowImage(image, nativeWindow);
969    napi_create_int32(env, SUCCESS, &result);
970    return result;
971}
972
973
974napi_value testNativeWindowNativeWindowSetScalingModeV2ScalingMode(napi_env env, napi_callback_info info)
975{
976    napi_value result = nullptr;
977    struct result result1 = InitNativeWindow();
978    OH_NativeImage *image = result1.image;
979    OHNativeWindow *nativeWindow = result1.nativeWindow;
980
981    int32_t flag;
982    OHScalingModeV2 arr[] = {OH_SCALING_MODE_FREEZE_V2, OH_SCALING_MODE_SCALE_TO_WINDOW_V2,
983                             OH_SCALING_MODE_SCALE_CROP_V2, OH_SCALING_MODE_NO_SCALE_CROP_V2,
984                             OH_SCALING_MODE_SCALE_FIT_V2};
985    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
986        flag = OH_NativeWindow_NativeWindowSetScalingModeV2(nativeWindow, OH_SCALING_MODE_FREEZE_V2);
987        if (flag != 0) {
988            napi_create_int32(env, i + 1, &result);
989            return result;
990        }
991    }
992
993    DestroyNativeWindowImage(image, nativeWindow);
994    napi_create_int32(env, SUCCESS, &result);
995    return result;
996}
997
998napi_value testNativeWindowGetColorSpaceFirst(napi_env env, napi_callback_info info)
999{
1000    napi_value result = nullptr;
1001    struct result result1 = InitNativeWindow();
1002    OH_NativeImage *image = result1.image;
1003    OHNativeWindow *nativeWindow = result1.nativeWindow;
1004    OHNativeWindowBuffer *windowBuffer = nullptr;
1005    int fenceFd;
1006    int32_t flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &windowBuffer, &fenceFd);
1007    if (flag != 0) {
1008        napi_create_int32(env, CONSTANT_1000 + CONSTANT_1, &result);
1009        return result;
1010    }
1011    OH_NativeBuffer_ColorSpace colorSpace;
1012    flag = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace);
1013    if (flag != CONSTANT_50002000 && flag != CONSTANT_50102000) {
1014        napi_create_int32(env, flag, &result);
1015        return result;
1016    }
1017
1018    DestroyNativeWindowImage(image, nativeWindow);
1019    napi_create_int32(env, SUCCESS, &result);
1020    return result;
1021}
1022
1023napi_value testNativeWindowSetColorSpaceNormal(napi_env env, napi_callback_info info)
1024{
1025    napi_value result = nullptr;
1026
1027    int32_t flag;
1028    for (int i = 0; i < sizeof(OH_NativeBuffer_ColorSpace); ++i) {
1029        OH_NativeBuffer_ColorSpace colorspace1 = static_cast<OH_NativeBuffer_ColorSpace>(i);
1030        struct result result1 = InitNativeWindow();
1031        OH_NativeImage *image = result1.image;
1032        OHNativeWindow *nativeWindow = result1.nativeWindow;
1033        OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1034        int fenceFd;
1035        auto res = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1036        Region::Rect rect{
1037            .x = 0x100,
1038            .y = 0x100,
1039            .w = 0x100,
1040            .h = 0x100,
1041        };
1042        Region region{.rects = &rect};
1043        res = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
1044        flag = OH_NativeWindow_SetColorSpace(nativeWindow, colorspace1);
1045        if (flag != 0) {
1046            napi_create_int32(env, CONSTANT_1000 * i + CONSTANT_1, &result);
1047            return result;
1048        }
1049        OH_NativeBuffer_ColorSpace colorSpace;
1050        flag = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace);
1051        if (flag != 0) {
1052            napi_create_int32(env, CONSTANT_1000 * i + CONSTANT_2, &result);
1053            return result;
1054        }
1055        if (colorSpace != colorspace1) {
1056            napi_create_int32(env, CONSTANT_1000 * i + CONSTANT_3, &result);
1057            return result;
1058        }
1059        DestroyNativeWindowImage(image, nativeWindow);
1060    }
1061
1062    napi_create_int32(env, SUCCESS, &result);
1063    return result;
1064}
1065
1066
1067napi_value testNativeWindowSetColorSpaceNullptr(napi_env env, napi_callback_info info)
1068{
1069    napi_value result = nullptr;
1070
1071    int32_t flag = OH_NativeWindow_SetColorSpace(nullptr, OH_COLORSPACE_NONE);
1072    if (flag != CONSTANT_40001000) {
1073        napi_create_int32(env, FAIL, &result);
1074        return result;
1075    }
1076
1077    napi_create_int32(env, SUCCESS, &result);
1078    return result;
1079}
1080
1081napi_value testNativeWindowSetColorSpaceAbnormal(napi_env env, napi_callback_info info)
1082{
1083    napi_value result = nullptr;
1084    struct result result1 = InitNativeWindow();
1085    OH_NativeImage *image = result1.image;
1086    OHNativeWindow *nativeWindow = result1.nativeWindow;
1087
1088    int32_t flag =
1089        OH_NativeWindow_SetColorSpace(nativeWindow, static_cast<OH_NativeBuffer_ColorSpace>(CONSTANT_100000));
1090    if (flag != CONSTANT_40001000) {
1091        napi_create_int32(env, FAIL, &result);
1092        return result;
1093    }
1094
1095    DestroyNativeWindowImage(image, nativeWindow);
1096    napi_create_int32(env, SUCCESS, &result);
1097    return result;
1098}
1099
1100
1101napi_value testNativeWindowGetColorSpaceNullptr(napi_env env, napi_callback_info info)
1102{
1103    napi_value result = nullptr;
1104
1105    int32_t flag;
1106    OH_NativeBuffer_ColorSpace ret;
1107    flag = OH_NativeWindow_GetColorSpace(nullptr, &ret);
1108    if (flag != CONSTANT_40001000) {
1109        napi_create_int32(env, FAIL, &result);
1110        return result;
1111    }
1112
1113    napi_create_int32(env, SUCCESS, &result);
1114    return result;
1115}
1116
1117
1118napi_value testNativeWindowGetMetadataValueFirst(napi_env env, napi_callback_info info)
1119{
1120    napi_value result = nullptr;
1121
1122    int32_t flag;
1123    struct result result1 = InitNativeWindow();
1124    OH_NativeImage *image = result1.image;
1125    OHNativeWindow *nativeWindow = result1.nativeWindow;
1126    int32_t ret1;
1127    uint8_t *ret2;
1128    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &ret1, &ret2);
1129    if (flag != CONSTANT_50002000 && flag != CONSTANT_50102000) {
1130        napi_create_int32(env, FAIL, &result);
1131        return result;
1132    }
1133
1134    DestroyNativeWindowImage(image, nativeWindow);
1135    napi_create_int32(env, SUCCESS, &result);
1136    return result;
1137}
1138
1139napi_value testNativeWindowSetDynamicMetadataValue1(napi_env env, napi_callback_info info,
1140                                                    OHNativeWindow *nativeWindow)
1141{
1142    napi_value result = nullptr;
1143    int32_t bufferSize;
1144    uint8_t *buffer;
1145    int32_t X = -1;
1146    uint8_t metaData[CONSTANT_60];
1147    auto flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, X, metaData);
1148    if (flag != CONSTANT_40001000) {
1149        napi_create_int32(env, CONSTANT_1000 + CONSTANT_1, &result);
1150        return result;
1151    }
1152    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &bufferSize, &buffer);
1153    if (flag != CONSTANT_50002000 && flag != CONSTANT_50102000) {
1154        napi_create_int32(env, CONSTANT_1000 + CONSTANT_2, &result);
1155        return result;
1156    }
1157    // 2. X=0 set调用失败 get调用失败
1158    X = 0;
1159    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, X, metaData);
1160    if (flag != CONSTANT_40001000) {
1161        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_1, &result);
1162        return result;
1163    }
1164    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &bufferSize, &buffer);
1165    if (flag != CONSTANT_50002000 && flag != CONSTANT_50102000) {
1166        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_2, &result);
1167        return result;
1168    }
1169    return result;
1170}
1171
1172napi_value testNativeWindowSetDynamicMetadataValue2(napi_env env, napi_callback_info info,
1173                                                    OHNativeWindow *nativeWindow)
1174{
1175    napi_value result = nullptr;
1176    int32_t bufferSize;
1177    uint8_t *buffer;
1178    uint8_t metaData[CONSTANT_60];
1179    int32_t X = 1; // 3. X=1 set调用成功 get调用成功 两者一致
1180    metaData[0] = static_cast<uint8_t>(0);
1181    int32_t flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, X, metaData);
1182    if (flag != 0) {
1183        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_1, &result);
1184        return result;
1185    }
1186    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &bufferSize, &buffer);
1187    if (flag != 0) {
1188        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_2, &result);
1189        return result;
1190    }
1191    if (bufferSize != X) {
1192        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_3, &result);
1193        return result;
1194    }
1195    X = CONSTANT_60; // 4. X=60 set调用成功 get调用成功 两者一致
1196    for (int i = 0; i < X; ++i) {
1197        metaData[i] = static_cast<uint8_t>(i);
1198    }
1199    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, CONSTANT_60, metaData);
1200    if (flag != 0) {
1201        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_1, &result);
1202        return result;
1203    }
1204    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &bufferSize, &buffer);
1205    if (flag != 0) {
1206        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_2, &result);
1207        return result;
1208    }
1209    if (bufferSize != X) {
1210        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_3, &result);
1211        return result;
1212    }
1213    return result;
1214}
1215
1216napi_value testNativeWindowSetDynamicMetadataValue3(napi_env env, napi_callback_info info,
1217                                                    OHNativeWindow *nativeWindow)
1218{
1219    napi_value result = nullptr;
1220    int32_t bufferSize;
1221    uint8_t *buffer;
1222    uint8_t metaData[CONSTANT_60];
1223    int32_t X = CONSTANT_2999;
1224    int32_t flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, X, metaData);
1225    if (flag != 0) {
1226        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_1, &result);
1227        return result;
1228    }
1229    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &bufferSize, &buffer);
1230    if (flag != 0) {
1231        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_2, &result);
1232        return result;
1233    }
1234    if (bufferSize != X) {
1235        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_3, &result);
1236        return result;
1237    }
1238    X = CONSTANT_3000;
1239    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, X, metaData);
1240    if (flag != 0) {
1241        napi_create_int32(env, CONSTANT_6 * CONSTANT_1000 + CONSTANT_1, &result);
1242        return result;
1243    }
1244    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &bufferSize, &buffer);
1245    if (flag != 0) {
1246        napi_create_int32(env, CONSTANT_6 * CONSTANT_1000 + CONSTANT_2, &result);
1247        return result;
1248    }
1249    if (bufferSize != X) {
1250        napi_create_int32(env, CONSTANT_6 * CONSTANT_1000 + CONSTANT_3, &result);
1251        return result;
1252    }
1253    return result;
1254}
1255
1256napi_value testNativeWindowSetDynamicMetadataValue4(napi_env env, napi_callback_info info,
1257                                                    OHNativeWindow *nativeWindow)
1258{
1259    napi_value result = nullptr;
1260    int32_t bufferSize;
1261    uint8_t *buffer;
1262    uint8_t metaData[CONSTANT_60];
1263    int32_t X = CONSTANT_3001;
1264    int32_t flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, X, metaData);
1265    if (flag != CONSTANT_40001000) {
1266        napi_create_int32(env, CONSTANT_7 * CONSTANT_1000 + CONSTANT_1, &result);
1267        return result;
1268    }
1269    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &bufferSize, &buffer);
1270    if (flag != 0) {
1271        napi_create_int32(env, CONSTANT_7 * CONSTANT_1000 + CONSTANT_2, &result);
1272        return result;
1273    }
1274    X = CONSTANT_100000000;
1275    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, X, metaData);
1276    if (flag != CONSTANT_40001000) {
1277        napi_create_int32(env, CONSTANT_8 * CONSTANT_1000 + CONSTANT_1, &result);
1278        return result;
1279    }
1280    return result;
1281}
1282
1283napi_value testNativeWindowSetDynamicMetadataValue(napi_env env, napi_callback_info info)
1284{
1285    napi_value result = nullptr;
1286    struct result result1 = InitNativeWindow();
1287    OH_NativeImage *image = result1.image;
1288    OHNativeWindow *nativeWindow = result1.nativeWindow;
1289    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1290    int fenceFd;
1291    auto res = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1292    Region::Rect rect{.x = 0x100, .y = 0x100, .w = 0x100, .h = 0x100};
1293    Region region{.rects = &rect};
1294    res = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
1295
1296    result = testNativeWindowSetDynamicMetadataValue1(env, info, nativeWindow);
1297    if (result != nullptr) {
1298        return result;
1299    }
1300    result = testNativeWindowSetDynamicMetadataValue2(env, info, nativeWindow);
1301    if (result != nullptr) {
1302        return result;
1303    }
1304    result = testNativeWindowSetDynamicMetadataValue3(env, info, nativeWindow);
1305    if (result != nullptr) {
1306        return result;
1307    }
1308    result = testNativeWindowSetDynamicMetadataValue4(env, info, nativeWindow);
1309    if (result != nullptr) {
1310        return result;
1311    }
1312    DestroyNativeWindowImage(image, nativeWindow);
1313    napi_create_int32(env, SUCCESS, &result);
1314    return result;
1315}
1316
1317
1318napi_value testNativeWindowSetMetadataValueTimes(napi_env env, napi_callback_info info)
1319{
1320    napi_value result = nullptr;
1321
1322    int32_t flag;
1323    struct result result1 = InitNativeWindow();
1324    OH_NativeImage *image = result1.image;
1325    OHNativeWindow *nativeWindow = result1.nativeWindow;
1326    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1327    int fenceFd;
1328    auto res = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1329    Region::Rect rect{
1330        .x = 0x100,
1331        .y = 0x100,
1332        .w = 0x100,
1333        .h = 0x100,
1334    };
1335    Region region{.rects = &rect};
1336    res = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
1337    int32_t bufferSize;
1338    uint8_t *buffer;
1339    int32_t X = CONSTANT_60;
1340    uint8_t metaData[X];
1341    for (int j = 0; j < X; ++j) {
1342        metaData[j] = static_cast<uint8_t>(j);
1343    }
1344
1345    for (int i = 0; i < CONSTANT_60; ++i) {
1346        flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, X, metaData);
1347        if (flag != 0) {
1348            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
1349            return result;
1350        }
1351        flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &bufferSize, &buffer);
1352        if (flag != 0) {
1353            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_2, &result);
1354            return result;
1355        }
1356        if (bufferSize != X) {
1357            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_3, &result);
1358            return result;
1359        }
1360    }
1361
1362    DestroyNativeWindowImage(image, nativeWindow);
1363    napi_create_int32(env, SUCCESS, &result);
1364    return result;
1365}
1366
1367
1368napi_value testNativeWindowSetStaticMetadataValue1(napi_env env, napi_callback_info info,
1369                                                   OHNativeWindow *nativeWindow)
1370{
1371    napi_value result = nullptr;
1372    int32_t bufferSize;
1373    uint8_t *buffer;
1374    uint8_t metaData[CONSTANT_60];
1375    // 1.
1376    int32_t X = -1;
1377    int32_t flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, X, metaData);
1378    if (flag != CONSTANT_40001000) {
1379        napi_create_int32(env, CONSTANT_1000 + CONSTANT_1, &result);
1380        return result;
1381    }
1382    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &bufferSize, &buffer);
1383    if (flag != CONSTANT_50002000 && flag != CONSTANT_50102000) {
1384        napi_create_int32(env, CONSTANT_1000 + CONSTANT_2, &result);
1385        return result;
1386    }
1387    // 2. X=0 set调用失败 get调用失败
1388    X = 0;
1389    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, X, metaData);
1390    if (flag != CONSTANT_40001000) {
1391        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_1, &result);
1392        return result;
1393    }
1394    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &bufferSize, &buffer);
1395    if (flag != CONSTANT_50002000 && flag != CONSTANT_50102000) {
1396        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_2, &result);
1397        return result;
1398    }
1399    return result;
1400}
1401
1402
1403napi_value testNativeWindowSetStaticMetadataValue2(napi_env env, napi_callback_info info,
1404                                                   OHNativeWindow *nativeWindow)
1405{
1406    napi_value result = nullptr;
1407    int32_t bufferSize;
1408    uint8_t *buffer;
1409    uint8_t metaData[CONSTANT_60];
1410    int32_t X = 1; // 3. X=1 set调用成功 get调用成功 两者一致
1411    metaData[0] = static_cast<uint8_t>(0);
1412    int32_t flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, X, metaData);
1413    if (flag != 0) {
1414        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_1, &result);
1415        return result;
1416    }
1417    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &bufferSize, &buffer);
1418    if (flag != 0) {
1419        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_2, &result);
1420        return result;
1421    }
1422    if (bufferSize != X) {
1423        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_3, &result);
1424        return result;
1425    }
1426    X = CONSTANT_60; // 4.
1427    for (int i = 0; i < X; ++i) {
1428        metaData[i] = static_cast<uint8_t>(i);
1429    }
1430    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, CONSTANT_60, metaData);
1431    if (flag != 0) {
1432        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_1, &result);
1433        return result;
1434    }
1435    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &bufferSize, &buffer);
1436    if (flag != 0) {
1437        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_2, &result);
1438        return result;
1439    }
1440    if (bufferSize != X) {
1441        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_3, &result);
1442        return result;
1443    }
1444    return result;
1445}
1446
1447napi_value testNativeWindowSetStaticMetadataValue3(napi_env env, napi_callback_info info,
1448                                                   OHNativeWindow *nativeWindow)
1449{
1450    napi_value result = nullptr;
1451    int32_t bufferSize;
1452    uint8_t *buffer;
1453    uint8_t metaData[CONSTANT_60];
1454
1455    int32_t X = CONSTANT_2999;
1456    int32_t flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, X, metaData);
1457    if (flag != 0) {
1458        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_1, &result);
1459        return result;
1460    }
1461    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &bufferSize, &buffer);
1462    if (flag != 0) {
1463        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_2, &result);
1464        return result;
1465    }
1466    if (bufferSize != X) {
1467        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_3, &result);
1468        return result;
1469    }
1470    X = CONSTANT_3000;
1471    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, X, metaData);
1472    if (flag != 0) {
1473        napi_create_int32(env, CONSTANT_6 * CONSTANT_1000 + CONSTANT_1, &result);
1474        return result;
1475    }
1476    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &bufferSize, &buffer);
1477    if (flag != 0) {
1478        napi_create_int32(env, CONSTANT_6 * CONSTANT_1000 + CONSTANT_2, &result);
1479        return result;
1480    }
1481    if (bufferSize != X) {
1482        napi_create_int32(env, CONSTANT_6 * CONSTANT_1000 + CONSTANT_3, &result);
1483        return result;
1484    }
1485    return result;
1486}
1487
1488napi_value testNativeWindowSetStaticMetadataValue4(napi_env env, napi_callback_info info,
1489                                                   OHNativeWindow *nativeWindow)
1490{
1491    napi_value result = nullptr;
1492    int32_t bufferSize;
1493    uint8_t *buffer;
1494    uint8_t metaData[CONSTANT_60];
1495    int32_t X = CONSTANT_3001;
1496    int32_t flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, X, buffer);
1497    if (flag != CONSTANT_40001000) {
1498        napi_create_int32(env, CONSTANT_7 * CONSTANT_1000 + CONSTANT_1, &result);
1499        return result;
1500    }
1501    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &bufferSize, &buffer);
1502    if (flag != 0) {
1503        napi_create_int32(env, CONSTANT_7 * CONSTANT_1000 + CONSTANT_2, &result);
1504        return result;
1505    }
1506    X = CONSTANT_100000000;
1507    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, X, metaData);
1508    if (flag != CONSTANT_40001000) {
1509        napi_create_int32(env, CONSTANT_8 * CONSTANT_1000 + CONSTANT_1, &result);
1510        return result;
1511    }
1512    return result;
1513}
1514
1515napi_value testNativeWindowSetStaticMetadataValue(napi_env env, napi_callback_info info)
1516{
1517    napi_value result = nullptr;
1518    struct result result1 = InitNativeWindow();
1519    OH_NativeImage *image = result1.image;
1520    OHNativeWindow *nativeWindow = result1.nativeWindow;
1521    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1522    int fenceFd;
1523    auto res = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1524    Region::Rect rect{.x = 0x100, .y = 0x100, .w = 0x100, .h = 0x100};
1525    Region region{.rects = &rect};
1526    res = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
1527
1528    result = testNativeWindowSetStaticMetadataValue1(env, info, nativeWindow);
1529    if (result != nullptr) {
1530        return result;
1531    }
1532    result = testNativeWindowSetStaticMetadataValue2(env, info, nativeWindow);
1533    if (result != nullptr) {
1534        return result;
1535    }
1536    result = testNativeWindowSetStaticMetadataValue3(env, info, nativeWindow);
1537    if (result != nullptr) {
1538        return result;
1539    }
1540    result = testNativeWindowSetStaticMetadataValue4(env, info, nativeWindow);
1541    if (result != nullptr) {
1542        return result;
1543    }
1544    DestroyNativeWindowImage(image, nativeWindow);
1545    napi_create_int32(env, SUCCESS, &result);
1546    return result;
1547}
1548
1549napi_value testNativeWindowSetMetadataValue1(napi_env env, napi_callback_info info, OHNativeWindow *nativeWindow)
1550{
1551    napi_value result = nullptr;
1552    int32_t flag;
1553    int32_t bufferSize;
1554    uint8_t *buffer;
1555    int32_t X = -1;
1556    uint8_t metaData[CONSTANT_60];
1557    // 1.
1558    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, X, metaData);
1559    if (flag != CONSTANT_40001000) {
1560        napi_create_int32(env, CONSTANT_1000 + CONSTANT_1, &result);
1561        return result;
1562    }
1563    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &bufferSize, &buffer);
1564    if (flag != CONSTANT_50002000 && flag != CONSTANT_50102000) {
1565        napi_create_int32(env, CONSTANT_1000 + CONSTANT_2, &result);
1566        return result;
1567    }
1568    // 2. X=0 set调用失败 get调用失败
1569    X = 0;
1570    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, X, metaData);
1571    if (flag != CONSTANT_40001000) {
1572        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_1, &result);
1573        return result;
1574    }
1575    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &bufferSize, &buffer);
1576    if (flag != CONSTANT_50002000 && flag != CONSTANT_50102000) {
1577        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_2, &result);
1578        return result;
1579    }
1580    return result;
1581}
1582
1583napi_value testNativeWindowSetMetadataValue2(napi_env env, napi_callback_info info, OHNativeWindow *nativeWindow)
1584{
1585    napi_value result = nullptr;
1586    int32_t bufferSize;
1587    uint8_t *buffer;
1588    int32_t X = 1; // 3. X=1 set调用成功 get调用成功 两者一致
1589    uint8_t metaData[CONSTANT_60];
1590    metaData[0] = static_cast<uint8_t>(X);
1591    auto flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, X, metaData);
1592    if (flag != 0) {
1593        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_1, &result);
1594        return result;
1595    }
1596    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &bufferSize, &buffer);
1597    if (flag != 0) {
1598        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_2, &result);
1599        return result;
1600    }
1601    if (bufferSize != CONSTANT_4) {
1602        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_3, &result);
1603        return result;
1604    }
1605    X = CONSTANT_4; // 4. X=60 set调用成功 get调用成功 两者一致
1606    for (int i = 0; i < X; ++i) {
1607        metaData[i] = static_cast<uint8_t>(i);
1608    }
1609    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, X, metaData);
1610    if (flag != 0) {
1611        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_1, &result);
1612        return result;
1613    }
1614    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &bufferSize, &buffer);
1615    if (flag != 0) {
1616        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_2, &result);
1617        return result;
1618    }
1619    if (bufferSize != CONSTANT_4) {
1620        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_3, &result);
1621        return result;
1622    }
1623    return result;
1624}
1625
1626napi_value testNativeWindowSetMetadataValue3(napi_env env, napi_callback_info info, OHNativeWindow *nativeWindow)
1627{
1628    napi_value result = nullptr;
1629    int32_t flag;
1630    int32_t bufferSize;
1631    uint8_t *buffer;
1632    int32_t X = -1;
1633    uint8_t metaData[CONSTANT_60];
1634    // 5. X=2999 set调用成功 get调用成功 两者一致
1635    X = CONSTANT_2999;
1636    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, X, metaData);
1637    if (flag != 0) {
1638        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_1, &result);
1639        return result;
1640    }
1641    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &bufferSize, &buffer);
1642    if (flag != 0) {
1643        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_2, &result);
1644        return result;
1645    }
1646    if (bufferSize != CONSTANT_4) {
1647        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_3, &result);
1648        return result;
1649    }
1650    // 6. X=3000 set调用成功 get调用成功 两者一致
1651    X = CONSTANT_3000;
1652    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, X, metaData);
1653    if (flag != 0) {
1654        napi_create_int32(env, CONSTANT_6 * CONSTANT_1000 + CONSTANT_1, &result);
1655        return result;
1656    }
1657    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &bufferSize, &buffer);
1658    if (flag != 0) {
1659        napi_create_int32(env, CONSTANT_6 * CONSTANT_1000 + CONSTANT_2, &result);
1660        return result;
1661    }
1662    if (bufferSize != CONSTANT_4) {
1663        napi_create_int32(env, CONSTANT_6 * CONSTANT_1000 + CONSTANT_3, &result);
1664        return result;
1665    }
1666    return result;
1667}
1668
1669napi_value testNativeWindowSetMetadataValue4(napi_env env, napi_callback_info info, OHNativeWindow *nativeWindow)
1670{
1671    napi_value result = nullptr;
1672    int32_t flag;
1673    int32_t bufferSize;
1674    uint8_t *buffer;
1675    int32_t X = -1;
1676    uint8_t metaData[CONSTANT_60];
1677    // 7.
1678    X = CONSTANT_3001;
1679    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, X, metaData);
1680    if (flag != CONSTANT_40001000) {
1681        napi_create_int32(env, CONSTANT_7 * CONSTANT_1000 + CONSTANT_1, &result);
1682        return result;
1683    }
1684    flag = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &bufferSize, &buffer);
1685    if (flag != 0) {
1686        napi_create_int32(env, CONSTANT_7 * CONSTANT_1000 + CONSTANT_2, &result);
1687        return result;
1688    }
1689    // 8. X=100000000 set调用失败 get调用失败
1690    X = CONSTANT_100000000;
1691    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, X, metaData);
1692    if (flag != CONSTANT_40001000) {
1693        napi_create_int32(env, CONSTANT_8 * CONSTANT_1000 + CONSTANT_1, &result);
1694        return result;
1695    }
1696    return result;
1697}
1698
1699napi_value testNativeWindowSetMetadataValue(napi_env env, napi_callback_info info)
1700{
1701    napi_value result = nullptr;
1702    struct result result1 = InitNativeWindow();
1703    OH_NativeImage *image = result1.image;
1704    OHNativeWindow *nativeWindow = result1.nativeWindow;
1705    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1706    int fenceFd;
1707    auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1708    Region::Rect rect{.x = 0x100, .y = 0x100, .w = 0x100, .h = 0x100};
1709    Region region{.rects = &rect};
1710    flag = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
1711
1712    result = testNativeWindowSetMetadataValue1(env, info, nativeWindow);
1713    if (result != nullptr) {
1714        return result;
1715    }
1716    result = testNativeWindowSetMetadataValue2(env, info, nativeWindow);
1717    if (result != nullptr) {
1718        return result;
1719    }
1720    result = testNativeWindowSetMetadataValue3(env, info, nativeWindow);
1721    if (result != nullptr) {
1722        return result;
1723    }
1724    result = testNativeWindowSetMetadataValue4(env, info, nativeWindow);
1725    if (result != nullptr) {
1726        return result;
1727    }
1728    DestroyNativeWindowImage(image, nativeWindow);
1729    napi_create_int32(env, SUCCESS, &result);
1730    return result;
1731}
1732
1733
1734napi_value testNativeWindowSetNullMetadataValue(napi_env env, napi_callback_info info)
1735{
1736    napi_value result = nullptr;
1737
1738    int32_t flag;
1739    struct result result1 = InitNativeWindow();
1740    OH_NativeImage *image = result1.image;
1741    OHNativeWindow *nativeWindow = result1.nativeWindow;
1742    uint8_t *buffer = new uint8_t[CONSTANT_60];
1743    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, static_cast<OH_NativeBuffer_MetadataKey>(CONSTANT_1000000),
1744                                            CONSTANT_60, buffer);
1745    if (flag != CONSTANT_50002000 && flag != CONSTANT_50102000) {
1746        napi_create_int32(env, FAIL, &result);
1747        return result;
1748    }
1749
1750    DestroyNativeWindowImage(image, nativeWindow);
1751    napi_create_int32(env, SUCCESS, &result);
1752    return result;
1753}
1754
1755
1756napi_value testNativeWindowSetMetadataValueNullptr(napi_env env, napi_callback_info info)
1757{
1758    napi_value result = nullptr;
1759
1760    int32_t flag;
1761    struct result result1 = InitNativeWindow();
1762    OH_NativeImage *image = result1.image;
1763    OHNativeWindow *nativeWindow = result1.nativeWindow;
1764    uint8_t *buffer = new uint8_t[CONSTANT_60];
1765    flag = OH_NativeWindow_SetMetadataValue(nullptr, OH_HDR_DYNAMIC_METADATA, CONSTANT_60, buffer);
1766    if (flag != CONSTANT_40001000) {
1767        napi_create_int32(env, 1, &result);
1768        return result;
1769    }
1770    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, CONSTANT_60, nullptr);
1771    if (flag != CONSTANT_40001000) {
1772        napi_create_int32(env, 1, &result);
1773        return result;
1774    }
1775
1776    DestroyNativeWindowImage(image, nativeWindow);
1777    napi_create_int32(env, SUCCESS, &result);
1778    return result;
1779}
1780
1781
1782napi_value testNativeWindowGetMetadataValueAbnormal(napi_env env, napi_callback_info info)
1783{
1784    napi_value result = nullptr;
1785
1786    int32_t flag;
1787    struct result result1 = InitNativeWindow();
1788    OH_NativeImage *image = result1.image;
1789    OHNativeWindow *nativeWindow = result1.nativeWindow;
1790    uint8_t *buffer = new uint8_t[CONSTANT_60];
1791    flag = OH_NativeWindow_SetMetadataValue(nullptr, OH_HDR_DYNAMIC_METADATA, CONSTANT_60, buffer);
1792    if (flag != CONSTANT_40001000) {
1793        napi_create_int32(env, 1, &result);
1794        return result;
1795    }
1796    flag = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, CONSTANT_60, nullptr);
1797    if (flag != CONSTANT_40001000) {
1798        napi_create_int32(env, 1, &result);
1799        return result;
1800    }
1801
1802    DestroyNativeWindowImage(image, nativeWindow);
1803    napi_create_int32(env, SUCCESS, &result);
1804    return result;
1805}
1806
1807napi_value testNativeWindowGetMetadataValueNullptr(napi_env env, napi_callback_info info)
1808{
1809    napi_value result = nullptr;
1810
1811    int32_t flag;
1812    struct result result1 = InitNativeWindow();
1813    OH_NativeImage *image = result1.image;
1814    OHNativeWindow *nativeWindow = result1.nativeWindow;
1815    uint8_t *buffer = new uint8_t[CONSTANT_60];
1816    int32_t ret1;
1817    uint8_t *ret2;
1818    // 1.
1819    flag = OH_NativeWindow_SetMetadataValue(nullptr, OH_HDR_DYNAMIC_METADATA, CONSTANT_60, buffer);
1820    if (flag != CONSTANT_40001000) {
1821        napi_create_int32(env, CONSTANT_1, &result);
1822        return result;
1823    }
1824    // 2.
1825    flag = OH_NativeWindow_GetMetadataValue(nullptr, OH_HDR_DYNAMIC_METADATA, &ret1, nullptr);
1826    if (flag != CONSTANT_40001000) {
1827        napi_create_int32(env, CONSTANT_2, &result);
1828        return result;
1829    }
1830    // 3.
1831    flag = OH_NativeWindow_GetMetadataValue(nullptr, OH_HDR_DYNAMIC_METADATA, nullptr, &ret2);
1832    if (flag != CONSTANT_40001000) {
1833        napi_create_int32(env, CONSTANT_3, &result);
1834        return result;
1835    }
1836    // 4.
1837    flag = OH_NativeWindow_GetMetadataValue(nullptr, OH_HDR_DYNAMIC_METADATA, &ret1, &ret2);
1838    if (flag != CONSTANT_40001000) {
1839        napi_create_int32(env, CONSTANT_4, &result);
1840        return result;
1841    }
1842    delete[] buffer;
1843
1844    DestroyNativeWindowImage(image, nativeWindow);
1845    napi_create_int32(env, SUCCESS, &result);
1846    return result;
1847}
1848
1849napi_value testNativeWindowNativeWindowHandleOptSetDesiredPresentTimeStampNormal(napi_env env,
1850                                                                                 napi_callback_info info)
1851{
1852    napi_value result = nullptr;
1853    int32_t flag;
1854    struct result result1 = InitNativeWindow();
1855    OH_NativeImage *image = result1.image;
1856    OHNativeWindow *nativeWindow = result1.nativeWindow;
1857    uint64_t arr[] = {CONSTANT_1, CONSTANT_1000, CONSTANT_1000000000, 1ULL << 63, CONSTANT_999999999999999999};
1858    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
1859        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_DESIRED_PRESENT_TIMESTAMP, arr[i]);
1860        if (flag != 0) {
1861            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
1862            return result;
1863        }
1864    }
1865
1866    DestroyNativeWindowImage(image, nativeWindow);
1867    napi_create_int32(env, SUCCESS, &result);
1868    return result;
1869}
1870
1871napi_value testNativeWindowNativeWindowHandleOptSetDesiredPresentTimeStampAbNormal(napi_env env,
1872                                                                                   napi_callback_info info)
1873{
1874    napi_value result = nullptr;
1875    int32_t flag;
1876    struct result result1 = InitNativeWindow();
1877    OH_NativeImage *image = result1.image;
1878    OHNativeWindow *nativeWindow = result1.nativeWindow;
1879    int64_t arr[] = {CONSTANT_0, -CONSTANT_1, -CONSTANT_1000, -CONSTANT_1000000, CONSTANT_NEG_9223372036854775807};
1880    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) {
1881        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_DESIRED_PRESENT_TIMESTAMP, arr[i]);
1882        if (flag != 0) {
1883            napi_create_int32(env, CONSTANT_1000 * (i + 1) + CONSTANT_1, &result);
1884            return result;
1885        }
1886    }
1887    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_DESIRED_PRESENT_TIMESTAMP, "sdasda213!");
1888    if (flag != 0) {
1889        napi_create_int32(env, CONSTANT_100000 + CONSTANT_1, &result);
1890        return result;
1891    }
1892    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_DESIRED_PRESENT_TIMESTAMP, NULL);
1893    if (flag != 0) {
1894        napi_create_int32(env, CONSTANT_2 * CONSTANT_100000 + CONSTANT_1, &result);
1895        return result;
1896    }
1897    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_DESIRED_PRESENT_TIMESTAMP);
1898    if (flag != 0) {
1899        napi_create_int32(env, CONSTANT_3 * CONSTANT_100000 + CONSTANT_1, &result);
1900        return result;
1901    }
1902    DestroyNativeWindowImage(image, nativeWindow);
1903    napi_create_int32(env, SUCCESS, &result);
1904    return result;
1905}