1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#include <gtest/gtest.h>
16#include "iconsumer_surface.h"
17#include <iservice_registry.h>
18#include <native_window.h>
19#include <securec.h>
20#include <ctime>
21#include "buffer_log.h"
22#include "external_window.h"
23#include "surface_utils.h"
24#include "sync_fence.h"
25#include "ipc_cparcel.h"
26#include "graphic_error_code.h"
27
28using namespace std;
29using namespace testing;
30using namespace testing::ext;
31
32namespace OHOS::Rosen {
33class BufferConsumerListener : public IBufferConsumerListener {
34public:
35    void OnBufferAvailable() override
36    {
37    }
38};
39
40static OHExtDataHandle *AllocOHExtDataHandle(uint32_t reserveInts)
41{
42    size_t handleSize = sizeof(OHExtDataHandle) + (sizeof(int32_t) * reserveInts);
43    OHExtDataHandle *handle = static_cast<OHExtDataHandle *>(malloc(handleSize));
44    if (handle == nullptr) {
45        BLOGE("AllocOHExtDataHandle malloc %zu failed", handleSize);
46        return nullptr;
47    }
48    auto ret = memset_s(handle, handleSize, 0, handleSize);
49    if (ret != EOK) {
50        BLOGE("AllocOHExtDataHandle memset_s failed");
51        return nullptr;
52    }
53    handle->fd = -1;
54    handle->reserveInts = reserveInts;
55    for (uint32_t i = 0; i < reserveInts; i++) {
56        handle->reserve[i] = -1;
57    }
58    return handle;
59}
60
61static void FreeOHExtDataHandle(OHExtDataHandle *handle)
62{
63    if (handle == nullptr) {
64        BLOGW("FreeOHExtDataHandle with nullptr handle");
65        return ;
66    }
67    if (handle->fd >= 0) {
68        close(handle->fd);
69        handle->fd = -1;
70    }
71    free(handle);
72}
73
74class NativeWindowTest : public testing::Test {
75public:
76    static void SetUpTestCase();
77    static void TearDownTestCase();
78
79    static inline BufferRequestConfig requestConfig = {};
80    static inline BufferFlushConfig flushConfig = {};
81    static inline sptr<OHOS::IConsumerSurface> cSurface = nullptr;
82    static inline sptr<OHOS::IBufferProducer> producer = nullptr;
83    static inline sptr<OHOS::Surface> pSurface = nullptr;
84    static inline sptr<OHOS::SurfaceBuffer> sBuffer = nullptr;
85    static inline NativeWindow* nativeWindow = nullptr;
86    static inline NativeWindowBuffer* nativeWindowBuffer = nullptr;
87};
88
89void NativeWindowTest::SetUpTestCase()
90{
91    requestConfig = {
92        .width = 0x100,  // small
93        .height = 0x100, // small
94        .strideAlignment = 0x8,
95        .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
96        .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
97        .timeout = 0,
98    };
99
100    cSurface = IConsumerSurface::Create();
101    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
102    cSurface->RegisterConsumerListener(listener);
103    producer = cSurface->GetProducer();
104    pSurface = Surface::CreateSurfaceAsProducer(producer);
105    int32_t fence;
106    pSurface->RequestBuffer(sBuffer, fence, requestConfig);
107}
108
109void NativeWindowTest::TearDownTestCase()
110{
111    flushConfig = { .damage = {
112        .w = 0x100,
113        .h = 0x100,
114    } };
115    pSurface->FlushBuffer(sBuffer, -1, flushConfig);
116    sBuffer = nullptr;
117    cSurface = nullptr;
118    producer = nullptr;
119    pSurface = nullptr;
120    OH_NativeWindow_DestroyNativeWindow(nativeWindow);
121    nativeWindow = nullptr;
122    nativeWindowBuffer = nullptr;
123}
124
125/*
126 * @tc.name  CreateNativeWindow001
127 * @tc.desc  call call OH_NativeWindow_CreateNativeWindow by abnormal input
128 * @tc.size  : MediumTest
129 * @tc.type  : Function
130 * @tc.level : Level 2
131 */
132HWTEST_F(NativeWindowTest, CreateNativeWindow001, Function | MediumTest | Level2)
133{
134    ASSERT_EQ(OH_NativeWindow_CreateNativeWindow(nullptr), nullptr);
135}
136
137/*
138 * @tc.name  CreateNativeWindow002
139 * @tc.desc  call OH_NativeWindow_CreateNativeWindow
140 * @tc.size  : MediumTest
141 * @tc.type  : Function
142 * @tc.level : Level 2
143 */
144HWTEST_F(NativeWindowTest, CreateNativeWindow002, Function | MediumTest | Level2)
145{
146    nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
147    ASSERT_NE(nativeWindow, nullptr);
148}
149
150/*
151 * @tc.name  CreateNativeWindow003
152 * @tc.desc  call OH_NativeWindow_CreateNativeWindow
153 * @tc.size  : MediumTest
154 * @tc.type  : Function
155 * @tc.level : Level 2
156 */
157HWTEST_F(NativeWindowTest, CreateNativeWindow003, Function | MediumTest | Level2)
158{
159    uint64_t surfaceId = 0;
160    int32_t ret = OH_NativeWindow_GetSurfaceId(nativeWindow, &surfaceId);
161    ASSERT_EQ(ret, NATIVE_ERROR_OK);
162    ASSERT_EQ(surfaceId, pSurface->GetUniqueId());
163}
164
165/*
166 * @tc.name  CreateNativeWindowFromSurfaceId001
167 * @tc.desc  call OH_NativeWindow_CreateNativeWindowFromSurfaceId
168 * @tc.size  : MediumTest
169 * @tc.type  : Function
170 * @tc.level : Level 2
171 */
172HWTEST_F(NativeWindowTest, CreateNativeWindowFromSurfaceId001, Function | MediumTest | Level2)
173{
174    uint64_t surfaceId = static_cast<uint64_t>(pSurface->GetUniqueId());
175    OHNativeWindow *window = nullptr;
176    int32_t ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, &window);
177    ASSERT_EQ(ret, NATIVE_ERROR_OK);
178    surfaceId = 0;
179    ret = OH_NativeWindow_GetSurfaceId(window, &surfaceId);
180    ASSERT_EQ(ret, NATIVE_ERROR_OK);
181    ASSERT_EQ(surfaceId, pSurface->GetUniqueId());
182    OH_NativeWindow_DestroyNativeWindow(window);
183}
184
185/*
186 * @tc.name  CreateNativeWindowFromSurfaceId002
187 * @tc.desc  call OH_NativeWindow_CreateNativeWindowFromSurfaceId
188 * @tc.size  : MediumTest
189 * @tc.type  : Function
190 * @tc.level : Level 2
191 */
192HWTEST_F(NativeWindowTest, CreateNativeWindowFromSurfaceId002, Function | MediumTest | Level2)
193{
194    int32_t ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(0, nullptr);
195    ASSERT_EQ(ret, NATIVE_ERROR_INVALID_ARGUMENTS);
196    ret = OH_NativeWindow_GetSurfaceId(nullptr, nullptr);
197    ASSERT_EQ(ret, NATIVE_ERROR_INVALID_ARGUMENTS);
198}
199
200/*
201 * @tc.name  CreateNativeWindowFromSurfaceId003
202 * @tc.desc  call OH_NativeWindow_CreateNativeWindowFromSurfaceId
203 * @tc.size  : MediumTest
204 * @tc.type  : Function
205 * @tc.level : Level 2
206 */
207HWTEST_F(NativeWindowTest, CreateNativeWindowFromSurfaceId003, Function | MediumTest | Level2)
208{
209    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
210    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
211    cSurfaceTmp->RegisterConsumerListener(listener);
212    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
213    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
214
215    uint64_t surfaceId = static_cast<uint64_t>(pSurfaceTmp->GetUniqueId());
216    auto utils = SurfaceUtils::GetInstance();
217    utils->Add(surfaceId, pSurfaceTmp);
218    OHNativeWindow *nativeWindowTmp = nullptr;
219    int32_t ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(0xFFFFFFFF, &nativeWindowTmp);
220    ASSERT_EQ(ret, NATIVE_ERROR_INVALID_ARGUMENTS);
221    ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, &nativeWindowTmp);
222    ASSERT_EQ(ret, NATIVE_ERROR_OK);
223    surfaceId = 0;
224    ret = OH_NativeWindow_GetSurfaceId(nativeWindowTmp, &surfaceId);
225    ASSERT_EQ(ret, NATIVE_ERROR_OK);
226    ASSERT_EQ(surfaceId, pSurfaceTmp->GetUniqueId());
227
228    cSurfaceTmp = nullptr;
229    producerTmp = nullptr;
230    pSurfaceTmp = nullptr;
231    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
232}
233
234/*
235 * @tc.name  HandleOpt001
236 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by abnormal input
237 * @tc.size  : MediumTest
238 * @tc.type  : Function
239 * @tc.level : Level 2
240 */
241HWTEST_F(NativeWindowTest, HandleOpt001, Function | MediumTest | Level2)
242{
243    int code = SET_USAGE;
244    uint64_t usage = BUFFER_USAGE_CPU_READ;
245    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nullptr, code, usage), NATIVE_ERROR_INVALID_ARGUMENTS);
246}
247
248/*
249 * @tc.name  HandleOpt002
250 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
251 * @tc.size  : MediumTest
252 * @tc.type  : Function
253 * @tc.level : Level 2
254 */
255HWTEST_F(NativeWindowTest, HandleOpt002, Function | MediumTest | Level2)
256{
257    int code = SET_USAGE;
258    uint64_t usageSet = BUFFER_USAGE_CPU_READ;
259    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), NATIVE_ERROR_OK);
260
261    code = GET_USAGE;
262    uint64_t usageGet = BUFFER_USAGE_CPU_WRITE;
263    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &usageGet), NATIVE_ERROR_OK);
264    ASSERT_EQ(usageSet, usageGet);
265}
266
267/*
268 * @tc.name  HandleOpt003
269 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
270 * @tc.size  : MediumTest
271 * @tc.type  : Function
272 * @tc.level : Level 2
273 */
274HWTEST_F(NativeWindowTest, HandleOpt003, Function | MediumTest | Level2)
275{
276    int code = SET_BUFFER_GEOMETRY;
277    int32_t heightSet = 0x100;
278    int32_t widthSet = 0x100;
279    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, heightSet, widthSet), NATIVE_ERROR_OK);
280
281    code = GET_BUFFER_GEOMETRY;
282    int32_t heightGet = 0;
283    int32_t widthGet = 0;
284    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &heightGet, &widthGet), NATIVE_ERROR_OK);
285    ASSERT_EQ(heightSet, heightGet);
286    ASSERT_EQ(widthSet, widthGet);
287}
288
289/*
290 * @tc.name  HandleOpt004
291 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
292 * @tc.size  : MediumTest
293 * @tc.type  : Function
294 * @tc.level : Level 2
295 */
296HWTEST_F(NativeWindowTest, HandleOpt004, Function | MediumTest | Level2)
297{
298    int code = SET_FORMAT;
299    int32_t formatSet = GRAPHIC_PIXEL_FMT_RGBA_8888;
300    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), NATIVE_ERROR_OK);
301
302    code = GET_FORMAT;
303    int32_t formatGet = GRAPHIC_PIXEL_FMT_CLUT8;
304    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &formatGet), NATIVE_ERROR_OK);
305    ASSERT_EQ(formatSet, formatGet);
306}
307
308/*
309 * @tc.name  HandleOpt005
310 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
311 * @tc.size  : MediumTest
312 * @tc.type  : Function
313 * @tc.level : Level 2
314 */
315HWTEST_F(NativeWindowTest, HandleOpt005, Function | MediumTest | Level2)
316{
317    int code = SET_STRIDE;
318    int32_t strideSet = 0x8;
319    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, strideSet), NATIVE_ERROR_OK);
320
321    code = GET_STRIDE;
322    int32_t strideGet = 0;
323    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &strideGet), NATIVE_ERROR_OK);
324    ASSERT_EQ(strideSet, strideGet);
325}
326
327/*
328 * @tc.name  HandleOpt006
329 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
330 * @tc.size  : MediumTest
331 * @tc.type  : Function
332 * @tc.level : Level 2
333 */
334HWTEST_F(NativeWindowTest, HandleOpt006, Function | MediumTest | Level2)
335{
336    int code = SET_COLOR_GAMUT;
337    int32_t colorGamutSet = static_cast<int32_t>(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
338    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, colorGamutSet), NATIVE_ERROR_OK);
339
340    code = GET_COLOR_GAMUT;
341    int32_t colorGamutGet = 0;
342    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &colorGamutGet), NATIVE_ERROR_OK);
343    ASSERT_EQ(colorGamutSet, colorGamutGet);
344}
345
346/*
347 * @tc.name  HandleOpt007
348 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
349 * @tc.size  : MediumTest
350 * @tc.type  : Function
351 * @tc.level : Level 2
352 */
353HWTEST_F(NativeWindowTest, HandleOpt007, Function | MediumTest | Level2)
354{
355    int code = SET_TIMEOUT;
356    int32_t timeoutSet = 10;
357    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, timeoutSet), NATIVE_ERROR_OK);
358
359    code = GET_TIMEOUT;
360    int32_t timeoutGet = 0;
361    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &timeoutGet), NATIVE_ERROR_OK);
362    ASSERT_EQ(timeoutSet, timeoutGet);
363}
364
365/*
366 * @tc.name  HandleOpt008
367 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
368 * @tc.size  : MediumTest
369 * @tc.type  : Function
370 * @tc.level : Level 2
371 */
372HWTEST_F(NativeWindowTest, HandleOpt008, Function | MediumTest | Level1)
373{
374    int code = GET_TRANSFORM;
375    int32_t transform = 0;
376    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &transform), NATIVE_ERROR_OK);
377    transform = GraphicTransformType::GRAPHIC_ROTATE_90;
378    code = SET_TRANSFORM;
379    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, transform), NATIVE_ERROR_OK);
380    int32_t transformTmp = 0;
381    code = GET_TRANSFORM;
382    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &transformTmp), NATIVE_ERROR_OK);
383    ASSERT_EQ(transformTmp, GraphicTransformType::GRAPHIC_ROTATE_90);
384    nativeWindow->surface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_180);
385    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &transformTmp), NATIVE_ERROR_OK);
386    ASSERT_EQ(transformTmp, GraphicTransformType::GRAPHIC_ROTATE_180);
387}
388
389/*
390 * @tc.name  HandleOpt009
391 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
392 * @tc.size  : MediumTest
393 * @tc.type  : Function
394 * @tc.level : Level 2
395 */
396HWTEST_F(NativeWindowTest, HandleOpt009, Function | MediumTest | Level1)
397{
398    int code = GET_BUFFERQUEUE_SIZE;
399    int32_t queueSize = 0;
400    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &queueSize), NATIVE_ERROR_OK);
401    ASSERT_EQ(queueSize, 3);
402    nativeWindow->surface->SetQueueSize(5);
403    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &queueSize), NATIVE_ERROR_OK);
404    ASSERT_EQ(queueSize, 5);
405}
406/*
407 * @tc.name  HandleOpt010
408 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
409 * @tc.size  : MediumTest
410 * @tc.type  : Function
411 * @tc.level : Level 2
412 */
413HWTEST_F(NativeWindowTest, HandleOpt010, Function | MediumTest | Level2)
414{
415    int code = SET_USAGE;
416    uint64_t usageSet = NATIVEBUFFER_USAGE_HW_RENDER | NATIVEBUFFER_USAGE_HW_TEXTURE |
417    NATIVEBUFFER_USAGE_CPU_READ_OFTEN | NATIVEBUFFER_USAGE_ALIGNMENT_512;
418    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), NATIVE_ERROR_OK);
419
420    code = GET_USAGE;
421    uint64_t usageGet = usageSet;
422    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &usageGet), NATIVE_ERROR_OK);
423    ASSERT_EQ(usageSet, usageGet);
424
425    code = SET_FORMAT;
426    int32_t formatSet = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010;
427    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), NATIVE_ERROR_OK);
428
429    code = GET_FORMAT;
430    int32_t formatGet = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010;
431    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &formatGet), NATIVE_ERROR_OK);
432    ASSERT_EQ(formatSet, formatGet);
433}
434/*
435 * @tc.name  HandleOpt011
436 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
437 * @tc.size  : MediumTest
438 * @tc.type  : Function
439 * @tc.level : Level 1
440 */
441HWTEST_F(NativeWindowTest, HandleOpt011, Function | MediumTest | Level1)
442{
443    int code = SET_SOURCE_TYPE;
444    OHSurfaceSource typeSet = OHSurfaceSource::OH_SURFACE_SOURCE_GAME;
445    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, typeSet), NATIVE_ERROR_OK);
446
447    code = GET_SOURCE_TYPE;
448    OHSurfaceSource typeGet = OHSurfaceSource::OH_SURFACE_SOURCE_DEFAULT;
449    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &typeGet), NATIVE_ERROR_OK);
450    ASSERT_EQ(typeSet, typeGet);
451}
452/*
453 * @tc.name  HandleOpt012
454 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
455 * @tc.size  : MediumTest
456 * @tc.type  : Function
457 * @tc.level : Level 1
458 */
459HWTEST_F(NativeWindowTest, HandleOpt012, Function | MediumTest | Level1)
460{
461    int code = SET_APP_FRAMEWORK_TYPE;
462    const char* typeSet = "test";
463    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, typeSet), NATIVE_ERROR_OK);
464
465    code = GET_APP_FRAMEWORK_TYPE;
466    const char* typeGet;
467    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &typeGet), NATIVE_ERROR_OK);
468    ASSERT_EQ(0, strcmp(typeSet, typeGet));
469}
470/*
471 * @tc.name  HandleOpt013
472 * @tc.desc  call OH_NativeWindow_NativeWindowHandleOpt by different param
473 * @tc.size  : MediumTest
474 * @tc.type  : Function
475 * @tc.level : Level 1
476 */
477HWTEST_F(NativeWindowTest, HandleOpt013, Function | MediumTest | Level1)
478{
479    int code = SET_HDR_WHITE_POINT_BRIGHTNESS;
480    float brightness = 0.8;
481    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), NATIVE_ERROR_OK);
482
483    code = SET_SDR_WHITE_POINT_BRIGHTNESS;
484    brightness = 0.5;
485    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), NATIVE_ERROR_OK);
486
487    ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.8) < 1e-6, true);
488    ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.5) < 1e-6, true);
489
490    code = SET_HDR_WHITE_POINT_BRIGHTNESS;
491    brightness = 1.8;
492    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), NATIVE_ERROR_OK);
493    ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.8) < 1e-6, true);
494    brightness = -0.5;
495    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), NATIVE_ERROR_OK);
496    ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.8) < 1e-6, true);
497    brightness = 0.5;
498    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), NATIVE_ERROR_OK);
499    ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.5) < 1e-6, true);
500
501    code = SET_SDR_WHITE_POINT_BRIGHTNESS;
502    brightness = 1.5;
503    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), NATIVE_ERROR_OK);
504    ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.5) < 1e-6, true);
505    brightness = -0.1;
506    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), NATIVE_ERROR_OK);
507    ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.5) < 1e-6, true);
508    brightness = 0.8;
509    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), NATIVE_ERROR_OK);
510    ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.8) < 1e-6, true);
511}
512/*
513 * @tc.name  NativeWindowAttachBuffer001
514 * @tc.desc  call OH_NativeWindow_NativeWindowAttachBuffer by abnormal input
515 * @tc.size  : MediumTest
516 * @tc.type  : Function
517 * @tc.level : Level 2
518 */
519HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer001, Function | MediumTest | Level1)
520{
521    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nullptr, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
522    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nullptr, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
523}
524
525void SetNativeWindowConfig(NativeWindow *nativeWindow)
526{
527    int code = SET_USAGE;
528    uint64_t usageSet = BUFFER_USAGE_CPU_READ;
529    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), NATIVE_ERROR_OK);
530
531    code = SET_BUFFER_GEOMETRY;
532    int32_t heightSet = 0x100;
533    int32_t widthSet = 0x100;
534    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, heightSet, widthSet), NATIVE_ERROR_OK);
535
536    code = SET_FORMAT;
537    int32_t formatSet = GRAPHIC_PIXEL_FMT_RGBA_8888;
538    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), NATIVE_ERROR_OK);
539
540    code = SET_STRIDE;
541    int32_t strideSet = 0x8;
542    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, strideSet), NATIVE_ERROR_OK);
543
544    code = SET_COLOR_GAMUT;
545    int32_t colorGamutSet = static_cast<int32_t>(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
546    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, colorGamutSet), NATIVE_ERROR_OK);
547
548    code = SET_TIMEOUT;
549    int32_t timeoutSet = 10;  // 10: for test
550    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, timeoutSet), NATIVE_ERROR_OK);
551}
552
553/*
554 * @tc.name  NativeWindowAttachBuffer002
555 * @tc.desc  call OH_NativeWindow_NativeWindowAttachBuffer by normal input
556 * @tc.size  : MediumTest
557 * @tc.type  : Function
558 * @tc.level : Level 2
559 */
560HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer002, Function | MediumTest | Level1)
561{
562    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
563    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
564    cSurfaceTmp->RegisterConsumerListener(listener);
565    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
566    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
567
568    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
569    ASSERT_NE(nativeWindowTmp, nullptr);
570    SetNativeWindowConfig(nativeWindowTmp);
571
572    NativeWindowBuffer *nativeWindowBuffer = nullptr;
573    int fenceFd = -1;
574    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer, &fenceFd);
575    ASSERT_EQ(ret, NATIVE_ERROR_OK);
576
577    int code = GET_BUFFERQUEUE_SIZE;
578    int32_t queueSize = 0;
579    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), NATIVE_ERROR_OK);
580    ASSERT_EQ(queueSize, 3);
581
582    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer), NATIVE_ERROR_OK);
583
584    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nativeWindowBuffer), NATIVE_ERROR_OK);
585
586    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer), NATIVE_ERROR_OK);
587
588    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp, nativeWindowBuffer), NATIVE_ERROR_OK);
589    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), NATIVE_ERROR_OK);
590    ASSERT_EQ(queueSize, 3);
591    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp, nativeWindowBuffer), NATIVE_ERROR_BUFFER_IN_CACHE);
592
593    struct Region *region = new Region();
594    struct Region::Rect *rect = new Region::Rect();
595    rect->x = 0x100;
596    rect->y = 0x100;
597    rect->w = 0x100;
598    rect->h = 0x100;
599    region->rects = rect;
600    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindowTmp, nativeWindowBuffer, fenceFd, *region);
601    ASSERT_EQ(ret, NATIVE_ERROR_OK);
602
603    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
604}
605
606void NativeWindowAttachBuffer003Test(NativeWindow *nativeWindowTmp, NativeWindow *nativeWindowTmp1)
607{
608    NativeWindowBuffer *nativeWindowBuffer1 = nullptr;
609    int fenceFd = -1;
610    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer1, &fenceFd);
611    ASSERT_EQ(ret, NATIVE_ERROR_OK);
612
613    NativeWindowBuffer *nativeWindowBuffer2 = nullptr;
614    fenceFd = -1;
615    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer2, &fenceFd);
616    ASSERT_EQ(ret, NATIVE_ERROR_OK);
617
618    NativeWindowBuffer *nativeWindowBuffer3 = nullptr;
619    fenceFd = -1;
620    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer3, &fenceFd);
621    ASSERT_EQ(ret, NATIVE_ERROR_OK);
622
623    int code = GET_BUFFERQUEUE_SIZE;
624    int32_t queueSize = 0;
625    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), NATIVE_ERROR_OK);
626    ASSERT_EQ(queueSize, 3);    // 3 : check num
627
628    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer1), NATIVE_ERROR_OK);
629    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer2), NATIVE_ERROR_OK);
630    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer3), NATIVE_ERROR_OK);
631
632    NativeWindowBuffer *nativeWindowBuffer4 = nullptr;
633    fenceFd = -1;
634    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer4, &fenceFd);
635    ASSERT_EQ(ret, NATIVE_ERROR_OK);
636
637    NativeWindowBuffer *nativeWindowBuffer10 = nullptr;
638    fenceFd = -1;
639    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp1, &nativeWindowBuffer10, &fenceFd);
640    ASSERT_EQ(ret, NATIVE_ERROR_OK);
641
642    NativeWindowBuffer *nativeWindowBuffer11 = nullptr;
643    fenceFd = -1;
644    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp1, &nativeWindowBuffer11, &fenceFd);
645    ASSERT_EQ(ret, NATIVE_ERROR_OK);
646
647    NativeWindowBuffer *nativeWindowBuffer12 = nullptr;
648    fenceFd = -1;
649    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp1, &nativeWindowBuffer12, &fenceFd);
650    ASSERT_EQ(ret, NATIVE_ERROR_OK);
651
652    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp1, nativeWindowBuffer1),
653        NATIVE_ERROR_BUFFER_QUEUE_FULL);
654}
655
656/*
657* Function: OH_NativeWindow_NativeWindowAttachBuffer
658* Type: Function
659* Rank: Important(2)
660* EnvConditions: N/A
661* CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
662*                  2. check ret
663 */
664HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer003, Function | MediumTest | Level1)
665{
666    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
667    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
668    cSurfaceTmp->RegisterConsumerListener(listener);
669    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
670    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
671
672    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
673    ASSERT_NE(nativeWindowTmp, nullptr);
674    SetNativeWindowConfig(nativeWindowTmp);
675
676    sptr<OHOS::IConsumerSurface> cSurfaceTmp1 = IConsumerSurface::Create();
677    sptr<IBufferConsumerListener> listener1 = new BufferConsumerListener();
678    cSurfaceTmp1->RegisterConsumerListener(listener1);
679    sptr<OHOS::IBufferProducer> producerTmp1 = cSurfaceTmp1->GetProducer();
680    sptr<OHOS::Surface> pSurfaceTmp1 = Surface::CreateSurfaceAsProducer(producerTmp1);
681
682    NativeWindow *nativeWindowTmp1 = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp1);
683    ASSERT_NE(nativeWindowTmp1, nullptr);
684    SetNativeWindowConfig(nativeWindowTmp1);
685
686    NativeWindowAttachBuffer003Test(nativeWindowTmp, nativeWindowTmp1);
687
688    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
689    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp1);
690}
691
692/*
693 * @tc.name  NativeWindowAttachBuffer004
694 * @tc.desc  call OH_NativeWindow_NativeWindowAttachBuffer by normal input
695 * @tc.size  : MediumTest
696 * @tc.type  : Function
697 * @tc.level : Level 2
698 */
699HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer004, Function | MediumTest | Level1)
700{
701    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
702    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
703    cSurfaceTmp->RegisterConsumerListener(listener);
704    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
705    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
706
707    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
708    ASSERT_NE(nativeWindowTmp, nullptr);
709    SetNativeWindowConfig(nativeWindowTmp);
710
711    NativeWindowBuffer *nativeWindowBuffer = nullptr;
712    int fenceFd = -1;
713    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer, &fenceFd);
714    ASSERT_EQ(ret, NATIVE_ERROR_OK);
715
716    struct Region *region = new Region();
717    struct Region::Rect *rect = new Region::Rect();
718    rect->x = 0x100;
719    rect->y = 0x100;
720    rect->w = 0x100;
721    rect->h = 0x100;
722    region->rects = rect;
723    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindowTmp, nativeWindowBuffer, fenceFd, *region);
724    ASSERT_EQ(ret, NATIVE_ERROR_OK);
725
726    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer),
727        NATIVE_ERROR_BUFFER_STATE_INVALID);
728
729    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer),
730        NATIVE_ERROR_BUFFER_NOT_IN_CACHE);
731
732    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
733}
734
735/*
736 * @tc.name  NativeWindowAttachBuffer005
737 * @tc.desc  call OH_NativeWindow_NativeWindowAttachBuffer by normal input
738 * @tc.size  : MediumTest
739 * @tc.type  : Function
740 * @tc.level : Level 2
741 */
742HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer005, Function | MediumTest | Level1)
743{
744    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
745    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
746    cSurfaceTmp->RegisterConsumerListener(listener);
747    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
748    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
749
750    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
751    ASSERT_NE(nativeWindowTmp, nullptr);
752    SetNativeWindowConfig(nativeWindowTmp);
753
754    NativeWindowBuffer *nativeWindowBuffer = nullptr;
755    int fenceFd = -1;
756    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer, &fenceFd);
757    ASSERT_EQ(ret, NATIVE_ERROR_OK);
758
759    ASSERT_EQ(cSurface->AttachBufferToQueue(nativeWindowBuffer->sfbuffer), GSERROR_OK);
760
761    ASSERT_EQ(cSurface->DetachBufferFromQueue(nativeWindowBuffer->sfbuffer), GSERROR_OK);
762
763    ASSERT_EQ(cSurface->AttachBufferToQueue(nativeWindowBuffer->sfbuffer), GSERROR_OK);
764
765    sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
766    ASSERT_EQ(cSurface->ReleaseBuffer(nativeWindowBuffer->sfbuffer, fence), GSERROR_OK);
767
768    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
769}
770/*
771 * @tc.name  NativeWindowAttachBuffer006
772 * @tc.desc  call OH_NativeWindow_NativeWindowAttachBuffer by normal input
773 * @tc.size  : MediumTest
774 * @tc.type  : Function
775 * @tc.level : Level 2
776 */
777HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer006, Function | MediumTest | Level1)
778{
779    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
780    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
781    cSurfaceTmp->RegisterConsumerListener(listener);
782    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
783    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
784
785    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
786    ASSERT_NE(nativeWindowTmp, nullptr);
787    SetNativeWindowConfig(nativeWindowTmp);
788
789    NativeWindowBuffer *nativeWindowBuffer1 = nullptr;
790    int fenceFd = -1;
791    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer1, &fenceFd);
792    ASSERT_EQ(ret, NATIVE_ERROR_OK);
793
794    int code = GET_BUFFERQUEUE_SIZE;
795    int32_t queueSize = 0;
796    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), NATIVE_ERROR_OK);
797    ASSERT_EQ(queueSize, 3);
798    clock_t startTime, endTime;
799    startTime = clock();
800    for (int32_t i = 0; i < 1000; i++) {
801        ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer1), NATIVE_ERROR_OK);
802        ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp, nativeWindowBuffer1), NATIVE_ERROR_OK);
803    }
804    endTime = clock();
805    cout << "DetachBuffer and AttachBuffer 1000 times cost time: " << (endTime - startTime) << "ms" << endl;
806    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), NATIVE_ERROR_OK);
807    ASSERT_EQ(queueSize, 3);
808    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
809}
810
811/*
812 * @tc.name  CreateNativeWindowBuffer001
813 * @tc.desc  call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer by abnormal input
814 * @tc.size  : MediumTest
815 * @tc.type  : Function
816 * @tc.level : Level 2
817 */
818HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer001, Function | MediumTest | Level2)
819{
820    ASSERT_EQ(OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(nullptr), nullptr);
821}
822
823/*
824 * @tc.name  CreateNativeWindowBuffer002
825 * @tc.desc  call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
826 * @tc.size  : MediumTest
827 * @tc.type  : Function
828 * @tc.level : Level 2
829 */
830HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer002, Function | MediumTest | Level2)
831{
832    nativeWindowBuffer = OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(&sBuffer);
833    ASSERT_NE(nativeWindowBuffer, nullptr);
834}
835
836/*
837 * @tc.name  CreateNativeWindowBuffer003
838 * @tc.desc  call OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
839 * @tc.size  : MediumTest
840 * @tc.type  : Function
841 * @tc.level : Level 2
842*/
843HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer003, Function | MediumTest | Level2)
844{
845    OH_NativeBuffer* nativeBuffer = sBuffer->SurfaceBufferToNativeBuffer();
846    ASSERT_NE(nativeBuffer, nullptr);
847    NativeWindowBuffer* nwBuffer = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nativeBuffer);
848    ASSERT_NE(nwBuffer, nullptr);
849    OH_NativeWindow_DestroyNativeWindowBuffer(nwBuffer);
850}
851
852/*
853 * @tc.name  RequestBuffer001
854 * @tc.desc  call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
855 * @tc.size  : MediumTest
856 * @tc.type  : Function
857 * @tc.level : Level 2
858 */
859HWTEST_F(NativeWindowTest, RequestBuffer001, Function | MediumTest | Level2)
860{
861    ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nullptr, &nativeWindowBuffer, nullptr),
862              NATIVE_ERROR_INVALID_ARGUMENTS);
863}
864
865/*
866 * @tc.name  RequestBuffer002
867 * @tc.desc  call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
868 * @tc.size  : MediumTest
869 * @tc.type  : Function
870 * @tc.level : Level 2
871 */
872HWTEST_F(NativeWindowTest, RequestBuffer002, Function | MediumTest | Level2)
873{
874    ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, nullptr, nullptr),
875              NATIVE_ERROR_INVALID_ARGUMENTS);
876}
877
878/*
879 * @tc.name  GetBufferHandle001
880 * @tc.desc  call OH_NativeWindow_GetBufferHandleFromNative by abnormal input
881 * @tc.size  : MediumTest
882 * @tc.type  : Function
883 * @tc.level : Level 2
884 */
885HWTEST_F(NativeWindowTest, GetBufferHandle001, Function | MediumTest | Level2)
886{
887    ASSERT_EQ(OH_NativeWindow_GetBufferHandleFromNative(nullptr), nullptr);
888}
889
890/*
891 * @tc.name  GetBufferHandle002
892 * @tc.desc  call OH_NativeWindow_GetBufferHandleFromNative
893 * @tc.size  : MediumTest
894 * @tc.type  : Function
895 * @tc.level : Level 2
896 */
897HWTEST_F(NativeWindowTest, GetBufferHandle002, Function | MediumTest | Level2)
898{
899    struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
900    buffer->sfbuffer = sBuffer;
901    ASSERT_NE(OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer), nullptr);
902    delete buffer;
903}
904
905/*
906 * @tc.name  FlushBuffer001
907 * @tc.desc  call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
908 * @tc.size  : MediumTest
909 * @tc.type  : Function
910 * @tc.level : Level 2
911 */
912HWTEST_F(NativeWindowTest, FlushBuffer001, Function | MediumTest | Level2)
913{
914    int fenceFd = -1;
915    struct Region *region = new Region();
916    struct Region::Rect * rect = new Region::Rect();
917    rect->x = 0x100;
918    rect->y = 0x100;
919    rect->w = 0x100;
920    rect->h = 0x100;
921    region->rects = rect;
922
923    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nullptr, nullptr, fenceFd, *region),
924              NATIVE_ERROR_INVALID_ARGUMENTS);
925    delete region;
926}
927
928/*
929 * @tc.name  FlushBuffer002
930 * @tc.desc  call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
931 * @tc.size  : MediumTest
932 * @tc.type  : Function
933 * @tc.level : Level 2
934 */
935HWTEST_F(NativeWindowTest, FlushBuffer002, Function | MediumTest | Level2)
936{
937    int fenceFd = -1;
938    struct Region *region = new Region();
939    struct Region::Rect * rect = new Region::Rect();
940    rect->x = 0x100;
941    rect->y = 0x100;
942    rect->w = 0x100;
943    rect->h = 0x100;
944    region->rects = rect;
945
946    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nullptr, fenceFd, *region),
947              NATIVE_ERROR_INVALID_ARGUMENTS);
948    delete region;
949}
950
951/*
952 * @tc.name  FlushBuffer003
953 * @tc.desc  call OH_NativeWindow_NativeWindowFlushBuffer
954 * @tc.size  : MediumTest
955 * @tc.type  : Function
956 * @tc.level : Level 2
957 */
958HWTEST_F(NativeWindowTest, FlushBuffer003, Function | MediumTest | Level2)
959{
960    int fenceFd = -1;
961    struct Region *region = new Region();
962    region->rectNumber = 0;
963    region->rects = nullptr;
964    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
965              NATIVE_ERROR_OK);
966
967    region->rectNumber = 1;
968    struct Region::Rect * rect = new Region::Rect();
969    rect->x = 0x100;
970    rect->y = 0x100;
971    rect->w = 0x100;
972    rect->h = 0x100;
973    region->rects = rect;
974    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
975              NATIVE_ERROR_BUFFER_STATE_INVALID);
976    delete rect;
977    delete region;
978}
979
980/*
981 * @tc.name  GetLastFlushedBuffer001
982 * @tc.desc  call OH_NativeWindow_NativeWindowRequestBuffer
983 * @tc.size  : MediumTest
984 * @tc.type  : Function
985 * @tc.level : Level 2
986 */
987HWTEST_F(NativeWindowTest, GetLastFlushedBuffer001, Function | MediumTest | Level2)
988{
989    int code = SET_TRANSFORM;
990    int32_t transform = GraphicTransformType::GRAPHIC_ROTATE_90;
991    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, transform), NATIVE_ERROR_OK);
992
993    code = SET_FORMAT;
994    int32_t format = GRAPHIC_PIXEL_FMT_RGBA_8888;
995    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, format), NATIVE_ERROR_OK);
996
997    NativeWindowBuffer *nativeWindowBuffer = nullptr;
998    int fenceFd = -1;
999    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1000    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1001
1002    struct Region *region = new Region();
1003    struct Region::Rect *rect = new Region::Rect();
1004    rect->x = 0x100;
1005    rect->y = 0x100;
1006    rect->w = 0x100;
1007    rect->h = 0x100;
1008    region->rects = rect;
1009    BufferHandle *bufferHanlde = OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer);
1010    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
1011    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1012    NativeWindowBuffer *lastFlushedBuffer;
1013    int lastFlushedFenceFd;
1014    float matrix[16];
1015    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
1016        NATIVE_ERROR_OK);
1017    BufferHandle *lastFlushedHanlde = OH_NativeWindow_GetBufferHandleFromNative(lastFlushedBuffer);
1018    ASSERT_EQ(bufferHanlde->virAddr, lastFlushedHanlde->virAddr);
1019
1020    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBufferV2(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
1021        NATIVE_ERROR_OK);
1022}
1023
1024/*
1025 * @tc.name  GetLastFlushedBuffer002
1026 * @tc.desc  call NativeWindowHandleOpt set BUFFER_USAGE_PROTECTED
1027 * @tc.size  : MediumTest
1028 * @tc.type  : Function
1029 * @tc.level : Level 2
1030 */
1031HWTEST_F(NativeWindowTest, GetLastFlushedBuffer002, Function | MediumTest | Level2)
1032{
1033    int code = SET_USAGE;
1034    uint64_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_PROTECTED;
1035    ASSERT_EQ(NativeWindowHandleOpt(nativeWindow, code, usage), NATIVE_ERROR_OK);
1036
1037    NativeWindowBuffer* nativeWindowBuffer = nullptr;
1038    int fenceFd = -1;
1039    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1040    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1041
1042    struct Region *region = new Region();
1043    struct Region::Rect *rect = new Region::Rect();
1044    rect->x = 0x100;
1045    rect->y = 0x100;
1046    rect->w = 0x100;
1047    rect->h = 0x100;
1048    region->rects = rect;
1049    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
1050    ASSERT_EQ(ret, NATIVE_ERROR_OK);
1051    NativeWindowBuffer* lastFlushedBuffer;
1052    int lastFlushedFenceFd;
1053    float matrix[16];
1054    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
1055        NATIVE_ERROR_UNSUPPORTED);
1056}
1057/*
1058 * @tc.name  OH_NativeWindow_SetColorSpace001
1059 * @tc.desc  call OH_NativeWindow_SetColorSpace
1060 * @tc.size  : MediumTest
1061 * @tc.type  : Function
1062 * @tc.level : Level 2
1063 */
1064HWTEST_F(NativeWindowTest, OH_NativeWindow_SetColorSpace001, Function | MediumTest | Level2)
1065{
1066    OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_NONE;
1067    auto ret = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace);
1068    if (ret != NATIVE_ERROR_UNSUPPORTED) { // some device not support set colorspace
1069        ASSERT_EQ(ret, NATIVE_ERROR_UNKNOWN);
1070    }
1071    ret = OH_NativeWindow_SetColorSpace(nativeWindow, OH_COLORSPACE_BT709_LIMIT);
1072    if (ret != NATIVE_ERROR_UNSUPPORTED) { // some device not support set colorspace
1073        ASSERT_EQ(ret, NATIVE_ERROR_OK);
1074    }
1075    ret = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace);
1076    if (ret != NATIVE_ERROR_UNSUPPORTED) { // some device not support set colorspace
1077        ASSERT_EQ(ret, NATIVE_ERROR_OK);
1078        ASSERT_EQ(colorSpace, OH_COLORSPACE_BT709_LIMIT);
1079    }
1080}
1081
1082/*
1083 * @tc.name  OH_NativeWindow_SetColorSpace001
1084 * @tc.desc  call OH_NativeWindow_SetMetadataValue
1085 * @tc.size  : MediumTest
1086 * @tc.type  : Function
1087 * @tc.level : Level 2
1088 */
1089HWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue001, Function | MediumTest | Level2)
1090{
1091    int len = 60;
1092    uint8_t buff[len];
1093    for (int i = 0; i < 60; ++i) {
1094        buff[i] = static_cast<uint8_t>(i);
1095    }
1096    int32_t buffSize;
1097    uint8_t *checkMetaData;
1098    auto ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &buffSize, &checkMetaData);
1099    if (ret != NATIVE_ERROR_UNSUPPORTED) { // some device not support set colorspace
1100        ASSERT_NE(ret, NATIVE_ERROR_OK);
1101    }
1102    int32_t maxSize = -1;
1103    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)maxSize, buff);
1104    if (ret != NATIVE_ERROR_UNSUPPORTED) { // some device not support set colorspace
1105        ASSERT_NE(ret, NATIVE_ERROR_OK);
1106    }
1107    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
1108    if (ret != NATIVE_ERROR_UNSUPPORTED) { // some device not support set colorspace
1109        ASSERT_EQ(ret, NATIVE_ERROR_OK);
1110    }
1111    ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &buffSize, &checkMetaData);
1112    if (ret != NATIVE_ERROR_UNSUPPORTED) { // some device not support set colorspace
1113        ASSERT_EQ(memcmp(checkMetaData, buff, 60), 0);
1114        delete[] checkMetaData;
1115        ASSERT_EQ(ret, NATIVE_ERROR_OK);
1116    }
1117}
1118/*
1119 * @tc.name  CancelBuffer001
1120 * @tc.desc  call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
1121 * @tc.size  : MediumTest
1122 * @tc.type  : Function
1123 * @tc.level : Level 2
1124 */
1125HWTEST_F(NativeWindowTest, CancelBuffer001, Function | MediumTest | Level2)
1126{
1127    ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nullptr, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
1128}
1129
1130/*
1131 * @tc.name  CancelBuffer002
1132 * @tc.desc  call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
1133 * @tc.size  : MediumTest
1134 * @tc.type  : Function
1135 * @tc.level : Level 2
1136 */
1137HWTEST_F(NativeWindowTest, CancelBuffer002, Function | MediumTest | Level2)
1138{
1139    ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
1140}
1141
1142/*
1143 * @tc.name CancelBuffer003
1144 * @tc.desc  call OH_NativeWindow_NativeWindowAbortBuffer
1145 * @tc.size  : MediumTest
1146 * @tc.type  : Function
1147 * @tc.level : Level 2
1148 */
1149HWTEST_F(NativeWindowTest, CancelBuffer003, Function | MediumTest | Level2)
1150{
1151    ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer), NATIVE_ERROR_OK);
1152}
1153
1154/*
1155 * @tc.name  Reference001
1156 * @tc.desc  call OH_NativeWindow_NativeObjectReference
1157 * @tc.size  : MediumTest
1158 * @tc.type  : Function
1159 * @tc.level : Level 2
1160 */
1161HWTEST_F(NativeWindowTest, Reference001, Function | MediumTest | Level2)
1162{
1163    struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
1164    buffer->sfbuffer = sBuffer;
1165    ASSERT_EQ(OH_NativeWindow_NativeObjectReference(reinterpret_cast<void *>(buffer)), NATIVE_ERROR_OK);
1166    delete buffer;
1167}
1168
1169/*
1170 * @tc.name  Unreference001
1171 * @tc.desc  call OH_NativeWindow_NativeObjectUnreference
1172 * @tc.size  : MediumTest
1173 * @tc.type  : Function
1174 * @tc.level : Level 2
1175 */
1176HWTEST_F(NativeWindowTest, Unreference001, Function | MediumTest | Level2)
1177{
1178    struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
1179    buffer->sfbuffer = sBuffer;
1180    ASSERT_EQ(OH_NativeWindow_NativeObjectUnreference(reinterpret_cast<void *>(buffer)), NATIVE_ERROR_OK);
1181    delete buffer;
1182}
1183
1184/*
1185 * @tc.name  DestroyNativeWindow001
1186 * @tc.desc  call OH_NativeWindow_DestroyNativeWindow by abnormal input
1187 * @tc.size  : MediumTest
1188 * @tc.type  : Function
1189 * @tc.level : Level 2
1190 */
1191HWTEST_F(NativeWindowTest, DestroyNativeWindow001, Function | MediumTest | Level2)
1192{
1193    OH_NativeWindow_DestroyNativeWindow(nullptr);
1194}
1195
1196/*
1197 * @tc.name  OH_NativeWindow_DestroyNativeWindowBuffer001
1198 * @tc.desc  call OH_NativeWindow_DestroyNativeWindowBuffer by abnormal input
1199 * @tc.size  : MediumTest
1200 * @tc.type  : Function
1201 * @tc.level : Level 2
1202 */
1203HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer001, Function | MediumTest | Level2)
1204{
1205    OH_NativeWindow_DestroyNativeWindowBuffer(nullptr);
1206}
1207
1208/*
1209 * @tc.name  OH_NativeWindow_DestroyNativeWindowBuffer002
1210 * @tc.desc  call OH_NativeWindow_DestroyNativeWindowBuffer again
1211 * @tc.size  : MediumTest
1212 * @tc.type  : Function
1213 * @tc.level : Level 2
1214 */
1215HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer002, Function | MediumTest | Level2)
1216{
1217    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
1218}
1219
1220/*
1221 * @tc.name  SetScalingMode001
1222 * @tc.desc  call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
1223 * @tc.size  : MediumTest
1224 * @tc.type  : Function
1225 * @tc.level : Level 2
1226 */
1227HWTEST_F(NativeWindowTest, SetScalingMode001, Function | MediumTest | Level2)
1228{
1229    OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
1230    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nullptr, -1, scalingMode), NATIVE_ERROR_INVALID_ARGUMENTS);
1231}
1232
1233/*
1234 * @tc.name  SetScalingMode002
1235 * @tc.desc  call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
1236 * @tc.size  : MediumTest
1237 * @tc.type  : Function
1238 * @tc.level : Level 2
1239 */
1240HWTEST_F(NativeWindowTest, SetScalingMode002, Function | MediumTest | Level2)
1241{
1242    OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
1243    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, -1, scalingMode), OHOS::GSERROR_NO_ENTRY);
1244}
1245
1246/*
1247 * @tc.name  SetScalingMode003
1248 * @tc.desc  call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
1249 * @tc.size  : MediumTest
1250 * @tc.type  : Function
1251 * @tc.level : Level 2
1252 */
1253HWTEST_F(NativeWindowTest, SetScalingMode003, Function | MediumTest | Level2)
1254{
1255    int32_t sequence = 0;
1256    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, sequence,
1257                                         static_cast<OHScalingMode>(OHScalingMode::OH_SCALING_MODE_NO_SCALE_CROP + 1)),
1258                                         NATIVE_ERROR_INVALID_ARGUMENTS);
1259}
1260/*
1261 * @tc.name  : SetScalingMode005
1262 * @tc.desc  : call OH_NativeWindow_NativeWindowSetScalingModeV2 with abnormal parameters and check ret
1263 * @tc.size  : MediumTest
1264 * @tc.type  : Function
1265 * @tc.level : Level 1
1266 */
1267HWTEST_F(NativeWindowTest, SetScalingMode005, Function | MediumTest | Level1)
1268{
1269    OHScalingModeV2 scalingMode = OHScalingModeV2::OH_SCALING_MODE_SCALE_TO_WINDOW_V2;
1270    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingModeV2(nativeWindow, scalingMode), NATIVE_ERROR_OK);
1271}
1272/*
1273 * @tc.name  SetMetaData001
1274 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1275 * @tc.size  : MediumTest
1276 * @tc.type  : Function
1277 * @tc.level : Level 2
1278 */
1279HWTEST_F(NativeWindowTest, SetMetaData001, Function | MediumTest | Level2)
1280{
1281    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nullptr, -1, 0, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
1282}
1283
1284/*
1285 * @tc.name  SetMetaData002
1286 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1287 * @tc.size  : MediumTest
1288 * @tc.type  : Function
1289 * @tc.level : Level 2
1290 */
1291HWTEST_F(NativeWindowTest, SetMetaData002, Function | MediumTest | Level2)
1292{
1293    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, 0, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
1294}
1295
1296/*
1297 * @tc.name  SetMetaData003
1298 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1299 * @tc.size  : MediumTest
1300 * @tc.type  : Function
1301 * @tc.level : Level 2
1302 */
1303HWTEST_F(NativeWindowTest, SetMetaData003, Function | MediumTest | Level2)
1304{
1305    int32_t sequence = 0;
1306    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, 0, nullptr),
1307              NATIVE_ERROR_INVALID_ARGUMENTS);
1308}
1309
1310/*
1311 * @tc.name  SetMetaData004
1312 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1313 * @tc.size  : MediumTest
1314 * @tc.type  : Function
1315 * @tc.level : Level 2
1316 */
1317HWTEST_F(NativeWindowTest, SetMetaData004, Function | MediumTest | Level2)
1318{
1319    int32_t sequence = 0;
1320    int32_t size = 1;
1321    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, size, nullptr),
1322              NATIVE_ERROR_INVALID_ARGUMENTS);
1323}
1324
1325/*
1326 * @tc.name  SetMetaData005
1327 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1328 * @tc.size  : MediumTest
1329 * @tc.type  : Function
1330 * @tc.level : Level 2
1331 */
1332HWTEST_F(NativeWindowTest, SetMetaData005, Function | MediumTest | Level2)
1333{
1334    int32_t size = 1;
1335    const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
1336    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, size, metaData), OHOS::GSERROR_NO_ENTRY);
1337}
1338
1339
1340/*
1341 * @tc.name  SetMetaDataSet001
1342 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1343 * @tc.size  : MediumTest
1344 * @tc.type  : Function
1345 * @tc.level : Level 2
1346 */
1347HWTEST_F(NativeWindowTest, SetMetaDataSet001, Function | MediumTest | Level2)
1348{
1349    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1350    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nullptr, -1, key, 0, nullptr),
1351              NATIVE_ERROR_INVALID_ARGUMENTS);
1352}
1353
1354/*
1355 * @tc.name  SetMetaDataSet002
1356 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1357 * @tc.size  : MediumTest
1358 * @tc.type  : Function
1359 * @tc.level : Level 2
1360 */
1361HWTEST_F(NativeWindowTest, SetMetaDataSet002, Function | MediumTest | Level2)
1362{
1363    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1364    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, 0, nullptr),
1365              NATIVE_ERROR_INVALID_ARGUMENTS);
1366}
1367
1368/*
1369 * @tc.name  SetMetaDataSet003
1370 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1371 * @tc.size  : MediumTest
1372 * @tc.type  : Function
1373 * @tc.level : Level 2
1374 */
1375HWTEST_F(NativeWindowTest, SetMetaDataSet003, Function | MediumTest | Level2)
1376{
1377    int32_t sequence = 0;
1378    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1379    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, 0, nullptr),
1380              NATIVE_ERROR_INVALID_ARGUMENTS);
1381}
1382
1383/*
1384 * @tc.name SetMetaDataSet004
1385 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1386 * @tc.size  : MediumTest
1387 * @tc.type  : Function
1388 * @tc.level : Level 2
1389 */
1390HWTEST_F(NativeWindowTest, SetMetaDataSet004, Function | MediumTest | Level2)
1391{
1392    int32_t sequence = 0;
1393    int32_t size = 1;
1394    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1395    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, size, nullptr),
1396              NATIVE_ERROR_INVALID_ARGUMENTS);
1397}
1398
1399/*
1400 * @tc.name  SetMetaDataSet005
1401 * @tc.desc  call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1402 * @tc.size  : MediumTest
1403 * @tc.type  : Function
1404 * @tc.level : Level 2
1405 */
1406HWTEST_F(NativeWindowTest, SetMetaDataSet005, Function | MediumTest | Level2)
1407{
1408    int32_t size = 1;
1409    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1410    const uint8_t metaData[] = {0};
1411    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, size, metaData),
1412              OHOS::GSERROR_NO_ENTRY);
1413}
1414
1415
1416/*
1417 * @tc.name  SetTunnelHandle001
1418 * @tc.desc  call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
1419 * @tc.size  : MediumTest
1420 * @tc.type  : Function
1421 * @tc.level : Level 2
1422 */
1423HWTEST_F(NativeWindowTest, SetTunnelHandle001, Function | MediumTest | Level2)
1424{
1425    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nullptr, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
1426}
1427
1428/*
1429 * @tc.name  SetTunnelHandle002
1430 * @tc.desc  call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
1431 * @tc.size  : MediumTest
1432 * @tc.type  : Function
1433 * @tc.level : Level 2
1434 */
1435HWTEST_F(NativeWindowTest, SetTunnelHandle002, Function | MediumTest | Level2)
1436{
1437    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
1438}
1439
1440/*
1441 * @tc.name  SetTunnelHandle003
1442 * @tc.desc  call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
1443 * @tc.size  : MediumTest
1444 * @tc.type  : Function
1445 * @tc.level : Level 2
1446 */
1447HWTEST_F(NativeWindowTest, SetTunnelHandle003, Function | MediumTest | Level2)
1448{
1449    uint32_t reserveInts = 1;
1450    OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
1451    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), NATIVE_ERROR_OK);
1452    FreeOHExtDataHandle(handle);
1453}
1454
1455/*
1456 * @tc.name  SetTunnelHandle004
1457 * @tc.desc  call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
1458 * @tc.size  : MediumTest
1459 * @tc.type  : Function
1460 * @tc.level : Level 1
1461 */
1462HWTEST_F(NativeWindowTest, SetTunnelHandle004, Function | MediumTest | Level1)
1463{
1464    uint32_t reserveInts = 2;
1465    OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
1466    nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
1467    ASSERT_NE(nativeWindow, nullptr);
1468    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), NATIVE_ERROR_OK);
1469    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_NO_ENTRY);
1470    FreeOHExtDataHandle(handle);
1471}
1472
1473/*
1474 * @tc.name  NativeWindowGetDefaultWidthAndHeight001
1475 * @tc.desc  call NativeWindowGetDefaultWidthAndHeight with normal parameters and check ret
1476 * @tc.size  : MediumTest
1477 * @tc.type  : Function
1478 * @tc.level : Level 1
1479 */
1480HWTEST_F(NativeWindowTest, NativeWindowGetDefaultWidthAndHeight001, Function | MediumTest | Level1)
1481{
1482    ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nullptr, nullptr, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
1483    cSurface->SetDefaultWidthAndHeight(300, 400);
1484    int32_t width;
1485    int32_t height;
1486    ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindow, &width, &height), NATIVE_ERROR_OK);
1487    ASSERT_EQ(width, 300);
1488    ASSERT_EQ(height, 400);
1489}
1490/*
1491 * @tc.name  : NativeWindowSetBufferHold001
1492 * @tc.desc  : call NativeWindowSetBufferHold and no ret
1493 * @tc.size  : MediumTest
1494 * @tc.type  : Function
1495 * @tc.level : Level 1
1496 */
1497HWTEST_F(NativeWindowTest, NativeWindowSetBufferHold001, Function | MediumTest | Level1)
1498{
1499    OH_NativeWindow_SetBufferHold(nativeWindow); // buffer one frame in advance
1500    int fenceFd = -1;
1501    struct Region *region = new Region();
1502    region->rectNumber = 0;
1503    region->rects = nullptr;
1504    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
1505              NATIVE_ERROR_INVALID_ARGUMENTS);
1506    region->rectNumber = 1;
1507    struct Region::Rect * rect = new Region::Rect();
1508    rect->x = 0x100;
1509    rect->y = 0x100;
1510    rect->w = 0x100;
1511    rect->h = 0x100;
1512    region->rects = rect;
1513    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
1514              NATIVE_ERROR_INVALID_ARGUMENTS);
1515    delete rect;
1516    delete region;
1517    cSurface->SetBufferHold(false);
1518}
1519
1520/*
1521 * @tc.name  : NativeWindowReadWriteWindow002
1522 * @tc.desc  : call OH_NativeWindow_WriteToParcel and OH_NativeWindow_ReadFromParcel
1523 * @tc.size  : MediumTest
1524 * @tc.type  : Function
1525 * @tc.level : Level 1
1526 */
1527HWTEST_F(NativeWindowTest, NativeWindowReadWriteWindow002, Function | MediumTest | Level1)
1528{
1529    using namespace OHOS;
1530    // test for no surface->GetUniqueId
1531    OHNativeWindow* nativeWindow1 = new OHNativeWindow();
1532    ASSERT_NE(nativeWindow1, nullptr);
1533    OHIPCParcel *parcel1 = OH_IPCParcel_Create();
1534    ASSERT_NE(parcel1, nullptr);
1535    ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow1, parcel1), NATIVE_ERROR_INVALID_ARGUMENTS);
1536    OHNativeWindow *readWindow = nullptr;
1537    ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, nullptr), NATIVE_ERROR_INVALID_ARGUMENTS);
1538    ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, &readWindow), NATIVE_ERROR_INVALID_ARGUMENTS);
1539    OH_IPCParcel_Destroy(parcel1);
1540    delete nativeWindow1;
1541}
1542/*
1543 * @tc.name  GetNativeObjectMagic001
1544 * @tc.desc  call OH_NativeWindow_GetNativeObjectMagic
1545 * @tc.size  : MediumTest
1546 * @tc.type  : Function
1547 * @tc.level : Level 2
1548 */
1549HWTEST_F(NativeWindowTest, GetNativeObjectMagic001, Function | MediumTest | Level2)
1550{
1551    struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
1552    buffer->sfbuffer = sBuffer;
1553    OH_NativeWindow_GetNativeObjectMagic(reinterpret_cast<void *>(buffer));
1554    delete buffer;
1555}
1556}
1557