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