1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ci//
17f6603c60Sopenharmony_ci// Created on 2024/8/6.
18f6603c60Sopenharmony_ci//
19f6603c60Sopenharmony_ci// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
20f6603c60Sopenharmony_ci// please include "napi/native_api.h".
21f6603c60Sopenharmony_ci#include "napi/native_api.h"
22f6603c60Sopenharmony_ci#include <IPCKit/ipc_cparcel.h>
23f6603c60Sopenharmony_ci#include <bits/alltypes.h>
24f6603c60Sopenharmony_ci#include <GLES2/gl2.h>
25f6603c60Sopenharmony_ci#include <multimedia/player_framework/native_avcodec_base.h>
26f6603c60Sopenharmony_ci#include <native_image/native_image.h>
27f6603c60Sopenharmony_ci#include <native_window/external_window.h>
28f6603c60Sopenharmony_ci#include <native_buffer/native_buffer.h>
29f6603c60Sopenharmony_ci
30f6603c60Sopenharmony_ci
31f6603c60Sopenharmony_ci#define SUCCESS 0
32f6603c60Sopenharmony_ci#define FAIL (-1)
33f6603c60Sopenharmony_ci
34f6603c60Sopenharmony_ci#define CONSTANT_0 0
35f6603c60Sopenharmony_ci#define CONSTANT_1 1
36f6603c60Sopenharmony_ci#define CONSTANT_2 2
37f6603c60Sopenharmony_ci#define CONSTANT_3 3
38f6603c60Sopenharmony_ci#define CONSTANT_4 4
39f6603c60Sopenharmony_ci#define CONSTANT_5 5
40f6603c60Sopenharmony_ci#define CONSTANT_6 6
41f6603c60Sopenharmony_ci#define CONSTANT_7 7
42f6603c60Sopenharmony_ci#define CONSTANT_8 8
43f6603c60Sopenharmony_ci
44f6603c60Sopenharmony_ci#define CONSTANT_500 500
45f6603c60Sopenharmony_ci#define CONSTANT_1000 1000
46f6603c60Sopenharmony_ci#define CONSTANT_10000 10000
47f6603c60Sopenharmony_ci
48f6603c60Sopenharmony_ci#define CONSTANT_40001000 40001000
49f6603c60Sopenharmony_ci#define CONSTANT_41207000 41207000
50f6603c60Sopenharmony_ci#define CONSTANT_41208000 41208000
51f6603c60Sopenharmony_ci#define CONSTANT_41210000 41210000
52f6603c60Sopenharmony_ci
53f6603c60Sopenharmony_ci#define CONSTANT_50002000 50002000
54f6603c60Sopenharmony_ci#define CONSTANT_50102000 50102000
55f6603c60Sopenharmony_ci
56f6603c60Sopenharmony_ci#define CONSTANT_999999999 999999999
57f6603c60Sopenharmony_ci#define CONSTANT_9999999999999999999 9999999999999999999
58f6603c60Sopenharmony_ci
59f6603c60Sopenharmony_cistruct result {
60f6603c60Sopenharmony_ci    OH_NativeImage *image;
61f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow;
62f6603c60Sopenharmony_ci    int32_t width_;
63f6603c60Sopenharmony_ci    int32_t height_;
64f6603c60Sopenharmony_ci};
65f6603c60Sopenharmony_ci
66f6603c60Sopenharmony_cistatic result InitNativeWindow()
67f6603c60Sopenharmony_ci{
68f6603c60Sopenharmony_ci    struct result result1;
69f6603c60Sopenharmony_ci    GLuint textureId;
70f6603c60Sopenharmony_ci    glGenTextures(1, &textureId);
71f6603c60Sopenharmony_ci    auto _image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
72f6603c60Sopenharmony_ci    result1.image = _image;
73f6603c60Sopenharmony_ci    OHNativeWindow *_nativeWindow = OH_NativeImage_AcquireNativeWindow(_image);
74f6603c60Sopenharmony_ci    result1.nativeWindow = _nativeWindow;
75f6603c60Sopenharmony_ci    int code = SET_BUFFER_GEOMETRY;
76f6603c60Sopenharmony_ci    result1.width_ = 0x100;
77f6603c60Sopenharmony_ci    result1.height_ = 0x100;
78f6603c60Sopenharmony_ci    int32_t ret = OH_NativeWindow_NativeWindowHandleOpt(_nativeWindow, code, result1.width_, result1.height_);
79f6603c60Sopenharmony_ci    code = SET_USAGE;
80f6603c60Sopenharmony_ci    int32_t usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA;
81f6603c60Sopenharmony_ci    ret = OH_NativeWindow_NativeWindowHandleOpt(_nativeWindow, code, usage);
82f6603c60Sopenharmony_ci    return result1;
83f6603c60Sopenharmony_ci}
84f6603c60Sopenharmony_ci
85f6603c60Sopenharmony_cistatic void DestroyNativeWindowImage(OH_NativeImage *image, OHNativeWindow *window)
86f6603c60Sopenharmony_ci{
87f6603c60Sopenharmony_ci    OH_NativeImage_Destroy(&image);
88f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(window);
89f6603c60Sopenharmony_ci}
90f6603c60Sopenharmony_ci
91f6603c60Sopenharmony_cinapi_value testNativeWindowCreateNativeWindowNullptr(napi_env env, napi_callback_info info)
92f6603c60Sopenharmony_ci{
93f6603c60Sopenharmony_ci    napi_value result = nullptr;
94f6603c60Sopenharmony_ci    auto p = OH_NativeWindow_CreateNativeWindow(nullptr);
95f6603c60Sopenharmony_ci    if (p == nullptr) {
96f6603c60Sopenharmony_ci        napi_create_int32(env, SUCCESS, &result);
97f6603c60Sopenharmony_ci    } else {
98f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
99f6603c60Sopenharmony_ci    }
100f6603c60Sopenharmony_ci    return result;
101f6603c60Sopenharmony_ci}
102f6603c60Sopenharmony_ci
103f6603c60Sopenharmony_cinapi_value testNativeWindowDestroyNativeWindowNullptr(napi_env env, napi_callback_info info)
104f6603c60Sopenharmony_ci{
105f6603c60Sopenharmony_ci    napi_value result = nullptr;
106f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nullptr);
107f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
108f6603c60Sopenharmony_ci    return result;
109f6603c60Sopenharmony_ci}
110f6603c60Sopenharmony_ci
111f6603c60Sopenharmony_cinapi_value testNativeWindowGetSurfaceIdNullptr(napi_env env, napi_callback_info info)
112f6603c60Sopenharmony_ci{
113f6603c60Sopenharmony_ci    napi_value result = nullptr;
114f6603c60Sopenharmony_ci    auto r = OH_NativeWindow_GetSurfaceId(nullptr, 0);
115f6603c60Sopenharmony_ci    if (CONSTANT_40001000 == r) {
116f6603c60Sopenharmony_ci        napi_create_int32(env, SUCCESS, &result);
117f6603c60Sopenharmony_ci    } else {
118f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
119f6603c60Sopenharmony_ci    }
120f6603c60Sopenharmony_ci    return result;
121f6603c60Sopenharmony_ci}
122f6603c60Sopenharmony_ci
123f6603c60Sopenharmony_ci
124f6603c60Sopenharmony_cinapi_value testNativeWindowCreateNativeWindowFromSurfaceIdNullptr(napi_env env, napi_callback_info info)
125f6603c60Sopenharmony_ci{
126f6603c60Sopenharmony_ci    napi_value result = nullptr;
127f6603c60Sopenharmony_ci
128f6603c60Sopenharmony_ci    // 设置OH_NativeWindow_CreateNativeWindowFromSurfaceId()的surfaceId=nullptr,其他参数正常调用该接口
129f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = nullptr;
130f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_CreateNativeWindowFromSurfaceId(0, &nativeWindow);
131f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
132f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
133f6603c60Sopenharmony_ci        return result;
134f6603c60Sopenharmony_ci    }
135f6603c60Sopenharmony_ci
136f6603c60Sopenharmony_ci    GLuint textureId;
137f6603c60Sopenharmony_ci    glGenTextures(1, &textureId);
138f6603c60Sopenharmony_ci    auto _image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
139f6603c60Sopenharmony_ci    auto _nativeWindow = OH_NativeImage_AcquireNativeWindow(_image);
140f6603c60Sopenharmony_ci    uint64_t surfaceId;
141f6603c60Sopenharmony_ci    OH_NativeWindow_GetSurfaceId(_nativeWindow, &surfaceId);
142f6603c60Sopenharmony_ci    // 设置OH_NativeWindow_CreateNativeWindowFromSurfaceId()的window=nullptr,,其他参数正常调用该接口
143f6603c60Sopenharmony_ci    flag = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, nullptr);
144f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
145f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
146f6603c60Sopenharmony_ci        return result;
147f6603c60Sopenharmony_ci    }
148f6603c60Sopenharmony_ci    OH_NativeImage_Destroy(&_image);
149f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(_nativeWindow);
150f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
151f6603c60Sopenharmony_ci    return result;
152f6603c60Sopenharmony_ci}
153f6603c60Sopenharmony_ci
154f6603c60Sopenharmony_ci
155f6603c60Sopenharmony_cinapi_value testNativeWindowCreateNativeWindowFromSurfaceIdNormal(napi_env env, napi_callback_info info)
156f6603c60Sopenharmony_ci{
157f6603c60Sopenharmony_ci    napi_value result = nullptr;
158f6603c60Sopenharmony_ci
159f6603c60Sopenharmony_ci    // 创建surface实例 获取id
160f6603c60Sopenharmony_ci    GLuint textureId;
161f6603c60Sopenharmony_ci    glGenTextures(1, &textureId);
162f6603c60Sopenharmony_ci    auto _image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
163f6603c60Sopenharmony_ci    auto _nativeWindow = OH_NativeImage_AcquireNativeWindow(_image);
164f6603c60Sopenharmony_ci    uint64_t surfaceId;
165f6603c60Sopenharmony_ci    OH_NativeWindow_GetSurfaceId(_nativeWindow, &surfaceId);
166f6603c60Sopenharmony_ci
167f6603c60Sopenharmony_ci    // 声明nativeWindow空指针为window
168f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = nullptr;
169f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, &nativeWindow);
170f6603c60Sopenharmony_ci    // 接口执行成功,返回错误码0 | 声明的window指针指向NativeWindow实例
171f6603c60Sopenharmony_ci    if (flag != 0 || nativeWindow == nullptr) {
172f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
173f6603c60Sopenharmony_ci        return result;
174f6603c60Sopenharmony_ci    }
175f6603c60Sopenharmony_ci
176f6603c60Sopenharmony_ci    // 声明一个surfaceId2
177f6603c60Sopenharmony_ci    uint64_t surfaceId2;
178f6603c60Sopenharmony_ci    flag = OH_NativeWindow_GetSurfaceId(nativeWindow, &surfaceId2);
179f6603c60Sopenharmony_ci    // 接口调用成功,返回错误码0 | get获取surfaceId2与surfaceId一致
180f6603c60Sopenharmony_ci    if (flag != 0 || surfaceId2 != surfaceId) {
181f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
182f6603c60Sopenharmony_ci        return result;
183f6603c60Sopenharmony_ci    }
184f6603c60Sopenharmony_ci
185f6603c60Sopenharmony_ci    OH_NativeImage_Destroy(&_image);
186f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindow);
187f6603c60Sopenharmony_ci
188f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
189f6603c60Sopenharmony_ci    return result;
190f6603c60Sopenharmony_ci}
191f6603c60Sopenharmony_ci
192f6603c60Sopenharmony_ci
193f6603c60Sopenharmony_cinapi_value testNativeWindowCreateNativeWindowFromSurfaceIdSurfaceId(napi_env env, napi_callback_info info)
194f6603c60Sopenharmony_ci{
195f6603c60Sopenharmony_ci    napi_value result = nullptr;
196f6603c60Sopenharmony_ci
197f6603c60Sopenharmony_ci    // 创建surface实例 获取一个正常的id
198f6603c60Sopenharmony_ci    GLuint textureId;
199f6603c60Sopenharmony_ci    glGenTextures(1, &textureId);
200f6603c60Sopenharmony_ci    auto _image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
201f6603c60Sopenharmony_ci    auto _nativeWindow = OH_NativeImage_AcquireNativeWindow(_image);
202f6603c60Sopenharmony_ci    uint64_t surfaceId;
203f6603c60Sopenharmony_ci    OH_NativeWindow_GetSurfaceId(_nativeWindow, &surfaceId);
204f6603c60Sopenharmony_ci
205f6603c60Sopenharmony_ci    // 调用该接口,查看执行结果
206f6603c60Sopenharmony_ci    uint64_t ids[] = {0, 1, surfaceId, 0xFFFFFFFF};
207f6603c60Sopenharmony_ci    for (int i = 0; i < sizeof(ids) / sizeof(uint64_t); i += 1) {
208f6603c60Sopenharmony_ci        uint64_t tmpId = ids[i];
209f6603c60Sopenharmony_ci        OHNativeWindow *nativeWindow = nullptr;
210f6603c60Sopenharmony_ci        auto flag = OH_NativeWindow_CreateNativeWindowFromSurfaceId(tmpId, &nativeWindow);
211f6603c60Sopenharmony_ci        // 只有样例3成功
212f6603c60Sopenharmony_ci        if (i == CONSTANT_2) {
213f6603c60Sopenharmony_ci            if (flag != SUCCESS) {
214f6603c60Sopenharmony_ci                napi_create_int32(env, i + 1, &result);
215f6603c60Sopenharmony_ci                return result;
216f6603c60Sopenharmony_ci            }
217f6603c60Sopenharmony_ci        } else {
218f6603c60Sopenharmony_ci            OH_NativeWindow_DestroyNativeWindow(nativeWindow);
219f6603c60Sopenharmony_ci            if (flag == SUCCESS) {
220f6603c60Sopenharmony_ci                napi_create_int32(env, 1 + 1, &result);
221f6603c60Sopenharmony_ci                return result;
222f6603c60Sopenharmony_ci            }
223f6603c60Sopenharmony_ci        }
224f6603c60Sopenharmony_ci    }
225f6603c60Sopenharmony_ci    OH_NativeImage_Destroy(&_image);
226f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(_nativeWindow);
227f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
228f6603c60Sopenharmony_ci    return result;
229f6603c60Sopenharmony_ci}
230f6603c60Sopenharmony_ci
231f6603c60Sopenharmony_ci
232f6603c60Sopenharmony_cinapi_value testNativeWindowCreateNativeWindowBufferFromNativeBufferNullptr(napi_env env, napi_callback_info info)
233f6603c60Sopenharmony_ci{
234f6603c60Sopenharmony_ci    napi_value result = nullptr;
235f6603c60Sopenharmony_ci    auto buffer = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nullptr);
236f6603c60Sopenharmony_ci    if (buffer == nullptr) {
237f6603c60Sopenharmony_ci        napi_create_int32(env, SUCCESS, &result);
238f6603c60Sopenharmony_ci    } else {
239f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
240f6603c60Sopenharmony_ci    }
241f6603c60Sopenharmony_ci    return result;
242f6603c60Sopenharmony_ci}
243f6603c60Sopenharmony_ci
244f6603c60Sopenharmony_ci
245f6603c60Sopenharmony_cinapi_value testNativeWindowCreateNativeWindowBufferFromSurfaceBufferNullptr(napi_env env, napi_callback_info info)
246f6603c60Sopenharmony_ci{
247f6603c60Sopenharmony_ci    napi_value result = nullptr;
248f6603c60Sopenharmony_ci    auto buffer = OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(nullptr);
249f6603c60Sopenharmony_ci    if (buffer == nullptr) {
250f6603c60Sopenharmony_ci        napi_create_int32(env, SUCCESS, &result);
251f6603c60Sopenharmony_ci    } else {
252f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
253f6603c60Sopenharmony_ci    }
254f6603c60Sopenharmony_ci    return result;
255f6603c60Sopenharmony_ci}
256f6603c60Sopenharmony_ci
257f6603c60Sopenharmony_ci
258f6603c60Sopenharmony_cinapi_value testNativeWindowDestroyNativeWindowBufferNullptr(napi_env env, napi_callback_info info)
259f6603c60Sopenharmony_ci{
260f6603c60Sopenharmony_ci    napi_value result = nullptr;
261f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nullptr);
262f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
263f6603c60Sopenharmony_ci    return result;
264f6603c60Sopenharmony_ci}
265f6603c60Sopenharmony_ci
266f6603c60Sopenharmony_cinapi_value testNativeWindowGetBufferHandleFromNativeNullptr(napi_env env, napi_callback_info info)
267f6603c60Sopenharmony_ci{
268f6603c60Sopenharmony_ci    napi_value result = nullptr;
269f6603c60Sopenharmony_ci    auto ptr = OH_NativeWindow_GetBufferHandleFromNative(nullptr);
270f6603c60Sopenharmony_ci    if (ptr == nullptr) {
271f6603c60Sopenharmony_ci        napi_create_int32(env, SUCCESS, &result);
272f6603c60Sopenharmony_ci    } else {
273f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
274f6603c60Sopenharmony_ci    }
275f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
276f6603c60Sopenharmony_ci    return result;
277f6603c60Sopenharmony_ci}
278f6603c60Sopenharmony_ci
279f6603c60Sopenharmony_ci
280f6603c60Sopenharmony_cinapi_value testNativeWindowCreateNativeWindowBufferFromNativeBufferNormal(napi_env env, napi_callback_info info)
281f6603c60Sopenharmony_ci{
282f6603c60Sopenharmony_ci    napi_value result = nullptr;
283f6603c60Sopenharmony_ci
284f6603c60Sopenharmony_ci    // 0. 创建 native buffer 实例
285f6603c60Sopenharmony_ci    OH_NativeBuffer_Config config{
286f6603c60Sopenharmony_ci        .width = 0x100,
287f6603c60Sopenharmony_ci        .height = 0x100,
288f6603c60Sopenharmony_ci        .format = NATIVEBUFFER_PIXEL_FMT_RGBA_8888,
289f6603c60Sopenharmony_ci        .usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA,
290f6603c60Sopenharmony_ci    };
291f6603c60Sopenharmony_ci    OH_NativeBuffer *buffer = OH_NativeBuffer_Alloc(&config);
292f6603c60Sopenharmony_ci    if (buffer == nullptr) {
293f6603c60Sopenharmony_ci        napi_create_int32(env, -1, &result);
294f6603c60Sopenharmony_ci        return result;
295f6603c60Sopenharmony_ci    }
296f6603c60Sopenharmony_ci
297f6603c60Sopenharmony_ci    // 1.
298f6603c60Sopenharmony_ci    auto nativeWindowBuffer = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(buffer);
299f6603c60Sopenharmony_ci    // 接口执行成功,返回非空指针
300f6603c60Sopenharmony_ci    if (nativeWindowBuffer == nullptr) {
301f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
302f6603c60Sopenharmony_ci        return result;
303f6603c60Sopenharmony_ci    }
304f6603c60Sopenharmony_ci
305f6603c60Sopenharmony_ci    // 2.
306f6603c60Sopenharmony_ci    auto bufferHandle = OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer);
307f6603c60Sopenharmony_ci    if (bufferHandle == nullptr) {
308f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
309f6603c60Sopenharmony_ci        return result;
310f6603c60Sopenharmony_ci    }
311f6603c60Sopenharmony_ci
312f6603c60Sopenharmony_ci    // 3.
313f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
314f6603c60Sopenharmony_ci
315f6603c60Sopenharmony_ci    // 4.
316f6603c60Sopenharmony_ci    bufferHandle = OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer);
317f6603c60Sopenharmony_ci    if (bufferHandle != nullptr) {
318f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_4, &result);
319f6603c60Sopenharmony_ci        return result;
320f6603c60Sopenharmony_ci    }
321f6603c60Sopenharmony_ci
322f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
323f6603c60Sopenharmony_ci    return result;
324f6603c60Sopenharmony_ci}
325f6603c60Sopenharmony_ci
326f6603c60Sopenharmony_ci
327f6603c60Sopenharmony_cinapi_value testNativeWindowCreateNativeWindowBufferFromNativeBufferMuch(napi_env env, napi_callback_info info)
328f6603c60Sopenharmony_ci{
329f6603c60Sopenharmony_ci    napi_value result = nullptr;
330f6603c60Sopenharmony_ci
331f6603c60Sopenharmony_ci    // 0. 创建 native buffer 实例
332f6603c60Sopenharmony_ci    OH_NativeBuffer_Config config{
333f6603c60Sopenharmony_ci        .width = 0x100,
334f6603c60Sopenharmony_ci        .height = 0x100,
335f6603c60Sopenharmony_ci        .format = NATIVEBUFFER_PIXEL_FMT_RGBA_8888,
336f6603c60Sopenharmony_ci        .usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA,
337f6603c60Sopenharmony_ci    };
338f6603c60Sopenharmony_ci    OH_NativeBuffer *buffer = OH_NativeBuffer_Alloc(&config);
339f6603c60Sopenharmony_ci    if (buffer == nullptr) {
340f6603c60Sopenharmony_ci        napi_create_int32(env, -1, &result);
341f6603c60Sopenharmony_ci        return result;
342f6603c60Sopenharmony_ci    }
343f6603c60Sopenharmony_ci
344f6603c60Sopenharmony_ci    for (int i = 0; i < CONSTANT_500; i += 1) {
345f6603c60Sopenharmony_ci        auto ptr = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(buffer);
346f6603c60Sopenharmony_ci        if (ptr == nullptr) {
347f6603c60Sopenharmony_ci            napi_create_int32(env, i + 1, &result);
348f6603c60Sopenharmony_ci            return result;
349f6603c60Sopenharmony_ci        }
350f6603c60Sopenharmony_ci    }
351f6603c60Sopenharmony_ci
352f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
353f6603c60Sopenharmony_ci    return result;
354f6603c60Sopenharmony_ci}
355f6603c60Sopenharmony_ci
356f6603c60Sopenharmony_ci
357f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowRequestBufferNullptr(napi_env env, napi_callback_info info)
358f6603c60Sopenharmony_ci{
359f6603c60Sopenharmony_ci    napi_value result = nullptr;
360f6603c60Sopenharmony_ci
361f6603c60Sopenharmony_ci    OHNativeWindowBuffer *oHNativeWindowBuffer;
362f6603c60Sopenharmony_ci    int fenceFd;
363f6603c60Sopenharmony_ci
364f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nullptr, &oHNativeWindowBuffer, &fenceFd);
365f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
366f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
367f6603c60Sopenharmony_ci        return result;
368f6603c60Sopenharmony_ci    }
369f6603c60Sopenharmony_ci
370f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
371f6603c60Sopenharmony_ci    return result;
372f6603c60Sopenharmony_ci}
373f6603c60Sopenharmony_ci
374f6603c60Sopenharmony_ci
375f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowAbortBufferNullptr(napi_env env, napi_callback_info info)
376f6603c60Sopenharmony_ci{
377f6603c60Sopenharmony_ci    napi_value result = nullptr;
378f6603c60Sopenharmony_ci
379f6603c60Sopenharmony_ci    // 0. 创建 native window 实例
380f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
381f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
382f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
383f6603c60Sopenharmony_ci    OHNativeWindowBuffer *oHNativeWindowBuffer;
384f6603c60Sopenharmony_ci
385f6603c60Sopenharmony_ci    // 1. window 为空指针
386f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowAbortBuffer(nullptr, oHNativeWindowBuffer);
387f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
388f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
389f6603c60Sopenharmony_ci        return result;
390f6603c60Sopenharmony_ci    }
391f6603c60Sopenharmony_ci
392f6603c60Sopenharmony_ci    // 2. buffer 为空指针
393f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nullptr);
394f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
395f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
396f6603c60Sopenharmony_ci        return result;
397f6603c60Sopenharmony_ci    }
398f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
399f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
400f6603c60Sopenharmony_ci    return result;
401f6603c60Sopenharmony_ci}
402f6603c60Sopenharmony_ci
403f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowRequestAbortBufferNormal(napi_env env, napi_callback_info info)
404f6603c60Sopenharmony_ci{
405f6603c60Sopenharmony_ci    napi_value result = nullptr;
406f6603c60Sopenharmony_ci
407f6603c60Sopenharmony_ci    // 0. 创建 native window 实例
408f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
409f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
410f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
411f6603c60Sopenharmony_ci
412f6603c60Sopenharmony_ci    // 0. 新建 native window buffer 指针
413f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
414f6603c60Sopenharmony_ci
415f6603c60Sopenharmony_ci    // 1.
416f6603c60Sopenharmony_ci    int fenceFd = -1;
417f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
418f6603c60Sopenharmony_ci    if (flag != 0 || nativeWindowBuffer == nullptr) {
419f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
420f6603c60Sopenharmony_ci        return result;
421f6603c60Sopenharmony_ci    }
422f6603c60Sopenharmony_ci
423f6603c60Sopenharmony_ci    // 2.
424f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer);
425f6603c60Sopenharmony_ci    if (flag != 0) {
426f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
427f6603c60Sopenharmony_ci        return result;
428f6603c60Sopenharmony_ci    }
429f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
430f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
431f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
432f6603c60Sopenharmony_ci    return result;
433f6603c60Sopenharmony_ci}
434f6603c60Sopenharmony_ci
435f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowRequestAbortBufferAbnormal(napi_env env, napi_callback_info info)
436f6603c60Sopenharmony_ci{
437f6603c60Sopenharmony_ci    napi_value result = nullptr;
438f6603c60Sopenharmony_ci
439f6603c60Sopenharmony_ci    // 0. 创建 native window 实例
440f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
441f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
442f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
443f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
444f6603c60Sopenharmony_ci
445f6603c60Sopenharmony_ci    // 1.
446f6603c60Sopenharmony_ci    int fenceFd = 0;
447f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
448f6603c60Sopenharmony_ci    if (flag != 0 || nativeWindowBuffer == nullptr) {
449f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
450f6603c60Sopenharmony_ci        return result;
451f6603c60Sopenharmony_ci    }
452f6603c60Sopenharmony_ci
453f6603c60Sopenharmony_ci    // 2.
454f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer);
455f6603c60Sopenharmony_ci    if (flag != 0) {
456f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
457f6603c60Sopenharmony_ci        return result;
458f6603c60Sopenharmony_ci    }
459f6603c60Sopenharmony_ci
460f6603c60Sopenharmony_ci    // 3.
461f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer);
462f6603c60Sopenharmony_ci    if (flag == 0) {
463f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_3, &result);
464f6603c60Sopenharmony_ci    }
465f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
466f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
467f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
468f6603c60Sopenharmony_ci    return result;
469f6603c60Sopenharmony_ci}
470f6603c60Sopenharmony_ci
471f6603c60Sopenharmony_ci
472f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowRequestBufferFenceFdNormal(napi_env env, napi_callback_info info)
473f6603c60Sopenharmony_ci{
474f6603c60Sopenharmony_ci    napi_value result = nullptr;
475f6603c60Sopenharmony_ci
476f6603c60Sopenharmony_ci    // 0. 创建 native window 实例
477f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
478f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
479f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
480f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
481f6603c60Sopenharmony_ci
482f6603c60Sopenharmony_ci    int32_t ls[] = {-CONSTANT_5, -CONSTANT_1, CONSTANT_0, CONSTANT_1, CONSTANT_10000, CONSTANT_999999999};
483f6603c60Sopenharmony_ci    for (int i = 0; i < sizeof(ls) / sizeof(int); i += 1) {
484f6603c60Sopenharmony_ci        int fenceFd = ls[i];
485f6603c60Sopenharmony_ci        auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
486f6603c60Sopenharmony_ci        if (flag != 0) {
487f6603c60Sopenharmony_ci            napi_create_int32(env, 1, &result);
488f6603c60Sopenharmony_ci            return result;
489f6603c60Sopenharmony_ci        }
490f6603c60Sopenharmony_ci        flag = OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer);
491f6603c60Sopenharmony_ci        if (flag != 0) {
492f6603c60Sopenharmony_ci            napi_create_int32(env, CONSTANT_2, &result);
493f6603c60Sopenharmony_ci            return result;
494f6603c60Sopenharmony_ci        }
495f6603c60Sopenharmony_ci    }
496f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
497f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
498f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
499f6603c60Sopenharmony_ci    return result;
500f6603c60Sopenharmony_ci}
501f6603c60Sopenharmony_ci
502f6603c60Sopenharmony_ci
503f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowRequestBufferFenceFdAbnormal(napi_env env, napi_callback_info info)
504f6603c60Sopenharmony_ci{
505f6603c60Sopenharmony_ci    napi_value result = nullptr;
506f6603c60Sopenharmony_ci
507f6603c60Sopenharmony_ci    // 0. 创建 native window 实例
508f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
509f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
510f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
511f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
512f6603c60Sopenharmony_ci
513f6603c60Sopenharmony_ci    int32_t *fenceFd1 = NULL;
514f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, fenceFd1);
515f6603c60Sopenharmony_ci    if (flag == 0) {
516f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
517f6603c60Sopenharmony_ci        return result;
518f6603c60Sopenharmony_ci    }
519f6603c60Sopenharmony_ci
520f6603c60Sopenharmony_ci    int32_t *fenceFd2 = nullptr;
521f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, fenceFd2);
522f6603c60Sopenharmony_ci    if (flag == 0) {
523f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
524f6603c60Sopenharmony_ci        return result;
525f6603c60Sopenharmony_ci    }
526f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
527f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
528f6603c60Sopenharmony_ci    return result;
529f6603c60Sopenharmony_ci}
530f6603c60Sopenharmony_ci
531f6603c60Sopenharmony_ci
532f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowRequestAbortBufferMax(napi_env env, napi_callback_info info)
533f6603c60Sopenharmony_ci{
534f6603c60Sopenharmony_ci    napi_value result = nullptr;
535f6603c60Sopenharmony_ci
536f6603c60Sopenharmony_ci    // 0. 创建 native window 实例
537f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
538f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
539f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
540f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
541f6603c60Sopenharmony_ci
542f6603c60Sopenharmony_ci    for (int i = 0; i < CONSTANT_4; ++i) {
543f6603c60Sopenharmony_ci        int fenceFd = -1;
544f6603c60Sopenharmony_ci        auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
545f6603c60Sopenharmony_ci        if (i >= CONSTANT_3) {
546f6603c60Sopenharmony_ci            if (flag == 0) {
547f6603c60Sopenharmony_ci                napi_create_int32(env, FAIL, &result);
548f6603c60Sopenharmony_ci                return result;
549f6603c60Sopenharmony_ci            }
550f6603c60Sopenharmony_ci        } else {
551f6603c60Sopenharmony_ci            if (flag != 0) {
552f6603c60Sopenharmony_ci                napi_create_int32(env, i + 1, &result);
553f6603c60Sopenharmony_ci                return result;
554f6603c60Sopenharmony_ci            }
555f6603c60Sopenharmony_ci        }
556f6603c60Sopenharmony_ci    }
557f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
558f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
559f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
560f6603c60Sopenharmony_ci    return result;
561f6603c60Sopenharmony_ci}
562f6603c60Sopenharmony_ci
563f6603c60Sopenharmony_ci
564f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowRequestAbortBufferErrorCode(napi_env env, napi_callback_info info)
565f6603c60Sopenharmony_ci{
566f6603c60Sopenharmony_ci    napi_value result = nullptr;
567f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
568f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
569f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
570f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
571f6603c60Sopenharmony_ci    int requestFenceFd;
572f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &requestFenceFd);
573f6603c60Sopenharmony_ci    if (flag != 0) {
574f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
575f6603c60Sopenharmony_ci        return result;
576f6603c60Sopenharmony_ci    }
577f6603c60Sopenharmony_ci    if (nativeWindowBuffer == nullptr || requestFenceFd != -1) {
578f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
579f6603c60Sopenharmony_ci        return result;
580f6603c60Sopenharmony_ci    }
581f6603c60Sopenharmony_ci    Region::Rect rect{
582f6603c60Sopenharmony_ci        .x = 0x100,
583f6603c60Sopenharmony_ci        .y = 0x100,
584f6603c60Sopenharmony_ci        .w = 0x100,
585f6603c60Sopenharmony_ci        .h = 0x100,
586f6603c60Sopenharmony_ci    };
587f6603c60Sopenharmony_ci    Region region{.rects = &rect};
588f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, requestFenceFd, region);
589f6603c60Sopenharmony_ci    if (flag != 0) {
590f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_3, &result);
591f6603c60Sopenharmony_ci        return result;
592f6603c60Sopenharmony_ci    }
593f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer);
594f6603c60Sopenharmony_ci    if (flag == 0) {
595f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_4, &result);
596f6603c60Sopenharmony_ci    }
597f6603c60Sopenharmony_ci
598f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
599f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
600f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
601f6603c60Sopenharmony_ci    return result;
602f6603c60Sopenharmony_ci}
603f6603c60Sopenharmony_ci
604f6603c60Sopenharmony_ci
605f6603c60Sopenharmony_cinapi_value testNativeWindowWriteToParcelErrptr(napi_env env, napi_callback_info info)
606f6603c60Sopenharmony_ci{
607f6603c60Sopenharmony_ci    napi_value result = nullptr;
608f6603c60Sopenharmony_ci
609f6603c60Sopenharmony_ci    // 0. 创建 native window 实例
610f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
611f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
612f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
613f6603c60Sopenharmony_ci    // 0. 已存在OHIPCParcel
614f6603c60Sopenharmony_ci    OHIPCParcel *parcel = OH_IPCParcel_Create();
615f6603c60Sopenharmony_ci
616f6603c60Sopenharmony_ci    // 1.
617f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_WriteToParcel(nullptr, parcel);
618f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
619f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
620f6603c60Sopenharmony_ci        return result;
621f6603c60Sopenharmony_ci    }
622f6603c60Sopenharmony_ci
623f6603c60Sopenharmony_ci    // 2.
624f6603c60Sopenharmony_ci    flag = OH_NativeWindow_WriteToParcel(nativeWindow, nullptr);
625f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
626f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
627f6603c60Sopenharmony_ci        return result;
628f6603c60Sopenharmony_ci    }
629f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
630f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
631f6603c60Sopenharmony_ci    return result;
632f6603c60Sopenharmony_ci}
633f6603c60Sopenharmony_ci
634f6603c60Sopenharmony_ci
635f6603c60Sopenharmony_cinapi_value testNativeWindowReadFromParcelErrptr(napi_env env, napi_callback_info info)
636f6603c60Sopenharmony_ci{
637f6603c60Sopenharmony_ci    napi_value result = nullptr;
638f6603c60Sopenharmony_ci
639f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = nullptr;
640f6603c60Sopenharmony_ci    // 0. 已存在OHIPCParcel
641f6603c60Sopenharmony_ci    OHIPCParcel *parcel = OH_IPCParcel_Create();
642f6603c60Sopenharmony_ci
643f6603c60Sopenharmony_ci    // 1.
644f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_ReadFromParcel(parcel, nullptr);
645f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
646f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
647f6603c60Sopenharmony_ci        return result;
648f6603c60Sopenharmony_ci    }
649f6603c60Sopenharmony_ci
650f6603c60Sopenharmony_ci    // 2.
651f6603c60Sopenharmony_ci    flag = OH_NativeWindow_ReadFromParcel(nullptr, &nativeWindow);
652f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
653f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
654f6603c60Sopenharmony_ci        return result;
655f6603c60Sopenharmony_ci    }
656f6603c60Sopenharmony_ci
657f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
658f6603c60Sopenharmony_ci    return result;
659f6603c60Sopenharmony_ci}
660f6603c60Sopenharmony_ci
661f6603c60Sopenharmony_cinapi_value testNativeWindowWRParcelNormal(napi_env env, napi_callback_info info)
662f6603c60Sopenharmony_ci{
663f6603c60Sopenharmony_ci    napi_value result = nullptr;
664f6603c60Sopenharmony_ci
665f6603c60Sopenharmony_ci    // 0. 创建 native window 实例
666f6603c60Sopenharmony_ci    GLuint textureId;
667f6603c60Sopenharmony_ci    glGenTextures(1, &textureId);
668f6603c60Sopenharmony_ci    auto _image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
669f6603c60Sopenharmony_ci    auto nativeWindow1 = OH_NativeImage_AcquireNativeWindow(_image);
670f6603c60Sopenharmony_ci    // 0. 已存在OHIPCParcel
671f6603c60Sopenharmony_ci    OHIPCParcel *parcel1 = OH_IPCParcel_Create();
672f6603c60Sopenharmony_ci
673f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_WriteToParcel(nativeWindow1, parcel1);
674f6603c60Sopenharmony_ci    if (flag != 0) {
675f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
676f6603c60Sopenharmony_ci        return result;
677f6603c60Sopenharmony_ci    }
678f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow2;
679f6603c60Sopenharmony_ci    flag = OH_NativeWindow_ReadFromParcel(parcel1, &nativeWindow2);
680f6603c60Sopenharmony_ci    if (flag != 0) {
681f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
682f6603c60Sopenharmony_ci        return result;
683f6603c60Sopenharmony_ci    }
684f6603c60Sopenharmony_ci    if (nativeWindow1 != nativeWindow2) {
685f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_3, &result);
686f6603c60Sopenharmony_ci        return result;
687f6603c60Sopenharmony_ci    }
688f6603c60Sopenharmony_ci
689f6603c60Sopenharmony_ci    OH_NativeImage_Destroy(&_image);
690f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindow1);
691f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindow2);
692f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
693f6603c60Sopenharmony_ci    return result;
694f6603c60Sopenharmony_ci}
695f6603c60Sopenharmony_ci
696f6603c60Sopenharmony_ci
697f6603c60Sopenharmony_cinapi_value testNativeWindowWriteToParcelAbNormal(napi_env env, napi_callback_info info)
698f6603c60Sopenharmony_ci{
699f6603c60Sopenharmony_ci    napi_value result = nullptr;
700f6603c60Sopenharmony_ci
701f6603c60Sopenharmony_ci    // 0.
702f6603c60Sopenharmony_ci    GLuint textureId;
703f6603c60Sopenharmony_ci    glGenTextures(1, &textureId);
704f6603c60Sopenharmony_ci    auto _image = OH_NativeImage_Create(textureId, GL_TEXTURE_2D);
705f6603c60Sopenharmony_ci    OHNativeWindow *window1 = nullptr;
706f6603c60Sopenharmony_ci    OHIPCParcel *parcel1 = OH_IPCParcel_Create();
707f6603c60Sopenharmony_ci
708f6603c60Sopenharmony_ci    // 1.
709f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_ReadFromParcel(parcel1, &window1);
710f6603c60Sopenharmony_ci    if (window1 != nullptr) {
711f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
712f6603c60Sopenharmony_ci        return result;
713f6603c60Sopenharmony_ci    }
714f6603c60Sopenharmony_ci    OH_NativeImage_Destroy(&_image);
715f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(window1);
716f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
717f6603c60Sopenharmony_ci    return result;
718f6603c60Sopenharmony_ci}
719f6603c60Sopenharmony_ci
720f6603c60Sopenharmony_cinapi_value testNativeWindowReadFromParcelAbNormal(napi_env env, napi_callback_info info)
721f6603c60Sopenharmony_ci{
722f6603c60Sopenharmony_ci    napi_value result = nullptr;
723f6603c60Sopenharmony_ci
724f6603c60Sopenharmony_ci    // 0.
725f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
726f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
727f6603c60Sopenharmony_ci    OHNativeWindow *window1 = result1.nativeWindow;
728f6603c60Sopenharmony_ci    OHIPCParcel *parcel1 = OH_IPCParcel_Create();
729f6603c60Sopenharmony_ci
730f6603c60Sopenharmony_ci    // 1.
731f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_WriteToParcel(window1, parcel1);
732f6603c60Sopenharmony_ci    if (flag != 0) {
733f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
734f6603c60Sopenharmony_ci        return result;
735f6603c60Sopenharmony_ci    }
736f6603c60Sopenharmony_ci
737f6603c60Sopenharmony_ci    // 2.
738f6603c60Sopenharmony_ci    flag = OH_NativeWindow_WriteToParcel(window1, parcel1);
739f6603c60Sopenharmony_ci    if (flag != 0) {
740f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
741f6603c60Sopenharmony_ci        return result;
742f6603c60Sopenharmony_ci    }
743f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, window1);
744f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
745f6603c60Sopenharmony_ci    return result;
746f6603c60Sopenharmony_ci}
747f6603c60Sopenharmony_ci
748f6603c60Sopenharmony_cinapi_value testNativeWindowWRParcelDifferent(napi_env env, napi_callback_info info)
749f6603c60Sopenharmony_ci{
750f6603c60Sopenharmony_ci    napi_value result = nullptr;
751f6603c60Sopenharmony_ci    struct result result1, result2;
752f6603c60Sopenharmony_ci    result1 = InitNativeWindow();
753f6603c60Sopenharmony_ci    result2 = InitNativeWindow();
754f6603c60Sopenharmony_ci    OH_NativeImage *image1 = result1.image;
755f6603c60Sopenharmony_ci    OHNativeWindow *window1 = result1.nativeWindow;
756f6603c60Sopenharmony_ci    OH_NativeImage *image2 = result2.image;
757f6603c60Sopenharmony_ci    OHNativeWindow *window2 = result2.nativeWindow;
758f6603c60Sopenharmony_ci    OHIPCParcel *parcel1 = OH_IPCParcel_Create();
759f6603c60Sopenharmony_ci    OHIPCParcel *parcel2 = OH_IPCParcel_Create();
760f6603c60Sopenharmony_ci
761f6603c60Sopenharmony_ci    // 1.
762f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_WriteToParcel(window1, parcel1);
763f6603c60Sopenharmony_ci    if (flag != 0) {
764f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
765f6603c60Sopenharmony_ci        return result;
766f6603c60Sopenharmony_ci    }
767f6603c60Sopenharmony_ci    // 2.
768f6603c60Sopenharmony_ci    flag = OH_NativeWindow_WriteToParcel(window1, parcel2);
769f6603c60Sopenharmony_ci    if (flag != 0) {
770f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
771f6603c60Sopenharmony_ci        return result;
772f6603c60Sopenharmony_ci    }
773f6603c60Sopenharmony_ci    // 3.
774f6603c60Sopenharmony_ci    flag = OH_NativeWindow_WriteToParcel(window2, parcel1);
775f6603c60Sopenharmony_ci    if (flag != 0) {
776f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_3, &result);
777f6603c60Sopenharmony_ci        return result;
778f6603c60Sopenharmony_ci    }
779f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image1, window1);
780f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image2, window2);
781f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
782f6603c60Sopenharmony_ci    return result;
783f6603c60Sopenharmony_ci}
784f6603c60Sopenharmony_ci
785f6603c60Sopenharmony_ci
786f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowFlushBufferNullptr(napi_env env, napi_callback_info info)
787f6603c60Sopenharmony_ci{
788f6603c60Sopenharmony_ci    napi_value result = nullptr;
789f6603c60Sopenharmony_ci
790f6603c60Sopenharmony_ci    // 0.
791f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
792f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
793f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
794f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
795f6603c60Sopenharmony_ci    int fenceFd = -1;
796f6603c60Sopenharmony_ci    Region::Rect rect{
797f6603c60Sopenharmony_ci        .x = 0x100,
798f6603c60Sopenharmony_ci        .y = 0x100,
799f6603c60Sopenharmony_ci        .w = 0x100,
800f6603c60Sopenharmony_ci        .h = 0x100,
801f6603c60Sopenharmony_ci    };
802f6603c60Sopenharmony_ci    Region region{.rects = &rect};
803f6603c60Sopenharmony_ci    OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
804f6603c60Sopenharmony_ci
805f6603c60Sopenharmony_ci    // 1.
806f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowFlushBuffer(nullptr, nativeWindowBuffer, fenceFd, region);
807f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
808f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
809f6603c60Sopenharmony_ci        return result;
810f6603c60Sopenharmony_ci    }
811f6603c60Sopenharmony_ci    // 2.
812f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nullptr, fenceFd, region);
813f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
814f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
815f6603c60Sopenharmony_ci        return result;
816f6603c60Sopenharmony_ci    }
817f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
818f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
819f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
820f6603c60Sopenharmony_ci    return result;
821f6603c60Sopenharmony_ci}
822f6603c60Sopenharmony_ci
823f6603c60Sopenharmony_ci
824f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowFlushBufferNormal(napi_env env, napi_callback_info info)
825f6603c60Sopenharmony_ci{
826f6603c60Sopenharmony_ci    napi_value result = nullptr;
827f6603c60Sopenharmony_ci
828f6603c60Sopenharmony_ci    // 0.
829f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
830f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
831f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
832f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
833f6603c60Sopenharmony_ci    int fenceFd = -1;
834f6603c60Sopenharmony_ci    Region::Rect rect{
835f6603c60Sopenharmony_ci        .x = 0x100,
836f6603c60Sopenharmony_ci        .y = 0x100,
837f6603c60Sopenharmony_ci        .w = 0x100,
838f6603c60Sopenharmony_ci        .h = 0x100,
839f6603c60Sopenharmony_ci    };
840f6603c60Sopenharmony_ci    Region region{.rects = &rect};
841f6603c60Sopenharmony_ci    OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
842f6603c60Sopenharmony_ci
843f6603c60Sopenharmony_ci    // 1.
844f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
845f6603c60Sopenharmony_ci    if (flag != 0) {
846f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
847f6603c60Sopenharmony_ci        return result;
848f6603c60Sopenharmony_ci    }
849f6603c60Sopenharmony_ci
850f6603c60Sopenharmony_ci    // 2.
851f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
852f6603c60Sopenharmony_ci    if (flag != CONSTANT_41207000) {
853f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
854f6603c60Sopenharmony_ci        return result;
855f6603c60Sopenharmony_ci    }
856f6603c60Sopenharmony_ci
857f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
858f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
859f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
860f6603c60Sopenharmony_ci    return result;
861f6603c60Sopenharmony_ci}
862f6603c60Sopenharmony_ci
863f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowFlushBufferAbnormal(napi_env env, napi_callback_info info)
864f6603c60Sopenharmony_ci{
865f6603c60Sopenharmony_ci    napi_value result = nullptr;
866f6603c60Sopenharmony_ci    // 1.
867f6603c60Sopenharmony_ci    int fenceFdList[] = {-CONSTANT_999999999, -CONSTANT_1000, -CONSTANT_1,       CONSTANT_0,
868f6603c60Sopenharmony_ci                         CONSTANT_1,          CONSTANT_1000,  CONSTANT_999999999};
869f6603c60Sopenharmony_ci    for (int i = 0; i < sizeof(fenceFdList) / sizeof(int); ++i) {
870f6603c60Sopenharmony_ci        struct result result1 = InitNativeWindow();
871f6603c60Sopenharmony_ci        OH_NativeImage *image = result1.image;
872f6603c60Sopenharmony_ci        OHNativeWindow *nativeWindow = result1.nativeWindow;
873f6603c60Sopenharmony_ci        OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
874f6603c60Sopenharmony_ci        int fenceFd = -1;
875f6603c60Sopenharmony_ci        auto ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
876f6603c60Sopenharmony_ci        Region::Rect rect{
877f6603c60Sopenharmony_ci            .x = 0x100,
878f6603c60Sopenharmony_ci            .y = 0x100,
879f6603c60Sopenharmony_ci            .w = 0x100,
880f6603c60Sopenharmony_ci            .h = 0x100,
881f6603c60Sopenharmony_ci        };
882f6603c60Sopenharmony_ci        Region region{.rects = &rect};
883f6603c60Sopenharmony_ci        auto flag = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFdList[i], region);
884f6603c60Sopenharmony_ci        if (flag != 0) {
885f6603c60Sopenharmony_ci            napi_create_int32(env, i + 1, &result);
886f6603c60Sopenharmony_ci            return result;
887f6603c60Sopenharmony_ci        }
888f6603c60Sopenharmony_ci
889f6603c60Sopenharmony_ci        DestroyNativeWindowImage(image, nativeWindow);
890f6603c60Sopenharmony_ci        OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
891f6603c60Sopenharmony_ci        napi_create_int32(env, SUCCESS, &result);
892f6603c60Sopenharmony_ci    }
893f6603c60Sopenharmony_ci    return result;
894f6603c60Sopenharmony_ci}
895f6603c60Sopenharmony_ci
896f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowFlushBufferErrorCode(napi_env env, napi_callback_info info)
897f6603c60Sopenharmony_ci{
898f6603c60Sopenharmony_ci    napi_value result = nullptr;
899f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
900f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
901f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
902f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
903f6603c60Sopenharmony_ci    int fenceFd = -1;
904f6603c60Sopenharmony_ci    Region::Rect rect{
905f6603c60Sopenharmony_ci        .x = 0x100,
906f6603c60Sopenharmony_ci        .y = 0x100,
907f6603c60Sopenharmony_ci        .w = 0x100,
908f6603c60Sopenharmony_ci        .h = 0x100,
909f6603c60Sopenharmony_ci    };
910f6603c60Sopenharmony_ci    Region region{.rects = &rect};
911f6603c60Sopenharmony_ci    OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
912f6603c60Sopenharmony_ci
913f6603c60Sopenharmony_ci    OH_NativeBuffer_Config config{
914f6603c60Sopenharmony_ci        .width = 0x100,
915f6603c60Sopenharmony_ci        .height = 0x100,
916f6603c60Sopenharmony_ci        .format = NATIVEBUFFER_PIXEL_FMT_RGBA_8888,
917f6603c60Sopenharmony_ci        .usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA,
918f6603c60Sopenharmony_ci    };
919f6603c60Sopenharmony_ci    OH_NativeBuffer *newBuffer = OH_NativeBuffer_Alloc(&config);
920f6603c60Sopenharmony_ci    nativeWindowBuffer = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(newBuffer);
921f6603c60Sopenharmony_ci
922f6603c60Sopenharmony_ci    // 1.
923f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, -1, region);
924f6603c60Sopenharmony_ci    if (flag != CONSTANT_41210000) {
925f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
926f6603c60Sopenharmony_ci        return result;
927f6603c60Sopenharmony_ci    }
928f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
929f6603c60Sopenharmony_ci    OH_NativeBuffer_Unreference(newBuffer);
930f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
931f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
932f6603c60Sopenharmony_ci    return result;
933f6603c60Sopenharmony_ci}
934f6603c60Sopenharmony_ci
935f6603c60Sopenharmony_ci
936f6603c60Sopenharmony_cinapi_value testNativeWindowGetLastFlushedBufferV2Nullptr(napi_env env, napi_callback_info info)
937f6603c60Sopenharmony_ci{
938f6603c60Sopenharmony_ci    napi_value result = nullptr;
939f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
940f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
941f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
942f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
943f6603c60Sopenharmony_ci    int fenceFd;
944f6603c60Sopenharmony_ci    float matrix[16];
945f6603c60Sopenharmony_ci
946f6603c60Sopenharmony_ci    // 1.
947f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_GetLastFlushedBufferV2(nullptr, &nativeWindowBuffer, &fenceFd, matrix);
948f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
949f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
950f6603c60Sopenharmony_ci        return result;
951f6603c60Sopenharmony_ci    }
952f6603c60Sopenharmony_ci    // 2.
953f6603c60Sopenharmony_ci    flag = OH_NativeWindow_GetLastFlushedBufferV2(nativeWindow, nullptr, &fenceFd, matrix);
954f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
955f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
956f6603c60Sopenharmony_ci        return result;
957f6603c60Sopenharmony_ci    }
958f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
959f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
960f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
961f6603c60Sopenharmony_ci    return result;
962f6603c60Sopenharmony_ci}
963f6603c60Sopenharmony_ci
964f6603c60Sopenharmony_ci
965f6603c60Sopenharmony_cinapi_value testNativeWindowGetLastFlushedBufferNullptr(napi_env env, napi_callback_info info)
966f6603c60Sopenharmony_ci{
967f6603c60Sopenharmony_ci    napi_value result = nullptr;
968f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
969f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
970f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
971f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
972f6603c60Sopenharmony_ci    int fenceFd;
973f6603c60Sopenharmony_ci    float matrix[16];
974f6603c60Sopenharmony_ci
975f6603c60Sopenharmony_ci    // 1.
976f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_GetLastFlushedBuffer(nullptr, &nativeWindowBuffer, &fenceFd, matrix);
977f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
978f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
979f6603c60Sopenharmony_ci        return result;
980f6603c60Sopenharmony_ci    }
981f6603c60Sopenharmony_ci    // 2.
982f6603c60Sopenharmony_ci    flag = OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, nullptr, &fenceFd, matrix);
983f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
984f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
985f6603c60Sopenharmony_ci        return result;
986f6603c60Sopenharmony_ci    }
987f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
988f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
989f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
990f6603c60Sopenharmony_ci    return result;
991f6603c60Sopenharmony_ci}
992f6603c60Sopenharmony_ci
993f6603c60Sopenharmony_cinapi_value testNativeWindowGetLastFlushedBufferV2Normal(napi_env env, napi_callback_info info)
994f6603c60Sopenharmony_ci{
995f6603c60Sopenharmony_ci    napi_value result = nullptr;
996f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
997f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
998f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
999f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1000f6603c60Sopenharmony_ci    int fenceFd;
1001f6603c60Sopenharmony_ci    float matrix[16];
1002f6603c60Sopenharmony_ci    Region::Rect rect{
1003f6603c60Sopenharmony_ci        .x = 0x100,
1004f6603c60Sopenharmony_ci        .y = 0x100,
1005f6603c60Sopenharmony_ci        .w = 0x100,
1006f6603c60Sopenharmony_ci        .h = 0x100,
1007f6603c60Sopenharmony_ci    };
1008f6603c60Sopenharmony_ci    Region region{.rects = &rect};
1009f6603c60Sopenharmony_ci    auto ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1010f6603c60Sopenharmony_ci    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
1011f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_GetLastFlushedBufferV2(nativeWindow, &nativeWindowBuffer, &fenceFd, matrix);
1012f6603c60Sopenharmony_ci    if (flag != 0) {
1013f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
1014f6603c60Sopenharmony_ci        return result;
1015f6603c60Sopenharmony_ci    }
1016f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1017f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1018f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1019f6603c60Sopenharmony_ci    return result;
1020f6603c60Sopenharmony_ci}
1021f6603c60Sopenharmony_ci
1022f6603c60Sopenharmony_cinapi_value testNativeWindowGetLastFlushedBufferNormal(napi_env env, napi_callback_info info)
1023f6603c60Sopenharmony_ci{
1024f6603c60Sopenharmony_ci    napi_value result = nullptr;
1025f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1026f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1027f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1028f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1029f6603c60Sopenharmony_ci    int fenceFd;
1030f6603c60Sopenharmony_ci    float matrix[16];
1031f6603c60Sopenharmony_ci    Region::Rect rect{
1032f6603c60Sopenharmony_ci        .x = 0x100,
1033f6603c60Sopenharmony_ci        .y = 0x100,
1034f6603c60Sopenharmony_ci        .w = 0x100,
1035f6603c60Sopenharmony_ci        .h = 0x100,
1036f6603c60Sopenharmony_ci    };
1037f6603c60Sopenharmony_ci    Region region{.rects = &rect};
1038f6603c60Sopenharmony_ci    auto ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1039f6603c60Sopenharmony_ci    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
1040f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd, matrix);
1041f6603c60Sopenharmony_ci    if (flag != 0) {
1042f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
1043f6603c60Sopenharmony_ci        return result;
1044f6603c60Sopenharmony_ci    }
1045f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1046f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1047f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1048f6603c60Sopenharmony_ci    return result;
1049f6603c60Sopenharmony_ci}
1050f6603c60Sopenharmony_ci
1051f6603c60Sopenharmony_ci
1052f6603c60Sopenharmony_cinapi_value testNativeWindowSetBufferHold(napi_env env, napi_callback_info info)
1053f6603c60Sopenharmony_ci{
1054f6603c60Sopenharmony_ci    napi_value result = nullptr;
1055f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1056f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1057f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1058f6603c60Sopenharmony_ci
1059f6603c60Sopenharmony_ci    OH_NativeWindow_SetBufferHold(nullptr);
1060f6603c60Sopenharmony_ci    OH_NativeWindow_SetBufferHold(nativeWindow);
1061f6603c60Sopenharmony_ci
1062f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1063f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1064f6603c60Sopenharmony_ci    return result;
1065f6603c60Sopenharmony_ci}
1066f6603c60Sopenharmony_ci
1067f6603c60Sopenharmony_cinapi_value testNativeWindowGetNativeObjectMagicNullptr(napi_env env, napi_callback_info info)
1068f6603c60Sopenharmony_ci{
1069f6603c60Sopenharmony_ci    napi_value result = nullptr;
1070f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_GetNativeObjectMagic(nullptr);
1071f6603c60Sopenharmony_ci    if (flag != -1) {
1072f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
1073f6603c60Sopenharmony_ci        return result;
1074f6603c60Sopenharmony_ci    }
1075f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1076f6603c60Sopenharmony_ci    return result;
1077f6603c60Sopenharmony_ci}
1078f6603c60Sopenharmony_ci
1079f6603c60Sopenharmony_cinapi_value testNativeWindowGetNativeObjectMagicNormal(napi_env env, napi_callback_info info)
1080f6603c60Sopenharmony_ci{
1081f6603c60Sopenharmony_ci    napi_value result = nullptr;
1082f6603c60Sopenharmony_ci
1083f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1084f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1085f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1086f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer;
1087f6603c60Sopenharmony_ci    int fenceFd = -1;
1088f6603c60Sopenharmony_ci    OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1089f6603c60Sopenharmony_ci
1090f6603c60Sopenharmony_ci    auto magicId = OH_NativeWindow_GetNativeObjectMagic(nativeWindow);
1091f6603c60Sopenharmony_ci    if (magicId == -1) {
1092f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1093f6603c60Sopenharmony_ci        return result;
1094f6603c60Sopenharmony_ci    }
1095f6603c60Sopenharmony_ci    auto magicId2 = OH_NativeWindow_GetNativeObjectMagic(nativeWindow);
1096f6603c60Sopenharmony_ci    if (magicId2 == -1) {
1097f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1098f6603c60Sopenharmony_ci        return result;
1099f6603c60Sopenharmony_ci    }
1100f6603c60Sopenharmony_ci    if (magicId != magicId2) {
1101f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_3, &result);
1102f6603c60Sopenharmony_ci        return result;
1103f6603c60Sopenharmony_ci    }
1104f6603c60Sopenharmony_ci    auto magicId3 = OH_NativeWindow_GetNativeObjectMagic(nativeWindowBuffer);
1105f6603c60Sopenharmony_ci    if (magicId3 == -1) {
1106f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
1107f6603c60Sopenharmony_ci        return result;
1108f6603c60Sopenharmony_ci    }
1109f6603c60Sopenharmony_ci    auto magicId4 = OH_NativeWindow_GetNativeObjectMagic(nativeWindowBuffer);
1110f6603c60Sopenharmony_ci    if (magicId4 == -1) {
1111f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
1112f6603c60Sopenharmony_ci        return result;
1113f6603c60Sopenharmony_ci    }
1114f6603c60Sopenharmony_ci
1115f6603c60Sopenharmony_ci    if (magicId3 != magicId4) {
1116f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_3, &result);
1117f6603c60Sopenharmony_ci        return result;
1118f6603c60Sopenharmony_ci    }
1119f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1120f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1121f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1122f6603c60Sopenharmony_ci    return result;
1123f6603c60Sopenharmony_ci}
1124f6603c60Sopenharmony_ci
1125f6603c60Sopenharmony_cinapi_value testNativeWindowNativeObjectReferenceNullptr(napi_env env, napi_callback_info info)
1126f6603c60Sopenharmony_ci{
1127f6603c60Sopenharmony_ci    napi_value result = nullptr;
1128f6603c60Sopenharmony_ci
1129f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1130f6603c60Sopenharmony_ci
1131f6603c60Sopenharmony_ci    auto magicId = OH_NativeWindow_NativeObjectReference(nullptr);
1132f6603c60Sopenharmony_ci    if (magicId != CONSTANT_40001000) {
1133f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1134f6603c60Sopenharmony_ci        return result;
1135f6603c60Sopenharmony_ci    }
1136f6603c60Sopenharmony_ci
1137f6603c60Sopenharmony_ci    magicId = OH_NativeWindow_NativeObjectReference(nativeWindowBuffer);
1138f6603c60Sopenharmony_ci    if (magicId != CONSTANT_40001000) {
1139f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
1140f6603c60Sopenharmony_ci        return result;
1141f6603c60Sopenharmony_ci    }
1142f6603c60Sopenharmony_ci
1143f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1144f6603c60Sopenharmony_ci    return result;
1145f6603c60Sopenharmony_ci}
1146f6603c60Sopenharmony_ci
1147f6603c60Sopenharmony_ci
1148f6603c60Sopenharmony_cinapi_value testNativeWindowNativeObjectReferenceNormal(napi_env env, napi_callback_info info)
1149f6603c60Sopenharmony_ci{
1150f6603c60Sopenharmony_ci    napi_value result = nullptr;
1151f6603c60Sopenharmony_ci
1152f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1153f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1154f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1155f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1156f6603c60Sopenharmony_ci    int fenceFd = -1;
1157f6603c60Sopenharmony_ci    OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1158f6603c60Sopenharmony_ci
1159f6603c60Sopenharmony_ci    auto magicId = OH_NativeWindow_NativeObjectReference(nativeWindow);
1160f6603c60Sopenharmony_ci    if (magicId != 0) {
1161f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1162f6603c60Sopenharmony_ci        return result;
1163f6603c60Sopenharmony_ci    }
1164f6603c60Sopenharmony_ci
1165f6603c60Sopenharmony_ci    magicId = OH_NativeWindow_NativeObjectReference(nativeWindowBuffer);
1166f6603c60Sopenharmony_ci    if (magicId != 0) {
1167f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
1168f6603c60Sopenharmony_ci        return result;
1169f6603c60Sopenharmony_ci    }
1170f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1171f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1172f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1173f6603c60Sopenharmony_ci    return result;
1174f6603c60Sopenharmony_ci}
1175f6603c60Sopenharmony_ci
1176f6603c60Sopenharmony_cinapi_value testNativeWindowNativeObjectUnreferenceNullptr(napi_env env, napi_callback_info info)
1177f6603c60Sopenharmony_ci{
1178f6603c60Sopenharmony_ci    napi_value result = nullptr;
1179f6603c60Sopenharmony_ci
1180f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1181f6603c60Sopenharmony_ci
1182f6603c60Sopenharmony_ci    auto magicId = OH_NativeWindow_NativeObjectUnreference(nullptr);
1183f6603c60Sopenharmony_ci    if (magicId != CONSTANT_40001000) {
1184f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1185f6603c60Sopenharmony_ci        return result;
1186f6603c60Sopenharmony_ci    }
1187f6603c60Sopenharmony_ci
1188f6603c60Sopenharmony_ci    magicId = OH_NativeWindow_NativeObjectUnreference(nativeWindowBuffer);
1189f6603c60Sopenharmony_ci    if (magicId != CONSTANT_40001000) {
1190f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
1191f6603c60Sopenharmony_ci        return result;
1192f6603c60Sopenharmony_ci    }
1193f6603c60Sopenharmony_ci
1194f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1195f6603c60Sopenharmony_ci    return result;
1196f6603c60Sopenharmony_ci}
1197f6603c60Sopenharmony_ci
1198f6603c60Sopenharmony_cinapi_value testNativeWindowNativeObjectUnreferenceNormal(napi_env env, napi_callback_info info)
1199f6603c60Sopenharmony_ci{
1200f6603c60Sopenharmony_ci    napi_value result = nullptr;
1201f6603c60Sopenharmony_ci
1202f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1203f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1204f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1205f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1206f6603c60Sopenharmony_ci    int fenceFd = -1;
1207f6603c60Sopenharmony_ci    OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1208f6603c60Sopenharmony_ci
1209f6603c60Sopenharmony_ci    auto magicId = OH_NativeWindow_NativeObjectUnreference(nativeWindow);
1210f6603c60Sopenharmony_ci    if (magicId != 0) {
1211f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1212f6603c60Sopenharmony_ci        return result;
1213f6603c60Sopenharmony_ci    }
1214f6603c60Sopenharmony_ci
1215f6603c60Sopenharmony_ci    magicId = OH_NativeWindow_NativeObjectUnreference(nativeWindowBuffer);
1216f6603c60Sopenharmony_ci    if (magicId != 0) {
1217f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
1218f6603c60Sopenharmony_ci        return result;
1219f6603c60Sopenharmony_ci    }
1220f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1221f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1222f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1223f6603c60Sopenharmony_ci    return result;
1224f6603c60Sopenharmony_ci}
1225f6603c60Sopenharmony_ci
1226f6603c60Sopenharmony_ci
1227f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowAttachBufferNullptr(napi_env env, napi_callback_info info)
1228f6603c60Sopenharmony_ci{
1229f6603c60Sopenharmony_ci    napi_value result = nullptr;
1230f6603c60Sopenharmony_ci
1231f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1232f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1233f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1234f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1235f6603c60Sopenharmony_ci    int fenceFd = -1;
1236f6603c60Sopenharmony_ci    OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1237f6603c60Sopenharmony_ci
1238f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowAttachBuffer(nullptr, nativeWindowBuffer);
1239f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
1240f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1241f6603c60Sopenharmony_ci        return result;
1242f6603c60Sopenharmony_ci    }
1243f6603c60Sopenharmony_ci
1244f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nullptr);
1245f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
1246f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1247f6603c60Sopenharmony_ci        return result;
1248f6603c60Sopenharmony_ci    }
1249f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1250f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1251f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1252f6603c60Sopenharmony_ci    return result;
1253f6603c60Sopenharmony_ci}
1254f6603c60Sopenharmony_ci
1255f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowDetachBufferNullptr(napi_env env, napi_callback_info info)
1256f6603c60Sopenharmony_ci{
1257f6603c60Sopenharmony_ci    napi_value result = nullptr;
1258f6603c60Sopenharmony_ci
1259f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1260f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1261f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1262f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1263f6603c60Sopenharmony_ci    int fenceFd = -1;
1264f6603c60Sopenharmony_ci    OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1265f6603c60Sopenharmony_ci
1266f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowDetachBuffer(nullptr, nativeWindowBuffer);
1267f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
1268f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1269f6603c60Sopenharmony_ci        return result;
1270f6603c60Sopenharmony_ci    }
1271f6603c60Sopenharmony_ci
1272f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nullptr);
1273f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
1274f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
1275f6603c60Sopenharmony_ci        return result;
1276f6603c60Sopenharmony_ci    }
1277f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1278f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1279f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1280f6603c60Sopenharmony_ci    return result;
1281f6603c60Sopenharmony_ci}
1282f6603c60Sopenharmony_ci
1283f6603c60Sopenharmony_ci
1284f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowDetachBufferNormal(napi_env env, napi_callback_info info)
1285f6603c60Sopenharmony_ci{
1286f6603c60Sopenharmony_ci    napi_value result = nullptr;
1287f6603c60Sopenharmony_ci
1288f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1289f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1290f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1291f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1292f6603c60Sopenharmony_ci    int fenceFd = -1;
1293f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1294f6603c60Sopenharmony_ci    if (flag != 0) {
1295f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
1296f6603c60Sopenharmony_ci        return result;
1297f6603c60Sopenharmony_ci    }
1298f6603c60Sopenharmony_ci
1299f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer);
1300f6603c60Sopenharmony_ci    if (flag != 0) {
1301f6603c60Sopenharmony_ci        napi_create_int32(env, 1, &result);
1302f6603c60Sopenharmony_ci        return result;
1303f6603c60Sopenharmony_ci    }
1304f6603c60Sopenharmony_ci
1305f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer);
1306f6603c60Sopenharmony_ci    if (flag != CONSTANT_41210000) {
1307f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
1308f6603c60Sopenharmony_ci        return result;
1309f6603c60Sopenharmony_ci    }
1310f6603c60Sopenharmony_ci
1311f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1312f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1313f6603c60Sopenharmony_ci
1314f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1315f6603c60Sopenharmony_ci    return result;
1316f6603c60Sopenharmony_ci}
1317f6603c60Sopenharmony_ci
1318f6603c60Sopenharmony_ci
1319f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowAttachBufferErrorCode(napi_env env, napi_callback_info info)
1320f6603c60Sopenharmony_ci{
1321f6603c60Sopenharmony_ci    napi_value result = nullptr;
1322f6603c60Sopenharmony_ci
1323f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1324f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1325f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1326f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nwb1, *nwb2, *nwb3, *nwb4;
1327f6603c60Sopenharmony_ci    int fenceFd = -1;
1328f6603c60Sopenharmony_ci    OH_NativeBuffer_Config config{
1329f6603c60Sopenharmony_ci        .width = 0x100,
1330f6603c60Sopenharmony_ci        .height = 0x100,
1331f6603c60Sopenharmony_ci        .format = NATIVEBUFFER_PIXEL_FMT_RGBA_8888,
1332f6603c60Sopenharmony_ci        .usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA,
1333f6603c60Sopenharmony_ci    };
1334f6603c60Sopenharmony_ci    OH_NativeBuffer *nativeBuffer = OH_NativeBuffer_Alloc(&config);
1335f6603c60Sopenharmony_ci    OHNativeWindowBuffer **arr[] = {&nwb1, &nwb2, &nwb3, &nwb4};
1336f6603c60Sopenharmony_ci    nwb1 = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nativeBuffer);
1337f6603c60Sopenharmony_ci    nwb2 = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nativeBuffer);
1338f6603c60Sopenharmony_ci    nwb3 = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nativeBuffer);
1339f6603c60Sopenharmony_ci    nwb4 = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nativeBuffer);
1340f6603c60Sopenharmony_ci
1341f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nwb1);
1342f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nwb2);
1343f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nwb3);
1344f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nwb4);
1345f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1346f6603c60Sopenharmony_ci    OH_NativeBuffer_Unreference(nativeBuffer);
1347f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1348f6603c60Sopenharmony_ci    return result;
1349f6603c60Sopenharmony_ci}
1350f6603c60Sopenharmony_ci
1351f6603c60Sopenharmony_ci
1352f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowAttachBufferNormal(napi_env env, napi_callback_info info)
1353f6603c60Sopenharmony_ci{
1354f6603c60Sopenharmony_ci    napi_value result = nullptr;
1355f6603c60Sopenharmony_ci
1356f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1357f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1358f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1359f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1360f6603c60Sopenharmony_ci    int fenceFd = -1;
1361f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1362f6603c60Sopenharmony_ci    if (flag != 0) {
1363f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
1364f6603c60Sopenharmony_ci        return result;
1365f6603c60Sopenharmony_ci    }
1366f6603c60Sopenharmony_ci
1367f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nativeWindowBuffer);
1368f6603c60Sopenharmony_ci    if (flag != CONSTANT_41208000) {
1369f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1370f6603c60Sopenharmony_ci        return result;
1371f6603c60Sopenharmony_ci    }
1372f6603c60Sopenharmony_ci
1373f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer);
1374f6603c60Sopenharmony_ci    if (flag != 0) {
1375f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2, &result);
1376f6603c60Sopenharmony_ci        return result;
1377f6603c60Sopenharmony_ci    }
1378f6603c60Sopenharmony_ci
1379f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nativeWindowBuffer);
1380f6603c60Sopenharmony_ci    if (flag != 0) {
1381f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_3, &result);
1382f6603c60Sopenharmony_ci        return result;
1383f6603c60Sopenharmony_ci    }
1384f6603c60Sopenharmony_ci
1385f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1386f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1387f6603c60Sopenharmony_ci
1388f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1389f6603c60Sopenharmony_ci    return result;
1390f6603c60Sopenharmony_ci}
1391f6603c60Sopenharmony_ci
1392f6603c60Sopenharmony_ci
1393f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowDetachBufferErrorCode(napi_env env, napi_callback_info info)
1394f6603c60Sopenharmony_ci{
1395f6603c60Sopenharmony_ci    napi_value result = nullptr;
1396f6603c60Sopenharmony_ci
1397f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1398f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1399f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1400f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer = nullptr;
1401f6603c60Sopenharmony_ci    int fenceFd;
1402f6603c60Sopenharmony_ci    Region::Rect rect{
1403f6603c60Sopenharmony_ci        .x = 0x100,
1404f6603c60Sopenharmony_ci        .y = 0x100,
1405f6603c60Sopenharmony_ci        .w = 0x100,
1406f6603c60Sopenharmony_ci        .h = 0x100,
1407f6603c60Sopenharmony_ci    };
1408f6603c60Sopenharmony_ci    Region region{.rects = &rect};
1409f6603c60Sopenharmony_ci    auto ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1410f6603c60Sopenharmony_ci    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, region);
1411f6603c60Sopenharmony_ci    if (ret != 0) {
1412f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
1413f6603c60Sopenharmony_ci        return result;
1414f6603c60Sopenharmony_ci    }
1415f6603c60Sopenharmony_ci    // 3.
1416f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer);
1417f6603c60Sopenharmony_ci    if (flag != CONSTANT_41207000) {
1418f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
1419f6603c60Sopenharmony_ci        return result;
1420f6603c60Sopenharmony_ci    }
1421f6603c60Sopenharmony_ci
1422f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1423f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1424f6603c60Sopenharmony_ci
1425f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1426f6603c60Sopenharmony_ci    return result;
1427f6603c60Sopenharmony_ci}
1428f6603c60Sopenharmony_ci
1429f6603c60Sopenharmony_ci
1430f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowAtDetachDifferentBufferNormal(napi_env env, napi_callback_info info)
1431f6603c60Sopenharmony_ci{
1432f6603c60Sopenharmony_ci    napi_value result = nullptr;
1433f6603c60Sopenharmony_ci
1434f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1435f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1436f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1437f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer1, *nativeWindowBuffer2, *nativeWindowBuffer3;
1438f6603c60Sopenharmony_ci    int fenceFd = -1;
1439f6603c60Sopenharmony_ci    OHNativeWindowBuffer **nativeWindowBuffers[] = {&nativeWindowBuffer1, &nativeWindowBuffer2, &nativeWindowBuffer3};
1440f6603c60Sopenharmony_ci    for (int i = 0; i < CONSTANT_3; ++i) {
1441f6603c60Sopenharmony_ci        auto flag = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, nativeWindowBuffers[i], &fenceFd);
1442f6603c60Sopenharmony_ci        if (flag != 0) {
1443f6603c60Sopenharmony_ci            napi_create_int32(env, CONSTANT_1000 + i + 1, &result);
1444f6603c60Sopenharmony_ci            return result;
1445f6603c60Sopenharmony_ci        }
1446f6603c60Sopenharmony_ci    }
1447f6603c60Sopenharmony_ci
1448f6603c60Sopenharmony_ci    for (int i = 0; i < CONSTANT_3; ++i) {
1449f6603c60Sopenharmony_ci        auto flag = OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, *nativeWindowBuffers[i]);
1450f6603c60Sopenharmony_ci        if (flag != 0) {
1451f6603c60Sopenharmony_ci            napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + i + 1, &result);
1452f6603c60Sopenharmony_ci            return result;
1453f6603c60Sopenharmony_ci        }
1454f6603c60Sopenharmony_ci    }
1455f6603c60Sopenharmony_ci
1456f6603c60Sopenharmony_ci    for (int i = 0; i < CONSTANT_3; ++i) {
1457f6603c60Sopenharmony_ci        auto flag = OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, *nativeWindowBuffers[i]);
1458f6603c60Sopenharmony_ci        if (flag != 0) {
1459f6603c60Sopenharmony_ci            napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + i + 1, &result);
1460f6603c60Sopenharmony_ci            return result;
1461f6603c60Sopenharmony_ci        }
1462f6603c60Sopenharmony_ci    }
1463f6603c60Sopenharmony_ci
1464f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1465f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer1);
1466f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer2);
1467f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer3);
1468f6603c60Sopenharmony_ci
1469f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1470f6603c60Sopenharmony_ci    return result;
1471f6603c60Sopenharmony_ci}
1472f6603c60Sopenharmony_ci
1473f6603c60Sopenharmony_cistruct  Paramater {
1474f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow1 = nullptr;
1475f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow2 = nullptr;
1476f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer1 = nullptr;
1477f6603c60Sopenharmony_ci    OHNativeWindowBuffer *nativeWindowBuffer2 = nullptr;
1478f6603c60Sopenharmony_ci    OH_NativeBuffer *nativeBuffer1 = nullptr;
1479f6603c60Sopenharmony_ci    OH_NativeBuffer *nativeBuffer2 = nullptr;
1480f6603c60Sopenharmony_ci};
1481f6603c60Sopenharmony_ci
1482f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowAtDetachDifferentBufferAbnormal1(
1483f6603c60Sopenharmony_ci    napi_env env, napi_callback_info info, Paramater paramater)
1484f6603c60Sopenharmony_ci{
1485f6603c60Sopenharmony_ci    napi_value result = nullptr;
1486f6603c60Sopenharmony_ci    int32_t flag = OH_NativeWindow_NativeWindowAttachBuffer(paramater.nativeWindow1, paramater.nativeWindowBuffer1);
1487f6603c60Sopenharmony_ci    if (flag != 0) {
1488f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_1, &result);
1489f6603c60Sopenharmony_ci        return result;
1490f6603c60Sopenharmony_ci    }
1491f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(paramater.nativeWindow2, paramater.nativeWindowBuffer2);
1492f6603c60Sopenharmony_ci    if (flag != 0) {
1493f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_2, &result);
1494f6603c60Sopenharmony_ci        return result;
1495f6603c60Sopenharmony_ci    }
1496f6603c60Sopenharmony_ci    return result;
1497f6603c60Sopenharmony_ci}
1498f6603c60Sopenharmony_ci
1499f6603c60Sopenharmony_ci
1500f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowAtDetachDifferentBufferAbnormal2(napi_env env, napi_callback_info info,
1501f6603c60Sopenharmony_ci                                                                        Paramater paramater)
1502f6603c60Sopenharmony_ci{
1503f6603c60Sopenharmony_ci    napi_value result = nullptr;
1504f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowAttachBuffer(paramater.nativeWindow2, paramater.nativeWindowBuffer1);
1505f6603c60Sopenharmony_ci    if (flag != 0) {
1506f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_1, &result);
1507f6603c60Sopenharmony_ci        return result;
1508f6603c60Sopenharmony_ci    }
1509f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(paramater.nativeWindow1, paramater.nativeWindowBuffer2);
1510f6603c60Sopenharmony_ci    if (flag != 0) {
1511f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_3 * CONSTANT_1000 + CONSTANT_2, &result);
1512f6603c60Sopenharmony_ci        return result;
1513f6603c60Sopenharmony_ci    }
1514f6603c60Sopenharmony_ci    // 4.
1515f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowDetachBuffer(paramater.nativeWindow1, paramater.nativeWindowBuffer1);
1516f6603c60Sopenharmony_ci    if (flag != 0) {
1517f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_1, &result);
1518f6603c60Sopenharmony_ci        return result;
1519f6603c60Sopenharmony_ci    }
1520f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowDetachBuffer(paramater.nativeWindow2, paramater.nativeWindowBuffer2);
1521f6603c60Sopenharmony_ci    if (flag != 0) {
1522f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_4 * CONSTANT_1000 + CONSTANT_2, &result);
1523f6603c60Sopenharmony_ci        return result;
1524f6603c60Sopenharmony_ci    }
1525f6603c60Sopenharmony_ci    // 5.
1526f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(paramater.nativeWindow2, paramater.nativeWindowBuffer1);
1527f6603c60Sopenharmony_ci    if (flag == 0) {
1528f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_1, &result);
1529f6603c60Sopenharmony_ci        return result;
1530f6603c60Sopenharmony_ci    }
1531f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowAttachBuffer(paramater.nativeWindow1, paramater.nativeWindowBuffer2);
1532f6603c60Sopenharmony_ci    if (flag == 0) {
1533f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_5 * CONSTANT_1000 + CONSTANT_2, &result);
1534f6603c60Sopenharmony_ci        return result;
1535f6603c60Sopenharmony_ci    }
1536f6603c60Sopenharmony_ci    return result;
1537f6603c60Sopenharmony_ci}
1538f6603c60Sopenharmony_ci
1539f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowAtDetachDifferentBufferAbnormal(napi_env env, napi_callback_info info)
1540f6603c60Sopenharmony_ci{
1541f6603c60Sopenharmony_ci    napi_value result = nullptr;
1542f6603c60Sopenharmony_ci    struct  Paramater paramater;
1543f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1544f6603c60Sopenharmony_ci    struct result result2 = InitNativeWindow();
1545f6603c60Sopenharmony_ci    OH_NativeImage *image1 = result1.image;
1546f6603c60Sopenharmony_ci    paramater.nativeWindow1 = result1.nativeWindow;
1547f6603c60Sopenharmony_ci    OH_NativeImage *image2 = result2.image;
1548f6603c60Sopenharmony_ci    paramater.nativeWindow2 = result2.nativeWindow;
1549f6603c60Sopenharmony_ci    OH_NativeBuffer_Config config{
1550f6603c60Sopenharmony_ci        .width = 0x100,
1551f6603c60Sopenharmony_ci        .height = 0x100,
1552f6603c60Sopenharmony_ci        .format = NATIVEBUFFER_PIXEL_FMT_RGBA_8888,
1553f6603c60Sopenharmony_ci        .usage = NATIVEBUFFER_USAGE_CPU_READ | NATIVEBUFFER_USAGE_CPU_WRITE | NATIVEBUFFER_USAGE_MEM_DMA,
1554f6603c60Sopenharmony_ci    };
1555f6603c60Sopenharmony_ci    paramater.nativeBuffer1 = OH_NativeBuffer_Alloc(&config);
1556f6603c60Sopenharmony_ci    paramater.nativeBuffer2 = OH_NativeBuffer_Alloc(&config);
1557f6603c60Sopenharmony_ci    paramater.nativeWindowBuffer1 = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(paramater.nativeBuffer1);
1558f6603c60Sopenharmony_ci    if (paramater.nativeWindowBuffer1 == nullptr) {
1559f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1000 + CONSTANT_1, &result);
1560f6603c60Sopenharmony_ci        return result;
1561f6603c60Sopenharmony_ci    }
1562f6603c60Sopenharmony_ci    paramater.nativeWindowBuffer2 = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(paramater.nativeBuffer2);
1563f6603c60Sopenharmony_ci    if (paramater.nativeWindowBuffer2 == nullptr) {
1564f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1000 + CONSTANT_2, &result);
1565f6603c60Sopenharmony_ci        return result;
1566f6603c60Sopenharmony_ci    }
1567f6603c60Sopenharmony_ci    result = testNativeWindowNativeWindowAtDetachDifferentBufferAbnormal1(env, info, paramater);
1568f6603c60Sopenharmony_ci    if (result != nullptr) {
1569f6603c60Sopenharmony_ci        return result;
1570f6603c60Sopenharmony_ci    }
1571f6603c60Sopenharmony_ci    result = testNativeWindowNativeWindowAtDetachDifferentBufferAbnormal2(env, info, paramater);
1572f6603c60Sopenharmony_ci    if (result != nullptr) {
1573f6603c60Sopenharmony_ci        return result;
1574f6603c60Sopenharmony_ci    }
1575f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image1, paramater.nativeWindow1);
1576f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image2, paramater.nativeWindow2);
1577f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(paramater.nativeWindowBuffer1);
1578f6603c60Sopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(paramater.nativeWindowBuffer2);
1579f6603c60Sopenharmony_ci    OH_NativeBuffer_Unreference(paramater.nativeBuffer1);
1580f6603c60Sopenharmony_ci    OH_NativeBuffer_Unreference(paramater.nativeBuffer2);
1581f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1582f6603c60Sopenharmony_ci    return result;
1583f6603c60Sopenharmony_ci}
1584f6603c60Sopenharmony_ci
1585f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowHandleOptNullptr(napi_env env, napi_callback_info info)
1586f6603c60Sopenharmony_ci{
1587f6603c60Sopenharmony_ci    napi_value result = nullptr;
1588f6603c60Sopenharmony_ci
1589f6603c60Sopenharmony_ci    int code = SET_BUFFER_GEOMETRY;
1590f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowHandleOpt(nullptr, code, 100, 100);
1591f6603c60Sopenharmony_ci    if (flag != CONSTANT_40001000) {
1592f6603c60Sopenharmony_ci        napi_create_int32(env, FAIL, &result);
1593f6603c60Sopenharmony_ci        return result;
1594f6603c60Sopenharmony_ci    }
1595f6603c60Sopenharmony_ci
1596f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1597f6603c60Sopenharmony_ci    return result;
1598f6603c60Sopenharmony_ci}
1599f6603c60Sopenharmony_ci
1600f6603c60Sopenharmony_ci
1601f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowHandleOptSetGetBufferGeometryNormal(napi_env env, napi_callback_info info)
1602f6603c60Sopenharmony_ci{
1603f6603c60Sopenharmony_ci    napi_value result = nullptr;
1604f6603c60Sopenharmony_ci
1605f6603c60Sopenharmony_ci    struct result result1 = InitNativeWindow();
1606f6603c60Sopenharmony_ci    OH_NativeImage *image = result1.image;
1607f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = result1.nativeWindow;
1608f6603c60Sopenharmony_ci
1609f6603c60Sopenharmony_ci    int arr[][2] = {{0, 0},        {2147483647, 2147483647},   {100, 100}, {-1000, -1000}, {-1000, 1000},
1610f6603c60Sopenharmony_ci                    {1000, -1000}, {-2147483647, -2147483647}, {-1, -1}};
1611f6603c60Sopenharmony_ci    int width1, height1;
1612f6603c60Sopenharmony_ci    auto ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_BUFFER_GEOMETRY, &width1, &height1);
1613f6603c60Sopenharmony_ci    if (ret != 0) {
1614f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1, &result);
1615f6603c60Sopenharmony_ci        return result;
1616f6603c60Sopenharmony_ci    }
1617f6603c60Sopenharmony_ci
1618f6603c60Sopenharmony_ci    for (int i = 0; i < sizeof(arr) / sizeof(int[2]); ++i) {
1619f6603c60Sopenharmony_ci        int width = arr[i][0];
1620f6603c60Sopenharmony_ci        int height = arr[i][1];
1621f6603c60Sopenharmony_ci        auto flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_BUFFER_GEOMETRY, width, height);
1622f6603c60Sopenharmony_ci        if (flag != 0) {
1623f6603c60Sopenharmony_ci            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_1, &result);
1624f6603c60Sopenharmony_ci            return result;
1625f6603c60Sopenharmony_ci        }
1626f6603c60Sopenharmony_ci        int width2, height2;
1627f6603c60Sopenharmony_ci        flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_BUFFER_GEOMETRY, &height2, &width2);
1628f6603c60Sopenharmony_ci        if (flag != 0) {
1629f6603c60Sopenharmony_ci            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_2, &result);
1630f6603c60Sopenharmony_ci            return result;
1631f6603c60Sopenharmony_ci        }
1632f6603c60Sopenharmony_ci        if (width != width2 || height != height2) {
1633f6603c60Sopenharmony_ci            napi_create_int32(env, (i + 1) * CONSTANT_1000 + CONSTANT_3, &result);
1634f6603c60Sopenharmony_ci            return result;
1635f6603c60Sopenharmony_ci        }
1636f6603c60Sopenharmony_ci    }
1637f6603c60Sopenharmony_ci
1638f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image, nativeWindow);
1639f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1640f6603c60Sopenharmony_ci    return result;
1641f6603c60Sopenharmony_ci}
1642f6603c60Sopenharmony_ci
1643f6603c60Sopenharmony_cinapi_value testNativeWindowNativeWindowHandleOptSetGetBufferGeometryAbnormal(napi_env env, napi_callback_info info)
1644f6603c60Sopenharmony_ci{
1645f6603c60Sopenharmony_ci    napi_value result = nullptr;
1646f6603c60Sopenharmony_ci    OH_NativeImage *image1 = InitNativeWindow().image;
1647f6603c60Sopenharmony_ci    OHNativeWindow *nativeWindow = InitNativeWindow().nativeWindow;
1648f6603c60Sopenharmony_ci
1649f6603c60Sopenharmony_ci    int32_t width, height;
1650f6603c60Sopenharmony_ci
1651f6603c60Sopenharmony_ci    // 1.
1652f6603c60Sopenharmony_ci    auto flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_BUFFER_GEOMETRY, NULL, NULL);
1653f6603c60Sopenharmony_ci    if (flag != 0) { // 应为 非0
1654f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1000 + CONSTANT_1, &result);
1655f6603c60Sopenharmony_ci        return result;
1656f6603c60Sopenharmony_ci    }
1657f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_BUFFER_GEOMETRY, &height, &width);
1658f6603c60Sopenharmony_ci    if (flag != 0) { // 应为 成功
1659f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1000 + CONSTANT_2, &result);
1660f6603c60Sopenharmony_ci        return result;
1661f6603c60Sopenharmony_ci    }
1662f6603c60Sopenharmony_ci    if (width != 0 || height != 0) {
1663f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_1000 + CONSTANT_3, &result);
1664f6603c60Sopenharmony_ci        return result;
1665f6603c60Sopenharmony_ci    }
1666f6603c60Sopenharmony_ci    // 2.2147483648
1667f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_BUFFER_GEOMETRY, CONSTANT_9999999999999999999,
1668f6603c60Sopenharmony_ci                                                 CONSTANT_9999999999999999999);
1669f6603c60Sopenharmony_ci    if (flag != 0) { // 应为 非0
1670f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_1, &result);
1671f6603c60Sopenharmony_ci        return result;
1672f6603c60Sopenharmony_ci    }
1673f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, GET_BUFFER_GEOMETRY, &height, &width);
1674f6603c60Sopenharmony_ci    if (flag != 0) { // 应为 成功
1675f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_2, &result);
1676f6603c60Sopenharmony_ci        return result;
1677f6603c60Sopenharmony_ci    }
1678f6603c60Sopenharmony_ci    // 3.
1679f6603c60Sopenharmony_ci    flag = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_BUFFER_GEOMETRY, "abc", "abc");
1680f6603c60Sopenharmony_ci    if (flag != 0) { // 应为 失败
1681f6603c60Sopenharmony_ci        napi_create_int32(env, CONSTANT_2 * CONSTANT_1000 + CONSTANT_3, &result);
1682f6603c60Sopenharmony_ci        return result;
1683f6603c60Sopenharmony_ci    }
1684f6603c60Sopenharmony_ci
1685f6603c60Sopenharmony_ci    DestroyNativeWindowImage(image1, nativeWindow);
1686f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1687f6603c60Sopenharmony_ci    return result;
1688f6603c60Sopenharmony_ci}
1689