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