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