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