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 <iservice_registry.h>
17 #include <native_window.h>
18 #include <securec.h>
19 #include <surface_type.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::Surface> 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 = Surface::CreateSurfaceAsConsumer();
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 struct Region::Rect * rect = new Region::Rect();
428 rect->x = 0x100;
429 rect->y = 0x100;
430 rect->w = 0x100;
431 rect->h = 0x100;
432 region->rects = rect;
433
434 ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
435 OHOS::GSERROR_OK);
436 delete region;
437 }
438
439 /*
440 * Function: OH_NativeWindow_NativeWindowAbortBuffer
441 * Type: Function
442 * Rank: Important(2)
443 * EnvConditions: N/A
444 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
445 * 2. check ret
446 */
447 HWTEST_F(NativeWindowTest, CancelBuffer001, Function | MediumTest | Level2)
448 {
449 ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
450 }
451
452 /*
453 * Function: OH_NativeWindow_NativeWindowAbortBuffer
454 * Type: Function
455 * Rank: Important(2)
456 * EnvConditions: N/A
457 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
458 * 2. check ret
459 */
460 HWTEST_F(NativeWindowTest, CancelBuffer002, Function | MediumTest | Level2)
461 {
462 ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
463 }
464
465 /*
466 * Function: OH_NativeWindow_NativeWindowAbortBuffer
467 * Type: Function
468 * Rank: Important(2)
469 * EnvConditions: N/A
470 * CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer
471 * 2. check ret
472 */
473 HWTEST_F(NativeWindowTest, CancelBuffer003, Function | MediumTest | Level2)
474 {
475 ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer), OHOS::GSERROR_OK);
476 }
477
478 /*
479 * Function: OH_NativeWindow_NativeObjectReference
480 * Type: Function
481 * Rank: Important(2)
482 * EnvConditions: N/A
483 * CaseDescription: 1. call OH_NativeWindow_NativeObjectReference
484 * 2. check ret
485 */
486 HWTEST_F(NativeWindowTest, Reference001, Function | MediumTest | Level2)
487 {
488 struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
489 buffer->sfbuffer = sBuffer;
490 ASSERT_EQ(OH_NativeWindow_NativeObjectReference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
491 delete buffer;
492 }
493
494 /*
495 * Function: OH_NativeWindow_NativeObjectUnreference
496 * Type: Function
497 * Rank: Important(2)
498 * EnvConditions: N/A
499 * CaseDescription: 1. call OH_NativeWindow_NativeObjectUnreference
500 * 2. check ret
501 */
502 HWTEST_F(NativeWindowTest, Unreference001, Function | MediumTest | Level2)
503 {
504 struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
505 buffer->sfbuffer = sBuffer;
506 ASSERT_EQ(OH_NativeWindow_NativeObjectUnreference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
507 delete buffer;
508 }
509
510 /*
511 * Function: OH_NativeWindow_DestroyNativeWindow
512 * Type: Function
513 * Rank: Important(2)
514 * EnvConditions: N/A
515 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindow by abnormal input
516 * 2. check ret
517 */
518 HWTEST_F(NativeWindowTest, DestroyNativeWindow001, Function | MediumTest | Level2)
519 {
520 OH_NativeWindow_DestroyNativeWindow(nullptr);
521 }
522
523 /*
524 * Function: OH_NativeWindow_DestroyNativeWindow
525 * Type: Function
526 * Rank: Important(2)
527 * EnvConditions: N/A
528 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindow
529 * 2. check ret
530 */
531 HWTEST_F(NativeWindowTest, DestroyNativeWindow002, Function | MediumTest | Level2)
532 {
533 OH_NativeWindow_DestroyNativeWindow(nativeWindow);
534 }
535
536 /*
537 * Function: OH_NativeWindow_DestroyNativeWindowBuffer
538 * Type: Function
539 * Rank: Important(2)
540 * EnvConditions: N/A
541 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer by abnormal input
542 * 2. check ret
543 */
544 HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer001, Function | MediumTest | Level2)
545 {
546 OH_NativeWindow_DestroyNativeWindowBuffer(nullptr);
547 }
548
549 /*
550 * Function: OH_NativeWindow_DestroyNativeWindowBuffer
551 * Type: Function
552 * Rank: Important(2)
553 * EnvConditions: N/A
554 * CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer again
555 * 2. check ret
556 */
557 HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer002, Function | MediumTest | Level2)
558 {
559 OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
560 }
561
562 /*
563 * Function: OH_NativeWindow_NativeWindowSetScalingMode
564 * Type: Function
565 * Rank: Important(2)
566 * EnvConditions: N/A
567 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
568 */
569 HWTEST_F(NativeWindowTest, SetScalingMode001, Function | MediumTest | Level2)
570 {
571 OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
572 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nullptr, -1, scalingMode), OHOS::GSERROR_INVALID_ARGUMENTS);
573 }
574
575 /*
576 * Function: OH_NativeWindow_NativeWindowSetScalingMode
577 * Type: Function
578 * Rank: Important(2)
579 * EnvConditions: N/A
580 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
581 */
582 HWTEST_F(NativeWindowTest, SetScalingMode002, Function | MediumTest | Level2)
583 {
584 OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
585 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, -1, scalingMode), OHOS::GSERROR_NO_ENTRY);
586 }
587
588 /*
589 * Function: OH_NativeWindow_NativeWindowSetScalingMode
590 * Type: Function
591 * Rank: Important(2)
592 * EnvConditions: N/A
593 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
594 */
595 HWTEST_F(NativeWindowTest, SetScalingMode003, Function | MediumTest | Level2)
596 {
597 int32_t sequence = 0;
598 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, sequence,
599 static_cast<OHScalingMode>(OHScalingMode::OH_SCALING_MODE_NO_SCALE_CROP + 1)),
600 OHOS::GSERROR_INVALID_ARGUMENTS);
601 }
602
603 /*
604 * Function: OH_NativeWindow_NativeWindowSetScalingMode
605 * Type: Function
606 * Rank: Important(1)
607 * EnvConditions: N/A
608 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
609 * 2. call OH_NativeWindow_NativeWindowSetScalingMode with normal parameters and check ret
610 */
611 HWTEST_F(NativeWindowTest, SetScalingMode004, Function | MediumTest | Level1)
612 {
613 int32_t sequence = 0;
614 OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
615 ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, sequence, scalingMode), OHOS::GSERROR_OK);
616 }
617
618 /*
619 * Function: OH_NativeWindow_NativeWindowSetMetaData
620 * Type: Function
621 * Rank: Important(2)
622 * EnvConditions: N/A
623 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
624 */
625 HWTEST_F(NativeWindowTest, SetMetaData001, Function | MediumTest | Level2)
626 {
627 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nullptr, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
628 }
629
630 /*
631 * Function: OH_NativeWindow_NativeWindowSetMetaData
632 * Type: Function
633 * Rank: Important(2)
634 * EnvConditions: N/A
635 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
636 */
637 HWTEST_F(NativeWindowTest, SetMetaData002, Function | MediumTest | Level2)
638 {
639 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
640 }
641
642 /*
643 * Function: OH_NativeWindow_NativeWindowSetMetaData
644 * Type: Function
645 * Rank: Important(2)
646 * EnvConditions: N/A
647 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
648 * 2. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
649 */
650 HWTEST_F(NativeWindowTest, SetMetaData003, Function | MediumTest | Level2)
651 {
652 int32_t sequence = 0;
653 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, 0, nullptr),
654 OHOS::GSERROR_INVALID_ARGUMENTS);
655 }
656
657 /*
658 * Function: OH_NativeWindow_NativeWindowSetMetaData
659 * Type: Function
660 * Rank: Important(2)
661 * EnvConditions: N/A
662 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
663 */
664 HWTEST_F(NativeWindowTest, SetMetaData004, Function | MediumTest | Level2)
665 {
666 int32_t sequence = 0;
667 int32_t size = 1;
668 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, size, nullptr),
669 OHOS::GSERROR_INVALID_ARGUMENTS);
670 }
671
672 /*
673 * Function: OH_NativeWindow_NativeWindowSetMetaData
674 * Type: Function
675 * Rank: Important(2)
676 * EnvConditions: N/A
677 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
678 */
679 HWTEST_F(NativeWindowTest, SetMetaData005, Function | MediumTest | Level2)
680 {
681 int32_t size = 1;
682 const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
683 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, size, metaData), OHOS::GSERROR_NO_ENTRY);
684 }
685
686 /*
687 * Function: OH_NativeWindow_NativeWindowSetMetaData
688 * Type: Function
689 * Rank: Important(1)
690 * EnvConditions: N/A
691 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
692 */
693 HWTEST_F(NativeWindowTest, SetMetaData006, Function | MediumTest | Level1)
694 {
695 int32_t sequence = 0;
696 int32_t size = 1;
697 const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
698 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, sequence, size, metaData), OHOS::GSERROR_OK);
699 }
700
701 /*
702 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
703 * Type: Function
704 * Rank: Important(2)
705 * EnvConditions: N/A
706 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
707 */
708 HWTEST_F(NativeWindowTest, SetMetaDataSet001, Function | MediumTest | Level2)
709 {
710 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
711 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nullptr, -1, key, 0, nullptr),
712 OHOS::GSERROR_INVALID_ARGUMENTS);
713 }
714
715 /*
716 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
717 * Type: Function
718 * Rank: Important(2)
719 * EnvConditions: N/A
720 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
721 */
722 HWTEST_F(NativeWindowTest, SetMetaDataSet002, Function | MediumTest | Level2)
723 {
724 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
725 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, 0, nullptr),
726 OHOS::GSERROR_INVALID_ARGUMENTS);
727 }
728
729 /*
730 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
731 * Type: Function
732 * Rank: Important(2)
733 * EnvConditions: N/A
734 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
735 */
736 HWTEST_F(NativeWindowTest, SetMetaDataSet003, Function | MediumTest | Level2)
737 {
738 int32_t sequence = 0;
739 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
740 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, 0, nullptr),
741 OHOS::GSERROR_INVALID_ARGUMENTS);
742 }
743
744 /*
745 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
746 * Type: Function
747 * Rank: Important(2)
748 * EnvConditions: N/A
749 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
750 */
751 HWTEST_F(NativeWindowTest, SetMetaDataSet004, Function | MediumTest | Level2)
752 {
753 int32_t sequence = 0;
754 int32_t size = 1;
755 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
756 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, size, nullptr),
757 OHOS::GSERROR_INVALID_ARGUMENTS);
758 }
759
760 /*
761 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
762 * Type: Function
763 * Rank: Important(2)
764 * EnvConditions: N/A
765 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
766 */
767 HWTEST_F(NativeWindowTest, SetMetaDataSet005, Function | MediumTest | Level2)
768 {
769 int32_t size = 1;
770 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
771 const uint8_t metaData[] = {0};
772 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, size, metaData),
773 OHOS::GSERROR_NO_ENTRY);
774 }
775
776 /*
777 * Function: OH_NativeWindow_NativeWindowSetMetaDataSet
778 * Type: Function
779 * Rank: Important(1)
780 * EnvConditions: N/A
781 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with normal parameters and check ret
782 */
783 HWTEST_F(NativeWindowTest, SetMetaDataSet006, Function | MediumTest | Level1)
784 {
785 int32_t sequence = 0;
786 int32_t size = 1;
787 OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
788 const uint8_t metaData[] = {0};
789 ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, sequence, key, size, metaData),
790 OHOS::GSERROR_OK);
791 }
792
793 /*
794 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
795 * Type: Function
796 * Rank: Important(2)
797 * EnvConditions: N/A
798 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
799 */
800 HWTEST_F(NativeWindowTest, SetTunnelHandle001, Function | MediumTest | Level2)
801 {
802 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
803 }
804
805 /*
806 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
807 * Type: Function
808 * Rank: Important(2)
809 * EnvConditions: N/A
810 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
811 */
812 HWTEST_F(NativeWindowTest, SetTunnelHandle002, Function | MediumTest | Level2)
813 {
814 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
815 }
816
817 /*
818 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
819 * Type: Function
820 * Rank: Important(2)
821 * EnvConditions: N/A
822 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
823 */
824 HWTEST_F(NativeWindowTest, SetTunnelHandle003, Function | MediumTest | Level2)
825 {
826 uint32_t reserveInts = 1;
827 OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
828 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
829 FreeOHExtDataHandle(handle);
830 }
831
832 /*
833 * Function: OH_NativeWindow_NativeWindowSetTunnelHandle
834 * Type: Function
835 * Rank: Important(1)
836 * EnvConditions: N/A
837 * CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
838 * @tc.require: issueI5GMZN issueI5IWHW
839 */
840 HWTEST_F(NativeWindowTest, SetTunnelHandle004, Function | MediumTest | Level1)
841 {
842 uint32_t reserveInts = 2;
843 OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
844 nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
845 ASSERT_NE(nativeWindow, nullptr);
846 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
847 ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_NO_ENTRY);
848 FreeOHExtDataHandle(handle);
849 }
850 }
851