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 "buffer_log.h"
21 #include "external_window.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS::Rosen {
27 class BufferConsumerListener : public IBufferConsumerListener {
28 public:
OnBufferAvailable()29 void OnBufferAvailable() override
30 {
31 }
32 };
33
AllocOHExtDataHandle(uint32_t reserveInts)34 static OHExtDataHandle *AllocOHExtDataHandle(uint32_t reserveInts)
35 {
36 size_t handleSize = sizeof(OHExtDataHandle) + (sizeof(int32_t) * reserveInts);
37 OHExtDataHandle *handle = static_cast<OHExtDataHandle *>(malloc(handleSize));
38 if (handle == nullptr) {
39 BLOGE("AllocOHExtDataHandle malloc %zu failed", handleSize);
40 return nullptr;
41 }
42 auto ret = memset_s(handle, handleSize, 0, handleSize);
43 if (ret != EOK) {
44 BLOGE("AllocOHExtDataHandle memset_s failed");
45 return nullptr;
46 }
47 handle->fd = -1;
48 handle->reserveInts = reserveInts;
49 for (uint32_t i = 0; i < reserveInts; i++) {
50 handle->reserve[i] = -1;
51 }
52 return handle;
53 }
54
FreeOHExtDataHandle(OHExtDataHandle * handle)55 static void FreeOHExtDataHandle(OHExtDataHandle *handle)
56 {
57 if (handle == nullptr) {
58 BLOGW("FreeOHExtDataHandle with nullptr handle");
59 return ;
60 }
61 if (handle->fd >= 0) {
62 close(handle->fd);
63 handle->fd = -1;
64 }
65 free(handle);
66 }
67
68 class NativeWindowTest : public testing::Test {
69 public:
70 static void SetUpTestCase();
71 static void TearDownTestCase();
72
73 static inline BufferRequestConfig requestConfig = {};
74 static inline BufferFlushConfig flushConfig = {};
75 static inline sptr<OHOS::IConsumerSurface> cSurface = nullptr;
76 static inline sptr<OHOS::IBufferProducer> producer = nullptr;
77 static inline sptr<OHOS::Surface> pSurface = nullptr;
78 static inline sptr<OHOS::SurfaceBuffer> sBuffer = nullptr;
79 static inline NativeWindow* nativeWindow = nullptr;
80 static inline NativeWindowBuffer* nativeWindowBuffer = nullptr;
81 };
82
SetUpTestCase()83 void NativeWindowTest::SetUpTestCase()
84 {
85 requestConfig = {
86 .width = 0x100, // small
87 .height = 0x100, // small
88 .strideAlignment = 0x8,
89 .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
90 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
91 .timeout = 0,
92 };
93
94 cSurface = IConsumerSurface::Create();
95 sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
96 cSurface->RegisterConsumerListener(listener);
97 producer = cSurface->GetProducer();
98 pSurface = Surface::CreateSurfaceAsProducer(producer);
99 int32_t fence;
100 pSurface->RequestBuffer(sBuffer, fence, requestConfig);
101 }
102
TearDownTestCase()103 void NativeWindowTest::TearDownTestCase()
104 {
105 flushConfig = { .damage = {
106 .w = 0x100,
107 .h = 0x100,
108 } };
109 pSurface->FlushBuffer(sBuffer, -1, flushConfig);
110 sBuffer = nullptr;
111 cSurface = nullptr;
112 producer = nullptr;
113 pSurface = nullptr;
114 OH_NativeWindow_DestroyNativeWindow(nativeWindow);
115 nativeWindow = nullptr;
116 nativeWindowBuffer = nullptr;
117 }
118
119 /*
120 * Function: OH_NativeWindow_CreateNativeWindow
121 * Type: Function
122 * Rank: Important(2)
123 * EnvConditions: N/A
124 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow by abnormal input
125 * 2. check ret
126 */
127 HWTEST_F(NativeWindowTest, CreateNativeWindow001, Function | MediumTest | Level2)
128 {
129 ASSERT_EQ(OH_NativeWindow_CreateNativeWindow(nullptr), nullptr);
130 }
131
132 /*
133 * Function: OH_NativeWindow_CreateNativeWindow
134 * Type: Function
135 * Rank: Important(2)
136 * EnvConditions: N/A
137 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow
138 * 2. check ret
139 */
140 HWTEST_F(NativeWindowTest, CreateNativeWindow002, Function | MediumTest | Level2)
141 {
142 nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
143 ASSERT_NE(nativeWindow, nullptr);
144 }
145
146 /*
147 * Function: OH_NativeWindow_NativeWindowHandleOpt
148 * Type: Function
149 * Rank: Important(2)
150 * EnvConditions: N/A
151 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by abnormal input
152 * 2. check ret
153 */
154 HWTEST_F(NativeWindowTest, HandleOpt001, Function | MediumTest | Level2)
155 {
156 int code = SET_USAGE;
157 uint64_t usage = BUFFER_USAGE_CPU_READ;
158 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nullptr, code, usage), OHOS::GSERROR_INVALID_ARGUMENTS);
159 }
160
161 /*
162 * Function: OH_NativeWindow_NativeWindowHandleOpt
163 * Type: Function
164 * Rank: Important(2)
165 * EnvConditions: N/A
166 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
167 * 2. check ret
168 */
169 HWTEST_F(NativeWindowTest, HandleOpt002, Function | MediumTest | Level2)
170 {
171 int code = SET_USAGE;
172 uint64_t usageSet = BUFFER_USAGE_CPU_READ;
173 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), OHOS::GSERROR_OK);
174
175 code = GET_USAGE;
176 uint64_t usageGet = BUFFER_USAGE_CPU_WRITE;
177 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &usageGet), OHOS::GSERROR_OK);
178 ASSERT_EQ(usageSet, usageGet);
179 }
180
181 /*
182 * Function: OH_NativeWindow_NativeWindowHandleOpt
183 * Type: Function
184 * Rank: Important(2)
185 * EnvConditions: N/A
186 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
187 * 2. check ret
188 */
189 HWTEST_F(NativeWindowTest, HandleOpt003, Function | MediumTest | Level2)
190 {
191 int code = SET_BUFFER_GEOMETRY;
192 int32_t heightSet = 0x100;
193 int32_t widthSet = 0x100;
194 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, heightSet, widthSet), OHOS::GSERROR_OK);
195
196 code = GET_BUFFER_GEOMETRY;
197 int32_t heightGet = 0;
198 int32_t widthGet = 0;
199 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &heightGet, &widthGet), OHOS::GSERROR_OK);
200 ASSERT_EQ(heightSet, heightGet);
201 ASSERT_EQ(widthSet, widthGet);
202 }
203
204 /*
205 * Function: OH_NativeWindow_NativeWindowHandleOpt
206 * Type: Function
207 * Rank: Important(2)
208 * EnvConditions: N/A
209 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
210 * 2. check ret
211 */
212 HWTEST_F(NativeWindowTest, HandleOpt004, Function | MediumTest | Level2)
213 {
214 int code = SET_FORMAT;
215 int32_t formatSet = GRAPHIC_PIXEL_FMT_RGBA_8888;
216 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), OHOS::GSERROR_OK);
217
218 code = GET_FORMAT;
219 int32_t formatGet = GRAPHIC_PIXEL_FMT_CLUT8;
220 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &formatGet), OHOS::GSERROR_OK);
221 ASSERT_EQ(formatSet, formatGet);
222 }
223
224 /*
225 * Function: OH_NativeWindow_NativeWindowHandleOpt
226 * Type: Function
227 * Rank: Important(2)
228 * EnvConditions: N/A
229 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
230 * 2. check ret
231 */
232 HWTEST_F(NativeWindowTest, HandleOpt005, Function | MediumTest | Level2)
233 {
234 int code = SET_STRIDE;
235 int32_t strideSet = 0x8;
236 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, strideSet), OHOS::GSERROR_OK);
237
238 code = GET_STRIDE;
239 int32_t strideGet = 0;
240 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &strideGet), OHOS::GSERROR_OK);
241 ASSERT_EQ(strideSet, strideGet);
242 }
243
244 /*
245 * Function: OH_NativeWindow_NativeWindowHandleOpt
246 * Type: Function
247 * Rank: Important(2)
248 * EnvConditions: N/A
249 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
250 * 2. check ret
251 */
252 HWTEST_F(NativeWindowTest, HandleOpt006, Function | MediumTest | Level2)
253 {
254 int code = SET_COLOR_GAMUT;
255 int32_t colorGamutSet = static_cast<int32_t>(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
256 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, colorGamutSet), OHOS::GSERROR_OK);
257
258 code = GET_COLOR_GAMUT;
259 int32_t colorGamutGet = 0;
260 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &colorGamutGet), OHOS::GSERROR_OK);
261 ASSERT_EQ(colorGamutSet, colorGamutGet);
262 }
263
264 /*
265 * Function: OH_NativeWindow_NativeWindowHandleOpt
266 * Type: Function
267 * Rank: Important(2)
268 * EnvConditions: N/A
269 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
270 * 2. check ret
271 */
272 HWTEST_F(NativeWindowTest, HandleOpt007, Function | MediumTest | Level2)
273 {
274 int code = SET_TIMEOUT;
275 int32_t timeoutSet = 10; // 10: for test
276 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, timeoutSet), OHOS::GSERROR_OK);
277
278 code = GET_TIMEOUT;
279 int32_t timeoutGet = 0;
280 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &timeoutGet), OHOS::GSERROR_OK);
281 ASSERT_EQ(timeoutSet, timeoutGet);
282 }
283
284 /*
285 * Function: OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
286 * Type: Function
287 * Rank: Important(2)
288 * EnvConditions: N/A
289 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer by abnormal input
290 * 2. check ret
291 */
292 HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer001, Function | MediumTest | Level2)
293 {
294 ASSERT_EQ(OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(nullptr), nullptr);
295 }
296
297 /*
298 * Function: OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
299 * Type: Function
300 * Rank: Important(2)
301 * EnvConditions: N/A
302 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
303 * 2. check ret
304 */
305 HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer002, Function | MediumTest | Level2)
306 {
307 nativeWindowBuffer = OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(&sBuffer);
308 ASSERT_NE(nativeWindowBuffer, nullptr);
309 }
310
311 /*
312 * Function: OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
313 * Type: Function
314 * Rank: Important(2)
315 * EnvConditions: N/A
316 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
317 * 2. check ret
318 */
319 HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer003, Function | MediumTest | Level2)
320 {
321 OH_NativeBuffer* nativeBuffer = sBuffer->SurfaceBufferToNativeBuffer();
322 ASSERT_NE(nativeBuffer, nullptr);
323 NativeWindowBuffer* nwBuffer = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nativeBuffer);
324 ASSERT_NE(nwBuffer, nullptr);
325 OH_NativeWindow_DestroyNativeWindowBuffer(nwBuffer);
326 }
327
328 /*
329 * Function: OH_NativeWindow_NativeWindowRequestBuffer
330 * Type: Function
331 * Rank: Important(2)
332 * EnvConditions: N/A
333 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
334 * 2. check ret
335 */
336 HWTEST_F(NativeWindowTest, RequestBuffer001, Function | MediumTest | Level2)
337 {
338 ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nullptr, &nativeWindowBuffer, nullptr),
339 OHOS::GSERROR_INVALID_ARGUMENTS);
340 }
341
342 /*
343 * Function: OH_NativeWindow_NativeWindowRequestBuffer
344 * Type: Function
345 * Rank: Important(2)
346 * EnvConditions: N/A
347 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
348 * 2. check ret
349 */
350 HWTEST_F(NativeWindowTest, RequestBuffer002, Function | MediumTest | Level2)
351 {
352 ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, nullptr, nullptr),
353 OHOS::GSERROR_INVALID_ARGUMENTS);
354 }
355
356 /*
357 * Function: OH_NativeWindow_GetBufferHandleFromNative
358 * Type: Function
359 * Rank: Important(2)
360 * EnvConditions: N/A
361 * CaseDescription: 1. call OH_NativeWindow_GetBufferHandleFromNative by abnormal input
362 * 2. check ret
363 */
364 HWTEST_F(NativeWindowTest, GetBufferHandle001, Function | MediumTest | Level2)
365 {
366 ASSERT_EQ(OH_NativeWindow_GetBufferHandleFromNative(nullptr), nullptr);
367 }
368
369 /*
370 * Function: OH_NativeWindow_GetBufferHandleFromNative
371 * Type: Function
372 * Rank: Important(2)
373 * EnvConditions: N/A
374 * CaseDescription: 1. call OH_NativeWindow_GetBufferHandleFromNative
375 * 2. check ret
376 */
377 HWTEST_F(NativeWindowTest, GetBufferHandle002, Function | MediumTest | Level2)
378 {
379 struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
380 buffer->sfbuffer = sBuffer;
381 ASSERT_NE(OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer), nullptr);
382 delete buffer;
383 }
384
385 /*
386 * Function: OH_NativeWindow_NativeWindowFlushBuffer
387 * Type: Function
388 * Rank: Important(2)
389 * EnvConditions: N/A
390 * CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
391 * 2. check ret
392 */
393 HWTEST_F(NativeWindowTest, FlushBuffer001, Function | MediumTest | Level2)
394 {
395 int fenceFd = -1;
396 struct Region *region = new Region();
397 struct Region::Rect * rect = new Region::Rect();
398 rect->x = 0x100;
399 rect->y = 0x100;
400 rect->w = 0x100;
401 rect->h = 0x100;
402 region->rects = rect;
403
404 ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nullptr, nullptr, fenceFd, *region),
405 OHOS::GSERROR_INVALID_ARGUMENTS);
406 delete region;
407 }
408
409 /*
410 * Function: OH_NativeWindow_NativeWindowFlushBuffer
411 * Type: Function
412 * Rank: Important(2)
413 * EnvConditions: N/A
414 * CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
415 * 2. check ret
416 */
417 HWTEST_F(NativeWindowTest, FlushBuffer002, Function | MediumTest | Level2)
418 {
419 int fenceFd = -1;
420 struct Region *region = new Region();
421 struct Region::Rect * rect = new Region::Rect();
422 rect->x = 0x100;
423 rect->y = 0x100;
424 rect->w = 0x100;
425 rect->h = 0x100;
426 region->rects = rect;
427
428 ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nullptr, fenceFd, *region),
429 OHOS::GSERROR_INVALID_ARGUMENTS);
430 delete region;
431 }
432
433 /*
434 * Function: OH_NativeWindow_NativeWindowFlushBuffer
435 * Type: Function
436 * Rank: Important(2)
437 * EnvConditions: N/A
438 * CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer
439 * 2. check ret
440 */
441 HWTEST_F(NativeWindowTest, FlushBuffer003, Function | MediumTest | Level2)
442 {
443 int fenceFd = -1;
444 struct Region *region = new Region();
445 region->rectNumber = 0;
446 region->rects = nullptr;
447 ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
448 OHOS::GSERROR_OK);
449
450 region->rectNumber = 1;
451 struct Region::Rect * rect = new Region::Rect();
452 rect->x = 0x100;
453 rect->y = 0x100;
454 rect->w = 0x100;
455 rect->h = 0x100;
456 region->rects = rect;
457 ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
458 OHOS::GSERROR_OK);
459 delete rect;
460 delete region;
461 }
462
463 /*
464 * Function: OH_NativeWindow_GetLastFlushedBuffer
465 * Type: Function
466 * Rank: Important(2)
467 * EnvConditions: N/A
468 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
469 * 2. call OH_NativeWindow_NativeWindowFlushBuffer
470 * 3. call OH_NativeWindow_GetLastFlushedBuffer
471 * 4. check ret
472 */
473 HWTEST_F(NativeWindowTest, GetLastFlushedBuffer001, Function | MediumTest | Level2)
474 {
475 NativeWindowBuffer *nativeWindowBuffer = nullptr;
476 int fenceFd = -1;
477 int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
478 ASSERT_EQ(ret, GSERROR_OK);
479
480 struct Region *region = new Region();
481 struct Region::Rect *rect = new Region::Rect();
482 rect->x = 0x100;
483 rect->y = 0x100;
484 rect->w = 0x100;
485 rect->h = 0x100;
486 region->rects = rect;
487 BufferHandle *bufferHanlde = OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer);
488 ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
489 ASSERT_EQ(ret, GSERROR_OK);
490 NativeWindowBuffer *lastFlushedBuffer;
491 int lastFlushedFenceFd;
492 float matrix[16];
493 ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
494 OHOS::GSERROR_OK);
495 BufferHandle *lastFlushedHanlde = OH_NativeWindow_GetBufferHandleFromNative(lastFlushedBuffer);
496 ASSERT_EQ(bufferHanlde->virAddr, lastFlushedHanlde->virAddr);
497 }
498
499 /*
500 * Function: OH_NativeWindow_GetLastFlushedBuffer
501 * Type: Function
502 * Rank: Important(2)
503 * EnvConditions: N/A
504 * CaseDescription: 1. call NativeWindowHandleOpt set BUFFER_USAGE_PROTECTED
505 * 2. call OH_NativeWindow_NativeWindowRequestBuffer
506 * 3. call OH_NativeWindow_NativeWindowFlushBuffer
507 * 4. call OH_NativeWindow_GetLastFlushedBuffer
508 * 5. check ret
509 */
510 HWTEST_F(NativeWindowTest, GetLastFlushedBuffer002, Function | MediumTest | Level2)
511 {
512 int code = SET_USAGE;
513 uint64_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_PROTECTED;
514 ASSERT_EQ(NativeWindowHandleOpt(nativeWindow, code, usage), OHOS::GSERROR_OK);
515
516 NativeWindowBuffer* nativeWindowBuffer = nullptr;
517 int fenceFd = -1;
518 int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
519 ASSERT_EQ(ret, GSERROR_OK);
520
521 struct Region *region = new Region();
522 struct Region::Rect *rect = new Region::Rect();
523 rect->x = 0x100;
524 rect->y = 0x100;
525 rect->w = 0x100;
526 rect->h = 0x100;
527 region->rects = rect;
528 ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
529 ASSERT_EQ(ret, GSERROR_OK);
530 NativeWindowBuffer* lastFlushedBuffer;
531 int lastFlushedFenceFd;
532 float matrix[16];
533 ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
534 OHOS::GSERROR_NO_PERMISSION);
535 }
536 /*
537 * Function: OH_NativeWindow_NativeWindowAbortBuffer
538 * Type: Function
539 * Rank: Important(2)
540 * EnvConditions: N/A
541 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
542 * 2. check ret
543 */
544 HWTEST_F(NativeWindowTest, CancelBuffer001, Function | MediumTest | Level2)
545 {
546 ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
547 }
548
549 /*
550 * Function: OH_NativeWindow_NativeWindowAbortBuffer
551 * Type: Function
552 * Rank: Important(2)
553 * EnvConditions: N/A
554 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
555 * 2. check ret
556 */
557 HWTEST_F(NativeWindowTest, CancelBuffer002, Function | MediumTest | Level2)
558 {
559 ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
560 }
561
562 /*
563 * Function: OH_NativeWindow_NativeWindowAbortBuffer
564 * Type: Function
565 * Rank: Important(2)
566 * EnvConditions: N/A
567 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer
568 * 2. check ret
569 */
570 HWTEST_F(NativeWindowTest, CancelBuffer003, Function | MediumTest | Level2)
571 {
572 ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer), OHOS::GSERROR_OK);
573 }
574
575 /*
576 * Function: OH_NativeWindow_NativeObjectReference
577 * Type: Function
578 * Rank: Important(2)
579 * EnvConditions: N/A
580 * CaseDescription: 1. call OH_NativeWindow_NativeObjectReference
581 * 2. check ret
582 */
583 HWTEST_F(NativeWindowTest, Reference001, Function | MediumTest | Level2)
584 {
585 struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
586 buffer->sfbuffer = sBuffer;
587 ASSERT_EQ(OH_NativeWindow_NativeObjectReference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
588 delete buffer;
589 }
590
591 /*
592 * Function: OH_NativeWindow_NativeObjectUnreference
593 * Type: Function
594 * Rank: Important(2)
595 * EnvConditions: N/A
596 * CaseDescription: 1. call OH_NativeWindow_NativeObjectUnreference
597 * 2. check ret
598 */
599 HWTEST_F(NativeWindowTest, Unreference001, Function | MediumTest | Level2)
600 {
601 struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
602 buffer->sfbuffer = sBuffer;
603 ASSERT_EQ(OH_NativeWindow_NativeObjectUnreference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
604 delete buffer;
605 }
606
607 /*
608 * Function: OH_NativeWindow_DestroyNativeWindow
609 * Type: Function
610 * Rank: Important(2)
611 * EnvConditions: N/A
612 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindow by abnormal input
613 * 2. check ret
614 */
615 HWTEST_F(NativeWindowTest, DestroyNativeWindow001, Function | MediumTest | Level2)
616 {
617 OH_NativeWindow_DestroyNativeWindow(nullptr);
618 }
619
620 /*
621 * Function: OH_NativeWindow_DestroyNativeWindowBuffer
622 * Type: Function
623 * Rank: Important(2)
624 * EnvConditions: N/A
625 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer by abnormal input
626 * 2. check ret
627 */
628 HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer001, Function | MediumTest | Level2)
629 {
630 OH_NativeWindow_DestroyNativeWindowBuffer(nullptr);
631 }
632
633 /*
634 * Function: OH_NativeWindow_DestroyNativeWindowBuffer
635 * Type: Function
636 * Rank: Important(2)
637 * EnvConditions: N/A
638 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer again
639 * 2. check ret
640 */
641 HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer002, Function | MediumTest | Level2)
642 {
643 OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
644 }
645
646 /*
647 * Function: OH_NativeWindow_NativeWindowSetScalingMode
648 * Type: Function
649 * Rank: Important(2)
650 * EnvConditions: N/A
651 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
652 */
653 HWTEST_F(NativeWindowTest, SetScalingMode001, Function | MediumTest | Level2)
654 {
655 OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
656 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nullptr, -1, scalingMode), OHOS::GSERROR_INVALID_ARGUMENTS);
657 }
658
659 /*
660 * Function: OH_NativeWindow_NativeWindowSetScalingMode
661 * Type: Function
662 * Rank: Important(2)
663 * EnvConditions: N/A
664 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
665 */
666 HWTEST_F(NativeWindowTest, SetScalingMode002, Function | MediumTest | Level2)
667 {
668 OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
669 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, -1, scalingMode), OHOS::GSERROR_NO_ENTRY);
670 }
671
672 /*
673 * Function: OH_NativeWindow_NativeWindowSetScalingMode
674 * Type: Function
675 * Rank: Important(2)
676 * EnvConditions: N/A
677 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
678 */
679 HWTEST_F(NativeWindowTest, SetScalingMode003, Function | MediumTest | Level2)
680 {
681 int32_t sequence = 0;
682 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, sequence,
683 static_cast<OHScalingMode>(OHScalingMode::OH_SCALING_MODE_NO_SCALE_CROP + 1)),
684 OHOS::GSERROR_INVALID_ARGUMENTS);
685 }
686
687 /*
688 * Function: OH_NativeWindow_NativeWindowSetScalingMode
689 * Type: Function
690 * Rank: Important(1)
691 * EnvConditions: N/A
692 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
693 * 2. call OH_NativeWindow_NativeWindowSetScalingMode with normal parameters and check ret
694 */
695 HWTEST_F(NativeWindowTest, SetScalingMode004, Function | MediumTest | Level1)
696 {
697 int32_t sequence = 0;
698 OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
699 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, sequence, scalingMode), OHOS::GSERROR_OK);
700 }
701
702 /*
703 * Function: OH_NativeWindow_NativeWindowSetMetaData
704 * Type: Function
705 * Rank: Important(2)
706 * EnvConditions: N/A
707 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
708 */
709 HWTEST_F(NativeWindowTest, SetMetaData001, Function | MediumTest | Level2)
710 {
711 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nullptr, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
712 }
713
714 /*
715 * Function: OH_NativeWindow_NativeWindowSetMetaData
716 * Type: Function
717 * Rank: Important(2)
718 * EnvConditions: N/A
719 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
720 */
721 HWTEST_F(NativeWindowTest, SetMetaData002, Function | MediumTest | Level2)
722 {
723 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
724 }
725
726 /*
727 * Function: OH_NativeWindow_NativeWindowSetMetaData
728 * Type: Function
729 * Rank: Important(2)
730 * EnvConditions: N/A
731 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
732 * 2. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
733 */
734 HWTEST_F(NativeWindowTest, SetMetaData003, Function | MediumTest | Level2)
735 {
736 int32_t sequence = 0;
737 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, 0, nullptr),
738 OHOS::GSERROR_INVALID_ARGUMENTS);
739 }
740
741 /*
742 * Function: OH_NativeWindow_NativeWindowSetMetaData
743 * Type: Function
744 * Rank: Important(2)
745 * EnvConditions: N/A
746 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
747 */
748 HWTEST_F(NativeWindowTest, SetMetaData004, Function | MediumTest | Level2)
749 {
750 int32_t sequence = 0;
751 int32_t size = 1;
752 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, size, nullptr),
753 OHOS::GSERROR_INVALID_ARGUMENTS);
754 }
755
756 /*
757 * Function: OH_NativeWindow_NativeWindowSetMetaData
758 * Type: Function
759 * Rank: Important(2)
760 * EnvConditions: N/A
761 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
762 */
763 HWTEST_F(NativeWindowTest, SetMetaData005, Function | MediumTest | Level2)
764 {
765 int32_t size = 1;
766 const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
767 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, size, metaData), OHOS::GSERROR_NO_ENTRY);
768 }
769
770 /*
771 * Function: OH_NativeWindow_NativeWindowSetMetaData
772 * Type: Function
773 * Rank: Important(1)
774 * EnvConditions: N/A
775 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
776 */
777 HWTEST_F(NativeWindowTest, SetMetaData006, Function | MediumTest | Level1)
778 {
779 int32_t sequence = 0;
780 int32_t size = 1;
781 const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
782 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, size, metaData), OHOS::GSERROR_OK);
783 }
784
785 /*
786 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
787 * Type: Function
788 * Rank: Important(2)
789 * EnvConditions: N/A
790 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
791 */
792 HWTEST_F(NativeWindowTest, SetMetaDataSet001, Function | MediumTest | Level2)
793 {
794 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
795 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nullptr, -1, key, 0, nullptr),
796 OHOS::GSERROR_INVALID_ARGUMENTS);
797 }
798
799 /*
800 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
801 * Type: Function
802 * Rank: Important(2)
803 * EnvConditions: N/A
804 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
805 */
806 HWTEST_F(NativeWindowTest, SetMetaDataSet002, Function | MediumTest | Level2)
807 {
808 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
809 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, 0, nullptr),
810 OHOS::GSERROR_INVALID_ARGUMENTS);
811 }
812
813 /*
814 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
815 * Type: Function
816 * Rank: Important(2)
817 * EnvConditions: N/A
818 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
819 */
820 HWTEST_F(NativeWindowTest, SetMetaDataSet003, Function | MediumTest | Level2)
821 {
822 int32_t sequence = 0;
823 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
824 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, 0, nullptr),
825 OHOS::GSERROR_INVALID_ARGUMENTS);
826 }
827
828 /*
829 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
830 * Type: Function
831 * Rank: Important(2)
832 * EnvConditions: N/A
833 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
834 */
835 HWTEST_F(NativeWindowTest, SetMetaDataSet004, Function | MediumTest | Level2)
836 {
837 int32_t sequence = 0;
838 int32_t size = 1;
839 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
840 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, size, nullptr),
841 OHOS::GSERROR_INVALID_ARGUMENTS);
842 }
843
844 /*
845 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
846 * Type: Function
847 * Rank: Important(2)
848 * EnvConditions: N/A
849 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
850 */
851 HWTEST_F(NativeWindowTest, SetMetaDataSet005, Function | MediumTest | Level2)
852 {
853 int32_t size = 1;
854 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
855 const uint8_t metaData[] = {0};
856 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, size, metaData),
857 OHOS::GSERROR_NO_ENTRY);
858 }
859
860 /*
861 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
862 * Type: Function
863 * Rank: Important(1)
864 * EnvConditions: N/A
865 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with normal parameters and check ret
866 */
867 HWTEST_F(NativeWindowTest, SetMetaDataSet006, Function | MediumTest | Level1)
868 {
869 int32_t sequence = 0;
870 int32_t size = 1;
871 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
872 const uint8_t metaData[] = {0};
873 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, size, metaData),
874 OHOS::GSERROR_OK);
875 }
876
877 /*
878 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
879 * Type: Function
880 * Rank: Important(2)
881 * EnvConditions: N/A
882 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
883 */
884 HWTEST_F(NativeWindowTest, SetTunnelHandle001, Function | MediumTest | Level2)
885 {
886 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
887 }
888
889 /*
890 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
891 * Type: Function
892 * Rank: Important(2)
893 * EnvConditions: N/A
894 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
895 */
896 HWTEST_F(NativeWindowTest, SetTunnelHandle002, Function | MediumTest | Level2)
897 {
898 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
899 }
900
901 /*
902 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
903 * Type: Function
904 * Rank: Important(2)
905 * EnvConditions: N/A
906 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
907 */
908 HWTEST_F(NativeWindowTest, SetTunnelHandle003, Function | MediumTest | Level2)
909 {
910 uint32_t reserveInts = 1;
911 OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
912 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
913 FreeOHExtDataHandle(handle);
914 }
915
916 /*
917 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
918 * Type: Function
919 * Rank: Important(1)
920 * EnvConditions: N/A
921 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
922 * @tc.require: issueI5GMZN issueI5IWHW
923 */
924 HWTEST_F(NativeWindowTest, SetTunnelHandle004, Function | MediumTest | Level1)
925 {
926 uint32_t reserveInts = 2;
927 OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
928 nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
929 ASSERT_NE(nativeWindow, nullptr);
930 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
931 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_NO_ENTRY);
932 FreeOHExtDataHandle(handle);
933 }
934 }
935