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