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