• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 
16 #include "av_hardware_memory.h"
17 #include "av_shared_allocator.h"
18 #include "av_shared_memory_ext.h"
19 #include "av_surface_allocator.h"
20 #include "av_surface_memory.h"
21 #include "avbuffer_unit_test.h"
22 #include "avbuffer_utils.h"
23 #include "unittest_log.h"
24 
25 using namespace std;
26 using namespace testing::ext;
27 using namespace OHOS;
28 using namespace OHOS::Media;
29 
30 namespace OHOS {
31 namespace Media {
32 namespace AVBufferUT {
33 /**
34  * @tc.name: AVBuffer_Config_001
35  * @tc.desc: compare config structs of different type
36  * @tc.type: FUNC
37  */
38 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_001, TestSize.Level1)
39 {
40     AVBufferConfig configFirst;
41     AVBufferConfig configSecond;
42     configFirst.memoryType = MemoryType::HARDWARE_MEMORY;
43     configSecond.memoryType = MemoryType::SURFACE_MEMORY;
44     EXPECT_FALSE(configFirst.memoryType <= configSecond.memoryType);
45 }
46 
47 /**
48  * @tc.name: AVBuffer_Config_002
49  * @tc.desc: compare config structs of dmabuffer
50  * @tc.type: FUNC
51  */
52 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_002, TestSize.Level1)
53 {
54     AVBufferConfig configFirst;
55     AVBufferConfig configSecond;
56     configFirst.memoryType = configSecond.memoryType = MemoryType::HARDWARE_MEMORY;
57     configFirst.size = 0;
58     configSecond.capacity = 1;
59     EXPECT_TRUE(configFirst <= configSecond);
60 
61     configFirst.size = 0;
62     configSecond.capacity = 0;
63     EXPECT_TRUE(configFirst <= configSecond);
64 
65     configFirst.size = 1;
66     configSecond.capacity = 0;
67     EXPECT_FALSE(configFirst <= configSecond);
68 
69     configFirst.size = 0;
70     configSecond.capacity = 1;
71     configFirst.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
72     configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
73     EXPECT_TRUE(configFirst <= configSecond);
74 
75     configFirst.size = 0;
76     configSecond.capacity = 1;
77     configFirst.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
78     configSecond.memoryFlag = MemoryFlag::MEMORY_READ_WRITE;
79     EXPECT_TRUE(configFirst <= configSecond);
80 
81     configFirst.size = 0;
82     configSecond.capacity = 1;
83     configFirst.memoryFlag = MemoryFlag::MEMORY_READ_WRITE;
84     configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
85     EXPECT_FALSE(configFirst <= configSecond);
86 }
87 
88 /**
89  * @tc.name: AVBuffer_Config_003
90  * @tc.desc: compare config structs of shared memory
91  * @tc.type: FUNC
92  */
93 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_003, TestSize.Level1)
94 {
95     AVBufferConfig configFirst;
96     AVBufferConfig configSecond;
97     configFirst.memoryType = configSecond.memoryType = MemoryType::SHARED_MEMORY;
98     configFirst.size = 0;
99     configSecond.capacity = 1;
100     EXPECT_TRUE(configFirst <= configSecond);
101 
102     configFirst.size = 0;
103     configSecond.capacity = 0;
104     EXPECT_TRUE(configFirst <= configSecond);
105 
106     configFirst.size = 2; // 2: first size
107     configSecond.capacity = 1;
108     configSecond.align = 2; // 2: align size
109     EXPECT_TRUE(configFirst <= configSecond);
110     configSecond.align = 0;
111 
112     configFirst.size = 1;
113     configSecond.capacity = 0;
114     EXPECT_FALSE(configFirst <= configSecond);
115 
116     configFirst.size = 0;
117     configSecond.capacity = 1;
118     configFirst.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
119     configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
120     EXPECT_TRUE(configFirst <= configSecond);
121 
122     configFirst.size = 0;
123     configSecond.capacity = 1;
124     configFirst.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
125     configSecond.memoryFlag = MemoryFlag::MEMORY_READ_WRITE;
126     EXPECT_TRUE(configFirst <= configSecond);
127 
128     configFirst.size = 0;
129     configSecond.capacity = 1;
130     configFirst.memoryFlag = MemoryFlag::MEMORY_READ_WRITE;
131     configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
132     EXPECT_FALSE(configFirst <= configSecond);
133 }
134 
135 /**
136  * @tc.name: AVBuffer_Config_004
137  * @tc.desc: compare config structs of surface memory
138  * @tc.type: FUNC
139  */
140 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_004, TestSize.Level1)
141 {
142     AVBufferConfig configFirst;
143     AVBufferConfig configSecond;
144     configFirst.memoryType = configSecond.memoryType = MemoryType::SURFACE_MEMORY;
145     configFirst.size = 1;
146     configSecond.capacity = 0;
147     EXPECT_TRUE(configFirst <= configSecond);
148 
149     configFirst.memoryFlag = MemoryFlag::MEMORY_READ_WRITE;
150     configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
151     EXPECT_TRUE(configFirst <= configSecond);
152 
153     *(configFirst.surfaceBufferConfig) = DEFAULT_CONFIG;
154     EXPECT_FALSE(configFirst <= configSecond);
155 
156     *(configFirst.surfaceBufferConfig) = DEFAULT_CONFIG;
157     *(configSecond.surfaceBufferConfig) = DEFAULT_CONFIG;
158     EXPECT_TRUE(configFirst <= configSecond);
159 }
160 
161 /**
162  * @tc.name: AVBuffer_Config_005
163  * @tc.desc: compare config structs of virual memory
164  * @tc.type: FUNC
165  */
166 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_005, TestSize.Level1)
167 {
168     AVBufferConfig configFirst;
169     AVBufferConfig configSecond;
170     configFirst.memoryType = configSecond.memoryType = MemoryType::VIRTUAL_MEMORY;
171     configFirst.size = 0;
172     configSecond.capacity = 1;
173     EXPECT_TRUE(configFirst <= configSecond);
174 
175     configFirst.size = 0;
176     configSecond.capacity = 0;
177     EXPECT_TRUE(configFirst <= configSecond);
178 
179     configFirst.size = 1;
180     configSecond.capacity = 0;
181     EXPECT_FALSE(configFirst <= configSecond);
182 
183     configFirst.size = 0;
184     configSecond.capacity = 1;
185     configFirst.memoryFlag = MemoryFlag::MEMORY_READ_WRITE;
186     configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY;
187     EXPECT_TRUE(configFirst <= configSecond);
188 
189     configFirst.size = 0;
190     configFirst.capacity = 1;
191     configSecond.size = 1;
192     configSecond.capacity = 1;
193     EXPECT_TRUE(configFirst <= configSecond);
194 
195     configFirst.size = 1;
196     configFirst.capacity = 0;
197     configSecond.size = 0;
198     configSecond.capacity = 1;
199     EXPECT_TRUE(configFirst <= configSecond);
200 
201     configFirst.size = 1;
202     configFirst.capacity = 0;
203     configSecond.size = 1;
204     configSecond.capacity = 0;
205     EXPECT_FALSE(configFirst <= configSecond);
206 }
207 
208 /**
209  * @tc.name: AVBuffer_Config_006
210  * @tc.desc: marshalled and unmarshalled config struct
211  * @tc.type: FUNC
212  */
213 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_006, TestSize.Level1)
214 {
215     AVBufferConfig configRemote;
216     configRemote.size = MEMSIZE;
217     configRemote.align = POSITION_ONE;
218     configRemote.memoryType = MemoryType::HARDWARE_MEMORY;
219     configRemote.memoryFlag = MemoryFlag::MEMORY_READ_WRITE;
220     configRemote.capacity = TEST_BUFFER_SIZE;
221     configRemote.dmaFd = 1;
222 
223     MessageParcel parcel;
224     *(configRemote.surfaceBufferConfig) = DEFAULT_CONFIG;
225     EXPECT_TRUE(MarshallingConfig(parcel, configRemote));
226 
227     AVBufferConfig configLocal;
228     EXPECT_TRUE(UnmarshallingConfig(parcel, configLocal));
229 
230     EXPECT_EQ(configRemote.size, configLocal.size);
231     EXPECT_EQ(configRemote.align, configLocal.align);
232     EXPECT_EQ(configRemote.memoryType, configLocal.memoryType);
233     EXPECT_EQ(configRemote.memoryFlag, configLocal.memoryFlag);
234     EXPECT_EQ(configRemote.capacity, configLocal.capacity);
235     EXPECT_EQ(configRemote.dmaFd, configLocal.dmaFd);
236 
237     EXPECT_EQ(configRemote.surfaceBufferConfig->width, configLocal.surfaceBufferConfig->width);
238     EXPECT_EQ(configRemote.surfaceBufferConfig->height, configLocal.surfaceBufferConfig->height);
239     EXPECT_EQ(configRemote.surfaceBufferConfig->strideAlignment, configLocal.surfaceBufferConfig->strideAlignment);
240     EXPECT_EQ(configRemote.surfaceBufferConfig->format, configLocal.surfaceBufferConfig->format);
241     EXPECT_EQ(configRemote.surfaceBufferConfig->usage, configLocal.surfaceBufferConfig->usage);
242     EXPECT_EQ(configRemote.surfaceBufferConfig->timeout, configLocal.surfaceBufferConfig->timeout);
243     EXPECT_EQ(configRemote.surfaceBufferConfig->colorGamut, configLocal.surfaceBufferConfig->colorGamut);
244     EXPECT_EQ(configRemote.surfaceBufferConfig->transform, configLocal.surfaceBufferConfig->transform);
245 }
246 
247 /**
248  * @tc.name: AVBuffer_Config_007
249  * @tc.desc: Overriding assignment operator test01
250  * @tc.type: FUNC
251  */
252 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_007, TestSize.Level1)
253 {
254     AVBufferConfig config1;
255     config1.size = MEMSIZE;
256     AVBufferConfig config2;
257     config2 = std::move(config1);
258     EXPECT_EQ(config2.size, MEMSIZE);
259 }
260 
261 /**
262  * @tc.name: AVBuffer_CreateWithInvalid_001
263  * @tc.desc: create memory with invalid parcel
264  * @tc.type: FUNC
265  */
266 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_001, TestSize.Level1)
267 {
268     parcel_ = std::make_shared<MessageParcel>();
269     buffer_ = AVBuffer::CreateAVBuffer();
270     ASSERT_FALSE(buffer_->ReadFromMessageParcel(*parcel_));
271     ASSERT_EQ(buffer_->memory_, nullptr);
272 }
273 
274 /**
275  * @tc.name: AVBuffer_CreateWithInvalid_002
276  * @tc.desc: create buffer with null allocator
277  * @tc.type: FUNC
278  */
279 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_002, TestSize.Level1)
280 {
281     buffer_ = AVBuffer::CreateAVBuffer(std::shared_ptr<AVAllocator>(nullptr));
282     EXPECT_EQ(nullptr, buffer_);
283 }
284 
285 /**
286  * @tc.name: AVBuffer_CreateWithInvalid_003
287  * @tc.desc: create virtual memory with invalid allocator
288  * @tc.type: FUNC
289  */
290 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_003, TestSize.Level1)
291 {
292     allocator_ = AVAllocatorFactory::CreateVirtualAllocator();
293     buffer_ = AVBuffer::CreateAVBuffer(allocator_, -1);
294     EXPECT_EQ(nullptr, buffer_);
295 
296     buffer_ = AVBuffer::CreateAVBuffer(allocator_, 0);
297     EXPECT_NE(nullptr, buffer_);
298 }
299 
300 /**
301  * @tc.name: AVBuffer_CreateWithInvalid_004
302  * @tc.desc: create hardware memory with invalid allocator
303  * @tc.type: FUNC
304  */
305 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_004, TestSize.Level1)
306 {
307     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
308     DmabufHeapBuffer dmaBuffer = {.size = capacity_, .heapFlags = 0};
309     int32_t dmaHeapFd = HardwareHeapFactory::GetInstance().GetHardwareHeapFd();
310     DmabufHeapBufferAlloc(dmaHeapFd, &dmaBuffer);
311     dmaBufferLst_.push_back(dmaBuffer);
312 
313     allocator_ = AVAllocatorFactory::CreateHardwareAllocator(0, capacity_, memFlag_);
314     buffer_ = AVBuffer::CreateAVBuffer(allocator_);
315     EXPECT_EQ(nullptr, buffer_);
316 
317     allocator_ = AVAllocatorFactory::CreateHardwareAllocator(dmaBuffer.fd, -1, memFlag_);
318     buffer_ = AVBuffer::CreateAVBuffer(allocator_);
319     EXPECT_EQ(nullptr, buffer_);
320 
321     allocator_ = AVAllocatorFactory::CreateHardwareAllocator(dmaBuffer.fd, 0, memFlag_);
322     buffer_ = AVBuffer::CreateAVBuffer(allocator_);
323     EXPECT_EQ(nullptr, buffer_);
324 }
325 
326 /**
327  * @tc.name: AVBuffer_CreateWithInvalid_005
328  * @tc.desc: create surface memory with invalid surface buffer
329  * @tc.type: FUNC
330  */
331 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_005, TestSize.Level1)
332 {
333     buffer_ = AVBuffer::CreateAVBuffer(sptr<SurfaceBuffer>(nullptr));
334     EXPECT_EQ(nullptr, buffer_);
335 }
336 
337 /**
338  * @tc.name: AVBuffer_Create_Local_SharedMemory_001
339  * @tc.desc: create local shared memory with allocator and align_ = 2
340  * @tc.type: FUNC
341  */
342 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SharedMemory_001, TestSize.Level1)
343 {
344     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
345     capacity_ = MEMSIZE;
346     align_ = 2; // test align
347     CreateLocalSharedMem();
348     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
349     int32_t offset = static_cast<size_t>(
350         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
351         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
352     EXPECT_EQ(std::static_pointer_cast<AVSharedMemoryExt>(buffer_->memory_)->allocator_->GetMemoryType(),
353               MemoryType::SHARED_MEMORY);
354     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY);
355     EXPECT_EQ(buffer_->memory_->capacity_, capacity_);
356     EXPECT_EQ(buffer_->memory_->offset_, offset);
357     EXPECT_EQ(std::static_pointer_cast<AVSharedAllocator>(allocator_)->memFlag_, memFlag_);
358 }
359 
360 /**
361  * @tc.name: AVBuffer_Create_Local_SharedMemory_002
362  * @tc.desc: create local shared memory with allocator
363  * @tc.type: FUNC
364  */
365 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SharedMemory_002, TestSize.Level1)
366 {
367     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
368     capacity_ = MEMSIZE;
369     align_ = 0;
370     allocator_ = AVAllocatorFactory::CreateSharedAllocator(memFlag_);
371     ASSERT_NE(nullptr, allocator_);
372     remoteBuffer_ = buffer_ = AVBuffer::CreateAVBuffer(allocator_, capacity_, align_);
373     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
374     EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_);
375 }
376 
377 /**
378  * @tc.name: AVBuffer_Create_Local_SharedMemory_003
379  * @tc.desc: create local shared memory with config
380  * @tc.type: FUNC
381  */
382 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SharedMemory_003, TestSize.Level1)
383 {
384     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
385     capacity_ = MEMSIZE;
386     align_ = 0;
387     CreateLocalSharedMemByConfig();
388     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
389     int32_t offset = static_cast<size_t>(
390         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
391         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
392     EXPECT_EQ(std::static_pointer_cast<AVSharedMemoryExt>(buffer_->memory_)->allocator_->GetMemoryType(),
393               MemoryType::SHARED_MEMORY);
394     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY);
395     EXPECT_EQ(buffer_->memory_->capacity_, capacity_);
396     EXPECT_EQ(buffer_->memory_->offset_, offset);
397 }
398 
399 /**
400  * @tc.name: AVBuffer_SharedMemory_GetConfig_001
401  * @tc.desc: get avbuffer's config
402  * @tc.type: FUNC
403  */
404 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetConfig_001, TestSize.Level1)
405 {
406     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
407     capacity_ = MEMSIZE;
408     align_ = 1;
409     CreateLocalSharedMem();
410     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
411     AVBufferConfig config = buffer_->GetConfig();
412     EXPECT_EQ(config.memoryType, MemoryType::SHARED_MEMORY);
413     EXPECT_EQ(config.memoryFlag, memFlag_);
414     EXPECT_EQ(config.capacity, capacity_);
415     EXPECT_EQ(config.align, align_);
416 }
417 
418 /**
419  * @tc.name: AVBuffer_Create_Remote_SharedMemory_001
420  * @tc.desc: create avbuffer of shared memory by reading parcel
421  * @tc.type: FUNC
422  */
423 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_SharedMemory_001, TestSize.Level1)
424 {
425     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
426     capacity_ = MEMSIZE;
427     align_ = 0;
428     CreateRemoteSharedMem();
429     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
430     GetRemoteBuffer();
431     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
432     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
433     int32_t offset = static_cast<size_t>(
434         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
435         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
436     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY);
437     EXPECT_EQ(buffer_->memory_->capacity_, capacity_);
438     EXPECT_EQ(buffer_->memory_->offset_, offset);
439     EXPECT_EQ(std::static_pointer_cast<AVSharedAllocator>(allocator_)->memFlag_, memFlag_);
440     EXPECT_GT(std::static_pointer_cast<AVSharedMemoryExt>(buffer_->memory_)->fd_, 0);
441 }
442 
443 /**
444  * @tc.name: AVBuffer_SharedMemory_SetParams_001
445  * @tc.desc: set and get parameters
446  * @tc.type: FUNC
447  */
448 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_SetParams_001, TestSize.Level1)
449 {
450     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
451     capacity_ = MEMSIZE;
452     align_ = 0;
453     CreateLocalSharedMem();
454     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
455     CheckMetaSetAndGet();
456 }
457 
458 /**
459  * @tc.name: AVBuffer_SharedMemory_SetParams_002
460  * @tc.desc: set and get parameters after reading parcel
461  * @tc.type: FUNC
462  */
463 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_SetParams_002, TestSize.Level1)
464 {
465     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
466     capacity_ = MEMSIZE;
467     align_ = 0;
468     CreateRemoteSharedMem();
469     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
470     CheckMetaSetAndGet();
471 }
472 
473 /**
474  * @tc.name: AVBuffer_SharedMemory_WriteAndRead_001
475  * @tc.desc: shared memory write and read
476  * @tc.type: FUNC
477  */
478 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_WriteAndRead_001, TestSize.Level1)
479 {
480     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
481     capacity_ = MEMSIZE;
482     align_ = 0;
483     CreateLocalSharedMem();
484     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
485     CheckMemTrans();
486 }
487 
488 /**
489  * @tc.name: AVBuffer_SharedMemory_WriteAndRead_002
490  * @tc.desc: shared memory write and read after reading parcel
491  * @tc.type: FUNC
492  */
493 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_WriteAndRead_002, TestSize.Level1)
494 {
495     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
496     capacity_ = MEMSIZE;
497     align_ = 0;
498     CreateRemoteSharedMem();
499     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
500     CheckMemTrans();
501 }
502 
503 /**
504  * @tc.name: AVBuffer_SharedMemory_WriteAndRead_003
505  * @tc.desc: shared memory write and read with valid position after reading parcel
506  * @tc.type: FUNC
507  */
508 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_WriteAndRead_003, TestSize.Level1)
509 {
510     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
511     capacity_ = MEMSIZE;
512     align_ = 0;
513     CreateRemoteSharedMem();
514     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
515     CheckMemTransPos(POSITION_ONE);
516 }
517 
518 /**
519  * @tc.name: AVBuffer_SharedMemory_WriteAndRead_004
520  * @tc.desc: shared memory write and read with invalid position after reading parcel
521  * @tc.type: FUNC
522  */
523 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_WriteAndRead_004, TestSize.Level1)
524 {
525     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
526     capacity_ = MEMSIZE;
527     align_ = 0;
528     CreateRemoteSharedMem();
529     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
530     CheckMemTransOutOfRange(POSITION_ONE);
531 }
532 
533 /**
534  * @tc.name: AVBuffer_SharedMemory_GetCapacity_001
535  * @tc.desc: shared memory get capacity
536  * @tc.type: FUNC
537  */
538 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetCapacity_001, TestSize.Level1)
539 {
540     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
541     capacity_ = MEMSIZE;
542     align_ = 0;
543     CreateLocalSharedMem();
544     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
545     EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_);
546 }
547 
548 /**
549  * @tc.name: AVBuffer_SharedMemory_GetCapacity_002
550  * @tc.desc: shared memory get capacity after reading parcel
551  * @tc.type: FUNC
552  */
553 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetCapacity_002, TestSize.Level1)
554 {
555     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
556     capacity_ = MEMSIZE;
557     align_ = 0;
558     CreateRemoteSharedMem();
559     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
560     GetRemoteBuffer();
561     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
562     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
563     EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_);
564 }
565 
566 /**
567  * @tc.name: AVBuffer_SharedMemory_CheckDataSize_001
568  * @tc.desc: shared memory check dataSize
569  * @tc.type: FUNC
570  */
571 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_CheckDataSize_001, TestSize.Level1)
572 {
573     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
574     capacity_ = MEMSIZE;
575     align_ = 0;
576     CreateLocalSharedMem();
577     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
578     CheckDataSize();
579 }
580 
581 /**
582  * @tc.name: AVBuffer_SharedMemory_CheckDataSize_002
583  * @tc.desc: shared memory check dataSize after reading parcel
584  * @tc.type: FUNC
585  */
586 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_CheckDataSize_002, TestSize.Level1)
587 {
588     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
589     capacity_ = MEMSIZE;
590     align_ = 0;
591     CreateRemoteSharedMem();
592     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
593     CheckDataSize();
594 }
595 
596 /**
597  * @tc.name: AVBuffer_SharedMemory_GetMemoryType_001
598  * @tc.desc: shared memory get memory type
599  * @tc.type: FUNC
600  */
601 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetMemoryType_001, TestSize.Level1)
602 {
603     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
604     capacity_ = MEMSIZE;
605     align_ = 0;
606     CreateLocalSharedMem();
607     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
608     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY);
609 }
610 
611 /**
612  * @tc.name: AVBuffer_SharedMemory_GetMemoryType_002
613  * @tc.desc: shared memory get memory type after reading parcel
614  * @tc.type: FUNC
615  */
616 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetMemoryType_002, TestSize.Level1)
617 {
618     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
619     capacity_ = MEMSIZE;
620     align_ = 0;
621     CreateRemoteSharedMem();
622     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
623     GetRemoteBuffer();
624     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
625     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
626     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY);
627 }
628 
629 /**
630  * @tc.name: AVBuffer_SharedMemory_GetFileDescriptor_001
631  * @tc.desc: shared memory get memory file descriptor
632  * @tc.type: FUNC
633  */
634 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetFileDescriptor_001, TestSize.Level1)
635 {
636     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
637     capacity_ = MEMSIZE;
638     align_ = 0;
639     CreateLocalSharedMem();
640     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
641     EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0);
642 }
643 
644 /**
645  * @tc.name: AVBuffer_SharedMemory_GetFileDescriptor_002
646  * @tc.desc: shared memory get memory file descriptor after reading parcel
647  * @tc.type: FUNC
648  */
649 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetFileDescriptor_002, TestSize.Level1)
650 {
651     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
652     capacity_ = MEMSIZE;
653     align_ = 0;
654     CreateRemoteSharedMem();
655     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
656     GetRemoteBuffer();
657     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
658     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
659     EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0);
660 }
661 
662 /**
663  * @tc.name: AVBuffer_SharedMemory_Reset_001
664  * @tc.desc: shared memory reset
665  * @tc.type: FUNC
666  */
667 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_Reset_001, TestSize.Level1)
668 {
669     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
670     capacity_ = MEMSIZE;
671     align_ = 0;
672     CreateLocalSharedMem();
673     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
674     buffer_->memory_->SetSize(MEMSIZE);
675     EXPECT_EQ(buffer_->memory_->size_, MEMSIZE);
676     buffer_->memory_->Reset();
677     EXPECT_EQ(buffer_->memory_->size_, 0);
678 }
679 
680 /**
681  * @tc.name: AVBuffer_SharedMemory_Reset_002
682  * @tc.desc: shared memory reset after reading parcel
683  * @tc.type: FUNC
684  */
685 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_Reset_002, TestSize.Level1)
686 {
687     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
688     capacity_ = MEMSIZE;
689     align_ = 0;
690     CreateRemoteSharedMem();
691     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
692     remoteBuffer_->memory_->SetSize(MEMSIZE);
693     EXPECT_EQ(remoteBuffer_->memory_->size_, MEMSIZE);
694     remoteBuffer_->memory_->Reset();
695     EXPECT_EQ(remoteBuffer_->memory_->size_, 0);
696     GetRemoteBuffer();
697     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
698     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
699     buffer_->memory_->Reset();
700     EXPECT_EQ(buffer_->memory_->size_, 0);
701 }
702 
703 /**
704  * @tc.name: AVBuffer_SharedMemory_ReadFromMessageParcel_001
705  * @tc.desc: shared memory read from message parcel
706  * @tc.type: FUNC
707  */
708 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_ReadFromMessageParcel_001, TestSize.Level1)
709 {
710     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
711     capacity_ = MEMSIZE;
712     align_ = 0;
713     CreateRemoteSharedMem();
714     CheckAttrTrans();
715 }
716 
717 /**
718  * @tc.name: AVBuffer_Create_Local_SurfaceMemory_001
719  * @tc.desc: create avbuffer of surface memory with allocator
720  * @tc.type: FUNC
721  */
722 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SurfaceMemory_001, TestSize.Level1)
723 {
724     align_ = 0;
725     CreateLocalSurfaceMem();
726     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
727     int32_t offset = static_cast<size_t>(
728         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
729         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
730     EXPECT_EQ(std::static_pointer_cast<AVSurfaceMemory>(buffer_->memory_)->allocator_->GetMemoryType(),
731               MemoryType::SURFACE_MEMORY);
732     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
733     EXPECT_EQ(buffer_->memory_->offset_, offset);
734 }
735 
736 /**
737  * @tc.name: AVBuffer_Create_Local_SurfaceMemory_002
738  * @tc.desc: create avbuffer of surface memory with parcel getting from SurfaceBuffer
739  * @tc.type: FUNC
740  */
741 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SurfaceMemory_002, TestSize.Level1)
742 {
743     align_ = 0;
744     CreateLocalSurfaceMemByParcel();
745     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
746     int32_t offset = static_cast<size_t>(
747         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
748         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
749     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
750     EXPECT_EQ(buffer_->memory_->offset_, offset);
751 }
752 
753 /**
754  * @tc.name: AVBuffer_Create_Local_SurfaceMemory_003
755  * @tc.desc: create avbuffer of surface memory with config struct
756  * @tc.type: FUNC
757  */
758 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SurfaceMemory_003, TestSize.Level1)
759 {
760     align_ = 0;
761     CreateLocalSurfaceMemByConfig();
762     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
763     int32_t offset = static_cast<size_t>(
764         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
765         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
766     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
767     EXPECT_EQ(buffer_->memory_->offset_, offset);
768 }
769 
770 /**
771  * @tc.name: AVBuffer_SurfaceMemory_GetConfig_001
772  * @tc.desc: create local surface memory with allocator, and get config
773  * @tc.type: FUNC
774  */
775 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetConfig_001, TestSize.Level1)
776 {
777     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
778     CreateLocalSurfaceMem();
779     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
780     AVBufferConfig config = buffer_->GetConfig();
781     EXPECT_EQ(config.memoryType, MemoryType::SURFACE_MEMORY);
782     EXPECT_EQ(config.surfaceBufferConfig->width, DEFAULT_CONFIG.width);
783     EXPECT_EQ(config.surfaceBufferConfig->height, DEFAULT_CONFIG.height);
784     EXPECT_EQ(config.surfaceBufferConfig->format, DEFAULT_CONFIG.format);
785     EXPECT_EQ(config.surfaceBufferConfig->usage, DEFAULT_CONFIG.usage);
786 }
787 
788 /**
789  * @tc.name: AVBuffer_SurfaceMemory_GetConfig_002
790  * @tc.desc: create local surface memory with config struct, and get config
791  * @tc.type: FUNC
792  */
793 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetConfig_002, TestSize.Level1)
794 {
795     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
796     CreateLocalSurfaceMemByConfig();
797     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
798     AVBufferConfig config = buffer_->GetConfig();
799     EXPECT_TRUE(config <= config_);
800 }
801 
802 /**
803  * @tc.name: AVBuffer_Create_Remote_SurfaceMemory_001
804  * @tc.desc: create avbuffer of surface memory by reading parcel
805  * @tc.type: FUNC
806  */
807 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_SurfaceMemory_001, TestSize.Level1)
808 {
809     align_ = 0;
810     CreateRemoteSurfaceMem();
811     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
812     GetRemoteBuffer();
813     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
814     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
815     int32_t offset = static_cast<size_t>(
816         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
817         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
818     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
819     EXPECT_EQ(buffer_->memory_->offset_, offset);
820     uint8_t *addr = buffer_->memory_->GetAddr();
821     auto surfaceBuffer = buffer_->memory_->GetSurfaceBuffer();
822     buffer_ = nullptr;
823     EXPECT_EQ(addr, surfaceBuffer->GetVirAddr());
824 }
825 
826 /**
827  * @tc.name: AVBuffer_Create_Remote_SurfaceMemory_002
828  * @tc.desc: create avbuffer of surface memory by reading parcel getting from SurfaceBuffer
829  * @tc.type: FUNC
830  */
831 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_SurfaceMemory_002, TestSize.Level1)
832 {
833     align_ = 0;
834     CreateRemoteSurfaceMemByParcel();
835     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
836     GetRemoteBuffer();
837     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
838     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
839     int32_t offset = static_cast<size_t>(
840         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
841         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
842     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
843     EXPECT_EQ(buffer_->memory_->offset_, offset);
844 }
845 
846 /**
847  * @tc.name: AVBuffer_Create_Remote_SurfaceMemory_003
848  * @tc.desc: create avbuffer of surface memory by sptr of SurfaceBuffer
849  * @tc.type: FUNC
850  */
851 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_SurfaceMemory_003, TestSize.Level1)
852 {
853     align_ = 0;
854     CreateRemoteSurfaceMemBySptr();
855     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
856     GetRemoteBuffer();
857     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
858     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
859     int32_t offset = static_cast<size_t>(
860         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
861         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
862     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
863     EXPECT_EQ(buffer_->memory_->offset_, offset);
864 }
865 
866 /**
867  * @tc.name: AVBuffer_SurfaceMemory_SetParams_001
868  * @tc.desc: surface memory get and set params
869  * @tc.type: FUNC
870  */
871 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_SetParams_001, TestSize.Level1)
872 {
873     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
874     align_ = 0;
875     CreateLocalSurfaceMem();
876     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
877     CheckMetaSetAndGet();
878 }
879 
880 /**
881  * @tc.name: AVBuffer_SurfaceMemory_SetParams_002
882  * @tc.desc: surface memory get and set params after reading parcel
883  * @tc.type: FUNC
884  */
885 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_SetParams_002, TestSize.Level1)
886 {
887     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
888     align_ = 0;
889     CreateRemoteSurfaceMem();
890     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
891     CheckMetaSetAndGet();
892 }
893 
894 /**
895  * @tc.name: AVBuffer_SurfaceMemory_SetParams_003
896  * @tc.desc: surface memory get and set params
897  * @tc.type: FUNC
898  */
899 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_SetParams_003, TestSize.Level1)
900 {
901     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
902     align_ = 0;
903     CreateLocalSurfaceMemByParcel();
904     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
905     CheckMetaSetAndGet();
906 }
907 
908 /**
909  * @tc.name: AVBuffer_SurfaceMemory_SetParams_004
910  * @tc.desc: surface memory get and set params after reading parcel
911  * @tc.type: FUNC
912  */
913 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_SetParams_004, TestSize.Level1)
914 {
915     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
916     align_ = 0;
917     CreateRemoteSurfaceMemByParcel();
918     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
919     CheckMetaSetAndGet();
920 }
921 
922 /**
923  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_001
924  * @tc.desc: surface memory write and read
925  * @tc.type: FUNC
926  */
927 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_001, TestSize.Level1)
928 {
929     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
930     align_ = 0;
931     CreateLocalSurfaceMem();
932     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
933     CheckMemTrans();
934 }
935 
936 /**
937  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_002
938  * @tc.desc: surface memory write and read after reading parcel
939  * @tc.type: FUNC
940  */
941 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_002, TestSize.Level1)
942 {
943     align_ = 0;
944     CreateRemoteSurfaceMem();
945     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
946     capacity_ = remoteBuffer_->memory_->GetSurfaceBuffer()->GetSize();
947     CheckMemTrans();
948 }
949 
950 /**
951  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_003
952  * @tc.desc: surface memory write and read with valid position after reading parcel
953  * @tc.type: FUNC
954  */
955 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_003, TestSize.Level1)
956 {
957     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
958     align_ = 0;
959     CreateRemoteSurfaceMem();
960     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
961     CheckMemTransPos(POSITION_ONE);
962 }
963 
964 /**
965  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_004
966  * @tc.desc: surface memory write and read with invalid position after reading parcel
967  * @tc.type: FUNC
968  */
969 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_004, TestSize.Level1)
970 {
971     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
972     align_ = 0;
973     CreateRemoteSurfaceMem();
974     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
975     CheckMemTransOutOfRange(POSITION_ONE);
976 }
977 
978 /**
979  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_005
980  * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer
981  *           2. surface memory write and read
982  * @tc.type: FUNC
983  */
984 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_005, TestSize.Level1)
985 {
986     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
987     align_ = 0;
988     CreateLocalSurfaceMemByParcel();
989     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
990     CheckMemTrans();
991 }
992 
993 /**
994  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_006
995  * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer
996  *           2. surface memory write and read after reading parcel
997  * @tc.type: FUNC
998  */
999 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_006, TestSize.Level1)
1000 {
1001     align_ = 0;
1002     CreateRemoteSurfaceMemByParcel();
1003     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1004     capacity_ = remoteBuffer_->memory_->GetSurfaceBuffer()->GetSize();
1005     CheckMemTrans();
1006 }
1007 
1008 /**
1009  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_007
1010  * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer
1011  *           2. surface memory write and read with valid position after reading parcel
1012  * @tc.type: FUNC
1013  */
1014 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_007, TestSize.Level1)
1015 {
1016     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1017     align_ = 0;
1018     CreateRemoteSurfaceMemByParcel();
1019     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1020     CheckMemTransPos(POSITION_ONE);
1021 }
1022 
1023 /**
1024  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_008
1025  * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer
1026  *           2. surface memory write and read with invalid position after reading parcel
1027  * @tc.type: FUNC
1028  */
1029 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_008, TestSize.Level1)
1030 {
1031     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1032     align_ = 0;
1033     CreateRemoteSurfaceMemByParcel();
1034     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1035     CheckMemTransOutOfRange(POSITION_ONE);
1036 }
1037 
1038 /**
1039  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_009
1040  * @tc.desc: 1. create surface memory with parcel sptr of SurfaceBuffer
1041  *           2. surface memory write and read after reading parcel
1042  * @tc.type: FUNC
1043  */
1044 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_009, TestSize.Level1)
1045 {
1046     align_ = 0;
1047     CreateRemoteSurfaceMemBySptr();
1048     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1049     capacity_ = remoteBuffer_->memory_->GetSurfaceBuffer()->GetSize();
1050     CheckMemTrans();
1051 }
1052 
1053 /**
1054  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_010
1055  * @tc.desc: 1. create surface memory with parcel sptr of SurfaceBuffer
1056  *           2. surface memory write and read with valid position after reading parcel
1057  * @tc.type: FUNC
1058  */
1059 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_010, TestSize.Level1)
1060 {
1061     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1062     align_ = 0;
1063     CreateRemoteSurfaceMemBySptr();
1064     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1065     CheckMemTransPos(POSITION_ONE);
1066 }
1067 
1068 /**
1069  * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_011
1070  * @tc.desc: 1. create surface memory with sptr of SurfaceBuffer
1071  *           2. surface memory write and read with invalid position after reading parcel
1072  * @tc.type: FUNC
1073  */
1074 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_011, TestSize.Level1)
1075 {
1076     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1077     align_ = 0;
1078     CreateRemoteSurfaceMemBySptr();
1079     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1080     CheckMemTransOutOfRange(POSITION_ONE);
1081 }
1082 
1083 /**
1084  * @tc.name: AVBuffer_SurfaceMemory_GetCapacity_001
1085  * @tc.desc: surface memory get capacity
1086  * @tc.type: FUNC
1087  */
1088 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetCapacity_001, TestSize.Level1)
1089 {
1090     align_ = 0;
1091     CreateLocalSurfaceMem();
1092     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1093 }
1094 
1095 /**
1096  * @tc.name: AVBuffer_SurfaceMemory_GetCapacity_002
1097  * @tc.desc: surface memory get capacity after reading parcel
1098  * @tc.type: FUNC
1099  */
1100 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetCapacity_002, TestSize.Level1)
1101 {
1102     align_ = 0;
1103     CreateRemoteSurfaceMem();
1104     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1105     GetRemoteBuffer();
1106     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1107     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1108 }
1109 
1110 /**
1111  * @tc.name: AVBuffer_SurfaceMemory_GetCapacity_003
1112  * @tc.desc: surface memory get capacity with parcel getting from SurfaceBuffer
1113  * @tc.type: FUNC
1114  */
1115 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetCapacity_003, TestSize.Level1)
1116 {
1117     align_ = 0;
1118     CreateLocalSurfaceMemByParcel();
1119     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1120 }
1121 
1122 /**
1123  * @tc.name: AVBuffer_SurfaceMemory_GetCapacity_004
1124  * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer
1125  *           2. surface memory get capacity after reading parcel
1126  * @tc.type: FUNC
1127  */
1128 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetCapacity_004, TestSize.Level1)
1129 {
1130     align_ = 0;
1131     CreateRemoteSurfaceMemByParcel();
1132     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1133     GetRemoteBuffer();
1134     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1135     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1136 }
1137 
1138 /**
1139  * @tc.name: AVBuffer_SurfaceMemory_CheckDataSize_001
1140  * @tc.desc: surface memory check dataSize
1141  * @tc.type: FUNC
1142  */
1143 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_CheckDataSize_001, TestSize.Level1)
1144 {
1145     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1146     align_ = 0;
1147     CreateLocalSurfaceMem();
1148     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1149     CheckDataSize();
1150 }
1151 
1152 /**
1153  * @tc.name: AVBuffer_SurfaceMemory_CheckDataSize_002
1154  * @tc.desc: surface memory check dataSize after reading parcel
1155  * @tc.type: FUNC
1156  */
1157 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_CheckDataSize_002, TestSize.Level1)
1158 {
1159     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1160     align_ = 0;
1161     CreateRemoteSurfaceMem();
1162     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1163     CheckDataSize();
1164 }
1165 
1166 /**
1167  * @tc.name: AVBuffer_SurfaceMemory_CheckDataSize_003
1168  * @tc.desc: surface memory check dataSize with parcel getting from SurfaceBuffer
1169  * @tc.type: FUNC
1170  */
1171 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_CheckDataSize_003, TestSize.Level1)
1172 {
1173     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1174     align_ = 0;
1175     CreateLocalSurfaceMemByParcel();
1176     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1177     CheckDataSize();
1178 }
1179 
1180 /**
1181  * @tc.name: AVBuffer_SurfaceMemory_CheckDataSize_004
1182  * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer
1183  *           2. surface memory check dataSize after reading parcel
1184  * @tc.type: FUNC
1185  */
1186 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_CheckDataSize_004, TestSize.Level1)
1187 {
1188     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1189     align_ = 0;
1190     CreateRemoteSurfaceMemByParcel();
1191     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1192     CheckDataSize();
1193 }
1194 
1195 /**
1196  * @tc.name: AVBuffer_SurfaceMemory_GetMemoryType_001
1197  * @tc.desc: surface memory get memory type
1198  * @tc.type: FUNC
1199  */
1200 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetMemoryType_001, TestSize.Level1)
1201 {
1202     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1203     align_ = 0;
1204     CreateLocalSurfaceMem();
1205     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1206     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
1207 }
1208 
1209 /**
1210  * @tc.name: AVBuffer_SurfaceMemory_GetMemoryType_002
1211  * @tc.desc: surface memory get memory type after reading parcel
1212  * @tc.type: FUNC
1213  */
1214 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetMemoryType_002, TestSize.Level1)
1215 {
1216     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1217     align_ = 0;
1218     CreateRemoteSurfaceMem();
1219     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1220     GetRemoteBuffer();
1221     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1222     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1223     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
1224 }
1225 
1226 /**
1227  * @tc.name: AVBuffer_SurfaceMemory_GetMemoryType_003
1228  * @tc.desc: surface memory get memory type with parcel getting from SurfaceBuffer
1229  * @tc.type: FUNC
1230  */
1231 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetMemoryType_003, TestSize.Level1)
1232 {
1233     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1234     align_ = 0;
1235     CreateLocalSurfaceMemByParcel();
1236     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1237     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
1238 }
1239 
1240 /**
1241  * @tc.name: AVBuffer_SurfaceMemory_GetMemoryType_004
1242  * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer
1243  *           2. surface memory get memory type after reading parcel
1244  * @tc.type: FUNC
1245  */
1246 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetMemoryType_004, TestSize.Level1)
1247 {
1248     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1249     align_ = 0;
1250     CreateRemoteSurfaceMemByParcel();
1251     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1252     GetRemoteBuffer();
1253     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1254     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1255     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY);
1256 }
1257 
1258 /**
1259  * @tc.name: AVBuffer_SurfaceMemory_GetFileDescriptor_001
1260  * @tc.desc: surface memory get memory file descriptor
1261  * @tc.type: FUNC
1262  */
1263 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetFileDescriptor_001, TestSize.Level1)
1264 {
1265     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1266     align_ = 0;
1267     CreateLocalSurfaceMem();
1268     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1269     EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0);
1270 }
1271 
1272 /**
1273  * @tc.name: AVBuffer_SurfaceMemory_GetFileDescriptor_002
1274  * @tc.desc: surface memory get memory file descriptor after reading parcel
1275  * @tc.type: FUNC
1276  */
1277 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetFileDescriptor_002, TestSize.Level1)
1278 {
1279     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1280     align_ = 0;
1281     CreateRemoteSurfaceMem();
1282     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1283     GetRemoteBuffer();
1284     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1285     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1286     EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0);
1287 }
1288 
1289 /**
1290  * @tc.name: AVBuffer_SurfaceMemory_GetFileDescriptor_003
1291  * @tc.desc: surface memory get memory file descriptor with parcel getting from SurfaceBuffer
1292  * @tc.type: FUNC
1293  */
1294 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetFileDescriptor_003, TestSize.Level1)
1295 {
1296     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1297     align_ = 0;
1298     CreateLocalSurfaceMemByParcel();
1299     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1300     EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0);
1301 }
1302 
1303 /**
1304  * @tc.name: AVBuffer_SurfaceMemory_GetFileDescriptor_004
1305  * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer
1306  *           2. surface memory get memory file descriptor after reading parcel
1307  * @tc.type: FUNC
1308  */
1309 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetFileDescriptor_004, TestSize.Level1)
1310 {
1311     capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE;
1312     align_ = 0;
1313     CreateRemoteSurfaceMemByParcel();
1314     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1315     GetRemoteBuffer();
1316     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1317     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1318     EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0);
1319 }
1320 
1321 /**
1322  * @tc.name: AVBuffer_SurfaceMemory_Reset_001
1323  * @tc.desc: surface memory reset
1324  * @tc.type: FUNC
1325  */
1326 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_Reset_001, TestSize.Level1)
1327 {
1328     capacity_ = MEMSIZE;
1329     align_ = 0;
1330     CreateLocalSurfaceMem();
1331     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1332     buffer_->memory_->SetSize(MEMSIZE);
1333     EXPECT_EQ(buffer_->memory_->size_, MEMSIZE);
1334     buffer_->memory_->Reset();
1335     EXPECT_EQ(buffer_->memory_->size_, 0);
1336 }
1337 
1338 /**
1339  * @tc.name: AVBuffer_SurfaceMemory_Reset_002
1340  * @tc.desc: surface memory reset after reading parcel
1341  * @tc.type: FUNC
1342  */
1343 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_Reset_002, TestSize.Level1)
1344 {
1345     capacity_ = MEMSIZE;
1346     align_ = 0;
1347     CreateRemoteSurfaceMem();
1348     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1349     remoteBuffer_->memory_->SetSize(MEMSIZE);
1350     EXPECT_EQ(remoteBuffer_->memory_->size_, MEMSIZE);
1351     remoteBuffer_->memory_->Reset();
1352     EXPECT_EQ(remoteBuffer_->memory_->size_, 0);
1353     GetRemoteBuffer();
1354     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1355     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1356     buffer_->memory_->Reset();
1357     EXPECT_EQ(buffer_->memory_->size_, 0);
1358 }
1359 
1360 /**
1361  * @tc.name: AVBuffer_SurfaceMemory_Reset_003
1362  * @tc.desc: surface memory reset with parcel getting from SurfaceBuffer
1363  * @tc.type: FUNC
1364  */
1365 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_Reset_003, TestSize.Level1)
1366 {
1367     capacity_ = MEMSIZE;
1368     align_ = 0;
1369     CreateLocalSurfaceMemByParcel();
1370     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1371     buffer_->memory_->SetSize(MEMSIZE);
1372     EXPECT_EQ(buffer_->memory_->size_, MEMSIZE);
1373     buffer_->memory_->Reset();
1374     EXPECT_EQ(buffer_->memory_->size_, 0);
1375 }
1376 
1377 /**
1378  * @tc.name: AVBuffer_SurfaceMemory_Reset_004
1379  * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer
1380  *           2. surface memory reset after reading parcel
1381  * @tc.type: FUNC
1382  */
1383 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_Reset_004, TestSize.Level1)
1384 {
1385     capacity_ = MEMSIZE;
1386     align_ = 0;
1387     CreateRemoteSurfaceMemByParcel();
1388     ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1389     remoteBuffer_->memory_->SetSize(MEMSIZE);
1390     EXPECT_EQ(remoteBuffer_->memory_->size_, MEMSIZE);
1391     remoteBuffer_->memory_->Reset();
1392     EXPECT_EQ(remoteBuffer_->memory_->size_, 0);
1393     GetRemoteBuffer();
1394     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1395     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1396     buffer_->memory_->Reset();
1397     EXPECT_EQ(buffer_->memory_->size_, 0);
1398 }
1399 
1400 /**
1401  * @tc.name: AVBuffer_SurfaceMemory_ReadFromMessageParcel_001
1402  * @tc.desc: surface memory read from message parcel
1403  * @tc.type: FUNC
1404  */
1405 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_ReadFromMessageParcel_001, TestSize.Level1)
1406 {
1407     capacity_ = MEMSIZE;
1408     align_ = 0;
1409     CreateRemoteSurfaceMem();
1410     CheckAttrTrans();
1411 }
1412 
1413 /**
1414  * @tc.name: AVBuffer_Create_Local_HardwareMemory_001
1415  * @tc.desc: create local hardware memory
1416  * @tc.type: FUNC
1417  */
1418 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_HardwareMemory_001, TestSize.Level1)
1419 {
1420     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1421     capacity_ = MEMSIZE;
1422     align_ = 0;
1423     CreateLocalHardwareMem();
1424     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1425     int32_t offset = static_cast<size_t>(
1426         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
1427         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
1428     EXPECT_EQ(std::static_pointer_cast<AVHardwareMemory>(buffer_->memory_)->allocator_->GetMemoryType(),
1429               MemoryType::HARDWARE_MEMORY);
1430     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY);
1431     EXPECT_EQ(buffer_->memory_->capacity_, capacity_);
1432     EXPECT_EQ(buffer_->memory_->offset_, offset);
1433     EXPECT_EQ(std::static_pointer_cast<AVHardwareAllocator>(allocator_)->memFlag_, memFlag_);
1434 }
1435 
1436 /**
1437  * @tc.name: AVBuffer_Create_Local_HardwareMemory_002
1438  * @tc.desc: create local hardware memory with config struct
1439  * @tc.type: FUNC
1440  */
1441 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_HardwareMemory_002, TestSize.Level1)
1442 {
1443     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1444     capacity_ = MEMSIZE;
1445     align_ = 0;
1446     CreateLocalHardwareMemByConfig();
1447     int32_t offset = static_cast<size_t>(
1448         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
1449         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
1450     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY);
1451     EXPECT_EQ(buffer_->memory_->capacity_, capacity_);
1452     EXPECT_EQ(buffer_->memory_->offset_, offset);
1453 }
1454 
1455 /**
1456  * @tc.name: AVBuffer_HardwareMemory_GetConfig_001
1457  * @tc.desc: create local hardware memory, and get config
1458  * @tc.type: FUNC
1459  */
1460 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetConfig_001, TestSize.Level1)
1461 {
1462     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1463     capacity_ = MEMSIZE;
1464     CreateLocalHardwareMem();
1465     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1466     AVBufferConfig config = buffer_->GetConfig();
1467     EXPECT_EQ(config.memoryType, MemoryType::HARDWARE_MEMORY);
1468     EXPECT_EQ(config.memoryFlag, memFlag_);
1469     EXPECT_EQ(config.capacity, capacity_);
1470 }
1471 
1472 /**
1473  * @tc.name: AVBuffer_Create_Remote_HardwareMemory_001
1474  * @tc.desc: create remote hardware memory after reading parcel
1475  * @tc.type: FUNC
1476  */
1477 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_HardwareMemory_001, TestSize.Level1)
1478 {
1479     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1480     capacity_ = MEMSIZE;
1481     align_ = 0;
1482     CreateRemoteHardwareMem();
1483     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1484     GetRemoteBuffer();
1485     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1486     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1487     int32_t offset = static_cast<size_t>(
1488         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
1489         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
1490     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY);
1491     EXPECT_EQ(buffer_->memory_->capacity_, capacity_);
1492     EXPECT_EQ(buffer_->memory_->offset_, offset);
1493     EXPECT_EQ(std::static_pointer_cast<AVHardwareAllocator>(allocator_)->memFlag_, memFlag_);
1494     EXPECT_GT(std::static_pointer_cast<AVHardwareMemory>(buffer_->memory_)->fd_, 0);
1495 }
1496 
1497 /**
1498  * @tc.name: AVBuffer_HardwareMemory_SetParams_001
1499  * @tc.desc: hardware memory set params
1500  * @tc.type: FUNC
1501  */
1502 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_SetParams_001, TestSize.Level1)
1503 {
1504     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1505     capacity_ = MEMSIZE;
1506     align_ = 0;
1507     CreateLocalHardwareMem();
1508     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1509     CheckMetaSetAndGet();
1510 }
1511 
1512 /**
1513  * @tc.name: AVBuffer_HardwareMemory_SetParams_002
1514  * @tc.desc: hardware memory set params after reading parcel
1515  * @tc.type: FUNC
1516  */
1517 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_SetParams_002, TestSize.Level1)
1518 {
1519     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1520     capacity_ = MEMSIZE;
1521     align_ = 0;
1522     CreateRemoteHardwareMem();
1523     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1524     CheckMetaSetAndGet();
1525 }
1526 
1527 /**
1528  * @tc.name: AVBuffer_HardwareMemory_WriteAndRead_001
1529  * @tc.desc: hardware memory write and read
1530  * @tc.type: FUNC
1531  */
1532 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_WriteAndRead_001, TestSize.Level1)
1533 {
1534     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1535     capacity_ = MEMSIZE;
1536     align_ = 0;
1537     CreateLocalHardwareMem();
1538     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1539     CheckMemTrans();
1540 }
1541 
1542 /**
1543  * @tc.name: AVBuffer_HardwareMemory_WriteAndRead_002
1544  * @tc.desc: hardware memory write and read after reading parcel
1545  * @tc.type: FUNC
1546  */
1547 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_WriteAndRead_002, TestSize.Level1)
1548 {
1549     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1550     capacity_ = MEMSIZE;
1551     align_ = 0;
1552     CreateRemoteHardwareMem();
1553     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1554     CheckMemTrans();
1555 }
1556 
1557 /**
1558  * @tc.name: AVBuffer_HardwareMemory_WriteAndRead_003
1559  * @tc.desc: hardware memory write and read with valid position after reading parcel
1560  * @tc.type: FUNC
1561  */
1562 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_WriteAndRead_003, TestSize.Level1)
1563 {
1564     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1565     capacity_ = MEMSIZE;
1566     align_ = 0;
1567     CreateRemoteHardwareMem();
1568     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1569     CheckMemTransPos(POSITION_ONE);
1570 }
1571 
1572 /**
1573  * @tc.name: AVBuffer_HardwareMemory_WriteAndRead_004
1574  * @tc.desc: hardware memory write and read with invalid position after reading parcel
1575  * @tc.type: FUNC
1576  */
1577 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_WriteAndRead_004, TestSize.Level1)
1578 {
1579     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1580     capacity_ = MEMSIZE;
1581     align_ = 0;
1582     CreateRemoteHardwareMem();
1583     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1584     CheckMemTransOutOfRange(POSITION_ONE);
1585 }
1586 
1587 /**
1588  * @tc.name: AVBuffer_HardwareMemory_GetCapacity_001
1589  * @tc.desc: hardware memory get capacity
1590  * @tc.type: FUNC
1591  */
1592 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetCapacity_001, TestSize.Level1)
1593 {
1594     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1595     capacity_ = MEMSIZE;
1596     align_ = 0;
1597     CreateLocalHardwareMem();
1598     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1599     EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_);
1600 }
1601 
1602 /**
1603  * @tc.name: AVBuffer_HardwareMemory_GetCapacity_002
1604  * @tc.desc: hardware memory get capacity after reading parcel
1605  * @tc.type: FUNC
1606  */
1607 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetCapacity_002, TestSize.Level1)
1608 {
1609     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1610     capacity_ = MEMSIZE;
1611     align_ = 0;
1612     CreateRemoteHardwareMem();
1613     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1614     GetRemoteBuffer();
1615     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1616     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1617     EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_);
1618 }
1619 
1620 /**
1621  * @tc.name: AVBuffer_HardwareMemory_CheckDataSize_001
1622  * @tc.desc: hardware memory check dataSize
1623  * @tc.type: FUNC
1624  */
1625 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_CheckDataSize_001, TestSize.Level1)
1626 {
1627     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1628     capacity_ = MEMSIZE;
1629     align_ = 0;
1630     CreateLocalHardwareMem();
1631     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1632     CheckDataSize();
1633 }
1634 
1635 /**
1636  * @tc.name: AVBuffer_HardwareMemory_CheckDataSize_002
1637  * @tc.desc: hardware memory check dataSize after reading parcel
1638  * @tc.type: FUNC
1639  */
1640 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_CheckDataSize_002, TestSize.Level1)
1641 {
1642     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1643     capacity_ = MEMSIZE;
1644     align_ = 0;
1645     CreateRemoteHardwareMem();
1646     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1647     CheckDataSize();
1648 }
1649 
1650 /**
1651  * @tc.name: AVBuffer_HardwareMemory_GetMemoryType_001
1652  * @tc.desc: hardware memory get memory type
1653  * @tc.type: FUNC
1654  */
1655 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetMemoryType_001, TestSize.Level1)
1656 {
1657     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1658     capacity_ = MEMSIZE;
1659     align_ = 0;
1660     CreateLocalHardwareMem();
1661     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1662     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY);
1663 }
1664 
1665 /**
1666  * @tc.name: AVBuffer_HardwareMemory_GetMemoryType_002
1667  * @tc.desc: hardware memory get memory type after reading parcel
1668  * @tc.type: FUNC
1669  */
1670 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetMemoryType_002, TestSize.Level1)
1671 {
1672     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1673     capacity_ = MEMSIZE;
1674     align_ = 0;
1675     CreateRemoteHardwareMem();
1676     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1677     GetRemoteBuffer();
1678     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1679     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1680     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY);
1681 }
1682 
1683 /**
1684  * @tc.name: AVBuffer_HardwareMemory_GetFileDescriptor_001
1685  * @tc.desc: hardware memory get file descriptor
1686  * @tc.type: FUNC
1687  */
1688 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetFileDescriptor_001, TestSize.Level1)
1689 {
1690     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1691     capacity_ = MEMSIZE;
1692     align_ = 0;
1693     CreateLocalHardwareMem();
1694     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1695     EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0);
1696 }
1697 
1698 /**
1699  * @tc.name: AVBuffer_HardwareMemory_GetFileDescriptor_002
1700  * @tc.desc: hardware memory get file descriptor after reading parcel
1701  * @tc.type: FUNC
1702  */
1703 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetFileDescriptor_002, TestSize.Level1)
1704 {
1705     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1706     capacity_ = MEMSIZE;
1707     align_ = 0;
1708     CreateRemoteHardwareMem();
1709     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1710     GetRemoteBuffer();
1711     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1712     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1713     EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0);
1714 }
1715 
1716 /**
1717  * @tc.name: AVBuffer_HardwareMemory_GetFileDescriptor_003
1718  * @tc.desc: hardware memory get file descriptor
1719  * @tc.type: FUNC
1720  */
1721 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetFileDescriptor_003, TestSize.Level1)
1722 {
1723     capacity_ = MEMSIZE;
1724     align_ = 0;
1725     CreateLocalHardwareMemSecure();
1726     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1727     EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0);
1728     MessageParcel parcel;
1729     EXPECT_FALSE(buffer_->WriteToMessageParcel(parcel));
1730 }
1731 
1732 /**
1733  * @tc.name: AVBuffer_HardwareMemory_Reset_001
1734  * @tc.desc: hardware memory reset
1735  * @tc.type: FUNC
1736  */
1737 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_Reset_001, TestSize.Level1)
1738 {
1739     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1740     capacity_ = MEMSIZE;
1741     align_ = 0;
1742     CreateLocalHardwareMem();
1743     ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1744     buffer_->memory_->SetSize(MEMSIZE);
1745     EXPECT_EQ(buffer_->memory_->size_, MEMSIZE);
1746     buffer_->memory_->Reset();
1747     EXPECT_EQ(buffer_->memory_->size_, 0);
1748 }
1749 
1750 /**
1751  * @tc.name: AVBuffer_HardwareMemory_Reset_002
1752  * @tc.desc: hardware memory reset after reading parcel
1753  * @tc.type: FUNC
1754  */
1755 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_Reset_002, TestSize.Level1)
1756 {
1757     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1758     capacity_ = MEMSIZE;
1759     align_ = 0;
1760     CreateRemoteHardwareMem();
1761     ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr));
1762     remoteBuffer_->memory_->SetSize(MEMSIZE);
1763     EXPECT_EQ(remoteBuffer_->memory_->size_, MEMSIZE);
1764     remoteBuffer_->memory_->Reset();
1765     EXPECT_EQ(remoteBuffer_->memory_->size_, 0);
1766     GetRemoteBuffer();
1767     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1768     ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId());
1769     buffer_->memory_->Reset();
1770     EXPECT_EQ(buffer_->memory_->size_, 0);
1771 }
1772 
1773 /**
1774  * @tc.name: AVBuffer_HardwareMemory_ReadFromMessageParcel_001
1775  * @tc.desc: hardware memory read from message parcel
1776  * @tc.type: FUNC
1777  */
1778 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_ReadFromMessageParcel_001, TestSize.Level1)
1779 {
1780     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1781     capacity_ = MEMSIZE;
1782     align_ = 0;
1783     CreateRemoteHardwareMem();
1784     CheckAttrTrans();
1785 }
1786 
1787 /**
1788  * @tc.name: AVBuffer_Create_Local_VirtualMemory_001
1789  * @tc.desc: create local virtual memory
1790  * @tc.type: FUNC
1791  */
1792 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_VirtualMemory_001, TestSize.Level1)
1793 {
1794     capacity_ = MEMSIZE;
1795     align_ = 0;
1796     CreateLocalVirtualMem();
1797     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1798     int32_t offset = static_cast<size_t>(
1799         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
1800         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
1801     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::VIRTUAL_MEMORY);
1802     EXPECT_EQ(buffer_->memory_->capacity_, capacity_);
1803     EXPECT_EQ(buffer_->memory_->offset_, offset);
1804 }
1805 
1806 /**
1807  * @tc.name: AVBuffer_Create_Local_VirtualMemory_002
1808  * @tc.desc: create local virtual memory with no parameters
1809  * @tc.type: FUNC
1810  */
1811 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_VirtualMemory_002, TestSize.Level1)
1812 {
1813     CreateLocalNullMem();
1814     ASSERT_NE(nullptr, remoteBuffer_);
1815     ASSERT_NE(nullptr, remoteBuffer_->meta_);
1816     ASSERT_EQ(nullptr, remoteBuffer_->memory_);
1817     remoteBuffer_->pts_ = DEFAULT_PTS;
1818     remoteBuffer_->dts_ = DEFAULT_DTS;
1819     remoteBuffer_->duration_ = DEFAULT_DURATION;
1820     remoteBuffer_->flag_ = DEFAULT_FLAG;
1821 
1822     GetRemoteBuffer();
1823     ASSERT_NE(nullptr, buffer_);
1824     ASSERT_NE(nullptr, buffer_->meta_);
1825     ASSERT_EQ(nullptr, buffer_->memory_);
1826     EXPECT_EQ(remoteBuffer_->pts_, buffer_->pts_);
1827     EXPECT_EQ(remoteBuffer_->dts_, buffer_->dts_);
1828     EXPECT_EQ(remoteBuffer_->duration_, buffer_->duration_);
1829     EXPECT_EQ(remoteBuffer_->flag_, buffer_->flag_);
1830 }
1831 
1832 /**
1833  * @tc.name: AVBuffer_Create_Local_VirtualMemory_003
1834  * @tc.desc: create local virtual memory with pointer
1835  * @tc.type: FUNC
1836  */
1837 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_VirtualMemory_003, TestSize.Level1)
1838 {
1839     // create loacal
1840     capacity_ = MEMSIZE;
1841     uint8_t *array = new uint8_t[capacity_];
1842     auto error = memcpy_s(array, capacity_, inputBuffer_.data(), capacity_);
1843     ASSERT_EQ(error, EOK);
1844     buffer_ = AVBuffer::CreateAVBuffer(array, capacity_, capacity_);
1845     ASSERT_NE(nullptr, buffer_);
1846     ASSERT_NE(nullptr, buffer_->memory_);
1847     ASSERT_NE(nullptr, buffer_->memory_->GetAddr());
1848     uint8_t *addr = buffer_->memory_->GetAddr();
1849     ASSERT_NE(addr, nullptr);
1850     EXPECT_EQ(memcmp(static_cast<void *>(addr), inputBuffer_.data(), capacity_), 0);
1851     // write and read
1852     outputBuffer_.resize(MEMSIZE, 0);
1853     EXPECT_EQ(buffer_->memory_->Read(outputBuffer_.data(), capacity_, 0), capacity_);
1854     EXPECT_EQ(buffer_->memory_->GetSize(), capacity_);
1855     EXPECT_EQ(memcmp(inputBuffer_.data(), outputBuffer_.data(), capacity_), 0);
1856     EXPECT_EQ(memcmp(static_cast<void *>(addr), inputBuffer_.data(), capacity_), 0);
1857     EXPECT_EQ(memcmp(static_cast<void *>(addr), outputBuffer_.data(), capacity_), 0);
1858     delete[] array;
1859 }
1860 
1861 /**
1862  * @tc.name: AVBuffer_Create_Local_VirtualMemory_004
1863  * @tc.desc: create local virtual memory with config struct
1864  * @tc.type: FUNC
1865  */
1866 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_VirtualMemory_004, TestSize.Level1)
1867 {
1868     capacity_ = MEMSIZE;
1869     align_ = 0;
1870     CreateLocalVirtualMemByConfig();
1871     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1872     int32_t offset = static_cast<size_t>(
1873         AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) -
1874         reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()));
1875     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::VIRTUAL_MEMORY);
1876     EXPECT_EQ(buffer_->memory_->capacity_, capacity_);
1877     EXPECT_EQ(buffer_->memory_->offset_, offset);
1878 }
1879 
1880 /**
1881  * @tc.name: AVBuffer_VirtualMemory_GetConfig_001
1882  * @tc.desc: create local virtual memory, and get config
1883  * @tc.type: FUNC
1884  */
1885 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_GetConfig_001, TestSize.Level1)
1886 {
1887     capacity_ = MEMSIZE;
1888     align_ = 1;
1889     CreateLocalVirtualMem();
1890     AVBufferConfig config = buffer_->GetConfig();
1891     EXPECT_EQ(config.memoryType, MemoryType::VIRTUAL_MEMORY);
1892     EXPECT_EQ(config.capacity, capacity_);
1893     EXPECT_EQ(config.align, align_);
1894 }
1895 
1896 /**
1897  * @tc.name: AVBuffer_VirtualMemory_SetParams_001
1898  * @tc.desc: virtual memory set params
1899  * @tc.type: FUNC
1900  */
1901 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_SetParams_001, TestSize.Level1)
1902 {
1903     capacity_ = MEMSIZE;
1904     align_ = 0;
1905     CreateLocalVirtualMem();
1906     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1907     CheckMetaSetAndGet();
1908 }
1909 
1910 /**
1911  * @tc.name: AVBuffer_VirtualMemory_WriteAndRead_001
1912  * @tc.desc: virtual memory write and read
1913  * @tc.type: FUNC
1914  */
1915 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_WriteAndRead_001, TestSize.Level1)
1916 {
1917     capacity_ = MEMSIZE;
1918     align_ = 0;
1919     CreateLocalVirtualMem();
1920     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1921     CheckMemTrans();
1922 }
1923 
1924 /**
1925  * @tc.name: AVBuffer_VirtualMemory_GetCapacity_001
1926  * @tc.desc: virtual memory get capacity
1927  * @tc.type: FUNC
1928  */
1929 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_GetCapacity_001, TestSize.Level1)
1930 {
1931     capacity_ = MEMSIZE;
1932     align_ = 0;
1933     CreateLocalVirtualMem();
1934     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1935     EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_);
1936 }
1937 
1938 /**
1939  * @tc.name: AVBuffer_VirtualMemory_CheckDataSize_001
1940  * @tc.desc: virtual memory check dataSize
1941  * @tc.type: FUNC
1942  */
1943 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_CheckDataSize_001, TestSize.Level1)
1944 {
1945     capacity_ = MEMSIZE;
1946     align_ = 0;
1947     CreateLocalVirtualMem();
1948     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1949     CheckDataSize();
1950 }
1951 
1952 /**
1953  * @tc.name: AVBuffer_VirtualMemory_GetMemoryType_001
1954  * @tc.desc: virtual memory get memory type
1955  * @tc.type: FUNC
1956  */
1957 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_GetMemoryType_001, TestSize.Level1)
1958 {
1959     capacity_ = MEMSIZE;
1960     align_ = 0;
1961     CreateLocalVirtualMem();
1962     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1963     EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::VIRTUAL_MEMORY);
1964 }
1965 
1966 /**
1967  * @tc.name: AVBuffer_VirtualMemory_GetFileDescriptor_001
1968  * @tc.desc: virtual memory get memory file descriptor
1969  * @tc.type: FUNC
1970  */
1971 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_GetFileDescriptor_001, TestSize.Level1)
1972 {
1973     capacity_ = MEMSIZE;
1974     align_ = 0;
1975     CreateLocalVirtualMem();
1976     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1977     EXPECT_EQ(buffer_->memory_->GetFileDescriptor(), -1);
1978 }
1979 
1980 /**
1981  * @tc.name: AVBuffer_VirtualMemory_Reset_001
1982  * @tc.desc: virtual memory reset
1983  * @tc.type: FUNC
1984  */
1985 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_Reset_001, TestSize.Level1)
1986 {
1987     memFlag_ = MemoryFlag::MEMORY_READ_WRITE;
1988     capacity_ = MEMSIZE;
1989     align_ = 0;
1990     CreateLocalVirtualMem();
1991     ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr));
1992     buffer_->memory_->SetSize(MEMSIZE);
1993     EXPECT_EQ(buffer_->memory_->size_, MEMSIZE);
1994     buffer_->memory_->Reset();
1995     EXPECT_EQ(buffer_->memory_->size_, 0);
1996 }
1997 
1998 /**
1999  * @tc.name: AVBuffer_VirtualMemory_ReadFromMessageParcel_001
2000  * @tc.desc: null memory read from message parcel
2001  * @tc.type: FUNC
2002  */
2003 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_ReadFromMessageParcel_001, TestSize.Level1)
2004 {
2005     CreateLocalNullMem();
2006     CreateRemoteHardwareMem();
2007     CheckAttrTrans();
2008 }
2009 } // namespace AVBufferUT
2010 } // namespace Media
2011 } // namespace OHOS