• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <gtest/gtest.h>
16 #include <iservice_registry.h>
17 #include <native_window.h>
18 #include <securec.h>
19 #include "surface_type.h"
20 #include "buffer_log.h"
21 #include "external_window.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS::Rosen {
27 class NativeWindowTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31 
32     static inline OHNativeWindow* nativeWindow = nullptr;
33     static inline OHNativeWindowBuffer* nativeWindowBuffer = nullptr;
34     static inline uint32_t sequence = 0;
35 };
36 
SetUpTestCase()37 void NativeWindowTest::SetUpTestCase()
38 {
39 }
40 
TearDownTestCase()41 void NativeWindowTest::TearDownTestCase()
42 {
43 }
44 
45 /*
46  * @tc.name  CreateNativeWindow001
47  * @tc.desc  test for call OH_NativeWindow_CreateNativeWindow by abnormal input and check ret
48  * @tc.type  FUNC
49  */
50 HWTEST_F(NativeWindowTest, CreateNativeWindow001, Function | MediumTest | Level2)
51 {
52     ASSERT_EQ(OH_NativeWindow_CreateNativeWindow(nullptr), nullptr);
53 }
54 
55 /*
56  * @tc.name  OH_NativeWindow_GetNativeObjectMagic
57  * @tc.desc  test for call OH_NativeWindow_GetNativeObjectMagic and check ret
58  * @tc.type  FUNC
59  */
60 HWTEST_F(NativeWindowTest, GetNativeObjectMagic001, Function | MediumTest | Level2)
61 {
62     int32_t ret = OH_NativeWindow_GetNativeObjectMagic(nativeWindow);
63     ASSERT_NE(ret, 0);
64 }
65 
66 /*
67  * @tc.name  HandleOpt001
68  * @tc.desc  test for call OH_NativeWindow_NativeWindowHandleOpt by different param and check ret
69  * @tc.type  FUNC
70  */
71 HWTEST_F(NativeWindowTest, HandleOpt001, Function | MediumTest | Level2)
72 {
73     int code = SET_BUFFER_GEOMETRY;
74     int32_t heightSet = 0x100;
75     int32_t widthSet = 0x100;
76     ASSERT_NE(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, heightSet, widthSet), 0);
77 
78     code = GET_BUFFER_GEOMETRY;
79     int32_t heightGet = 0;
80     int32_t widthGet = 0;
81     ASSERT_NE(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &heightGet, &widthGet), 0);
82     ASSERT_NE(heightSet, heightGet);
83     ASSERT_NE(widthSet, widthGet);
84 }
85 
86 
87 /*
88  * @tc.name  HandleOpt005
89  * @tc.desc  test for call OH_NativeWindow_NativeWindowHandleOpt by different param and check ret
90  * @tc.type  FUNC
91  */
92 HWTEST_F(NativeWindowTest, HandleOpt005, Function | MediumTest | Level2)
93 {
94     int code = SET_STRIDE;
95     int32_t strideSet = 0x8;
96     ASSERT_NE(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, strideSet), 0);
97 
98     code = GET_STRIDE;
99     int32_t strideGet = 0;
100     ASSERT_NE(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &strideGet), 0);
101     ASSERT_NE(strideSet, strideGet);
102 }
103 
104 /*
105  * @tc.name  HandleOpt007
106  * @tc.desc  test for call OH_NativeWindow_NativeWindowHandleOpt by different param and check ret
107  * @tc.type  FUNC
108  */
109 HWTEST_F(NativeWindowTest, HandleOpt007, Function | MediumTest | Level2)
110 {
111     int code = SET_TIMEOUT;
112     int32_t timeoutSet = 10;  // 10: for test
113     ASSERT_NE(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, timeoutSet), 0);
114 
115     code = GET_TIMEOUT;
116     int32_t timeoutGet = 0;
117     ASSERT_NE(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &timeoutGet), 0);
118     ASSERT_NE(timeoutSet, timeoutGet);
119 }
120 
121 /*
122  * @tc.name  CreateNativeWindowBuffer001
123  * @tc.desc  test for call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer by abnormal input and check ret
124  * @tc.type  FUNC
125  */
126 HWTEST_F(NativeWindowTest, CreateNativeWindowBuffer001, Function | MediumTest | Level2)
127 {
128     ASSERT_EQ(OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(nullptr), nullptr);
129 }
130 
131 /*
132  * @tc.name  RequestBuffer001
133  * @tc.desc  test for call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input and check ret
134  * @tc.type  FUNC
135  */
136 HWTEST_F(NativeWindowTest, RequestBuffer001, Function | MediumTest | Level2)
137 {
138     ASSERT_NE(OH_NativeWindow_NativeWindowRequestBuffer(nullptr, &nativeWindowBuffer, nullptr), 0);
139 }
140 
141 /*
142  * @tc.name  RequestBuffer002
143  * @tc.desc  test for call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input and check ret
144  * @tc.type  FUNC
145  */
146 HWTEST_F(NativeWindowTest, RequestBuffer002, Function | MediumTest | Level2)
147 {
148     ASSERT_NE(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, nullptr, nullptr), 0);
149 }
150 
151 /*
152  * @tc.name  GetBufferHandle001
153  * @tc.desc  test for call OH_NativeWindow_GetBufferHandleFromNative by abnormal input and check ret
154  * @tc.type  FUNC
155  */
156 HWTEST_F(NativeWindowTest, GetBufferHandle001, Function | MediumTest | Level2)
157 {
158     ASSERT_EQ(OH_NativeWindow_GetBufferHandleFromNative(nullptr), nullptr);
159 }
160 
161 /*
162  * @tc.name  FlushBuffer001
163  * @tc.desc  test for call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input and check ret
164  * @tc.type  FUNC
165  */
166 HWTEST_F(NativeWindowTest, FlushBuffer001, Function | MediumTest | Level2)
167 {
168     int fenceFd = -1;
169     struct Region *region = new Region();
170     struct Region::Rect * rect = new Region::Rect();
171     rect->x = 0x100;
172     rect->y = 0x100;
173     rect->w = 0x100;
174     rect->h = 0x100;
175     region->rects = rect;
176 
177     ASSERT_NE(OH_NativeWindow_NativeWindowFlushBuffer(nullptr, nullptr, fenceFd, *region), 0);
178     delete region;
179 }
180 
181 /*
182  * @tc.name  FlushBuffer002
183  * @tc.desc  test for call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input and check ret
184  * @tc.type  FUNC
185  */
186 HWTEST_F(NativeWindowTest, FlushBuffer002, Function | MediumTest | Level2)
187 {
188     int fenceFd = -1;
189     struct Region *region = new Region();
190     struct Region::Rect * rect = new Region::Rect();
191     rect->x = 0x100;
192     rect->y = 0x100;
193     rect->w = 0x100;
194     rect->h = 0x100;
195     region->rects = rect;
196 
197     ASSERT_NE(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nullptr, fenceFd, *region), 0);
198     delete region;
199 }
200 
201 /*
202  * @tc.name  CancelBuffer001
203  * @tc.desc  test for call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input and check ret
204  * @tc.type  FUNC
205  */
206 HWTEST_F(NativeWindowTest, CancelBuffer001, Function | MediumTest | Level2)
207 {
208     ASSERT_NE(OH_NativeWindow_NativeWindowAbortBuffer(nullptr, nullptr), 0);
209 }
210 
211 /*
212  * @tc.name  Reference001
213  * @tc.desc  test for call OH_NativeWindow_NativeObjectReference and check ret
214  * @tc.type  FUNC
215  */
216 HWTEST_F(NativeWindowTest, Reference001, Function | MediumTest | Level2)
217 {
218     ASSERT_NE(OH_NativeWindow_NativeObjectReference(nullptr), 0);
219 }
220 
221 /*
222  * @tc.name  Unreference001
223  * @tc.desc  test for call OH_NativeWindow_NativeObjectUnreference and check ret
224  * @tc.type  FUNC
225  */
226 HWTEST_F(NativeWindowTest, Unreference001, Function | MediumTest | Level2)
227 {
228     ASSERT_NE(OH_NativeWindow_NativeObjectUnreference(nullptr), 0);
229 }
230 
231 /*
232  * @tc.name  DestroyNativeWindow001
233  * @tc.desc  test for call OH_NativeWindow_DestroyNativeWindow by abnormal input and check ret
234  * @tc.type  FUNC
235  */
236 HWTEST_F(NativeWindowTest, DestroyNativeWindow001, Function | MediumTest | Level2)
237 {
238     OH_NativeWindow_DestroyNativeWindow(nullptr);
239 }
240 
241 /*
242  * @tc.name  OH_NativeWindow_DestroyNativeWindowBuffer001
243  * @tc.desc  test for call OH_NativeWindow_DestroyNativeWindowBuffer by abnormal input and check ret
244  * @tc.type  FUNC
245  */
246 HWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer001, Function | MediumTest | Level2)
247 {
248     OH_NativeWindow_DestroyNativeWindowBuffer(nullptr);
249 }
250 
251 /*
252  * @tc.name  SetScalingMode001
253  * @tc.desc  test for call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
254  * @tc.type  FUNC
255  */
256 HWTEST_F(NativeWindowTest, SetScalingMode001, Function | MediumTest | Level2)
257 {
258     OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
259     ASSERT_NE(OH_NativeWindow_NativeWindowSetScalingMode(nullptr, -1, scalingMode), 0);
260 }
261 
262 /*
263  * @tc.name  SetScalingMode002
264  * @tc.desc  test for call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
265  * @tc.type  FUNC
266  */
267 HWTEST_F(NativeWindowTest, SetScalingMode002, Function | MediumTest | Level2)
268 {
269     OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
270     ASSERT_NE(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, -1, scalingMode), 0);
271 }
272 
273 
274 /*
275  * @tc.name  SetMetaData001
276  * @tc.desc  test for call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
277  * @tc.type  FUNC
278  */
279 HWTEST_F(NativeWindowTest, SetMetaData001, Function | MediumTest | Level2)
280 {
281     ASSERT_NE(OH_NativeWindow_NativeWindowSetMetaData(nullptr, -1, 0, nullptr), 0);
282 }
283 
284 /*
285  * @tc.name  SetMetaData002
286  * @tc.desc  test for call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
287  * @tc.type  FUNC
288  */
289 HWTEST_F(NativeWindowTest, SetMetaData002, Function | MediumTest | Level2)
290 {
291     ASSERT_NE(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, 0, nullptr), 0);
292 }
293 
294 /*
295  * @tc.name  SetMetaDataSet001
296  * @tc.desc  test for call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
297  * @tc.type  FUNC
298  */
299 HWTEST_F(NativeWindowTest, SetMetaDataSet001, Function | MediumTest | Level2)
300 {
301     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
302     ASSERT_NE(OH_NativeWindow_NativeWindowSetMetaDataSet(nullptr, -1, key, 0, nullptr), 0);
303 }
304 
305 /*
306  * @tc.name  SetMetaDataSet002
307  * @tc.desc  test for call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
308  * @tc.type  FUNC
309  */
310 HWTEST_F(NativeWindowTest, SetMetaDataSet002, Function | MediumTest | Level2)
311 {
312     OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
313     ASSERT_NE(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, 0, nullptr), 0);
314 }
315 
316 /*
317  * @tc.name  SetTunnelHandle001
318  * @tc.desc  test for call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
319  * @tc.type  FUNC
320  */
321 HWTEST_F(NativeWindowTest, SetTunnelHandle001, Function | MediumTest | Level2)
322 {
323     ASSERT_NE(OH_NativeWindow_NativeWindowSetTunnelHandle(nullptr, nullptr), 0);
324 }
325 
326 /*
327  * @tc.name  SetTunnelHandle002
328  * @tc.desc  test for call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
329  * @tc.type  FUNC
330  */
331 HWTEST_F(NativeWindowTest, SetTunnelHandle002, Function | MediumTest | Level2)
332 {
333     ASSERT_NE(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, nullptr), 0);
334 }
335 }