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