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