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_inner_object.h"
26 #include "ipc_cparcel.h"
27 
28 using namespace std;
29 using namespace testing;
30 using namespace testing::ext;
31 
32 namespace OHOS::Rosen {
33 class BufferConsumerListener : public IBufferConsumerListener {
34 public:
OnBufferAvailable()35     void OnBufferAvailable() override
36     {
37     }
38 };
39 
AllocOHExtDataHandle(uint32_t reserveInts)40 static 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 
FreeOHExtDataHandle(OHExtDataHandle * handle)61 static 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 
74 class NativeWindowTest : public testing::Test {
75 public:
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     static inline uint32_t firstSeqnum = 0;
88 };
89 
SetUpTestCase()90 void NativeWindowTest::SetUpTestCase()
91 {
92     requestConfig = {
93         .width = 0x100,  // small
94         .height = 0x100, // small
95         .strideAlignment = 0x8,
96         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
97         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
98         .timeout = 0,
99     };
100 
101     cSurface = IConsumerSurface::Create();
102     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
103     cSurface->RegisterConsumerListener(listener);
104     producer = cSurface->GetProducer();
105     pSurface = Surface::CreateSurfaceAsProducer(producer);
106     int32_t fence;
107     pSurface->RequestBuffer(sBuffer, fence, requestConfig);
108     firstSeqnum = sBuffer->GetSeqNum();
109 }
110 
TearDownTestCase()111 void NativeWindowTest::TearDownTestCase()
112 {
113     flushConfig = { .damage = {
114         .w = 0x100,
115         .h = 0x100,
116     } };
117     pSurface->FlushBuffer(sBuffer, -1, flushConfig);
118     sBuffer = nullptr;
119     cSurface = nullptr;
120     producer = nullptr;
121     pSurface = nullptr;
122     OH_NativeWindow_DestroyNativeWindow(nativeWindow);
123     nativeWindow = nullptr;
124     nativeWindowBuffer = nullptr;
125 }
126 
127 /*
128 * Function: OH_NativeWindow_CreateNativeWindow
129 * Type: Function
130 * Rank: Important(2)
131 * EnvConditions: N/A
132 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow by abnormal input
133 *                  2. check ret
134  */
135 HWTEST_F(NativeWindowTest, CreateNativeWindow001, Function | MediumTest | Level2)
136 {
137     ASSERT_EQ(OH_NativeWindow_CreateNativeWindow(nullptr), nullptr);
138 }
139 
140 /*
141 * Function: OH_NativeWindow_CreateNativeWindow
142 * Type: Function
143 * Rank: Important(2)
144 * EnvConditions: N/A
145 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow
146 *                  2. check ret
147  */
148 HWTEST_F(NativeWindowTest, CreateNativeWindow002, Function | MediumTest | Level2)
149 {
150     nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
151     ASSERT_NE(nativeWindow, nullptr);
152 }
153 
154 /*
155 * Function: OH_NativeWindow_CreateNativeWindow
156 * Type: Function
157 * Rank: Important(2)
158 * EnvConditions: N/A
159 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow
160 *                  2. check ret
161  */
162 HWTEST_F(NativeWindowTest, CreateNativeWindow003, Function | MediumTest | Level2)
163 {
164     uint64_t surfaceId = 0;
165     int32_t ret = OH_NativeWindow_GetSurfaceId(nativeWindow, &surfaceId);
166     ASSERT_EQ(ret, OHOS::GSERROR_OK);
167     ASSERT_EQ(surfaceId, pSurface->GetUniqueId());
168 }
169 
170 /*
171 * Function: OH_NativeWindow_CreateNativeWindowFromSurfaceId
172 * Type: Function
173 * Rank: Important(2)
174 * EnvConditions: N/A
175 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowFromSurfaceId
176 *                  2. check ret
177  */
178 HWTEST_F(NativeWindowTest, CreateNativeWindowFromSurfaceId001, Function | MediumTest | Level2)
179 {
180     uint64_t surfaceId = static_cast<uint64_t>(pSurface->GetUniqueId());
181     OHNativeWindow *window = nullptr;
182     int32_t ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, &window);
183     ASSERT_EQ(ret, OHOS::GSERROR_OK);
184     surfaceId = 0;
185     ret = OH_NativeWindow_GetSurfaceId(window, &surfaceId);
186     ASSERT_EQ(ret, OHOS::GSERROR_OK);
187     ASSERT_EQ(surfaceId, pSurface->GetUniqueId());
188     OH_NativeWindow_DestroyNativeWindow(window);
189 }
190 
191 /*
192 * Function: OH_NativeWindow_CreateNativeWindowFromSurfaceId
193 * Type: Function
194 * Rank: Important(2)
195 * EnvConditions: N/A
196 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowFromSurfaceId
197 *                  2. check ret
198  */
199 HWTEST_F(NativeWindowTest, CreateNativeWindowFromSurfaceId002, Function | MediumTest | Level2)
200 {
201     int32_t ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(0, nullptr);
202     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
203     ret = OH_NativeWindow_GetSurfaceId(nullptr, nullptr);
204     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
205 }
206 
207 /*
208 * Function: OH_NativeWindow_CreateNativeWindowFromSurfaceId
209 * Type: Function
210 * Rank: Important(2)
211 * EnvConditions: N/A
212 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowFromSurfaceId
213 *                  2. check ret
214  */
215 HWTEST_F(NativeWindowTest, CreateNativeWindowFromSurfaceId003, Function | MediumTest | Level2)
216 {
217     sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
218     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
219     cSurfaceTmp->RegisterConsumerListener(listener);
220     sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
221     sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
222 
223     uint64_t surfaceId = static_cast<uint64_t>(pSurfaceTmp->GetUniqueId());
224     auto utils = SurfaceUtils::GetInstance();
225     utils->Add(surfaceId, pSurfaceTmp);
226     OHNativeWindow *nativeWindowTmp = nullptr;
227     int32_t ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(0xFFFFFFFF, &nativeWindowTmp);
228     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
229     ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, &nativeWindowTmp);
230     ASSERT_EQ(ret, OHOS::GSERROR_OK);
231     surfaceId = 0;
232     ret = OH_NativeWindow_GetSurfaceId(nativeWindowTmp, &surfaceId);
233     ASSERT_EQ(ret, OHOS::GSERROR_OK);
234     ASSERT_EQ(surfaceId, pSurfaceTmp->GetUniqueId());
235 
236     cSurfaceTmp = nullptr;
237     producerTmp = nullptr;
238     pSurfaceTmp = nullptr;
239     OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
240 }
241 
242 /*
243 * Function: OH_NativeWindow_NativeWindowHandleOpt
244 * Type: Function
245 * Rank: Important(2)
246 * EnvConditions: N/A
247 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by abnormal input
248 *                  2. check ret
249  */
250 HWTEST_F(NativeWindowTest, HandleOpt001, Function | MediumTest | Level2)
251 {
252     int code = SET_USAGE;
253     uint64_t usage = BUFFER_USAGE_CPU_READ;
254     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nullptr, code, usage), OHOS::GSERROR_INVALID_ARGUMENTS);
255 }
256 
257 /*
258 * Function: OH_NativeWindow_NativeWindowHandleOpt
259 * Type: Function
260 * Rank: Important(2)
261 * EnvConditions: N/A
262 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
263 *                  2. check ret
264  */
265 HWTEST_F(NativeWindowTest, HandleOpt002, Function | MediumTest | Level2)
266 {
267     int code = SET_USAGE;
268     uint64_t usageSet = BUFFER_USAGE_CPU_READ;
269     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), OHOS::GSERROR_OK);
270 
271     code = GET_USAGE;
272     uint64_t usageGet = BUFFER_USAGE_CPU_WRITE;
273     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &usageGet), OHOS::GSERROR_OK);
274     ASSERT_EQ(usageSet, usageGet);
275 }
276 
277 /*
278 * Function: OH_NativeWindow_NativeWindowHandleOpt
279 * Type: Function
280 * Rank: Important(2)
281 * EnvConditions: N/A
282 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
283 *                  2. check ret
284  */
285 HWTEST_F(NativeWindowTest, HandleOpt003, Function | MediumTest | Level2)
286 {
287     int code = SET_BUFFER_GEOMETRY;
288     int32_t heightSet = 0x100;
289     int32_t widthSet = 0x100;
290     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, heightSet, widthSet), OHOS::GSERROR_OK);
291 
292     code = GET_BUFFER_GEOMETRY;
293     int32_t heightGet = 0;
294     int32_t widthGet = 0;
295     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &heightGet, &widthGet), OHOS::GSERROR_OK);
296     ASSERT_EQ(heightSet, heightGet);
297     ASSERT_EQ(widthSet, widthGet);
298 }
299 
300 /*
301 * Function: OH_NativeWindow_NativeWindowHandleOpt
302 * Type: Function
303 * Rank: Important(2)
304 * EnvConditions: N/A
305 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
306 *                  2. check ret
307  */
308 HWTEST_F(NativeWindowTest, HandleOpt004, Function | MediumTest | Level2)
309 {
310     int code = SET_FORMAT;
311     int32_t formatSet = GRAPHIC_PIXEL_FMT_RGBA_8888;
312     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), OHOS::GSERROR_OK);
313 
314     code = GET_FORMAT;
315     int32_t formatGet = GRAPHIC_PIXEL_FMT_CLUT8;
316     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &formatGet), OHOS::GSERROR_OK);
317     ASSERT_EQ(formatSet, formatGet);
318 }
319 
320 /*
321 * Function: OH_NativeWindow_NativeWindowHandleOpt
322 * Type: Function
323 * Rank: Important(2)
324 * EnvConditions: N/A
325 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
326 *                  2. check ret
327  */
328 HWTEST_F(NativeWindowTest, HandleOpt005, Function | MediumTest | Level2)
329 {
330     int code = SET_STRIDE;
331     int32_t strideSet = 0x8;
332     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, strideSet), OHOS::GSERROR_OK);
333 
334     code = GET_STRIDE;
335     int32_t strideGet = 0;
336     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &strideGet), OHOS::GSERROR_OK);
337     ASSERT_EQ(strideSet, strideGet);
338 }
339 
340 /*
341 * Function: OH_NativeWindow_NativeWindowHandleOpt
342 * Type: Function
343 * Rank: Important(2)
344 * EnvConditions: N/A
345 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
346 *                  2. check ret
347  */
348 HWTEST_F(NativeWindowTest, HandleOpt006, Function | MediumTest | Level2)
349 {
350     int code = SET_COLOR_GAMUT;
351     int32_t colorGamutSet = static_cast<int32_t>(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
352     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, colorGamutSet), OHOS::GSERROR_OK);
353 
354     code = GET_COLOR_GAMUT;
355     int32_t colorGamutGet = 0;
356     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &colorGamutGet), OHOS::GSERROR_OK);
357     ASSERT_EQ(colorGamutSet, colorGamutGet);
358 }
359 
360 /*
361 * Function: OH_NativeWindow_NativeWindowHandleOpt
362 * Type: Function
363 * Rank: Important(2)
364 * EnvConditions: N/A
365 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
366 *                  2. check ret
367  */
368 HWTEST_F(NativeWindowTest, HandleOpt007, Function | MediumTest | Level2)
369 {
370     int code = SET_TIMEOUT;
371     int32_t timeoutSet = 10;  // 10: for test
372     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, timeoutSet), OHOS::GSERROR_OK);
373 
374     code = GET_TIMEOUT;
375     int32_t timeoutGet = 0;
376     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &timeoutGet), OHOS::GSERROR_OK);
377     ASSERT_EQ(timeoutSet, timeoutGet);
378 }
379 
380 /*
381 * Function: OH_NativeWindow_NativeWindowHandleOpt
382 * Type: Function
383 * Rank: Important(2)
384 * EnvConditions: N/A
385 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
386 *                  2. check ret
387  */
388 HWTEST_F(NativeWindowTest, HandleOpt008, Function | MediumTest | Level1)
389 {
390     int code = GET_TRANSFORM;
391     int32_t transform = 0;
392     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &transform), OHOS::GSERROR_OK);
393     transform = GraphicTransformType::GRAPHIC_ROTATE_90;
394     code = SET_TRANSFORM;
395     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, transform), OHOS::GSERROR_OK);
396     int32_t transformTmp = 0;
397     code = GET_TRANSFORM;
398     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &transformTmp), OHOS::GSERROR_OK);
399     ASSERT_EQ(transformTmp, GraphicTransformType::GRAPHIC_ROTATE_90);
400     nativeWindow->surface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_180);
401     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &transformTmp), OHOS::GSERROR_OK);
402     ASSERT_EQ(transformTmp, GraphicTransformType::GRAPHIC_ROTATE_180);
403 }
404 
405 /*
406 * Function: OH_NativeWindow_NativeWindowHandleOpt
407 * Type: Function
408 * Rank: Important(2)
409 * EnvConditions: N/A
410 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
411 *                  2. check ret
412  */
413 HWTEST_F(NativeWindowTest, HandleOpt009, Function | MediumTest | Level1)
414 {
415     int code = GET_BUFFERQUEUE_SIZE;
416     int32_t queueSize = 0;
417     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &queueSize), OHOS::GSERROR_OK);
418     ASSERT_EQ(queueSize, 3);
419     nativeWindow->surface->SetQueueSize(5);
420     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &queueSize), OHOS::GSERROR_OK);
421     ASSERT_EQ(queueSize, 5);
422 }
423 
424 /*
425 * Function: OH_NativeWindow_NativeWindowHandleOpt
426 * Type: Function
427 * Rank: Important(2)
428 * EnvConditions: N/A
429 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
430 *                  2. check ret
431  */
432 HWTEST_F(NativeWindowTest, HandleOpt010, Function | MediumTest | Level2)
433 {
434     int code = SET_USAGE;
435     uint64_t usageSet = NATIVEBUFFER_USAGE_HW_RENDER | NATIVEBUFFER_USAGE_HW_TEXTURE |
436     NATIVEBUFFER_USAGE_CPU_READ_OFTEN | NATIVEBUFFER_USAGE_ALIGNMENT_512;
437     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), OHOS::GSERROR_OK);
438 
439     code = GET_USAGE;
440     uint64_t usageGet = usageSet;
441     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &usageGet), OHOS::GSERROR_OK);
442     ASSERT_EQ(usageSet, usageGet);
443 
444     code = SET_FORMAT;
445     int32_t formatSet = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010;
446     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), OHOS::GSERROR_OK);
447 
448     code = GET_FORMAT;
449     int32_t formatGet = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010;
450     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &formatGet), OHOS::GSERROR_OK);
451     ASSERT_EQ(formatSet, formatGet);
452 }
453 
454 /*
455 * Function: OH_NativeWindow_NativeWindowHandleOpt
456 * Type: Function
457 * Rank: Important(2)
458 * EnvConditions: N/A
459 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
460 *                  2. check ret
461  */
462 HWTEST_F(NativeWindowTest, HandleOpt011, Function | MediumTest | Level1)
463 {
464     int code = SET_SOURCE_TYPE;
465     OHSurfaceSource typeSet = OHSurfaceSource::OH_SURFACE_SOURCE_GAME;
466     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, typeSet), OHOS::GSERROR_OK);
467 
468     code = GET_SOURCE_TYPE;
469     OHSurfaceSource typeGet = OHSurfaceSource::OH_SURFACE_SOURCE_DEFAULT;
470     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &typeGet), OHOS::GSERROR_OK);
471     ASSERT_EQ(typeSet, typeGet);
472 }
473 
474 /*
475 * Function: OH_NativeWindow_NativeWindowHandleOpt
476 * Type: Function
477 * Rank: Important(2)
478 * EnvConditions: N/A
479 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
480 *                  2. check ret
481  */
482 HWTEST_F(NativeWindowTest, HandleOpt012, Function | MediumTest | Level1)
483 {
484     int code = SET_APP_FRAMEWORK_TYPE;
485     const char* typeSet = "test";
486     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, typeSet), OHOS::GSERROR_OK);
487 
488     code = GET_APP_FRAMEWORK_TYPE;
489     const char* typeGet;
490     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &typeGet), OHOS::GSERROR_OK);
491     ASSERT_EQ(0, strcmp(typeSet, typeGet));
492 }
493 
494 /*
495 * Function: OH_NativeWindow_NativeWindowHandleOpt
496 * Type: Function
497 * Rank: Important(2)
498 * EnvConditions: N/A
499 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
500 *                  2. check ret
501  */
502 HWTEST_F(NativeWindowTest, HandleOpt013, Function | MediumTest | Level1)
503 {
504     int code = SET_HDR_WHITE_POINT_BRIGHTNESS;
505     float brightness = 0.8;
506     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
507 
508     code = SET_SDR_WHITE_POINT_BRIGHTNESS;
509     brightness = 0.5;
510     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
511 
512     ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.8) < 1e-6, true);
513     ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.5) < 1e-6, true);
514 
515     code = SET_HDR_WHITE_POINT_BRIGHTNESS;
516     brightness = 1.8;
517     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
518     ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.8) < 1e-6, true);
519     brightness = -0.5;
520     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
521     ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.8) < 1e-6, true);
522     brightness = 0.5;
523     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
524     ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.5) < 1e-6, true);
525 
526     code = SET_SDR_WHITE_POINT_BRIGHTNESS;
527     brightness = 1.5;
528     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
529     ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.5) < 1e-6, true);
530     brightness = -0.1;
531     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
532     ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.5) < 1e-6, true);
533     brightness = 0.8;
534     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
535     ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.8) < 1e-6, true);
536 }
537 
538 /*
539 * Function: OH_NativeWindow_NativeWindowHandleOpt
540 * Type: Function
541 * Rank: Important(2)
542 * EnvConditions: N/A
543 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
544 *                  2. check ret
545  */
546 HWTEST_F(NativeWindowTest, HandleOpt014, Function | MediumTest | Level1)
547 {
548     int code = SET_APP_FRAMEWORK_TYPE;
549     const char* typeSet = "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttest";
550     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, typeSet), OHOS::GSERROR_OK);
551 
552     code = GET_APP_FRAMEWORK_TYPE;
553     const char* typeGet;
554     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &typeGet), OHOS::GSERROR_OK);
555     ASSERT_EQ(0, strcmp(typeSet, typeGet));
556 }
557 
558 /*
559 * Function: OH_NativeWindow_NativeWindowAttachBuffer
560 * Type: Function
561 * Rank: Important(2)
562 * EnvConditions: N/A
563 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by abnormal input
564 *                  2. check ret
565  */
566 HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer001, Function | MediumTest | Level1)
567 {
568     ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
569     ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
570     ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
571     ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
572 }
573 
SetNativeWindowConfig(NativeWindow * nativeWindow)574 void SetNativeWindowConfig(NativeWindow *nativeWindow)
575 {
576     int code = SET_USAGE;
577     uint64_t usageSet = BUFFER_USAGE_CPU_READ;
578     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), OHOS::GSERROR_OK);
579 
580     code = SET_BUFFER_GEOMETRY;
581     int32_t heightSet = 0x100;
582     int32_t widthSet = 0x100;
583     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, heightSet, widthSet), OHOS::GSERROR_OK);
584 
585     code = SET_FORMAT;
586     int32_t formatSet = GRAPHIC_PIXEL_FMT_RGBA_8888;
587     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), OHOS::GSERROR_OK);
588 
589     code = SET_STRIDE;
590     int32_t strideSet = 0x8;
591     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, strideSet), OHOS::GSERROR_OK);
592 
593     code = SET_COLOR_GAMUT;
594     int32_t colorGamutSet = static_cast<int32_t>(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
595     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, colorGamutSet), OHOS::GSERROR_OK);
596 
597     code = SET_TIMEOUT;
598     int32_t timeoutSet = 10;  // 10: for test
599     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, timeoutSet), OHOS::GSERROR_OK);
600 }
601 
602 /*
603 * Function: OH_NativeWindow_NativeWindowAttachBuffer
604 * Type: Function
605 * Rank: Important(2)
606 * EnvConditions: N/A
607 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
608 *                  2. check ret
609  */
610 HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer002, Function | MediumTest | Level1)
611 {
612     sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
613     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
614     cSurfaceTmp->RegisterConsumerListener(listener);
615     sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
616     sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
617 
618     NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
619     ASSERT_NE(nativeWindowTmp, nullptr);
620     SetNativeWindowConfig(nativeWindowTmp);
621 
622     NativeWindowBuffer *nativeWindowBuffer = nullptr;
623     int fenceFd = -1;
624     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer, &fenceFd);
625     ASSERT_EQ(ret, GSERROR_OK);
626 
627     int code = GET_BUFFERQUEUE_SIZE;
628     int32_t queueSize = 0;
629     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
630     ASSERT_EQ(queueSize, 3);
631 
632     ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer), OHOS::GSERROR_OK);
633 
634     ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nativeWindowBuffer), OHOS::GSERROR_OK);
635 
636     ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer), OHOS::GSERROR_OK);
637 
638     ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp, nativeWindowBuffer), OHOS::GSERROR_OK);
639     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
640     ASSERT_EQ(queueSize, 3);
641     ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp, nativeWindowBuffer),
642         OHOS::GSERROR_BUFFER_IS_INCACHE);
643 
644     struct Region *region = new Region();
645     struct Region::Rect *rect = new Region::Rect();
646     rect->x = 0x100;
647     rect->y = 0x100;
648     rect->w = 0x100;
649     rect->h = 0x100;
650     region->rects = rect;
651     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindowTmp, nativeWindowBuffer, fenceFd, *region);
652     ASSERT_EQ(ret, GSERROR_OK);
653 
654     OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
655 }
656 
NativeWindowAttachBuffer003Test(NativeWindow * nativeWindowTmp,NativeWindow * nativeWindowTmp1)657 void NativeWindowAttachBuffer003Test(NativeWindow *nativeWindowTmp, NativeWindow *nativeWindowTmp1)
658 {
659     NativeWindowBuffer *nativeWindowBuffer1 = nullptr;
660     int fenceFd = -1;
661     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer1, &fenceFd);
662     ASSERT_EQ(ret, GSERROR_OK);
663 
664     NativeWindowBuffer *nativeWindowBuffer2 = nullptr;
665     fenceFd = -1;
666     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer2, &fenceFd);
667     ASSERT_EQ(ret, GSERROR_OK);
668 
669     NativeWindowBuffer *nativeWindowBuffer3 = nullptr;
670     fenceFd = -1;
671     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer3, &fenceFd);
672     ASSERT_EQ(ret, GSERROR_OK);
673 
674     int code = GET_BUFFERQUEUE_SIZE;
675     int32_t queueSize = 0;
676     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
677     ASSERT_EQ(queueSize, 3);
678 
679     ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer1), OHOS::GSERROR_OK);
680     ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer2), OHOS::GSERROR_OK);
681     ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer3), OHOS::GSERROR_OK);
682 
683     NativeWindowBuffer *nativeWindowBuffer4 = nullptr;
684     fenceFd = -1;
685     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer4, &fenceFd);
686     ASSERT_EQ(ret, GSERROR_OK);
687 
688     NativeWindowBuffer *nativeWindowBuffer10 = nullptr;
689     fenceFd = -1;
690     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp1, &nativeWindowBuffer10, &fenceFd);
691     ASSERT_EQ(ret, GSERROR_OK);
692 
693     NativeWindowBuffer *nativeWindowBuffer11 = nullptr;
694     fenceFd = -1;
695     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp1, &nativeWindowBuffer11, &fenceFd);
696     ASSERT_EQ(ret, GSERROR_OK);
697 
698     NativeWindowBuffer *nativeWindowBuffer12 = nullptr;
699     fenceFd = -1;
700     ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp1, &nativeWindowBuffer12, &fenceFd);
701     ASSERT_EQ(ret, GSERROR_OK);
702 
703     ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp1, nativeWindowBuffer1),
704         OHOS::SURFACE_ERROR_BUFFER_QUEUE_FULL);
705 }
706 
707 /*
708 * Function: OH_NativeWindow_NativeWindowAttachBuffer
709 * Type: Function
710 * Rank: Important(2)
711 * EnvConditions: N/A
712 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
713 *                  2. check ret
714  */
715 HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer003, Function | MediumTest | Level1)
716 {
717     sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
718     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
719     cSurfaceTmp->RegisterConsumerListener(listener);
720     sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
721     sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
722 
723     NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
724     ASSERT_NE(nativeWindowTmp, nullptr);
725     SetNativeWindowConfig(nativeWindowTmp);
726 
727     sptr<OHOS::IConsumerSurface> cSurfaceTmp1 = IConsumerSurface::Create();
728     sptr<IBufferConsumerListener> listener1 = new BufferConsumerListener();
729     cSurfaceTmp1->RegisterConsumerListener(listener1);
730     sptr<OHOS::IBufferProducer> producerTmp1 = cSurfaceTmp1->GetProducer();
731     sptr<OHOS::Surface> pSurfaceTmp1 = Surface::CreateSurfaceAsProducer(producerTmp1);
732 
733     NativeWindow *nativeWindowTmp1 = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp1);
734     ASSERT_NE(nativeWindowTmp1, nullptr);
735     SetNativeWindowConfig(nativeWindowTmp1);
736 
737     NativeWindowAttachBuffer003Test(nativeWindowTmp, nativeWindowTmp1);
738 
739     OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
740     OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp1);
741 }
742 
743 /*
744 * Function: OH_NativeWindow_NativeWindowAttachBuffer
745 * Type: Function
746 * Rank: Important(2)
747 * EnvConditions: N/A
748 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
749 *                  2. check ret
750  */
751 HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer004, Function | MediumTest | Level1)
752 {
753     sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
754     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
755     cSurfaceTmp->RegisterConsumerListener(listener);
756     sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
757     sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
758 
759     NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
760     ASSERT_NE(nativeWindowTmp, nullptr);
761     SetNativeWindowConfig(nativeWindowTmp);
762 
763     NativeWindowBuffer *nativeWindowBuffer = nullptr;
764     int fenceFd = -1;
765     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer, &fenceFd);
766     ASSERT_EQ(ret, GSERROR_OK);
767 
768     struct Region *region = new Region();
769     struct Region::Rect *rect = new Region::Rect();
770     rect->x = 0x100;
771     rect->y = 0x100;
772     rect->w = 0x100;
773     rect->h = 0x100;
774     region->rects = rect;
775     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindowTmp, nativeWindowBuffer, fenceFd, *region);
776     ASSERT_EQ(ret, GSERROR_OK);
777 
778     ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer),
779         OHOS::SURFACE_ERROR_BUFFER_STATE_INVALID);
780 
781     ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer),
782         OHOS::SURFACE_ERROR_BUFFER_NOT_INCACHE);
783 
784     OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
785 }
786 
787 /*
788 * Function: OH_NativeWindow_NativeWindowAttachBuffer
789 * Type: Function
790 * Rank: Important(2)
791 * EnvConditions: N/A
792 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
793 *                  2. check ret
794  */
795 HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer005, Function | MediumTest | Level1)
796 {
797     sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
798     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
799     cSurfaceTmp->RegisterConsumerListener(listener);
800     sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
801     sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
802 
803     NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
804     ASSERT_NE(nativeWindowTmp, nullptr);
805     SetNativeWindowConfig(nativeWindowTmp);
806 
807     NativeWindowBuffer *nativeWindowBuffer = nullptr;
808     int fenceFd = -1;
809     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer, &fenceFd);
810     ASSERT_EQ(ret, GSERROR_OK);
811 
812     ASSERT_EQ(cSurface->AttachBufferToQueue(nativeWindowBuffer->sfbuffer), GSERROR_OK);
813 
814     ASSERT_EQ(cSurface->DetachBufferFromQueue(nativeWindowBuffer->sfbuffer), GSERROR_OK);
815 
816     ASSERT_EQ(cSurface->AttachBufferToQueue(nativeWindowBuffer->sfbuffer), GSERROR_OK);
817 
818     sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
819     ASSERT_EQ(cSurface->ReleaseBuffer(nativeWindowBuffer->sfbuffer, fence), GSERROR_OK);
820 
821     OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
822 }
823 
824 /*
825 * Function: OH_NativeWindow_NativeWindowAttachBuffer
826 * Type: Function
827 * Rank: Important(2)
828 * EnvConditions: N/A
829 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
830 *                  2. check ret
831  */
832 HWTEST_F(NativeWindowTest, NativeWindowAttachBuffer006, Function | MediumTest | Level1)
833 {
834     sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
835     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
836     cSurfaceTmp->RegisterConsumerListener(listener);
837     sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
838     sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
839 
840     NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
841     ASSERT_NE(nativeWindowTmp, nullptr);
842     SetNativeWindowConfig(nativeWindowTmp);
843 
844     NativeWindowBuffer *nativeWindowBuffer1 = nullptr;
845     int fenceFd = -1;
846     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer1, &fenceFd);
847     ASSERT_EQ(ret, GSERROR_OK);
848 
849     int code = GET_BUFFERQUEUE_SIZE;
850     int32_t queueSize = 0;
851     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
852     ASSERT_EQ(queueSize, 3);
853     clock_t startTime, endTime;
854     startTime = clock();
855     for (int32_t i = 0; i < 1000; i++) {
856         ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer1), OHOS::GSERROR_OK);
857         ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp, nativeWindowBuffer1), OHOS::GSERROR_OK);
858     }
859     endTime = clock();
860     cout << "DetachBuffer and AttachBuffer 1000 times cost time: " << (endTime - startTime) << "ms" << endl;
861     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
862     ASSERT_EQ(queueSize, 3);
863     OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
864 }
865 
866 /*
867 * Function: OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
868 * Type: Function
869 * Rank: Important(2)
870 * EnvConditions: N/A
871 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer by abnormal input
872 *                  2. check ret
873  */
874 HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer001, Function | MediumTest | Level2)
875 {
876     ASSERT_EQ(OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(nullptr), nullptr);
877 }
878 
879 /*
880 * Function: OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
881 * Type: Function
882 * Rank: Important(2)
883 * EnvConditions: N/A
884 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
885 *                  2. check ret
886  */
887 HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer002, Function | MediumTest | Level2)
888 {
889     nativeWindowBuffer = OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(&sBuffer);
890     ASSERT_NE(nativeWindowBuffer, nullptr);
891 }
892 
893 /*
894 * Function: OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
895 * Type: Function
896 * Rank: Important(2)
897 * EnvConditions: N/A
898 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
899 *                  2. check ret
900 */
901 HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer003, Function | MediumTest | Level2)
902 {
903     OH_NativeBuffer* nativeBuffer = sBuffer->SurfaceBufferToNativeBuffer();
904     ASSERT_NE(nativeBuffer, nullptr);
905     NativeWindowBuffer* nwBuffer = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nativeBuffer);
906     ASSERT_NE(nwBuffer, nullptr);
907     OH_NativeWindow_DestroyNativeWindowBuffer(nwBuffer);
908 }
909 
910 /*
911 * Function: OH_NativeWindow_NativeWindowRequestBuffer
912 * Type: Function
913 * Rank: Important(2)
914 * EnvConditions: N/A
915 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
916 *                  2. check ret
917  */
918 HWTEST_F(NativeWindowTest, RequestBuffer001, Function | MediumTest | Level2)
919 {
920     ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nullptr, &nativeWindowBuffer, nullptr),
921               OHOS::GSERROR_INVALID_ARGUMENTS);
922 }
923 
924 /*
925 * Function: OH_NativeWindow_NativeWindowRequestBuffer
926 * Type: Function
927 * Rank: Important(2)
928 * EnvConditions: N/A
929 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
930 *                  2. check ret
931  */
932 HWTEST_F(NativeWindowTest, RequestBuffer002, Function | MediumTest | Level2)
933 {
934     ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, nullptr, nullptr),
935               OHOS::GSERROR_INVALID_ARGUMENTS);
936 }
937 
938 /*
939 * Function: OH_NativeWindow_GetBufferHandleFromNative
940 * Type: Function
941 * Rank: Important(2)
942 * EnvConditions: N/A
943 * CaseDescription: 1. call OH_NativeWindow_GetBufferHandleFromNative by abnormal input
944 *                  2. check ret
945  */
946 HWTEST_F(NativeWindowTest, GetBufferHandle001, Function | MediumTest | Level2)
947 {
948     ASSERT_EQ(OH_NativeWindow_GetBufferHandleFromNative(nullptr), nullptr);
949 }
950 
951 /*
952 * Function: OH_NativeWindow_GetBufferHandleFromNative
953 * Type: Function
954 * Rank: Important(2)
955 * EnvConditions: N/A
956 * CaseDescription: 1. call OH_NativeWindow_GetBufferHandleFromNative
957 *                  2. check ret
958  */
959 HWTEST_F(NativeWindowTest, GetBufferHandle002, Function | MediumTest | Level2)
960 {
961     struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
962     buffer->sfbuffer = sBuffer;
963     ASSERT_NE(OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer), nullptr);
964     delete buffer;
965 }
966 
967 /*
968 * Function: OH_NativeWindow_NativeWindowFlushBuffer
969 * Type: Function
970 * Rank: Important(2)
971 * EnvConditions: N/A
972 * CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
973 *                  2. check ret
974  */
975 HWTEST_F(NativeWindowTest, FlushBuffer001, Function | MediumTest | Level2)
976 {
977     int fenceFd = -1;
978     struct Region *region = new Region();
979     struct Region::Rect * rect = new Region::Rect();
980     rect->x = 0x100;
981     rect->y = 0x100;
982     rect->w = 0x100;
983     rect->h = 0x100;
984     region->rects = rect;
985 
986     ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nullptr, nullptr, fenceFd, *region),
987               OHOS::GSERROR_INVALID_ARGUMENTS);
988     delete region;
989 }
990 
991 /*
992 * Function: OH_NativeWindow_NativeWindowFlushBuffer
993 * Type: Function
994 * Rank: Important(2)
995 * EnvConditions: N/A
996 * CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
997 *                  2. check ret
998  */
999 HWTEST_F(NativeWindowTest, FlushBuffer002, Function | MediumTest | Level2)
1000 {
1001     int fenceFd = -1;
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 
1010     ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nullptr, fenceFd, *region),
1011               OHOS::GSERROR_INVALID_ARGUMENTS);
1012     delete region;
1013 }
1014 
1015 /*
1016 * Function: OH_NativeWindow_NativeWindowFlushBuffer
1017 * Type: Function
1018 * Rank: Important(2)
1019 * EnvConditions: N/A
1020 * CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer
1021 *                  2. check ret
1022  */
1023 HWTEST_F(NativeWindowTest, FlushBuffer003, Function | MediumTest | Level2)
1024 {
1025     int fenceFd = -1;
1026     struct Region *region = new Region();
1027     region->rectNumber = 0;
1028     region->rects = nullptr;
1029     ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
1030               OHOS::GSERROR_OK);
1031 
1032     region->rectNumber = 1;
1033     struct Region::Rect * rect = new Region::Rect();
1034     rect->x = 0x100;
1035     rect->y = 0x100;
1036     rect->w = 0x100;
1037     rect->h = 0x100;
1038     region->rects = rect;
1039     ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
1040               OHOS::SURFACE_ERROR_BUFFER_STATE_INVALID);
1041     delete rect;
1042     delete region;
1043 }
1044 constexpr int32_t MATRIX_SIZE = 16;
CheckMatricIsSame(float matrixOld[MATRIX_SIZE],float matrixNew[MATRIX_SIZE])1045 bool CheckMatricIsSame(float matrixOld[MATRIX_SIZE], float matrixNew[MATRIX_SIZE])
1046 {
1047     for (int32_t i = 0; i < MATRIX_SIZE; i++) {
1048         if (fabs(matrixOld[i] - matrixNew[i]) > 1e-6) {
1049             return false;
1050         }
1051     }
1052     return true;
1053 }
1054 
1055 /*
1056 * Function: OH_NativeWindow_GetLastFlushedBuffer
1057 * Type: Function
1058 * Rank: Important(2)
1059 * EnvConditions: N/A
1060 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
1061 *                  2. call OH_NativeWindow_NativeWindowFlushBuffer
1062 *                  3. call OH_NativeWindow_GetLastFlushedBuffer
1063 *                  4. check ret
1064  */
1065 HWTEST_F(NativeWindowTest, GetLastFlushedBuffer001, Function | MediumTest | Level2)
1066 {
1067     int code = SET_TRANSFORM;
1068     int32_t transform = GraphicTransformType::GRAPHIC_ROTATE_90;
1069     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, transform), OHOS::GSERROR_OK);
1070 
1071     code = SET_FORMAT;
1072     int32_t format = GRAPHIC_PIXEL_FMT_RGBA_8888;
1073     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, format), OHOS::GSERROR_OK);
1074 
1075     NativeWindowBuffer *nativeWindowBuffer = nullptr;
1076     int fenceFd = -1;
1077     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1078     ASSERT_EQ(ret, GSERROR_OK);
1079 
1080     struct Region *region = new Region();
1081     struct Region::Rect *rect = new Region::Rect();
1082     rect->x = 0x100;
1083     rect->y = 0x100;
1084     rect->w = 0x100;
1085     rect->h = 0x100;
1086     region->rects = rect;
1087     BufferHandle *bufferHanlde = OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer);
1088     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
1089     ASSERT_EQ(ret, GSERROR_OK);
1090     NativeWindowBuffer *lastFlushedBuffer;
1091     int lastFlushedFenceFd;
1092     float matrix[16];
1093     ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, nullptr, matrix),
1094         SURFACE_ERROR_INVALID_PARAM);
1095     ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
1096         OHOS::GSERROR_OK);
1097     BufferHandle *lastFlushedHanlde = OH_NativeWindow_GetBufferHandleFromNative(lastFlushedBuffer);
1098     ASSERT_EQ(bufferHanlde->virAddr, lastFlushedHanlde->virAddr);
1099 
1100     ASSERT_EQ(OH_NativeWindow_GetLastFlushedBufferV2(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
1101         OHOS::GSERROR_OK);
1102     float matrix90[16] = {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
1103     bool bRet = CheckMatricIsSame(matrix90, matrix);
1104     ASSERT_EQ(bRet, true);
1105 }
1106 
1107 /*
1108 * Function: OH_NativeWindow_GetLastFlushedBuffer
1109 * Type: Function
1110 * Rank: Important(2)
1111 * EnvConditions: N/A
1112 * CaseDescription: 1. call NativeWindowHandleOpt set BUFFER_USAGE_PROTECTED
1113 *                  2. call OH_NativeWindow_NativeWindowRequestBuffer
1114 *                  3. call OH_NativeWindow_NativeWindowFlushBuffer
1115 *                  4. call OH_NativeWindow_GetLastFlushedBuffer
1116 *                  5. check ret
1117  */
1118 HWTEST_F(NativeWindowTest, GetLastFlushedBuffer002, Function | MediumTest | Level2)
1119 {
1120     int code = SET_USAGE;
1121     uint64_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_PROTECTED;
1122     ASSERT_EQ(NativeWindowHandleOpt(nativeWindow, code, usage), OHOS::GSERROR_OK);
1123 
1124     NativeWindowBuffer* nativeWindowBuffer = nullptr;
1125     int fenceFd = -1;
1126     int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
1127     ASSERT_EQ(ret, GSERROR_OK);
1128 
1129     struct Region *region = new Region();
1130     struct Region::Rect *rect = new Region::Rect();
1131     rect->x = 0x100;
1132     rect->y = 0x100;
1133     rect->w = 0x100;
1134     rect->h = 0x100;
1135     region->rects = rect;
1136     ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
1137     ASSERT_EQ(ret, GSERROR_OK);
1138     NativeWindowBuffer* lastFlushedBuffer;
1139     int lastFlushedFenceFd;
1140     float matrix[16];
1141     ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
1142         OHOS::SURFACE_ERROR_NOT_SUPPORT);
1143 }
1144 
1145 /*
1146 * Function: OH_NativeWindow_SetColorSpace
1147 * Type: Function
1148 * Rank: Important(2)
1149 * EnvConditions: N/A
1150 * CaseDescription: 1. call OH_NativeWindow_SetColorSpace
1151 *                  2. check ret
1152  */
1153 HWTEST_F(NativeWindowTest, OH_NativeWindow_SetColorSpace001, Function | MediumTest | Level2)
1154 {
1155     OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_BT709_LIMIT;
1156     auto ret = OH_NativeWindow_GetColorSpace(nullptr, &colorSpace);
1157     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1158         ASSERT_NE(ret, GSERROR_INTERNAL);
1159     }
1160 }
1161 
1162 /*
1163 * Function: OH_NativeWindow_SetColorSpace
1164 * Type: Function
1165 * Rank: Important(2)
1166 * EnvConditions: N/A
1167 * CaseDescription: 1. call OH_NativeWindow_SetColorSpace
1168 *                  2. check ret
1169  */
1170 HWTEST_F(NativeWindowTest, OH_NativeWindow_SetColorSpace002, Function | MediumTest | Level2)
1171 {
1172     OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_BT709_LIMIT;
1173     auto ret = OH_NativeWindow_SetColorSpace(nativeWindow, colorSpace);
1174     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1175         ASSERT_EQ(ret, GSERROR_OK);
1176     }
1177 }
1178 
1179 /*
1180 * Function: OH_NativeWindow_GetColorSpace
1181 * Type: Function
1182 * Rank: Important(2)
1183 * EnvConditions: N/A
1184 * CaseDescription: 1. call OH_NativeWindow_GetColorSpace
1185 *                  2. check ret
1186  */
1187 HWTEST_F(NativeWindowTest, OH_NativeWindow_GetColorSpace001, Function | MediumTest | Level2)
1188 {
1189     OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_NONE;
1190     auto ret = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace);
1191     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1192         ASSERT_EQ(ret, GSERROR_OK);
1193     }
1194 }
1195 
1196 /*
1197 * Function: OH_NativeWindow_GetColorSpace
1198 * Type: Function
1199 * Rank: Important(2)
1200 * EnvConditions: N/A
1201 * CaseDescription: 1. call OH_NativeWindow_GetColorSpace
1202 *                  2. check ret
1203  */
1204 HWTEST_F(NativeWindowTest, OH_NativeWindow_GetColorSpace002, Function | MediumTest | Level2)
1205 {
1206     OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_NONE;
1207     OH_NativeBuffer_ColorSpace colorSpaceSet = OH_COLORSPACE_BT709_FULL;
1208     auto ret = OH_NativeWindow_SetColorSpace(nativeWindow, colorSpaceSet);
1209     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1210         ASSERT_EQ(ret, GSERROR_OK);
1211     }
1212     ret = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace);
1213     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1214         ASSERT_EQ(ret, GSERROR_OK);
1215         ASSERT_EQ(colorSpace, colorSpaceSet);
1216     }
1217 }
1218 
1219 /*
1220 * Function: OH_NativeWindow_SetMetadataValue
1221 * Type: Function
1222 * Rank: Important(2)
1223 * EnvConditions: N/A
1224 * CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
1225 *                  2. check ret
1226  */
1227 HWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue001, Function | MediumTest | Level2)
1228 {
1229     int len = 60;
1230     uint8_t buff[len];
1231     for (int i = 0; i < 60; ++i) {
1232         buff[i] = static_cast<uint8_t>(i);
1233     }
1234     int32_t buffSize;
1235     uint8_t *checkMetaData;
1236     auto ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &buffSize, &checkMetaData);
1237     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1238         ASSERT_NE(ret, GSERROR_OK);
1239     }
1240     ret = OH_NativeWindow_SetMetadataValue(nullptr, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
1241     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1242         ASSERT_NE(ret, GSERROR_OK);
1243     }
1244 }
1245 
1246 /*
1247 * Function: OH_NativeWindow_SetMetadataValue
1248 * Type: Function
1249 * Rank: Important(2)
1250 * EnvConditions: N/A
1251 * CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
1252 *                  2. check ret
1253  */
1254 HWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue002, Function | MediumTest | Level2)
1255 {
1256     int len = 60;
1257     uint8_t buff[len];
1258     for (int i = 0; i < 60; ++i) {
1259         buff[i] = static_cast<uint8_t>(i);
1260     }
1261     int32_t max_size = -1;
1262     auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)max_size, buff);
1263     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1264         ASSERT_NE(ret, GSERROR_OK);
1265     }
1266 }
1267 
1268 /*
1269 * Function: OH_NativeWindow_SetMetadataValue
1270 * Type: Function
1271 * Rank: Important(2)
1272 * EnvConditions: N/A
1273 * CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
1274 *                  2. check ret
1275  */
1276 HWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue003, Function | MediumTest | Level2)
1277 {
1278     int len = 60;
1279     uint8_t buff[len];
1280     for (int i = 0; i < 60; ++i) {
1281         buff[i] = static_cast<uint8_t>(i);
1282     }
1283     auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
1284     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1285         ASSERT_EQ(ret, GSERROR_OK);
1286     }
1287     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
1288     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1289         ASSERT_EQ(ret, GSERROR_OK);
1290     }
1291     OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HLG;
1292     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type),
1293                                            reinterpret_cast<uint8_t *>(&type));
1294     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1295         ASSERT_EQ(ret, GSERROR_OK);
1296     }
1297 }
1298 
1299 /*
1300 * Function: OH_NativeWindow_SetMetadataValue
1301 * Type: Function
1302 * Rank: Important(2)
1303 * EnvConditions: N/A
1304 * CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
1305 *                  2. check ret
1306  */
1307 HWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue004, Function | MediumTest | Level2)
1308 {
1309     int len = 60;
1310     uint8_t buff[len];
1311     for (int i = 0; i < 60; ++i) {
1312         buff[i] = static_cast<uint8_t>(i);
1313     }
1314     auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
1315     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1316         ASSERT_EQ(ret, GSERROR_OK);
1317     }
1318     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
1319     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1320         ASSERT_EQ(ret, GSERROR_OK);
1321     }
1322     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
1323     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1324         ASSERT_EQ(ret, GSERROR_OK);
1325     }
1326     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
1327     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1328         ASSERT_EQ(ret, GSERROR_OK);
1329     }
1330     OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HLG;
1331     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type),
1332                                            reinterpret_cast<uint8_t *>(&type));
1333     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1334         ASSERT_EQ(ret, GSERROR_OK);
1335     }
1336     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type),
1337                                            reinterpret_cast<uint8_t *>(&type));
1338     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1339         ASSERT_EQ(ret, GSERROR_OK);
1340     }
1341 }
1342 
1343 /*
1344 * Function: OH_NativeWindow_SetMetadataValue
1345 * Type: Function
1346 * Rank: Important(2)
1347 * EnvConditions: N/A
1348 * CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
1349 *                  2. check ret
1350  */
1351 HWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue005, Function | MediumTest | Level2)
1352 {
1353     int len = 60;
1354     uint8_t buff[len];
1355     for (int i = 0; i < 60; ++i) {
1356         buff[i] = static_cast<uint8_t>(i);
1357     }
1358     NativeWindowBuffer *nativeWindowbuffer1 = nullptr;
1359     int fenceFd = -1;
1360     int32_t err = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowbuffer1, &fenceFd);
1361     ASSERT_EQ(err, GSERROR_OK);
1362     auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
1363     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1364         ASSERT_EQ(ret, GSERROR_OK);
1365     }
1366     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
1367     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1368         ASSERT_EQ(ret, GSERROR_OK);
1369     }
1370     OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HLG;
1371     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type),
1372                                            reinterpret_cast<uint8_t *>(&type));
1373     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1374         ASSERT_EQ(ret, GSERROR_OK);
1375     }
1376 }
1377 
1378 /*
1379 * Function: OH_NativeWindow_GetMetadataValue
1380 * Type: Function
1381 * Rank: Important(2)
1382 * EnvConditions: N/A
1383 * CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
1384 *                  2. check ret
1385  */
1386 HWTEST_F(NativeWindowTest, OH_NativeWindow_GetMetadataValue001, Function | MediumTest | Level2)
1387 {
1388     int32_t buffSize;
1389     uint8_t *checkMetaData;
1390     auto ret = OH_NativeWindow_GetMetadataValue(nullptr, OH_HDR_STATIC_METADATA, &buffSize, &checkMetaData);
1391     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1392         ASSERT_NE(ret, GSERROR_OK);
1393     }
1394 }
1395 
1396 /*
1397 * Function: OH_NativeWindow_GetMetadataValue
1398 * Type: Function
1399 * Rank: Important(2)
1400 * EnvConditions: N/A
1401 * CaseDescription: 1. call OH_NativeWindow_GetMetadataValue
1402 *                  2. check ret
1403  */
1404 HWTEST_F(NativeWindowTest, OH_NativeWindow_GetMetadataValue002, Function | MediumTest | Level2)
1405 {
1406     uint8_t *checkMetaData;
1407     auto ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, nullptr, &checkMetaData);
1408     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1409         ASSERT_NE(ret, GSERROR_OK);
1410     }
1411 }
1412 
1413 /*
1414 * Function: OH_NativeWindow_SetMetadataValue
1415 * Type: Function
1416 * Rank: Important(2)
1417 * EnvConditions: N/A
1418 * CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
1419 *                  2. check ret
1420  */
1421 HWTEST_F(NativeWindowTest, OH_NativeWindow_GetMetadataValue003, Function | MediumTest | Level2)
1422 {
1423     int len = 60;
1424     uint8_t buff[len];
1425     for (int i = 0; i < 60; ++i) {
1426         buff[i] = static_cast<uint8_t>(60 - i);
1427     }
1428     int32_t buffSize;
1429     uint8_t *checkMetaData;
1430     auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
1431     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
1432         ASSERT_EQ(ret, GSERROR_OK);
1433     }
1434     ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &buffSize, &checkMetaData);
1435     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
1436         ASSERT_EQ(memcmp(checkMetaData, buff, 60), 0);
1437         delete[] checkMetaData;
1438         ASSERT_EQ(ret, GSERROR_OK);
1439     }
1440     for (int i = 0; i < 60; i++) {
1441         buff[i] = static_cast<uint8_t>(70 - i);
1442     }
1443     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
1444     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
1445         ASSERT_EQ(ret, GSERROR_OK);
1446     }
1447     ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &buffSize, &checkMetaData);
1448     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
1449         ASSERT_EQ(memcmp(checkMetaData, buff, 60), 0);
1450         delete[] checkMetaData;
1451         ASSERT_EQ(ret, GSERROR_OK);
1452     }
1453     OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HDR10;
1454     int32_t typeSize = sizeof(type);
1455     uint8_t pa = static_cast<uint8_t>(type);
1456     ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type), &pa);
1457     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
1458         ASSERT_EQ(ret, GSERROR_OK);
1459     }
1460     ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &typeSize, &checkMetaData);
1461     if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
1462         ASSERT_EQ(static_cast<uint8_t>(type), checkMetaData[0]);
1463         delete[] checkMetaData;
1464         ASSERT_EQ(ret, GSERROR_OK);
1465     }
1466 }
1467 /*
1468 * Function: OH_NativeWindow_NativeWindowAbortBuffer
1469 * Type: Function
1470 * Rank: Important(2)
1471 * EnvConditions: N/A
1472 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
1473 *                  2. check ret
1474  */
1475 HWTEST_F(NativeWindowTest, CancelBuffer001, Function | MediumTest | Level2)
1476 {
1477     ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
1478 }
1479 
1480 /*
1481 * Function: OH_NativeWindow_NativeWindowAbortBuffer
1482 * Type: Function
1483 * Rank: Important(2)
1484 * EnvConditions: N/A
1485 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
1486 *                  2. check ret
1487  */
1488 HWTEST_F(NativeWindowTest, CancelBuffer002, Function | MediumTest | Level2)
1489 {
1490     ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
1491 }
1492 
1493 /*
1494 * Function: OH_NativeWindow_NativeWindowAbortBuffer
1495 * Type: Function
1496 * Rank: Important(2)
1497 * EnvConditions: N/A
1498 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer
1499 *                  2. check ret
1500  */
1501 HWTEST_F(NativeWindowTest, CancelBuffer003, Function | MediumTest | Level2)
1502 {
1503     ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer), OHOS::GSERROR_OK);
1504 }
1505 
1506 /*
1507 * Function: OH_NativeWindow_NativeObjectReference
1508 * Type: Function
1509 * Rank: Important(2)
1510 * EnvConditions: N/A
1511 * CaseDescription: 1. call OH_NativeWindow_NativeObjectReference
1512 *                  2. check ret
1513  */
1514 HWTEST_F(NativeWindowTest, Reference001, Function | MediumTest | Level2)
1515 {
1516     struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
1517     buffer->sfbuffer = sBuffer;
1518     ASSERT_EQ(OH_NativeWindow_NativeObjectReference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
1519     delete buffer;
1520 }
1521 
1522 /*
1523 * Function: OH_NativeWindow_NativeObjectUnreference
1524 * Type: Function
1525 * Rank: Important(2)
1526 * EnvConditions: N/A
1527 * CaseDescription: 1. call OH_NativeWindow_NativeObjectUnreference
1528 *                  2. check ret
1529  */
1530 HWTEST_F(NativeWindowTest, Unreference001, Function | MediumTest | Level2)
1531 {
1532     struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
1533     buffer->sfbuffer = sBuffer;
1534     ASSERT_EQ(OH_NativeWindow_NativeObjectUnreference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
1535     delete buffer;
1536 }
1537 
1538 /*
1539 * Function: OH_NativeWindow_DestroyNativeWindow
1540 * Type: Function
1541 * Rank: Important(2)
1542 * EnvConditions: N/A
1543 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindow by abnormal input
1544 *                  2. check ret
1545  */
1546 HWTEST_F(NativeWindowTest, DestroyNativeWindow001, Function | MediumTest | Level2)
1547 {
1548     OH_NativeWindow_DestroyNativeWindow(nullptr);
1549 }
1550 
1551 /*
1552 * Function: OH_NativeWindow_DestroyNativeWindowBuffer
1553 * Type: Function
1554 * Rank: Important(2)
1555 * EnvConditions: N/A
1556 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer by abnormal input
1557 *                  2. check ret
1558  */
1559 HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer001, Function | MediumTest | Level2)
1560 {
1561     OH_NativeWindow_DestroyNativeWindowBuffer(nullptr);
1562 }
1563 
1564 /*
1565 * Function: OH_NativeWindow_NativeWindowSetScalingMode
1566 * Type: Function
1567 * Rank: Important(2)
1568 * EnvConditions: N/A
1569 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
1570  */
1571 HWTEST_F(NativeWindowTest, SetScalingMode001, Function | MediumTest | Level2)
1572 {
1573     OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
1574     ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nullptr, -1, scalingMode), OHOS::GSERROR_INVALID_ARGUMENTS);
1575 }
1576 
1577 /*
1578 * Function: OH_NativeWindow_NativeWindowSetScalingMode
1579 * Type: Function
1580 * Rank: Important(2)
1581 * EnvConditions: N/A
1582 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
1583  */
1584 HWTEST_F(NativeWindowTest, SetScalingMode002, Function | MediumTest | Level2)
1585 {
1586     OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
1587     ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, -1, scalingMode), OHOS::GSERROR_NO_ENTRY);
1588 }
1589 
1590 /*
1591 * Function: OH_NativeWindow_NativeWindowSetScalingMode
1592 * Type: Function
1593 * Rank: Important(2)
1594 * EnvConditions: N/A
1595 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
1596  */
1597 HWTEST_F(NativeWindowTest, SetScalingMode003, Function | MediumTest | Level2)
1598 {
1599     ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, firstSeqnum,
1600                                          static_cast<OHScalingMode>(OHScalingMode::OH_SCALING_MODE_NO_SCALE_CROP + 1)),
1601                                          OHOS::GSERROR_INVALID_ARGUMENTS);
1602 }
1603 
1604 /*
1605 * Function: OH_NativeWindow_NativeWindowSetScalingMode
1606 * Type: Function
1607 * Rank: Important(1)
1608 * EnvConditions: N/A
1609 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
1610 *                  2. call OH_NativeWindow_NativeWindowSetScalingMode with normal parameters and check ret
1611  */
1612 HWTEST_F(NativeWindowTest, SetScalingMode004, Function | MediumTest | Level1)
1613 {
1614     OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
1615     ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, firstSeqnum, scalingMode), OHOS::GSERROR_OK);
1616 }
1617 
1618 /*
1619 * Function: OH_NativeWindow_NativeWindowSetScalingModeV2
1620 * Type: Function
1621 * Rank: Important(1)
1622 * EnvConditions: N/A
1623 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingModeV2 with abnormal parameters and check ret
1624 *                  2. call OH_NativeWindow_NativeWindowSetScalingModeV2 with normal parameters and check ret
1625  */
1626 HWTEST_F(NativeWindowTest, SetScalingMode005, Function | MediumTest | Level1)
1627 {
1628     OHScalingModeV2 scalingMode = OHScalingModeV2::OH_SCALING_MODE_SCALE_TO_WINDOW_V2;
1629     ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingModeV2(nativeWindow, scalingMode), OHOS::GSERROR_OK);
1630 }
1631 
1632 
1633 /*
1634 * Function: OH_NativeWindow_NativeWindowSetMetaData
1635 * Type: Function
1636 * Rank: Important(2)
1637 * EnvConditions: N/A
1638 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1639  */
1640 HWTEST_F(NativeWindowTest, SetMetaData001, Function | MediumTest | Level2)
1641 {
1642     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nullptr, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
1643 }
1644 
1645 /*
1646 * Function: OH_NativeWindow_NativeWindowSetMetaData
1647 * Type: Function
1648 * Rank: Important(2)
1649 * EnvConditions: N/A
1650 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1651  */
1652 HWTEST_F(NativeWindowTest, SetMetaData002, Function | MediumTest | Level2)
1653 {
1654     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
1655 }
1656 
1657 /*
1658 * Function: OH_NativeWindow_NativeWindowSetMetaData
1659 * Type: Function
1660 * Rank: Important(2)
1661 * EnvConditions: N/A
1662 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1663 *                  2. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
1664  */
1665 HWTEST_F(NativeWindowTest, SetMetaData003, Function | MediumTest | Level2)
1666 {
1667     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, firstSeqnum, 0, nullptr),
1668               OHOS::GSERROR_INVALID_ARGUMENTS);
1669 }
1670 
1671 /*
1672 * Function: OH_NativeWindow_NativeWindowSetMetaData
1673 * Type: Function
1674 * Rank: Important(2)
1675 * EnvConditions: N/A
1676 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1677  */
1678 HWTEST_F(NativeWindowTest, SetMetaData004, Function | MediumTest | Level2)
1679 {
1680     int32_t size = 1;
1681     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, firstSeqnum, size, nullptr),
1682               OHOS::GSERROR_INVALID_ARGUMENTS);
1683 }
1684 
1685 /*
1686 * Function: OH_NativeWindow_NativeWindowSetMetaData
1687 * Type: Function
1688 * Rank: Important(2)
1689 * EnvConditions: N/A
1690 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
1691  */
1692 HWTEST_F(NativeWindowTest, SetMetaData005, Function | MediumTest | Level2)
1693 {
1694     int32_t size = 1;
1695     const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
1696     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, size, metaData), OHOS::GSERROR_NO_ENTRY);
1697 }
1698 
1699 /*
1700 * Function: OH_NativeWindow_NativeWindowSetMetaData
1701 * Type: Function
1702 * Rank: Important(1)
1703 * EnvConditions: N/A
1704 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
1705  */
1706 HWTEST_F(NativeWindowTest, SetMetaData006, Function | MediumTest | Level1)
1707 {
1708     int32_t size = 1;
1709     const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
1710     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, firstSeqnum, size, metaData), OHOS::GSERROR_OK);
1711 }
1712 
1713 /*
1714 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
1715 * Type: Function
1716 * Rank: Important(2)
1717 * EnvConditions: N/A
1718 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1719  */
1720 HWTEST_F(NativeWindowTest, SetMetaDataSet001, Function | MediumTest | Level2)
1721 {
1722     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1723     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nullptr, -1, key, 0, nullptr),
1724               OHOS::GSERROR_INVALID_ARGUMENTS);
1725 }
1726 
1727 /*
1728 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
1729 * Type: Function
1730 * Rank: Important(2)
1731 * EnvConditions: N/A
1732 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1733  */
1734 HWTEST_F(NativeWindowTest, SetMetaDataSet002, Function | MediumTest | Level2)
1735 {
1736     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1737     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, 0, nullptr),
1738               OHOS::GSERROR_INVALID_ARGUMENTS);
1739 }
1740 
1741 /*
1742 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
1743 * Type: Function
1744 * Rank: Important(2)
1745 * EnvConditions: N/A
1746 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1747  */
1748 HWTEST_F(NativeWindowTest, SetMetaDataSet003, Function | MediumTest | Level2)
1749 {
1750     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1751     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, firstSeqnum, key, 0, nullptr),
1752               OHOS::GSERROR_INVALID_ARGUMENTS);
1753 }
1754 
1755 /*
1756 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
1757 * Type: Function
1758 * Rank: Important(2)
1759 * EnvConditions: N/A
1760 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1761  */
1762 HWTEST_F(NativeWindowTest, SetMetaDataSet004, Function | MediumTest | Level2)
1763 {
1764     int32_t size = 1;
1765     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1766     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, firstSeqnum, key, size, nullptr),
1767               OHOS::GSERROR_INVALID_ARGUMENTS);
1768 }
1769 
1770 /*
1771 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
1772 * Type: Function
1773 * Rank: Important(2)
1774 * EnvConditions: N/A
1775 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
1776  */
1777 HWTEST_F(NativeWindowTest, SetMetaDataSet005, Function | MediumTest | Level2)
1778 {
1779     int32_t size = 1;
1780     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1781     const uint8_t metaData[] = {0};
1782     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, size, metaData),
1783               OHOS::GSERROR_NO_ENTRY);
1784 }
1785 
1786 /*
1787 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
1788 * Type: Function
1789 * Rank: Important(1)
1790 * EnvConditions: N/A
1791 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with normal parameters and check ret
1792  */
1793 HWTEST_F(NativeWindowTest, SetMetaDataSet006, Function | MediumTest | Level1)
1794 {
1795     int32_t size = 1;
1796     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
1797     const uint8_t metaData[] = {0};
1798     ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, firstSeqnum, key, size, metaData),
1799               OHOS::GSERROR_OK);
1800 }
1801 
1802 /*
1803 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
1804 * Type: Function
1805 * Rank: Important(2)
1806 * EnvConditions: N/A
1807 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
1808  */
1809 HWTEST_F(NativeWindowTest, SetTunnelHandle001, Function | MediumTest | Level2)
1810 {
1811     ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
1812 }
1813 
1814 /*
1815 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
1816 * Type: Function
1817 * Rank: Important(2)
1818 * EnvConditions: N/A
1819 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
1820  */
1821 HWTEST_F(NativeWindowTest, SetTunnelHandle002, Function | MediumTest | Level2)
1822 {
1823     ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
1824 }
1825 
1826 /*
1827 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
1828 * Type: Function
1829 * Rank: Important(2)
1830 * EnvConditions: N/A
1831 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
1832  */
1833 HWTEST_F(NativeWindowTest, SetTunnelHandle003, Function | MediumTest | Level2)
1834 {
1835     uint32_t reserveInts = 1;
1836     OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
1837     ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
1838     FreeOHExtDataHandle(handle);
1839 }
1840 
1841 /*
1842 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
1843 * Type: Function
1844 * Rank: Important(1)
1845 * EnvConditions: N/A
1846 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
1847 * @tc.require: issueI5GMZN issueI5IWHW
1848  */
1849 HWTEST_F(NativeWindowTest, SetTunnelHandle004, Function | MediumTest | Level1)
1850 {
1851     uint32_t reserveInts = 2;
1852     OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
1853     nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
1854     ASSERT_NE(nativeWindow, nullptr);
1855     ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
1856     ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_NO_ENTRY);
1857     FreeOHExtDataHandle(handle);
1858 }
1859 
1860 /*
1861 * Function: NativeWindowGetTransformHint
1862 * Type: Function
1863 * Rank: Important(1)
1864 * EnvConditions: N/A
1865 * CaseDescription: 1. call NativeWindowGetTransformHint with normal parameters and check ret
1866 * @tc.require: issueI5GMZN issueI5IWHW
1867  */
1868 HWTEST_F(NativeWindowTest, NativeWindowGetTransformHint001, Function | MediumTest | Level1)
1869 {
1870     OH_NativeBuffer_TransformType transform = OH_NativeBuffer_TransformType::NATIVEBUFFER_ROTATE_180;
1871     ASSERT_EQ(NativeWindowGetTransformHint(nullptr, &transform), OHOS::GSERROR_INVALID_ARGUMENTS);
1872     ASSERT_EQ(NativeWindowSetTransformHint(nullptr, transform), OHOS::GSERROR_INVALID_ARGUMENTS);
1873     ASSERT_EQ(NativeWindowSetTransformHint(nativeWindow, transform), OHOS::GSERROR_OK);
1874     transform = OH_NativeBuffer_TransformType::NATIVEBUFFER_ROTATE_NONE;
1875     ASSERT_EQ(NativeWindowGetTransformHint(nativeWindow, &transform), OHOS::GSERROR_OK);
1876     ASSERT_EQ(transform, OH_NativeBuffer_TransformType::NATIVEBUFFER_ROTATE_180);
1877 }
1878 
1879 /*
1880 * Function: NativeWindowGetDefaultWidthAndHeight
1881 * Type: Function
1882 * Rank: Important(1)
1883 * EnvConditions: N/A
1884 * CaseDescription: 1. call NativeWindowGetDefaultWidthAndHeight with normal parameters and check ret
1885 * @tc.require: issueI5GMZN issueI5IWHW
1886  */
1887 HWTEST_F(NativeWindowTest, NativeWindowGetDefaultWidthAndHeight001, Function | MediumTest | Level1)
1888 {
1889     ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nullptr, nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
1890     cSurface->SetDefaultWidthAndHeight(300, 400);
1891     int32_t width;
1892     int32_t height;
1893     ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindow, &width, &height), OHOS::GSERROR_OK);
1894     ASSERT_EQ(width, 300);
1895     ASSERT_EQ(height, 400);
1896 }
1897 
1898 /*
1899 * Function: NativeWindowSetBufferHold
1900 * Type: Function
1901 * Rank: Important(1)
1902 * EnvConditions: N/A
1903 * CaseDescription: 1. call NativeWindowSetBufferHold and no ret
1904 * @tc.require: issueI5GMZN issueI5IWHW
1905  */
1906 HWTEST_F(NativeWindowTest, NativeWindowSetBufferHold001, Function | MediumTest | Level1)
1907 {
1908     NativeWindowSetBufferHold(nullptr);
1909     NativeWindowSetBufferHold(nativeWindow);
1910     int fenceFd = -1;
1911     struct Region *region = new Region();
1912     region->rectNumber = 0;
1913     region->rects = nullptr;
1914     ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
1915               OHOS::GSERROR_BUFFER_STATE_INVALID);
1916     region->rectNumber = 1;
1917     struct Region::Rect * rect = new Region::Rect();
1918     rect->x = 0x100;
1919     rect->y = 0x100;
1920     rect->w = 0x100;
1921     rect->h = 0x100;
1922     region->rects = rect;
1923     ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
1924               OHOS::GSERROR_BUFFER_STATE_INVALID);
1925     delete rect;
1926     delete region;
1927     cSurface->SetBufferHold(false);
1928 }
1929 
1930 /*
1931 * Function: NativeWindow_ReadWriteWindow
1932 * Type: Function
1933 * Rank: Important(1)
1934 * EnvConditions: N/A
1935 * CaseDescription: 1. call OH_NativeWindow_WriteToParcel and OH_NativeWindow_ReadFromParcel
1936 * @tc.require: issueI5GMZN issueI5IWHW
1937  */
1938 HWTEST_F(NativeWindowTest, NativeWindowReadWriteWindow001, Function | MediumTest | Level1)
1939 {
1940     using namespace OHOS;
1941     sptr<OHOS::IConsumerSurface> cSurface = IConsumerSurface::Create();
1942     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
1943     cSurface->RegisterConsumerListener(listener);
1944     sptr<OHOS::IBufferProducer> producer = cSurface->GetProducer();
1945     sptr<OHOS::Surface> pSurface = Surface::CreateSurfaceAsProducer(producer);
1946     OHNativeWindow* nativeWindow = CreateNativeWindowFromSurface(&pSurface);
1947     auto uniqueId = nativeWindow->surface->GetUniqueId();
1948     ASSERT_NE(nativeWindow, nullptr);
1949     OHIPCParcel *parcel1 = OH_IPCParcel_Create();
1950     OHIPCParcel *parcel2 = OH_IPCParcel_Create();
1951     ASSERT_NE(parcel1, nullptr);
1952     ASSERT_NE(parcel2, nullptr);
1953     ASSERT_EQ(OH_NativeWindow_WriteToParcel(nullptr, parcel1), SURFACE_ERROR_INVALID_PARAM);
1954     ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow, nullptr), SURFACE_ERROR_INVALID_PARAM);
1955     auto innerParcel = parcel1->msgParcel;
1956     parcel1->msgParcel = nullptr;
1957     ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow, parcel1), SURFACE_ERROR_INVALID_PARAM);
1958     parcel1->msgParcel = innerParcel;
1959     ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow, parcel1), GSERROR_OK);
1960     ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow, parcel2), GSERROR_OK);
1961     // test read
1962     OHNativeWindow *readWindow = nullptr;
1963     ASSERT_EQ(OH_NativeWindow_ReadFromParcel(nullptr, &readWindow), SURFACE_ERROR_INVALID_PARAM);
1964     ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, &readWindow), GSERROR_OK);
1965     ASSERT_NE(readWindow, nullptr);
1966     // test read twice
1967     OHNativeWindow *tempWindow = nullptr;
1968     ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, &tempWindow), SURFACE_ERROR_INVALID_PARAM);
1969     cout << "test read write window, write window is " << nativeWindow << ", read windows is " << readWindow << endl;
1970     auto readId = readWindow->surface->GetUniqueId();
1971     ASSERT_EQ(uniqueId, readId);
1972     OHNativeWindow *readWindow1 = nullptr;
1973     SurfaceUtils::GetInstance()->RemoveNativeWindow(uniqueId);
1974     ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel2, &readWindow1), GSERROR_OK);
1975     ASSERT_NE(readWindow1, nativeWindow);
1976     auto readId1 = readWindow1->surface->GetUniqueId();
1977     ASSERT_EQ(uniqueId, readId1);
1978     cout << "write uniqueId is " << uniqueId << ", parcel1 read id is " << readId <<
1979         ", parcel2 read id is " << readId1 << endl;
1980     OH_NativeWindow_DestroyNativeWindow(readWindow1);
1981     OH_NativeWindow_DestroyNativeWindow(nativeWindow);
1982     OH_IPCParcel_Destroy(parcel1);
1983     OH_IPCParcel_Destroy(parcel2);
1984 }
1985 
1986 /*
1987 * Function: NativeWindow_ReadWriteWindow
1988 * Type: Function
1989 * Rank: Important(1)
1990 * EnvConditions: N/A
1991 * CaseDescription: 1. call OH_NativeWindow_WriteToParcel and OH_NativeWindow_ReadFromParcel
1992 * @tc.require: issueI5GMZN issueI5IWHW
1993  */
1994 HWTEST_F(NativeWindowTest, NativeWindowReadWriteWindow002, Function | MediumTest | Level1)
1995 {
1996     using namespace OHOS;
1997     // test for no surface->GetUniqueId
1998     OHNativeWindow* nativeWindow1 = new OHNativeWindow();
1999     ASSERT_NE(nativeWindow1, nullptr);
2000     OHIPCParcel *parcel1 = OH_IPCParcel_Create();
2001     ASSERT_NE(parcel1, nullptr);
2002     ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow1, parcel1), SURFACE_ERROR_INVALID_PARAM);
2003     OHNativeWindow *readWindow = nullptr;
2004     ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, nullptr), SURFACE_ERROR_INVALID_PARAM);
2005     ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, &readWindow), SURFACE_ERROR_INVALID_PARAM);
2006     OH_IPCParcel_Destroy(parcel1);
2007     delete nativeWindow1;
2008 }
2009 
2010 /*
2011 * Function: SurfaceErrorInvalidParameter
2012 * Type: Function
2013 * Rank: Important(2)
2014 * EnvConditions: N/A
2015 * CaseDescription: 1. call functions with invalid parameters and check ret
2016 */
2017 HWTEST_F(NativeWindowTest, SurfaceErrorInvalidParameter001, Function | MediumTest | Level2)
2018 {
2019     int fence = -1;
2020     ASSERT_EQ(OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nullptr), nullptr);
2021     ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nullptr, nullptr, &fence, nullptr), SURFACE_ERROR_INVALID_PARAM);
2022     ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, nullptr, &fence, nullptr),
2023         SURFACE_ERROR_INVALID_PARAM);
2024     ASSERT_EQ(GetNativeObjectMagic(nullptr), -1);
2025     ASSERT_EQ(GetSurfaceId(nativeWindow, nullptr), SURFACE_ERROR_INVALID_PARAM);
2026     ASSERT_EQ(NativeWindowGetTransformHint(nativeWindow, nullptr), SURFACE_ERROR_INVALID_PARAM);
2027     ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindow, nullptr, nullptr), SURFACE_ERROR_INVALID_PARAM);
2028     int32_t width;
2029     ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindow, &width, nullptr), SURFACE_ERROR_INVALID_PARAM);
2030     ASSERT_EQ(OH_NativeWindow_GetLastFlushedBufferV2(nullptr, nullptr, &fence, nullptr), SURFACE_ERROR_INVALID_PARAM);
2031     ASSERT_EQ(OH_NativeWindow_GetLastFlushedBufferV2(nativeWindow, nullptr, &fence, nullptr),
2032         SURFACE_ERROR_INVALID_PARAM);
2033     ASSERT_EQ(OH_NativeWindow_GetLastFlushedBufferV2(nativeWindow, nullptr, nullptr, nullptr),
2034         SURFACE_ERROR_INVALID_PARAM);
2035     ASSERT_EQ(NativeWindowDisconnect(nullptr), SURFACE_ERROR_INVALID_PARAM);
2036     ASSERT_EQ(OH_NativeWindow_SetColorSpace(nullptr, OH_COLORSPACE_NONE), SURFACE_ERROR_INVALID_PARAM);
2037     ASSERT_EQ(OH_NativeWindow_GetColorSpace(nullptr, nullptr), SURFACE_ERROR_INVALID_PARAM);
2038     ASSERT_EQ(OH_NativeWindow_GetColorSpace(nativeWindow, nullptr), SURFACE_ERROR_INVALID_PARAM);
2039     ASSERT_EQ(OH_NativeWindow_GetMetadataValue(nullptr, OH_HDR_METADATA_TYPE, nullptr, nullptr),
2040         SURFACE_ERROR_INVALID_PARAM);
2041     ASSERT_EQ(OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, nullptr, nullptr),
2042         SURFACE_ERROR_INVALID_PARAM);
2043 }
2044 
2045 /*
2046 * Function: SurfaceErrorInvalidParameter
2047 * Type: Function
2048 * Rank: Important(2)
2049 * EnvConditions: N/A
2050 * CaseDescription: 1. call functions with invalid parameters and check ret
2051 */
2052 HWTEST_F(NativeWindowTest, SurfaceErrorInvalidParameter002, Function | MediumTest | Level2)
2053 {
2054     OHNativeWindow *nativeWindowTemp = new OHNativeWindow();
2055     NativeWindowBuffer *nativeWindowBuffer1;
2056     Region region;
2057     int32_t height;
2058     int32_t width;
2059     int fence = -1;
2060     ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer1, nullptr),
2061         SURFACE_ERROR_INVALID_PARAM);
2062     ASSERT_EQ(NativeWindowFlushBuffer(nativeWindowTemp, nativeWindowBuffer, fence, region),
2063         SURFACE_ERROR_INVALID_PARAM);
2064     ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTemp, 0), OHOS::GSERROR_INVALID_ARGUMENTS);
2065     OHScalingMode scalingMode1 = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
2066     OHScalingModeV2 scalingMode2 = OHScalingModeV2::OH_SCALING_MODE_SCALE_TO_WINDOW_V2;
2067     ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindowTemp, firstSeqnum, scalingMode1),
2068         OHOS::GSERROR_INVALID_ARGUMENTS);
2069     ASSERT_EQ(NativeWindowSetScalingModeV2(nativeWindowTemp, scalingMode2), OHOS::GSERROR_INVALID_ARGUMENTS);
2070     ASSERT_EQ(NativeWindowSetScalingModeV2(nullptr, scalingMode2), OHOS::GSERROR_INVALID_ARGUMENTS);
2071     ASSERT_EQ(NativeWindowSetMetaData(nativeWindowTemp, 0, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
2072     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
2073     ASSERT_EQ(NativeWindowSetMetaDataSet(nativeWindowTemp, 0, key, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
2074     OHExtDataHandle *handle = AllocOHExtDataHandle(1);
2075     ASSERT_EQ(NativeWindowSetTunnelHandle(nativeWindowTemp, handle), OHOS::GSERROR_INVALID_ARGUMENTS);
2076     OH_NativeBuffer_TransformType transform = OH_NativeBuffer_TransformType::NATIVEBUFFER_ROTATE_180;
2077     ASSERT_EQ(NativeWindowGetTransformHint(nativeWindowTemp, &transform), OHOS::GSERROR_INVALID_ARGUMENTS);
2078     ASSERT_EQ(NativeWindowSetTransformHint(nativeWindowTemp, transform), OHOS::GSERROR_INVALID_ARGUMENTS);
2079     ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindowTemp, &width, &height), OHOS::GSERROR_INVALID_ARGUMENTS);
2080     NativeWindowSetBufferHold(nativeWindowTemp);
2081 }
2082 
2083 /*
2084 * Function: NativeWindowSetRequestWidthAndHeight
2085 * Type: Function
2086 * Rank: Important(2)
2087 * EnvConditions: N/A
2088 * CaseDescription: 1. call NativeWindowSetRequestWidthAndHeight with invalid parameters and check ret
2089 *                  2. call NativeWindowSetRequestWidthAndHeight with normal parameters and check ret
2090 *                  3. call NativeWindowSetRequestWidthAndHeight with zore width and check ret
2091 *                  3. call NativeWindowSetRequestWidthAndHeight with zore height and check ret
2092  */
2093 HWTEST_F(NativeWindowTest, NativeWindowSetRequestWidthAndHeight001, Function | MediumTest | Level2)
2094 {
2095     int fence = -1;
2096     ASSERT_EQ(NativeWindowSetRequestWidthAndHeight(nullptr, 0, 0), SURFACE_ERROR_INVALID_PARAM);
2097     cSurface->SetDefaultWidthAndHeight(300, 400);
2098     //分支1:走使用requestWidth/Height新建config分支
2099     ASSERT_EQ(NativeWindowSetRequestWidthAndHeight(nativeWindow, 100, 200), OHOS::GSERROR_OK);
2100     NativeWindowBuffer *nativeWindowBuffer1 = nullptr;
2101     ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer1, &fence), GSERROR_OK);
2102     ASSERT_EQ(nativeWindowBuffer1->sfbuffer->GetWidth(), 100);
2103     ASSERT_EQ(nativeWindowBuffer1->sfbuffer->GetHeight(), 200);
2104     ASSERT_EQ(NativeWindowCancelBuffer(nativeWindow, nativeWindowBuffer1), GSERROR_OK);
2105     //分支2:使用surface成员变量windowConfig_(未初始化)
2106     ASSERT_EQ(NativeWindowSetRequestWidthAndHeight(nativeWindow, 0, 200), OHOS::GSERROR_OK);
2107     ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer1, &fence),
2108         SURFACE_ERROR_UNKOWN);
2109     ASSERT_EQ(NativeWindowSetRequestWidthAndHeight(nativeWindow, 100, 0), OHOS::GSERROR_OK);
2110     ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer1, &fence),
2111         SURFACE_ERROR_UNKOWN);
2112 }
2113 
2114 /*
2115 * Function: OH_NativeWindow_DestroyNativeWindowBuffer
2116 * Type: Function
2117 * Rank: Important(2)
2118 * EnvConditions: N/A
2119 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer again
2120 *                  2. check ret
2121  */
2122 HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer002, Function | MediumTest | Level2)
2123 {
2124     ASSERT_NE(nativeWindowBuffer, nullptr);
2125     OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
2126 }
2127 }
2128