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_consumer_listener.h"
21 #include "sync_fence.h"
22 #include "consumer_surface.h"
23 #include "producer_surface_delegator.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS::Rosen {
29 class BufferQueueTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33
34 static inline BufferRequestConfig requestConfig = {
35 .width = 0x100,
36 .height = 0x100,
37 .strideAlignment = 0x8,
38 .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
39 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
40 .timeout = 0,
41 };
42 static inline BufferFlushConfigWithDamages flushConfig = {
43 .damages = {
44 {
45 .w = 0x100,
46 .h = 0x100,
47 }
48 },
49 };
50 static inline int64_t timestamp = 0;
51 static inline std::vector<Rect> damages = {};
52 static inline sptr<BufferQueue> bq = nullptr;
53 static inline std::map<int32_t, sptr<SurfaceBuffer>> cache;
54 static inline sptr<BufferExtraData> bedata = nullptr;
55 static inline sptr<ProducerSurfaceDelegator> surfaceDelegator = nullptr;
56 static inline sptr<IConsumerSurface> csurface1 = nullptr;
57 };
58
SetUpTestCase()59 void BufferQueueTest::SetUpTestCase()
60 {
61 bq = new BufferQueue("test");
62 sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
63 bq->RegisterConsumerListener(listener);
64 bedata = new OHOS::BufferExtraDataImpl;
65 csurface1 = IConsumerSurface::Create();
66 }
67
TearDownTestCase()68 void BufferQueueTest::TearDownTestCase()
69 {
70 bq = nullptr;
71 }
72
73 /*
74 * Function: GetUsedSize
75 * Type: Function
76 * Rank: Important(2)
77 * EnvConditions: N/A
78 * CaseDescription: 1. call GetUsedSize and check ret
79 */
80 HWTEST_F(BufferQueueTest, GetUsedSize001, Function | MediumTest | Level2)
81 {
82 uint32_t usedSize = bq->GetUsedSize();
83 ASSERT_NE(usedSize, -1);
84 }
85
86 /*
87 * Function: SetQueueSize and GetQueueSize
88 * Type: Function
89 * Rank: Important(2)
90 * EnvConditions: N/A
91 * CaseDescription: 1. call GetQueueSize for default
92 * 2. call SetQueueSize
93 * 3. call SetQueueSize again with abnormal input
94 * 4. check ret and call GetQueueSize
95 */
96 HWTEST_F(BufferQueueTest, QueueSize001, Function | MediumTest | Level2)
97 {
98 ASSERT_EQ(bq->GetQueueSize(), (uint32_t)SURFACE_DEFAULT_QUEUE_SIZE);
99
100 GSError ret = bq->SetQueueSize(2);
101 ASSERT_EQ(ret, OHOS::GSERROR_OK);
102
103 ret = bq->SetQueueSize(SURFACE_MAX_QUEUE_SIZE + 1);
104 ASSERT_NE(ret, OHOS::GSERROR_OK);
105
106 ASSERT_EQ(bq->GetQueueSize(), 2u);
107 BufferQueue *bqTmp = new BufferQueue("testTmp", true);
108 EXPECT_EQ(bqTmp->SetQueueSize(2), GSERROR_INVALID_ARGUMENTS);
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: SetDesiredPresentTimestampAndUiTimestamp
417 * Type: Function
418 * Rank: Important(2)
419 * EnvConditions: N/A
420 * CaseDescription: 1. call SetDesiredPresentTimestampAndUiTimestamp with different parameter and check ret
421 * 2. call SetDesiredPresentTimestampAndUiTimestamp with empty parameter and check ret
422 * 3. repeatly call SetDesiredPresentTimestampAndUiTimestamp with different parameter and check ret
423 */
424 HWTEST_F(BufferQueueTest, SetDesiredPresentTimestampAndUiTimestamp001, Function | MediumTest | Level2)
425 {
426 IBufferProducer::RequestBufferReturnValue retval;
427 BufferRequestConfig config = requestConfig;
428 config.width = 1921;
429 GSError ret = bq->RequestBuffer(config, bedata, retval);
430 ASSERT_EQ(ret, OHOS::GSERROR_OK);
431 ASSERT_GE(retval.sequence, 0);
432
433 // call SetDesiredPresentTimestampAndUiTimestamp with different uiTimestamp and desireTimestamp, check ret
434 int64_t desiredPresentTimestamp = 0;
435 uint64_t uiTimestamp = 2;
436 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
437 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, uiTimestamp);
438 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
439 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, false);
440
441 desiredPresentTimestamp = -1;
442 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
443 ASSERT_GT(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, 0);
444 ASSERT_NE(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, uiTimestamp);
445 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
446 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, true);
447
448 desiredPresentTimestamp = 1;
449 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
450 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, desiredPresentTimestamp);
451 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
452 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, false);
453
454 // call SetDesiredPresentTimestampAndUiTimestamp with empty uiTimestamp and desireTimestamp, check ret
455 desiredPresentTimestamp = 0;
456 uiTimestamp = 0;
457 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
458 ASSERT_NE(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, desiredPresentTimestamp);
459 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
460 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, true);
461
462 //repeatly call SetDesiredPresentTimestampAndUiTimestamp with different uiTimestamp and desireTimestamp, check ret
463 desiredPresentTimestamp = 0;
464 uiTimestamp = 2;
465 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
466 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, uiTimestamp);
467 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
468 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, false);
469
470 desiredPresentTimestamp = -1;
471 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
472 ASSERT_GT(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, 0);
473 ASSERT_NE(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, uiTimestamp);
474 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
475 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, true);
476
477 desiredPresentTimestamp = 1;
478 bq->SetDesiredPresentTimestampAndUiTimestamp(retval.sequence, desiredPresentTimestamp, uiTimestamp);
479 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].desiredPresentTimestamp, desiredPresentTimestamp);
480 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].timestamp, uiTimestamp);
481 ASSERT_EQ(bq->bufferQueueCache_[retval.sequence].isAutoTimestamp, false);
482
483 ret = bq->CancelBuffer(retval.sequence, bedata);
484 ASSERT_EQ(ret, OHOS::GSERROR_OK);
485 }
486
487 /*
488 * Function: RequestBuffer
489 * Type: Function
490 * Rank: Important(2)
491 * EnvConditions: N/A
492 * CaseDescription: 1. set BufferRequestConfig with abnormal value
493 * 2. call RequestBuffer
494 * 3. check ret
495 */
496 HWTEST_F(BufferQueueTest, RequestBuffer001, Function | MediumTest | Level2)
497 {
498 IBufferProducer::RequestBufferReturnValue retval;
499 BufferRequestConfig config = requestConfig;
500 config.width = -1;
501
502 GSError ret = bq->RequestBuffer(config, bedata, retval);
503 ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
504 }
505
506 /*
507 * Function: RequestBuffer
508 * Type: Function
509 * Rank: Important(2)
510 * EnvConditions: N/A
511 * CaseDescription: 1. set BufferRequestConfig with abnormal value
512 * 2. call RequestBuffer
513 * 3. check ret
514 */
515 HWTEST_F(BufferQueueTest, RequestBuffer002, Function | MediumTest | Level2)
516 {
517 IBufferProducer::RequestBufferReturnValue retval;
518 BufferRequestConfig config = requestConfig;
519 config.height = -1;
520
521 GSError ret = bq->RequestBuffer(config, bedata, retval);
522 ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
523 }
524
525
526 /*
527 * Function: RequestBuffer
528 * Type: Function
529 * Rank: Important(2)
530 * EnvConditions: N/A
531 * CaseDescription: 1. set BufferRequestConfig with abnormal value
532 * 2. call RequestBuffer
533 * 3. check ret
534 */
535 HWTEST_F(BufferQueueTest, RequestBuffer003, Function | MediumTest | Level2)
536 {
537 IBufferProducer::RequestBufferReturnValue retval;
538 BufferRequestConfig config = requestConfig;
539 config.strideAlignment = SURFACE_MIN_STRIDE_ALIGNMENT - 1;
540
541 GSError ret = bq->RequestBuffer(config, bedata, retval);
542 ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
543 }
544
545 /*
546 * Function: RequestBuffer
547 * Type: Function
548 * Rank: Important(2)
549 * EnvConditions: N/A
550 * CaseDescription: 1. set BufferRequestConfig with abnormal value
551 * 2. call RequestBuffer
552 * 3. check ret
553 */
554 HWTEST_F(BufferQueueTest, RequestBuffer004, Function | MediumTest | Level2)
555 {
556 IBufferProducer::RequestBufferReturnValue retval;
557 BufferRequestConfig config = requestConfig;
558 config.strideAlignment = SURFACE_MAX_STRIDE_ALIGNMENT + 1;
559
560 GSError ret = bq->RequestBuffer(config, bedata, retval);
561 ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
562 }
563
564 /*
565 * Function: RequestBuffer
566 * Type: Function
567 * Rank: Important(2)
568 * EnvConditions: N/A
569 * CaseDescription: 1. set BufferRequestConfig with abnormal value
570 * 2. call RequestBuffer
571 * 3. check ret
572 */
573 HWTEST_F(BufferQueueTest, RequestBuffer005, Function | MediumTest | Level2)
574 {
575 IBufferProducer::RequestBufferReturnValue retval;
576 BufferRequestConfig config = requestConfig;
577 config.strideAlignment = 3;
578
579 GSError ret = bq->RequestBuffer(config, bedata, retval);
580 ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
581 }
582
583 /*
584 * Function: RequestBuffer
585 * Type: Function
586 * Rank: Important(2)
587 * EnvConditions: N/A
588 * CaseDescription: 1. set BufferRequestConfig with abnormal value
589 * 2. call RequestBuffer
590 * 3. check ret
591 */
592 HWTEST_F(BufferQueueTest, RequestBuffer006, Function | MediumTest | Level2)
593 {
594 IBufferProducer::RequestBufferReturnValue retval;
595 BufferRequestConfig config = requestConfig;
596 config.format = -1;
597
598 GSError ret = bq->RequestBuffer(config, bedata, retval);
599 ASSERT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
600 }
601
602 /*
603 * Function: QueryIfBufferAvailable
604 * Type: Function
605 * Rank: Important(2)
606 * EnvConditions: N/A
607 * CaseDescription: 1. call QueryIfBufferAvailable and check ret
608 */
609 HWTEST_F(BufferQueueTest, QueryIfBufferAvailable001, Function | MediumTest | Level2)
610 {
611 bq->CleanCache(false);
612 bool ret = bq->QueryIfBufferAvailable();
613 ASSERT_EQ(ret, true);
614
615 GSError reqRet = OHOS::GSERROR_OK;
616 IBufferProducer::RequestBufferReturnValue retval;
617 BufferRequestConfig config = requestConfig;
618 while (reqRet != OHOS::GSERROR_NO_BUFFER) {
619 reqRet = bq->RequestBuffer(config, bedata, retval);
620 }
621
622 ret = bq->QueryIfBufferAvailable();
623 ASSERT_EQ(ret, false);
624 }
625
626 /*
627 * Function: GetName
628 * Type: Function
629 * Rank: Important(2)
630 * EnvConditions: N/A
631 * CaseDescription: 1. call GetName and check ret
632 */
633 HWTEST_F(BufferQueueTest, GetName001, Function | MediumTest | Level2)
634 {
635 std::string name("na");
636 GSError ret = bq->GetName(name);
637 ASSERT_EQ(ret, GSERROR_OK);
638 ASSERT_NE(name, "na");
639 }
640
641 /*
642 * Function: RegisterConsumerListener
643 * Type: Function
644 * Rank: Important(2)
645 * EnvConditions: N/A
646 * CaseDescription: 1. call RegisterConsumerListener and check ret
647 */
648 HWTEST_F(BufferQueueTest, RegisterConsumerListener001, Function | MediumTest | Level2)
649 {
650 sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
651 GSError ret = bq->RegisterConsumerListener(listener);
652 ASSERT_EQ(ret, GSERROR_OK);
653 }
654
655 /*
656 * Function: SetDefaultWidthAndHeight
657 * Type: Function
658 * Rank: Important(2)
659 * EnvConditions: N/A
660 * CaseDescription: 1. call SetDefaultWidthAndHeight and check ret
661 */
662 HWTEST_F(BufferQueueTest, SetDefaultWidthAndHeight001, Function | MediumTest | Level2)
663 {
664 int width = 0;
665 int height = 0;
666 GSError ret = bq->SetDefaultWidthAndHeight(width, height);
667 ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
668
669 width = 1;
670 ret = bq->SetDefaultWidthAndHeight(width, height);
671 ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS);
672
673 width = 80;
674 height = 80;
675 ret = bq->SetDefaultWidthAndHeight(width, height);
676 ASSERT_EQ(ret, GSERROR_OK);
677 }
678
679 /*
680 * Function: GetDefaultWidth and GetDefaultHeight
681 * Type: Function
682 * Rank: Important(2)
683 * EnvConditions: N/A
684 * CaseDescription: 1. call GetDefaultWidth and check ret
685 */
686 HWTEST_F(BufferQueueTest, GetDefaultWidth001, Function | MediumTest | Level2)
687 {
688 int32_t width = 80;
689 int32_t height = 80;
690 GSError ret = bq->SetDefaultWidthAndHeight(width, height);
691 ASSERT_EQ(ret, GSERROR_OK);
692
693 ASSERT_EQ(width, bq->GetDefaultWidth());
694 ASSERT_EQ(height, bq->GetDefaultHeight());
695 }
696
697 /*
698 * Function: SetDefaultUsage and GetDefaultUsage
699 * Type: Function
700 * Rank: Important(2)
701 * EnvConditions: N/A
702 * CaseDescription: 1. call SetDefaultUsage and check ret
703 */
704 HWTEST_F(BufferQueueTest, SetDefaultUsage001, Function | MediumTest | Level2)
705 {
706 uint64_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA;
707 GSError ret = bq->SetDefaultUsage(usage);
708 ASSERT_EQ(ret, GSERROR_OK);
709 ASSERT_EQ(usage, bq->GetDefaultUsage());
710 }
711
712 /*
713 * Function: CleanCache
714 * Type: Function
715 * Rank: Important(2)
716 * EnvConditions: N/A
717 * CaseDescription: 1. call CleanCache and check ret
718 */
719 HWTEST_F(BufferQueueTest, CleanCache001, Function | MediumTest | Level2)
720 {
721 GSError ret = bq->CleanCache(false);
722 ASSERT_EQ(ret, GSERROR_OK);
723 }
724 /*
725 * Function: AttachBufferUpdateStatus
726 * Type: Function
727 * Rank: Important(2)
728 * EnvConditions: N/A
729 * CaseDescription: 1. call AttachBufferUpdateStatus and check ret
730 */
731 HWTEST_F(BufferQueueTest, AttachBufferUpdateStatus, Function | MediumTest | Level2)
732 {
733 uint32_t sequence = 2;
734 int32_t timeOut = 6;
735 std::mutex mutex_;
736 std::unique_lock<std::mutex> lock(mutex_);
737 GSError ret = bq->AttachBufferUpdateStatus(lock, sequence, timeOut);
738 ASSERT_EQ(ret, GSERROR_OK);
739 }
740
741 /*
742 * Function: AttachBuffer
743 * Type: Function
744 * Rank: Important(2)
745 * EnvConditions: N/A
746 * CaseDescription: 1. call AttachBuffer, DetachBuffer and check ret
747 */
748 HWTEST_F(BufferQueueTest, AttachBufferAndDetachBuffer001, Function | MediumTest | Level2)
749 {
750 bq->CleanCache(false);
751 int32_t timeOut = 6;
752 IBufferProducer::RequestBufferReturnValue retval;
753 GSError ret = bq->AttachBuffer(retval.buffer, timeOut);
754 ASSERT_EQ(ret, GSERROR_INVALID_OPERATING);
755 EXPECT_EQ(bq->DetachBuffer(retval.buffer), GSERROR_INVALID_ARGUMENTS);
756 sptr<SurfaceBuffer> buffer = nullptr;
757 EXPECT_EQ(bq->DetachBuffer(buffer), GSERROR_INVALID_ARGUMENTS);
758 BufferQueue *bqTmp = new BufferQueue("testTmp", true);
759 EXPECT_EQ(bqTmp->DetachBuffer(buffer), GSERROR_INVALID_OPERATING);
760 bqTmp = nullptr;
761 }
762
763 /*
764 * Function: AttachBuffer
765 * Type: Function
766 * Rank: Important(2)
767 * EnvConditions: N/A
768 * CaseDescription: 1. call AttachBuffer, DetachBuffer and check ret
769 */
770 HWTEST_F(BufferQueueTest, AttachBufferAndDetachBuffer002, Function | MediumTest | Level2)
771 {
772 bq->CleanCache(false);
773 int32_t timeOut = 6;
774 EXPECT_EQ(bq->SetQueueSize(SURFACE_MAX_QUEUE_SIZE), GSERROR_OK);
775 sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
776 ASSERT_NE(buffer, nullptr);
777 GSError ret = bq->AttachBuffer(buffer, timeOut);
778 sptr<SurfaceBuffer> buffer1 = SurfaceBuffer::Create();
779 EXPECT_EQ(bq->GetUsedSize(), 1);
780 ASSERT_EQ(ret, GSERROR_OK);
781 EXPECT_EQ(bq->AttachBuffer(buffer1, timeOut), GSERROR_OK);
782 ret= bq->DetachBuffer(buffer);
783 EXPECT_EQ(ret, GSERROR_NO_ENTRY);
784 EXPECT_EQ(bq->DetachBuffer(buffer1), GSERROR_NO_ENTRY);
785 EXPECT_EQ(bq->AllocBuffer(buffer1, requestConfig), GSERROR_OK);
786 EXPECT_EQ(bq->DetachBuffer(buffer1), GSERROR_OK);
787 }
788
789 /*
790 * Function: RegisterSurfaceDelegator
791 * Type: Function
792 * Rank: Important(2)
793 * EnvConditions: N/A
794 * CaseDescription: 1. call RegisterSurfaceDelegator and check ret
795 */
796 HWTEST_F(BufferQueueTest, RegisterSurfaceDelegator001, Function | MediumTest | Level2)
797 {
798 surfaceDelegator = ProducerSurfaceDelegator::Create();
799 GSError ret = bq->RegisterSurfaceDelegator(surfaceDelegator->AsObject(), csurface1);
800 ASSERT_EQ(ret, GSERROR_OK);
801 }
802
803 /*
804 * Function: RegisterDeleteBufferListener
805 * Type: Function
806 * Rank: Important(2)
807 * EnvConditions: N/A
808 * CaseDescription: 1. call RegisterDeleteBufferListener and check ret
809 */
810 HWTEST_F(BufferQueueTest, RegisterDeleteBufferListener001, Function | MediumTest | Level2)
811 {
812 surfaceDelegator = ProducerSurfaceDelegator::Create();
813 GSError ret = bq->RegisterDeleteBufferListener(nullptr, true);
814 ASSERT_EQ(ret, GSERROR_OK);
815 }
816
817 /*
818 * Function: QueueAndDequeueDelegator
819 * Type: Function
820 * Rank: Important(2)
821 * EnvConditions: N/A
822 * CaseDescription: 1. call RegisterSurfaceDelegator and check ret
823 * 2. call RequestBuffer and check ret (this will call DelegatorDequeueBuffer)
824 * 3. call FlushBuffer and check ret (this will call DelegatorQueueBuffer)
825 */
826 HWTEST_F(BufferQueueTest, QueueAndDequeueDelegator001, Function | MediumTest | Level2)
827 {
828 surfaceDelegator = ProducerSurfaceDelegator::Create();
829 GSError ret = bq->RegisterSurfaceDelegator(surfaceDelegator->AsObject(), csurface1);
830 ASSERT_EQ(ret, GSERROR_OK);
831
832 IBufferProducer::RequestBufferReturnValue retval;
833 ret = bq->RequestBuffer(requestConfig, bedata, retval);
834 ASSERT_EQ(ret, GSERROR_OK);
835 ASSERT_NE(retval.buffer, nullptr);
836 ASSERT_GE(retval.sequence, 0);
837
838 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
839 ret = bq->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
840 ASSERT_EQ(ret, OHOS::GSERROR_OK);
841 }
842
843 /*
844 * Function: SetSurfaceSourceType and GetSurfaceSourceType
845 * Type: Function
846 * Rank: Important(2)
847 * EnvConditions: N/A
848 * CaseDescription: 1. call SetSurfaceSourceType and check ret
849 * 2. call GetSurfaceSourceType and check the value
850 */
851 HWTEST_F(BufferQueueTest, SurfaceSourceType001, Function | MediumTest | Level2)
852 {
853 OHSurfaceSource sourceType = OHSurfaceSource::OH_SURFACE_SOURCE_VIDEO;
854 GSError ret = bq->SetSurfaceSourceType(sourceType);
855 ASSERT_EQ(ret, OHOS::GSERROR_OK);
856 ASSERT_EQ(sourceType, bq->GetSurfaceSourceType());
857 }
858
859 /*
860 * Function: SetSurfaceAppFrameworkType
861 * Type: Function
862 * Rank: Important(2)
863 * EnvConditions: N/A
864 * CaseDescription: 1. call SetSurfaceAppFrameworkType and check ret
865 */
866 HWTEST_F(BufferQueueTest, SetSurfaceAppFrameworkType001, Function | MediumTest | Level2)
867 {
868 std::string type = "";
869 GSError ret = bq->SetSurfaceAppFrameworkType(type);
870 ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
871
872 std::string type1 = "AAAAABBBBBCCCCCDDDDDEEEEEFFFFFGGGGGAAAAABBBBBCCCCCDDDDDEEEEEFFFFFGGGGG";
873 ret = bq->SetSurfaceAppFrameworkType(type1);
874 ASSERT_EQ(ret, OHOS::GSERROR_OUT_OF_RANGE);
875
876 std::string type2 = "test";
877 ret = bq->SetSurfaceAppFrameworkType(type2);
878 ASSERT_EQ(ret, OHOS::GSERROR_OK);
879 }
880
881 /*
882 * Function: GetSurfaceAppFrameworkType
883 * Type: Function
884 * Rank: Important(2)
885 * EnvConditions: N/A
886 * CaseDescription: 1. call GetSurfaceAppFrameworkType and check value
887 */
888 HWTEST_F(BufferQueueTest, GetSurfaceAppFrameworkType001, Function | MediumTest | Level2)
889 {
890 std::string type = "test";
891 GSError ret = bq->SetSurfaceAppFrameworkType(type);
892 ASSERT_EQ(ret, OHOS::GSERROR_OK);
893 ASSERT_EQ(bq->GetSurfaceAppFrameworkType(), "test");
894 }
895 }
896