• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <gtest/gtest.h>
16 #include <iservice_registry.h>
17 #include <native_buffer.h>
18 #include "surface_type.h"
19 #include "graphic_common_c.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS::Rosen {
25 class NativeBufferTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29 
30     static inline OH_NativeBuffer_Config config = {
31         .width = 0x100,
32         .height = 0x100,
33         .format = PIXEL_FMT_RGBA_8888,
34         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
35     };
36     static inline OH_NativeBuffer_Config checkConfig = {};
37     static inline OH_NativeBuffer* buffer = nullptr;
38 };
39 
SetUpTestCase()40 void NativeBufferTest::SetUpTestCase()
41 {
42     buffer = nullptr;
43 }
44 
TearDownTestCase()45 void NativeBufferTest::TearDownTestCase()
46 {
47     buffer = nullptr;
48 }
49 
50 /*
51  * @tc.name  OHNativeBufferAlloc001
52  * @tc.desc  test for call OH_NativeBuffer_Alloc by abnormal input and check ret
53  * @tc.type  FUNC
54  */
55 HWTEST_F(NativeBufferTest, OHNativeBufferAlloc001, Function | MediumTest | Level2)
56 {
57     buffer = OH_NativeBuffer_Alloc(nullptr);
58     ASSERT_EQ(buffer, nullptr);
59 }
60 
61 /*
62  * @tc.name  OHNativeBufferAlloc002
63  * @tc.desc  test for call OH_NativeBuffer_Alloc and check ret
64  * @tc.type  FUNC
65  */
66 HWTEST_F(NativeBufferTest, OHNativeBufferAlloc002, Function | MediumTest | Level2)
67 {
68     buffer = OH_NativeBuffer_Alloc(&config);
69     ASSERT_NE(buffer, nullptr);
70 }
71 
72 /*
73  * @tc.name  OHNativeBufferGetSeqNum001
74  * @tc.desc  test for call OH_NativeBuffer_GetSeqNum by abnormal input and check ret
75  * @tc.type  FUNC
76  */
77 HWTEST_F(NativeBufferTest, OHNativeBufferGetSeqNum001, Function | MediumTest | Level2)
78 {
79     uint32_t id = OH_NativeBuffer_GetSeqNum(nullptr);
80     ASSERT_EQ(id, GSERROR_INVALID_ARGUMENTS);
81 }
82 
83 /*
84  * @tc.name  OHNativeBufferGetSeqNum002
85  * @tc.desc  test for call OH_NativeBuffer_GetSeqNum and check ret
86  * @tc.type  FUNC
87  */
88 HWTEST_F(NativeBufferTest, OHNativeBufferGetSeqNum002, Function | MediumTest | Level2)
89 {
90     uint32_t id = OH_NativeBuffer_GetSeqNum(buffer);
91     ASSERT_NE(id, GSERROR_INVALID_ARGUMENTS);
92 }
93 
94 /*
95  * @tc.name  OHNativeBufferGetConfig001
96  * @tc.desc  test for call OH_NativeBuffer_GetConfig and check ret
97  * @tc.type  FUNC
98  */
99 HWTEST_F(NativeBufferTest, OHNativeBufferGetConfig001, Function | MediumTest | Level2)
100 {
101     OH_NativeBuffer_GetConfig(buffer, &checkConfig);
102     ASSERT_NE(&checkConfig, nullptr);
103 }
104 
105 /*
106  * @tc.name  OHNativeBufferGetConfig002
107  * @tc.desc  test for call OH_NativeBuffer_GetConfig by abnormal input and check ret
108  * @tc.type  FUNC
109  */
110 HWTEST_F(NativeBufferTest, OHNativeBufferGetConfig002, Function | MediumTest | Level2)
111 {
112     checkConfig.width = 0x0;
113     checkConfig.height = 0x0;
114     checkConfig.format = 0x0;
115     checkConfig.usage = 0x0;
116     OH_NativeBuffer_GetConfig(nullptr, &checkConfig);
117     ASSERT_EQ(checkConfig.width, 0x0);
118     ASSERT_EQ(checkConfig.height, 0x0);
119     ASSERT_EQ(checkConfig.format, 0x0);
120     ASSERT_EQ(checkConfig.usage, 0x0);
121 }
122 
123 
124 /*
125  * @tc.name  OHNativeBufferReference001
126  * @tc.desc  test for call OH_NativeBuffer_Reference by abnormal input and check ret
127  * @tc.type  FUNC
128  */
129 HWTEST_F(NativeBufferTest, OHNativeBufferReference001, Function | MediumTest | Level2)
130 {
131     int32_t ret = OH_NativeBuffer_Reference(nullptr);
132     ASSERT_NE(ret, GSERROR_OK);
133 }
134 
135 /*
136  * @tc.name  OHNativeBufferReference002
137  * @tc.desc  test for call OH_NativeBuffer_Reference and check ret
138  * @tc.type  FUNC
139  */
140 HWTEST_F(NativeBufferTest, OHNativeBufferReference002, Function | MediumTest | Level2)
141 {
142     int32_t ret = OH_NativeBuffer_Reference(buffer);
143     ASSERT_EQ(ret, GSERROR_OK);
144 }
145 
146 /*
147  * @tc.name  OHNativeBufferUnreference001
148  * @tc.desc  test for call OH_NativeBuffer_Unreference by abnormal input and check ret
149  * @tc.type  FUNC
150  */
151 HWTEST_F(NativeBufferTest, OHNativeBufferUnreference001, Function | MediumTest | Level2)
152 {
153     int32_t ret = OH_NativeBuffer_Unreference(nullptr);
154     ASSERT_NE(ret, GSERROR_OK);
155 }
156 
157 /*
158  * @tc.name  OHNativeBufferUnreference002
159  * @tc.desc  test for call OH_NativeBuffer_Unreference and check ret
160  * @tc.type  FUNC
161  */
162 HWTEST_F(NativeBufferTest, OHNativeBufferUnreference002, Function | MediumTest | Level2)
163 {
164     int32_t ret = OH_NativeBuffer_Unreference(buffer);
165     ASSERT_EQ(ret, GSERROR_OK);
166 }
167 
168 /*
169  * @tc.name  OHNativeBufferGetSeqNum003
170  * @tc.desc  test for check OH_NativeBuffer_GetSeqNum
171  * @tc.type  FUNC
172  */
173 HWTEST_F(NativeBufferTest, OHNativeBufferGetSeqNum003, Function | MediumTest | Level2)
174 {
175     uint32_t oldSeq = OH_NativeBuffer_GetSeqNum(buffer);
176     int32_t ret = OH_NativeBuffer_Unreference(buffer);
177     ASSERT_EQ(ret, GSERROR_OK);
178     buffer = OH_NativeBuffer_Alloc(&config);
179     ASSERT_EQ(oldSeq + 1, OH_NativeBuffer_GetSeqNum(buffer));
180 }
181 
182 /*
183  * @tc.name  OHNativeBufferMap001
184  * @tc.desc  test for call OH_NativeBuffer_Map by abnormal input and check ret
185  * @tc.type  FUNC
186  */
187 HWTEST_F(NativeBufferTest, OHNativeBufferMap001, Function | MediumTest | Level2)
188 {
189     void *virAddr = nullptr;
190     int32_t ret = OH_NativeBuffer_Map(nullptr, &virAddr);
191     ASSERT_NE(ret, GSERROR_OK);
192 }
193 
194 /*
195  * @tc.name  OHNativeBufferMap002
196  * @tc.desc  test for call OH_NativeBuffer_Map and check ret
197  * @tc.type  FUNC
198  */
199 HWTEST_F(NativeBufferTest, OHNativeBufferMap002, Function | MediumTest | Level2)
200 {
201     void *virAddr = nullptr;
202     int32_t ret = OH_NativeBuffer_Map(buffer, &virAddr);
203     ASSERT_EQ(ret, GSERROR_OK);
204     ASSERT_NE(virAddr, nullptr);
205 }
206 
207 /*
208  * @tc.name  OHNativeBufferUnmap001
209  * @tc.desc  test for call OH_NativeBuffer_Unmap by abnormal input and check ret
210  * @tc.type  FUNC
211  */
212 HWTEST_F(NativeBufferTest, OHNativeBufferUnmap001, Function | MediumTest | Level2)
213 {
214     int32_t ret = OH_NativeBuffer_Unmap(nullptr);
215     ASSERT_NE(ret, GSERROR_OK);
216 }
217 
218 /*
219  * @tc.name  OHNativeBufferUnmap001
220  * @tc.desc  test for call OH_NativeBuffer_Unmap
221  * @tc.type  FUNC
222  */
223 HWTEST_F(NativeBufferTest, OHNativeBufferUnmap002, Function | MediumTest | Level2)
224 {
225     int32_t ret = OH_NativeBuffer_Unmap(buffer);
226     ASSERT_EQ(ret, GSERROR_OK);
227     ret = OH_NativeBuffer_Unreference(buffer);
228     ASSERT_EQ(ret, GSERROR_OK);
229 }
230 }