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 nativeWindow = nullptr;
115 nativeWindowBuffer = nullptr;
116 }
117
118 /*
119 * Function: OH_NativeWindow_CreateNativeWindow
120 * Type: Function
121 * Rank: Important(2)
122 * EnvConditions: N/A
123 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow by abnormal input
124 * 2. check ret
125 */
126 HWTEST_F(NativeWindowTest, CreateNativeWindow001, Function | MediumTest | Level2)
127 {
128 ASSERT_EQ(OH_NativeWindow_CreateNativeWindow(nullptr), nullptr);
129 }
130
131 /*
132 * Function: OH_NativeWindow_CreateNativeWindow
133 * Type: Function
134 * Rank: Important(2)
135 * EnvConditions: N/A
136 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow
137 * 2. check ret
138 */
139 HWTEST_F(NativeWindowTest, CreateNativeWindow002, Function | MediumTest | Level2)
140 {
141 nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
142 ASSERT_NE(nativeWindow, nullptr);
143 }
144
145 /*
146 * Function: OH_NativeWindow_NativeWindowHandleOpt
147 * Type: Function
148 * Rank: Important(2)
149 * EnvConditions: N/A
150 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by abnormal input
151 * 2. check ret
152 */
153 HWTEST_F(NativeWindowTest, HandleOpt001, Function | MediumTest | Level2)
154 {
155 int code = SET_USAGE;
156 uint64_t usage = BUFFER_USAGE_CPU_READ;
157 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nullptr, code, usage), OHOS::GSERROR_INVALID_ARGUMENTS);
158 }
159
160 /*
161 * Function: OH_NativeWindow_NativeWindowHandleOpt
162 * Type: Function
163 * Rank: Important(2)
164 * EnvConditions: N/A
165 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
166 * 2. check ret
167 */
168 HWTEST_F(NativeWindowTest, HandleOpt002, Function | MediumTest | Level2)
169 {
170 int code = SET_USAGE;
171 uint64_t usageSet = BUFFER_USAGE_CPU_READ;
172 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), OHOS::GSERROR_OK);
173
174 code = GET_USAGE;
175 uint64_t usageGet = BUFFER_USAGE_CPU_WRITE;
176 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &usageGet), OHOS::GSERROR_OK);
177 ASSERT_EQ(usageSet, usageGet);
178 }
179
180 /*
181 * Function: OH_NativeWindow_NativeWindowHandleOpt
182 * Type: Function
183 * Rank: Important(2)
184 * EnvConditions: N/A
185 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
186 * 2. check ret
187 */
188 HWTEST_F(NativeWindowTest, HandleOpt003, Function | MediumTest | Level2)
189 {
190 int code = SET_BUFFER_GEOMETRY;
191 int32_t heightSet = 0x100;
192 int32_t widthSet = 0x100;
193 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, heightSet, widthSet), OHOS::GSERROR_OK);
194
195 code = GET_BUFFER_GEOMETRY;
196 int32_t heightGet = 0;
197 int32_t widthGet = 0;
198 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &heightGet, &widthGet), OHOS::GSERROR_OK);
199 ASSERT_EQ(heightSet, heightGet);
200 ASSERT_EQ(widthSet, widthGet);
201 }
202
203 /*
204 * Function: OH_NativeWindow_NativeWindowHandleOpt
205 * Type: Function
206 * Rank: Important(2)
207 * EnvConditions: N/A
208 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
209 * 2. check ret
210 */
211 HWTEST_F(NativeWindowTest, HandleOpt004, Function | MediumTest | Level2)
212 {
213 int code = SET_FORMAT;
214 int32_t formatSet = GRAPHIC_PIXEL_FMT_RGBA_8888;
215 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), OHOS::GSERROR_OK);
216
217 code = GET_FORMAT;
218 int32_t formatGet = GRAPHIC_PIXEL_FMT_CLUT8;
219 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &formatGet), OHOS::GSERROR_OK);
220 ASSERT_EQ(formatSet, formatGet);
221 }
222
223 /*
224 * Function: OH_NativeWindow_NativeWindowHandleOpt
225 * Type: Function
226 * Rank: Important(2)
227 * EnvConditions: N/A
228 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
229 * 2. check ret
230 */
231 HWTEST_F(NativeWindowTest, HandleOpt005, Function | MediumTest | Level2)
232 {
233 int code = SET_STRIDE;
234 int32_t strideSet = 0x8;
235 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, strideSet), OHOS::GSERROR_OK);
236
237 code = GET_STRIDE;
238 int32_t strideGet = 0;
239 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &strideGet), OHOS::GSERROR_OK);
240 ASSERT_EQ(strideSet, strideGet);
241 }
242
243 /*
244 * Function: OH_NativeWindow_NativeWindowHandleOpt
245 * Type: Function
246 * Rank: Important(2)
247 * EnvConditions: N/A
248 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
249 * 2. check ret
250 */
251 HWTEST_F(NativeWindowTest, HandleOpt006, Function | MediumTest | Level2)
252 {
253 int code = SET_COLOR_GAMUT;
254 int32_t colorGamutSet = static_cast<int32_t>(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
255 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, colorGamutSet), OHOS::GSERROR_OK);
256
257 code = GET_COLOR_GAMUT;
258 int32_t colorGamutGet = 0;
259 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &colorGamutGet), OHOS::GSERROR_OK);
260 ASSERT_EQ(colorGamutSet, colorGamutGet);
261 }
262
263 /*
264 * Function: OH_NativeWindow_NativeWindowHandleOpt
265 * Type: Function
266 * Rank: Important(2)
267 * EnvConditions: N/A
268 * CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
269 * 2. check ret
270 */
271 HWTEST_F(NativeWindowTest, HandleOpt007, Function | MediumTest | Level2)
272 {
273 int code = SET_TIMEOUT;
274 int32_t timeoutSet = 10; // 10: for test
275 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, timeoutSet), OHOS::GSERROR_OK);
276
277 code = GET_TIMEOUT;
278 int32_t timeoutGet = 0;
279 ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &timeoutGet), OHOS::GSERROR_OK);
280 ASSERT_EQ(timeoutSet, timeoutGet);
281 }
282
283 /*
284 * Function: OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
285 * Type: Function
286 * Rank: Important(2)
287 * EnvConditions: N/A
288 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer by abnormal input
289 * 2. check ret
290 */
291 HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer001, Function | MediumTest | Level2)
292 {
293 ASSERT_EQ(OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(nullptr), nullptr);
294 }
295
296 /*
297 * Function: OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
298 * Type: Function
299 * Rank: Important(2)
300 * EnvConditions: N/A
301 * CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
302 * 2. check ret
303 */
304 HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer002, Function | MediumTest | Level2)
305 {
306 nativeWindowBuffer = OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(&sBuffer);
307 ASSERT_NE(nativeWindowBuffer, nullptr);
308 }
309
310 /*
311 * Function: OH_NativeWindow_NativeWindowRequestBuffer
312 * Type: Function
313 * Rank: Important(2)
314 * EnvConditions: N/A
315 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
316 * 2. check ret
317 */
318 HWTEST_F(NativeWindowTest, RequestBuffer001, Function | MediumTest | Level2)
319 {
320 ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nullptr, &nativeWindowBuffer, nullptr),
321 OHOS::GSERROR_INVALID_ARGUMENTS);
322 }
323
324 /*
325 * Function: OH_NativeWindow_NativeWindowRequestBuffer
326 * Type: Function
327 * Rank: Important(2)
328 * EnvConditions: N/A
329 * CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
330 * 2. check ret
331 */
332 HWTEST_F(NativeWindowTest, RequestBuffer002, Function | MediumTest | Level2)
333 {
334 ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, nullptr, nullptr),
335 OHOS::GSERROR_INVALID_ARGUMENTS);
336 }
337
338 /*
339 * Function: OH_NativeWindow_GetBufferHandleFromNative
340 * Type: Function
341 * Rank: Important(2)
342 * EnvConditions: N/A
343 * CaseDescription: 1. call OH_NativeWindow_GetBufferHandleFromNative by abnormal input
344 * 2. check ret
345 */
346 HWTEST_F(NativeWindowTest, GetBufferHandle001, Function | MediumTest | Level2)
347 {
348 ASSERT_EQ(OH_NativeWindow_GetBufferHandleFromNative(nullptr), nullptr);
349 }
350
351 /*
352 * Function: OH_NativeWindow_GetBufferHandleFromNative
353 * Type: Function
354 * Rank: Important(2)
355 * EnvConditions: N/A
356 * CaseDescription: 1. call OH_NativeWindow_GetBufferHandleFromNative
357 * 2. check ret
358 */
359 HWTEST_F(NativeWindowTest, GetBufferHandle002, Function | MediumTest | Level2)
360 {
361 struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
362 buffer->sfbuffer = sBuffer;
363 ASSERT_NE(OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer), nullptr);
364 delete buffer;
365 }
366
367 /*
368 * Function: OH_NativeWindow_NativeWindowFlushBuffer
369 * Type: Function
370 * Rank: Important(2)
371 * EnvConditions: N/A
372 * CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
373 * 2. check ret
374 */
375 HWTEST_F(NativeWindowTest, FlushBuffer001, Function | MediumTest | Level2)
376 {
377 int fenceFd = -1;
378 struct Region *region = new Region();
379 struct Region::Rect * rect = new Region::Rect();
380 rect->x = 0x100;
381 rect->y = 0x100;
382 rect->w = 0x100;
383 rect->h = 0x100;
384 region->rects = rect;
385
386 ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nullptr, nullptr, fenceFd, *region),
387 OHOS::GSERROR_INVALID_ARGUMENTS);
388 delete region;
389 }
390
391 /*
392 * Function: OH_NativeWindow_NativeWindowFlushBuffer
393 * Type: Function
394 * Rank: Important(2)
395 * EnvConditions: N/A
396 * CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
397 * 2. check ret
398 */
399 HWTEST_F(NativeWindowTest, FlushBuffer002, Function | MediumTest | Level2)
400 {
401 int fenceFd = -1;
402 struct Region *region = new Region();
403 struct Region::Rect * rect = new Region::Rect();
404 rect->x = 0x100;
405 rect->y = 0x100;
406 rect->w = 0x100;
407 rect->h = 0x100;
408 region->rects = rect;
409
410 ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nullptr, fenceFd, *region),
411 OHOS::GSERROR_INVALID_ARGUMENTS);
412 delete region;
413 }
414
415 /*
416 * Function: OH_NativeWindow_NativeWindowFlushBuffer
417 * Type: Function
418 * Rank: Important(2)
419 * EnvConditions: N/A
420 * CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer
421 * 2. check ret
422 */
423 HWTEST_F(NativeWindowTest, FlushBuffer003, Function | MediumTest | Level2)
424 {
425 int fenceFd = -1;
426 struct Region *region = new Region();
427 region->rectNumber = 0;
428 region->rects = nullptr;
429 ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
430 OHOS::GSERROR_OK);
431
432 region->rectNumber = 1;
433 struct Region::Rect * rect = new Region::Rect();
434 rect->x = 0x100;
435 rect->y = 0x100;
436 rect->w = 0x100;
437 rect->h = 0x100;
438 region->rects = rect;
439 ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
440 OHOS::GSERROR_OK);
441 delete rect;
442 delete region;
443 }
444
445 /*
446 * Function: OH_NativeWindow_NativeWindowAbortBuffer
447 * Type: Function
448 * Rank: Important(2)
449 * EnvConditions: N/A
450 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
451 * 2. check ret
452 */
453 HWTEST_F(NativeWindowTest, CancelBuffer001, Function | MediumTest | Level2)
454 {
455 ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
456 }
457
458 /*
459 * Function: OH_NativeWindow_NativeWindowAbortBuffer
460 * Type: Function
461 * Rank: Important(2)
462 * EnvConditions: N/A
463 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
464 * 2. check ret
465 */
466 HWTEST_F(NativeWindowTest, CancelBuffer002, Function | MediumTest | Level2)
467 {
468 ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
469 }
470
471 /*
472 * Function: OH_NativeWindow_NativeWindowAbortBuffer
473 * Type: Function
474 * Rank: Important(2)
475 * EnvConditions: N/A
476 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer
477 * 2. check ret
478 */
479 HWTEST_F(NativeWindowTest, CancelBuffer003, Function | MediumTest | Level2)
480 {
481 ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer), OHOS::GSERROR_OK);
482 }
483
484 /*
485 * Function: OH_NativeWindow_NativeObjectReference
486 * Type: Function
487 * Rank: Important(2)
488 * EnvConditions: N/A
489 * CaseDescription: 1. call OH_NativeWindow_NativeObjectReference
490 * 2. check ret
491 */
492 HWTEST_F(NativeWindowTest, Reference001, Function | MediumTest | Level2)
493 {
494 struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
495 buffer->sfbuffer = sBuffer;
496 ASSERT_EQ(OH_NativeWindow_NativeObjectReference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
497 delete buffer;
498 }
499
500 /*
501 * Function: OH_NativeWindow_NativeObjectUnreference
502 * Type: Function
503 * Rank: Important(2)
504 * EnvConditions: N/A
505 * CaseDescription: 1. call OH_NativeWindow_NativeObjectUnreference
506 * 2. check ret
507 */
508 HWTEST_F(NativeWindowTest, Unreference001, Function | MediumTest | Level2)
509 {
510 struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
511 buffer->sfbuffer = sBuffer;
512 ASSERT_EQ(OH_NativeWindow_NativeObjectUnreference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
513 delete buffer;
514 }
515
516 /*
517 * Function: OH_NativeWindow_DestroyNativeWindow
518 * Type: Function
519 * Rank: Important(2)
520 * EnvConditions: N/A
521 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindow by abnormal input
522 * 2. check ret
523 */
524 HWTEST_F(NativeWindowTest, DestroyNativeWindow001, Function | MediumTest | Level2)
525 {
526 OH_NativeWindow_DestroyNativeWindow(nullptr);
527 }
528
529 /*
530 * Function: OH_NativeWindow_DestroyNativeWindow
531 * Type: Function
532 * Rank: Important(2)
533 * EnvConditions: N/A
534 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindow
535 * 2. check ret
536 */
537 HWTEST_F(NativeWindowTest, DestroyNativeWindow002, Function | MediumTest | Level2)
538 {
539 OH_NativeWindow_DestroyNativeWindow(nativeWindow);
540 }
541
542 /*
543 * Function: OH_NativeWindow_DestroyNativeWindowBuffer
544 * Type: Function
545 * Rank: Important(2)
546 * EnvConditions: N/A
547 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer by abnormal input
548 * 2. check ret
549 */
550 HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer001, Function | MediumTest | Level2)
551 {
552 OH_NativeWindow_DestroyNativeWindowBuffer(nullptr);
553 }
554
555 /*
556 * Function: OH_NativeWindow_DestroyNativeWindowBuffer
557 * Type: Function
558 * Rank: Important(2)
559 * EnvConditions: N/A
560 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer again
561 * 2. check ret
562 */
563 HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer002, Function | MediumTest | Level2)
564 {
565 OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
566 }
567
568 /*
569 * Function: OH_NativeWindow_NativeWindowSetScalingMode
570 * Type: Function
571 * Rank: Important(2)
572 * EnvConditions: N/A
573 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
574 */
575 HWTEST_F(NativeWindowTest, SetScalingMode001, Function | MediumTest | Level2)
576 {
577 OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
578 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nullptr, -1, scalingMode), OHOS::GSERROR_INVALID_ARGUMENTS);
579 }
580
581 /*
582 * Function: OH_NativeWindow_NativeWindowSetScalingMode
583 * Type: Function
584 * Rank: Important(2)
585 * EnvConditions: N/A
586 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
587 */
588 HWTEST_F(NativeWindowTest, SetScalingMode002, Function | MediumTest | Level2)
589 {
590 OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
591 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, -1, scalingMode), OHOS::GSERROR_NO_ENTRY);
592 }
593
594 /*
595 * Function: OH_NativeWindow_NativeWindowSetScalingMode
596 * Type: Function
597 * Rank: Important(2)
598 * EnvConditions: N/A
599 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
600 */
601 HWTEST_F(NativeWindowTest, SetScalingMode003, Function | MediumTest | Level2)
602 {
603 int32_t sequence = 0;
604 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, sequence,
605 static_cast<OHScalingMode>(OHScalingMode::OH_SCALING_MODE_NO_SCALE_CROP + 1)),
606 OHOS::GSERROR_INVALID_ARGUMENTS);
607 }
608
609 /*
610 * Function: OH_NativeWindow_NativeWindowSetScalingMode
611 * Type: Function
612 * Rank: Important(1)
613 * EnvConditions: N/A
614 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
615 * 2. call OH_NativeWindow_NativeWindowSetScalingMode with normal parameters and check ret
616 */
617 HWTEST_F(NativeWindowTest, SetScalingMode004, Function | MediumTest | Level1)
618 {
619 int32_t sequence = 0;
620 OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
621 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, sequence, scalingMode), OHOS::GSERROR_OK);
622 }
623
624 /*
625 * Function: OH_NativeWindow_NativeWindowSetMetaData
626 * Type: Function
627 * Rank: Important(2)
628 * EnvConditions: N/A
629 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
630 */
631 HWTEST_F(NativeWindowTest, SetMetaData001, Function | MediumTest | Level2)
632 {
633 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nullptr, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
634 }
635
636 /*
637 * Function: OH_NativeWindow_NativeWindowSetMetaData
638 * Type: Function
639 * Rank: Important(2)
640 * EnvConditions: N/A
641 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
642 */
643 HWTEST_F(NativeWindowTest, SetMetaData002, Function | MediumTest | Level2)
644 {
645 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
646 }
647
648 /*
649 * Function: OH_NativeWindow_NativeWindowSetMetaData
650 * Type: Function
651 * Rank: Important(2)
652 * EnvConditions: N/A
653 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
654 * 2. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
655 */
656 HWTEST_F(NativeWindowTest, SetMetaData003, Function | MediumTest | Level2)
657 {
658 int32_t sequence = 0;
659 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, 0, nullptr),
660 OHOS::GSERROR_INVALID_ARGUMENTS);
661 }
662
663 /*
664 * Function: OH_NativeWindow_NativeWindowSetMetaData
665 * Type: Function
666 * Rank: Important(2)
667 * EnvConditions: N/A
668 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
669 */
670 HWTEST_F(NativeWindowTest, SetMetaData004, Function | MediumTest | Level2)
671 {
672 int32_t sequence = 0;
673 int32_t size = 1;
674 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, size, nullptr),
675 OHOS::GSERROR_INVALID_ARGUMENTS);
676 }
677
678 /*
679 * Function: OH_NativeWindow_NativeWindowSetMetaData
680 * Type: Function
681 * Rank: Important(2)
682 * EnvConditions: N/A
683 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
684 */
685 HWTEST_F(NativeWindowTest, SetMetaData005, Function | MediumTest | Level2)
686 {
687 int32_t size = 1;
688 const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
689 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, size, metaData), OHOS::GSERROR_NO_ENTRY);
690 }
691
692 /*
693 * Function: OH_NativeWindow_NativeWindowSetMetaData
694 * Type: Function
695 * Rank: Important(1)
696 * EnvConditions: N/A
697 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
698 */
699 HWTEST_F(NativeWindowTest, SetMetaData006, Function | MediumTest | Level1)
700 {
701 int32_t sequence = 0;
702 int32_t size = 1;
703 const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
704 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, size, metaData), OHOS::GSERROR_OK);
705 }
706
707 /*
708 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
709 * Type: Function
710 * Rank: Important(2)
711 * EnvConditions: N/A
712 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
713 */
714 HWTEST_F(NativeWindowTest, SetMetaDataSet001, Function | MediumTest | Level2)
715 {
716 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
717 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nullptr, -1, key, 0, nullptr),
718 OHOS::GSERROR_INVALID_ARGUMENTS);
719 }
720
721 /*
722 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
723 * Type: Function
724 * Rank: Important(2)
725 * EnvConditions: N/A
726 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
727 */
728 HWTEST_F(NativeWindowTest, SetMetaDataSet002, Function | MediumTest | Level2)
729 {
730 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
731 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, 0, nullptr),
732 OHOS::GSERROR_INVALID_ARGUMENTS);
733 }
734
735 /*
736 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
737 * Type: Function
738 * Rank: Important(2)
739 * EnvConditions: N/A
740 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
741 */
742 HWTEST_F(NativeWindowTest, SetMetaDataSet003, Function | MediumTest | Level2)
743 {
744 int32_t sequence = 0;
745 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
746 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, 0, nullptr),
747 OHOS::GSERROR_INVALID_ARGUMENTS);
748 }
749
750 /*
751 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
752 * Type: Function
753 * Rank: Important(2)
754 * EnvConditions: N/A
755 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
756 */
757 HWTEST_F(NativeWindowTest, SetMetaDataSet004, Function | MediumTest | Level2)
758 {
759 int32_t sequence = 0;
760 int32_t size = 1;
761 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
762 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, size, nullptr),
763 OHOS::GSERROR_INVALID_ARGUMENTS);
764 }
765
766 /*
767 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
768 * Type: Function
769 * Rank: Important(2)
770 * EnvConditions: N/A
771 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
772 */
773 HWTEST_F(NativeWindowTest, SetMetaDataSet005, Function | MediumTest | Level2)
774 {
775 int32_t size = 1;
776 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
777 const uint8_t metaData[] = {0};
778 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, size, metaData),
779 OHOS::GSERROR_NO_ENTRY);
780 }
781
782 /*
783 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
784 * Type: Function
785 * Rank: Important(1)
786 * EnvConditions: N/A
787 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with normal parameters and check ret
788 */
789 HWTEST_F(NativeWindowTest, SetMetaDataSet006, Function | MediumTest | Level1)
790 {
791 int32_t sequence = 0;
792 int32_t size = 1;
793 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
794 const uint8_t metaData[] = {0};
795 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, size, metaData),
796 OHOS::GSERROR_OK);
797 }
798
799 /*
800 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
801 * Type: Function
802 * Rank: Important(2)
803 * EnvConditions: N/A
804 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
805 */
806 HWTEST_F(NativeWindowTest, SetTunnelHandle001, Function | MediumTest | Level2)
807 {
808 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
809 }
810
811 /*
812 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
813 * Type: Function
814 * Rank: Important(2)
815 * EnvConditions: N/A
816 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
817 */
818 HWTEST_F(NativeWindowTest, SetTunnelHandle002, Function | MediumTest | Level2)
819 {
820 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
821 }
822
823 /*
824 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
825 * Type: Function
826 * Rank: Important(2)
827 * EnvConditions: N/A
828 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
829 */
830 HWTEST_F(NativeWindowTest, SetTunnelHandle003, Function | MediumTest | Level2)
831 {
832 uint32_t reserveInts = 1;
833 OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
834 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
835 FreeOHExtDataHandle(handle);
836 }
837
838 /*
839 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
840 * Type: Function
841 * Rank: Important(1)
842 * EnvConditions: N/A
843 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
844 * @tc.require: issueI5GMZN issueI5IWHW
845 */
846 HWTEST_F(NativeWindowTest, SetTunnelHandle004, Function | MediumTest | Level1)
847 {
848 uint32_t reserveInts = 2;
849 OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
850 nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
851 ASSERT_NE(nativeWindow, nullptr);
852 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
853 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_NO_ENTRY);
854 FreeOHExtDataHandle(handle);
855 }
856 }
857