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