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