• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <chrono>
16 #include <thread>
17 #include <vector>
18 #include <fcntl.h>
19 #include <sys/wait.h>
20 #include <sys/mman.h>
21 #include <unistd.h>
22 #include <gtest/gtest.h>
23 
24 #include <iservice_registry.h>
25 #include <surface.h>
26 #include <buffer_extra_data_impl.h>
27 #include <buffer_client_producer.h>
28 #include <buffer_queue_producer.h>
29 #include "buffer_consumer_listener.h"
30 #include "sync_fence.h"
31 #include "accesstoken_kit.h"
32 #include "nativetoken_kit.h"
33 #include "token_setproc.h"
34 #include <buffer_producer_listener.h>
35 
36 using namespace testing;
37 using namespace testing::ext;
38 
39 namespace OHOS::Rosen {
40 class BufferClientProducerRemoteTest : public testing::Test {
41 public:
42     static void SetUpTestCase();
43     static void TearDownTestCase();
44 
45     static inline BufferRequestConfig requestConfig = {
46         .width = 0x100,
47         .height = 0x100,
48         .strideAlignment = 0x8,
49         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
50         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
51         .timeout = 0,
52         .transform = GraphicTransformType::GRAPHIC_ROTATE_90,
53         .colorGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_NATIVE,
54     };
55     static inline BufferFlushConfigWithDamages flushConfig = {
56         .damages = {
57             {
58                 .w = 0x100,
59                 .h = 0x100,
60             }
61         },
62     };
63     static inline sptr<IRemoteObject> robj = nullptr;
64     static inline sptr<IBufferProducer> bp = nullptr;
65     static inline std::vector<uint32_t> deletingBuffers;
66     static inline pid_t pid = 0;
67     static inline int pipeFd[2] = {};
68     static inline int pipe1Fd[2] = {};
69     static inline int32_t systemAbilityID = 345135;
70     static inline sptr<BufferExtraData> bedata = new BufferExtraDataImpl;
71     static inline uint32_t firstSeqnum = 0;
72 };
73 
InitNativeTokenInfo()74 static void InitNativeTokenInfo()
75 {
76     uint64_t tokenId;
77     const char *perms[2];
78     perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC";
79     perms[1] = "ohos.permission.CAMERA";
80     NativeTokenInfoParams infoInstance = {
81         .dcapsNum = 0,
82         .permsNum = 2,
83         .aclsNum = 0,
84         .dcaps = NULL,
85         .perms = perms,
86         .acls = NULL,
87         .processName = "dcamera_client_demo",
88         .aplStr = "system_basic",
89     };
90     tokenId = GetAccessTokenId(&infoInstance);
91     SetSelfTokenID(tokenId);
92     int32_t ret = Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
93     ASSERT_EQ(ret, Security::AccessToken::RET_SUCCESS);
94     std::this_thread::sleep_for(std::chrono::milliseconds(50));  // wait 50ms
95 }
96 
SetUpTestCase()97 void BufferClientProducerRemoteTest::SetUpTestCase()
98 {
99     if (pipe(pipeFd) < 0) {
100         exit(1);
101     }
102     if (pipe(pipe1Fd) < 0) {
103         exit(0);
104     }
105     pid = fork();
106     if (pid < 0) {
107         exit(1);
108     }
109     if (pid == 0) {
110         InitNativeTokenInfo();
111         sptr<BufferQueue> bq = new BufferQueue("test");
112         ASSERT_NE(bq, nullptr);
113         sptr<BufferQueueProducer> bqp = new BufferQueueProducer(bq);
114         ASSERT_NE(bqp, nullptr);
115         sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
116         bq->RegisterConsumerListener(listener);
117         auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
118         sam->AddSystemAbility(systemAbilityID, bqp);
119         close(pipeFd[1]);
120         close(pipe1Fd[0]);
121         char buf[10] = "start";
122         write(pipe1Fd[1], buf, sizeof(buf));
123         sleep(0);
124         read(pipeFd[0], buf, sizeof(buf));
125         sam->RemoveSystemAbility(systemAbilityID);
126         close(pipeFd[0]);
127         close(pipe1Fd[1]);
128         exit(0);
129     } else {
130         close(pipeFd[0]);
131         close(pipe1Fd[1]);
132         char buf[10];
133         read(pipe1Fd[0], buf, sizeof(buf));
134         auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
135         robj = sam->GetSystemAbility(systemAbilityID);
136         bp = iface_cast<IBufferProducer>(robj);
137     }
138 }
139 
TearDownTestCase()140 void BufferClientProducerRemoteTest::TearDownTestCase()
141 {
142     bp = nullptr;
143     robj = nullptr;
144 
145     char buf[10] = "over";
146     write(pipeFd[1], buf, sizeof(buf));
147     close(pipeFd[1]);
148     close(pipe1Fd[0]);
149 
150     int32_t ret = 0;
151     do {
152         waitpid(pid, nullptr, 0);
153     } while (ret == -1 && errno == EINTR);
154 }
155 
156 /*
157 * Function: IsProxyObject
158 * Type: Function
159 * Rank: Important(2)
160 * EnvConditions: N/A
161 * CaseDescription: 1. check ret for IsProxyObject func
162  */
163 HWTEST_F(BufferClientProducerRemoteTest, IsProxy001, TestSize.Level0)
164 {
165     ASSERT_TRUE(robj->IsProxyObject());
166 }
167 
168 /*
169 * Function: SetQueueSize and GetQueueSize
170 * Type: Function
171 * Rank: Important(2)
172 * EnvConditions: N/A
173 * CaseDescription: 1. call GetQueueSize for default
174 *                  2. call SetQueueSize and check the ret of GetQueueSize
175  */
176 HWTEST_F(BufferClientProducerRemoteTest, QueueSize001, TestSize.Level0)
177 {
178     ASSERT_EQ(bp->GetQueueSize(), (uint32_t)SURFACE_DEFAULT_QUEUE_SIZE);
179 
180     GSError ret = bp->SetQueueSize(2);
181     ASSERT_EQ(ret, OHOS::GSERROR_OK);
182 
183     ret = bp->SetQueueSize(SURFACE_MAX_QUEUE_SIZE + 1);
184     ASSERT_NE(ret, OHOS::GSERROR_OK);
185 
186     ASSERT_EQ(bp->GetQueueSize(), 2u);
187 }
188 
189 /*
190 * Function: SetQueueSize and GetQueueSize
191 * Type: Function
192 * Rank: Important(2)
193 * EnvConditions: N/A
194 * CaseDescription: 1. call GetQueueSize for default
195 *                  2. call SetQueueSize and check the ret of GetQueueSize
196  */
197 HWTEST_F(BufferClientProducerRemoteTest, ReqCan001, TestSize.Level0)
198 {
199     IBufferProducer::RequestBufferReturnValue retval;
200     GSError ret = bp->RequestBuffer(requestConfig, bedata, retval);
201     ASSERT_EQ(ret, OHOS::GSERROR_OK);
202     ASSERT_NE(retval.buffer, nullptr);
203     firstSeqnum = retval.buffer->GetSeqNum();
204 
205     ret = bp->CancelBuffer(retval.sequence, bedata);
206     ASSERT_EQ(ret, OHOS::GSERROR_OK);
207 }
208 
209 /*
210 * Function: RequestBuffer and CancelBuffer
211 * Type: Function
212 * Rank: Important(2)
213 * EnvConditions: N/A
214 * CaseDescription: 1. call RequestBuffer
215 *                  2. call CancelBuffer 2 times
216  */
217 HWTEST_F(BufferClientProducerRemoteTest, ReqCan002, TestSize.Level0)
218 {
219     IBufferProducer::RequestBufferReturnValue retval;
220     GSError ret = bp->RequestBuffer(requestConfig, bedata, retval);
221     ASSERT_EQ(ret, OHOS::GSERROR_OK);
222     ASSERT_EQ(retval.buffer, nullptr);
223 
224     ret = bp->CancelBuffer(retval.sequence, bedata);
225     ASSERT_EQ(ret, OHOS::GSERROR_OK);
226 
227     ret = bp->CancelBuffer(retval.sequence, bedata);
228     ASSERT_NE(ret, OHOS::GSERROR_OK);
229 }
230 
231 /*
232 * Function: RequestBuffer and CancelBuffer
233 * Type: Function
234 * Rank: Important(2)
235 * EnvConditions: N/A
236 * CaseDescription: 1. call RequestBuffer and CancelBuffer 3 times
237  */
238 HWTEST_F(BufferClientProducerRemoteTest, ReqCan003, TestSize.Level0)
239 {
240     IBufferProducer::RequestBufferReturnValue retval1;
241     IBufferProducer::RequestBufferReturnValue retval2;
242     IBufferProducer::RequestBufferReturnValue retval3;
243     GSError ret;
244 
245     ret = bp->RequestBuffer(requestConfig, bedata, retval1);
246     ASSERT_EQ(ret, OHOS::GSERROR_OK);
247     ASSERT_EQ(retval1.buffer, nullptr);
248 
249     ret = bp->RequestBuffer(requestConfig, bedata, retval2);
250     ASSERT_EQ(ret, OHOS::GSERROR_OK);
251     ASSERT_NE(retval2.buffer, nullptr);
252 
253     ret = bp->RequestBuffer(requestConfig, bedata, retval3);
254     ASSERT_NE(ret, OHOS::GSERROR_OK);
255     ASSERT_EQ(retval3.buffer, nullptr);
256 
257     ret = bp->CancelBuffer(retval1.sequence, bedata);
258     ASSERT_EQ(ret, OHOS::GSERROR_OK);
259 
260     ret = bp->CancelBuffer(retval2.sequence, bedata);
261     ASSERT_EQ(ret, OHOS::GSERROR_OK);
262 
263     ret = bp->CancelBuffer(retval3.sequence, bedata);
264     ASSERT_NE(ret, OHOS::GSERROR_OK);
265 }
266 
267 /*
268 * Function: SetQueueSize, RequestBuffer and CancelBuffer
269 * Type: Function
270 * Rank: Important(2)
271 * EnvConditions: N/A
272 * CaseDescription: 1. call SetQueueSize
273 *                  2. call RequestBuffer and CancelBuffer
274 *                  3. call SetQueueSize again
275  */
276 HWTEST_F(BufferClientProducerRemoteTest, SetQueueSizeDeleting001, TestSize.Level0)
277 {
278     GSError ret = bp->SetQueueSize(1);
279     ASSERT_EQ(ret, OHOS::GSERROR_OK);
280 
281     IBufferProducer::RequestBufferReturnValue retval;
282     ret = bp->RequestBuffer(requestConfig, bedata, retval);
283     ASSERT_EQ(ret, OHOS::GSERROR_OK);
284     ASSERT_EQ(retval.buffer, nullptr);
285 
286     ret = bp->CancelBuffer(retval.sequence, bedata);
287     ASSERT_EQ(ret, OHOS::GSERROR_OK);
288 
289     ret = bp->SetQueueSize(2);
290     ASSERT_EQ(ret, OHOS::GSERROR_OK);
291 }
292 
293 /*
294 * Function: RequestBuffer and FlushBuffer
295 * Type: Function
296 * Rank: Important(2)
297 * EnvConditions: N/A
298 * CaseDescription: 1. call RequestBuffer
299 *                  2. call FlushBuffer
300  */
301 HWTEST_F(BufferClientProducerRemoteTest, ReqFlu001, TestSize.Level0)
302 {
303     IBufferProducer::RequestBufferReturnValue retval;
304     GSError ret = bp->RequestBuffer(requestConfig, bedata, retval);
305     ASSERT_EQ(ret, OHOS::GSERROR_OK);
306 
307     sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
308     bp->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_90);
309     ret = bp->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
310     ASSERT_EQ(ret, OHOS::GSERROR_OK);
311 
312     sptr<SurfaceBuffer> bufferTmp;
313     float matrix[16];
314     bool isUseNewMatrix = false;
315     ret = bp->GetLastFlushedBuffer(bufferTmp, acquireFence, matrix, isUseNewMatrix);
316     ASSERT_EQ(ret, OHOS::GSERROR_OK);
317     ASSERT_EQ(bufferTmp->GetSurfaceBufferColorGamut(), GraphicColorGamut::GRAPHIC_COLOR_GAMUT_NATIVE);
318     ASSERT_EQ(bufferTmp->GetSurfaceBufferTransform(), GraphicTransformType::GRAPHIC_ROTATE_90);
319     ASSERT_EQ(bufferTmp->GetSurfaceBufferWidth(), 0x100);
320     ASSERT_EQ(bufferTmp->GetSurfaceBufferHeight(), 0x100);
321 }
322 
323 /*
324 * Function: RequestBuffer and FlushBuffer
325 * Type: Function
326 * Rank: Important(2)
327 * EnvConditions: N/A
328 * CaseDescription: 1. call RequestBuffer
329 *                  2. call FlushBuffer 2 times
330  */
331 HWTEST_F(BufferClientProducerRemoteTest, ReqFlu002, TestSize.Level0)
332 {
333     IBufferProducer::RequestBufferReturnValue retval;
334     GSError ret = bp->RequestBuffer(requestConfig, bedata, retval);
335     ASSERT_EQ(ret, OHOS::GSERROR_OK);
336 
337     sptr<SyncFence> acquireFence = SyncFence::INVALID_FENCE;
338     ret = bp->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
339     ASSERT_EQ(ret, OHOS::GSERROR_OK);
340 
341     ret = bp->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig);
342     ASSERT_NE(ret, OHOS::GSERROR_OK);
343 }
344 
345 /*
346 * Function: AttachBuffer and DetachBuffer
347 * Type: Function
348 * Rank: Important(2)
349 * EnvConditions: N/A
350 * CaseDescription: 1. call AttachBuffer
351 *                  2. call DetachBuffer
352 */
353 HWTEST_F(BufferClientProducerRemoteTest, AttachDetach001, TestSize.Level0)
354 {
355     sptr<OHOS::SurfaceBuffer> buffer = new SurfaceBufferImpl(0);
356     GSError ret = bp->AttachBuffer(buffer);
357     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
358 
359     ret = bp->DetachBuffer(buffer);
360     ASSERT_EQ(ret, OHOS::GSERROR_NOT_SUPPORT);
361 }
362 
363 /*
364 * Function: RegisterReleaseListener
365 * Type: Function
366 * Rank: Important(2)
367 * EnvConditions: N/A
368 * CaseDescription: 1. call RegisterReleaseListener
369 */
370 HWTEST_F(BufferClientProducerRemoteTest, RegisterReleaseListener001, TestSize.Level0)
371 {
372     OnReleaseFunc onBufferRelease = nullptr;
373     sptr<IProducerListener> listener = new BufferReleaseProducerListener(onBufferRelease);
374     GSError ret = bp->RegisterReleaseListener(listener);
375     ASSERT_EQ(ret, OHOS::GSERROR_OK);
376 }
377 
378 /*
379 * Function: RegisterReleaseListenerBackup
380 * Type: Function
381 * Rank: Important(2)
382 * EnvConditions: N/A
383 * CaseDescription: 1. call RegisterReleaseListenerBackup
384 */
385 HWTEST_F(BufferClientProducerRemoteTest, RegisterReleaseListenerBackup001, TestSize.Level0)
386 {
387     OnReleaseFuncWithFence onBufferReleaseWithFence = nullptr;
388     sptr<IProducerListener> listener = new BufferReleaseProducerListener(nullptr, onBufferReleaseWithFence);
389     GSError ret = bp->RegisterReleaseListenerBackup(listener);
390     ASSERT_EQ(ret, OHOS::GSERROR_OK);
391 }
392 
393 /*
394 * Function: UnRegisterReleaseListener
395 * Type: Function
396 * Rank: Important(2)
397 * EnvConditions: N/A
398 * CaseDescription: 1. call UnRegisterReleaseListener
399 */
400 HWTEST_F(BufferClientProducerRemoteTest, UnRegisterReleaseListener001, TestSize.Level0)
401 {
402     GSError ret = bp->UnRegisterReleaseListener();
403     ASSERT_EQ(ret, OHOS::GSERROR_OK);
404 }
405 
406 /*
407 * Function: UnRegisterReleaseListenerBackup
408 * Type: Function
409 * Rank: Important(2)
410 * EnvConditions: N/A
411 * CaseDescription: 1. call UnRegisterReleaseListenerBackup
412 */
413 HWTEST_F(BufferClientProducerRemoteTest, UnRegisterReleaseListenerBackup001, TestSize.Level0)
414 {
415     GSError ret = bp->UnRegisterReleaseListenerBackup();
416     ASSERT_EQ(ret, OHOS::GSERROR_OK);
417 }
418 
419 /*
420 * Function: GetName
421 * Type: Function
422 * Rank: Important(2)
423 * EnvConditions: N/A
424 * CaseDescription: 1. call GetName
425 */
426 HWTEST_F(BufferClientProducerRemoteTest, GetName001, TestSize.Level0)
427 {
428     std::string name;
429     GSError ret = bp->GetName(name);
430     ASSERT_EQ(ret, OHOS::GSERROR_OK);
431 }
432 
433 /*
434 * Function: GetUniqueId
435 * Type: Function
436 * Rank: Important(2)
437 * EnvConditions: N/A
438 * CaseDescription: 1. call GetUniqueId
439 */
440 HWTEST_F(BufferClientProducerRemoteTest, GetUniqueId001, TestSize.Level0)
441 {
442     uint64_t bpid = bp->GetUniqueId();
443     ASSERT_NE(bpid, 0);
444     string name;
445     GSError ret = bp->GetNameAndUniqueId(name, bpid);
446     ASSERT_EQ(ret, OHOS::GSERROR_OK);
447     ASSERT_NE(bpid, 0);
448     ASSERT_NE(bpid, 0);
449 }
450 
451 /*
452 * Function: GetDefaultUsage
453 * Type: Function
454 * Rank: Important(2)
455 * EnvConditions: N/A
456 * CaseDescription: 1. call GetDefaultUsage
457 */
458 HWTEST_F(BufferClientProducerRemoteTest, GetDefaultUsage001, TestSize.Level0)
459 {
460     uint64_t usage = bp->GetDefaultUsage();
461     ASSERT_EQ(usage, 0);
462 }
463 
464 /*
465 * Function: SetTransform
466 * Type: Function
467 * Rank: Important(2)
468 * EnvConditions: N/A
469 * CaseDescription: 1. call SetTransform
470 */
471 HWTEST_F(BufferClientProducerRemoteTest, SetTransform001, TestSize.Level0)
472 {
473     GraphicTransformType transform = GraphicTransformType::GRAPHIC_ROTATE_90;
474     GSError ret = bp->SetTransform(transform);
475     ASSERT_EQ(ret, OHOS::GSERROR_OK);
476     GraphicTransformType transform2 = GraphicTransformType::GRAPHIC_ROTATE_NONE;
477     ASSERT_EQ(bp->GetTransform(transform2), OHOS::GSERROR_OK);
478     ASSERT_EQ(transform, transform2);
479 }
480 
481 /*
482 * Function: SetScalingMode
483 * Type: Function
484 * Rank: Important(2)
485 * EnvConditions: N/A
486 * CaseDescription: 1. call SetScalingMode with abnormal parameters and check ret
487 */
488 HWTEST_F(BufferClientProducerRemoteTest, SetScalingMode001, TestSize.Level0)
489 {
490     ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
491     GSError ret = bp->SetScalingMode(-1, scalingMode);
492     ASSERT_EQ(ret, OHOS::GSERROR_NO_ENTRY);
493 }
494 
495 /*
496 * Function: SetScalingMode002
497 * Type: Function
498 * Rank: Important(2)
499 * EnvConditions: N/A
500 * CaseDescription: 1. call SetScalingMode with abnormal parameters and check ret
501 */
502 HWTEST_F(BufferClientProducerRemoteTest, SetScalingMode002, TestSize.Level0)
503 {
504     ScalingMode scalingMode = ScalingMode::SCALING_MODE_SCALE_TO_WINDOW;
505     GSError ret = bp->SetScalingMode(scalingMode);
506     ASSERT_EQ(ret, OHOS::GSERROR_OK);
507 }
508 
509 /*
510 * Function: SetMetaData
511 * Type: Function
512 * Rank: Important(2)
513 * EnvConditions: N/A
514 * CaseDescription: 1. call SetMetaData with abnormal parameters and check ret
515 */
516 HWTEST_F(BufferClientProducerRemoteTest, SetMetaData001, TestSize.Level0)
517 {
518     std::vector<GraphicHDRMetaData> metaData;
519     GSError ret = bp->SetMetaData(firstSeqnum, metaData);
520     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
521 }
522 
523 /*
524 * Function: SetMetaDataSet
525 * Type: Function
526 * Rank: Important(2)
527 * EnvConditions: N/A
528 * CaseDescription: 1. call SetMetaDataSet with abnormal parameters and check ret
529 */
530 HWTEST_F(BufferClientProducerRemoteTest, SetMetaDataSet001, TestSize.Level0)
531 {
532     GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_HDR10_PLUS;
533     std::vector<uint8_t> metaData;
534 
535     GSError ret = bp->SetMetaDataSet(firstSeqnum, key, metaData);
536     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
537 }
538 
539 /*
540 * Function: GoBackground
541 * Type: Function
542 * Rank: Important(2)
543 * EnvConditions: N/A
544 * CaseDescription: 1. call GoBackground
545 */
546 HWTEST_F(BufferClientProducerRemoteTest, GoBackground001, TestSize.Level0)
547 {
548     GSError ret = bp->GoBackground();
549     ASSERT_EQ(ret, OHOS::GSERROR_OK);
550 }
551 
552 /*
553 * Function: AttachBuffer
554 * Type: Function
555 * Rank: Important(2)
556 * EnvConditions: N/A
557 * CaseDescription: 1. call AttachBuffer
558 */
559 HWTEST_F(BufferClientProducerRemoteTest, AttachBuffer001, TestSize.Level0)
560 {
561     GSError ret = bp->CleanCache(false);
562     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
563     ASSERT_NE(buffer, nullptr);
564     ret = buffer->Alloc(requestConfig);
565     ASSERT_EQ(ret, OHOS::GSERROR_OK);
566     sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
567     int32_t timeOut = 1;
568     ret = bp->AttachBuffer(buffer, timeOut);
569     ASSERT_EQ(ret, OHOS::GSERROR_OK);
570 }
571 
572 /*
573 * Function: SetSurfaceSourceType and GetSurfaceSourceType
574 * Type: Function
575 * Rank: Important(2)
576 * EnvConditions: N/A
577 * CaseDescription: 1. call GetSurfaceSourceType for default
578 *                  2. call SetSurfaceSourceType and check the ret
579 */
580 HWTEST_F(BufferClientProducerRemoteTest, SurfaceSourceType001, TestSize.Level0)
581 {
582     OHSurfaceSource sourceType;
583     bp->GetSurfaceSourceType(sourceType);
584     ASSERT_EQ(sourceType, OH_SURFACE_SOURCE_DEFAULT);
585 
586     GSError ret = bp->SetSurfaceSourceType(OH_SURFACE_SOURCE_VIDEO);
587     ASSERT_EQ(ret, OHOS::GSERROR_OK);
588     bp->GetSurfaceSourceType(sourceType);
589     ASSERT_EQ(sourceType, OH_SURFACE_SOURCE_VIDEO);
590 }
591 
592 /*
593 * Function: SetSurfaceAppFrameworkType and GetSurfaceAppFrameworkType
594 * Type: Function
595 * Rank: Important(2)
596 * EnvConditions: N/A
597 * CaseDescription: 1. call GetSurfaceAppFrameworkType for default
598 *                  2. call SetSurfaceAppFrameworkType and check the ret
599 */
600 HWTEST_F(BufferClientProducerRemoteTest, SurfaceAppFrameworkType001, TestSize.Level0)
601 {
602     std::string appFrameworkType;
603     bp->GetSurfaceAppFrameworkType(appFrameworkType);
604     ASSERT_EQ(appFrameworkType, "");
605 
606     GSError ret = bp->SetSurfaceAppFrameworkType("test");
607     ASSERT_EQ(ret, OHOS::GSERROR_OK);
608     bp->GetSurfaceAppFrameworkType(appFrameworkType);
609     ASSERT_EQ(appFrameworkType, "test");
610 }
611 /*
612 * Function: RequestBuffersAndFlushBuffers
613 * Type: Function
614 * Rank: Important(1)
615 * EnvConditions: N/A
616 * CaseDescription: 1. call RequestBuffers and FlushBuffers
617 * @tc.require: issueI5GMZN issueI5IWHW
618  */
619 HWTEST_F(BufferClientProducerRemoteTest, RequestBuffersAndFlushBuffers, TestSize.Level0)
620 {
621     constexpr uint32_t size = 12;
622     bp->SetQueueSize(size);
623     std::vector<IBufferProducer::RequestBufferReturnValue> retvalues;
624     std::vector<sptr<BufferExtraData>> bedatas;
625     std::vector<BufferFlushConfigWithDamages> flushConfigs;
626     retvalues.resize(size);
627     GSError ret = bp->RequestBuffers(requestConfig, bedatas, retvalues);
628     EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
629     for (uint32_t i = 0; i < size * 10; ++i) {
630         sptr<BufferExtraData> data = new BufferExtraDataImpl;
631         bedatas.emplace_back(data);
632         flushConfigs.emplace_back(flushConfig);
633     }
634     ret = bp->RequestBuffers(requestConfig, bedatas, retvalues);
635     EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
636     bedatas.resize(size);
637     ret = bp->RequestBuffers(requestConfig, bedatas, retvalues);
638     EXPECT_EQ(ret, OHOS::GSERROR_OK);
639     for (const auto &retval : retvalues) {
640         EXPECT_NE(retval.buffer, nullptr);
641     }
642     std::cout << "request buffers ok\n";
643     std::vector<sptr<SyncFence>> acquireFences;
644     std::vector<uint32_t> sequences;
645     ret = bp->FlushBuffers(sequences, bedatas, acquireFences, flushConfigs);
646     EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
647     for (const auto &i : retvalues) {
648         sequences.emplace_back(i.sequence);
649     }
650     for (uint32_t i = 0; i < size * 10; ++i) {
651         acquireFences.emplace_back(new SyncFence(-1));
652         sequences.emplace_back(i);
653     }
654     ret = bp->FlushBuffers(sequences, bedatas, acquireFences, flushConfigs);
655     EXPECT_EQ(ret, OHOS::SURFACE_ERROR_UNKOWN);
656     sequences.resize(retvalues.size());
657     acquireFences.resize(retvalues.size());
658     ret = bp->FlushBuffers(sequences, bedatas, acquireFences, flushConfigs);
659     EXPECT_EQ(ret, OHOS::GSERROR_OK);
660 }
661 
662 /*
663 * Function: AcquireAndReleaseLastFlushedBuffer
664 * Type: Function
665 * Rank: Important(1)
666 * EnvConditions: N/A
667 * CaseDescription: 1. call AcquireLastFlushedBuffer and check the ret
668 *                  2. call ReleaseLastFlushedBuffer and check the ret
669  */
670 HWTEST_F(BufferClientProducerRemoteTest, AcquireAndReleaseLastFlushedBuffer001, TestSize.Level0)
671 {
672     sptr<SurfaceBuffer> buffer;
673     sptr<SyncFence> fence;
674     float matrix[16];
675     GSError ret = bp->AcquireLastFlushedBuffer(buffer, fence, matrix, 16, false);
676     EXPECT_EQ(ret, OHOS::GSERROR_OK);
677     EXPECT_NE(buffer, nullptr);
678     ret = bp->ReleaseLastFlushedBuffer(buffer->GetSeqNum());
679     EXPECT_EQ(ret, OHOS::GSERROR_OK);
680 }
681 
682 /*
683 * Function: SetBufferhold
684 * Type: Function
685 * Rank: Important(1)
686 * EnvConditions: N/A
687 * CaseDescription: 1. call SetBufferhold and check ret
688 * @tc.require: issueI5GMZN issueI5IWHW
689  */
690 HWTEST_F(BufferClientProducerRemoteTest, SetBufferhold001, TestSize.Level0)
691 {
692     EXPECT_EQ(bp->SetBufferHold(true), GSERROR_OK);
693     EXPECT_EQ(bp->SetBufferHold(false), GSERROR_OK);
694 }
695 
696 /*
697 * Function: SetBufferReallocFlag
698 * Type: Function
699 * Rank: Important(1)
700 * EnvConditions: N/A
701 * CaseDescription: 1. call SetBufferReallocFlag and check ret
702 * @tc.require: issueI5GMZN issueI5IWHW
703  */
704 HWTEST_F(BufferClientProducerRemoteTest, SetBufferReallocFlag001, TestSize.Level0)
705 {
706     EXPECT_EQ(bp->SetBufferReallocFlag(true), GSERROR_OK);
707     EXPECT_EQ(bp->SetBufferReallocFlag(false), GSERROR_OK);
708 }
709 
710 /*
711 * Function: SetRequestBufferNoblockMode
712 * Type: Function
713 * Rank: Important(1)
714 * EnvConditions: N/A
715 * CaseDescription: 1. call SetRequestBufferNoblockMode and check ret
716 * @tc.require: issueICALHV
717  */
718 HWTEST_F(BufferClientProducerRemoteTest, SetRequestBufferNoblockMode001, TestSize.Level0)
719 {
720     EXPECT_EQ(bp->SetRequestBufferNoblockMode(true), GSERROR_OK);
721     EXPECT_EQ(bp->SetRequestBufferNoblockMode(false), GSERROR_OK);
722 }
723 
724 /*
725 * Function: SetWhitePointBrightness
726 * Type: Function
727 * Rank: Important(1)
728 * EnvConditions: N/A
729 * CaseDescription: 1. call SetWhitePointBrightness and check ret
730 * @tc.require: issueI5GMZN issueI5IWHW
731  */
732 HWTEST_F(BufferClientProducerRemoteTest, SetWhitePointBrightness001, TestSize.Level0)
733 {
734     EXPECT_EQ(bp->SetHdrWhitePointBrightness(1), GSERROR_OK);
735     EXPECT_EQ(bp->SetSdrWhitePointBrightness(1), GSERROR_OK);
736 }
737 
738 /*
739 * Function: AttachAndDetachBuffer
740 * Type: Function
741 * Rank: Important(1)
742 * EnvConditions: N/A
743 * CaseDescription: 1. call AttachBufferFromQueue and check the ret
744 *                  2. call DetachBufferFromQueue and check the ret
745  */
746 HWTEST_F(BufferClientProducerRemoteTest, AcquireLastFlushedBuffer001, TestSize.Level0)
747 {
748     sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
749     GSError ret = bp->AttachBufferToQueue(buffer);
750     ASSERT_NE(ret, OHOS::GSERROR_OK);
751     ret = bp->DetachBufferFromQueue(buffer);
752     ASSERT_NE(ret, OHOS::GSERROR_OK);
753 }
754 
755 /*
756 * Function: SetGlobalAlpha
757 * Type: Function
758 * Rank: Important(1)
759 * EnvConditions: N/A
760 * CaseDescription: 1. call SetGlobalAlpha and check the ret
761  */
762 HWTEST_F(BufferClientProducerRemoteTest, SetGlobalAlpha001, TestSize.Level0)
763 {
764     ASSERT_EQ(bp->SetGlobalAlpha(-1), OHOS::GSERROR_OK);
765     ASSERT_EQ(bp->SetGlobalAlpha(255), OHOS::GSERROR_OK);
766 }
767 
768 /*
769 * Function: SetGlobalAlpha
770 * Type: Function
771 * Rank: Important(1)
772 * EnvConditions: N/A
773 * CaseDescription: 1. call SetGlobalAlpha and check the ret
774  */
775 HWTEST_F(BufferClientProducerRemoteTest, SetFrameGravity001, TestSize.Level0)
776 {
777     ASSERT_EQ(bp->SetFrameGravity(-1), OHOS::GSERROR_OK);
778     ASSERT_EQ(bp->SetFrameGravity(15), OHOS::GSERROR_OK);
779 }
780 
781 /*
782 * Function: SetGlobalAlpha
783 * Type: Function
784 * Rank: Important(1)
785 * EnvConditions: N/A
786 * CaseDescription: 1. call SetGlobalAlpha and check the ret
787  */
788 HWTEST_F(BufferClientProducerRemoteTest, SetFixedRotation001, TestSize.Level0)
789 {
790     ASSERT_EQ(bp->SetFixedRotation(-1), OHOS::GSERROR_OK);
791     ASSERT_EQ(bp->SetFixedRotation(1), OHOS::GSERROR_OK);
792 }
793 
794 /**
795  * Function: SetScalingMode and GetScalingMode
796  * Type: Function
797  * Rank: Important(2)
798  * EnvConditions: N/A
799  * CaseDescription: 1. preSetUp: na
800  *                  2. operation: call RequestAndDetachBuffer and AttachAndFlushBuffer
801  *                  3. result: return OK
802  */
803 HWTEST_F(BufferClientProducerRemoteTest, RequestAndDetachBuffer001, TestSize.Level0)
804 {
805     ASSERT_EQ(bp->CleanCache(true), OHOS::GSERROR_OK);
806     BufferRequestConfig requestConfigTmp = {
807         .width = 0x100,
808         .height = 0x100,
809         .strideAlignment = 0x8,
810         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
811         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
812         .timeout = 0,
813     };
814     BufferFlushConfigWithDamages flushConfig = {
815         .damages = {
816             {
817                 .w = 0x100,
818                 .h = 0x100,
819             }
820         },
821     };
822     sptr<SurfaceBuffer> buffer = nullptr;
823     sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
824     IBufferProducer::RequestBufferReturnValue retvalTmp;
825     sptr<BufferExtraData> bedataTmp = new BufferExtraDataImpl;
826     GSError ret = bp->RequestAndDetachBuffer(requestConfigTmp, bedataTmp, retvalTmp);
827     ASSERT_EQ(ret, OHOS::GSERROR_OK);
828     ret = bp->AttachAndFlushBuffer(retvalTmp.buffer, bedataTmp, fence, flushConfig, false);
829     ASSERT_EQ(ret, OHOS::GSERROR_OK);
830     ASSERT_EQ(bp->CleanCache(true), OHOS::GSERROR_OK);
831 }
832 
833 /*
834 * Function: RegisterPropertyListener
835 * Type: Function
836 * Rank: Important(2)
837 * EnvConditions: N/A
838 * CaseDescription: 1. call RegisterPropertyListener
839 */
840 HWTEST_F(BufferClientProducerRemoteTest, RegisterPropertyListener001, TestSize.Level0)
841 {
842     OnReleaseFunc onBufferRelease = nullptr;
843     sptr<IProducerListener> listener = new BufferReleaseProducerListener(onBufferRelease);
844     GSError ret = bp->RegisterPropertyListener(listener, 0);
845     ASSERT_EQ(ret, OHOS::GSERROR_OK);
846 }
847 
848 /*
849 * Function: PreAllocBuffers
850 * Type: Function
851 * Rank: Important(1)
852 * EnvConditions: N/A
853 * CaseDescription: 1. preSetUp: call PreAllocBuffers and check the ret
854 *                  2. operation: clents sends config to producer
855 *                  3. result: All server-side asynchronous execution results return sucess
856 */
857 HWTEST_F(BufferClientProducerRemoteTest, PreAllocBuffers001, TestSize.Level0)
858 {
859     BufferRequestConfig requestConfigTmp = {
860         .width = 0x100,
861         .height = 0x100,
862         .strideAlignment = 0x8,
863         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
864         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
865     };
866     uint32_t allocBufferCount = 3;
867     GSError ret = bp->PreAllocBuffers(requestConfigTmp, allocBufferCount);
868     sleep(1); // 给alloc预留内存分配时间
869     ASSERT_EQ(ret, OHOS::GSERROR_OK);
870 }
871 
872 /*
873 * Function: UnRegisterPropertyListener
874 * Type: Function
875 * Rank: Important(2)
876 * EnvConditions: N/A
877 * CaseDescription: 1. call UnRegisterPropertyListener
878 */
879 HWTEST_F(BufferClientProducerRemoteTest, UnRegisterPropertyListener001, TestSize.Level0)
880 {
881     GSError ret = bp->UnRegisterPropertyListener(0);
882     ASSERT_EQ(ret, OHOS::GSERROR_OK);
883 }
884 /*
885  * Function: SetLppShareFd
886  * Type: Function
887  * Rank: Important(2)
888  * EnvConditions: N/A
889  * CaseDescription: call SetLppShareFd
890  */
891 HWTEST_F(BufferClientProducerRemoteTest, SetLppShareFd001, TestSize.Level0)
892 {
893     int fd = -1;
894     bool state = false;
895     GSError ret = bp->SetLppShareFd(fd, state);
896     ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
897 }
898 /*
899  * Function: SetLppShareFd
900  * Type: Function
901  * Rank: Important(2)
902  * EnvConditions: N/A
903  * CaseDescription: call SetLppShareFd
904  */
905 HWTEST_F(BufferClientProducerRemoteTest, SetLppShareFd002, TestSize.Level0)
906 {
907     int fd = open("/dev/lpptest", O_RDWR | O_CREAT, static_cast<mode_t>(0600));
908     ASSERT_NE(fd, -1);
909     ASSERT_NE(ftruncate(fd, 0x1000), -1);
910     bool state = false;
911     GSError ret = bp->SetLppShareFd(fd, state);
912     ASSERT_EQ(ret, OHOS::GSERROR_OK);
913     close(fd);
914 }
915 }
916