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 <securec.h>
16 #include <gtest/gtest.h>
17 #include <surface.h>
18 #include <consumer_surface.h>
19 #include "buffer_consumer_listener.h"
20 #include <native_window.h>
21 #include "sync_fence.h"
22 #include "producer_surface_delegator.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS::Rosen {
28 class ProducerSurfaceTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32
33 static inline BufferRequestConfig requestConfig = {
34 .width = 0x100,
35 .height = 0x100,
36 .strideAlignment = 0x8,
37 .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
38 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
39 .timeout = 0,
40 };
41 static inline BufferFlushConfig flushConfig = {
42 .damage = {
43 .w = 0x100,
44 .h = 0x100,
45 },
46 };
47 static inline int64_t timestamp = 0;
48 static inline Rect damage = {};
49 static inline sptr<IConsumerSurface> csurf = nullptr;
50 static inline sptr<IBufferProducer> producer = nullptr;
51 static inline sptr<Surface> pSurface = nullptr;
52 static inline sptr<ProducerSurfaceDelegator> surfaceDelegator = nullptr;
53
OnBufferRelease(sptr<SurfaceBuffer> & buffer)54 static inline GSError OnBufferRelease(sptr<SurfaceBuffer> &buffer)
55 {
56 return GSERROR_OK;
57 }
58 };
59
SetUpTestCase()60 void ProducerSurfaceTest::SetUpTestCase()
61 {
62 csurf = IConsumerSurface::Create();
63 sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
64 csurf->RegisterConsumerListener(listener);
65 producer = csurf->GetProducer();
66 pSurface = Surface::CreateSurfaceAsProducer(producer);
67 pSurface->RegisterReleaseListener(OnBufferRelease);
68 }
69
TearDownTestCase()70 void ProducerSurfaceTest::TearDownTestCase()
71 {
72 pSurface->UnRegisterReleaseListener();
73 csurf = nullptr;
74 producer = nullptr;
75 pSurface = nullptr;
76 }
77
78 /*
79 * Function: ProducerSurface
80 * Type: Function
81 * Rank: Important(2)
82 * EnvConditions: N/A
83 * CaseDescription: 1. check pSurface
84 */
85 HWTEST_F(ProducerSurfaceTest, ProducerSurface001, Function | MediumTest | Level2)
86 {
87 ASSERT_NE(pSurface, nullptr);
88 }
89
90 /*
91 * Function: SetQueueSize and GetQueueSize
92 * Type: Function
93 * Rank: Important(2)
94 * EnvConditions: N/A
95 * CaseDescription: 1. call GetQueueSize and get default value
96 * 2. call SetQueueSize
97 * 3. call SetQueueSize again with abnormal value
98 * 4. call GetQueueSize
99 * 5. check ret
100 */
101 HWTEST_F(ProducerSurfaceTest, QueueSize001, Function | MediumTest | Level2)
102 {
103 ASSERT_EQ(pSurface->GetQueueSize(), (uint32_t)SURFACE_DEFAULT_QUEUE_SIZE);
104 GSError ret = pSurface->SetQueueSize(2);
105 ASSERT_EQ(ret, OHOS::GSERROR_OK);
106
107 ret = pSurface->SetQueueSize(SURFACE_MAX_QUEUE_SIZE + 1);
108 ASSERT_NE(ret, OHOS::GSERROR_OK);
109
110 ASSERT_EQ(pSurface->GetQueueSize(), 2u);
111 }
112
113 /*
114 * Function: RequestBuffer and FlushBuffer
115 * Type: Function
116 * Rank: Important(2)
117 * EnvConditions: N/A
118 * CaseDescription: 1. call RequestBuffer
119 * 2. call FlushBuffer
120 * 3. check ret
121 */
122 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel001, Function | MediumTest | Level2)
123 {
124 sptr<SurfaceBuffer> buffer;
125
126 int releaseFence = -1;
127 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
128 ASSERT_EQ(ret, OHOS::GSERROR_OK);
129 ASSERT_NE(buffer, nullptr);
130
131 ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
132 ASSERT_EQ(ret, OHOS::GSERROR_OK);
133 }
134
135 /*
136 * Function: RequestBuffer and FlushBuffer
137 * Type: Function
138 * Rank: Important(2)
139 * EnvConditions: N/A
140 * CaseDescription: 1. call RequestBuffer
141 * 2. call FlushBuffer 2 times
142 * 3. check ret
143 */
144 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel002, Function | MediumTest | Level2)
145 {
146 sptr<SurfaceBuffer> buffer;
147 int releaseFence = -1;
148
149 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
150 ASSERT_EQ(ret, OHOS::GSERROR_OK);
151 ASSERT_NE(buffer, nullptr);
152
153 ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
154 ASSERT_EQ(ret, OHOS::GSERROR_OK);
155
156 ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
157 ASSERT_NE(ret, OHOS::GSERROR_OK);
158 }
159
160 /*
161 * Function: AcquireBuffer and ReleaseBuffer
162 * Type: Function
163 * Rank: Important(2)
164 * EnvConditions: N/A
165 * CaseDescription: 1. call AcquireBuffer and ReleaseBuffer many times
166 * 2. check ret
167 */
168 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel003, Function | MediumTest | Level2)
169 {
170 sptr<SurfaceBuffer> buffer;
171 int32_t flushFence;
172
173 GSError ret = csurf->AcquireBuffer(buffer, flushFence, timestamp, damage);
174 ASSERT_EQ(ret, OHOS::GSERROR_OK);
175
176 ret = csurf->ReleaseBuffer(buffer, -1);
177 ASSERT_EQ(ret, OHOS::GSERROR_OK);
178
179 ret = csurf->AcquireBuffer(buffer, flushFence, timestamp, damage);
180 ASSERT_EQ(ret, OHOS::GSERROR_OK);
181
182 ret = csurf->ReleaseBuffer(buffer, -1);
183 ASSERT_EQ(ret, OHOS::GSERROR_OK);
184 }
185
186 /*
187 * Function: RequestBuffer and CancelBuffer
188 * Type: Function
189 * Rank: Important(2)
190 * EnvConditions: N/A
191 * CaseDescription: 1. call RequestBuffer
192 * 2. call CancelBuffer
193 * 3. check ret
194 */
195 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel004, Function | MediumTest | Level2)
196 {
197 sptr<SurfaceBuffer> buffer;
198
199 int releaseFence = -1;
200 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
201 ASSERT_EQ(ret, OHOS::GSERROR_OK);
202
203 ret = pSurface->CancelBuffer(buffer);
204 ASSERT_EQ(ret, OHOS::GSERROR_OK);
205 }
206
207 /*
208 * Function: RequestBuffer and CancelBuffer
209 * Type: Function
210 * Rank: Important(2)
211 * EnvConditions: N/A
212 * CaseDescription: 1. call RequestBuffer
213 * 2. call CancelBuffer 2 times
214 * 3. check ret
215 */
216 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel005, Function | MediumTest | Level2)
217 {
218 sptr<SurfaceBuffer> buffer;
219
220 int releaseFence = -1;
221 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
222 ASSERT_EQ(ret, OHOS::GSERROR_OK);
223
224 ret = pSurface->CancelBuffer(buffer);
225 ASSERT_EQ(ret, OHOS::GSERROR_OK);
226
227 ret = pSurface->CancelBuffer(buffer);
228 ASSERT_NE(ret, OHOS::GSERROR_OK);
229 }
230
231 /*
232 * Function: RequestBuffer and CancelBuffer
233 * Type: Function
234 * Rank: Important(2)
235 * EnvConditions: N/A
236 * CaseDescription: 1. call RequestBuffer and CancelBuffer many times
237 * 2. check ret
238 */
239 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel006, Function | MediumTest | Level2)
240 {
241 sptr<SurfaceBuffer> buffer;
242 sptr<SurfaceBuffer> buffer1;
243 sptr<SurfaceBuffer> buffer2;
244 int releaseFence = -1;
245
246 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
247 ASSERT_EQ(ret, OHOS::GSERROR_OK);
248
249 ret = pSurface->RequestBuffer(buffer1, releaseFence, requestConfig);
250 ASSERT_EQ(ret, OHOS::GSERROR_OK);
251
252 ret = pSurface->RequestBuffer(buffer2, releaseFence, requestConfig);
253 ASSERT_NE(ret, OHOS::GSERROR_OK);
254
255 ret = pSurface->CancelBuffer(buffer);
256 ASSERT_EQ(ret, OHOS::GSERROR_OK);
257
258 ret = pSurface->CancelBuffer(buffer1);
259 ASSERT_EQ(ret, OHOS::GSERROR_OK);
260
261 ret = pSurface->CancelBuffer(buffer2);
262 ASSERT_NE(ret, OHOS::GSERROR_OK);
263 }
264
265 /*
266 * Function: GetQueueSize and SetQueueSize
267 * Type: Function
268 * Rank: Important(2)
269 * EnvConditions: N/A
270 * CaseDescription: 1. call GetQeueSize
271 * 2. call SetQueueSize 2 times
272 * 3. check ret
273 */
274 HWTEST_F(ProducerSurfaceTest, SetQueueSizeDeleting001, Function | MediumTest | Level2)
275 {
276 sptr<ConsumerSurface> cs = static_cast<ConsumerSurface*>(csurf.GetRefPtr());
277 sptr<BufferQueueProducer> bqp = static_cast<BufferQueueProducer*>(cs->GetProducer().GetRefPtr());
278 ASSERT_EQ(bqp->GetQueueSize(), 2u);
279
280 GSError ret = pSurface->SetQueueSize(1);
281 ASSERT_EQ(ret, OHOS::GSERROR_OK);
282
283 ret = pSurface->SetQueueSize(2);
284 ASSERT_EQ(ret, OHOS::GSERROR_OK);
285 }
286
287 /*
288 * Function: RequestBuffer, ReleaseBuffer and CancelBuffer
289 * Type: Function
290 * Rank: Important(2)
291 * EnvConditions: N/A
292 * CaseDescription: 1. call RequestBuffer
293 * 2. call ReleaseBuffer
294 * 3. call CancelBuffer
295 * 4. check ret
296 */
297 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel007, Function | MediumTest | Level2)
298 {
299 sptr<SurfaceBuffer> buffer;
300
301 int releaseFence = -1;
302 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
303 ASSERT_EQ(ret, OHOS::GSERROR_OK);
304
305 ret = pSurface->CancelBuffer(buffer);
306 ASSERT_EQ(ret, OHOS::GSERROR_OK);
307 }
308
309 /*
310 * Function: SetUserData and GetUserData
311 * Type: Function
312 * Rank: Important(2)
313 * EnvConditions: N/A
314 * CaseDescription: 1. call SetUserData and GetUserData many times
315 * 2. check ret
316 */
317 HWTEST_F(ProducerSurfaceTest, UserData001, Function | MediumTest | Level2)
318 {
319 GSError ret;
320
321 std::string strs[SURFACE_MAX_USER_DATA_COUNT];
322 constexpr int32_t stringLengthMax = 32;
323 char str[stringLengthMax] = {};
324 for (int i = 0; i < SURFACE_MAX_USER_DATA_COUNT; i++) {
325 auto secRet = snprintf_s(str, sizeof(str), sizeof(str) - 1, "%d", i);
326 ASSERT_GT(secRet, 0);
327
328 strs[i] = str;
329 ret = pSurface->SetUserData(strs[i], "magic");
330 ASSERT_EQ(ret, OHOS::GSERROR_OK);
331 }
332
333 ret = pSurface->SetUserData("-1", "error");
334 ASSERT_NE(ret, OHOS::GSERROR_OK);
335
336 std::string retStr;
337 for (int i = 0; i < SURFACE_MAX_USER_DATA_COUNT; i++) {
338 retStr = pSurface->GetUserData(strs[i]);
339 ASSERT_EQ(retStr, "magic");
340 }
341 }
342
343 /*
344 * Function: GetUniqueId
345 * Type: Function
346 * Rank: Important(2)
347 * EnvConditions: N/A
348 * CaseDescription: 1. call GetUniqueId
349 * 2. check ret
350 */
351 HWTEST_F(ProducerSurfaceTest, UniqueId001, Function | MediumTest | Level2)
352 {
353 uint64_t uniqueId = pSurface->GetUniqueId();
354 ASSERT_NE(uniqueId, 0);
355 }
356
357 /*
358 * Function: SetTransform and GetTransform
359 * Type: Function
360 * Rank: Important(2)
361 * EnvConditions: N/A
362 * CaseDescription: 1. call GetTransform with default and check ret
363 */
364 HWTEST_F(ProducerSurfaceTest, transform001, Function | MediumTest | Level2)
365 {
366 GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_NONE);
367 ASSERT_EQ(ret, OHOS::GSERROR_OK);
368 }
369
370 /*
371 * Function: SetTransform and GetTransform
372 * Type: Function
373 * Rank: Important(1)
374 * EnvConditions: N/A
375 * CaseDescription: 1. call SetTransform with other parameters and check ret
376 */
377 HWTEST_F(ProducerSurfaceTest, transform002, Function | MediumTest | Level1)
378 {
379 GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_90);
380 ASSERT_EQ(ret, OHOS::GSERROR_OK);
381 }
382
383 /*
384 * Function: SetTransform and GetTransform
385 * Type: Function
386 * Rank: Important(1)
387 * EnvConditions: N/A
388 * CaseDescription: 1. call SetTransform with other parameters and check ret
389 */
390 HWTEST_F(ProducerSurfaceTest, transform003, Function | MediumTest | Level1)
391 {
392 GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_180);
393 ASSERT_EQ(ret, OHOS::GSERROR_OK);
394 }
395
396 /*
397 * Function: SetTransform and GetTransform
398 * Type: Function
399 * Rank: Important(1)
400 * EnvConditions: N/A
401 * CaseDescription: 1. call SetTransform with other parameters and check ret
402 */
403 HWTEST_F(ProducerSurfaceTest, transform004, Function | MediumTest | Level1)
404 {
405 GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_270);
406 ASSERT_EQ(ret, OHOS::GSERROR_OK);
407 }
408
409 /*
410 * Function: IsSupportedAlloc
411 * Type: Function
412 * Rank: Important(2)
413 * EnvConditions: N/A
414 * CaseDescription: 1. call IsSupportedAlloc with abnormal parameters and check ret
415 */
416 HWTEST_F(ProducerSurfaceTest, isSupportedAlloc001, Function | MediumTest | Level2)
417 {
418 std::vector<BufferVerifyAllocInfo> infos;
419 std::vector<bool> supporteds;
420 GSError ret = pSurface->IsSupportedAlloc(infos, supporteds);
421 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
422 }
423
424 /*
425 * Function: IsSupportedAlloc
426 * Type: Function
427 * Rank: Important(2)
428 * EnvConditions: N/A
429 * CaseDescription: 1. call IsSupportedAlloc with abnormal parameters and check ret
430 */
431 HWTEST_F(ProducerSurfaceTest, isSupportedAlloc002, Function | MediumTest | Level2)
432 {
433 std::vector<BufferVerifyAllocInfo> infos;
434 std::vector<bool> supporteds;
435 GSError ret = pSurface->IsSupportedAlloc(infos, supporteds);
436 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
437
438 BufferVerifyAllocInfo info = {
439 .width = 0x100,
440 .height = 0x100,
441 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
442 .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
443 };
444 infos.push_back(info);
445 info.format = GRAPHIC_PIXEL_FMT_YCRCB_420_SP;
446 infos.push_back(info);
447 info.format = GRAPHIC_PIXEL_FMT_YUV_422_I;
448 infos.push_back(info);
449
450 ret = pSurface->IsSupportedAlloc(infos, supporteds);
451 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
452 }
453
454 /*
455 * Function: IsSupportedAlloc
456 * Type: Function
457 * Rank: Important(1)
458 * EnvConditions: N/A
459 * CaseDescription: 1. call IsSupportedAlloc with normal parameters and check ret
460 */
461 HWTEST_F(ProducerSurfaceTest, isSupportedAlloc003, Function | MediumTest | Level1)
462 {
463 std::vector<BufferVerifyAllocInfo> infos;
464 std::vector<bool> supporteds;
465 BufferVerifyAllocInfo info = {
466 .width = 0x100,
467 .height = 0x100,
468 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
469 .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
470 };
471 infos.push_back(info);
472 info.format = GRAPHIC_PIXEL_FMT_YCRCB_420_SP;
473 infos.push_back(info);
474 info.format = GRAPHIC_PIXEL_FMT_YUV_422_I;
475 infos.push_back(info);
476
477 supporteds.push_back(false);
478 supporteds.push_back(false);
479 supporteds.push_back(false);
480
481 GSError ret = pSurface->IsSupportedAlloc(infos, supporteds);
482 ASSERT_EQ(ret, OHOS::GSERROR_OK); // mock data result
483 ASSERT_EQ(supporteds[0], true); // mock data result
484 ASSERT_EQ(supporteds[1], true); // mock data result
485 ASSERT_EQ(supporteds[2], false); // mock data result
486 }
487
488 /*
489 * Function: SetScalingMode and GetScalingMode
490 * Type: Function
491 * Rank: Important(2)
492 * EnvConditions: N/A
493 * CaseDescription: 1. call SetScalingMode with abnormal parameters and check ret
494 */
495 HWTEST_F(ProducerSurfaceTest, scalingMode001, Function | MediumTest | Level2)
496 {
497 ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
498 GSError ret = pSurface->SetScalingMode(-1, scalingMode);
499 ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
500 }
501
502 /*
503 * Function: SetScalingMode and GetScalingMode
504 * Type: Function
505 * Rank: Important(1)
506 * EnvConditions: N/A
507 * CaseDescription: 1. call SetScalingMode with normal parameters and check ret
508 * 2. call GetScalingMode and check ret
509 */
510 HWTEST_F(ProducerSurfaceTest, scalingMode002, Function | MediumTest | Level1)
511 {
512 ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
513 sptr<SurfaceBuffer> buffer;
514 int releaseFence = -1;
515 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
516 ASSERT_EQ(ret, OHOS::GSERROR_OK);
517 ASSERT_NE(buffer, nullptr);
518
519 uint32_t sequence = buffer->GetSeqNum();
520 ret = pSurface->SetScalingMode(sequence, scalingMode);
521 ASSERT_EQ(ret, OHOS::GSERROR_OK);
522
523 ret = pSurface->CancelBuffer(buffer);
524 ASSERT_EQ(ret, OHOS::GSERROR_OK);
525 }
526
527 /*
528 * Function: SetMetaData and GetMetaData
529 * Type: Function
530 * Rank: Important(2)
531 * EnvConditions: N/A
532 * CaseDescription: 1. call SetMetaData with abnormal parameters and check ret
533 */
534 HWTEST_F(ProducerSurfaceTest, metaData001, Function | MediumTest | Level2)
535 {
536 uint32_t sequence = 0;
537 std::vector<GraphicHDRMetaData> metaData;
538 GSError ret = pSurface->SetMetaData(sequence, metaData);
539 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
540 }
541
542 /*
543 * Function: SetMetaData and GetMetaData
544 * Type: Function
545 * Rank: Important(2)
546 * EnvConditions: N/A
547 * CaseDescription: 1. call SetMetaData with abnormal parameters and check ret
548 */
549 HWTEST_F(ProducerSurfaceTest, metaData002, Function | MediumTest | Level2)
550 {
551 std::vector<GraphicHDRMetaData> metaData;
552 GraphicHDRMetaData data = {
553 .key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_RED_PRIMARY_X,
554 .value = 100, // for test
555 };
556 metaData.push_back(data);
557 GSError ret = pSurface->SetMetaData(-1, metaData);
558 ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
559 }
560
561 /*
562 * Function: SetMetaData and GetMetaData
563 * Type: Function
564 * Rank: Important(1)
565 * EnvConditions: N/A
566 * CaseDescription: 1. call SetMetaData with normal parameters and check ret
567 * 2. call GetMetaData and check ret
568 */
569 HWTEST_F(ProducerSurfaceTest, metaData003, Function | MediumTest | Level1)
570 {
571 uint32_t sequence = 0;
572 std::vector<GraphicHDRMetaData> metaData;
573 GraphicHDRMetaData data = {
574 .key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_RED_PRIMARY_X,
575 .value = 100, // for test
576 };
577 metaData.push_back(data);
578 sptr<SurfaceBuffer> buffer;
579 int releaseFence = -1;
580 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
581 ASSERT_EQ(ret, OHOS::GSERROR_OK);
582 ASSERT_NE(buffer, nullptr);
583
584 sequence = buffer->GetSeqNum();
585 ret = pSurface->SetMetaData(sequence, metaData);
586 ASSERT_EQ(ret, OHOS::GSERROR_OK);
587
588 ret = pSurface->CancelBuffer(buffer);
589 ASSERT_EQ(ret, OHOS::GSERROR_OK);
590 }
591
592 /*
593 * Function: SetMetaDataSet and GetMetaDataSet
594 * Type: Function
595 * Rank: Important(2)
596 * EnvConditions: N/A
597 * CaseDescription: 1. call SetMetaDataSet with abnormal parameters and check ret
598 */
599 HWTEST_F(ProducerSurfaceTest, metaDataSet001, Function | MediumTest | Level2)
600 {
601 GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
602 std::vector<uint8_t> metaData;
603
604 uint32_t sequence = 0;
605 GSError ret = pSurface->SetMetaDataSet(sequence, key, metaData);
606 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
607 }
608
609 /*
610 * Function: SetMetaDataSet and GetMetaDataSet
611 * Type: Function
612 * Rank: Important(2)
613 * EnvConditions: N/A
614 * CaseDescription: 1. call SetMetaDataSet with abnormal parameters and check ret
615 */
616 HWTEST_F(ProducerSurfaceTest, metaDataSet002, Function | MediumTest | Level2)
617 {
618 GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
619 std::vector<uint8_t> metaData;
620
621 uint8_t data = 10; // for test
622 metaData.push_back(data);
623 GSError ret = pSurface->SetMetaDataSet(-1, key, metaData);
624 ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
625 }
626
627 /*
628 * Function: SetMetaDataSet and GetMetaDataSet
629 * Type: Function
630 * Rank: Important(1)
631 * EnvConditions: N/A
632 * CaseDescription: 1. call SetMetaDataSet with normal parameters and check ret
633 * 2. call GetMetaDataSet and check ret
634 */
635 HWTEST_F(ProducerSurfaceTest, metaDataSet003, Function | MediumTest | Level1)
636 {
637 GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
638 std::vector<uint8_t> metaData;
639 uint32_t sequence = 0;
640 uint8_t data = 10; // for test
641 metaData.push_back(data);
642
643 sptr<SurfaceBuffer> buffer;
644 int releaseFence = -1;
645 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
646 ASSERT_EQ(ret, OHOS::GSERROR_OK);
647 ASSERT_NE(buffer, nullptr);
648
649 sequence = buffer->GetSeqNum();
650 ret = pSurface->SetMetaDataSet(sequence, key, metaData);
651 ASSERT_EQ(ret, OHOS::GSERROR_OK);
652
653 ret = pSurface->CancelBuffer(buffer);
654 ASSERT_EQ(ret, OHOS::GSERROR_OK);
655 }
656
657 /*
658 * Function: SetTunnelHandle and GetTunnelHandle
659 * Type: Function
660 * Rank: Important(2)
661 * EnvConditions: N/A
662 * CaseDescription: 1. call SetTunnelhandle with normal parameters and check ret
663 */
664 HWTEST_F(ProducerSurfaceTest, tunnelHandle002, Function | MediumTest | Level2)
665 {
666 GraphicExtDataHandle *handle = nullptr;
667 handle = static_cast<GraphicExtDataHandle *>(malloc(sizeof(GraphicExtDataHandle) + sizeof(int32_t) * 1));
668 handle->fd = -1;
669 handle->reserveInts = 1;
670 handle->reserve[0] = 0;
671 GSError ret = pSurface->SetTunnelHandle(handle);
672 ASSERT_EQ(ret, OHOS::GSERROR_OK);
673
674 ret = pSurface->SetTunnelHandle(handle);
675 ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
676 free(handle);
677 }
678
679 /*
680 * Function: disconnect
681 * Type: Function
682 * Rank: Important(1)
683 * EnvConditions: N/A
684 * CaseDescription: 1. call Disconnect and check ret
685 */
686 HWTEST_F(ProducerSurfaceTest, disconnect001, Function | MediumTest | Level1)
687 {
688 GSError ret = pSurface->Disconnect();
689 ASSERT_EQ(ret, OHOS::GSERROR_OK);
690 }
691
692 /*
693 * Function: SetPresentTimestamp and GetPresentTimestamp
694 * Type: Function
695 * Rank: Important(2)
696 * EnvConditions: N/A
697 * CaseDescription: 1. call GetPresentTimestamp with normal parameters and check ret
698 * @tc.require: issueI5I57K
699 */
700 HWTEST_F(ProducerSurfaceTest, presentTimestamp002, Function | MediumTest | Level2)
701 {
702 uint32_t sequence = 0;
703 GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
704 int64_t time = 0;
705
706 GSError ret = pSurface->GetPresentTimestamp(sequence, type, time);
707 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
708 }
709
710 /*
711 * Function: SetPresentTimestamp and GetPresentTimestamp
712 * Type: Function
713 * Rank: Important(2)
714 * EnvConditions: N/A
715 * CaseDescription: 1. call SetPresentTimestamp with normal parameters and check ret
716 * @tc.require: issueI5I57K
717 */
718 HWTEST_F(ProducerSurfaceTest, presentTimestamp003, Function | MediumTest | Level2)
719 {
720 GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_DELAY;
721 int64_t time = 0;
722 GSError ret = pSurface->GetPresentTimestamp(-1, type, time);
723 ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
724 }
725
726 /*
727 * Function: SetPresentTimestamp and GetPresentTimestamp
728 * Type: Function
729 * Rank: Important(1)
730 * EnvConditions: N/A
731 * CaseDescription: 1. call SetPresentTimestamp and check ret
732 * @tc.require: issueI5I57K
733 */
734 HWTEST_F(ProducerSurfaceTest, presentTimestamp004, Function | MediumTest | Level1)
735 {
736 sptr<SurfaceBuffer> buffer;
737 int releaseFence = -1;
738 GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
739 ASSERT_EQ(ret, OHOS::GSERROR_OK);
740 ASSERT_NE(buffer, nullptr);
741
742 uint32_t sequence = buffer->GetSeqNum();
743 GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_DELAY;
744 int64_t time = 0;
745 ret = pSurface->GetPresentTimestamp(sequence, type, time);
746 ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
747
748 ret = pSurface->CancelBuffer(buffer);
749 ASSERT_EQ(ret, OHOS::GSERROR_OK);
750 }
751
752 /*
753 * Function: SetWptrNativeWindowToPSurface
754 * Type: Function
755 * Rank: Important(1)
756 * EnvConditions: N/A
757 * CaseDescription: 1. SetWptrNativeWindowToPSurface and check ret
758 * @tc.require: issueI7WYIY
759 */
760 HWTEST_F(ProducerSurfaceTest, SetWptrNativeWindowToPSurface001, Function | MediumTest | Level1)
761 {
762 struct NativeWindow nativeWindow;
763 GSError ret = pSurface->SetWptrNativeWindowToPSurface(&nativeWindow);
764 ASSERT_EQ(ret, OHOS::GSERROR_OK);
765 }
766
767 /*
768 * Function: AttachBuffer
769 * Type: Function
770 * Rank: Important(1)
771 * EnvConditions: N/A
772 * CaseDescription: 1. AttachBuffer and check ret
773 * @tc.require: issueI7WYIY
774 */
775 HWTEST_F(ProducerSurfaceTest, AttachBuffer001, Function | MediumTest | Level1)
776 {
777 GSError ret = pSurface->CleanCache();
778 ASSERT_EQ(ret, OHOS::GSERROR_OK);
779 sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
780 ASSERT_NE(buffer, nullptr);
781 sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
782 int32_t timeOut = 5;
783 ret = pSurface->AttachBuffer(buffer, timeOut);
784 ASSERT_EQ(ret, OHOS::GSERROR_OK);
785 }
786
787 /*
788 * Function: RegisterSurfaceDelegator000
789 * Type: Function
790 * Rank: Important(1)
791 * EnvConditions: N/A
792 * CaseDescription: 1. RegisterSurfaceDelegator and check ret
793 * @tc.require: issueI7WYIY
794 */
795 HWTEST_F(ProducerSurfaceTest, RegisterSurfaceDelegator001, Function | MediumTest | Level1)
796 {
797 GSError ret = pSurface->CleanCache();
798 ASSERT_EQ(ret, OHOS::GSERROR_OK);
799 ret = pSurface->RegisterSurfaceDelegator(nullptr);
800 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
801 }
802 }
803