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