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 <map>
16 #include <gtest/gtest.h>
17 #include <surface.h>
18 #include <buffer_extra_data_impl.h>
19 #include <buffer_queue.h>
20 #include <buffer_producer_listener.h>
21 #include "buffer_consumer_listener.h"
22 #include "sync_fence.h"
23 #include "consumer_surface.h"
24 #include "producer_surface_delegator.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS::Rosen {
30 class BufferQueueTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34
35 static inline BufferRequestConfig requestConfig = {
36 .width = 0x100,
37 .height = 0x100,
38 .strideAlignment = 0x8,
39 .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
40 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
41 .timeout = 0,
42 };
43 static inline BufferFlushConfigWithDamages flushConfig = {
44 .damages = {
45 {
46 .w = 0x100,
47 .h = 0x100,
48 }
49 },
50 };
51 static inline int64_t timestamp = 0;
52 static inline std::vector<Rect> damages = {};
53 static inline sptr<BufferQueue> bq = nullptr;
54 static inline std::map<int32_t, sptr<SurfaceBuffer>> cache;
55 static inline sptr<BufferExtraData> bedata = nullptr;
56 static inline sptr<ProducerSurfaceDelegator> surfaceDelegator = nullptr;
57 static inline sptr<IConsumerSurface> csurface1 = nullptr;
58 };
59
SetUpTestCase()60 void BufferQueueTest::SetUpTestCase()
61 {
62 bq = new BufferQueue("test");
63 sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
64 bq->RegisterConsumerListener(listener);
65 bedata = new OHOS::BufferExtraDataImpl;
66 csurface1 = IConsumerSurface::Create();
67 }
68
TearDownTestCase()69 void BufferQueueTest::TearDownTestCase()
70 {
71 bq = nullptr;
72 }
73
74 /*
75 * Function: GetUsedSize
76 * Type: Function
77 * Rank: Important(2)
78 * EnvConditions: N/A
79 * CaseDescription: 1. call GetUsedSize and check ret
80 */
81 HWTEST_F(BufferQueueTest, GetUsedSize001, Function | MediumTest | Level2)
82 {
83 uint32_t usedSize = bq->GetUsedSize();
84 ASSERT_NE(usedSize, -1);
85 }
86
87 /*
88 * Function: SetQueueSize and GetQueueSize
89 * Type: Function
90 * Rank: Important(2)
91 * EnvConditions: N/A
92 * CaseDescription: 1. call GetQueueSize for default
93 * 2. call SetQueueSize
94 * 3. call SetQueueSize again with abnormal input
95 * 4. check ret and call GetQueueSize
96 */
97 HWTEST_F(BufferQueueTest, QueueSize001, Function | MediumTest | Level2)
98 {
99 ASSERT_EQ(bq->GetQueueSize(), (uint32_t)SURFACE_DEFAULT_QUEUE_SIZE);
100
101 GSError ret = bq->SetQueueSize(2);
102 ASSERT_EQ(ret, OHOS::GSERROR_OK);
103
104 ret = bq->SetQueueSize(SURFACE_MAX_QUEUE_SIZE + 1);
105 ASSERT_NE(ret, OHOS::GSERROR_OK);
106
107 ASSERT_EQ(bq->GetQueueSize(), 2u);
108 BufferQueue *bqTmp = new BufferQueue("testTmp");
109 EXPECT_EQ(bqTmp->SetQueueSize(1), GSERROR_OK);
110 bqTmp = nullptr;
111 }
112
113 /*
114 * Function: SetQueueSize and GetQueueSize
115 * Type: Function
116 * Rank: Important(2)
117 * EnvConditions: N/A
118 * CaseDescription: 1. call SetQueueSize 2 times both with abnormal input
119 * 2. call GetQueueSize
120 * 3. check ret
121 */
122 HWTEST_F(BufferQueueTest, QueueSize002, Function | MediumTest | Level2)
123 {
124 GSError ret = bq->SetQueueSize(-1);
125 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
126 ASSERT_EQ(bq->GetQueueSize(), 2u);
127
128 ret = bq->SetQueueSize(0);
129 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
130 ASSERT_EQ(bq->GetQueueSize(), 2u);
131 }
132
133 /*
134 * Function: RequestBuffer, FlushBuffer, AcquireBuffer and ReleaseBuffer
135 * Type: Function
136 * Rank: Important(2)
137 * EnvConditions: N/A
138 * CaseDescription: 1. call RequestBuffer and FlushBuffer
139 * 2. call AcquireBuffer and ReleaseBuffer
140 * 3. check ret
141 */
142 HWTEST_F(BufferQueueTest, ReqCanFluAcqRel001, Function | MediumTest | Level2)
143 {
144 IBufferProducer::RequestBufferReturnValue retval;
145
146 // first request
147 GSError ret = bq->RequestBuffer(requestConfig, bedata, retval);
148 ASSERT_EQ(ret, OHOS::GSERROR_OK);
149 ASSERT_NE(retval.buffer, nullptr);
150 ASSERT_GE(retval.sequence, 0);
151
152 // add cache
153 cache[retval.sequence] = retval.buffer;
154
155 // buffer queue will map
156 uint8_t *addr1 = reinterpret_cast<uint8_t*>(retval.buffer->GetVirAddr());
157 ASSERT_NE(addr1, nullptr);
158 addr1[0] = 5;
159
160 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
161 ret = bq->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
162 ASSERT_EQ(ret, OHOS::GSERROR_OK);
163
164 ret = bq->AcquireBuffer(retval.buffer, retval.fence, timestamp, damages);
165 ASSERT_EQ(ret, OHOS::GSERROR_OK);
166 ASSERT_NE(retval.buffer, nullptr);
167
168 uint8_t *addr2 = reinterpret_cast<uint8_t*>(retval.buffer->GetVirAddr());
169 ASSERT_NE(addr2, nullptr);
170 if (addr2 != nullptr) {
171 ASSERT_EQ(addr2[0], 5u);
172 }
173
174 sptr<SyncFence> releaseFence = SyncFence::INVALID_FENCE;
175 ret = bq->ReleaseBuffer(retval.buffer, releaseFence);
176 ASSERT_EQ(ret, OHOS::GSERROR_OK);
177 }
178
179 /*
180 * Function: RequestBuffer and CancelBuffer
181 * Type: Function
182 * Rank: Important(2)
183 * EnvConditions: N/A
184 * CaseDescription: 1. call RequestBuffer
185 * 2. call CancelBuffer
186 * 3. check ret
187 */
188 HWTEST_F(BufferQueueTest, ReqCanFluAcqRel002, Function | MediumTest | Level2)
189 {
190 IBufferProducer::RequestBufferReturnValue retval;
191
192 // not first request
193 GSError ret = bq->RequestBuffer(requestConfig, bedata, retval);
194 ASSERT_EQ(ret, OHOS::GSERROR_OK);
195 ASSERT_GE(retval.sequence, 0);
196 ASSERT_EQ(retval.buffer, nullptr);
197
198 ret = bq->CancelBuffer(retval.sequence, bedata);
199 ASSERT_EQ(ret, OHOS::GSERROR_OK);
200 }
201
202 /*
203 * Function: RequestBuffer and CancelBuffer
204 * Type: Function
205 * Rank: Important(2)
206 * EnvConditions: N/A
207 * CaseDescription: 1. call RequestBuffer
208 * 2. call CancelBuffer 2 times
209 * 3. check ret
210 */
211 HWTEST_F(BufferQueueTest, ReqCanFluAcqRel003, Function | MediumTest | Level2)
212 {
213 IBufferProducer::RequestBufferReturnValue retval;
214
215 // not first request
216 GSError ret = bq->RequestBuffer(requestConfig, bedata, retval);
217 ASSERT_EQ(ret, OHOS::GSERROR_OK);
218 ASSERT_GE(retval.sequence, 0);
219 ASSERT_EQ(retval.buffer, nullptr);
220
221 ret = bq->CancelBuffer(retval.sequence, bedata);
222 ASSERT_EQ(ret, OHOS::GSERROR_OK);
223
224 ret = bq->CancelBuffer(retval.sequence, bedata);
225 ASSERT_NE(ret, OHOS::GSERROR_OK);
226 }
227
228 /*
229 * Function: RequestBuffer and FlushBuffer
230 * Type: Function
231 * Rank: Important(2)
232 * EnvConditions: N/A
233 * CaseDescription: 1. call RequestBuffer
234 * 2. call FlushBuffer 2 times
235 * 3. check ret
236 */
237 HWTEST_F(BufferQueueTest, ReqCanFluAcqRel004, Function | MediumTest | Level2)
238 {
239 IBufferProducer::RequestBufferReturnValue retval;
240
241 // not first request
242 GSError ret = bq->RequestBuffer(requestConfig, bedata, retval);
243 ASSERT_EQ(ret, OHOS::GSERROR_OK);
244 ASSERT_GE(retval.sequence, 0);
245 ASSERT_EQ(retval.buffer, nullptr);
246
247 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
248 ret = bq->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
249 ASSERT_EQ(ret, OHOS::GSERROR_OK);
250
251 ret = bq->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
252 ASSERT_NE(ret, OHOS::GSERROR_OK);
253 }
254
255 /*
256 * Function: AcquireBuffer and ReleaseBuffer
257 * Type: Function
258 * Rank: Important(2)
259 * EnvConditions: N/A
260 * CaseDescription: 1. call AcquireBuffer
261 * 2. call ReleaseBuffer 2 times
262 * 3. check ret
263 */
264 HWTEST_F(BufferQueueTest, ReqCanFluAcqRel005, Function | MediumTest | Level2)
265 {
266 sptr<SurfaceBuffer> buffer;
267
268 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
269 GSError ret = bq->AcquireBuffer(buffer, acquireFence, timestamp, damages);
270 ASSERT_EQ(ret, OHOS::GSERROR_OK);
271
272 sptr<SyncFence> ReleaseFence = SyncFence::INVALID_FENCE;
273 ret = bq->ReleaseBuffer(buffer, ReleaseFence);
274 ASSERT_EQ(ret, OHOS::GSERROR_OK);
275
276 ret = bq->ReleaseBuffer(buffer, ReleaseFence);
277 ASSERT_NE(ret, OHOS::GSERROR_OK);
278 }
279
280 /*
281 * Function: RequestBuffer, and CancelBuffer
282 * Type: Function
283 * Rank: Important(2)
284 * EnvConditions: N/A
285 * CaseDescription: 1. call RequestBuffer and CancelBuffer by different retval
286 * 2. check ret
287 */
288 HWTEST_F(BufferQueueTest, ReqCanFluAcqRel006, Function | MediumTest | Level2)
289 {
290 IBufferProducer::RequestBufferReturnValue retval1;
291 IBufferProducer::RequestBufferReturnValue retval2;
292 IBufferProducer::RequestBufferReturnValue retval3;
293 GSError ret;
294
295 // not alloc
296 ret = bq->RequestBuffer(requestConfig, bedata, retval1);
297 ASSERT_EQ(ret, OHOS::GSERROR_OK);
298 ASSERT_GE(retval1.sequence, 0);
299 ASSERT_EQ(retval1.buffer, nullptr);
300
301 // alloc
302 ret = bq->RequestBuffer(requestConfig, bedata, retval2);
303 ASSERT_EQ(ret, OHOS::GSERROR_OK);
304 ASSERT_GE(retval2.sequence, 0);
305 ASSERT_NE(retval2.buffer, nullptr);
306
307 cache[retval2.sequence] = retval2.buffer;
308
309 // no buffer
310 ret = bq->RequestBuffer(requestConfig, bedata, retval3);
311 ASSERT_NE(ret, OHOS::GSERROR_OK);
312 ASSERT_EQ(retval3.buffer, nullptr);
313
314 ret = bq->CancelBuffer(retval1.sequence, bedata);
315 ASSERT_EQ(ret, OHOS::GSERROR_OK);
316
317 ret = bq->CancelBuffer(retval2.sequence, bedata);
318 ASSERT_EQ(ret, OHOS::GSERROR_OK);
319
320 ret = bq->CancelBuffer(retval3.sequence, bedata);
321 ASSERT_NE(ret, OHOS::GSERROR_OK);
322 }
323
324 /*
325 * Function: RequestBuffer, ReleaseBuffer and FlushBuffer
326 * Type: Function
327 * Rank: Important(2)
328 * EnvConditions: N/A
329 * CaseDescription: 1. call RequestBuffer
330 * 2. call ReleaseBuffer
331 * 3. call FlushBuffer
332 * 4. check ret
333 */
334 HWTEST_F(BufferQueueTest, ReqCanFluAcqRel007, Function | MediumTest | Level2)
335 {
336 IBufferProducer::RequestBufferReturnValue retval;
337
338 // not alloc
339 GSError ret = bq->RequestBuffer(requestConfig, bedata, retval);
340 ASSERT_EQ(ret, OHOS::GSERROR_OK);
341 ASSERT_GE(retval.sequence, 0);
342 ASSERT_EQ(retval.buffer, nullptr);
343
344 retval.buffer = cache[retval.sequence];
345
346 sptr<SyncFence> releaseFence = SyncFence::INVALID_FENCE;
347 ret = bq->ReleaseBuffer(retval.buffer, releaseFence);
348 ASSERT_NE(ret, OHOS::GSERROR_OK);
349
350 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
351 ret = bq->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
352 ASSERT_EQ(ret, OHOS::GSERROR_OK);
353 }
354
355 /*
356 * Function: AcquireBuffer, FlushBuffer and ReleaseBuffer
357 * Type: Function
358 * Rank: Important(2)
359 * EnvConditions: N/A
360 * CaseDescription: 1. call AcquireBuffer
361 * 2. call FlushBuffer
362 * 3. call ReleaseBuffer
363 * 4. check ret
364 */
365 HWTEST_F(BufferQueueTest, ReqCanFluAcqRel008, Function | MediumTest | Level2)
366 {
367 sptr<SurfaceBuffer> buffer;
368 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
369
370 // acq from last test
371 GSError ret = bq->AcquireBuffer(buffer, acquireFence, timestamp, damages);
372 ASSERT_EQ(ret, OHOS::GSERROR_OK);
373
374 uint32_t sequence;
375 for (auto it = cache.begin(); it != cache.end(); it++) {
376 if (it->second.GetRefPtr() == buffer.GetRefPtr()) {
377 sequence = it->first;
378 }
379 }
380 ASSERT_GE(sequence, 0);
381
382 ret = bq->FlushBuffer(sequence, bedata, acquireFence, flushConfig);
383 ASSERT_NE(ret, OHOS::GSERROR_OK);
384
385 sptr<SyncFence> releaseFence = SyncFence::INVALID_FENCE;
386 ret = bq->ReleaseBuffer(buffer, releaseFence);
387 ASSERT_EQ(ret, OHOS::GSERROR_OK);
388 }
389
390 /*
391 * Function: RequestBuffer and CancelBuffer
392 * Type: Function
393 * Rank: Important(2)
394 * EnvConditions: N/A
395 * CaseDescription: 1. call RequestBuffer
396 * 2. call CancelBuffer
397 * 3. check retval and ret
398 */
399 HWTEST_F(BufferQueueTest, ReqCanFluAcqRel009, Function | MediumTest | Level2)
400 {
401 IBufferProducer::RequestBufferReturnValue retval;
402 BufferRequestConfig deleteconfig = requestConfig;
403 deleteconfig.width = 1921;
404
405 GSError ret = bq->RequestBuffer(deleteconfig, bedata, retval);
406 ASSERT_EQ(ret, OHOS::GSERROR_OK);
407 ASSERT_EQ(retval.deletingBuffers.size(), 1u);
408 ASSERT_GE(retval.sequence, 0);
409 ASSERT_NE(retval.buffer, nullptr);
410
411 ret = bq->CancelBuffer(retval.sequence, bedata);
412 ASSERT_EQ(ret, OHOS::GSERROR_OK);
413 }
414
415 /*
416 * Function: GetLastConsumeTime
417 * Type: Function
418 * Rank: Important(2)
419 * EnvConditions: N/A
420 * CaseDescription: 1. call GetLastConsumeTime
421 * 2. check lastConsumeTime
422 */
423 HWTEST_F(BufferQueueTest, GetLastConsumeTimeTest, Function | MediumTest | Level2)
424 {
425 int64_t lastConsumeTime = 0;
426 bq->GetLastConsumeTime(lastConsumeTime);
427 std::cout << "lastConsumeTime = " << lastConsumeTime << std::endl;
428 ASSERT_NE(lastConsumeTime, 0);
429 }
430
431 /*
432 * Function: SetDesiredPresentTimestampAndUiTimestamp
433 * Type: Function
434 * Rank: Important(2)
435 * EnvConditions: N/A
436 * CaseDescription: 1. call SetDesiredPresentTimestampAndUiTimestamp with different parameter and check ret
437 * 2. call SetDesiredPresentTimestampAndUiTimestamp with empty parameter and check ret
438 * 3. repeatly call SetDesiredPresentTimestampAndUiTimestamp with different parameter and check ret
439 */
440 HWTEST_F(BufferQueueTest, SetDesiredPresentTimestampAndUiTimestamp001, Function | MediumTest | Level2)
441 {
442 IBufferProducer::RequestBufferReturnValue retval;
443 BufferRequestConfig config = requestConfig;
444 config.width = 1921;
445 GSError ret = bq->RequestBuffer(config, bedata, retval);
446 ASSERT_EQ(ret, OHOS::GSERROR_OK);
447 ASSERT_GE(retval.sequence, 0);
448
449 // call SetDesiredPresentTimestampAndUiTimestamp with different uiTimestamp and desireTimestamp, check ret
450 int64_t desiredPresentTimestamp = 0;
451 uint64_t uiTimestamp = 2;
452 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
453 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, uiTimestamp);
454 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
455 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, false);
456
457 desiredPresentTimestamp = -1;
458 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
459 ASSERT_GT(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, 0);
460 ASSERT_NE(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, uiTimestamp);
461 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
462 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, true);
463
464 desiredPresentTimestamp = 1;
465 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
466 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, desiredPresentTimestamp);
467 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
468 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, false);
469
470 // call SetDesiredPresentTimestampAndUiTimestamp with empty uiTimestamp and desireTimestamp, check ret
471 desiredPresentTimestamp = 0;
472 uiTimestamp = 0;
473 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
474 ASSERT_NE(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, desiredPresentTimestamp);
475 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
476 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, true);
477
478 //repeatly call SetDesiredPresentTimestampAndUiTimestamp with different uiTimestamp and desireTimestamp, check ret
479 desiredPresentTimestamp = 0;
480 uiTimestamp = 2;
481 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
482 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, uiTimestamp);
483 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
484 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, false);
485
486 desiredPresentTimestamp = -1;
487 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
488 ASSERT_GT(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, 0);
489 ASSERT_NE(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, uiTimestamp);
490 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
491 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, true);
492
493 desiredPresentTimestamp = 1;
494 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
495 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, desiredPresentTimestamp);
496 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
497 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, false);
498
499 ret = bq->CancelBuffer(retval.sequence, bedata);
500 ASSERT_EQ(ret, OHOS::GSERROR_OK);
501 }
502
503 /*
504 * Function: RequestBuffer
505 * Type: Function
506 * Rank: Important(2)
507 * EnvConditions: N/A
508 * CaseDescription: 1. set BufferRequestConfig with abnormal value
509 * 2. call RequestBuffer
510 * 3. check ret
511 */
512 HWTEST_F(BufferQueueTest, RequestBuffer001, Function | MediumTest | Level2)
513 {
514 IBufferProducer::RequestBufferReturnValue retval;
515 BufferRequestConfig config = requestConfig;
516 config.width = -1;
517
518 GSError ret = bq->RequestBuffer(config, bedata, retval);
519 ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
520 }
521
522 /*
523 * Function: RequestBuffer
524 * Type: Function
525 * Rank: Important(2)
526 * EnvConditions: N/A
527 * CaseDescription: 1. set BufferRequestConfig with abnormal value
528 * 2. call RequestBuffer
529 * 3. check ret
530 */
531 HWTEST_F(BufferQueueTest, RequestBuffer002, Function | MediumTest | Level2)
532 {
533 IBufferProducer::RequestBufferReturnValue retval;
534 BufferRequestConfig config = requestConfig;
535 config.height = -1;
536
537 GSError ret = bq->RequestBuffer(config, bedata, retval);
538 ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
539 }
540
541 /*
542 * Function: RequestBuffer
543 * Type: Function
544 * Rank: Important(2)
545 * EnvConditions: N/A
546 * CaseDescription: 1. set BufferRequestConfig with abnormal value
547 * 2. call RequestBuffer
548 * 3. check ret
549 */
550 HWTEST_F(BufferQueueTest, RequestBuffer006, Function | MediumTest | Level2)
551 {
552 IBufferProducer::RequestBufferReturnValue retval;
553 BufferRequestConfig config = requestConfig;
554 config.format = -1;
555
556 GSError ret = bq->RequestBuffer(config, bedata, retval);
557 ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
558 }
559
560 /*
561 * Function: QueryIfBufferAvailable
562 * Type: Function
563 * Rank: Important(2)
564 * EnvConditions: N/A
565 * CaseDescription: 1. call QueryIfBufferAvailable and check ret
566 */
567 HWTEST_F(BufferQueueTest, QueryIfBufferAvailable001, Function | MediumTest | Level2)
568 {
569 bq->CleanCache(false, nullptr);
570 bool ret = bq->QueryIfBufferAvailable();
571 ASSERT_EQ(ret, true);
572
573 GSError reqRet = OHOS::GSERROR_OK;
574 IBufferProducer::RequestBufferReturnValue retval;
575 BufferRequestConfig config = requestConfig;
576 while (reqRet != OHOS::GSERROR_NO_BUFFER) {
577 reqRet = bq->RequestBuffer(config, bedata, retval);
578 }
579
580 ret = bq->QueryIfBufferAvailable();
581 ASSERT_EQ(ret, false);
582 }
583
584 /*
585 * Function: GetName
586 * Type: Function
587 * Rank: Important(2)
588 * EnvConditions: N/A
589 * CaseDescription: 1. call GetName and check ret
590 */
591 HWTEST_F(BufferQueueTest, GetName001, Function | MediumTest | Level2)
592 {
593 std::string name("na");
594 GSError ret = bq->GetName(name);
595 ASSERT_EQ(ret, GSERROR_OK);
596 ASSERT_NE(name, "na");
597 }
598
599 /*
600 * Function: RegisterConsumerListener
601 * Type: Function
602 * Rank: Important(2)
603 * EnvConditions: N/A
604 * CaseDescription: 1. call RegisterConsumerListener and check ret
605 */
606 HWTEST_F(BufferQueueTest, RegisterConsumerListener001, Function | MediumTest | Level2)
607 {
608 sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
609 GSError ret = bq->RegisterConsumerListener(listener);
610 ASSERT_EQ(ret, GSERROR_OK);
611 }
612
613 /*
614 * Function: SetDefaultWidthAndHeight
615 * Type: Function
616 * Rank: Important(2)
617 * EnvConditions: N/A
618 * CaseDescription: 1. call SetDefaultWidthAndHeight and check ret
619 */
620 HWTEST_F(BufferQueueTest, SetDefaultWidthAndHeight001, Function | MediumTest | Level2)
621 {
622 int width = 0;
623 int height = 0;
624 GSError ret = bq->SetDefaultWidthAndHeight(width, height);
625 ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
626
627 width = 1;
628 ret = bq->SetDefaultWidthAndHeight(width, height);
629 ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
630
631 width = 80;
632 height = 80;
633 ret = bq->SetDefaultWidthAndHeight(width, height);
634 ASSERT_EQ(ret, GSERROR_OK);
635 }
636
637 /*
638 * Function: GetDefaultWidth and GetDefaultHeight
639 * Type: Function
640 * Rank: Important(2)
641 * EnvConditions: N/A
642 * CaseDescription: 1. call GetDefaultWidth and check ret
643 */
644 HWTEST_F(BufferQueueTest, GetDefaultWidth001, Function | MediumTest | Level2)
645 {
646 int32_t width = 80;
647 int32_t height = 80;
648 GSError ret = bq->SetDefaultWidthAndHeight(width, height);
649 ASSERT_EQ(ret, GSERROR_OK);
650
651 ASSERT_EQ(width, bq->GetDefaultWidth());
652 ASSERT_EQ(height, bq->GetDefaultHeight());
653 }
654
655 /*
656 * Function: SetDefaultUsage and GetDefaultUsage
657 * Type: Function
658 * Rank: Important(2)
659 * EnvConditions: N/A
660 * CaseDescription: 1. call SetDefaultUsage and check ret
661 */
662 HWTEST_F(BufferQueueTest, SetDefaultUsage001, Function | MediumTest | Level2)
663 {
664 uint64_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA;
665 GSError ret = bq->SetDefaultUsage(usage);
666 ASSERT_EQ(ret, GSERROR_OK);
667 ASSERT_EQ(usage, bq->GetDefaultUsage());
668 }
669
670 /*
671 * Function: CleanCache
672 * Type: Function
673 * Rank: Important(2)
674 * EnvConditions: N/A
675 * CaseDescription: 1. call CleanCache and check ret
676 */
677 HWTEST_F(BufferQueueTest, CleanCache001, Function | MediumTest | Level2)
678 {
679 GSError ret = bq->CleanCache(false, nullptr);
680 ASSERT_EQ(ret, GSERROR_OK);
681 }
682 /*
683 * Function: AttachBufferUpdateStatus
684 * Type: Function
685 * Rank: Important(2)
686 * EnvConditions: N/A
687 * CaseDescription: 1. call AttachBufferUpdateStatus and check ret
688 */
689 HWTEST_F(BufferQueueTest, AttachBufferUpdateStatus, Function | MediumTest | Level2)
690 {
691 uint32_t sequence = 2;
692 int32_t timeOut = 6;
693 std::mutex mutex_;
694 std::unique_lock<std::mutex> lock(mutex_);
695 GSError ret = bq->AttachBufferUpdateStatus(lock, sequence, timeOut);
696 ASSERT_EQ(ret, GSERROR_OK);
697 }
698
699 /*
700 * Function: AttachBuffer
701 * Type: Function
702 * Rank: Important(2)
703 * EnvConditions: N/A
704 * CaseDescription: 1. call AttachBuffer, DetachBuffer and check ret
705 */
706 HWTEST_F(BufferQueueTest, AttachBufferAndDetachBuffer001, Function | MediumTest | Level2)
707 {
708 bq->CleanCache(false, nullptr);
709 int32_t timeOut = 6;
710 IBufferProducer::RequestBufferReturnValue retval;
711 GSError ret = bq->AttachBuffer(retval.buffer, timeOut);
712 ASSERT_EQ(ret, GSERROR_INVALID_OPERATING);
713 EXPECT_EQ(bq->DetachBuffer(retval.buffer), GSERROR_INVALID_ARGUMENTS);
714 sptr<SurfaceBuffer> buffer = nullptr;
715 EXPECT_EQ(bq->DetachBuffer(buffer), GSERROR_INVALID_ARGUMENTS);
716 }
717
718 /*
719 * Function: AttachBuffer
720 * Type: Function
721 * Rank: Important(2)
722 * EnvConditions: N/A
723 * CaseDescription: 1. call AttachBuffer, DetachBuffer and check ret
724 */
725 HWTEST_F(BufferQueueTest, AttachBufferAndDetachBuffer002, Function | MediumTest | Level2)
726 {
727 bq->CleanCache(false, nullptr);
728 int32_t timeOut = 6;
729 EXPECT_EQ(bq->SetQueueSize(SURFACE_MAX_QUEUE_SIZE), GSERROR_OK);
730 sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
731 ASSERT_NE(buffer, nullptr);
732 GSError ret = bq->AttachBuffer(buffer, timeOut);
733 sptr<SurfaceBuffer> buffer1 = SurfaceBuffer::Create();
734 EXPECT_EQ(bq->GetUsedSize(), 1);
735 ASSERT_EQ(ret, GSERROR_OK);
736 EXPECT_EQ(bq->AttachBuffer(buffer1, timeOut), GSERROR_OK);
737 ret= bq->DetachBuffer(buffer);
738 EXPECT_EQ(ret, GSERROR_NO_ENTRY);
739 EXPECT_EQ(bq->DetachBuffer(buffer1), GSERROR_NO_ENTRY);
740 {
741 std::mutex mutex;
742 std::unique_lock<std::mutex> lock(mutex);
743 EXPECT_EQ(bq->AllocBuffer(buffer1, requestConfig, lock), GSERROR_OK);
744 }
745 EXPECT_EQ(bq->DetachBuffer(buffer1), GSERROR_OK);
746 }
747
748 /*
749 * Function: RegisterSurfaceDelegator
750 * Type: Function
751 * Rank: Important(2)
752 * EnvConditions: N/A
753 * CaseDescription: 1. call RegisterSurfaceDelegator and check ret
754 */
755 HWTEST_F(BufferQueueTest, RegisterSurfaceDelegator001, Function | MediumTest | Level2)
756 {
757 surfaceDelegator = ProducerSurfaceDelegator::Create();
758 GSError ret = bq->RegisterSurfaceDelegator(surfaceDelegator->AsObject(), csurface1);
759 ASSERT_EQ(ret, GSERROR_OK);
760 }
761
762 /*
763 * Function: RegisterDeleteBufferListener
764 * Type: Function
765 * Rank: Important(2)
766 * EnvConditions: N/A
767 * CaseDescription: 1. call RegisterDeleteBufferListener and check ret
768 */
769 HWTEST_F(BufferQueueTest, RegisterDeleteBufferListener001, Function | MediumTest | Level2)
770 {
771 surfaceDelegator = ProducerSurfaceDelegator::Create();
772 GSError ret = bq->RegisterDeleteBufferListener(nullptr, true);
773 ASSERT_EQ(ret, GSERROR_OK);
774 }
775
776 /*
777 * Function: QueueAndDequeueDelegator
778 * Type: Function
779 * Rank: Important(2)
780 * EnvConditions: N/A
781 * CaseDescription: 1. call RegisterSurfaceDelegator and check ret
782 * 2. call RequestBuffer and check ret (this will call DelegatorDequeueBuffer)
783 * 3. call FlushBuffer and check ret (this will call DelegatorQueueBuffer)
784 */
785 HWTEST_F(BufferQueueTest, QueueAndDequeueDelegator001, Function | MediumTest | Level2)
786 {
787 surfaceDelegator = ProducerSurfaceDelegator::Create();
788 GSError ret = bq->RegisterSurfaceDelegator(surfaceDelegator->AsObject(), csurface1);
789 ASSERT_EQ(ret, GSERROR_OK);
790
791 IBufferProducer::RequestBufferReturnValue retval;
792 ret = bq->RequestBuffer(requestConfig, bedata, retval);
793 ASSERT_EQ(ret, GSERROR_OK);
794 ASSERT_NE(retval.buffer, nullptr);
795 ASSERT_GE(retval.sequence, 0);
796
797 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
798 ret = bq->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
799 ASSERT_EQ(ret, OHOS::GSERROR_OK);
800 }
801
802 /*
803 * Function: SetSurfaceSourceType and GetSurfaceSourceType
804 * Type: Function
805 * Rank: Important(2)
806 * EnvConditions: N/A
807 * CaseDescription: 1. call SetSurfaceSourceType and check ret
808 * 2. call GetSurfaceSourceType and check the value
809 */
810 HWTEST_F(BufferQueueTest, SurfaceSourceType001, Function | MediumTest | Level2)
811 {
812 OHSurfaceSource sourceType = OHSurfaceSource::OH_SURFACE_SOURCE_VIDEO;
813 GSError ret = bq->SetSurfaceSourceType(sourceType);
814 ASSERT_EQ(ret, OHOS::GSERROR_OK);
815 ASSERT_EQ(sourceType, bq->GetSurfaceSourceType());
816 }
817
818 /*
819 * Function: SetSurfaceAppFrameworkType
820 * Type: Function
821 * Rank: Important(2)
822 * EnvConditions: N/A
823 * CaseDescription: 1. call SetSurfaceAppFrameworkType and check ret
824 */
825 HWTEST_F(BufferQueueTest, SetSurfaceAppFrameworkType001, Function | MediumTest | Level2)
826 {
827 std::string type = "";
828 GSError ret = bq->SetSurfaceAppFrameworkType(type);
829 ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
830
831 std::string type1 = "AAAAABBBBBCCCCCDDDDDEEEEEFFFFFGGGGGAAAAABBBBBCCCCCDDDDDEEEEEFFFFFGGGGG";
832 ret = bq->SetSurfaceAppFrameworkType(type1);
833 ASSERT_EQ(ret, OHOS::GSERROR_OUT_OF_RANGE);
834
835 std::string type2 = "test";
836 ret = bq->SetSurfaceAppFrameworkType(type2);
837 ASSERT_EQ(ret, OHOS::GSERROR_OK);
838 }
839
840 /*
841 * Function: GetSurfaceAppFrameworkType
842 * Type: Function
843 * Rank: Important(2)
844 * EnvConditions: N/A
845 * CaseDescription: 1. call GetSurfaceAppFrameworkType and check value
846 */
847 HWTEST_F(BufferQueueTest, GetSurfaceAppFrameworkType001, Function | MediumTest | Level2)
848 {
849 std::string type = "test";
850 GSError ret = bq->SetSurfaceAppFrameworkType(type);
851 ASSERT_EQ(ret, OHOS::GSERROR_OK);
852 ASSERT_EQ(bq->GetSurfaceAppFrameworkType(), "test");
853 }
854
855 /*
856 * Function: SetGlobalAlpha and GetGlobalAlpha
857 * Type: Function
858 * Rank: Important(2)
859 * EnvConditions: N/A
860 * CaseDescription: 1. call SetGlobalAlpha and check value
861 * 2. call GetGlobalAlpha and check value
862 */
863 HWTEST_F(BufferQueueTest, SetGlobalAlpha001, Function | MediumTest | Level2)
864 {
865 int32_t alpha = 255;
866 GSError ret = bq->SetGlobalAlpha(alpha);
867 ASSERT_EQ(ret, OHOS::GSERROR_OK);
868
869 int32_t resultAlpha = -1;
870 ret = bq->GetGlobalAlpha(resultAlpha);
871 ASSERT_EQ(ret, OHOS::GSERROR_OK);
872 ASSERT_EQ(resultAlpha, alpha);
873 }
874
875 /*
876 * Function: GetLastFlushedDesiredPresentTimeStamp
877 * Type: Function
878 * Rank: Important(2)
879 * EnvConditions: N/A
880 * CaseDescription: 1. call GetLastFlushedDesiredPresentTimeStamp and check value
881 */
882 HWTEST_F(BufferQueueTest, GetLastFlushedDesiredPresentTimeStamp001, Function | MediumTest | Level2)
883 {
884 int64_t timeStampValue = 100000;
885 bq->lastFlushedDesiredPresentTimeStamp_ = timeStampValue;
886 int64_t result = 0;
887 GSError ret = bq->GetLastFlushedDesiredPresentTimeStamp(result);
888 ASSERT_EQ(ret, OHOS::GSERROR_OK);
889 ASSERT_EQ(result, timeStampValue);
890 }
891
892 /*
893 * Function: GetBufferSupportFastCompose
894 * Type: Function
895 * Rank: Important(2)
896 * EnvConditions: N/A
897 * CaseDescription: 1. call GetBufferSupportFastCompose and check value
898 */
899 HWTEST_F(BufferQueueTest, GetBufferSupportFastCompose001, Function | MediumTest | Level2)
900 {
901 bool supportFastCompose = true;
902 bq->bufferSupportFastCompose_ = supportFastCompose;
903 bool result = false;
904 GSError ret = bq->GetBufferSupportFastCompose(result);
905 ASSERT_EQ(ret, OHOS::GSERROR_OK);
906 ASSERT_EQ(result, supportFastCompose);
907 }
908
909 /*
910 * Function: RegisterProducerPropertyListener
911 * Type: Function
912 * Rank: Important(2)
913 * EnvConditions: N/A
914 * CaseDescription: 1. call RegisterProducerPropertyListener and check value
915 */
916 HWTEST_F(BufferQueueTest, RegisterProducerPropertyListener001, Function | MediumTest | Level2)
917 {
918 bool producerId = 6;
919 OnReleaseFunc onBufferRelease = nullptr;
920 sptr<IProducerListener> listener = new BufferReleaseProducerListener(onBufferRelease);
921 std::map<uint64_t, sptr<IProducerListener>> propertyChangeListeners_ = {{producerId, listener}};
922 GSError ret = bq->RegisterProducerPropertyListener(listener, producerId);
923 ASSERT_EQ(ret, OHOS::GSERROR_OK);
924 }
925
926 /*
927 * Function: UnRegisterProducerPropertyListener
928 * Type: Function
929 * Rank: Important(2)
930 * EnvConditions: N/A
931 * CaseDescription: 1. call UnRegisterProducerPropertyListener and check value
932 */
933 HWTEST_F(BufferQueueTest, UnRegisterProducerPropertyListener001, Function | MediumTest | Level2)
934 {
935 bool producerId = 6;
936 OnReleaseFunc onBufferRelease = nullptr;
937 sptr<IProducerListener> listener = new BufferReleaseProducerListener(onBufferRelease);
938 std::map<uint64_t, sptr<IProducerListener>> propertyChangeListeners_ = {{producerId, listener}};
939 GSError ret = bq->UnRegisterProducerPropertyListener(producerId);
940 ASSERT_EQ(ret, OHOS::GSERROR_OK);
941 }
942
943 /*
944 * Function: SetTransformHint
945 * Type: Function
946 * Rank: Important(2)
947 * EnvConditions: N/A
948 * CaseDescription: 1. call SetTransformHint and check value
949 */
950 HWTEST_F(BufferQueueTest, SetTransformHint001, Function | MediumTest | Level2)
951 {
952 GraphicTransformType transformHint = GraphicTransformType::GRAPHIC_ROTATE_90;
953 uint64_t producerId = 0;
954 EXPECT_EQ(bq->SetTransformHint(transformHint, producerId), GSERROR_OK);
955 transformHint = GraphicTransformType::GRAPHIC_ROTATE_NONE;
956 ASSERT_EQ(bq->SetTransformHint(transformHint, producerId), OHOS::GSERROR_OK);
957 }
958 }
959