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