• 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 <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<Surface> csurf = nullptr;
47     static inline sptr<IBufferProducer> producer = nullptr;
48     static inline sptr<Surface> pSurface = nullptr;
49 };
50 
SetUpTestCase()51 void ProducerSurfaceTest::SetUpTestCase()
52 {
53     csurf = Surface::CreateSurfaceAsConsumer();
54     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
55     csurf->RegisterConsumerListener(listener);
56     producer = csurf->GetProducer();
57     pSurface = Surface::CreateSurfaceAsProducer(producer);
58 }
59 
TearDownTestCase()60 void ProducerSurfaceTest::TearDownTestCase()
61 {
62     csurf = nullptr;
63     producer = nullptr;
64     pSurface = nullptr;
65 }
66 
67 /*
68 * Function: ProducerSurface
69 * Type: Function
70 * Rank: Important(2)
71 * EnvConditions: N/A
72 * CaseDescription: 1. check pSurface
73  */
74 HWTEST_F(ProducerSurfaceTest, ProducerSurface001, Function | MediumTest | Level2)
75 {
76     ASSERT_NE(pSurface, nullptr);
77 }
78 
79 /*
80 * Function: SetQueueSize and GetQueueSize
81 * Type: Function
82 * Rank: Important(2)
83 * EnvConditions: N/A
84 * CaseDescription: 1. call GetQueueSize and get default value
85 *                  2. call SetQueueSize
86 *                  3. call SetQueueSize again with abnormal value
87 *                  4. call GetQueueSize
88 *                  5. check ret
89  */
90 HWTEST_F(ProducerSurfaceTest, QueueSize001, Function | MediumTest | Level2)
91 {
92     ASSERT_EQ(pSurface->GetQueueSize(), (uint32_t)SURFACE_DEFAULT_QUEUE_SIZE);
93     GSError ret = pSurface->SetQueueSize(2);
94     ASSERT_EQ(ret, OHOS::GSERROR_OK);
95 
96     ret = pSurface->SetQueueSize(SURFACE_MAX_QUEUE_SIZE + 1);
97     ASSERT_NE(ret, OHOS::GSERROR_OK);
98 
99     ASSERT_EQ(pSurface->GetQueueSize(), 2u);
100 }
101 
102 /*
103 * Function: RequestBuffer and FlushBuffer
104 * Type: Function
105 * Rank: Important(2)
106 * EnvConditions: N/A
107 * CaseDescription: 1. call RequestBuffer
108 *                  2. call FlushBuffer
109 *                  3. check ret
110  */
111 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel001, Function | MediumTest | Level2)
112 {
113     sptr<SurfaceBuffer> buffer;
114 
115     int releaseFence = -1;
116     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
117     ASSERT_EQ(ret, OHOS::GSERROR_OK);
118     ASSERT_NE(buffer, nullptr);
119 
120     ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
121     ASSERT_EQ(ret, OHOS::GSERROR_OK);
122 }
123 
124 /*
125 * Function: RequestBuffer and FlushBuffer
126 * Type: Function
127 * Rank: Important(2)
128 * EnvConditions: N/A
129 * CaseDescription: 1. call RequestBuffer
130 *                  2. call FlushBuffer 2 times
131 *                  3. check ret
132  */
133 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel002, Function | MediumTest | Level2)
134 {
135     sptr<SurfaceBuffer> buffer;
136     int releaseFence = -1;
137 
138     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
139     ASSERT_EQ(ret, OHOS::GSERROR_OK);
140     ASSERT_NE(buffer, nullptr);
141 
142     ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
143     ASSERT_EQ(ret, OHOS::GSERROR_OK);
144 
145     ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
146     ASSERT_NE(ret, OHOS::GSERROR_OK);
147 }
148 
149 /*
150 * Function: AcquireBuffer and ReleaseBuffer
151 * Type: Function
152 * Rank: Important(2)
153 * EnvConditions: N/A
154 * CaseDescription: 1. call AcquireBuffer and ReleaseBuffer many times
155 *                  2. check ret
156  */
157 HWTEST_F(ProducerSurfaceTest, ReqCanFluAcqRel003, Function | MediumTest | Level2)
158 {
159     sptr<SurfaceBuffer> buffer;
160     int32_t flushFence;
161 
162     GSError ret = pSurface->AcquireBuffer(buffer, flushFence, timestamp, damage);
163     ASSERT_NE(ret, OHOS::GSERROR_OK);
164 
165     ret = pSurface->ReleaseBuffer(buffer, -1);
166     ASSERT_NE(ret, OHOS::GSERROR_OK);
167 
168     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->ReleaseBuffer(buffer, -1);
301     ASSERT_NE(ret, OHOS::GSERROR_OK);
302 
303     ret = pSurface->CancelBuffer(buffer);
304     ASSERT_EQ(ret, OHOS::GSERROR_OK);
305 }
306 
307 /*
308 * Function: SetUserData and GetUserData
309 * Type: Function
310 * Rank: Important(2)
311 * EnvConditions: N/A
312 * CaseDescription: 1. call SetUserData and GetUserData many times
313 *                  2. check ret
314  */
315 HWTEST_F(ProducerSurfaceTest, UserData001, Function | MediumTest | Level2)
316 {
317     GSError ret;
318 
319     std::string strs[SURFACE_MAX_USER_DATA_COUNT];
320     constexpr int32_t stringLengthMax = 32;
321     char str[stringLengthMax] = {};
322     for (int i = 0; i < SURFACE_MAX_USER_DATA_COUNT; i++) {
323         auto secRet = snprintf_s(str, sizeof(str), sizeof(str) - 1, "%d", i);
324         ASSERT_GT(secRet, 0);
325 
326         strs[i] = str;
327         ret = pSurface->SetUserData(strs[i], "magic");
328         ASSERT_EQ(ret, OHOS::GSERROR_OK);
329     }
330 
331     ret = pSurface->SetUserData("-1", "error");
332     ASSERT_NE(ret, OHOS::GSERROR_OK);
333 
334     std::string retStr;
335     for (int i = 0; i < SURFACE_MAX_USER_DATA_COUNT; i++) {
336         retStr = pSurface->GetUserData(strs[i]);
337         ASSERT_EQ(retStr, "magic");
338     }
339 }
340 
341 /*
342 * Function: RegisterConsumerListener
343 * Type: Function
344 * Rank: Important(2)
345 * EnvConditions: N/A
346 * CaseDescription: 1. call RegisterConsumerListener
347 *                  2. check ret
348  */
349 HWTEST_F(ProducerSurfaceTest, RegisterConsumerListener001, Function | MediumTest | Level2)
350 {
351     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
352     GSError ret = pSurface->RegisterConsumerListener(listener);
353     ASSERT_NE(ret, OHOS::GSERROR_OK);
354 }
355 
356 /*
357 * Function: GetUniqueId
358 * Type: Function
359 * Rank: Important(2)
360 * EnvConditions: N/A
361 * CaseDescription: 1. call GetUniqueId
362 *                  2. check ret
363  */
364 HWTEST_F(ProducerSurfaceTest, UniqueId001, Function | MediumTest | Level2)
365 {
366     uint64_t uniqueId = pSurface->GetUniqueId();
367     ASSERT_NE(uniqueId, 0);
368 }
369 
370 /*
371 * Function: SetTransform and GetTransform
372 * Type: Function
373 * Rank: Important(2)
374 * EnvConditions: N/A
375 * CaseDescription: 1. call GetTransform with default and check ret
376  */
377 HWTEST_F(ProducerSurfaceTest, transform001, Function | MediumTest | Level2)
378 {
379     ASSERT_EQ(pSurface->GetTransform(), GraphicTransformType::GRAPHIC_ROTATE_BUTT);
380     GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_NONE);
381     ASSERT_EQ(ret, OHOS::GSERROR_OK);
382 }
383 
384 /*
385 * Function: SetTransform and GetTransform
386 * Type: Function
387 * Rank: Important(1)
388 * EnvConditions: N/A
389 * CaseDescription: 1. call SetTransform with other parameters and check ret
390  */
391 HWTEST_F(ProducerSurfaceTest, transform002, Function | MediumTest | Level1)
392 {
393     GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_90);
394     ASSERT_EQ(ret, OHOS::GSERROR_OK);
395 }
396 
397 /*
398 * Function: SetTransform and GetTransform
399 * Type: Function
400 * Rank: Important(1)
401 * EnvConditions: N/A
402 * CaseDescription: 1. call SetTransform with other parameters and check ret
403  */
404 HWTEST_F(ProducerSurfaceTest, transform003, Function | MediumTest | Level1)
405 {
406     GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_180);
407     ASSERT_EQ(ret, OHOS::GSERROR_OK);
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 other parameters and check ret
416  */
417 HWTEST_F(ProducerSurfaceTest, transform004, Function | MediumTest | Level1)
418 {
419     GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_270);
420     ASSERT_EQ(ret, OHOS::GSERROR_OK);
421 }
422 
423 /*
424 * Function: IsSupportedAlloc
425 * Type: Function
426 * Rank: Important(2)
427 * EnvConditions: N/A
428 * CaseDescription: 1. call IsSupportedAlloc with abnormal parameters and check ret
429  */
430 HWTEST_F(ProducerSurfaceTest, isSupportedAlloc001, Function | MediumTest | Level2)
431 {
432     std::vector<BufferVerifyAllocInfo> infos;
433     std::vector<bool> supporteds;
434     GSError ret = pSurface->IsSupportedAlloc(infos, supporteds);
435     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
436 }
437 
438 /*
439 * Function: IsSupportedAlloc
440 * Type: Function
441 * Rank: Important(2)
442 * EnvConditions: N/A
443 * CaseDescription: 1. call IsSupportedAlloc with abnormal parameters and check ret
444  */
445 HWTEST_F(ProducerSurfaceTest, isSupportedAlloc002, Function | MediumTest | Level2)
446 {
447     std::vector<BufferVerifyAllocInfo> infos;
448     std::vector<bool> supporteds;
449     GSError ret = pSurface->IsSupportedAlloc(infos, supporteds);
450     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
451 
452     BufferVerifyAllocInfo info = {
453         .width = 0x100,
454         .height = 0x100,
455         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
456         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
457     };
458     infos.push_back(info);
459     info.format = GRAPHIC_PIXEL_FMT_YCRCB_420_SP;
460     infos.push_back(info);
461     info.format = GRAPHIC_PIXEL_FMT_YUV_422_I;
462     infos.push_back(info);
463 
464     ret = pSurface->IsSupportedAlloc(infos, supporteds);
465     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
466 }
467 
468 /*
469 * Function: IsSupportedAlloc
470 * Type: Function
471 * Rank: Important(1)
472 * EnvConditions: N/A
473 * CaseDescription: 1. call IsSupportedAlloc with normal parameters and check ret
474  */
475 HWTEST_F(ProducerSurfaceTest, isSupportedAlloc003, Function | MediumTest | Level1)
476 {
477     std::vector<BufferVerifyAllocInfo> infos;
478     std::vector<bool> supporteds;
479     BufferVerifyAllocInfo info = {
480         .width = 0x100,
481         .height = 0x100,
482         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
483         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
484     };
485     infos.push_back(info);
486     info.format = GRAPHIC_PIXEL_FMT_YCRCB_420_SP;
487     infos.push_back(info);
488     info.format = GRAPHIC_PIXEL_FMT_YUV_422_I;
489     infos.push_back(info);
490 
491     supporteds.push_back(false);
492     supporteds.push_back(false);
493     supporteds.push_back(false);
494 
495     GSError ret = pSurface->IsSupportedAlloc(infos, supporteds);
496     ASSERT_EQ(ret, OHOS::GSERROR_OK);  // mock data result
497     ASSERT_EQ(supporteds[0], true);  // mock data result
498     ASSERT_EQ(supporteds[1], true);  // mock data result
499     ASSERT_EQ(supporteds[2], false);  // mock data result
500 }
501 
502 /*
503 * Function: SetScalingMode and GetScalingMode
504 * Type: Function
505 * Rank: Important(2)
506 * EnvConditions: N/A
507 * CaseDescription: 1. call SetScalingMode with abnormal parameters and check ret
508  */
509 HWTEST_F(ProducerSurfaceTest, scalingMode001, Function | MediumTest | Level2)
510 {
511     ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
512     GSError ret = pSurface->SetScalingMode(-1, scalingMode);
513     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
514 }
515 
516 /*
517 * Function: SetScalingMode and GetScalingMode
518 * Type: Function
519 * Rank: Important(1)
520 * EnvConditions: N/A
521 * CaseDescription: 1. call SetScalingMode with normal parameters and check ret
522 *                  2. call GetScalingMode and check ret
523  */
524 HWTEST_F(ProducerSurfaceTest, scalingMode002, Function | MediumTest | Level1)
525 {
526     ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
527     sptr<SurfaceBuffer> buffer;
528     int releaseFence = -1;
529     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
530     ASSERT_EQ(ret, OHOS::GSERROR_OK);
531     ASSERT_NE(buffer, nullptr);
532 
533     uint32_t sequence = buffer->GetSeqNum();
534     ret = pSurface->SetScalingMode(sequence, scalingMode);
535     ASSERT_EQ(ret, OHOS::GSERROR_OK);
536 
537     ret = pSurface->GetScalingMode(sequence, scalingMode);
538     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
539 
540     ret = pSurface->CancelBuffer(buffer);
541     ASSERT_EQ(ret, OHOS::GSERROR_OK);
542 }
543 
544 /*
545 * Function: SetMetaData and GetMetaData
546 * Type: Function
547 * Rank: Important(2)
548 * EnvConditions: N/A
549 * CaseDescription: 1. call SetMetaData with abnormal parameters and check ret
550  */
551 HWTEST_F(ProducerSurfaceTest, metaData001, Function | MediumTest | Level2)
552 {
553     uint32_t sequence = 0;
554     std::vector<GraphicHDRMetaData> metaData;
555     GSError ret = pSurface->SetMetaData(sequence, metaData);
556     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
557 }
558 
559 /*
560 * Function: SetMetaData and GetMetaData
561 * Type: Function
562 * Rank: Important(2)
563 * EnvConditions: N/A
564 * CaseDescription: 1. call SetMetaData with abnormal parameters and check ret
565  */
566 HWTEST_F(ProducerSurfaceTest, metaData002, Function | MediumTest | Level2)
567 {
568     std::vector<GraphicHDRMetaData> metaData;
569     GraphicHDRMetaData data = {
570         .key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_RED_PRIMARY_X,
571         .value = 100,  // for test
572     };
573     metaData.push_back(data);
574     GSError ret = pSurface->SetMetaData(-1, metaData);
575     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
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 *                  2. call GetMetaData and check ret
585  */
586 HWTEST_F(ProducerSurfaceTest, metaData003, Function | MediumTest | Level1)
587 {
588     uint32_t sequence = 0;
589     std::vector<GraphicHDRMetaData> metaData;
590     GraphicHDRMetaData data = {
591         .key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_RED_PRIMARY_X,
592         .value = 100,  // for test
593     };
594     metaData.push_back(data);
595     sptr<SurfaceBuffer> buffer;
596     int releaseFence = -1;
597     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
598     ASSERT_EQ(ret, OHOS::GSERROR_OK);
599     ASSERT_NE(buffer, nullptr);
600 
601     sequence = buffer->GetSeqNum();
602     ret = pSurface->SetMetaData(sequence, metaData);
603     ASSERT_EQ(ret, OHOS::GSERROR_OK);
604 
605     ret = pSurface->GetMetaData(sequence, metaData);
606     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
607 
608     ret = pSurface->CancelBuffer(buffer);
609     ASSERT_EQ(ret, OHOS::GSERROR_OK);
610 }
611 
612 /*
613 * Function: SetMetaDataSet and GetMetaDataSet
614 * Type: Function
615 * Rank: Important(2)
616 * EnvConditions: N/A
617 * CaseDescription: 1. call SetMetaDataSet with abnormal parameters and check ret
618  */
619 HWTEST_F(ProducerSurfaceTest, metaDataSet001, Function | MediumTest | Level2)
620 {
621     GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
622     std::vector<uint8_t> metaData;
623 
624     uint32_t sequence = 0;
625     GSError ret = pSurface->SetMetaDataSet(sequence, key, metaData);
626     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
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(ProducerSurfaceTest, metaDataSet002, Function | MediumTest | Level2)
637 {
638     GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
639     std::vector<uint8_t> metaData;
640 
641     uint8_t data = 10;  // for test
642     metaData.push_back(data);
643     GSError ret = pSurface->SetMetaDataSet(-1, key, metaData);
644     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
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 *                  2. call GetMetaDataSet and check ret
654  */
655 HWTEST_F(ProducerSurfaceTest, metaDataSet003, Function | MediumTest | Level1)
656 {
657     GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
658     std::vector<uint8_t> metaData;
659     uint32_t sequence = 0;
660     uint8_t data = 10;  // for test
661     metaData.push_back(data);
662 
663     sptr<SurfaceBuffer> buffer;
664     int releaseFence = -1;
665     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
666     ASSERT_EQ(ret, OHOS::GSERROR_OK);
667     ASSERT_NE(buffer, nullptr);
668 
669     sequence = buffer->GetSeqNum();
670     ret = pSurface->SetMetaDataSet(sequence, key, metaData);
671     ASSERT_EQ(ret, OHOS::GSERROR_OK);
672 
673     ret = pSurface->GetMetaDataSet(sequence, key, metaData);
674     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
675 
676     ret = pSurface->CancelBuffer(buffer);
677     ASSERT_EQ(ret, OHOS::GSERROR_OK);
678 }
679 
680 /*
681 * Function: QueryMetaDataType
682 * Type: Function
683 * Rank: Important(1)
684 * EnvConditions: N/A
685 * CaseDescription: 1. call QueryMetaDataType and check ret
686  */
687 HWTEST_F(ProducerSurfaceTest, QueryMetaDataType001, Function | MediumTest | Level1)
688 {
689     uint32_t sequence = 0;
690     HDRMetaDataType type = HDRMetaDataType::HDR_NOT_USED;
691     GSError ret = pSurface->QueryMetaDataType(sequence, type);
692     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
693 }
694 
695 /*
696 * Function: SetTunnelHandle and GetTunnelHandle
697 * Type: Function
698 * Rank: Important(2)
699 * EnvConditions: N/A
700 * CaseDescription: 1. call GetTunnelhandle and check ret
701 * @tc.require: issueI5GMZN issueI5IWHW
702  */
703 HWTEST_F(ProducerSurfaceTest, tunnelHandle001, Function | MediumTest | Level2)
704 {
705     ASSERT_EQ(pSurface->GetTunnelHandle(), nullptr);
706 }
707 
708 /*
709 * Function: SetTunnelHandle and GetTunnelHandle
710 * Type: Function
711 * Rank: Important(2)
712 * EnvConditions: N/A
713 * CaseDescription: 1. call SetTunnelhandle with normal parameters and check ret
714  */
715 HWTEST_F(ProducerSurfaceTest, tunnelHandle002, Function | MediumTest | Level2)
716 {
717     GraphicExtDataHandle *handle = nullptr;
718     handle = static_cast<GraphicExtDataHandle *>(malloc(sizeof(GraphicExtDataHandle) + sizeof(int32_t) * 1));
719     handle->fd = -1;
720     handle->reserveInts = 1;
721     handle->reserve[0] = 0;
722     GSError ret = pSurface->SetTunnelHandle(handle);
723     ASSERT_EQ(ret, OHOS::GSERROR_OK);
724 
725     ret = pSurface->SetTunnelHandle(handle);
726     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
727     free(handle);
728 }
729 
730 /*
731 * Function: disconnect
732 * Type: Function
733 * Rank: Important(1)
734 * EnvConditions: N/A
735 * CaseDescription: 1. call Disconnect and check ret
736  */
737 HWTEST_F(ProducerSurfaceTest, disconnect001, Function | MediumTest | Level1)
738 {
739     GSError ret = pSurface->Disconnect();
740     ASSERT_EQ(ret, OHOS::GSERROR_OK);
741 }
742 
743 /*
744 * Function: SetPresentTimestamp and GetPresentTimestamp
745 * Type: Function
746 * Rank: Important(2)
747 * EnvConditions: N/A
748 * CaseDescription: 1. call SetPresentTimestamp and check ret
749 * @tc.require: issueI5I57K
750  */
751 HWTEST_F(ProducerSurfaceTest, presentTimestamp001, Function | MediumTest | Level2)
752 {
753     uint32_t sequence = 0;
754     GraphicPresentTimestamp timestamp = {GRAPHIC_DISPLAY_PTS_UNSUPPORTED, 0};
755 
756     GSError ret = pSurface->SetPresentTimestamp(sequence, timestamp);
757     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
758 }
759 
760 /*
761 * Function: SetPresentTimestamp and GetPresentTimestamp
762 * Type: Function
763 * Rank: Important(2)
764 * EnvConditions: N/A
765 * CaseDescription: 1. call GetPresentTimestamp with normal parameters and check ret
766 * @tc.require: issueI5I57K
767  */
768 HWTEST_F(ProducerSurfaceTest, presentTimestamp002, Function | MediumTest | Level2)
769 {
770     uint32_t sequence = 0;
771     GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
772     int64_t time = 0;
773 
774     GSError ret = pSurface->GetPresentTimestamp(sequence, type, time);
775     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
776 }
777 
778 /*
779 * Function: SetPresentTimestamp and GetPresentTimestamp
780 * Type: Function
781 * Rank: Important(2)
782 * EnvConditions: N/A
783 * CaseDescription: 1. call SetPresentTimestamp with normal parameters and check ret
784 * @tc.require: issueI5I57K
785  */
786 HWTEST_F(ProducerSurfaceTest, presentTimestamp003, Function | MediumTest | Level2)
787 {
788     GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_DELAY;
789     int64_t time = 0;
790     GSError ret = pSurface->GetPresentTimestamp(-1, type, time);
791     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
792 }
793 
794 /*
795 * Function: SetPresentTimestamp and GetPresentTimestamp
796 * Type: Function
797 * Rank: Important(1)
798 * EnvConditions: N/A
799 * CaseDescription: 1. call SetPresentTimestamp and check ret
800 * @tc.require: issueI5I57K
801  */
802 HWTEST_F(ProducerSurfaceTest, presentTimestamp004, Function | MediumTest | Level1)
803 {
804     sptr<SurfaceBuffer> buffer;
805     int releaseFence = -1;
806     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
807     ASSERT_EQ(ret, OHOS::GSERROR_OK);
808     ASSERT_NE(buffer, nullptr);
809 
810     uint32_t sequence = buffer->GetSeqNum();
811     GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_DELAY;
812     int64_t time = 0;
813     ret = pSurface->GetPresentTimestamp(sequence, type, time);
814     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
815 
816     ret = pSurface->CancelBuffer(buffer);
817     ASSERT_EQ(ret, OHOS::GSERROR_OK);
818 }
819 }
820