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