1 /*
2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <gtest/gtest.h>
16 #include <fcntl.h>
17 #include <surface.h>
18 #include <sys/mman.h>
19 #include <buffer_extra_data_impl.h>
20 #include <buffer_queue_producer.h>
21 #include "buffer_consumer_listener.h"
22 #include "buffer_utils.h"
23 #include "consumer_surface.h"
24 #include "frame_report.h"
25 #include "sync_fence.h"
26 #include "producer_surface_delegator.h"
27
28 using namespace testing;
29 using namespace testing::ext;
30
31 namespace OHOS::Rosen {
32 class BufferQueueProducerTest : public testing::Test {
33 public:
SetUpTestCase()34 static void SetUpTestCase() {}
TearDownTestCase()35 static void TearDownTestCase() {}
36 void SetUp();
37 void TearDown();
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 BufferFlushConfigWithDamages flushConfig = {
48 .damages = {
49 {
50 .w = 0x100,
51 .h = 0x100,
52 }
53 },
54 };
55 protected:
56 int64_t timestamp_ = 0;
57 std::vector<Rect> damages_ = {};
58 sptr<BufferQueueProducer> bqp_ = nullptr;
59 sptr<BufferQueue> bq_ = nullptr;
60 sptr<BufferExtraData> bedata_ = nullptr;
61 };
62
63
SetUp()64 void BufferQueueProducerTest::SetUp()
65 {
66 bq_ = new BufferQueue("test");
67 sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
68 bq_->RegisterConsumerListener(listener);
69 if (bqp_ == nullptr) {
70 bqp_ = new BufferQueueProducer(bq_);
71 }
72 if (bedata_ == nullptr) {
73 bedata_ = new OHOS::BufferExtraDataImpl;
74 }
75 }
76
TearDown()77 void BufferQueueProducerTest::TearDown()
78 {
79 damages_.clear();
80 std::vector<Rect> tmp;
81 std::swap(damages_, tmp);
82 if (bqp_ != nullptr) {
83 bqp_->SetStatus(false);
84 bqp_ = nullptr;
85 }
86 bq_ = nullptr;
87 if (bedata_ != nullptr) {
88 bedata_ = nullptr;
89 }
90 }
91
92 /*
93 * Function: SetQueueSize and GetQueueSize
94 * Type: Function
95 * Rank: Important(2)
96 * EnvConditions: N/A
97 * CaseDescription: 1. call GetQueueSize and get default value
98 * 2. call SetQueueSize
99 * 3. call SetQueueSize again with abnormal value
100 * 4. call GetQueueSize for BufferQueueProducer and BufferQueue
101 * 5. check ret
102 */
103 HWTEST_F(BufferQueueProducerTest, QueueSize001, TestSize.Level0)
104 {
105 ASSERT_EQ(bqp_->GetQueueSize(), (uint32_t)SURFACE_DEFAULT_QUEUE_SIZE);
106
107 GSError ret = bqp_->SetQueueSize(2);
108 ASSERT_EQ(ret, OHOS::GSERROR_OK);
109
110 ret = bqp_->SetQueueSize(SURFACE_MAX_QUEUE_SIZE + 1);
111 EXPECT_NE(ret, OHOS::GSERROR_OK);
112
113 EXPECT_EQ(bqp_->GetQueueSize(), 2u);
114 EXPECT_EQ(bq_->GetQueueSize(), 2u);
115 }
116
117 /*
118 * Function: SetStatus and GetStatus
119 * Type: Function
120 * Rank: Important(2)
121 * EnvConditions: N/A
122 * CaseDescription: 1. call SetStatus with false and check get status value
123 * 2. call SetStatus with true and check get status value
124 */
125 HWTEST_F(BufferQueueProducerTest, Status001, TestSize.Level0)
126 {
127 bqp_->SetStatus(false);
128 EXPECT_EQ(bqp_->GetStatus(), false);
129 bqp_->SetStatus(true);
130 EXPECT_EQ(bqp_->GetStatus(), true);
131 }
132
133 /*
134 * Function: RequestBuffer and CancelBuffer
135 * Type: Function
136 * Rank: Important(2)
137 * EnvConditions: N/A
138 * CaseDescription: 1. call RequestBuffer
139 * 2. call CancelBuffer
140 * 3. check ret
141 */
142 HWTEST_F(BufferQueueProducerTest, ReqCan001, TestSize.Level0)
143 {
144 IBufferProducer::RequestBufferReturnValue retval;
145 GSError ret = bqp_->RequestBuffer(requestConfig, bedata_, retval);
146 ASSERT_EQ(ret, OHOS::GSERROR_OK);
147
148 ret = bqp_->CancelBuffer(retval.sequence, bedata_);
149 ASSERT_EQ(ret, OHOS::GSERROR_OK);
150 }
151
152 /*
153 * Function: RequestBuffer and CancelBuffer
154 * Type: Function
155 * Rank: Important(2)
156 * EnvConditions: N/A
157 * CaseDescription: 1. call RequestBuffer
158 * 2. call CancelBuffer 2 times
159 * 3. check ret
160 */
161 HWTEST_F(BufferQueueProducerTest, ReqCan002, TestSize.Level0)
162 {
163 IBufferProducer::RequestBufferReturnValue retval;
164 GSError ret = bqp_->RequestBuffer(requestConfig, bedata_, retval);
165 ASSERT_EQ(ret, OHOS::GSERROR_OK);
166
167 ret = bqp_->CancelBuffer(retval.sequence, bedata_);
168 ASSERT_EQ(ret, OHOS::GSERROR_OK);
169
170 ret = bqp_->CancelBuffer(retval.sequence, bedata_);
171 ASSERT_NE(ret, OHOS::GSERROR_OK);
172 }
173
174 /*
175 * Function: RequestBuffer, and CancelBuffer
176 * Type: Function
177 * Rank: Important(2)
178 * EnvConditions: N/A
179 * CaseDescription: 1. call RequestBuffer and CancelBuffer by different retval
180 * 2. check ret
181 */
182 HWTEST_F(BufferQueueProducerTest, ReqCan003, TestSize.Level0)
183 {
184 IBufferProducer::RequestBufferReturnValue retval1;
185 IBufferProducer::RequestBufferReturnValue retval2;
186 IBufferProducer::RequestBufferReturnValue retval3;
187
188 auto ret = bqp_->RequestBuffer(requestConfig, bedata_, retval1);
189 ASSERT_EQ(ret, OHOS::GSERROR_OK);
190 EXPECT_NE(retval1.buffer, nullptr);
191
192 ret = bqp_->RequestBuffer(requestConfig, bedata_, retval2);
193 EXPECT_EQ(ret, OHOS::GSERROR_OK);
194 EXPECT_NE(retval2.buffer, nullptr);
195
196 ret = bqp_->RequestBuffer(requestConfig, bedata_, retval3);
197 EXPECT_EQ(ret, OHOS::GSERROR_OK);
198 EXPECT_NE(retval3.buffer, nullptr);
199
200 ret = bqp_->CancelBuffer(retval1.sequence, bedata_);
201 EXPECT_EQ(ret, OHOS::GSERROR_OK);
202
203 ret = bqp_->CancelBuffer(retval2.sequence, bedata_);
204 EXPECT_EQ(ret, OHOS::GSERROR_OK);
205
206 ret = bqp_->CancelBuffer(retval3.sequence, bedata_);
207 EXPECT_EQ(ret, OHOS::GSERROR_OK);
208 }
209
210 /*
211 * Function: RequestBuffer, FlushBuffer, AcquireBuffer and ReleaseBuffer
212 * Type: Function
213 * Rank: Important(2)
214 * EnvConditions: N/A
215 * CaseDescription: 1. call RequestBuffer and FlushBuffer
216 * 2. call AcquireBuffer and ReleaseBuffer
217 * 3. check ret
218 */
219 HWTEST_F(BufferQueueProducerTest, ReqFlu001, TestSize.Level0)
220 {
221 IBufferProducer::RequestBufferReturnValue retval;
222 GSError ret = bqp_->RequestBuffer(requestConfig, bedata_, retval);
223 EXPECT_EQ(ret, OHOS::GSERROR_OK);
224
225 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
226 ret = bqp_->FlushBuffer(retval.sequence, bedata_, acquireFence, flushConfig);
227 EXPECT_EQ(ret, OHOS::GSERROR_OK);
228
229 ret = bq_->AcquireBuffer(retval.buffer, retval.fence, timestamp_, damages_);
230 ASSERT_EQ(ret, OHOS::GSERROR_OK);
231
232 sptr<SyncFence> releaseFence = SyncFence::INVALID_FENCE;
233 ret = bq_->ReleaseBuffer(retval.buffer, releaseFence);
234 ASSERT_EQ(ret, OHOS::GSERROR_OK);
235 }
236
237 /*
238 * Function: RequestBuffer, FlushBuffer, AcquireBuffer and ReleaseBuffer
239 * Type: Function
240 * Rank: Important(2)
241 * EnvConditions: N/A
242 * CaseDescription: 1. call RequestBuffer and FlushBuffer
243 * 2. call FlushBuffer again
244 * 3. call AcquireBuffer and ReleaseBuffer
245 * 4. check ret
246 */
247 HWTEST_F(BufferQueueProducerTest, ReqFlu002, TestSize.Level0)
248 {
249 IBufferProducer::RequestBufferReturnValue retval;
250 GSError ret = bqp_->RequestBuffer(requestConfig, bedata_, retval);
251 ASSERT_EQ(ret, OHOS::GSERROR_OK);
252
253 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
254 ret = bqp_->FlushBuffer(retval.sequence, bedata_, acquireFence, flushConfig);
255 ASSERT_EQ(ret, OHOS::GSERROR_OK);
256
257 ret = bqp_->FlushBuffer(retval.sequence, bedata_, acquireFence, flushConfig);
258 ASSERT_NE(ret, OHOS::GSERROR_OK);
259
260 ret = bq_->AcquireBuffer(retval.buffer, retval.fence, timestamp_, damages_);
261 ASSERT_EQ(ret, OHOS::GSERROR_OK);
262
263 sptr<SyncFence> releaseFence = SyncFence::INVALID_FENCE;
264 ret = bq_->ReleaseBuffer(retval.buffer, releaseFence);
265 ASSERT_EQ(ret, OHOS::GSERROR_OK);
266
267 int32_t timeOut = 1;
268 ret = bqp_->AttachBuffer(retval.buffer, timeOut);
269 ASSERT_EQ(ret, OHOS::GSERROR_OK);
270 }
271
272 /*
273 * Function: AttachBuffer and DetachBuffer
274 * Type: Function
275 * Rank: Important(2)
276 * EnvConditions: N/A
277 * CaseDescription: 1. call AttachBuffer and DetachBuffer
278 * 4. check ret
279 */
280 HWTEST_F(BufferQueueProducerTest, AttachAndDetachBuffer001, TestSize.Level0)
281 {
282 IBufferProducer::RequestBufferReturnValue retVal;
283 sptr<SurfaceBuffer> &buffer = retVal.buffer;
284
285 sptr<BufferQueue> bufferQueue = nullptr;
286 sptr<BufferQueueProducer> bqpTmp = new BufferQueueProducer(bufferQueue);
287
288 GSError ret = bqpTmp->AttachBuffer(buffer);
289 ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
290 ret = bqpTmp->DetachBuffer(buffer);
291 ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
292 bqpTmp = nullptr;
293 }
294
295 /*
296 * Function: AttachAndDetachBufferRemote
297 * Type: Function
298 * Rank: Important(2)
299 * EnvConditions: N/A
300 * CaseDescription: 1. call AttachBufferRemote, DetachBufferRemote
301 * 4. check ret
302 */
303 HWTEST_F(BufferQueueProducerTest, AttachAndDetachBufferRemote, TestSize.Level0)
304 {
305 MessageParcel arguments;
306 arguments.WriteInt32(5); // write sequence
307 MessageParcel reply;
308 reply.WriteInt32(6);
309 MessageOption option;
310 int32_t ret = bqp_->AttachBufferRemote(arguments, reply, option);
311 ASSERT_EQ(ret, ERR_INVALID_DATA);
312 ret = bqp_->DetachBufferRemote(arguments, reply, option);
313 ASSERT_EQ(ret, ERR_NONE);
314 }
315
316 /*
317 * Function: SetTunnelHandle
318 * Type: Function
319 * Rank: Important(2)
320 * EnvConditions: N/A
321 * CaseDescription: 1. call SetTunnelHandle
322 * 4. check ret
323 */
324 HWTEST_F(BufferQueueProducerTest, SetTunnelHandle, TestSize.Level0)
325 {
326 EXPECT_EQ(bqp_->SetTunnelHandle(nullptr), GSERROR_OK);
327 GraphicExtDataHandle *handle = static_cast<GraphicExtDataHandle *>(
328 malloc(sizeof(GraphicExtDataHandle) + sizeof(int32_t)));
329 handle->fd = -1;
330 handle->reserveInts = 1;
331 handle->reserve[0] = 0;
332 GSError ret = bqp_->SetTunnelHandle(handle);
333 EXPECT_EQ(ret, GSERROR_NO_ENTRY);
334 free(handle);
335 }
336
337 /*
338 * Function: SetTunnelHandleRemote
339 * Type: Function
340 * Rank: Important(2)
341 * EnvConditions: N/A
342 * CaseDescription: 1. call SetTunnelHandleRemote
343 * 4. check ret
344 */
345 HWTEST_F(BufferQueueProducerTest, SetTunnelHandleRemote, TestSize.Level0)
346 {
347 MessageParcel arguments;
348 arguments.WriteInt32(5);
349 MessageParcel reply;
350 reply.WriteInt32(6);
351 MessageOption option;
352 int32_t ret = bqp_->SetTunnelHandleRemote(arguments, reply, option);
353 EXPECT_EQ(ret, ERR_NONE);
354 }
355
356 /*
357 * Function: SetTunnelHandleRemote002
358 * Type: Function
359 * Rank: Important(2)
360 * EnvConditions: N/A
361 * CaseDescription: 1. call SetTunnelHandleRemote
362 * 2. check ret and errno
363 */
364 HWTEST_F(BufferQueueProducerTest, SetTunnelHandleRemote002, TestSize.Level0)
365 {
366 system("mount -o remount, rw /");
367 system("mkdir -p /data/SurfaceTestTmp");
368 system("touch /data/SurfaceTestTmp/test.txt");
369 int32_t fd = -1;
370 {
371 sptr<BufferQueueProducer> tmpBufferQueueProducer = nullptr;
372 sptr<BufferQueue> tmpBufferQueue = nullptr;
373 tmpBufferQueue = new BufferQueue("SetTunnelHandleRemoteTest");
374 sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
375 tmpBufferQueue->RegisterConsumerListener(listener);
376 if (tmpBufferQueueProducer == nullptr) {
377 tmpBufferQueueProducer = new BufferQueueProducer(tmpBufferQueue);
378 }
379
380 GraphicExtDataHandle *handle =
381 static_cast<GraphicExtDataHandle *>(malloc(sizeof(GraphicExtDataHandle) + sizeof(int32_t) * 1));
382 EXPECT_NE(handle, nullptr);
383 if (handle) {
384 MessageParcel arguments, reply;
385 MessageOption option;
386 std::string testPath = "/data/SurfaceTestTmp/test.txt";
387 errno = 0; // reset errno
388 fd = open(testPath.c_str(), O_RDONLY);
389 EXPECT_GE(fd, 0);
390 handle->fd = fd;
391 handle->reserveInts = 1;
392 handle->reserve[0] = 0;
393 EXPECT_EQ(arguments.WriteBool(true), true);
394 EXPECT_EQ(WriteExtDataHandle(arguments, handle), GSERROR_OK);
395 EXPECT_EQ(tmpBufferQueueProducer->SetTunnelHandleRemote(arguments, reply, option), ERR_NONE);
396 free(handle);
397 handle = nullptr;
398 }
399 }
400
401 /* tmpBufferQueueProducer and tmpBufferQueue has been destructed,
402 * and the fd dup by WriteExtDataHandle has been closed.
403 * so the global variable errno is expected to be 0.
404 */
405 EXPECT_EQ(errno, 0);
406
407 if (fd > 0) {
408 EXPECT_EQ(close(fd), 0);
409 }
410 system("rm -rf /data/SurfaceTestTmp");
411 }
412
413 /*
414 * Function: GetPresentTimestampRemote
415 * Type: Function
416 * Rank: Important(2)
417 * EnvConditions: N/A
418 * CaseDescription: 1. call GetPresentTimestampRemote
419 * 4. check ret
420 */
421 HWTEST_F(BufferQueueProducerTest, GetPresentTimestampRemote, TestSize.Level0)
422 {
423 MessageParcel arguments;
424 arguments.WriteInt32(5);
425 MessageParcel reply;
426 reply.WriteInt32(6);
427 MessageOption option;
428 int32_t ret = bqp_->GetPresentTimestampRemote(arguments, reply, option);
429 EXPECT_EQ(ret, ERR_NONE);
430 }
431
432 /*
433 * Function: SetSurfaceSourceType and GetSurfaceSourceType
434 * Type: Function
435 * Rank: Important(2)
436 * EnvConditions: N/A
437 * CaseDescription: 1. call GetSurfaceSourceType for default
438 * 2. call SetSurfaceSourceType and check the ret
439 */
440 HWTEST_F(BufferQueueProducerTest, SurfaceSourceType001, TestSize.Level0)
441 {
442 OHSurfaceSource sourceType;
443 GSError ret = bqp_->GetSurfaceSourceType(sourceType);
444 ASSERT_EQ(ret, OHOS::GSERROR_OK);
445 ASSERT_EQ(sourceType, OH_SURFACE_SOURCE_DEFAULT);
446
447 ret = bqp_->SetSurfaceSourceType(OH_SURFACE_SOURCE_VIDEO);
448 ASSERT_EQ(ret, OHOS::GSERROR_OK);
449 bqp_->GetSurfaceSourceType(sourceType);
450 ASSERT_EQ(sourceType, OH_SURFACE_SOURCE_VIDEO);
451 }
452
453 /*
454 * Function: SetSurfaceAppFrameworkType and GetSurfaceAppFrameworkType
455 * Type: Function
456 * Rank: Important(2)
457 * EnvConditions: N/A
458 * CaseDescription: 1. call GetSurfaceAppFrameworkType for default
459 * 2. call SetSurfaceAppFrameworkType and check the ret
460 */
461 HWTEST_F(BufferQueueProducerTest, SurfaceAppFrameworkType001, TestSize.Level0)
462 {
463 std::string appFrameworkType;
464 bqp_->GetSurfaceAppFrameworkType(appFrameworkType);
465 ASSERT_EQ(appFrameworkType, "");
466
467 GSError ret = bqp_->SetSurfaceAppFrameworkType("test");
468 ASSERT_EQ(ret, OHOS::GSERROR_OK);
469 bqp_->GetSurfaceAppFrameworkType(appFrameworkType);
470 ASSERT_EQ(appFrameworkType, "test");
471 }
472
473 /*
474 * Function: SetSurfaceSourceTypeRemote
475 * Type: Function
476 * Rank: Important(2)
477 * EnvConditions: N/A
478 * CaseDescription: 1. call SetSurfaceSourceTypeRemote
479 * 4. check ret
480 */
481 HWTEST_F(BufferQueueProducerTest, SetSurfaceSourceTypeRemote001, TestSize.Level0)
482 {
483 MessageParcel arguments;
484 arguments.WriteInt32(1);
485 MessageParcel reply;
486 reply.WriteInt32(6);
487 MessageOption option;
488 int32_t ret = bqp_->SetSurfaceSourceTypeRemote(arguments, reply, option);
489 EXPECT_EQ(ret, ERR_NONE);
490 }
491
492 /*
493 * Function: GetSurfaceSourceTypeRemote
494 * Type: Function
495 * Rank: Important(2)
496 * EnvConditions: N/A
497 * CaseDescription: 1. call GetSurfaceSourceTypeRemote
498 * 4. check ret
499 */
500 HWTEST_F(BufferQueueProducerTest, GetSurfaceSourceTypeRemote001, TestSize.Level0)
501 {
502 MessageParcel arguments;
503 arguments.WriteInt32(5);
504 MessageParcel reply;
505 reply.WriteInt32(6);
506 MessageOption option;
507 int32_t ret = bqp_->GetSurfaceSourceTypeRemote(arguments, reply, option);
508 EXPECT_EQ(ret, ERR_NONE);
509 }
510
511 /*
512 * Function: SetSurfaceAppFrameworkTypeRemote
513 * Type: Function
514 * Rank: Important(2)
515 * EnvConditions: N/A
516 * CaseDescription: 1. call SetSurfaceAppFrameworkTypeRemote
517 * 4. check ret
518 */
519 HWTEST_F(BufferQueueProducerTest, SetSurfaceAppFrameworkTypeRemote001, TestSize.Level0)
520 {
521 MessageParcel arguments;
522 arguments.WriteString("test");
523 MessageParcel reply;
524 reply.WriteInt32(6);
525 MessageOption option;
526 int32_t ret = bqp_->SetSurfaceAppFrameworkTypeRemote(arguments, reply, option);
527 EXPECT_EQ(ret, ERR_NONE);
528 }
529
530 /*
531 * Function: GetSurfaceAppFrameworkTypeRemote
532 * Type: Function
533 * Rank: Important(2)
534 * EnvConditions: N/A
535 * CaseDescription: 1. call GetSurfaceAppFrameworkTypeRemote
536 * 4. check ret
537 */
538 HWTEST_F(BufferQueueProducerTest, GetSurfaceAppFrameworkTypeRemote001, TestSize.Level0)
539 {
540 MessageParcel arguments;
541 arguments.WriteInt32(5);
542 MessageParcel reply;
543 reply.WriteInt32(6);
544 MessageOption option;
545 int32_t ret = bqp_->GetSurfaceAppFrameworkTypeRemote(arguments, reply, option);
546 EXPECT_EQ(ret, ERR_NONE);
547 }
548
549 /*
550 * Function: SetWhitePointBrightness
551 * Type: Function
552 * Rank: Important(2)
553 * EnvConditions: N/A
554 * CaseDescription: 1. call SetHdrWhitePointBrightness, SetSdrWhitePointBrightness
555 * 2. check ret
556 */
557 HWTEST_F(BufferQueueProducerTest, SetWhitePointBrightness001, TestSize.Level0)
558 {
559 MessageParcel arguments;
560 arguments.WriteFloat(1);
561 MessageParcel reply;
562 MessageOption option;
563 int32_t ret = bqp_->SetHdrWhitePointBrightnessRemote(arguments, reply, option);
564 EXPECT_EQ(ret, ERR_NONE);
565 ret = bqp_->SetSdrWhitePointBrightnessRemote(arguments, reply, option);
566 EXPECT_EQ(ret, ERR_NONE);
567 }
568
569 /*
570 * Function: SetDefaultUsage
571 * Type: Function
572 * Rank: Important(2)
573 * EnvConditions: N/A
574 * CaseDescription: 1. call SetDefaultUsage
575 * 2. check ret
576 */
577 HWTEST_F(BufferQueueProducerTest, SetDefaultUsage001, TestSize.Level0)
578 {
579 MessageParcel arguments;
580 arguments.WriteUint64(0);
581 MessageParcel reply;
582 MessageOption option;
583 int32_t ret = bqp_->SetDefaultUsageRemote(arguments, reply, option);
584 EXPECT_EQ(ret, ERR_NONE);
585 }
586
587 /*
588 * Function: SetBufferHold
589 * Type: Function
590 * Rank: Important(2)
591 * EnvConditions: N/A
592 * CaseDescription: 1. call SetBufferHold
593 * 2. check ret
594 */
595 HWTEST_F(BufferQueueProducerTest, SetBufferHold001, TestSize.Level0)
596 {
597 MessageParcel arguments;
598 arguments.WriteBool(false);
599 MessageParcel reply;
600 MessageOption option;
601 int32_t ret = bqp_->SetBufferHoldRemote(arguments, reply, option);
602 EXPECT_EQ(ret, ERR_NONE);
603 }
604
605 /*
606 * Function: SetBufferReallocFlag
607 * Type: Function
608 * Rank: Important(2)
609 * EnvConditions: N/A
610 * CaseDescription: 1. call SetBufferReallocFlag
611 * 2. check ret
612 */
613 HWTEST_F(BufferQueueProducerTest, SetBufferReallocFlag001, TestSize.Level0)
614 {
615 MessageParcel arguments;
616 arguments.WriteBool(false);
617 MessageParcel reply;
618 MessageOption option;
619 int32_t ret = bqp_->SetBufferReallocFlagRemote(arguments, reply, option);
620 EXPECT_EQ(ret, ERR_NONE);
621 }
622
623 /*
624 * Function: TransformHint
625 * Type: Function
626 * Rank: Important(2)
627 * EnvConditions: N/A
628 * CaseDescription: 1. call TransformHint
629 * 2. check ret
630 */
631 HWTEST_F(BufferQueueProducerTest, TransformHint001, TestSize.Level0)
632 {
633 GraphicTransformType transform = GraphicTransformType::GRAPHIC_FLIP_H;
634
635 MessageParcel arguments;
636 arguments.WriteUint32(transform);
637 MessageParcel reply;
638 MessageOption option;
639 int32_t ret = bqp_->SetBufferHoldRemote(arguments, reply, option);
640 EXPECT_EQ(ret, ERR_NONE);
641 int32_t err = reply.ReadInt32();
642 EXPECT_EQ(err, OHOS::GSERROR_OK);
643
644 ret = bqp_->GetTransformHintRemote(arguments, reply, option);
645 EXPECT_EQ(ret, ERR_NONE);
646 err = reply.ReadInt32();
647 EXPECT_EQ(err, OHOS::GSERROR_OK);
648 }
649
650
651 /*
652 * Function: BufferQueueProducer member function nullptr test
653 * Type: Function
654 * Rank: Important(2)
655 * EnvConditions: N/A
656 * CaseDescription: BufferQueueProducer member function nullptr test
657 */
658 HWTEST_F(BufferQueueProducerTest, NullTest, TestSize.Level0)
659 {
660 sptr<BufferQueue> bqTmp = nullptr;
661 sptr<BufferQueueProducer> bqpTmp = new BufferQueueProducer(bqTmp);
662 IBufferProducer::RequestBufferReturnValue retval;
663 GSError ret = bqpTmp->RequestBuffer(requestConfig, bedata_, retval);
664 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
665 ret = bqpTmp->RequestAndDetachBuffer(requestConfig, bedata_, retval);
666 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
667 ret = bqpTmp->CancelBuffer(retval.sequence, bedata_);
668 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
669 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
670 ret = bqpTmp->FlushBuffer(retval.sequence, bedata_, acquireFence, flushConfig);
671 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
672 ret = bqpTmp->AttachAndFlushBuffer(retval.buffer, bedata_, acquireFence, flushConfig, true);
673 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
674 ret = bqpTmp->GetLastFlushedBuffer(retval.buffer, acquireFence, nullptr, false);
675 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
676 EXPECT_EQ(bqpTmp->AttachBuffer(retval.buffer), OHOS::GSERROR_INVALID_ARGUMENTS);
677 EXPECT_EQ(bqpTmp->DetachBuffer(retval.buffer), OHOS::GSERROR_INVALID_ARGUMENTS);
678 EXPECT_EQ(bqpTmp->GetQueueSize(), 0);
679 EXPECT_EQ(bqpTmp->SetQueueSize(0), OHOS::GSERROR_INVALID_ARGUMENTS);
680 std::string name = "test";
681 EXPECT_EQ(bqpTmp->GetName(name), OHOS::GSERROR_INVALID_ARGUMENTS);
682 EXPECT_EQ(bqpTmp->GetDefaultWidth(), 0);
683 EXPECT_EQ(bqpTmp->GetDefaultHeight(), 0);
684 EXPECT_EQ(bqpTmp->GetDefaultUsage(), 0);
685 EXPECT_EQ(bqpTmp->GetUniqueId(), 0);
686 sptr<IProducerListener> listener = nullptr;
687 EXPECT_EQ(bqpTmp->RegisterReleaseListener(listener), OHOS::GSERROR_INVALID_ARGUMENTS);
688 EXPECT_EQ(bqpTmp->RegisterReleaseListenerBackup(listener), OHOS::GSERROR_INVALID_ARGUMENTS);
689 EXPECT_EQ(bqpTmp->UnRegisterReleaseListener(), OHOS::GSERROR_INVALID_ARGUMENTS);
690 EXPECT_EQ(bqpTmp->UnRegisterReleaseListenerBackup(), OHOS::GSERROR_INVALID_ARGUMENTS);
691 EXPECT_EQ(bqpTmp->SetTransform(GraphicTransformType::GRAPHIC_FLIP_H), OHOS::GSERROR_INVALID_ARGUMENTS);
692 std::vector<BufferVerifyAllocInfo> infos;
693 uint64_t uniqueId;
694 EXPECT_EQ(bqpTmp->GetNameAndUniqueId(name, uniqueId), OHOS::GSERROR_INVALID_ARGUMENTS);
695 EXPECT_EQ(bqpTmp->Disconnect(nullptr), OHOS::SURFACE_ERROR_UNKOWN);
696 EXPECT_EQ(bqpTmp->SetScalingMode(0, ScalingMode::SCALING_MODE_FREEZE), OHOS::GSERROR_INVALID_ARGUMENTS);
697 EXPECT_EQ(bqpTmp->SetScalingMode(ScalingMode::SCALING_MODE_FREEZE), OHOS::GSERROR_INVALID_ARGUMENTS);
698 std::vector<GraphicHDRMetaData> meta;
699 EXPECT_EQ(bqpTmp->SetMetaData(0, meta), OHOS::GSERROR_INVALID_ARGUMENTS);
700 std::vector<uint8_t> metaData;
701 EXPECT_EQ(bqpTmp->SetMetaDataSet(0, GraphicHDRMetadataKey::GRAPHIC_MATAKEY_BLUE_PRIMARY_X,
702 metaData), OHOS::GSERROR_INVALID_ARGUMENTS);
703 sptr<SurfaceTunnelHandle> handle = nullptr;
704 EXPECT_EQ(bqpTmp->SetTunnelHandle(handle), OHOS::GSERROR_INVALID_ARGUMENTS);
705 int64_t time = 0;
706 EXPECT_EQ(bqpTmp->GetPresentTimestamp(0, GraphicPresentTimestampType::GRAPHIC_DISPLAY_PTS_DELAY,
707 time), OHOS::GSERROR_INVALID_ARGUMENTS);
708 EXPECT_EQ(bqpTmp->GetStatus(), false);
709 bqpTmp->SetStatus(false);
710 EXPECT_EQ(bqpTmp->AcquireLastFlushedBuffer(retval.buffer, acquireFence, nullptr, 0, false),
711 OHOS::SURFACE_ERROR_UNKOWN);
712 EXPECT_EQ(bqpTmp->ReleaseLastFlushedBuffer(0), OHOS::SURFACE_ERROR_UNKOWN);
713 bqpTmp->OnBufferProducerRemoteDied();
714 EXPECT_EQ(bqpTmp->SetBufferHold(false), OHOS::GSERROR_INVALID_ARGUMENTS);
715 EXPECT_EQ(bqpTmp->SetBufferReallocFlag(false), OHOS::GSERROR_INVALID_ARGUMENTS);
716 EXPECT_EQ(bqpTmp->SetSdrWhitePointBrightness(1), OHOS::SURFACE_ERROR_UNKOWN);
717 EXPECT_EQ(bqpTmp->SetHdrWhitePointBrightness(1), OHOS::SURFACE_ERROR_UNKOWN);
718 EXPECT_EQ(bqpTmp->SetSurfaceAppFrameworkType(name), OHOS::GSERROR_INVALID_ARGUMENTS);
719 EXPECT_EQ(bqpTmp->GetSurfaceAppFrameworkType(name), OHOS::GSERROR_INVALID_ARGUMENTS);
720 OHSurfaceSource sourceType = OH_SURFACE_SOURCE_DEFAULT;
721 EXPECT_EQ(bqpTmp->SetSurfaceSourceType(sourceType), OHOS::GSERROR_INVALID_ARGUMENTS);
722 EXPECT_EQ(bqpTmp->GetSurfaceSourceType(sourceType), OHOS::GSERROR_INVALID_ARGUMENTS);
723 GraphicTransformType transform = GraphicTransformType::GRAPHIC_FLIP_H;
724 EXPECT_EQ(bqpTmp->SetTransformHint(transform, 0), OHOS::GSERROR_INVALID_ARGUMENTS);
725 EXPECT_EQ(bqpTmp->GetTransformHint(transform), OHOS::GSERROR_INVALID_ARGUMENTS);
726 EXPECT_EQ(bqpTmp->GoBackground(), OHOS::GSERROR_INVALID_ARGUMENTS);
727 EXPECT_EQ(bqpTmp->CleanCache(true, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
728 EXPECT_EQ(bqpTmp->SetDefaultUsage(0), OHOS::GSERROR_INVALID_ARGUMENTS);
729 EXPECT_EQ(bqpTmp->AttachBufferToQueue(nullptr), OHOS::SURFACE_ERROR_UNKOWN);
730 EXPECT_EQ(bqpTmp->DetachBufferFromQueue(nullptr), OHOS::SURFACE_ERROR_UNKOWN);
731 ProducerInitInfo info;
732 EXPECT_EQ(bqpTmp->GetProducerInitInfo(info), OHOS::SURFACE_ERROR_UNKOWN);
733 vector<uint32_t> sequences;
734 vector<sptr<SyncFence>> fences;
735 vector<sptr<BufferExtraData>> bedata;
736 vector<BufferFlushConfigWithDamages> damages;
737 vector<BufferQueueProducer::RequestBufferReturnValue> retvalues;
738 BufferRequestConfig config;
739 EXPECT_EQ(bqpTmp->RequestBuffers(config, bedata, retvalues), OHOS::SURFACE_ERROR_UNKOWN);
740 EXPECT_EQ(bqpTmp->FlushBuffers(sequences, bedata, fences, damages), OHOS::SURFACE_ERROR_UNKOWN);
741 EXPECT_EQ(bqpTmp->SetGlobalAlpha(-1), OHOS::SURFACE_ERROR_UNKOWN);
742 EXPECT_EQ(bqpTmp->SetFrameGravity(-1), OHOS::SURFACE_ERROR_UNKOWN);
743 EXPECT_EQ(bqpTmp->SetFixedRotation(-1), OHOS::SURFACE_ERROR_UNKOWN);
744 EXPECT_EQ(bqpTmp->PreAllocBuffers(config, 0), OHOS::SURFACE_ERROR_UNKOWN);
745 EXPECT_EQ(bqpTmp->SetRequestBufferNoblockMode(true), OHOS::SURFACE_ERROR_UNKOWN);
746 EXPECT_EQ(bqpTmp->SetAlphaType(GraphicAlphaType::GRAPHIC_ALPHATYPE_UNKNOWN), OHOS::SURFACE_ERROR_UNKOWN);
747 bqTmp = nullptr;
748 bqpTmp = nullptr;
749 }
750
751 /*
752 * Function: SetRequestBufferNoblockMode
753 * Type: Function
754 * Rank: Important(2)
755 * EnvConditions: N/A
756 * CaseDescription: 1. call SetRequestBufferNoblockMode
757 * 2. check ret
758 */
759 HWTEST_F(BufferQueueProducerTest, SetRequestBufferNoblockMode, TestSize.Level0)
760 {
761 ASSERT_EQ(bqp_->SetRequestBufferNoblockMode(true), OHOS::GSERROR_OK);
762 bool noblockMode = false;
763 ASSERT_EQ(bq_->GetRequestBufferNoblockMode(noblockMode), OHOS::GSERROR_OK);
764 ASSERT_EQ(noblockMode, true);
765
766 ASSERT_EQ(bqp_->SetRequestBufferNoblockMode(false), OHOS::GSERROR_OK);
767 ASSERT_EQ(bq_->GetRequestBufferNoblockMode(noblockMode), OHOS::GSERROR_OK);
768 ASSERT_EQ(noblockMode, false);
769 }
770
771 /*
772 * Function: SetRequestBufferNoblockModeRemote
773 * Type: Function
774 * Rank: Important(2)
775 * EnvConditions: N/A
776 * CaseDescription: 1. call SetRequestBufferNoblockModeRemote
777 * 2. check ret
778 */
779 HWTEST_F(BufferQueueProducerTest, SetRequestBufferNoblockModeRemote, TestSize.Level0)
780 {
781 MessageParcel arguments;
782 arguments.WriteBool(false);
783 MessageParcel reply;
784 MessageOption option;
785 int32_t ret = bqp_->SetRequestBufferNoblockModeRemote(arguments, reply, option);
786 EXPECT_EQ(ret, ERR_NONE);
787 }
788
789 /*
790 * Function: CheckIsAliveTest
791 * Type: Function
792 * Rank: Important(2)
793 * EnvConditions: N/A
794 * CaseDescription: CheckIsAliveTest member function test
795 */
796 HWTEST_F(BufferQueueProducerTest, CheckIsAliveTest, TestSize.Level0)
797 {
798 bqp_->magicNum_ = 0;
799 EXPECT_EQ(bqp_->CheckIsAlive(), false);
800 bqp_->magicNum_ = BufferQueueProducer::MAGIC_INIT;
801 EXPECT_EQ(bqp_->CheckIsAlive(), true);
802 }
803
804 /*
805 * Function: UnRegisterPropertyListener
806 * Type: Function
807 * Rank: Important(2)
808 * EnvConditions: N/A
809 * CaseDescription: UnRegisterPropertyListener member function test
810 */
811 HWTEST_F(BufferQueueProducerTest, UnRegisterPropertyListenerTest, TestSize.Level0)
812 {
813 sptr<BufferQueue> bqtmp = nullptr;
814 sptr<BufferQueueProducer> bqptmp = new BufferQueueProducer(bqtmp);
815 EXPECT_EQ(bqptmp->UnRegisterPropertyListener(0), OHOS::GSERROR_INVALID_ARGUMENTS);
816 }
817
818 /*
819 * Function: RegisterPropertyListener
820 * Type: Function
821 * Rank: Important(2)
822 * EnvConditions: N/A
823 * CaseDescription: RegisterPropertyListener member function test
824 */
825 HWTEST_F(BufferQueueProducerTest, RegisterPropertyListenerTest, TestSize.Level0)
826 {
827 sptr<IProducerListener> listener = nullptr;
828 sptr<BufferQueue> bqtmp = nullptr;
829 sptr<BufferQueueProducer> bqptmp = new BufferQueueProducer(bqtmp);
830 EXPECT_EQ(bqptmp->RegisterPropertyListener(listener, 0), OHOS::GSERROR_INVALID_ARGUMENTS);
831 }
832
833 /*
834 * Function: RegisterPropertyListenerRemote
835 * Type: Function
836 * Rank: Important(2)
837 * EnvConditions: N/A
838 * CaseDescription: RegisterPropertyListenerRemote member function test
839 */
840 HWTEST_F(BufferQueueProducerTest, RegisterPropertyListenerRemote001, TestSize.Level0)
841 {
842 MessageParcel arguments;
843 arguments.WriteBool(false);
844 MessageParcel reply;
845 MessageOption option;
846 int32_t ret = bqp_->RegisterPropertyListenerRemote(arguments, reply, option);
847 EXPECT_EQ(ret, ERR_INVALID_REPLY);
848 }
849
850 /*
851 * Function: UnRegisterPropertyListenerRemote
852 * Type: Function
853 * Rank: Important(2)
854 * EnvConditions: N/A
855 * CaseDescription: UnRegisterPropertyListenerRemote member function test
856 */
857 HWTEST_F(BufferQueueProducerTest, UnRegisterPropertyListenerRemote001, TestSize.Level0)
858 {
859 MessageParcel arguments;
860 arguments.WriteInt64(0);
861 MessageParcel reply;
862 MessageOption option;
863 int32_t ret = bqp_->UnRegisterPropertyListenerRemote(arguments, reply, option);
864 EXPECT_EQ(ret, ERR_NONE);
865 }
866
867 /*
868 * Function: GetProducerInitInfoRemote
869 * Type: Function
870 * Rank: Important(2)
871 * EnvConditions: N/A
872 * CaseDescription: GetProducerInitInfoRemote member function test
873 */
874 HWTEST_F(BufferQueueProducerTest, GetProducerInitInfoRemote001, TestSize.Level0)
875 {
876 MessageParcel arguments;
877 arguments.WriteBool(false);
878 MessageParcel reply;
879 MessageOption option;
880 int32_t ret = bqp_->GetProducerInitInfoRemote(arguments, reply, option);
881 EXPECT_EQ(ret, ERR_INVALID_DATA);
882 }
883 /*
884 * Function: SetLppShareFdRemote
885 * Type: Function
886 * Rank: Important(2)
887 * EnvConditions: N/A
888 * CaseDescription: SetLppShareFdRemote member function test
889 */
890 HWTEST_F(BufferQueueProducerTest, SetLppShareFdRemote001, TestSize.Level0)
891 {
892 int fd = -1;
893 bool state = false;
894 MessageParcel arguments;
895 arguments.WriteFileDescriptor(fd);
896 arguments.WriteBool(state);
897 MessageParcel reply;
898 MessageOption option;
899 int32_t ret = bqp_->SetLppShareFdRemote(arguments, reply, option);
900 EXPECT_EQ(ret, ERR_INVALID_VALUE);
901 }
902 /*
903 * Function: SetLppShareFdRemote
904 * Type: Function
905 * Rank: Important(2)
906 * EnvConditions: N/A
907 * CaseDescription: SetLppShareFdRemote member function test
908 */
909 HWTEST_F(BufferQueueProducerTest, SetLppShareFdRemote002, TestSize.Level0)
910 {
911 int fd = open("/dev/lpptest", O_RDWR | O_CREAT, static_cast<mode_t>(0600));
912 ASSERT_NE(fd, -1);
913 ASSERT_NE(ftruncate(fd, 0x1000), -1);
914 bool state = false;
915 MessageParcel arguments;
916 arguments.WriteFileDescriptor(fd);
917 arguments.WriteBool(state);
918 MessageParcel reply;
919 MessageOption option;
920 int32_t ret = bqp_->SetLppShareFdRemote(arguments, reply, option);
921 EXPECT_EQ(ret, ERR_NONE);
922 }
923 /*
924 * Function: SetLppShareFd
925 * Type: Function
926 * Rank: Important(2)
927 * EnvConditions: N/A
928 * CaseDescription: SetLppShareFd member function test
929 */
930 HWTEST_F(BufferQueueProducerTest, SetLppShareFd001, TestSize.Level0)
931 {
932 int fd = -1;
933 bool state = false;
934 sptr<BufferQueue> bqtmp = nullptr;
935 sptr<BufferQueueProducer> bqptmp = new BufferQueueProducer(bqtmp);
936 bqptmp->bufferQueue_ = nullptr;
937 int ret = bqptmp->SetLppShareFd(fd, state);
938 ASSERT_EQ(ret, SURFACE_ERROR_UNKOWN);
939 }
940
941 /*
942 * Function: SetLppShareFd
943 * Type: Function
944 * Rank: Important(2)
945 * EnvConditions: N/A
946 * CaseDescription: SetLppShareFd member function test
947 */
948 HWTEST_F(BufferQueueProducerTest, SetLppShareFd002, TestSize.Level0)
949 {
950 int fd = -1;
951 bool state = false;
952 sptr<BufferQueue> bqtmp = new BufferQueue("test");
953 sptr<BufferQueueProducer> bqptmp = new BufferQueueProducer(bqtmp);
954 int ret = bqptmp->SetLppShareFd(fd, state);
955 ASSERT_EQ(ret, GSERROR_OK);
956 }
957
958 /*
959 * Function: SetAlphaTypeRemote
960 * Type: Function
961 * Rank: Important(2)
962 * EnvConditions: N/A
963 * CaseDescription: call SetAlphaTypeRemote
964 */
965 HWTEST_F(BufferQueueProducerTest, SetAlphaTypeRemote, TestSize.Level0)
966 {
967 MessageParcel arguments;
968 arguments.WriteInt32(1);
969 MessageParcel reply;
970 reply.WriteInt32(2);
971 MessageOption option;
972 int32_t ret = bqp_->SetAlphaTypeRemote(arguments, reply, option);
973 EXPECT_EQ(ret, ERR_NONE);
974 }
975
976 /*
977 * Function: SetAlphaType
978 * Type: Function
979 * Rank: Important(2)
980 * EnvConditions: N/A
981 * CaseDescription: SetAlphaType member function test
982 */
983 HWTEST_F(BufferQueueProducerTest, SetAlphaTypeTest, TestSize.Level0)
984 {
985 GraphicAlphaType alphaType = GraphicAlphaType::GRAPHIC_ALPHATYPE_OPAQUE;
986 sptr<BufferQueue> bqtmp = new BufferQueue("test");
987 sptr<BufferQueueProducer> bqptmp = new BufferQueueProducer(bqtmp);
988 int ret = bqptmp->SetAlphaType(alphaType);
989 ASSERT_EQ(ret, GSERROR_OK);
990 }
991 }
992