• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "avmemory_unittest.h"
17 #include "surface_buffer.h"
18 namespace OHOS {
19 namespace Media {
20 using namespace testing;
21 using namespace testing::ext;
22 
SetUpTestCase(void)23 void AVMemoryUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)24 void AVMemoryUnitTest::TearDownTestCase(void) {}
SetUp(void)25 void AVMemoryUnitTest::SetUp(void) {}
TearDown(void)26 void AVMemoryUnitTest::TearDown(void) {}
27 
28 /**
29  * @tc.name  : Test CreateAVMemory API
30  * @tc.number: CreateAVMemory_001
31  * @tc.desc  : Test case default
32  */
33 HWTEST_F(AVMemoryUnitTest, CreateAVMemory_001, TestSize.Level0)
34 {
35     auto avMemory = std::make_shared<AVMemory>();
36     ASSERT_NE(avMemory, nullptr);
37     MemoryType type = MemoryType::UNKNOWN_MEMORY;
38     std::shared_ptr<MockAVAllocator> mockAllocator = std::make_shared<MockAVAllocator>();
39     EXPECT_CALL(*(mockAllocator), GetMemoryType()).WillRepeatedly(Return(type));
40     std::shared_ptr<AVAllocator> allocator = mockAllocator;
41     auto ret = AVMemory::CreateAVMemory(allocator);
42     EXPECT_EQ(ret, nullptr);
43 }
44 
45 /**
46  * @tc.name  : Test CreateAVMemory API
47  * @tc.number: CreateAVMemory_002
48  * @tc.desc  : Test case MemoryType::VIRTUAL_MEMORY
49  */
50 HWTEST_F(AVMemoryUnitTest, CreateAVMemory_002, TestSize.Level0)
51 {
52     auto avMemory = std::make_shared<AVMemory>();
53     ASSERT_NE(avMemory, nullptr);
54     MessageParcel parcel;
55     parcel.writable_ = true;
56     auto ret = AVMemory::CreateAVMemory(parcel, false);
57     EXPECT_EQ(ret, nullptr);
58 }
59 
60 /**
61  * @tc.name  : Test CreateAVMemory API
62  * @tc.number: CreateAVMemory_003
63  * @tc.desc  : Test case default
64  */
65 HWTEST_F(AVMemoryUnitTest, CreateAVMemory_003, TestSize.Level0)
66 {
67     auto avMemory = std::make_shared<AVMemory>();
68     ASSERT_NE(avMemory, nullptr);
69     MessageParcel parcel;
70     parcel.writable_ = false;
71     auto ret = AVMemory::CreateAVMemory(parcel, false);
72     EXPECT_EQ(ret, nullptr);
73 }
74 
75 /**
76  * @tc.name  : Test Init API
77  * @tc.number: Init_001
78  * @tc.desc  : Test all
79  */
80 HWTEST_F(AVMemoryUnitTest, Init_001, TestSize.Level0)
81 {
82     auto avMemory = std::make_shared<AVMemory>();
83     ASSERT_NE(avMemory, nullptr);
84     auto ret = avMemory->Init();
85     EXPECT_EQ(ret, Status::ERROR_UNIMPLEMENTED);
86 
87     MessageParcel parcel;
88     ret = avMemory->Init(parcel);
89     EXPECT_EQ(ret, Status::ERROR_UNIMPLEMENTED);
90 }
91 
92 /**
93  * @tc.name  : Test InitSurfaceBuffer API
94  * @tc.number: InitSurfaceBuffer_001
95  * @tc.desc  : Test all
96  */
97 HWTEST_F(AVMemoryUnitTest, InitSurfaceBuffer_001, TestSize.Level0)
98 {
99     auto avMemory = std::make_shared<AVMemory>();
100     ASSERT_NE(avMemory, nullptr);
101     sptr<OHOS::SurfaceBuffer> surfaceBuffer;
102     auto ret = avMemory->InitSurfaceBuffer(surfaceBuffer);
103     EXPECT_EQ(ret, Status::ERROR_UNIMPLEMENTED);
104 
105     MessageParcel parcel;
106     ret = avMemory->InitSurfaceBuffer(parcel);
107     EXPECT_EQ(ret, Status::ERROR_UNIMPLEMENTED);
108 }
109 
110 /**
111  * @tc.name  : Test ReadFromMessageParcel API
112  * @tc.number: ReadFromMessageParcel_001
113  * @tc.desc  : Test all
114  */
115 HWTEST_F(AVMemoryUnitTest, ReadFromMessageParcel_001, TestSize.Level0)
116 {
117     auto avMemory = std::make_shared<AVMemory>();
118     ASSERT_NE(avMemory, nullptr);
119     MessageParcel parcel;
120     auto ret = avMemory->ReadFromMessageParcel(parcel);
121     EXPECT_EQ(ret, false);
122 }
123 
124 /**
125  * @tc.name  : Test WriteToMessageParcel API
126  * @tc.number: WriteToMessageParcel_001
127  * @tc.desc  : Test all
128  */
129 HWTEST_F(AVMemoryUnitTest, WriteToMessageParcel_001, TestSize.Level0)
130 {
131     auto avMemory = std::make_shared<AVMemory>();
132     ASSERT_NE(avMemory, nullptr);
133     MessageParcel parcel;
134     auto ret = avMemory->WriteToMessageParcel(parcel);
135     EXPECT_EQ(ret, false);
136 }
137 } // namespace Media
138 } // namespace OHOS