• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <gtest/gtest.h>
16 #include <securec.h>
17 #include <sys/time.h>
18 
19 #include "buffer_consumer_listener.h"
20 #include "consumer_surface.h"
21 #include "metadata_helper.h"
22 #include "native_window.h"
23 #include "producer_surface.h"
24 #include "producer_surface_delegator.h"
25 #include "surface.h"
26 #include "surface_buffer_impl.h"
27 #include "sync_fence.h"
28 
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace OHOS::HDI::Display::Graphic::Common::V1_0;
32 
33 namespace OHOS::Rosen {
34 class ProducerSurfaceTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp() override;
39     void TearDown() override;
40 
41     static inline BufferRequestConfig requestConfig = {
42         .width = 0x100,
43         .height = 0x100,
44         .strideAlignment = 0x8,
45         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
46         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
47         .timeout = 0,
48     };
49     static inline BufferFlushConfig flushConfig = {
50         .damage = {
51             .w = 0x100,
52             .h = 0x100,
53         },
54     };
55     static inline int64_t timestamp = 0;
56     static inline Rect damage = {};
57     static inline sptr<IConsumerSurface> csurf = nullptr;
58     static inline sptr<IBufferProducer> producer = nullptr;
59     static inline sptr<Surface> pSurface = nullptr;
60     static inline sptr<ProducerSurfaceDelegator> surfaceDelegator = nullptr;
61     static inline uint32_t firstSeqnum = 0;
62 
OnBufferRelease(sptr<SurfaceBuffer> & buffer)63     static inline GSError OnBufferRelease(sptr<SurfaceBuffer> &buffer)
64     {
65         return GSERROR_OK;
66     }
67     sptr<ProducerSurface> surface_ = nullptr;
68     sptr<ProducerSurface> surfaceMd_ = nullptr;
69 };
70 
SetUpTestCase()71 void ProducerSurfaceTest::SetUpTestCase()
72 {
73     csurf = IConsumerSurface::Create();
74     sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
75     csurf->RegisterConsumerListener(listener);
76     producer = csurf->GetProducer();
77     pSurface = Surface::CreateSurfaceAsProducer(producer);
78     pSurface->RegisterReleaseListener(OnBufferRelease);
79 }
80 
TearDownTestCase()81 void ProducerSurfaceTest::TearDownTestCase()
82 {
83     pSurface->UnRegisterReleaseListener();
84     csurf = nullptr;
85     producer = nullptr;
86     pSurface = nullptr;
87 }
88 
SetUp()89 void ProducerSurfaceTest::SetUp()
90 {
91     surface_ = new ProducerSurface(producer);
92     ASSERT_NE(surface_, nullptr);
93     surface_->producer_ = nullptr;
94 
95     surfaceMd_ = new ProducerSurface(producer);
96     ASSERT_NE(surfaceMd_, nullptr);
97     surfaceMd_->producer_ = nullptr;
98 }
99 
TearDown()100 void ProducerSurfaceTest::TearDown()
101 {
102     surface_ = nullptr;
103 }
104 
105 /*
106 * Function: ProducerSurface
107 * Type: Function
108 * Rank: Important(2)
109 * EnvConditions: N/A
110 * CaseDescription: 1. check pSurface
111  */
112 HWTEST_F(ProducerSurfaceTest, ProducerSurfaceCheck, Function | MediumTest | Level2)
113 {
114     ASSERT_NE(pSurface, nullptr);
115 }
116 
117 /*
118 * Function: GetProducerInitInfo
119 * Type: Function
120 * Rank: Important(2)
121 * EnvConditions: N/A
122 * CaseDescription: 1. check pSurface
123  */
124 HWTEST_F(ProducerSurfaceTest, GetProducerInitInfoTest, Function | MediumTest | Level2)
125 {
126     ProducerInitInfo info;
127     GSError ret = surface_->GetProducerInitInfo(info);
128     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
129 }
130 
131 /*
132 * Function: RequestBuffer
133 * Type: Function
134 * Rank: Important(2)
135 * EnvConditions: N/A
136 * CaseDescription: 1. call RequestBuffer with nullptr params
137 *                  2. check ret
138  */
139 HWTEST_F(ProducerSurfaceTest, RequestBufferTest001, Function | MediumTest | Level2)
140 {
141     sptr<SurfaceBuffer> buffer = nullptr;
142     sptr<SyncFence> releaseFence = nullptr;
143     GSError ret = surface_->RequestBuffer(buffer, releaseFence, requestConfig);
144     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
145 }
146 
147 /*
148 * Function: RequestBuffer
149 * Type: Function
150 * Rank: Important(2)
151 * EnvConditions: N/A
152 * CaseDescription: 1. call RequestBuffer with nullptr params
153 *                  2. check ret
154  */
155 HWTEST_F(ProducerSurfaceTest, RequestBufferTest002, Function | MediumTest | Level2)
156 {
157     sptr<SurfaceBuffer> buffer = nullptr;
158     int releaseFence = -1;
159     GSError ret = surface_->RequestBuffer(buffer, releaseFence, requestConfig);
160     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
161 }
162 
163 /*
164 * Function: RequestBuffer
165 * Type: Function
166 * Rank: Important(2)
167 * EnvConditions: N/A
168 * CaseDescription: 1. call RequestBuffer with nullptr params
169 *                  2. check ret
170  */
171 HWTEST_F(ProducerSurfaceTest, RequestBufferTest003, Function | MediumTest | Level2)
172 {
173     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
174     sptr<SyncFence> releaseFence = nullptr;
175     GSError ret = surface_->RequestBuffer(buffer, releaseFence, requestConfig);
176     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
177 }
178 
179 /*
180 * Function: RequestBuffer
181 * Type: Function
182 * Rank: Important(2)
183 * EnvConditions: N/A
184 * CaseDescription: 1. call RequestBuffer with producer_ is nullptr
185 *                  2. check ret
186  */
187 HWTEST_F(ProducerSurfaceTest, RequestBufferTest004, Function | MediumTest | Level2)
188 {
189     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
190     int releaseFence = -1;
191     GSError ret = surface_->RequestBuffer(buffer, releaseFence, requestConfig);
192     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
193 }
194 
195 /*
196 * Function: RequestBuffers
197 * Type: Function
198 * Rank: Important(2)
199 * EnvConditions: N/A
200 * CaseDescription: 1. call RequestBuffers with producer_ is nullptr
201 *                  2. check ret
202  */
203 HWTEST_F(ProducerSurfaceTest, RequestBuffersTest, Function | MediumTest | Level2)
204 {
205     std::vector<sptr<SurfaceBuffer>> sfbuffers;
206     std::vector<sptr<SyncFence>> releaseFences;
207     GSError ret = surface_->RequestBuffers(sfbuffers, releaseFences, requestConfig);
208     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
209 }
210 
211 /*
212 * Function: FlushBuffer
213 * Type: Function
214 * Rank: Important(2)
215 * EnvConditions: N/A
216 * CaseDescription: 1. call FlushBuffer with nullptr params
217 *                  2. check ret
218  */
219 HWTEST_F(ProducerSurfaceTest, FlushBufferTest001, Function | MediumTest | Level2)
220 {
221     sptr<SurfaceBuffer> buffer = nullptr;
222     GSError ret = surface_->FlushBuffer(buffer, SyncFence::INVALID_FENCE, flushConfig);
223     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
224 }
225 
226 /*
227 * Function: FlushBuffer
228 * Type: Function
229 * Rank: Important(2)
230 * EnvConditions: N/A
231 * CaseDescription: 1. call FlushBuffer with producer_ is nullptr
232 *                  2. check ret
233  */
234 HWTEST_F(ProducerSurfaceTest, FlushBufferTest002, Function | MediumTest | Level2)
235 {
236     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
237     GSError ret = surface_->FlushBuffer(buffer, SyncFence::INVALID_FENCE, flushConfig);
238     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
239 }
240 
241 /*
242 * Function: FlushBuffer
243 * Type: Function
244 * Rank: Important(2)
245 * EnvConditions: N/A
246 * CaseDescription: 1. call FlushBuffer with nullptr params
247 *                  2. check ret
248  */
249 HWTEST_F(ProducerSurfaceTest, FlushBufferTest003, Function | MediumTest | Level2)
250 {
251     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
252     GSError ret = surface_->FlushBuffer(buffer, nullptr, flushConfig);
253     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
254 }
255 
256 /*
257 * Function: FlushBuffers
258 * Type: Function
259 * Rank: Important(2)
260 * EnvConditions: N/A
261 * CaseDescription: 1. call FlushBuffers with producer_ is nullptr
262 *                  2. check ret
263  */
264 HWTEST_F(ProducerSurfaceTest, FlushBuffersTest, Function | MediumTest | Level2)
265 {
266     std::vector<sptr<SurfaceBuffer>> buffers;
267     buffers.push_back(SurfaceBuffer::Create());
268     std::vector<sptr<SyncFence>> flushFences;
269     std::vector<BufferFlushConfigWithDamages> configs;
270     GSError ret = surface_->FlushBuffers(buffers, flushFences, configs);
271     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
272 }
273 
274 /*
275 * Function: GetLastFlushedBuffer
276 * Type: Function
277 * Rank: Important(2)
278 * EnvConditions: N/A
279 * CaseDescription: 1. call GetLastFlushedBuffer with producer_ is nullptr
280 *                  2. check ret
281  */
282 HWTEST_F(ProducerSurfaceTest, GetLastFlushedBufferTest, Function | MediumTest | Level2)
283 {
284     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
285     sptr<SyncFence> fence;
286     float matrix[16];
287     GSError ret = surface_->GetLastFlushedBuffer(buffer, fence, matrix, false);
288     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
289 }
290 
291 /*
292 * Function: CancelBuffer
293 * Type: Function
294 * Rank: Important(2)
295 * EnvConditions: N/A
296 * CaseDescription: 1. call CancelBuffer with producer_ is nullptr
297 *                  2. check ret
298  */
299 HWTEST_F(ProducerSurfaceTest, CancelBufferTest, Function | MediumTest | Level2)
300 {
301     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
302     GSError ret = surface_->CancelBuffer(buffer);
303     ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
304 }
305 
306 /*
307 * Function: AttachBufferToQueue
308 * Type: Function
309 * Rank: Important(2)
310 * EnvConditions: N/A
311 * CaseDescription: 1. call AttachBufferToQueue with producer_ is nullptr
312 *                  2. check ret
313  */
314 HWTEST_F(ProducerSurfaceTest, AttachBufferToQueueTest, Function | MediumTest | Level2)
315 {
316     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
317     GSError ret = surface_->AttachBufferToQueue(buffer);
318     ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
319 }
320 
321 /*
322 * Function: DetachBufferFromQueue
323 * Type: Function
324 * Rank: Important(2)
325 * EnvConditions: N/A
326 * CaseDescription: 1. call DetachBufferFromQueue with producer_ is nullptr
327 *                  2. check ret
328  */
329 HWTEST_F(ProducerSurfaceTest, DetachBufferFromQueueTest, Function | MediumTest | Level2)
330 {
331     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
332     GSError ret = surface_->DetachBufferFromQueue(buffer);
333     ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
334 }
335 
336 /*
337 * Function: DetachBuffer
338 * Type: Function
339 * Rank: Important(2)
340 * EnvConditions: N/A
341 * CaseDescription: 1. call DetachBuffer with producer_ is nullptr
342 *                  2. check ret
343  */
344 HWTEST_F(ProducerSurfaceTest, DetachBufferTest, Function | MediumTest | Level2)
345 {
346     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
347     GSError ret = surface_->DetachBuffer(buffer);
348     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
349 }
350 
351 /*
352 * Function: SetQueueSize and GetQueueSize
353 * Type: Function
354 * Rank: Important(2)
355 * EnvConditions: N/A
356 * CaseDescription: 1. call GetQueueSize and get default value
357 *                  2. call SetQueueSize
358 *                  3. call SetQueueSize again with abnormal value
359 *                  4. call GetQueueSize
360 *                  5. check ret
361  */
362 HWTEST_F(ProducerSurfaceTest, GetAndSetQueueSizeTest001, Function | MediumTest | Level2)
363 {
364     ASSERT_EQ(pSurface->GetQueueSize(), (uint32_t)SURFACE_DEFAULT_QUEUE_SIZE);
365     GSError ret = pSurface->SetQueueSize(2);
366     ASSERT_EQ(ret, OHOS::GSERROR_OK);
367 
368     ret = pSurface->SetQueueSize(SURFACE_MAX_QUEUE_SIZE + 1);
369     ASSERT_NE(ret, OHOS::GSERROR_OK);
370 
371     ASSERT_EQ(pSurface->GetQueueSize(), 2u);
372 }
373 
374 /*
375 * Function: SetQueueSize and GetQueueSize
376 * Type: Function
377 * Rank: Important(2)
378 * EnvConditions: N/A
379 * CaseDescription: 1. call GetQueueSize with producer_ is nullptr and check ret
380 *                  2. call SetQueueSize with producer_ is nullptr and check ret
381  */
382 HWTEST_F(ProducerSurfaceTest, GetAndSetQueueSizeTest002, Function | MediumTest | Level2)
383 {
384     uint32_t queueSize = surface_->GetQueueSize();
385     ASSERT_EQ(queueSize, 0);
386     GSError ret = surface_->SetQueueSize(queueSize);
387     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
388 }
389 
390 /*
391 * Function: GetQueueSize and SetQueueSize
392 * Type: Function
393 * Rank: Important(2)
394 * EnvConditions: N/A
395 * CaseDescription: 1. call GetQueueSize
396 *                  2. call SetQueueSize 2 times
397 *                  3. check ret
398  */
399 HWTEST_F(ProducerSurfaceTest, GetAndSetQueueSizeTest003, Function | MediumTest | Level2)
400 {
401     sptr<ConsumerSurface> cs = static_cast<ConsumerSurface*>(csurf.GetRefPtr());
402     sptr<BufferQueueProducer> bqp = static_cast<BufferQueueProducer*>(cs->GetProducer().GetRefPtr());
403     ASSERT_EQ(bqp->GetQueueSize(), 2u);
404 
405     GSError ret = pSurface->SetQueueSize(1);
406     ASSERT_EQ(ret, OHOS::GSERROR_OK);
407 
408     ret = pSurface->SetQueueSize(2);
409     ASSERT_EQ(ret, OHOS::GSERROR_OK);
410 }
411 
412 /*
413 * Function: GetDefaultWidth, GetDefaultHeight and SetDefaultWidthAndHeight
414 * Type: Function
415 * Rank: Important(2)
416 * EnvConditions: N/A
417 * CaseDescription: 1. call SetDefaultWidthAndHeight with producer_ is nullptr and check ret
418 *                  2. call GetDefaultWidth with producer_ is nullptr and check ret
419 *                  3. call GetDefaultHeight with producer_ is nullptr and check ret
420  */
421 HWTEST_F(ProducerSurfaceTest, DefaultWidthAndHeightTest, Function | MediumTest | Level2)
422 {
423     GSError ret = surface_->SetDefaultWidthAndHeight(0, 0);
424     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
425     int32_t width = surface_->GetDefaultWidth();
426     ASSERT_EQ(width, -1);  // -1 is default width
427     int32_t height = surface_->GetDefaultHeight();
428     ASSERT_EQ(height, -1);  // -1 is default height
429 }
430 
431 /*
432 * Function: SetTransformHint and GetTransformHint
433 * Type: Function
434 * Rank: Important(2)
435 * EnvConditions: N/A
436 * CaseDescription: 1. call SetTransformHint with producer_ is nullptr and check ret
437 *                  2. call GetTransformHint with producer_ is nullptr and check ret
438  */
439 HWTEST_F(ProducerSurfaceTest, GetAndSetTransformHintTest, Function | MediumTest | Level2)
440 {
441     GSError ret = surface_->SetTransformHint(GraphicTransformType::GRAPHIC_ROTATE_NONE);
442     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
443     GraphicTransformType type = surface_->GetTransformHint();
444     ASSERT_EQ(type, GraphicTransformType::GRAPHIC_ROTATE_NONE);
445 }
446 
447 /*
448 * Function: SetDefaultUsage and GetDefaultUsage
449 * Type: Function
450 * Rank: Important(2)
451 * EnvConditions: N/A
452 * CaseDescription: 1. call SetDefaultUsage with producer_ is nullptr and check ret
453 *                  2. call GetDefaultUsage with producer_ is nullptr and check ret
454  */
455 HWTEST_F(ProducerSurfaceTest, SetAndGetDefaultUsageTest, Function | MediumTest | Level2)
456 {
457     GSError ret = surface_->SetDefaultUsage(0);
458     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
459     uint64_t usage = surface_->GetDefaultUsage();
460     ASSERT_EQ(usage, 0);
461 }
462 
463 /*
464 * Function: RequestBuffer and FlushBuffer
465 * Type: Function
466 * Rank: Important(2)
467 * EnvConditions: N/A
468 * CaseDescription: 1. call RequestBuffer
469 *                  2. call FlushBuffer
470 *                  3. check ret
471  */
472 HWTEST_F(ProducerSurfaceTest, RequestAndFlushBufferTest001, Function | MediumTest | Level2)
473 {
474     sptr<SurfaceBuffer> buffer;
475 
476     int releaseFence = -1;
477     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
478     ASSERT_EQ(ret, OHOS::GSERROR_OK);
479     ASSERT_NE(buffer, nullptr);
480     firstSeqnum = buffer->GetSeqNum();
481 
482     ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
483     ASSERT_EQ(ret, OHOS::GSERROR_OK);
484 }
485 
486 /*
487 * Function: RequestBuffer and FlushBuffer
488 * Type: Function
489 * Rank: Important(2)
490 * EnvConditions: N/A
491 * CaseDescription: 1. call RequestBuffer
492 *                  2. call FlushBuffer 2 times
493 *                  3. check ret
494  */
495 HWTEST_F(ProducerSurfaceTest, RequestAndFlushBufferTest002, Function | MediumTest | Level2)
496 {
497     sptr<SurfaceBuffer> buffer;
498     int releaseFence = -1;
499 
500     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
501     ASSERT_EQ(ret, OHOS::GSERROR_OK);
502     ASSERT_NE(buffer, nullptr);
503 
504     ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
505     ASSERT_EQ(ret, OHOS::GSERROR_OK);
506 
507     ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
508     ASSERT_NE(ret, OHOS::GSERROR_OK);
509 }
510 
511 /*
512 * Function: AcquireBuffer and ReleaseBuffer
513 * Type: Function
514 * Rank: Important(2)
515 * EnvConditions: N/A
516 * CaseDescription: 1. call AcquireBuffer and ReleaseBuffer many times
517 *                  2. check ret
518  */
519 HWTEST_F(ProducerSurfaceTest, AcquireAndReleaseBufferTest001, Function | MediumTest | Level2)
520 {
521     sptr<SurfaceBuffer> buffer;
522     int32_t flushFence;
523 
524     GSError ret = csurf->AcquireBuffer(buffer, flushFence, timestamp, damage);
525     ASSERT_EQ(ret, OHOS::GSERROR_OK);
526 
527     ret = csurf->ReleaseBuffer(buffer, -1);
528     ASSERT_EQ(ret, OHOS::GSERROR_OK);
529 
530     ret = csurf->AcquireBuffer(buffer, flushFence, timestamp, damage);
531     ASSERT_EQ(ret, OHOS::GSERROR_OK);
532 
533     ret = csurf->ReleaseBuffer(buffer, -1);
534     ASSERT_EQ(ret, OHOS::GSERROR_OK);
535 }
536 
537 /*
538 * Function: RequestBuffer and CancelBuffer
539 * Type: Function
540 * Rank: Important(2)
541 * EnvConditions: N/A
542 * CaseDescription: 1. call RequestBuffer
543 *                  2. call CancelBuffer
544 *                  3. check ret
545  */
546 HWTEST_F(ProducerSurfaceTest, RequestAndCancelBufferTest001, Function | MediumTest | Level2)
547 {
548     sptr<SurfaceBuffer> buffer;
549 
550     int releaseFence = -1;
551     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
552     ASSERT_EQ(ret, OHOS::GSERROR_OK);
553 
554     ret = pSurface->CancelBuffer(buffer);
555     ASSERT_EQ(ret, OHOS::GSERROR_OK);
556 }
557 
558 /*
559 * Function: RequestBuffer and CancelBuffer
560 * Type: Function
561 * Rank: Important(2)
562 * EnvConditions: N/A
563 * CaseDescription: 1. call RequestBuffer
564 *                  2. call CancelBuffer 2 times
565 *                  3. check ret
566  */
567 HWTEST_F(ProducerSurfaceTest, RequestAndCancelBufferTest002, Function | MediumTest | Level2)
568 {
569     sptr<SurfaceBuffer> buffer;
570 
571     int releaseFence = -1;
572     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
573     ASSERT_EQ(ret, OHOS::GSERROR_OK);
574 
575     ret = pSurface->CancelBuffer(buffer);
576     ASSERT_EQ(ret, OHOS::GSERROR_OK);
577 
578     ret = pSurface->CancelBuffer(buffer);
579     ASSERT_NE(ret, OHOS::GSERROR_OK);
580 }
581 
582 /*
583 * Function: RequestBuffer and CancelBuffer
584 * Type: Function
585 * Rank: Important(2)
586 * EnvConditions: N/A
587 * CaseDescription: 1. call RequestBuffer and CancelBuffer many times
588 *                  2. check ret
589  */
590 HWTEST_F(ProducerSurfaceTest, RequestAndCancelBufferTest003, Function | MediumTest | Level2)
591 {
592     sptr<SurfaceBuffer> buffer;
593     sptr<SurfaceBuffer> buffer1;
594     sptr<SurfaceBuffer> buffer2;
595     int releaseFence = -1;
596 
597     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
598     ASSERT_EQ(ret, OHOS::GSERROR_OK);
599 
600     ret = pSurface->RequestBuffer(buffer1, releaseFence, requestConfig);
601     ASSERT_EQ(ret, OHOS::GSERROR_OK);
602 
603     ret = pSurface->RequestBuffer(buffer2, releaseFence, requestConfig);
604     ASSERT_NE(ret, OHOS::GSERROR_OK);
605 
606     ret = pSurface->CancelBuffer(buffer);
607     ASSERT_EQ(ret, OHOS::GSERROR_OK);
608 
609     ret = pSurface->CancelBuffer(buffer1);
610     ASSERT_EQ(ret, OHOS::GSERROR_OK);
611 
612     ret = pSurface->CancelBuffer(buffer2);
613     ASSERT_NE(ret, OHOS::GSERROR_OK);
614 }
615 
616 /*
617 * Function: RequestBuffer, ReleaseBuffer and CancelBuffer
618 * Type: Function
619 * Rank: Important(2)
620 * EnvConditions: N/A
621 * CaseDescription: 1. call RequestBuffer
622 *                  2. call ReleaseBuffer
623 *                  3. call CancelBuffer
624 *                  4. check ret
625  */
626 HWTEST_F(ProducerSurfaceTest, RequestAndCancelBufferTest004, Function | MediumTest | Level2)
627 {
628     sptr<SurfaceBuffer> buffer;
629 
630     int releaseFence = -1;
631     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
632     ASSERT_EQ(ret, OHOS::GSERROR_OK);
633 
634     ret = pSurface->CancelBuffer(buffer);
635     ASSERT_EQ(ret, OHOS::GSERROR_OK);
636 }
637 
638 /*
639 * Function: SetUserData and GetUserData
640 * Type: Function
641 * Rank: Important(2)
642 * EnvConditions: N/A
643 * CaseDescription: 1. call SetUserData and GetUserData many times
644 *                  2. check ret
645  */
646 HWTEST_F(ProducerSurfaceTest, SetAndGetUserDataTest, Function | MediumTest | Level2)
647 {
648     GSError ret;
649 
650     std::string strs[SURFACE_MAX_USER_DATA_COUNT];
651     constexpr int32_t stringLengthMax = 32;
652     char str[stringLengthMax] = {};
653     for (int i = 0; i < SURFACE_MAX_USER_DATA_COUNT; i++) {
654         auto secRet = snprintf_s(str, sizeof(str), sizeof(str) - 1, "%d", i);
655         ASSERT_GT(secRet, 0);
656 
657         strs[i] = str;
658         ret = pSurface->SetUserData(strs[i], "magic");
659         ASSERT_EQ(ret, OHOS::GSERROR_OK);
660     }
661 
662     ret = pSurface->SetUserData("-1", "error");
663     ASSERT_NE(ret, OHOS::GSERROR_OK);
664 
665     std::string retStr;
666     for (int i = 0; i < SURFACE_MAX_USER_DATA_COUNT; i++) {
667         retStr = pSurface->GetUserData(strs[i]);
668         ASSERT_EQ(retStr, "magic");
669     }
670 }
671 
672 /*
673 * Function: RegisterUserDataChangeListener
674 * Type: Function
675 * Rank: Important(2)
676 * EnvConditions: N/A
677 * CaseDescription: 1. RegisterUserDataChangeListener
678 *                  2. SetUserData
679 *                  3. check ret
680  */
681 HWTEST_F(ProducerSurfaceTest, RegisterUserDataChangeListenerTest001, Function | MediumTest | Level2)
682 {
683     sptr<IConsumerSurface> csurfTestUserData = IConsumerSurface::Create();
684     sptr<IBufferConsumerListener> listenerTestUserData = new BufferConsumerListener();
685     csurfTestUserData->RegisterConsumerListener(listenerTestUserData);
686     sptr<IBufferProducer> producerTestUserData = csurf->GetProducer();
687     sptr<Surface> pSurfaceTestUserData = Surface::CreateSurfaceAsProducer(producerTestUserData);
688 
689     GSError ret1 = OHOS::GSERROR_INVALID_ARGUMENTS;
690     GSError ret2 = OHOS::GSERROR_INVALID_ARGUMENTS;
__anon5a7e27240102(const std::string& key, const std::string& value) 691     auto func1 = [&ret1](const std::string& key, const std::string& value) {
692         ret1 = OHOS::GSERROR_OK;
693     };
__anon5a7e27240202(const std::string& key, const std::string& value) 694     auto func2 = [&ret2](const std::string& key, const std::string& value) {
695         ret2 = OHOS::GSERROR_OK;
696     };
697     pSurfaceTestUserData->RegisterUserDataChangeListener("func1", func1);
698     pSurfaceTestUserData->RegisterUserDataChangeListener("func2", func2);
699     pSurfaceTestUserData->RegisterUserDataChangeListener("func3", nullptr);
700     ASSERT_EQ(pSurfaceTestUserData->RegisterUserDataChangeListener("func2", func2), OHOS::GSERROR_INVALID_ARGUMENTS);
701 
702     if (pSurfaceTestUserData->SetUserData("Regist", "OK") == OHOS::GSERROR_OK) {
703         ASSERT_EQ(ret1, OHOS::GSERROR_OK);
704         ASSERT_EQ(ret2, OHOS::GSERROR_OK);
705     }
706 
707     ret1 = OHOS::GSERROR_INVALID_ARGUMENTS;
708     ret2 = OHOS::GSERROR_INVALID_ARGUMENTS;
709     pSurfaceTestUserData->UnRegisterUserDataChangeListener("func1");
710     ASSERT_EQ(pSurfaceTestUserData->UnRegisterUserDataChangeListener("func1"), OHOS::GSERROR_INVALID_ARGUMENTS);
711 
712     if (pSurfaceTestUserData->SetUserData("UnRegist", "INVALID") == OHOS::GSERROR_OK) {
713         ASSERT_EQ(ret1, OHOS::GSERROR_INVALID_ARGUMENTS);
714         ASSERT_EQ(ret2, OHOS::GSERROR_OK);
715     }
716 
717     ret1 = OHOS::GSERROR_INVALID_ARGUMENTS;
718     ret2 = OHOS::GSERROR_INVALID_ARGUMENTS;
719     pSurfaceTestUserData->ClearUserDataChangeListener();
720     pSurfaceTestUserData->RegisterUserDataChangeListener("func1", func1);
721     if (pSurfaceTestUserData->SetUserData("Clear", "OK") == OHOS::GSERROR_OK) {
722         ASSERT_EQ(ret1, OHOS::GSERROR_OK);
723         ASSERT_EQ(ret2, OHOS::GSERROR_INVALID_ARGUMENTS);
724     }
725 }
726 
727 /*
728 * Function: RegisterUserDataChangeListener
729 * Type: Function
730 * Rank: Important(2)
731 * EnvConditions: N/A
732 * CaseDescription: 1. RegisterUserDataChangeListener
733 *                  2. SetUserData
734 *                  3. check ret
735  */
736 HWTEST_F(ProducerSurfaceTest, RegisterUserDataChangeListenerTest002, Function | MediumTest | Level2)
737 {
738     sptr<IConsumerSurface> csurfTestUserData = IConsumerSurface::Create();
739     sptr<IBufferConsumerListener> listenerTestUserData = new BufferConsumerListener();
740     csurfTestUserData->RegisterConsumerListener(listenerTestUserData);
741     sptr<IBufferProducer> producerTestUserData = csurf->GetProducer();
742     sptr<Surface> pSurfaceTestUserData = Surface::CreateSurfaceAsProducer(producerTestUserData);
743 
__anon5a7e27240302(const std::string& FuncName) 744     auto func = [&pSurfaceTestUserData](const std::string& FuncName) {
745         constexpr int32_t registerListenerNum = 1000;
746         std::vector<GSError> ret(registerListenerNum, OHOS::GSERROR_INVALID_ARGUMENTS);
747         std::string strs[registerListenerNum];
748         constexpr int32_t stringLengthMax = 32;
749         char str[stringLengthMax] = {};
750         for (int i = 0; i < registerListenerNum; i++) {
751             auto secRet = snprintf_s(str, sizeof(str), sizeof(str) - 1, "%s%d", FuncName.c_str(), i);
752             ASSERT_GT(secRet, 0);
753             strs[i] = str;
754             ASSERT_EQ(pSurfaceTestUserData->RegisterUserDataChangeListener(strs[i], [i, &ret]
755             (const std::string& key, const std::string& value) {
756                 ret[i] = OHOS::GSERROR_OK;
757             }), OHOS::GSERROR_OK);
758         }
759 
760         if (pSurfaceTestUserData->SetUserData("Regist", FuncName) == OHOS::GSERROR_OK) {
761             for (int i = 0; i < registerListenerNum; i++) {
762                 ASSERT_EQ(ret[i], OHOS::GSERROR_OK);
763             }
764         }
765 
766         for (int i = 0; i < registerListenerNum; i++) {
767             pSurfaceTestUserData->UnRegisterUserDataChangeListener(strs[i]);
768         }
769     };
770 
771     std::thread t1(func, "thread1");
772     std::thread t2(func, "thread2");
773     t1.join();
774     t2.join();
775 }
776 
777 /*
778 * Function: GetUniqueId
779 * Type: Function
780 * Rank: Important(2)
781 * EnvConditions: N/A
782 * CaseDescription: 1. call GetUniqueId
783 *                  2. check ret
784  */
785 HWTEST_F(ProducerSurfaceTest, GetUniqueIdTest, Function | MediumTest | Level2)
786 {
787     uint64_t uniqueId = pSurface->GetUniqueId();
788     ASSERT_NE(uniqueId, 0);
789 }
790 
791 /*
792 * Function: SetTransform and GetTransform
793 * Type: Function
794 * Rank: Important(2)
795 * EnvConditions: N/A
796 * CaseDescription: 1. call GetTransform with default and check ret
797  */
798 HWTEST_F(ProducerSurfaceTest, SetTransformTest001, Function | MediumTest | Level2)
799 {
800     GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_NONE);
801     ASSERT_EQ(ret, OHOS::GSERROR_OK);
802 }
803 
804 /*
805 * Function: SetTransform and GetTransform
806 * Type: Function
807 * Rank: Important(1)
808 * EnvConditions: N/A
809 * CaseDescription: 1. call SetTransform with other parameters and check ret
810  */
811 HWTEST_F(ProducerSurfaceTest, SetTransformTest002, Function | MediumTest | Level1)
812 {
813     GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_90);
814     ASSERT_EQ(ret, OHOS::GSERROR_OK);
815 }
816 
817 /*
818 * Function: SetTransform and GetTransform
819 * Type: Function
820 * Rank: Important(1)
821 * EnvConditions: N/A
822 * CaseDescription: 1. call SetTransform with other parameters and check ret
823  */
824 HWTEST_F(ProducerSurfaceTest, SetTransformTest003, Function | MediumTest | Level1)
825 {
826     GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_180);
827     ASSERT_EQ(ret, OHOS::GSERROR_OK);
828 }
829 
830 /*
831 * Function: SetTransform and GetTransform
832 * Type: Function
833 * Rank: Important(1)
834 * EnvConditions: N/A
835 * CaseDescription: 1. call SetTransform with other parameters and check ret
836  */
837 HWTEST_F(ProducerSurfaceTest, SetTransformTest004, Function | MediumTest | Level1)
838 {
839     GSError ret = pSurface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_270);
840     ASSERT_EQ(ret, OHOS::GSERROR_OK);
841 }
842 
843 /*
844  * Function: SetTransform and GetTransform
845  * Type: Function
846  * Rank: Important(1)
847  * EnvConditions: N/A
848  * CaseDescription: 1. call SetTransform with producer_ is nullptr and check ret
849  *                  2. call GetTransform with producer_ is nullptr and check ret
850  */
851 HWTEST_F(ProducerSurfaceTest, SetTransformTest005, Function | MediumTest | Level1)
852 {
853     GSError ret = surface_->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_270);
854     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
855     GraphicTransformType type = surface_->GetTransform();
856     ASSERT_EQ(type, GraphicTransformType::GRAPHIC_ROTATE_BUTT);
857 }
858 
859 /*
860  * Function: SetScalingMode and GetScalingMode
861  * Type: Function
862  * Rank: Important(2)
863  * EnvConditions: N/A
864  * CaseDescription: 1. call SetScalingMode with abnormal parameters and check ret
865  */
866 HWTEST_F(ProducerSurfaceTest, SetScalingModeTest001, Function | MediumTest | Level2)
867 {
868     ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
869     GSError ret = pSurface->SetScalingMode(-1, scalingMode);
870     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
871 }
872 
873 /*
874  * Function: SetScalingMode and GetScalingMode
875  * Type: Function
876  * Rank: Important(1)
877  * EnvConditions: N/A
878  * CaseDescription: 1. call SetScalingMode with normal parameters and check ret
879  *                  2. call GetScalingMode and check ret
880  */
881 HWTEST_F(ProducerSurfaceTest, SetScalingModeTest002, Function | MediumTest | Level1)
882 {
883     ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
884     sptr<SurfaceBuffer> buffer;
885     int releaseFence = -1;
886     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
887     ASSERT_EQ(ret, OHOS::GSERROR_OK);
888     ASSERT_NE(buffer, nullptr);
889 
890     uint32_t sequence = buffer->GetSeqNum();
891     ret = pSurface->SetScalingMode(sequence, scalingMode);
892     ASSERT_EQ(ret, OHOS::GSERROR_OK);
893 
894     ret = pSurface->CancelBuffer(buffer);
895     ASSERT_EQ(ret, OHOS::GSERROR_OK);
896 }
897 
898 /*
899  * Function: SetScalingMode003
900  * Type: Function
901  * Rank: Important(2)
902  * EnvConditions: N/A
903  * CaseDescription: 1. call SetScalingMode with abnormal parameters and check ret
904  */
905 HWTEST_F(ProducerSurfaceTest, SetScalingModeTest003, Function | MediumTest | Level2)
906 {
907     ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
908     GSError ret = pSurface->SetScalingMode(scalingMode);
909     ASSERT_EQ(ret, OHOS::GSERROR_OK);
910 }
911 
912 /*
913  * Function: SetScalingMode and GetScalingMode
914  * Type: Function
915  * Rank: Important(2)
916  * EnvConditions: N/A
917  * CaseDescription: 1. call SetScalingMode with producer_ is nullptr and check ret
918  *                  2. call GetScalingMode and check ret
919  */
920 HWTEST_F(ProducerSurfaceTest, SetScalingModeTest004, Function | MediumTest | Level2)
921 {
922     ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
923     GSError ret = surface_->SetScalingMode(scalingMode);
924     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
925     ret = surface_->SetScalingMode(0, scalingMode);
926     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
927     ret = surface_->GetScalingMode(0, scalingMode);
928     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
929 }
930 
931 /*
932  * Function: SetMetaData and GetMetaData
933  * Type: Function
934  * Rank: Important(2)
935  * EnvConditions: N/A
936  * CaseDescription: 1. call SetMetaData with abnormal parameters and check ret
937  */
938 HWTEST_F(ProducerSurfaceTest, SetMetaDataTest001, Function | MediumTest | Level2)
939 {
940     std::vector<GraphicHDRMetaData> metaData;
941     GSError ret = pSurface->SetMetaData(firstSeqnum, metaData);
942     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
943 }
944 
945 /*
946  * Function: SetMetaData and GetMetaData
947  * Type: Function
948  * Rank: Important(2)
949  * EnvConditions: N/A
950  * CaseDescription: 1. call SetMetaData with abnormal parameters and check ret
951  */
952 HWTEST_F(ProducerSurfaceTest, SetMetaDataTest002, Function | MediumTest | Level2)
953 {
954     std::vector<GraphicHDRMetaData> metaData;
955     GraphicHDRMetaData data = {
956         .key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_RED_PRIMARY_X,
957         .value = 100,  // for test
958     };
959     metaData.push_back(data);
960     GSError ret = pSurface->SetMetaData(-1, metaData);
961     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
962 }
963 
964 /*
965  * Function: SetMetaData and GetMetaData
966  * Type: Function
967  * Rank: Important(1)
968  * EnvConditions: N/A
969  * CaseDescription: 1. call SetMetaData with normal parameters and check ret
970  *                  2. call GetMetaData and check ret
971  */
972 HWTEST_F(ProducerSurfaceTest, SetMetaDataTest003, Function | MediumTest | Level1)
973 {
974     std::vector<GraphicHDRMetaData> metaData;
975     GraphicHDRMetaData data = {
976         .key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_RED_PRIMARY_X,
977         .value = 100,  // for test
978     };
979     metaData.push_back(data);
980     sptr<SurfaceBuffer> buffer;
981     int releaseFence = -1;
982     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
983     ASSERT_EQ(ret, OHOS::GSERROR_OK);
984     ASSERT_NE(buffer, nullptr);
985 
986     uint32_t sequence = buffer->GetSeqNum();
987     ret = pSurface->SetMetaData(sequence, metaData);
988     ASSERT_EQ(ret, OHOS::GSERROR_OK);
989 
990     ret = pSurface->CancelBuffer(buffer);
991     ASSERT_EQ(ret, OHOS::GSERROR_OK);
992 }
993 
994 /*
995  * Function: SetMetaData and GetMetaData
996  * Type: Function
997  * Rank: Important(2)
998  * EnvConditions: N/A
999  * CaseDescription: 1. call SetMetaData with producer_ is nullptr and check ret
1000  *                  2. call GetMetaData and check ret
1001  */
1002 HWTEST_F(ProducerSurfaceTest, SetMetaDataAndGetMetaDataTest, Function | MediumTest | Level2)
1003 {
1004     std::vector<GraphicHDRMetaData> metaData;
1005     GSError ret = surface_->SetMetaData(0, metaData);
1006     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1007     GraphicHDRMetaData data = {
1008         .key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_RED_PRIMARY_X,
1009         .value = 100,  // 100 metaData value for test
1010     };
1011     metaData.push_back(data);
1012     ret = surface_->SetMetaData(0, metaData);
1013     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1014     ret = surface_->GetMetaData(0, metaData);
1015     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
1016 }
1017 
1018 /*
1019  * Function: SetMetadataValue
1020  * Type: Function
1021  * Rank: Important(2)
1022  * EnvConditions:
1023  * CaseDescription: 1. call SetUserData then SetMetadataValue and check ret
1024  *                  2. call get functions and compare
1025  */
1026 HWTEST_F(ProducerSurfaceTest, SetMetadataValueTest, Function | MediumTest | Level2)
1027 {
1028     GSError ret;
1029     sptr<SurfaceBuffer> buffer_;
1030     int releaseFence = -1;
1031     ret = pSurface->RequestBuffer(buffer_, releaseFence, requestConfig);
1032 
1033     std::string valueInfo = "mockInfo";
1034     std::string valueDynamic = "mockDynamic";
1035     std::string valueStatic = "mockStatic";
1036     std::string valueType = "mockType";
1037 
1038     surfaceMd_->SetUserData("ATTRKEY_COLORSPACE_INFO", valueInfo);
1039     surfaceMd_->SetUserData("OH_HDR_DYNAMIC_METADATA", valueDynamic);
1040     surfaceMd_->SetUserData("OH_HDR_STATIC_METADATA", valueStatic);
1041     surfaceMd_->SetUserData("OH_HDR_METADATA_TYPE", valueType);
1042 
1043     ret = surfaceMd_->SetMetadataValue(buffer_);
1044     if (ret == OHOS::GSERROR_OK) {
1045         CM_ColorSpaceType colorSpaceType;
1046         MetadataHelper::GetColorSpaceType(buffer_, colorSpaceType);
1047         EXPECT_EQ(static_cast<CM_ColorSpaceType>(atoi(valueInfo.c_str())), colorSpaceType);
1048 
1049         std::vector<uint8_t> setDynamicMetadata, getDynamicMetadata;
1050         setDynamicMetadata.resize(valueDynamic.size());
1051         setDynamicMetadata.assign(valueDynamic.begin(), valueDynamic.end());
1052         MetadataHelper::GetHDRDynamicMetadata(buffer_, getDynamicMetadata);
1053         EXPECT_EQ(setDynamicMetadata, getDynamicMetadata);
1054 
1055         std::vector<uint8_t> setStaticMetadata, getStaticMetadata;
1056         setStaticMetadata.resize(valueStatic.size());
1057         setStaticMetadata.assign(valueStatic.begin(), valueStatic.end());
1058         MetadataHelper::GetHDRStaticMetadata(buffer_, getStaticMetadata);
1059         EXPECT_EQ(setStaticMetadata, getStaticMetadata);
1060 
1061         CM_HDR_Metadata_Type hdrMetadataType;
1062         MetadataHelper::GetHDRMetadataType(buffer_, hdrMetadataType);
1063         EXPECT_EQ(static_cast<CM_HDR_Metadata_Type>(atoi(valueType.c_str())), hdrMetadataType);
1064     } else {
1065         EXPECT_EQ(ret, OHOS::GSERROR_HDI_ERROR);
1066     }
1067 }
1068 
1069 /*
1070  * Function: SetMetaDataSet and GetMetaDataSet
1071  * Type: Function
1072  * Rank: Important(2)
1073  * EnvConditions: N/A
1074  * CaseDescription: 1. call SetMetaDataSet with abnormal parameters and check ret
1075  */
1076 HWTEST_F(ProducerSurfaceTest, SetMetaDataSetTest001, Function | MediumTest | Level2)
1077 {
1078     GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
1079     std::vector<uint8_t> metaData;
1080 
1081     GSError ret = pSurface->SetMetaDataSet(firstSeqnum, key, metaData);
1082     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1083 }
1084 
1085 /*
1086  * Function: SetMetaDataSet and GetMetaDataSet
1087  * Type: Function
1088  * Rank: Important(2)
1089  * EnvConditions: N/A
1090  * CaseDescription: 1. call SetMetaDataSet with abnormal parameters and check ret
1091  */
1092 HWTEST_F(ProducerSurfaceTest, SetMetaDataSetTest002, Function | MediumTest | Level2)
1093 {
1094     GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
1095     std::vector<uint8_t> metaData;
1096 
1097     uint8_t data = 10;  // for test
1098     metaData.push_back(data);
1099     GSError ret = pSurface->SetMetaDataSet(-1, key, metaData);
1100     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
1101 }
1102 
1103 /*
1104  * Function: SetMetaDataSet and GetMetaDataSet
1105  * Type: Function
1106  * Rank: Important(1)
1107  * EnvConditions: N/A
1108  * CaseDescription: 1. call SetMetaDataSet with normal parameters and check ret
1109  *                  2. call GetMetaDataSet and check ret
1110  */
1111 HWTEST_F(ProducerSurfaceTest, SetMetaDataSetTest003, Function | MediumTest | Level1)
1112 {
1113     GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
1114     std::vector<uint8_t> metaData;
1115     uint8_t data = 10;  // for test
1116     metaData.push_back(data);
1117 
1118     sptr<SurfaceBuffer> buffer;
1119     int releaseFence = -1;
1120     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
1121     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1122     ASSERT_NE(buffer, nullptr);
1123 
1124     uint32_t sequence = buffer->GetSeqNum();
1125     ret = pSurface->SetMetaDataSet(sequence, key, metaData);
1126     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1127 
1128     ret = pSurface->CancelBuffer(buffer);
1129     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1130 }
1131 
1132 /*
1133  * Function: SetMetaDataSet and GetMetaDataSet
1134  * Type: Function
1135  * Rank: Important(2)
1136  * EnvConditions: N/A
1137  * CaseDescription: 1. call SetMetaDataSet with producer_ is nullptr and check ret
1138  *                  2. call GetMetaDataSet and check ret
1139  */
1140 HWTEST_F(ProducerSurfaceTest, SetMetaDataSetAndGetMetaDataSetTest, Function | MediumTest | Level2)
1141 {
1142     GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
1143     std::vector<uint8_t> metaData;
1144 
1145     uint8_t data = 10;  // metaData value for test
1146     metaData.push_back(data);
1147     GSError ret = surface_->SetMetaDataSet(0, key, metaData);
1148     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1149     ret = surface_->GetMetaDataSet(0, key, metaData);
1150     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
1151 }
1152 
1153 /*
1154  * Function: SetTunnelHandle and GetTunnelHandle
1155  * Type: Function
1156  * Rank: Important(2)
1157  * EnvConditions: N/A
1158  * CaseDescription: 1. call SetTunnelhandle with producer_ is nullptr and check ret
1159  */
1160 HWTEST_F(ProducerSurfaceTest, SetTunnelHandleTest001, Function | MediumTest | Level2)
1161 {
1162     GraphicExtDataHandle *handle = nullptr;
1163     handle = static_cast<GraphicExtDataHandle *>(malloc(sizeof(GraphicExtDataHandle) + sizeof(int32_t) * 1));
1164     ASSERT_NE(handle, nullptr);
1165     handle->fd = -1;
1166     handle->reserveInts = 1;
1167     handle->reserve[0] = 0;
1168     GSError ret = surface_->SetTunnelHandle(handle);
1169     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1170 
1171     sptr<SurfaceTunnelHandle> handleGet = surface_->GetTunnelHandle();
1172     ASSERT_EQ(handleGet, nullptr);
1173     free(handle);
1174 }
1175 
1176 /*
1177  * Function: SetTunnelHandle and GetTunnelHandle
1178  * Type: Function
1179  * Rank: Important(2)
1180  * EnvConditions: N/A
1181  * CaseDescription: 1. call SetTunnelhandle with normal parameters and check ret
1182  */
1183 HWTEST_F(ProducerSurfaceTest, SetTunnelHandleTest002, Function | MediumTest | Level2)
1184 {
1185     GraphicExtDataHandle *handle = nullptr;
1186     handle = static_cast<GraphicExtDataHandle *>(malloc(sizeof(GraphicExtDataHandle) + sizeof(int32_t) * 1));
1187     ASSERT_NE(handle, nullptr);
1188     handle->fd = -1;
1189     handle->reserveInts = 1;
1190     handle->reserve[0] = 0;
1191     GSError ret = pSurface->SetTunnelHandle(handle);
1192     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1193 
1194     ret = pSurface->SetTunnelHandle(handle);
1195     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
1196     free(handle);
1197 }
1198 
1199 /*
1200  * Function: Connect
1201  * Type: Function
1202  * Rank: Important(1)
1203  * EnvConditions: N/A
1204  * CaseDescription: 1. call Connect and check ret
1205  */
1206 HWTEST_F(ProducerSurfaceTest, ConnectTest001, Function | MediumTest | Level1)
1207 {
1208     GSError ret = pSurface->Connect();
1209     ASSERT_EQ(ret, OHOS::SURFACE_ERROR_CONSUMER_IS_CONNECTED);
1210 }
1211 
1212 /*
1213  * Function: Connect
1214  * Type: Function
1215  * Rank: Important(1)
1216  * EnvConditions: N/A
1217  * CaseDescription: 1. call Connect and check ret
1218  */
1219 HWTEST_F(ProducerSurfaceTest, ConnectTest002, Function | MediumTest | Level1)
1220 {
1221     GSError ret = pSurface->Connect();
1222     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1223 }
1224 
1225 /*
1226  * Function: Connect
1227  * Type: Function
1228  * Rank: Important(1)
1229  * EnvConditions: N/A
1230  * CaseDescription: 1. call Connect with producer_ is nullptr and check ret
1231  */
1232 HWTEST_F(ProducerSurfaceTest, ConnectTest003, Function | MediumTest | Level1)
1233 {
1234     GSError ret = surface_->Connect();
1235     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1236 }
1237 
1238 /*
1239  * Function: Disconnect
1240  * Type: Function
1241  * Rank: Important(1)
1242  * EnvConditions: N/A
1243  * CaseDescription: 1. call Disconnect and check ret
1244  */
1245 HWTEST_F(ProducerSurfaceTest, DisconnectTest001, Function | MediumTest | Level1)
1246 {
1247     GSError ret = pSurface->Disconnect();
1248     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1249 }
1250 
1251 /*
1252  * Function: Disconnect
1253  * Type: Function
1254  * Rank: Important(1)
1255  * EnvConditions: N/A
1256  * CaseDescription: 1. call Disconnect and check ret
1257  */
1258 HWTEST_F(ProducerSurfaceTest, DisconnectTest002, Function | MediumTest | Level1)
1259 {
1260     GSError ret = pSurface->Disconnect();
1261     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1262 }
1263 
1264 /*
1265  * Function: Disconnect
1266  * Type: Function
1267  * Rank: Important(1)
1268  * EnvConditions: N/A
1269  * CaseDescription: 1. call Disconnect with producer_ is nullptr and check ret
1270  */
1271 HWTEST_F(ProducerSurfaceTest, DisconnectTest003, Function | MediumTest | Level1)
1272 {
1273     GSError ret = surface_->Disconnect();
1274     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1275 }
1276 
1277 /*
1278  * Function: SetPresentTimestamp and GetPresentTimestamp
1279  * Type: Function
1280  * Rank: Important(2)
1281  * EnvConditions: N/A
1282  * CaseDescription: 1. call GetPresentTimestamp with producer_ is nullptr and check ret
1283  *                  2. call SetPresentTimestamp and check ret
1284  */
1285 HWTEST_F(ProducerSurfaceTest, GetPresentTimestampAndSetPresentTimestampTest, Function | MediumTest | Level2)
1286 {
1287     GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
1288     int64_t time = 0;
1289 
1290     GSError ret = surface_->GetPresentTimestamp(firstSeqnum, type, time);
1291     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1292     GraphicPresentTimestamp timestamp;
1293     ret = surface_->SetPresentTimestamp(firstSeqnum, timestamp);
1294     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
1295 }
1296 
1297 /*
1298  * Function: SetPresentTimestamp and GetPresentTimestamp
1299  * Type: Function
1300  * Rank: Important(2)
1301  * EnvConditions: N/A
1302  * CaseDescription: 1. call GetPresentTimestamp with normal parameters and check ret
1303  * @tc.require: issueI5I57K
1304  */
1305 HWTEST_F(ProducerSurfaceTest, GetPresentTimestampTest001, Function | MediumTest | Level2)
1306 {
1307     GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
1308     int64_t time = 0;
1309 
1310     GSError ret = pSurface->GetPresentTimestamp(firstSeqnum, type, time);
1311     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1312 }
1313 
1314 /*
1315  * Function: SetPresentTimestamp and GetPresentTimestamp
1316  * Type: Function
1317  * Rank: Important(2)
1318  * EnvConditions: N/A
1319  * CaseDescription: 1. call SetPresentTimestamp with normal parameters and check ret
1320  * @tc.require: issueI5I57K
1321  */
1322 HWTEST_F(ProducerSurfaceTest, GetPresentTimestampTest002, Function | MediumTest | Level2)
1323 {
1324     GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_DELAY;
1325     int64_t time = 0;
1326     GSError ret = pSurface->GetPresentTimestamp(-1, type, time);
1327     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
1328 }
1329 
1330 /*
1331  * Function: SetPresentTimestamp and GetPresentTimestamp
1332  * Type: Function
1333  * Rank: Important(1)
1334  * EnvConditions: N/A
1335  * CaseDescription: 1. call SetPresentTimestamp and check ret
1336  * @tc.require: issueI5I57K
1337  */
1338 HWTEST_F(ProducerSurfaceTest, GetPresentTimestampTest003, Function | MediumTest | Level1)
1339 {
1340     sptr<SurfaceBuffer> buffer;
1341     int releaseFence = -1;
1342     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
1343     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1344     ASSERT_NE(buffer, nullptr);
1345 
1346     uint32_t sequence = buffer->GetSeqNum();
1347     GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_DELAY;
1348     int64_t time = 0;
1349     ret = pSurface->GetPresentTimestamp(sequence, type, time);
1350     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
1351 
1352     ret = pSurface->CancelBuffer(buffer);
1353     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1354 }
1355 
1356 /*
1357  * Function: SetWptrNativeWindowToPSurface
1358  * Type: Function
1359  * Rank: Important(1)
1360  * EnvConditions: N/A
1361  * CaseDescription: 1. SetWptrNativeWindowToPSurface and check ret
1362  * @tc.require: issueI7WYIY
1363  */
1364 HWTEST_F(ProducerSurfaceTest, SetWptrNativeWindowToPSurfaceTest001, Function | MediumTest | Level1)
1365 {
1366     struct NativeWindow nativeWindow;
1367     GSError ret = pSurface->SetWptrNativeWindowToPSurface(&nativeWindow);
1368     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1369 }
1370 
1371 /*
1372  * Function: SetWptrNativeWindowToPSurface
1373  * Type: Function
1374  * Rank: Important(1)
1375  * EnvConditions: N/A
1376  * CaseDescription: 1. SetWptrNativeWindowToPSurface with nullptr param and check ret
1377  * @tc.require: issueIANSVH
1378  */
1379 HWTEST_F(ProducerSurfaceTest, SetWptrNativeWindowToPSurfaceTest002, Function | MediumTest | Level1)
1380 {
1381     GSError ret = surface_->SetWptrNativeWindowToPSurface(nullptr);
1382     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1383 }
1384 
1385 /*
1386  * Function: SetWindowConfigOpt
1387  * Type: Function
1388  * Rank: Important(1)
1389  * EnvConditions: N/A
1390  * CaseDescription: 1. Call SetWindowConfig with params
1391  *                  2. Call GetWindowConfig and check ret
1392  * @tc.require: issueIANSVH
1393  */
1394 HWTEST_F(ProducerSurfaceTest, SetWindowConfigTest, Function | MediumTest | Level1)
1395 {
1396     surface_->SetWindowConfigWidthAndHeight(requestConfig.width, requestConfig.height);
1397     surface_->SetWindowConfigStride(requestConfig.strideAlignment);
1398     surface_->SetWindowConfigFormat(requestConfig.format);
1399     surface_->SetWindowConfigUsage(requestConfig.usage);
1400     surface_->SetWindowConfigTimeout(requestConfig.timeout);
1401     surface_->SetWindowConfigColorGamut(requestConfig.colorGamut);
1402     surface_->SetWindowConfigTransform(requestConfig.transform);
1403     auto configGet = surface_->GetWindowConfig();
1404     ASSERT_EQ(requestConfig.width, configGet.width);
1405     ASSERT_EQ(requestConfig.height, configGet.height);
1406     ASSERT_EQ(requestConfig.strideAlignment, configGet.strideAlignment);
1407     ASSERT_EQ(requestConfig.format, configGet.format);
1408     ASSERT_EQ(requestConfig.usage, configGet.usage);
1409     ASSERT_EQ(requestConfig.timeout, configGet.timeout);
1410     ASSERT_EQ(requestConfig.colorGamut, configGet.colorGamut);
1411     ASSERT_EQ(requestConfig.transform, configGet.transform);
1412 }
1413 
1414 /*
1415  * Function: SetWindowConfig and GetWindowConfig
1416  * Type: Function
1417  * Rank: Important(1)
1418  * EnvConditions: N/A
1419  * CaseDescription: 1. Call SetWindowConfig
1420  *                  2. Call GetWindowConfig and check ret
1421  * @tc.require: issueIANSVH
1422  */
1423 HWTEST_F(ProducerSurfaceTest, SetWindowConfigAndGetWindowConfigTest, Function | MediumTest | Level1)
1424 {
1425     surface_->SetWindowConfig(requestConfig);
1426     auto configGet = surface_->GetWindowConfig();
1427     ASSERT_EQ(requestConfig, configGet);
1428 }
1429 
1430 /*
1431  * Function: SetSurfaceSourceType and GetSurfaceSourceType
1432  * Type: Function
1433  * Rank: Important(2)
1434  * EnvConditions: N/A
1435  * CaseDescription: 1. call SetSurfaceSourceType and check ret
1436  *                  2. call GetSurfaceSourceType and check ret
1437  */
1438 HWTEST_F(ProducerSurfaceTest, SetSurfaceSourceTypeAndGetSurfaceSourceTypeTest001, Function | MediumTest | Level2)
1439 {
1440     OHSurfaceSource sourceType = OHSurfaceSource::OH_SURFACE_SOURCE_VIDEO;
1441     GSError ret = pSurface->SetSurfaceSourceType(sourceType);
1442     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1443     ASSERT_EQ(pSurface->GetSurfaceSourceType(), OH_SURFACE_SOURCE_VIDEO);
1444 }
1445 
1446 /*
1447  * Function: SetSurfaceSourceType and GetSurfaceSourceType
1448  * Type: Function
1449  * Rank: Important(2)
1450  * EnvConditions: N/A
1451  * CaseDescription: 1. call SetSurfaceSourceType with producer_ is nullptr and check ret
1452  *                  2. call GetSurfaceSourceType with producer_ is nullptr and check ret
1453  */
1454 HWTEST_F(ProducerSurfaceTest, SetSurfaceSourceTypeAndGetSurfaceSourceTypeTest002, Function | MediumTest | Level2)
1455 {
1456     OHSurfaceSource sourceType = OHSurfaceSource::OH_SURFACE_SOURCE_VIDEO;
1457     GSError ret = surface_->SetSurfaceSourceType(sourceType);
1458     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1459     ASSERT_EQ(surface_->GetSurfaceSourceType(), OHSurfaceSource::OH_SURFACE_SOURCE_DEFAULT);
1460 }
1461 
1462 /*
1463  * Function: AttachBuffer
1464  * Type: Function
1465  * Rank: Important(1)
1466  * EnvConditions: N/A
1467  * CaseDescription: 1. AttachBuffer and check ret
1468  * @tc.require: issueI7WYIY
1469  */
1470 HWTEST_F(ProducerSurfaceTest, AttachBufferTest001, Function | MediumTest | Level1)
1471 {
1472     GSError ret = pSurface->CleanCache();
1473     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1474     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
1475     ASSERT_NE(buffer, nullptr);
1476     sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
1477     int32_t timeOut = 5;
1478     ret = pSurface->AttachBuffer(buffer, timeOut);
1479     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1480 }
1481 
1482 /*
1483  * Function: AttachBuffer
1484  * Type: Function
1485  * Rank: Important(2)
1486  * EnvConditions: N/A
1487  * CaseDescription: 1. call AttachBuffer with producer_ is nullptr
1488  *                  2. check ret
1489  */
1490 HWTEST_F(ProducerSurfaceTest, AttachBufferTest002, Function | MediumTest | Level2)
1491 {
1492     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
1493     GSError ret = surface_->AttachBuffer(buffer);
1494     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1495     ret = surface_->AttachBuffer(buffer, 0);
1496     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1497 }
1498 
1499 /*
1500  * Function: RegisterSurfaceDelegator000
1501  * Type: Function
1502  * Rank: Important(1)
1503  * EnvConditions: N/A
1504  * CaseDescription: 1. RegisterSurfaceDelegator and check ret
1505  * @tc.require: issueI7WYIY
1506  */
1507 HWTEST_F(ProducerSurfaceTest, RegisterSurfaceDelegatorTest001, Function | MediumTest | Level1)
1508 {
1509     GSError ret = pSurface->CleanCache();
1510     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1511     ret = pSurface->RegisterSurfaceDelegator(nullptr);
1512     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1513 }
1514 
1515 /*
1516  * Function: CleanCache001
1517  * Type: Function
1518  * Rank: Important(1)
1519  * EnvConditions: N/A
1520  * CaseDescription: 1. CleanCache and check ret
1521  */
1522 HWTEST_F(ProducerSurfaceTest, CleanCacheTest001, Function | MediumTest | Level2)
1523 {
1524     GSError ret = pSurface->CleanCache(true);
1525     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1526 }
1527 
1528 /*
1529  * Function: CleanCache
1530  * Type: Function
1531  * Rank: Important(1)
1532  * EnvConditions: N/A
1533  * CaseDescription: 1. CleanCache with producer_ is nullptr and check ret
1534  */
1535 HWTEST_F(ProducerSurfaceTest, CleanCacheTest002, Function | MediumTest | Level2)
1536 {
1537     GSError ret = surface_->CleanCache(true);
1538     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1539 }
1540 
1541 /*
1542  * Function: GoBackground
1543  * Type: Function
1544  * Rank: Important(1)
1545  * EnvConditions: N/A
1546  * CaseDescription: 1. GoBackground with producer_ is nullptr and check ret
1547  */
1548 HWTEST_F(ProducerSurfaceTest, GoBackgroundTest001, Function | MediumTest | Level2)
1549 {
1550     GSError ret = surface_->GoBackground();
1551     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1552 }
1553 
1554 /*
1555  * Function: SetSurfaceAppFrameworkType and GetSurfaceAppFrameworkType
1556  * Type: Function
1557  * Rank: Important(2)
1558  * EnvConditions: N/A
1559  * CaseDescription: 1. call SetSurfaceAppFrameworkType and check ret
1560  *                  2. call GetSurfaceAppFrameworkType and check ret
1561  */
1562 HWTEST_F(ProducerSurfaceTest, SetSurfaceAppFrameworkTypeTest001, Function | MediumTest | Level2)
1563 {
1564     std::string type = "test";
1565     GSError ret = pSurface->SetSurfaceAppFrameworkType(type);
1566     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1567     ASSERT_EQ(pSurface->GetSurfaceAppFrameworkType(), "test");
1568 }
1569 
1570 /*
1571  * Function: SetSurfaceAppFrameworkType and GetSurfaceAppFrameworkType
1572  * Type: Function
1573  * Rank: Important(2)
1574  * EnvConditions: N/A
1575  * CaseDescription: 1. call SetSurfaceAppFrameworkType with producer_ is nullptr and check ret
1576  *                  2. call GetSurfaceAppFrameworkType with producer_ is nullptr and check ret
1577  */
1578 HWTEST_F(ProducerSurfaceTest, SetSurfaceAppFrameworkTypeTest002, Function | MediumTest | Level2)
1579 {
1580     std::string type = "test";
1581     GSError ret = surface_->SetSurfaceAppFrameworkType(type);
1582     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1583     ASSERT_EQ(surface_->GetSurfaceAppFrameworkType(), "");
1584 }
1585 
1586 /*
1587  * Function: RequestBuffersAndFlushBuffers
1588  * Type: Function
1589  * Rank: Important(1)
1590  * EnvConditions: N/A
1591  * CaseDescription: 1. call RequestBuffers and FlushBuffers
1592  * @tc.require: issueI5GMZN issueI5IWHW
1593  */
1594 HWTEST_F(ProducerSurfaceTest, RequestBuffersAndFlushBuffersTest, Function | MediumTest | Level1)
1595 {
1596     pSurface->SetQueueSize(12);
1597     std::vector<sptr<SurfaceBuffer>> sfbuffers;
1598     std::vector<sptr<SyncFence>> releaseFences;
1599     EXPECT_EQ(OHOS::GSERROR_OK, pSurface->RequestBuffers(sfbuffers, releaseFences, requestConfig));
1600     for (size_t i = 0; i < sfbuffers.size(); ++i) {
1601         EXPECT_NE(nullptr, sfbuffers[i]);
1602     }
1603     std::cout << sfbuffers.size() << std::endl;
1604     uint32_t num = static_cast<uint32_t>(sfbuffers.size());
1605     std::vector<sptr<SyncFence>> flushFences;
1606     std::vector<BufferFlushConfigWithDamages> configs;
1607     flushFences.resize(num);
1608     configs.reserve(num);
__anon5a7e27240502(BufferFlushConfigWithDamages &config) 1609     auto handleConfig = [](BufferFlushConfigWithDamages &config) -> void {
1610         config.damages.reserve(1);
1611         OHOS::Rect damage = {
1612             .x = 0,
1613             .y = 0,
1614             .w = 0x100,
1615             .h = 0x100
1616         };
1617         config.damages.emplace_back(damage);
1618         config.timestamp = 0;
1619     };
1620     for (uint32_t i = 0; i < num; ++i) {
1621         flushFences[i] = new SyncFence(-1);
1622         BufferFlushConfigWithDamages config;
1623         handleConfig(config);
1624         configs.emplace_back(config);
1625     }
1626     flushFences[0] = nullptr;
1627     EXPECT_EQ(OHOS::GSERROR_INVALID_ARGUMENTS, pSurface->FlushBuffers(sfbuffers, flushFences, configs));
1628     flushFences[0] = new SyncFence(-1);
1629     EXPECT_EQ(OHOS::GSERROR_OK, pSurface->FlushBuffers(sfbuffers, flushFences, configs));
1630     sptr<SurfaceBuffer> buffer;
1631     int32_t flushFence;
1632     for (uint32_t i = 0; i < num; ++i) {
1633         GSError ret = csurf->AcquireBuffer(buffer, flushFence, timestamp, damage);
1634         ASSERT_EQ(ret, OHOS::GSERROR_OK);
1635         ret = csurf->ReleaseBuffer(buffer, -1);
1636         ASSERT_EQ(ret, OHOS::GSERROR_OK);
1637     }
1638     EXPECT_EQ(OHOS::GSERROR_NO_BUFFER, csurf->AcquireBuffer(buffer, flushFence, timestamp, damage));
1639     pSurface->SetQueueSize(2);
1640 }
1641 
1642 /*
1643  * Function: RegisterUserDataChangeListener
1644  * Type: Function
1645  * Rank: Important(2)
1646  * EnvConditions: N/A
1647  * CaseDescription: 1. call RegisterUserDataChangeListener with nullptr param
1648  *                  2. check ret
1649  */
1650 HWTEST_F(ProducerSurfaceTest, RegisterUserDataChangeListenerTest, Function | MediumTest | Level2)
1651 {
1652     GSError ret = surface_->RegisterUserDataChangeListener("test", nullptr);
1653     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1654 }
1655 
1656 /*
1657  * Function: RegisterReleaseListener and UnRegisterReleaseListener
1658  * Type: Function
1659  * Rank: Important(2)
1660  * EnvConditions: N/A
1661  * CaseDescription: 1. call RegisterReleaseListener with producer_ is nullptr and check ret
1662  *                  2. call UnRegisterReleaseListener with producer_ is nullptr and check ret
1663  */
1664 HWTEST_F(ProducerSurfaceTest, RegisterReleaseListenerTest, Function | MediumTest | Level2)
1665 {
1666     GSError ret = surface_->RegisterReleaseListener(OnBufferRelease);
1667     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1668     OnReleaseFuncWithFence releaseFuncWithFence;
1669     ret = surface_->RegisterReleaseListener(releaseFuncWithFence);
1670     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1671     ret = surface_->UnRegisterReleaseListener();
1672     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1673 }
1674 
1675 /*
1676  * Function: AcquireLastFlushedBuffer and ReleaseLastFlushedBuffer
1677  * Type: Function
1678  * Rank: Important(1)
1679  * EnvConditions: N/A
1680  * CaseDescription: 1. call AcquireLastFlushedBuffer OK
1681  *                  2. call AcquireLastFlushedBuffer FAIL
1682  *                  3. call ReleaseLastFlushedBuffer
1683  */
1684 HWTEST_F(ProducerSurfaceTest, AcquireLastFlushedBufferTest001, Function | MediumTest | Level2)
1685 {
1686     sptr<SurfaceBuffer> buffer;
1687     int releaseFence = -1;
1688     EXPECT_EQ(producer->SetQueueSize(3), OHOS::GSERROR_OK);
1689     GSError ret = pSurface->RequestBuffer(buffer, releaseFence, requestConfig);
1690     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1691 
1692     ret = pSurface->FlushBuffer(buffer, -1, flushConfig);
1693     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1694 
1695     int32_t flushFence;
1696     ret = csurf->AcquireBuffer(buffer, flushFence, timestamp, damage);
1697     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1698     ret = csurf->ReleaseBuffer(buffer, -1);
1699     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1700 
1701     sptr<SurfaceBuffer> buffer1 = nullptr;
1702     sptr<SyncFence> fence = nullptr;
1703     float matrix[16];
1704 
1705     ret = pSurface->AcquireLastFlushedBuffer(buffer1, fence, matrix, 16, false);
1706     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1707     EXPECT_EQ(buffer->GetSeqNum(), buffer1->GetSeqNum());
1708 
1709     ret = pSurface->AcquireLastFlushedBuffer(buffer1, fence, matrix, 16, false);
1710     EXPECT_EQ(ret, OHOS::SURFACE_ERROR_BUFFER_STATE_INVALID);
1711 
1712     sptr<SurfaceBuffer> buffer2;
1713     ret = pSurface->RequestBuffer(buffer2, releaseFence, requestConfig);
1714     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1715 
1716     sptr<SurfaceBuffer> buffer3;
1717     ret = pSurface->RequestBuffer(buffer3, releaseFence, requestConfig);
1718     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1719 
1720     sptr<SurfaceBuffer> buffer4;
1721     ret = pSurface->RequestBuffer(buffer4, releaseFence, requestConfig);
1722     EXPECT_EQ(ret, OHOS::GSERROR_NO_BUFFER);
1723 
1724     ret = pSurface->ReleaseLastFlushedBuffer(buffer1);
1725     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1726 
1727     ret = pSurface->RequestBuffer(buffer4, releaseFence, requestConfig);
1728     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1729 
1730     ret = pSurface->FlushBuffer(buffer2, -1, flushConfig);
1731     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1732 
1733     ret = pSurface->FlushBuffer(buffer3, -1, flushConfig);
1734     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1735 
1736     ret = pSurface->FlushBuffer(buffer4, -1, flushConfig);
1737     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1738 
1739     ret = pSurface->ReleaseLastFlushedBuffer(buffer2);
1740     EXPECT_EQ(ret, OHOS::SURFACE_ERROR_BUFFER_STATE_INVALID);
1741 
1742     EXPECT_EQ(pSurface->CleanCache(), OHOS::GSERROR_OK);
1743 }
1744 
1745 /*
1746  * Function: AcquireLastFlushedBuffer and ReleaseLastFlushedBuffer
1747  * Type: Function
1748  * Rank: Important(1)
1749  * EnvConditions: N/A
1750  * CaseDescription: 1. call AcquireLastFlushedBuffer FAIL
1751  *                  3. call ReleaseLastFlushedBuffer FAIL
1752  */
1753 HWTEST_F(ProducerSurfaceTest, AcquireLastFlushedBufferTest002, Function | MediumTest | Level2)
1754 {
1755     sptr<SurfaceBuffer> buffer1 = nullptr;
1756     sptr<SyncFence> fence = nullptr;
1757     float matrix[16];
1758     GSError ret = surface_->AcquireLastFlushedBuffer(buffer1, fence, matrix, 16, false);
1759     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1760     ret = surface_->ReleaseLastFlushedBuffer(buffer1);
1761     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1762     ret = pSurface->ReleaseLastFlushedBuffer(nullptr);
1763     EXPECT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1764 }
1765 
1766 /*
1767  * Function: SetHdrWhitePointBrightness and SetSdrWhitePointBrightness
1768  * Type: Function
1769  * Rank: Important(2)
1770  * EnvConditions: N/A
1771  * CaseDescription: 1. call SetHdrWhitePointBrightness with producer_ is nullptr and check ret
1772  *                  2. call SetSdrWhitePointBrightness with producer_ is nullptr and check ret
1773  */
1774 HWTEST_F(ProducerSurfaceTest, SetWhitePointBrightnessTest, Function | MediumTest | Level2)
1775 {
1776     GSError ret = surface_->SetHdrWhitePointBrightness(0);
1777     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1778     ret = surface_->SetSdrWhitePointBrightness(0);
1779     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1780 }
1781 
1782 /*
1783  * Function: SetGlobalAlpha
1784  * Type: Function
1785  * Rank: Important(2)
1786  * EnvConditions: N/A
1787  * CaseDescription: 1. call SetGlobalAlpha with abnormal parameters and check ret
1788  */
1789 HWTEST_F(ProducerSurfaceTest, SetGlobalAlphaTest, Function | MediumTest | Level2)
1790 {
1791     int32_t alpha = -255;
1792     GSError ret = pSurface->SetGlobalAlpha(alpha);
1793     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1794     alpha = 256;
1795     ret = pSurface->SetGlobalAlpha(alpha);
1796     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
1797     alpha = 255;
1798     ret = pSurface->SetGlobalAlpha(alpha);
1799     ASSERT_EQ(ret, OHOS::GSERROR_OK);
1800 }
1801 
1802 /*
1803  * Function: IsInHebcWhiletList
1804  * Type: Function
1805  * Rank: Important(2)
1806  * EnvConditions: N/A
1807  * CaseDescription: 1. call IsInHebcWhiletList and check ret
1808  */
1809 HWTEST_F(ProducerSurfaceTest, IsInHebcWhiletListTest, Function | MediumTest | Level2)
1810 {
1811     bool isInHebcList = pSurface->IsInHebcList();
1812     ASSERT_EQ(isInHebcList, false);
1813 }
1814 
1815 /*
1816  * Function: RequestBufferConcurrentTest001
1817  * Type: Function
1818  * Rank: Important(2)
1819  * EnvConditions: N/A
1820  * CaseDescription: 1. call RequestBuffer and check ret
1821  */
1822 HWTEST_F(ProducerSurfaceTest, RequestBufferConcurrentTest001, Function | MediumTest | Level2)
1823 {
1824     sptr<IConsumerSurface> cSurfTmp = IConsumerSurface::Create();
1825     sptr<IBufferConsumerListener> listenerTmp = new BufferConsumerListener();
1826     cSurfTmp->RegisterConsumerListener(listenerTmp);
1827     sptr<IBufferProducer> producerTmp = cSurfTmp->GetProducer();
1828     sptr<Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
1829 
1830     GSError ret = pSurfaceTmp->SetQueueSize(3);
1831     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1832 
1833     BufferRequestConfig requestConfigTmp = {
1834         .width = 0x100,
1835         .height = 0x100,
1836         .strideAlignment = 0x8,
1837         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
1838         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
1839         .timeout = 3000,
1840     };
1841     sptr<SurfaceBuffer> buffer = nullptr;
1842     int releaseFence = -1;
1843     for (uint32_t i = 0; i < 3; i++) {
1844         ret = pSurfaceTmp->RequestBuffer(buffer, releaseFence, requestConfigTmp);
1845         EXPECT_EQ(ret, OHOS::GSERROR_OK);
1846     }
1847 
__anon5a7e27240602(const std::string& FuncName) 1848     auto func = [&pSurfaceTmp](const std::string& FuncName) {
1849         usleep(1000);
1850         clock_t start = clock();
1851         pSurfaceTmp->GetSurfaceSourceType();
1852         clock_t end = clock();
1853         int32_t time = (end - start) / CLOCKS_PER_SEC;
1854         EXPECT_EQ(time < 1, true);
1855     };
1856     std::thread t1(func, "thread1");
1857 
1858     ret = pSurfaceTmp->RequestBuffer(buffer, releaseFence, requestConfigTmp);
1859     EXPECT_EQ(ret, OHOS::SURFACE_ERROR_NO_BUFFER);
1860     t1.join();
1861     pSurfaceTmp = nullptr;
1862     producerTmp = nullptr;
1863     cSurfTmp = nullptr;
1864 }
1865 
1866 /*
1867  * Function: RequestBufferConcurrentTest002
1868  * Type: Function
1869  * Rank: Important(2)
1870  * EnvConditions: N/A
1871  * CaseDescription: 1. call RequestBuffer and check ret
1872  */
1873 HWTEST_F(ProducerSurfaceTest, RequestBufferConcurrentTest002, Function | MediumTest | Level2)
1874 {
1875     sptr<IConsumerSurface> cSurfTmp = IConsumerSurface::Create();
1876     sptr<IBufferConsumerListener> listenerTmp = new BufferConsumerListener();
1877     cSurfTmp->RegisterConsumerListener(listenerTmp);
1878     sptr<IBufferProducer> producerTmp = cSurfTmp->GetProducer();
1879     sptr<Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
1880 
1881     GSError ret = pSurfaceTmp->SetQueueSize(3);
1882     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1883 
1884     BufferRequestConfig requestConfigTmp = {
1885         .width = 0x100,
1886         .height = 0x100,
1887         .strideAlignment = 0x8,
1888         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
1889         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
1890         .timeout = 1000,
1891     };
1892     sptr<SurfaceBuffer> buffer = nullptr;
1893     int releaseFence = -1;
1894 
__anon5a7e27240702(const std::string& FuncName) 1895     auto func = [&pSurfaceTmp](const std::string& FuncName) {
1896         for (uint32_t i = 0; i < 300000; i++) {
1897             usleep(5);
1898             pSurfaceTmp->SetScalingMode(ScalingMode::SCALING_MODE_SCALE_TO_WINDOW);
1899             pSurfaceTmp->SetSurfaceSourceType(OHSurfaceSource::OH_SURFACE_SOURCE_UI);
1900             pSurfaceTmp->GetSurfaceSourceType();
1901             pSurfaceTmp->CleanCache(true);
1902         }
1903     };
1904     std::thread t1(func, "thread1");
1905     for (uint32_t i = 0; i < 300000; i++) {
1906         ret = pSurfaceTmp->RequestBuffer(buffer, releaseFence, requestConfigTmp);
1907         if (ret == SURFACE_ERROR_NO_BUFFER) {
1908             break;
1909         } else {
1910             EXPECT_EQ(ret, OHOS::GSERROR_OK);
1911         }
1912     }
1913 
1914     t1.join();
1915     pSurfaceTmp = nullptr;
1916     producerTmp = nullptr;
1917     cSurfTmp = nullptr;
1918 }
1919 
1920 /*
1921  * Function: RequestBufferConcurrentTest003
1922  * Type: Function
1923  * Rank: Important(2)
1924  * EnvConditions: N/A
1925  * CaseDescription: 1. call RequestBuffer and check ret
1926  */
1927 HWTEST_F(ProducerSurfaceTest, RequestBufferConcurrentTest003, Function | MediumTest | Level2)
1928 {
1929     sptr<IConsumerSurface> cSurfTmp = IConsumerSurface::Create();
1930     sptr<IBufferConsumerListener> listenerTmp = new BufferConsumerListener();
1931     cSurfTmp->RegisterConsumerListener(listenerTmp);
1932     sptr<IBufferProducer> producerTmp = cSurfTmp->GetProducer();
1933     sptr<Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
1934 
1935     GSError ret = pSurfaceTmp->SetQueueSize(3);
1936     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1937 
1938     BufferRequestConfig requestConfigTmp = {
1939         .width = 0x100,
1940         .height = 0x100,
1941         .strideAlignment = 0x8,
1942         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
1943         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
1944         .timeout = 1000,
1945     };
1946     sptr<SurfaceBuffer> buffer = nullptr;
1947     int releaseFence = -1;
1948 
__anon5a7e27240802(const std::string& FuncName) 1949     auto func = [&pSurfaceTmp, &cSurfTmp](const std::string& FuncName) {
1950         sptr<SurfaceBuffer> buffer;
1951         int32_t flushFence;
1952         int64_t timestamp;
1953         OHOS::Rect damage;
1954         GSError ret;
1955         for (uint32_t i = 0; i < 100000; i++) {
1956             usleep(5);
1957             ret = cSurfTmp->AcquireBuffer(buffer, flushFence, timestamp, damage);
1958             if (ret != SURFACE_ERROR_NO_BUFFER) {
1959                 EXPECT_EQ(ret, OHOS::GSERROR_OK);
1960                 ret = cSurfTmp->ReleaseBuffer(buffer, -1);
1961                 if (ret != SURFACE_ERROR_BUFFER_NOT_INCACHE) {
1962                     EXPECT_EQ(ret, OHOS::GSERROR_OK);
1963                 }
1964             }
1965             pSurfaceTmp->CleanCache(true);
1966         }
1967     };
1968     std::thread t1(func, "thread1");
1969     BufferFlushConfig flushConfig = {
1970         .damage = {
1971             .w = 0x100,
1972             .h = 0x100,
1973         },
1974     };
1975     for (uint32_t i = 0; i < 100000; i++) {
1976         ret = pSurfaceTmp->RequestBuffer(buffer, releaseFence, requestConfigTmp);
1977         if (ret == SURFACE_ERROR_NO_BUFFER) {
1978             break;
1979         } else {
1980             EXPECT_EQ(ret, OHOS::GSERROR_OK);
1981         }
1982         ret = pSurfaceTmp->FlushBuffer(buffer, -1, flushConfig);
1983         if (ret == SURFACE_ERROR_BUFFER_NOT_INCACHE) {
1984             continue;
1985         } else {
1986             EXPECT_EQ(ret, OHOS::GSERROR_OK);
1987         }
1988     }
1989 
1990     t1.join();
1991     pSurfaceTmp = nullptr;
1992     producerTmp = nullptr;
1993     cSurfTmp = nullptr;
1994 }
1995 
1996 /*
1997  * Function: RequestBufferConcurrentTest004
1998  * Type: Function
1999  * Rank: Important(2)
2000  * EnvConditions: N/A
2001  * CaseDescription: 1. call RequestBuffer and check ret
2002  */
2003 HWTEST_F(ProducerSurfaceTest, RequestBufferConcurrentTest004, Function | MediumTest | Level2)
2004 {
2005     sptr<IConsumerSurface> cSurfTmp = IConsumerSurface::Create();
2006     sptr<IBufferConsumerListener> listenerTmp = new BufferConsumerListener();
2007     cSurfTmp->RegisterConsumerListener(listenerTmp);
2008     sptr<IBufferProducer> producerTmp = cSurfTmp->GetProducer();
2009     sptr<Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
2010 
2011     GSError ret = pSurfaceTmp->SetQueueSize(10);
2012     EXPECT_EQ(ret, OHOS::GSERROR_OK);
2013 
2014     BufferRequestConfig requestConfigTmp = {
2015         .width = 0x100,
2016         .height = 0x100,
2017         .strideAlignment = 0x8,
2018         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
2019         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
2020         .timeout = 1000,
2021     };
2022     sptr<SurfaceBuffer> buffer = nullptr;
2023     int releaseFence = -1;
2024     BufferFlushConfig flushConfig = {
2025         .damage = {
2026             .w = 0x100,
2027             .h = 0x100,
2028         },
2029     };
2030 
__anon5a7e27240902(const std::string& FuncName) 2031     auto func = [&pSurfaceTmp, &buffer, &requestConfigTmp, &releaseFence, &flushConfig](const std::string& FuncName) {
2032         for (uint32_t i = 0; i < 10000; i++) {
2033             GSError ret = pSurfaceTmp->RequestBuffer(buffer, releaseFence, requestConfigTmp);
2034             if (ret == OHOS::GSERROR_OK) {
2035                 ret = pSurfaceTmp->FlushBuffer(buffer, -1, flushConfig);
2036                 if (ret != SURFACE_ERROR_BUFFER_NOT_INCACHE && ret != SURFACE_ERROR_BUFFER_STATE_INVALID) {
2037                     EXPECT_EQ(ret, OHOS::GSERROR_OK);
2038                 }
2039             }
2040             pSurfaceTmp->CleanCache(true);
2041         }
2042     };
2043     std::thread t1(func, "thread1");
2044     for (uint32_t i = 0; i < 10000; i++) {
2045         ret = pSurfaceTmp->RequestBuffer(buffer, releaseFence, requestConfigTmp);
2046         if (ret == OHOS::GSERROR_OK) {
2047             ret = pSurfaceTmp->FlushBuffer(buffer, -1, flushConfig);
2048             if (ret != SURFACE_ERROR_BUFFER_NOT_INCACHE && ret != SURFACE_ERROR_BUFFER_STATE_INVALID) {
2049                 EXPECT_EQ(ret, OHOS::GSERROR_OK);
2050             }
2051         }
2052         pSurfaceTmp->CleanCache(true);
2053     }
2054 
2055     t1.join();
2056     pSurfaceTmp = nullptr;
2057     producerTmp = nullptr;
2058     cSurfTmp = nullptr;
2059 }
2060 
2061 /*
2062  * Function: RequestBufferNoConsumerTest
2063  * Type: Function
2064  * Rank: Important(2)
2065  * EnvConditions: N/A
2066  * CaseDescription: 1. call RequestBuffer and check ret
2067  */
2068 HWTEST_F(ProducerSurfaceTest, RequestBufferNoConsumerTest, Function | MediumTest | Level2)
2069 {
2070     sptr<IConsumerSurface> cSurfTmp = IConsumerSurface::Create();
2071     sptr<IBufferConsumerListener> listenerTmp = new BufferConsumerListener();
2072     cSurfTmp->RegisterConsumerListener(listenerTmp);
2073     sptr<IBufferProducer> producerTmp = cSurfTmp->GetProducer();
2074     sptr<Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
2075 
2076     BufferRequestConfig requestConfigTmp = {
2077         .width = 0x100,
2078         .height = 0x100,
2079         .strideAlignment = 0x8,
2080         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
2081         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
2082         .timeout = 0,
2083     };
2084     sptr<SurfaceBuffer> buffer = nullptr;
2085     int releaseFence = -1;
2086     GSError ret = pSurfaceTmp->RequestBuffer(buffer, releaseFence, requestConfigTmp);
2087     ASSERT_EQ(ret, OHOS::GSERROR_OK);
2088 
2089     cSurfTmp = nullptr;
2090     ret = pSurfaceTmp->RequestBuffer(buffer, releaseFence, requestConfigTmp);
2091     ASSERT_EQ(ret, OHOS::GSERROR_NO_CONSUMER);
2092 
2093     pSurfaceTmp = nullptr;
2094     producerTmp = nullptr;
2095 }
2096 
2097 /*
2098  * Function: RequestBufferNoListenerTest
2099  * Type: Function
2100  * Rank: Important(2)
2101  * EnvConditions: N/A
2102  * CaseDescription: 1. call RequestBuffer and check ret
2103  */
2104 HWTEST_F(ProducerSurfaceTest, RequestBufferNoListenerTest, Function | MediumTest | Level2)
2105 {
2106     sptr<IConsumerSurface> cSurfTmp = IConsumerSurface::Create();
2107     sptr<IBufferProducer> producerTmp = cSurfTmp->GetProducer();
2108     sptr<Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
2109 
2110     BufferRequestConfig requestConfigTmp = {
2111         .width = 0x100,
2112         .height = 0x100,
2113         .strideAlignment = 0x8,
2114         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
2115         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
2116         .timeout = 0,
2117     };
2118     sptr<SurfaceBuffer> buffer = nullptr;
2119     int releaseFence = -1;
2120     GSError ret = pSurfaceTmp->RequestBuffer(buffer, releaseFence, requestConfigTmp);
2121     ASSERT_EQ(ret, OHOS::SURFACE_ERROR_CONSUMER_UNREGISTER_LISTENER);
2122 
2123     ret = pSurfaceTmp->Disconnect();
2124     ASSERT_EQ(ret, OHOS::GSERROR_OK);
2125 
2126     ret = pSurfaceTmp->Connect();
2127     ASSERT_EQ(ret, OHOS::GSERROR_OK);
2128 
2129     ret = pSurfaceTmp->Disconnect();
2130     ASSERT_EQ(ret, OHOS::GSERROR_OK);
2131 
2132     pSurfaceTmp = nullptr;
2133     producerTmp = nullptr;
2134     cSurfTmp = nullptr;
2135 }
2136 
2137 /*
2138  * Function: RequestBuffersNoListenerTest
2139  * Type: Function
2140  * Rank: Important(2)
2141  * EnvConditions: N/A
2142  * CaseDescription: 1. call RequestBuffer and check ret
2143  */
2144 HWTEST_F(ProducerSurfaceTest, RequestBuffersNoListenerTest, Function | MediumTest | Level2)
2145 {
2146     sptr<IConsumerSurface> cSurfTmp = IConsumerSurface::Create();
2147     sptr<IBufferProducer> producerTmp = cSurfTmp->GetProducer();
2148     sptr<Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
2149 
2150     BufferRequestConfig requestConfigTmp = {
2151         .width = 0x100,
2152         .height = 0x100,
2153         .strideAlignment = 0x8,
2154         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
2155         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
2156         .timeout = 0,
2157         .transform = GraphicTransformType::GRAPHIC_ROTATE_BUTT,
2158     };
2159 
2160     std::vector<sptr<SurfaceBuffer>> sfbuffers;
2161     std::vector<sptr<SyncFence>> releaseFences;
2162     GSError ret = pSurfaceTmp->RequestBuffers(sfbuffers, releaseFences, requestConfigTmp);
2163     ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
2164 
2165     ret = pSurfaceTmp->Disconnect();
2166     ASSERT_EQ(ret, OHOS::GSERROR_OK);
2167 
2168     ret = pSurfaceTmp->Connect();
2169     ASSERT_EQ(ret, OHOS::GSERROR_OK);
2170 
2171     ret = pSurfaceTmp->Disconnect();
2172     ASSERT_EQ(ret, OHOS::GSERROR_OK);
2173 
2174     pSurfaceTmp = nullptr;
2175     producerTmp = nullptr;
2176     cSurfTmp = nullptr;
2177 }
2178 
2179 /*
2180  * Function: ProducerSurfaceParameterNullTest
2181  * Type: Function
2182  * Rank: Important(2)
2183  * EnvConditions: N/A
2184  * CaseDescription: 1. call ProducerSurfuce function and check ret
2185  */
2186 HWTEST_F(ProducerSurfaceTest, ProducerSurfaceParameterNullTest, Function | MediumTest | Level2)
2187 {
2188     sptr<IBufferProducer> producer = nullptr;
2189     sptr<ProducerSurface> pSurfaceTmp = new ProducerSurface(producer);
2190     ProducerInitInfo info;
2191     ASSERT_EQ(pSurfaceTmp->GetProducerInitInfo(info), OHOS::GSERROR_INVALID_ARGUMENTS);
2192     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
2193     sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
2194     BufferRequestConfig config;
2195     ASSERT_EQ(pSurfaceTmp->RequestBuffer(buffer, fence, config), OHOS::GSERROR_INVALID_ARGUMENTS);
2196     std::vector<sptr<SurfaceBuffer>> buffers;
2197     std::vector<sptr<SyncFence>> fences;
2198     ASSERT_EQ(pSurfaceTmp->RequestBuffers(buffers, fences, config), OHOS::GSERROR_INVALID_ARGUMENTS);
2199     BufferFlushConfigWithDamages configWithDamage;
2200     ASSERT_EQ(pSurfaceTmp->FlushBuffer(buffer, fence, configWithDamage), OHOS::GSERROR_INVALID_ARGUMENTS);
2201     std::vector<BufferFlushConfigWithDamages> configWithDamages;
2202     ASSERT_EQ(pSurfaceTmp->FlushBuffers(buffers, fences, configWithDamages), OHOS::GSERROR_INVALID_ARGUMENTS);
2203     float matrix[16];
2204     bool isUseNewMatrix = false;
2205     ASSERT_EQ(pSurfaceTmp->GetLastFlushedBuffer(buffer, fence, matrix, isUseNewMatrix),
2206         OHOS::GSERROR_INVALID_ARGUMENTS);
2207     ASSERT_EQ(pSurfaceTmp->CancelBuffer(buffer), OHOS::SURFACE_ERROR_UNKOWN);
2208     ASSERT_EQ(pSurfaceTmp->AttachBufferToQueue(nullptr), OHOS::SURFACE_ERROR_UNKOWN);
2209     ASSERT_EQ(pSurfaceTmp->AttachBufferToQueue(buffer), OHOS::SURFACE_ERROR_UNKOWN);
2210     ASSERT_EQ(pSurfaceTmp->DetachBufferFromQueue(nullptr), OHOS::SURFACE_ERROR_UNKOWN);
2211     ASSERT_EQ(pSurfaceTmp->DetachBufferFromQueue(buffer), OHOS::SURFACE_ERROR_UNKOWN);
2212     sptr<SurfaceBuffer> bufferTmp;
2213     ASSERT_EQ(pSurfaceTmp->AttachBuffer(bufferTmp), OHOS::GSERROR_INVALID_ARGUMENTS);
2214     ASSERT_EQ(pSurfaceTmp->AttachBuffer(buffer), OHOS::GSERROR_INVALID_ARGUMENTS);
2215     ASSERT_EQ(pSurfaceTmp->AttachBuffer(bufferTmp, 0), OHOS::GSERROR_INVALID_ARGUMENTS);
2216     ASSERT_EQ(pSurfaceTmp->AttachBuffer(buffer, 0), OHOS::GSERROR_INVALID_ARGUMENTS);
2217     ASSERT_EQ(pSurfaceTmp->DetachBuffer(bufferTmp), OHOS::GSERROR_INVALID_ARGUMENTS);
2218     ASSERT_EQ(pSurfaceTmp->DetachBuffer(buffer), OHOS::GSERROR_INVALID_ARGUMENTS);
2219     ASSERT_EQ(pSurfaceTmp->GetQueueSize(), 0);
2220     ASSERT_EQ(pSurfaceTmp->SetQueueSize(0), OHOS::GSERROR_INVALID_ARGUMENTS);
2221     pSurfaceTmp->GetName();
2222     ASSERT_EQ(pSurfaceTmp->GetDefaultWidth(), -1);
2223     ASSERT_EQ(pSurfaceTmp->GetDefaultHeight(), -1);
2224     GraphicTransformType transform = GraphicTransformType::GRAPHIC_ROTATE_NONE;
2225     ASSERT_EQ(pSurfaceTmp->SetTransformHint(transform), OHOS::GSERROR_INVALID_ARGUMENTS);
2226     ASSERT_EQ(pSurfaceTmp->SetDefaultUsage(0), OHOS::GSERROR_INVALID_ARGUMENTS);
2227     ASSERT_EQ(pSurfaceTmp->GetDefaultUsage(), 0);
2228     OHSurfaceSource sourceType = OHSurfaceSource::OH_SURFACE_SOURCE_VIDEO;
2229     ASSERT_EQ(pSurfaceTmp->SetSurfaceSourceType(sourceType), OHOS::GSERROR_INVALID_ARGUMENTS);
2230     ASSERT_EQ(pSurfaceTmp->GetSurfaceSourceType(), OHSurfaceSource::OH_SURFACE_SOURCE_DEFAULT);
2231     std::string appFrameworkType;
2232     ASSERT_EQ(pSurfaceTmp->SetSurfaceAppFrameworkType(appFrameworkType), OHOS::GSERROR_INVALID_ARGUMENTS);
2233     ASSERT_EQ(pSurfaceTmp->GetSurfaceAppFrameworkType(), "");
2234     OnReleaseFunc func = nullptr;
2235     ASSERT_EQ(pSurfaceTmp->RegisterReleaseListener(func), OHOS::GSERROR_INVALID_ARGUMENTS);
2236     ASSERT_EQ(pSurfaceTmp->RegisterReleaseListener(OnBufferRelease), OHOS::GSERROR_INVALID_ARGUMENTS);
2237     OnReleaseFuncWithFence funcWithFence = nullptr;
2238     ASSERT_EQ(pSurfaceTmp->RegisterReleaseListener(funcWithFence), OHOS::GSERROR_INVALID_ARGUMENTS);
2239     ASSERT_EQ(pSurfaceTmp->RegisterReleaseListener(OnBufferReleaseWithFence), OHOS::GSERROR_INVALID_ARGUMENTS);
2240     ASSERT_EQ(pSurfaceTmp->UnRegisterReleaseListener(), OHOS::GSERROR_INVALID_ARGUMENTS);
2241     ASSERT_EQ(pSurfaceTmp->IsRemote(), false);
2242     ASSERT_EQ(pSurfaceTmp->CleanCache(true), OHOS::GSERROR_INVALID_ARGUMENTS);
2243     ASSERT_EQ(pSurfaceTmp->GoBackground(), OHOS::GSERROR_INVALID_ARGUMENTS);
2244     pSurfaceTmp->GetUniqueId();
2245     ASSERT_EQ(pSurfaceTmp->SetTransform(transform), OHOS::GSERROR_INVALID_ARGUMENTS);
2246     ASSERT_EQ(pSurfaceTmp->GetTransform(), GraphicTransformType::GRAPHIC_ROTATE_BUTT);
2247     ASSERT_EQ(pSurfaceTmp->Connect(), OHOS::GSERROR_INVALID_ARGUMENTS);
2248     ASSERT_EQ(pSurfaceTmp->Disconnect(), OHOS::GSERROR_INVALID_ARGUMENTS);
2249     ScalingMode scalingMode = ScalingMode::SCALING_MODE_FREEZE;
2250     ASSERT_EQ(pSurfaceTmp->SetScalingMode(0, scalingMode), OHOS::GSERROR_INVALID_ARGUMENTS);
2251     ASSERT_EQ(pSurfaceTmp->SetScalingMode(scalingMode), OHOS::GSERROR_INVALID_ARGUMENTS);
2252     pSurfaceTmp->SetBufferHold(false);
2253     std::vector<GraphicHDRMetaData> metaData;
2254     ASSERT_EQ(pSurfaceTmp->SetMetaData(0, metaData), OHOS::GSERROR_INVALID_ARGUMENTS);
2255     GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_RED_PRIMARY_X ;
2256     std::vector<uint8_t> metaData1;
2257     ASSERT_EQ(pSurfaceTmp->SetMetaDataSet(0, key, metaData1), OHOS::GSERROR_INVALID_ARGUMENTS);
2258     ASSERT_EQ(pSurfaceTmp->SetTunnelHandle(nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
2259     int64_t time;
2260     GraphicPresentTimestampType type = GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_TIMESTAMP;
2261     ASSERT_EQ(pSurfaceTmp->GetPresentTimestamp(0, type, time), OHOS::GSERROR_INVALID_ARGUMENTS);
2262     ASSERT_EQ(pSurfaceTmp->SetWptrNativeWindowToPSurface(nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
2263     ASSERT_EQ(pSurfaceTmp->SetHdrWhitePointBrightness(0.0), OHOS::GSERROR_INVALID_ARGUMENTS);
2264     ASSERT_EQ(pSurfaceTmp->SetSdrWhitePointBrightness(0.0), OHOS::GSERROR_INVALID_ARGUMENTS);
2265     ASSERT_EQ(pSurfaceTmp->AcquireLastFlushedBuffer(buffer, fence, matrix, 0, 0), OHOS::GSERROR_INVALID_ARGUMENTS);
2266     ASSERT_EQ(pSurfaceTmp->ReleaseLastFlushedBuffer(nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
2267     ASSERT_EQ(pSurfaceTmp->ReleaseLastFlushedBuffer(buffer), OHOS::GSERROR_INVALID_ARGUMENTS);
2268     ASSERT_EQ(pSurfaceTmp->SetGlobalAlpha(0), OHOS::GSERROR_INVALID_ARGUMENTS);
2269     pSurfaceTmp = nullptr;
2270 }
2271 }
2272