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 <chrono>
16 #include <thread>
17 #include <vector>
18 #include <sys/wait.h>
19 #include <unistd.h>
20 #include <gtest/gtest.h>
21
22 #include <iservice_registry.h>
23 #include <surface.h>
24 #include <buffer_extra_data_impl.h>
25 #include <buffer_client_producer.h>
26 #include <buffer_queue_producer.h>
27 #include "buffer_consumer_listener.h"
28 #include "sync_fence.h"
29 #include "accesstoken_kit.h"
30 #include "nativetoken_kit.h"
31 #include "token_setproc.h"
32
33 using namespace testing;
34 using namespace testing::ext;
35
36 namespace OHOS::Rosen {
37 class BufferClientProducerRemoteTest : public testing::Test {
38 public:
39 static void SetUpTestCase();
40 static void TearDownTestCase();
41
42 static inline BufferRequestConfig requestConfig = {
43 .width = 0x100,
44 .height = 0x100,
45 .strideAlignment = 0x8,
46 .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
47 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
48 .timeout = 0,
49 };
50 static inline BufferFlushConfigWithDamages flushConfig = {
51 .damages = {
52 {
53 .w = 0x100,
54 .h = 0x100,
55 }
56 },
57 };
58 static inline sptr<IRemoteObject> robj = nullptr;
59 static inline sptr<IBufferProducer> bp = nullptr;
60 static inline std::vector<uint32_t> deletingBuffers;
61 static inline pid_t pid = 0;
62 static inline int pipeFd[2] = {};
63 static inline int pipe1Fd[2] = {};
64 static inline int32_t systemAbilityID = 345135;
65 static inline sptr<BufferExtraData> bedata = new BufferExtraDataImpl;
66 static inline uint32_t firstSeqnum = 0;
67 };
68
InitNativeTokenInfo()69 static void InitNativeTokenInfo()
70 {
71 uint64_t tokenId;
72 const char *perms[2];
73 perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC";
74 perms[1] = "ohos.permission.CAMERA";
75 NativeTokenInfoParams infoInstance = {
76 .dcapsNum = 0,
77 .permsNum = 2,
78 .aclsNum = 0,
79 .dcaps = NULL,
80 .perms = perms,
81 .acls = NULL,
82 .processName = "dcamera_client_demo",
83 .aplStr = "system_basic",
84 };
85 tokenId = GetAccessTokenId(&infoInstance);
86 SetSelfTokenID(tokenId);
87 int32_t ret = Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
88 ASSERT_EQ(ret, Security::AccessToken::RET_SUCCESS);
89 std::this_thread::sleep_for(std::chrono::milliseconds(50)); // wait 50ms
90 }
91
SetUpTestCase()92 void BufferClientProducerRemoteTest::SetUpTestCase()
93 {
94 if (pipe(pipeFd) < 0) {
95 exit(1);
96 }
97 if (pipe(pipe1Fd) < 0) {
98 exit(0);
99 }
100 pid = fork();
101 if (pid < 0) {
102 exit(1);
103 }
104 if (pid == 0) {
105 InitNativeTokenInfo();
106 sptr<BufferQueue> bq = new BufferQueue("test");
107 ASSERT_NE(bq, nullptr);
108 sptr<BufferQueueProducer> bqp = new BufferQueueProducer(bq);
109 ASSERT_NE(bqp, nullptr);
110 sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
111 bq->RegisterConsumerListener(listener);
112 auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
113 sam->AddSystemAbility(systemAbilityID, bqp);
114 close(pipeFd[1]);
115 close(pipe1Fd[0]);
116 char buf[10] = "start";
117 write(pipe1Fd[1], buf, sizeof(buf));
118 sleep(0);
119 read(pipeFd[0], buf, sizeof(buf));
120 sam->RemoveSystemAbility(systemAbilityID);
121 close(pipeFd[0]);
122 close(pipe1Fd[1]);
123 exit(0);
124 } else {
125 close(pipeFd[0]);
126 close(pipe1Fd[1]);
127 char buf[10];
128 read(pipe1Fd[0], buf, sizeof(buf));
129 auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
130 robj = sam->GetSystemAbility(systemAbilityID);
131 bp = iface_cast<IBufferProducer>(robj);
132 }
133 }
134
TearDownTestCase()135 void BufferClientProducerRemoteTest::TearDownTestCase()
136 {
137 bp = nullptr;
138 robj = nullptr;
139
140 char buf[10] = "over";
141 write(pipeFd[1], buf, sizeof(buf));
142 close(pipeFd[1]);
143 close(pipe1Fd[0]);
144
145 int32_t ret = 0;
146 do {
147 waitpid(pid, nullptr, 0);
148 } while (ret == -1 && errno == EINTR);
149 }
150
151 /*
152 * Function: IsProxyObject
153 * Type: Function
154 * Rank: Important(2)
155 * EnvConditions: N/A
156 * CaseDescription: 1. check ret for IsProxyObject func
157 */
HWTEST_F(BufferClientProducerRemoteTest, IsProxy001, Function | MediumTest | Level2)158 HWTEST_F(BufferClientProducerRemoteTest, IsProxy001, Function | MediumTest | Level2)
159 {
160 ASSERT_TRUE(robj->IsProxyObject());
161 }
162
163 /*
164 * Function: SetQueueSize and GetQueueSize
165 * Type: Function
166 * Rank: Important(2)
167 * EnvConditions: N/A
168 * CaseDescription: 1. call GetQueueSize for default
169 * 2. call SetQueueSize and check the ret of GetQueueSize
170 */
HWTEST_F(BufferClientProducerRemoteTest, QueueSize001, Function | MediumTest | Level2)171 HWTEST_F(BufferClientProducerRemoteTest, QueueSize001, Function | MediumTest | Level2)
172 {
173 ASSERT_EQ(bp->GetQueueSize(), (uint32_t)SURFACE_DEFAULT_QUEUE_SIZE);
174
175 GSError ret = bp->SetQueueSize(2);
176 ASSERT_EQ(ret, OHOS::GSERROR_OK);
177
178 ret = bp->SetQueueSize(SURFACE_MAX_QUEUE_SIZE + 1);
179 ASSERT_NE(ret, OHOS::GSERROR_OK);
180
181 ASSERT_EQ(bp->GetQueueSize(), 2u);
182 }
183
184 /*
185 * Function: SetQueueSize and GetQueueSize
186 * Type: Function
187 * Rank: Important(2)
188 * EnvConditions: N/A
189 * CaseDescription: 1. call GetQueueSize for default
190 * 2. call SetQueueSize and check the ret of GetQueueSize
191 */
HWTEST_F(BufferClientProducerRemoteTest, ReqCan001, Function | MediumTest | Level2)192 HWTEST_F(BufferClientProducerRemoteTest, ReqCan001, Function | MediumTest | Level2)
193 {
194 IBufferProducer::RequestBufferReturnValue retval;
195 GSError ret = bp->RequestBuffer(requestConfig, bedata, retval);
196 ASSERT_EQ(ret, OHOS::GSERROR_OK);
197 ASSERT_NE(retval.buffer, nullptr);
198 firstSeqnum = retval.buffer->GetSeqNum();
199
200 ret = bp->CancelBuffer(retval.sequence, bedata);
201 ASSERT_EQ(ret, OHOS::GSERROR_OK);
202 }
203
204 /*
205 * Function: RequestBuffer and CancelBuffer
206 * Type: Function
207 * Rank: Important(2)
208 * EnvConditions: N/A
209 * CaseDescription: 1. call RequestBuffer
210 * 2. call CancelBuffer 2 times
211 */
HWTEST_F(BufferClientProducerRemoteTest, ReqCan002, Function | MediumTest | Level2)212 HWTEST_F(BufferClientProducerRemoteTest, ReqCan002, Function | MediumTest | Level2)
213 {
214 IBufferProducer::RequestBufferReturnValue retval;
215 GSError ret = bp->RequestBuffer(requestConfig, bedata, retval);
216 ASSERT_EQ(ret, OHOS::GSERROR_OK);
217 ASSERT_EQ(retval.buffer, nullptr);
218
219 ret = bp->CancelBuffer(retval.sequence, bedata);
220 ASSERT_EQ(ret, OHOS::GSERROR_OK);
221
222 ret = bp->CancelBuffer(retval.sequence, bedata);
223 ASSERT_NE(ret, OHOS::GSERROR_OK);
224 }
225
226 /*
227 * Function: RequestBuffer and CancelBuffer
228 * Type: Function
229 * Rank: Important(2)
230 * EnvConditions: N/A
231 * CaseDescription: 1. call RequestBuffer and CancelBuffer 3 times
232 */
HWTEST_F(BufferClientProducerRemoteTest, ReqCan003, Function | MediumTest | Level2)233 HWTEST_F(BufferClientProducerRemoteTest, ReqCan003, Function | MediumTest | Level2)
234 {
235 IBufferProducer::RequestBufferReturnValue retval1;
236 IBufferProducer::RequestBufferReturnValue retval2;
237 IBufferProducer::RequestBufferReturnValue retval3;
238 GSError ret;
239
240 ret = bp->RequestBuffer(requestConfig, bedata, retval1);
241 ASSERT_EQ(ret, OHOS::GSERROR_OK);
242 ASSERT_EQ(retval1.buffer, nullptr);
243
244 ret = bp->RequestBuffer(requestConfig, bedata, retval2);
245 ASSERT_EQ(ret, OHOS::GSERROR_OK);
246 ASSERT_NE(retval2.buffer, nullptr);
247
248 ret = bp->RequestBuffer(requestConfig, bedata, retval3);
249 ASSERT_NE(ret, OHOS::GSERROR_OK);
250 ASSERT_EQ(retval3.buffer, nullptr);
251
252 ret = bp->CancelBuffer(retval1.sequence, bedata);
253 ASSERT_EQ(ret, OHOS::GSERROR_OK);
254
255 ret = bp->CancelBuffer(retval2.sequence, bedata);
256 ASSERT_EQ(ret, OHOS::GSERROR_OK);
257
258 ret = bp->CancelBuffer(retval3.sequence, bedata);
259 ASSERT_NE(ret, OHOS::GSERROR_OK);
260 }
261
262 /*
263 * Function: SetQueueSize, RequestBuffer and CancelBuffer
264 * Type: Function
265 * Rank: Important(2)
266 * EnvConditions: N/A
267 * CaseDescription: 1. call SetQueueSize
268 * 2. call RequestBuffer and CancelBuffer
269 * 3. call SetQueueSize again
270 */
HWTEST_F(BufferClientProducerRemoteTest, SetQueueSizeDeleting001, Function | MediumTest | Level2)271 HWTEST_F(BufferClientProducerRemoteTest, SetQueueSizeDeleting001, Function | MediumTest | Level2)
272 {
273 GSError ret = bp->SetQueueSize(1);
274 ASSERT_EQ(ret, OHOS::GSERROR_OK);
275
276 IBufferProducer::RequestBufferReturnValue retval;
277 ret = bp->RequestBuffer(requestConfig, bedata, retval);
278 ASSERT_EQ(ret, OHOS::GSERROR_OK);
279 ASSERT_EQ(retval.buffer, nullptr);
280
281 ret = bp->CancelBuffer(retval.sequence, bedata);
282 ASSERT_EQ(ret, OHOS::GSERROR_OK);
283
284 ret = bp->SetQueueSize(2);
285 ASSERT_EQ(ret, OHOS::GSERROR_OK);
286 }
287
288 /*
289 * Function: RequestBuffer and FlushBuffer
290 * Type: Function
291 * Rank: Important(2)
292 * EnvConditions: N/A
293 * CaseDescription: 1. call RequestBuffer
294 * 2. call FlushBuffer
295 */
HWTEST_F(BufferClientProducerRemoteTest, ReqFlu001, Function | MediumTest | Level2)296 HWTEST_F(BufferClientProducerRemoteTest, ReqFlu001, Function | MediumTest | Level2)
297 {
298 IBufferProducer::RequestBufferReturnValue retval;
299 GSError ret = bp->RequestBuffer(requestConfig, bedata, retval);
300 ASSERT_EQ(ret, OHOS::GSERROR_OK);
301
302 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
303 ret = bp->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
304 ASSERT_EQ(ret, OHOS::GSERROR_OK);
305 }
306
307 /*
308 * Function: RequestBuffer and FlushBuffer
309 * Type: Function
310 * Rank: Important(2)
311 * EnvConditions: N/A
312 * CaseDescription: 1. call RequestBuffer
313 * 2. call FlushBuffer 2 times
314 */
HWTEST_F(BufferClientProducerRemoteTest, ReqFlu002, Function | MediumTest | Level2)315 HWTEST_F(BufferClientProducerRemoteTest, ReqFlu002, Function | MediumTest | Level2)
316 {
317 IBufferProducer::RequestBufferReturnValue retval;
318 GSError ret = bp->RequestBuffer(requestConfig, bedata, retval);
319 ASSERT_EQ(ret, OHOS::GSERROR_OK);
320
321 sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
322 ret = bp->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
323 ASSERT_EQ(ret, OHOS::GSERROR_OK);
324
325 ret = bp->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
326 ASSERT_NE(ret, OHOS::GSERROR_OK);
327 }
328
329 /*
330 * Function: AttachBuffer and DetachBuffer
331 * Type: Function
332 * Rank: Important(2)
333 * EnvConditions: N/A
334 * CaseDescription: 1. call AttachBuffer
335 * 2. call DetachBuffer
336 */
HWTEST_F(BufferClientProducerRemoteTest, AttachDetach001, Function | MediumTest | Level2)337 HWTEST_F(BufferClientProducerRemoteTest, AttachDetach001, Function | MediumTest | Level2)
338 {
339 sptr<OHOS::SurfaceBuffer> buffer = new SurfaceBufferImpl(0);
340 GSError ret = bp->AttachBuffer(buffer);
341 ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
342
343 ret = bp->DetachBuffer(buffer);
344 ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
345 }
346
347 /*
348 * Function: RegisterReleaseListener
349 * Type: Function
350 * Rank: Important(2)
351 * EnvConditions: N/A
352 * CaseDescription: 1. call RegisterReleaseListener
353 */
HWTEST_F(BufferClientProducerRemoteTest, RegisterReleaseListener001, Function | MediumTest | Level2)354 HWTEST_F(BufferClientProducerRemoteTest, RegisterReleaseListener001, Function | MediumTest | Level2)
355 {
356 OnReleaseFunc onBufferRelease = nullptr;
357 sptr<IProducerListener> listener = new BufferReleaseProducerListener(onBufferRelease);
358 GSError ret = bp->RegisterReleaseListener(listener);
359 ASSERT_EQ(ret, OHOS::GSERROR_OK);
360 }
361
362 /*
363 * Function: UnRegisterReleaseListener
364 * Type: Function
365 * Rank: Important(2)
366 * EnvConditions: N/A
367 * CaseDescription: 1. call UnRegisterReleaseListener
368 */
HWTEST_F(BufferClientProducerRemoteTest, UnRegisterReleaseListener001, Function | MediumTest | Level2)369 HWTEST_F(BufferClientProducerRemoteTest, UnRegisterReleaseListener001, Function | MediumTest | Level2)
370 {
371 GSError ret = bp->UnRegisterReleaseListener();
372 ASSERT_EQ(ret, OHOS::GSERROR_OK);
373 }
374
375 /*
376 * Function: GetName
377 * Type: Function
378 * Rank: Important(2)
379 * EnvConditions: N/A
380 * CaseDescription: 1. call GetName
381 */
HWTEST_F(BufferClientProducerRemoteTest, GetName001, Function | MediumTest | Level2)382 HWTEST_F(BufferClientProducerRemoteTest, GetName001, Function | MediumTest | Level2)
383 {
384 std::string name;
385 GSError ret = bp->GetName(name);
386 ASSERT_EQ(ret, OHOS::GSERROR_OK);
387 }
388
389 /*
390 * Function: GetUniqueId
391 * Type: Function
392 * Rank: Important(2)
393 * EnvConditions: N/A
394 * CaseDescription: 1. call GetUniqueId
395 */
HWTEST_F(BufferClientProducerRemoteTest, GetUniqueId001, Function | MediumTest | Level2)396 HWTEST_F(BufferClientProducerRemoteTest, GetUniqueId001, Function | MediumTest | Level2)
397 {
398 uint64_t bpid = bp->GetUniqueId();
399 ASSERT_NE(bpid, 0);
400 string name;
401 GSError ret = bp->GetNameAndUniqueId(name, bpid);
402 ASSERT_EQ(ret, OHOS::GSERROR_OK);
403 ASSERT_NE(bpid, 0);
404 ASSERT_NE(bpid, 0);
405 }
406
407 /*
408 * Function: GetDefaultUsage
409 * Type: Function
410 * Rank: Important(2)
411 * EnvConditions: N/A
412 * CaseDescription: 1. call GetDefaultUsage
413 */
HWTEST_F(BufferClientProducerRemoteTest, GetDefaultUsage001, Function | MediumTest | Level2)414 HWTEST_F(BufferClientProducerRemoteTest, GetDefaultUsage001, Function | MediumTest | Level2)
415 {
416 uint64_t usage = bp->GetDefaultUsage();
417 ASSERT_EQ(usage, 0);
418 }
419
420 /*
421 * Function: SetTransform
422 * Type: Function
423 * Rank: Important(2)
424 * EnvConditions: N/A
425 * CaseDescription: 1. call SetTransform
426 */
HWTEST_F(BufferClientProducerRemoteTest, SetTransform001, Function | MediumTest | Level2)427 HWTEST_F(BufferClientProducerRemoteTest, SetTransform001, Function | MediumTest | Level2)
428 {
429 GraphicTransformType transform = GraphicTransformType::GRAPHIC_ROTATE_90;
430 GSError ret = bp->SetTransform(transform);
431 ASSERT_EQ(ret, OHOS::GSERROR_OK);
432 GraphicTransformType transform2 = GraphicTransformType::GRAPHIC_ROTATE_NONE;
433 ASSERT_EQ(bp->GetTransform(transform2), OHOS::GSERROR_OK);
434 ASSERT_EQ(transform, transform2);
435 }
436
437 /*
438 * Function: IsSupportedAlloc
439 * Type: Function
440 * Rank: Important(2)
441 * EnvConditions: N/A
442 * CaseDescription: 1. call IsSupportedAlloc with abnormal parameters and check ret
443 */
HWTEST_F(BufferClientProducerRemoteTest, isSupportedAlloc001, Function | MediumTest | Level2)444 HWTEST_F(BufferClientProducerRemoteTest, isSupportedAlloc001, Function | MediumTest | Level2)
445 {
446 std::vector<BufferVerifyAllocInfo> infos;
447 std::vector<bool> supporteds;
448 GSError ret = bp->IsSupportedAlloc(infos, supporteds);
449 ASSERT_EQ(ret, OHOS::GSERROR_OK);
450 }
451
452 /*
453 * Function: IsSupportedAlloc
454 * Type: Function
455 * Rank: Important(2)
456 * EnvConditions: N/A
457 * CaseDescription: 1. call IsSupportedAlloc with abnormal parameters and check ret
458 */
HWTEST_F(BufferClientProducerRemoteTest, isSupportedAlloc002, Function | MediumTest | Level2)459 HWTEST_F(BufferClientProducerRemoteTest, isSupportedAlloc002, Function | MediumTest | Level2)
460 {
461 std::vector<BufferVerifyAllocInfo> infos;
462 std::vector<bool> supporteds;
463 GSError ret = bp->IsSupportedAlloc(infos, supporteds);
464 ASSERT_EQ(ret, OHOS::GSERROR_OK);
465
466 BufferVerifyAllocInfo info = {
467 .width = 0x100,
468 .height = 0x100,
469 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
470 .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
471 };
472 infos.push_back(info);
473 info.format = GRAPHIC_PIXEL_FMT_YCRCB_420_SP;
474 infos.push_back(info);
475 info.format = GRAPHIC_PIXEL_FMT_YUV_422_I;
476 infos.push_back(info);
477
478 ret = bp->IsSupportedAlloc(infos, supporteds);
479 ASSERT_EQ(ret, OHOS::GSERROR_OK);
480 }
481
482 /*
483 * Function: SetScalingMode
484 * Type: Function
485 * Rank: Important(2)
486 * EnvConditions: N/A
487 * CaseDescription: 1. call SetScalingMode with abnormal parameters and check ret
488 */
HWTEST_F(BufferClientProducerRemoteTest, SetScalingMode001, Function | MediumTest | Level2)489 HWTEST_F(BufferClientProducerRemoteTest, SetScalingMode001, Function | MediumTest | Level2)
490 {
491 ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
492 GSError ret = bp->SetScalingMode(-1, scalingMode);
493 ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
494 }
495
496 /*
497 * Function: SetScalingMode002
498 * Type: Function
499 * Rank: Important(2)
500 * EnvConditions: N/A
501 * CaseDescription: 1. call SetScalingMode with abnormal parameters and check ret
502 */
HWTEST_F(BufferClientProducerRemoteTest, SetScalingMode002, Function | MediumTest | Level2)503 HWTEST_F(BufferClientProducerRemoteTest, SetScalingMode002, Function | MediumTest | Level2)
504 {
505 ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
506 GSError ret = bp->SetScalingMode(scalingMode);
507 ASSERT_EQ(ret, OHOS::GSERROR_OK);
508 }
509
510 /*
511 * Function: SetMetaData
512 * Type: Function
513 * Rank: Important(2)
514 * EnvConditions: N/A
515 * CaseDescription: 1. call SetMetaData with abnormal parameters and check ret
516 */
HWTEST_F(BufferClientProducerRemoteTest, SetMetaData001, Function | MediumTest | Level2)517 HWTEST_F(BufferClientProducerRemoteTest, SetMetaData001, Function | MediumTest | Level2)
518 {
519 std::vector<GraphicHDRMetaData> metaData;
520 GSError ret = bp->SetMetaData(firstSeqnum, metaData);
521 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
522 }
523
524 /*
525 * Function: SetMetaDataSet
526 * Type: Function
527 * Rank: Important(2)
528 * EnvConditions: N/A
529 * CaseDescription: 1. call SetMetaDataSet with abnormal parameters and check ret
530 */
HWTEST_F(BufferClientProducerRemoteTest, SetMetaDataSet001, Function | MediumTest | Level2)531 HWTEST_F(BufferClientProducerRemoteTest, SetMetaDataSet001, Function | MediumTest | Level2)
532 {
533 GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
534 std::vector<uint8_t> metaData;
535
536 GSError ret = bp->SetMetaDataSet(firstSeqnum, key, metaData);
537 ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
538 }
539
540 /*
541 * Function: GoBackground
542 * Type: Function
543 * Rank: Important(2)
544 * EnvConditions: N/A
545 * CaseDescription: 1. call GoBackground
546 */
HWTEST_F(BufferClientProducerRemoteTest, GoBackground001, Function | MediumTest | Level2)547 HWTEST_F(BufferClientProducerRemoteTest, GoBackground001, Function | MediumTest | Level2)
548 {
549 GSError ret = bp->GoBackground();
550 ASSERT_EQ(ret, OHOS::GSERROR_OK);
551 }
552
553 /*
554 * Function: AttachBuffer
555 * Type: Function
556 * Rank: Important(2)
557 * EnvConditions: N/A
558 * CaseDescription: 1. call AttachBuffer
559 */
HWTEST_F(BufferClientProducerRemoteTest, AttachBuffer001, Function | MediumTest | Level2)560 HWTEST_F(BufferClientProducerRemoteTest, AttachBuffer001, Function | MediumTest | Level2)
561 {
562 GSError ret = bp->CleanCache(false);
563 sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
564 ASSERT_NE(buffer, nullptr);
565 ret = buffer->Alloc(requestConfig);
566 ASSERT_EQ(ret, OHOS::GSERROR_OK);
567 sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
568 int32_t timeOut = 1;
569 ret = bp->AttachBuffer(buffer, timeOut);
570 ASSERT_EQ(ret, OHOS::GSERROR_OK);
571 }
572
573 /*
574 * Function: SetSurfaceSourceType and GetSurfaceSourceType
575 * Type: Function
576 * Rank: Important(2)
577 * EnvConditions: N/A
578 * CaseDescription: 1. call GetSurfaceSourceType for default
579 * 2. call SetSurfaceSourceType and check the ret
580 */
HWTEST_F(BufferClientProducerRemoteTest, SurfaceSourceType001, Function | MediumTest | Level2)581 HWTEST_F(BufferClientProducerRemoteTest, SurfaceSourceType001, Function | MediumTest | Level2)
582 {
583 OHSurfaceSource sourceType;
584 bp->GetSurfaceSourceType(sourceType);
585 ASSERT_EQ(sourceType, OH_SURFACE_SOURCE_DEFAULT);
586
587 GSError ret = bp->SetSurfaceSourceType(OH_SURFACE_SOURCE_VIDEO);
588 ASSERT_EQ(ret, OHOS::GSERROR_OK);
589 bp->GetSurfaceSourceType(sourceType);
590 ASSERT_EQ(sourceType, OH_SURFACE_SOURCE_VIDEO);
591 }
592
593 /*
594 * Function: SetSurfaceAppFrameworkType and GetSurfaceAppFrameworkType
595 * Type: Function
596 * Rank: Important(2)
597 * EnvConditions: N/A
598 * CaseDescription: 1. call GetSurfaceAppFrameworkType for default
599 * 2. call SetSurfaceAppFrameworkType and check the ret
600 */
HWTEST_F(BufferClientProducerRemoteTest, SurfaceAppFrameworkType001, Function | MediumTest | Level2)601 HWTEST_F(BufferClientProducerRemoteTest, SurfaceAppFrameworkType001, Function | MediumTest | Level2)
602 {
603 std::string appFrameworkType;
604 bp->GetSurfaceAppFrameworkType(appFrameworkType);
605 ASSERT_EQ(appFrameworkType, "");
606
607 GSError ret = bp->SetSurfaceAppFrameworkType("test");
608 ASSERT_EQ(ret, OHOS::GSERROR_OK);
609 bp->GetSurfaceAppFrameworkType(appFrameworkType);
610 ASSERT_EQ(appFrameworkType, "test");
611 }
612 /*
613 * Function: RequestBuffersAndFlushBuffers
614 * Type: Function
615 * Rank: Important(1)
616 * EnvConditions: N/A
617 * CaseDescription: 1. call RequestBuffers and FlushBuffers
618 * @tc.require: issueI5GMZN issueI5IWHW
619 */
HWTEST_F(BufferClientProducerRemoteTest, RequestBuffersAndFlushBuffers, Function | MediumTest | Level2)620 HWTEST_F(BufferClientProducerRemoteTest, RequestBuffersAndFlushBuffers, Function | MediumTest | Level2)
621 {
622 constexpr uint32_t size = 12;
623 bp->SetQueueSize(size);
624 std::vector<IBufferProducer::RequestBufferReturnValue> retvalues;
625 std::vector<sptr<BufferExtraData>> bedatas;
626 std::vector<BufferFlushConfigWithDamages> flushConfigs;
627 retvalues.resize(size);
628 GSError ret = bp->RequestBuffers(requestConfig, bedatas, retvalues);
629 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
630 for (uint32_t i = 0; i < size * 10; ++i) {
631 sptr<BufferExtraData> data = new BufferExtraDataImpl;
632 bedatas.emplace_back(data);
633 flushConfigs.emplace_back(flushConfig);
634 }
635 ret = bp->RequestBuffers(requestConfig, bedatas, retvalues);
636 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
637 bedatas.resize(size);
638 ret = bp->RequestBuffers(requestConfig, bedatas, retvalues);
639 EXPECT_EQ(ret, OHOS::GSERROR_OK);
640 for (const auto &retval : retvalues) {
641 EXPECT_NE(retval.buffer, nullptr);
642 }
643 std::cout << "request buffers ok\n";
644 std::vector<sptr<SyncFence>> acquireFences;
645 std::vector<uint32_t> sequences;
646 ret = bp->FlushBuffers(sequences, bedatas, acquireFences, flushConfigs);
647 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
648 for (const auto &i : retvalues) {
649 sequences.emplace_back(i.sequence);
650 }
651 for (uint32_t i = 0; i < size * 10; ++i) {
652 acquireFences.emplace_back(new SyncFence(-1));
653 sequences.emplace_back(i);
654 }
655 ret = bp->FlushBuffers(sequences, bedatas, acquireFences, flushConfigs);
656 EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
657 sequences.resize(retvalues.size());
658 acquireFences.resize(retvalues.size());
659 ret = bp->FlushBuffers(sequences, bedatas, acquireFences, flushConfigs);
660 EXPECT_EQ(ret, OHOS::GSERROR_OK);
661 }
662
663 /*
664 * Function: SetBufferhold
665 * Type: Function
666 * Rank: Important(1)
667 * EnvConditions: N/A
668 * CaseDescription: 1. call SetBufferhold and check ret
669 * @tc.require: issueI5GMZN issueI5IWHW
670 */
HWTEST_F(BufferClientProducerRemoteTest, SetBufferhold001, Function | MediumTest | Level2)671 HWTEST_F(BufferClientProducerRemoteTest, SetBufferhold001, Function | MediumTest | Level2)
672 {
673 EXPECT_EQ(bp->SetBufferHold(true), GSERROR_OK);
674 EXPECT_EQ(bp->SetBufferHold(false), GSERROR_OK);
675 }
676
677 /*
678 * Function: SetWhitePointBrightness
679 * Type: Function
680 * Rank: Important(1)
681 * EnvConditions: N/A
682 * CaseDescription: 1. call SetWhitePointBrightness and check ret
683 * @tc.require: issueI5GMZN issueI5IWHW
684 */
HWTEST_F(BufferClientProducerRemoteTest, SetWhitePointBrightness001, Function | MediumTest | Level2)685 HWTEST_F(BufferClientProducerRemoteTest, SetWhitePointBrightness001, Function | MediumTest | Level2)
686 {
687 EXPECT_EQ(bp->SetHdrWhitePointBrightness(1), GSERROR_OK);
688 EXPECT_EQ(bp->SetSdrWhitePointBrightness(1), GSERROR_OK);
689 }
690
691 /*
692 * Function: AcquireAndReleaseLastFlushedBuffer
693 * Type: Function
694 * Rank: Important(1)
695 * EnvConditions: N/A
696 * CaseDescription: 1. call AcquireLastFlushedBuffer and check the ret
697 * 2. call ReleaseLastFlushedBuffer and check the ret
698 */
HWTEST_F(BufferClientProducerRemoteTest, AcquireAndReleaseLastFlushedBuffer001, Function | MediumTest | Level2)699 HWTEST_F(BufferClientProducerRemoteTest, AcquireAndReleaseLastFlushedBuffer001, Function | MediumTest | Level2)
700 {
701 sptr<SurfaceBuffer> buffer;
702 sptr<SyncFence> fence;
703 float matrix[16];
704 GSError ret = bp->AcquireLastFlushedBuffer(buffer, fence, matrix, 16, false);
705 EXPECT_EQ(ret, OHOS::GSERROR_OK);
706 EXPECT_NE(buffer, nullptr);
707 ret = bp->ReleaseLastFlushedBuffer(buffer->GetSeqNum());
708 EXPECT_EQ(ret, OHOS::GSERROR_OK);
709 }
710
711 /*
712 * Function: AttachAndDetachBuffer
713 * Type: Function
714 * Rank: Important(1)
715 * EnvConditions: N/A
716 * CaseDescription: 1. call AttachBufferFromQueue and check the ret
717 * 2. call DetachBufferFromQueue and check the ret
718 */
HWTEST_F(BufferClientProducerRemoteTest, AcquireLastFlushedBuffer001, Function | MediumTest | Level2)719 HWTEST_F(BufferClientProducerRemoteTest, AcquireLastFlushedBuffer001, Function | MediumTest | Level2)
720 {
721 sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
722 GSError ret = bp->AttachBufferToQueue(buffer);
723 ASSERT_NE(ret, OHOS::GSERROR_OK);
724 ret = bp->DetachBufferFromQueue(buffer);
725 ASSERT_NE(ret, OHOS::GSERROR_OK);
726 }
727
728 /*
729 * Function: SetGlobalAlpha
730 * Type: Function
731 * Rank: Important(1)
732 * EnvConditions: N/A
733 * CaseDescription: 1. call SetGlobalAlpha and check the ret
734 * 2. call DetachBufferFromQueue and check the ret
735 */
HWTEST_F(BufferClientProducerRemoteTest, SetGlobalAlpha001, Function | MediumTest | Level2)736 HWTEST_F(BufferClientProducerRemoteTest, SetGlobalAlpha001, Function | MediumTest | Level2)
737 {
738 ASSERT_EQ(bp->SetGlobalAlpha(-1), OHOS::GSERROR_OK);
739 ASSERT_EQ(bp->SetGlobalAlpha(255), OHOS::GSERROR_OK);
740 }
741 }
742