• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <gtest/gtest.h>
16 #include "iconsumer_surface.h"
17 #include <iservice_registry.h>
18 #include <native_window.h>
19 #include <securec.h>
20 #include <ctime>
21 #include "buffer_log.h"
22 #include "external_window.h"
23 #include "surface_utils.h"
24 #include "sync_fence.h"
25 #include "ipc_inner_object.h"
26 #include "ipc_cparcel.h"
27 
28 using namespace std;
29 using namespace testing;
30 using namespace testing::ext;
31 
32 namespace OHOS::Rosen {
33 class BufferConsumerListener : public IBufferConsumerListener {
34 public:
OnBufferAvailable()35     void OnBufferAvailable() override
36     {
37     }
38 };
39 
AllocOHExtDataHandle(uint32_t reserveInts)40 static OHExtDataHandle *AllocOHExtDataHandle(uint32_t reserveInts)
41 {
42     size_t handleSize = sizeof(OHExtDataHandle) + (sizeof(int32_t) * reserveInts);
43     OHExtDataHandle *handle = static_cast<OHExtDataHandle *>(malloc(handleSize));
44     if (handle == nullptr) {
45         BLOGE("AllocOHExtDataHandle malloc %zu failed", handleSize);
46         return nullptr;
47     }
48     auto ret = memset_s(handle, handleSize, 0, handleSize);
49     if (ret != EOK) {
50         BLOGE("AllocOHExtDataHandle memset_s failed");
51         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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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 */
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  */
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  */
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  */
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  */
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  */
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