1 /*
2  * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 "DrawingNativePathCommon.h"
17 #include "drawing_color.h"
18 #include "drawing_color_filter.h"
19 #include "drawing_filter.h"
20 #include "drawing_image.h"
21 #include "drawing_matrix.h"
22 #include "drawing_path.h"
23 #include "drawing_path_effect.h"
24 #include "drawing_pen.h"
25 #include "drawing_point.h"
26 #include "drawing_rect.h"
27 #include "drawing_region.h"
28 #include "drawing_round_rect.h"
29 #include "utils/scalar.h"
30 #include "gtest/gtest.h"
31 
32 using namespace testing;
33 using namespace testing::ext;
34 
35 namespace OHOS {
36 namespace Rosen {
37 namespace Drawing {
38 
39 /*
40  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_1900
41  * @tc.name: testPathAddArcNormal
42  * @tc.desc: Test for adding an arc to a path with normal parameters.
43  * @tc.size  : SmallTest
44  * @tc.type  : Function
45  * @tc.level : Level 0
46  */
HWTEST_F(DrawingNativePathTest, testPathAddArcNormal, TestSize.Level0)47 HWTEST_F(DrawingNativePathTest, testPathAddArcNormal, TestSize.Level0) {
48     // 1. Create a path object using OH_Drawing_PathCreate.
49     OH_Drawing_Path *path = OH_Drawing_PathCreate();
50     // 2. Create a rectangle object using OH_Drawing_RectCreate.
51     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
52     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
53     OH_Drawing_PathMoveTo(path, 0, 0);
54     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
55     OH_Drawing_PathLineTo(path, 100, 100);
56     // 5. Add an arc to the path using OH_Drawing_PathAddArc, which serves as the starting point of the new contour.
57     OH_Drawing_PathAddArc(path, rect, 0.0, 0.0);
58     // 6. Free the memory.
59     OH_Drawing_PathDestroy(path);
60     OH_Drawing_RectDestroy(rect);
61 }
62 
63 /*
64  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_1901
65  * @tc.name: testPathAddArcNull
66  * @tc.desc: Test for adding an arc to a path with NULL or invalid parameters.
67  * @tc.size  : SmallTest
68  * @tc.type  : Function
69  * @tc.level : Level 3
70  */
HWTEST_F(DrawingNativePathTest, testPathAddArcNull, TestSize.Level3)71 HWTEST_F(DrawingNativePathTest, testPathAddArcNull, TestSize.Level3) {
72     // 1. Create a path object using OH_Drawing_PathCreate.
73     OH_Drawing_Path *path = OH_Drawing_PathCreate();
74     // 2. Create a rectangle object using OH_Drawing_RectCreate.
75     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
76     // 3. Call OH_Drawing_PathAddArc with a nullptr as the first parameter, expecting OH_DRAWING_ERROR_INVALID_PARAMETER
77     // error code.
78     OH_Drawing_PathAddArc(nullptr, rect, 0.0, 0.0);
79     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
80     // 4. Call OH_Drawing_PathAddArc with a nullptr as the second parameter, expecting
81     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
82     OH_Drawing_PathAddArc(path, nullptr, 0.0, 0.0);
83     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
84     // 5. Call OH_Drawing_PathAddArc with 0.0 as the third parameter, expecting failure without crash.
85     OH_Drawing_PathAddArc(path, rect, 0.0, 0.0);
86     // 6. Call OH_Drawing_PathAddArc with 0.0 as the fourth parameter, expecting failure without crash.
87     OH_Drawing_PathAddArc(path, rect, 0.0, 0.0);
88     // 7. Free the memory.
89     OH_Drawing_PathDestroy(path);
90     OH_Drawing_RectDestroy(rect);
91 }
92 
93 /*
94  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_1902
95  * @tc.name: testPathAddArcAbnormal
96  * @tc.desc: Test for adding an arc to a path with abnormal data types as parameters.
97  * @tc.size  : SmallTest
98  * @tc.type  : Function
99  * @tc.level : Level 3
100  */
HWTEST_F(DrawingNativePathTest, testPathAddArcAbnormal, TestSize.Level3)101 HWTEST_F(DrawingNativePathTest, testPathAddArcAbnormal, TestSize.Level3) {
102     // 1. Create a path object using OH_Drawing_PathCreate.
103     OH_Drawing_Path *path = OH_Drawing_PathCreate();
104     // 2. Create a rectangle object using OH_Drawing_RectCreate.
105     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
106     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
107     OH_Drawing_PathMoveTo(path, 0, 0);
108     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
109     OH_Drawing_PathLineTo(path, 100, 100);
110     // 5. Add an arc to the path using OH_Drawing_PathAddArc, passing an integer or character type as the third
111     // parameter.
112     OH_Drawing_PathAddArc(path, rect, 30, 30.0f);
113     // 6. Add an arc to the path using OH_Drawing_PathAddArc, passing an integer or character type as the fourth
114     // parameter.
115     OH_Drawing_PathAddArc(path, rect, 30.0f, 30);
116     // 7. Free the memory.
117     OH_Drawing_PathDestroy(path);
118 }
119 
120 /*
121  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_1903
122  * @tc.name: testPathAddArcMaximal
123  * @tc.desc: Test for adding an arc to a path with maximal values as parameters.
124  * @tc.size  : SmallTest
125  * @tc.type  : Function
126  * @tc.level : Level 3
127  */
HWTEST_F(DrawingNativePathTest, testPathAddArcMaximal, TestSize.Level3)128 HWTEST_F(DrawingNativePathTest, testPathAddArcMaximal, TestSize.Level3) {
129     // 1. Create a path object using OH_Drawing_PathCreate.
130     OH_Drawing_Path *path = OH_Drawing_PathCreate();
131     // 2. Create a rectangle object using OH_Drawing_RectCreate.
132     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
133     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
134     OH_Drawing_PathMoveTo(path, 0, 0);
135     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
136     OH_Drawing_PathLineTo(path, 100, 100);
137     // 5. Add an arc to the path using OH_Drawing_PathAddArc, passing FLT_MAX + 1 as the third parameter, which will
138     // fail without crashing.
139     OH_Drawing_PathAddArc(path, rect, FLT_MAX + 1, 0.0);
140     // 6. Add an arc to the path using OH_Drawing_PathAddArc, passing FLT_MAX + 1 as the fourth parameter, which will
141     // fail without crashing.
142     OH_Drawing_PathAddArc(path, rect, 0.0, FLT_MAX + 1);
143     // 7. Free the memory.
144     OH_Drawing_PathDestroy(path);
145     OH_Drawing_RectDestroy(rect);
146 }
147 
148 /*
149  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2000
150  * @tc.name: testPathAddPathNormal
151  * @tc.desc: Test for adding a path to another path with normal parameters.
152  * @tc.size  : SmallTest
153  * @tc.type  : Function
154  * @tc.level : Level 0
155  */
HWTEST_F(DrawingNativePathTest, testPathAddPathNormal, TestSize.Level0)156 HWTEST_F(DrawingNativePathTest, testPathAddPathNormal, TestSize.Level0) {
157     // 1. Create a path object using OH_Drawing_PathCreate.
158     OH_Drawing_Path *path = OH_Drawing_PathCreate();
159     // 2. Create a path object using OH_Drawing_PathCreate.
160     OH_Drawing_Path *src = OH_Drawing_PathCreate();
161     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
162     OH_Drawing_PathMoveTo(src, 0, 0);
163     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo (create the source
164     // path src).
165     OH_Drawing_PathLineTo(src, 100, 100);
166     // 5. Add the transformed source path to the current path using OH_Drawing_PathAddPath.
167     OH_Drawing_PathAddPath(path, src, nullptr);
168     // 6. Free the memory.
169     OH_Drawing_PathDestroy(path);
170     OH_Drawing_PathDestroy(src);
171 }
172 
173 /*
174  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2001
175  * @tc.name: testPathAddPathNull
176  * @tc.desc: Test for adding a path to another path with NULL or invalid parameters.
177  * @tc.size  : SmallTest
178  * @tc.type  : Function
179  * @tc.level : Level 3
180  */
HWTEST_F(DrawingNativePathTest, testPathAddPathNull, TestSize.Level3)181 HWTEST_F(DrawingNativePathTest, testPathAddPathNull, TestSize.Level3) {
182     // 1. Create a path object using OH_Drawing_PathCreate.
183     OH_Drawing_Path *path = OH_Drawing_PathCreate();
184     // 2. Create a path object using OH_Drawing_PathCreate.
185     OH_Drawing_Path *src = OH_Drawing_PathCreate();
186     // 3. Call OH_Drawing_PathAddPath with a nullptr as the first parameter, expecting
187     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
188     OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
189     OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1);
190     OH_Drawing_PathAddPath(nullptr, src, matrix);
191     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
192     // 4. Call OH_Drawing_PathAddPath with a nullptr as the second parameter, expecting
193     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
194     OH_Drawing_PathAddPath(path, nullptr, matrix);
195     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
196     // 5. Call OH_Drawing_PathAddPath with a nullptr as the third parameter, expecting failure without crash.
197     OH_Drawing_PathAddPath(path, src, nullptr);
198     // 6. Free the memory.
199     OH_Drawing_PathDestroy(path);
200     OH_Drawing_PathDestroy(src);
201     OH_Drawing_MatrixDestroy(matrix);
202 }
203 
204 /*
205  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2100
206  * @tc.name: testPathAddPathWithMatrixAndModeNormal
207  * @tc.desc: Test for adding a path to another path with matrix and mode transformations using normal parameters.
208  * @tc.size  : SmallTest
209  * @tc.type  : Function
210  * @tc.level : Level 0
211  */
HWTEST_F(DrawingNativePathTest, testPathAddPathWithMatrixAndModeNormal, TestSize.Level0)212 HWTEST_F(DrawingNativePathTest, testPathAddPathWithMatrixAndModeNormal, TestSize.Level0) {
213     // 1. Create a path object using OH_Drawing_PathCreate.
214     OH_Drawing_Path *path = OH_Drawing_PathCreate();
215     // 2. Create a path object using OH_Drawing_PathCreate.
216     OH_Drawing_Path *src = OH_Drawing_PathCreate();
217     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
218     OH_Drawing_PathMoveTo(src, 0, 0);
219     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo (create the source
220     // path src).
221     OH_Drawing_PathLineTo(src, 100, 100);
222     // 5. Add the transformed source path to the current path using OH_Drawing_PathAddPathWithMatrixAndMode. The fourth
223     // parameter enumerates calling this interface.
224     OH_Drawing_PathAddMode modes[] = {PATH_ADD_MODE_APPEND, PATH_ADD_MODE_EXTEND};
225     for (int i = 0; i < 2; i++) {
226         OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
227         OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1);
228         OH_Drawing_PathAddPathWithMatrixAndMode(path, src, matrix, modes[i]);
229         OH_Drawing_MatrixDestroy(matrix);
230     }
231     // 6. Free the memory.
232     OH_Drawing_PathDestroy(path);
233     OH_Drawing_PathDestroy(src);
234 }
235 
236 /*
237  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2101
238  * @tc.name: testPathAddPathWithMatrixAndModeNull
239  * @tc.desc: Test for adding a path to another path with matrix and mode transformations using NULL or invalid
240  * parameters.
241  * @tc.size  : SmallTest
242  * @tc.type  : Function
243  * @tc.level : Level 3
244  */
HWTEST_F(DrawingNativePathTest, testPathAddPathWithMatrixAndModeNull, TestSize.Level3)245 HWTEST_F(DrawingNativePathTest, testPathAddPathWithMatrixAndModeNull, TestSize.Level3) {
246     // 1. Create a path object using OH_Drawing_PathCreate.
247     OH_Drawing_Path *path = OH_Drawing_PathCreate();
248     // 2. Create a path object using OH_Drawing_PathCreate.
249     OH_Drawing_Path *src = OH_Drawing_PathCreate();
250     // 3. Call OH_Drawing_PathAddPathWithMatrixAndMode with a nullptr as the first parameter, expecting
251     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
252     OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
253     OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1);
254     OH_Drawing_PathAddPathWithMatrixAndMode(nullptr, src, matrix, PATH_ADD_MODE_APPEND);
255     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
256     // 4. Call OH_Drawing_PathAddPathWithMatrixAndMode with a nullptr as the second parameter, expecting
257     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
258     OH_Drawing_PathAddPathWithMatrixAndMode(path, nullptr, matrix, PATH_ADD_MODE_APPEND);
259     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
260     // 5. Call OH_Drawing_PathAddPathWithMatrixAndMode with a nullptr as the third parameter, expecting failure without
261     // crash.
262     OH_Drawing_PathAddPathWithMatrixAndMode(path, src, nullptr, PATH_ADD_MODE_APPEND);
263     // 6. Free the memory.
264     OH_Drawing_PathDestroy(path);
265     OH_Drawing_PathDestroy(src);
266     OH_Drawing_MatrixDestroy(matrix);
267 }
268 
269 /*
270  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2200
271  * @tc.name: testPathAddPathWithModeNormal
272  * @tc.desc: Test for adding a path to another path with mode transformations using normal parameters.
273  * @tc.size  : SmallTest
274  * @tc.type  : Function
275  * @tc.level : Level 0
276  */
HWTEST_F(DrawingNativePathTest, testPathAddPathWithModeNormal, TestSize.Level0)277 HWTEST_F(DrawingNativePathTest, testPathAddPathWithModeNormal, TestSize.Level0) {
278     // 1. Create a path object using OH_Drawing_PathCreate.
279     OH_Drawing_Path *path = OH_Drawing_PathCreate();
280     // 2. Create a path object using OH_Drawing_PathCreate.
281     OH_Drawing_Path *src = OH_Drawing_PathCreate();
282     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
283     OH_Drawing_PathMoveTo(src, 0, 0);
284     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo (create the source
285     // path src).
286     OH_Drawing_PathLineTo(src, 100, 100);
287     // 5. Add the source path to the current path using OH_Drawing_PathAddPathWithMode. The third parameter enumerates
288     // calling this interface.
289     OH_Drawing_PathAddMode modes[] = {PATH_ADD_MODE_APPEND, PATH_ADD_MODE_EXTEND};
290     for (int i = 0; i < 2; i++) {
291         OH_Drawing_PathAddPathWithMode(path, src, modes[i]);
292     }
293     // 6. Free the memory.
294     OH_Drawing_PathDestroy(path);
295 }
296 
297 /*
298  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2201
299  * @tc.name: testPathAddPathWithModeNull
300  * @tc.desc: Test for adding a path to another path with mode transformations using NULL or invalid parameters.
301  * @tc.size  : SmallTest
302  * @tc.type  : Function
303  * @tc.level : Level 3
304  */
HWTEST_F(DrawingNativePathTest, testPathAddPathWithModeNull, TestSize.Level3)305 HWTEST_F(DrawingNativePathTest, testPathAddPathWithModeNull, TestSize.Level3) {
306     // 1. Create a path object using OH_Drawing_PathCreate.
307     OH_Drawing_Path *path = OH_Drawing_PathCreate();
308     // 2. Create a path object using OH_Drawing_PathCreate.
309     OH_Drawing_Path *src = OH_Drawing_PathCreate();
310     // 3. Call OH_Drawing_PathAddPathWithMode with a nullptr as the first parameter, expecting
311     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
312     OH_Drawing_PathAddPathWithMode(nullptr, src, PATH_ADD_MODE_APPEND);
313     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
314     // 4. Call OH_Drawing_PathAddPathWithMode with a nullptr as the second parameter, expecting
315     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
316     OH_Drawing_PathAddPathWithMode(path, nullptr, PATH_ADD_MODE_APPEND);
317     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
318     // 5. Free the memory.
319     OH_Drawing_PathDestroy(path);
320     OH_Drawing_PathDestroy(src);
321 }
322 
323 /*
324  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2300
325  * @tc.name: testPathAddPathWithOffsetAndModeNormal
326  * @tc.desc: Test for adding a path to another path with offset and mode transformations using normal parameters.
327  * @tc.size  : SmallTest
328  * @tc.type  : Function
329  * @tc.level : Level 0
330  */
HWTEST_F(DrawingNativePathTest, testPathAddPathWithOffsetAndModeNormal, TestSize.Level0)331 HWTEST_F(DrawingNativePathTest, testPathAddPathWithOffsetAndModeNormal, TestSize.Level0) {
332     // 1. Create a path object using OH_Drawing_PathCreate.
333     OH_Drawing_Path *path = OH_Drawing_PathCreate();
334     // 2. Create a path object using OH_Drawing_PathCreate.
335     OH_Drawing_Path *src = OH_Drawing_PathCreate();
336     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
337     OH_Drawing_PathMoveTo(src, 0, 0);
338     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo (create the source
339     // path src).
340     OH_Drawing_PathLineTo(src, 100, 100);
341     // 5. Add the transformed source path to the current path using OH_Drawing_PathAddPathWithOffsetAndMode. The fifth
342     // parameter enumerates calling this interface.
343     OH_Drawing_PathAddMode modes[] = {PATH_ADD_MODE_APPEND, PATH_ADD_MODE_EXTEND};
344     for (int i = 0; i < 2; i++) {
345         OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 10.0, 10.0, modes[i]);
346     }
347     // 6. Free the memory.
348     OH_Drawing_PathDestroy(path);
349     OH_Drawing_PathDestroy(src);
350 }
351 
352 /*
353  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2301
354  * @tc.name: testPathAddPathWithOffsetAndModeNull
355  * @tc.desc: Test for adding a path to another path with offset and mode transformations using NULL or invalid
356  * parameters.
357  * @tc.size  : SmallTest
358  * @tc.type  : Function
359  * @tc.level : Level 3
360  */
HWTEST_F(DrawingNativePathTest, testPathAddPathWithOffsetAndModeNull, TestSize.Level3)361 HWTEST_F(DrawingNativePathTest, testPathAddPathWithOffsetAndModeNull, TestSize.Level3) {
362     // 1. Create a path object using OH_Drawing_PathCreate.
363     OH_Drawing_Path *path = OH_Drawing_PathCreate();
364     // 2. Create a path object using OH_Drawing_PathCreate.
365     OH_Drawing_Path *src = OH_Drawing_PathCreate();
366     // 3. Call OH_Drawing_PathAddPathWithOffsetAndMode with a nullptr as the first parameter, expecting
367     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
368     OH_Drawing_PathAddPathWithOffsetAndMode(nullptr, src, 10.0, 10.0, PATH_ADD_MODE_APPEND);
369     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
370     // 4. Call OH_Drawing_PathAddPathWithOffsetAndMode with a nullptr as the second parameter, expecting
371     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
372     OH_Drawing_PathAddPathWithOffsetAndMode(path, nullptr, 10.0, 10.0, PATH_ADD_MODE_APPEND);
373     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
374     // 5. Call OH_Drawing_PathAddPathWithOffsetAndMode with 0.00 as the third parameter, expecting failure without
375     // crash.
376     OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 0.0, 10.0, PATH_ADD_MODE_APPEND);
377     // 6. Call OH_Drawing_PathAddPathWithOffsetAndMode with 0.00 as the fourth parameter, expecting failure without
378     // crash.
379     OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 10.0, 0.0, PATH_ADD_MODE_APPEND);
380     // 7. Free the memory.
381     OH_Drawing_PathDestroy(path);
382     OH_Drawing_PathDestroy(src);
383 }
384 
385 /*
386  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2302
387  * @tc.name: testPathAddPathWithOffsetAndModeAbnormal
388  * @tc.desc: Test for adding a path to another path with offset and mode transformations using abnormal parameters.
389  * @tc.size  : SmallTest
390  * @tc.type  : Function
391  * @tc.level : Level 3
392  */
HWTEST_F(DrawingNativePathTest, testPathAddPathWithOffsetAndModeAbnormal, TestSize.Level3)393 HWTEST_F(DrawingNativePathTest, testPathAddPathWithOffsetAndModeAbnormal, TestSize.Level3) {
394     // 1. Create a path object using OH_Drawing_PathCreate.
395     OH_Drawing_Path *path = OH_Drawing_PathCreate();
396     // 2. Create a path object using OH_Drawing_PathCreate.
397     OH_Drawing_Path *src = OH_Drawing_PathCreate();
398     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
399     OH_Drawing_PathMoveTo(src, 0, 0);
400     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo (create the source
401     // path src).
402     OH_Drawing_PathLineTo(src, 100, 100);
403     // 5. Call OH_Drawing_PathAddPathWithOffsetAndMode with an integer as the third parameter, expecting successful
404     // call.
405     OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 10, 10.0f, PATH_ADD_MODE_APPEND);
406     // 6. Call OH_Drawing_PathAddPathWithOffsetAndMode with an integer as the fourth parameter, expecting successful
407     // call.
408     OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 10.0f, 10, PATH_ADD_MODE_APPEND);
409     // 7. Free the memory.
410     OH_Drawing_PathDestroy(path);
411     OH_Drawing_PathDestroy(src);
412 }
413 
414 /*
415  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2303
416  * @tc.name: testPathAddPathWithOffsetAndModeMaximal
417  * @tc.desc: Test for adding a path to another path with offset and mode transformations using maximal values.
418  * @tc.size  : SmallTest
419  * @tc.type  : Function
420  * @tc.level : Level 3
421  */
HWTEST_F(DrawingNativePathTest, testPathAddPathWithOffsetAndModeMaximal, TestSize.Level3)422 HWTEST_F(DrawingNativePathTest, testPathAddPathWithOffsetAndModeMaximal, TestSize.Level3) {
423     // 1. Create a path object using OH_Drawing_PathCreate.
424     OH_Drawing_Path *path = OH_Drawing_PathCreate();
425     // 2. Create a path object using OH_Drawing_PathCreate.
426     OH_Drawing_Path *src = OH_Drawing_PathCreate();
427     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
428     OH_Drawing_PathMoveTo(src, 0, 0);
429     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo (create the source
430     // path src).
431     OH_Drawing_PathLineTo(src, 100, 100);
432     // 5. Call OH_Drawing_PathAddPathWithOffsetAndMode with the third parameter as FLT_MAX + 1, without crashing.
433     OH_Drawing_PathAddPathWithOffsetAndMode(path, src, FLT_MAX + 1, 10.0f, PATH_ADD_MODE_APPEND);
434     // 6. Call OH_Drawing_PathAddPathWithOffsetAndMode with the fourth parameter as FLT_MAX + 1, without crashing.
435     OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 10.0f, FLT_MAX + 1, PATH_ADD_MODE_APPEND);
436     // 7. Free the memory.
437     OH_Drawing_PathDestroy(path);
438 }
439 
440 /*
441  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2400
442  * @tc.name: testPathAddOvalNormal
443  * @tc.desc: Test for adding an oval to a path using normal parameters.
444  * @tc.size  : SmallTest
445  * @tc.type  : Function
446  * @tc.level : Level 0
447  */
HWTEST_F(DrawingNativePathTest, testPathAddOvalNormal, TestSize.Level0)448 HWTEST_F(DrawingNativePathTest, testPathAddOvalNormal, TestSize.Level0) {
449     // 1. Create a path object using OH_Drawing_PathCreate.
450     OH_Drawing_Path *path = OH_Drawing_PathCreate();
451     // 2. Create a rectangle object using OH_Drawing_RectCreate.
452     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
453     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
454     OH_Drawing_PathMoveTo(path, 0, 0);
455     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
456     OH_Drawing_PathLineTo(path, 100, 100);
457     // 5. Add an oval to the path with the specified direction using OH_Drawing_PathAddOval. The third parameter
458     // enumerates calling this interface.
459     OH_Drawing_PathDirection directions[] = {PATH_DIRECTION_CW, PATH_DIRECTION_CCW};
460     for (int i = 0; i < 2; i++) {
461         OH_Drawing_PathAddOval(path, rect, directions[i]);
462     }
463     // 6. Free the memory.
464     OH_Drawing_PathDestroy(path);
465     OH_Drawing_RectDestroy(rect);
466 }
467 
468 /*
469  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2401
470  * @tc.name: testPathAddOvalNull
471  * @tc.desc: Test for adding an oval to a path using NULL or invalid parameters.
472  * @tc.size  : SmallTest
473  * @tc.type  : Function
474  * @tc.level : Level 3
475  */
HWTEST_F(DrawingNativePathTest, testPathAddOvalNull, TestSize.Level3)476 HWTEST_F(DrawingNativePathTest, testPathAddOvalNull, TestSize.Level3) {
477     // 1. Create a path object using OH_Drawing_PathCreate.
478     OH_Drawing_Path *path = OH_Drawing_PathCreate();
479     // 2. Create a rectangle object using OH_Drawing_RectCreate.
480     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
481     // 3. Call OH_Drawing_PathAddOval with a nullptr as the first parameter, expecting
482     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
483     OH_Drawing_PathAddOval(nullptr, rect, PATH_DIRECTION_CW);
484     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
485     // 4. Call OH_Drawing_PathAddOval with a nullptr as the second parameter, expecting
486     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
487     OH_Drawing_PathAddOval(path, nullptr, PATH_DIRECTION_CW);
488     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
489     // 5. Free the memory.
490     OH_Drawing_PathDestroy(path);
491     OH_Drawing_RectDestroy(rect);
492 }
493 
494 /*
495  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2500
496  * @tc.name: testPathAddPolygonNormal
497  * @tc.desc: Test for adding a polygon to a path with the fourth parameter set to true.
498  * @tc.size  : SmallTest
499  * @tc.type  : Function
500  * @tc.level : Level 0
501  */
HWTEST_F(DrawingNativePathTest, testPathAddPolygonNormal, TestSize.Level0)502 HWTEST_F(DrawingNativePathTest, testPathAddPolygonNormal, TestSize.Level0) {
503     // 1. Create a path object using OH_Drawing_PathCreate.
504     OH_Drawing_Path *path = OH_Drawing_PathCreate();
505     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
506     OH_Drawing_PathMoveTo(path, 0, 0);
507     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
508     OH_Drawing_PathLineTo(path, 100, 100);
509     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
510     OH_Drawing_PathLineTo(path, 100, 0);
511     // 5. Add a polygon to the path. Set the fourth parameter to true.
512     OH_Drawing_Point2D point1 = {0, 0};
513     OH_Drawing_Point2D point2 = {100, 0};
514     OH_Drawing_Point2D point3 = {100, 100};
515     OH_Drawing_Point2D point4 = {0, 100};
516     OH_Drawing_Point2D points[4] = {point1, point2, point3, point4};
517     OH_Drawing_PathAddPolygon(path, points, 4, true);
518     // 6. Free the memory.
519     OH_Drawing_PathDestroy(path);
520 }
521 
522 /*
523  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2501
524  * @tc.name: testPathAddPolygonNormal2
525  * @tc.desc: Test for adding a polygon to a path with the fourth parameter set to false.
526  * @tc.size  : SmallTest
527  * @tc.type  : Function
528  * @tc.level : Level 0
529  */
HWTEST_F(DrawingNativePathTest, testPathAddPolygonNormal2, TestSize.Level0)530 HWTEST_F(DrawingNativePathTest, testPathAddPolygonNormal2, TestSize.Level0) {
531     // 1. Create a path object using OH_Drawing_PathCreate.
532     OH_Drawing_Path *path = OH_Drawing_PathCreate();
533     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
534     OH_Drawing_PathMoveTo(path, 0, 0);
535     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
536     OH_Drawing_PathLineTo(path, 100, 100);
537     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
538     OH_Drawing_PathLineTo(path, 100, 0);
539     // 5. Add a polygon to the path. Set the fourth parameter to false.
540     OH_Drawing_Point2D point1 = {0, 0};
541     OH_Drawing_Point2D point2 = {100, 0};
542     OH_Drawing_Point2D point3 = {100, 100};
543     OH_Drawing_Point2D point4 = {0, 100};
544     OH_Drawing_Point2D points[4] = {point1, point2, point3, point4};
545     OH_Drawing_PathAddPolygon(path, points, 4, false);
546     // 6. Free the memory.
547     OH_Drawing_PathDestroy(path);
548 }
549 
550 /*
551  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2502
552  * @tc.name: testPathAddPolygonNull
553  * @tc.desc: Test for adding a polygon to a path using NULL or invalid parameters.
554  * @tc.size  : SmallTest
555  * @tc.type  : Function
556  * @tc.level : Level 3
557  */
HWTEST_F(DrawingNativePathTest, testPathAddPolygonNull, TestSize.Level3)558 HWTEST_F(DrawingNativePathTest, testPathAddPolygonNull, TestSize.Level3) {
559     // 1. Create a path object using OH_Drawing_PathCreate.
560     OH_Drawing_Path *path = OH_Drawing_PathCreate();
561     OH_Drawing_Point2D point1 = {0, 0};
562     OH_Drawing_Point2D point2 = {100, 0};
563     OH_Drawing_Point2D point3 = {100, 100};
564     OH_Drawing_Point2D point4 = {0, 100};
565     OH_Drawing_Point2D points[4] = {point1, point2, point3, point4};
566     // 2. Call OH_Drawing_PathAddPolygon with a nullptr as the first parameter, expecting
567     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
568     OH_Drawing_PathAddPolygon(nullptr, points, 4, true);
569     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
570     // 3. Call OH_Drawing_PathAddPolygon with a nullptr as the second parameter, expecting
571     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
572     OH_Drawing_PathAddPolygon(path, nullptr, 4, true);
573     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
574     // 4. Call OH_Drawing_PathAddPolygon with the third parameter as 0, expecting OH_DRAWING_ERROR_INVALID_PARAMETER
575     // error code.
576     OH_Drawing_PathAddPolygon(path, points, 0, true);
577     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
578     // 5. Free the memory.
579     OH_Drawing_PathDestroy(path);
580 }
581 
582 /*
583  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2503
584  * @tc.name: testPathAddPolygonAbnormal
585  * @tc.desc: Test for adding a polygon to a path using abnormal parameters.
586  * @tc.size  : SmallTest
587  * @tc.type  : Function
588  * @tc.level : Level 3
589  */
HWTEST_F(DrawingNativePathTest, testPathAddPolygonAbnormal, TestSize.Level3)590 HWTEST_F(DrawingNativePathTest, testPathAddPolygonAbnormal, TestSize.Level3) {
591     // 1. Create a path object using OH_Drawing_PathCreate.
592     OH_Drawing_Path *path = OH_Drawing_PathCreate();
593     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
594     OH_Drawing_PathMoveTo(path, 0, 0);
595     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
596     OH_Drawing_PathLineTo(path, 100, 100);
597     // 4. Add a polygon to the path with the second parameter's x-coordinate as an integer or character type, which will
598     // succeed.
599     OH_Drawing_Point2D point1 = {0, 0};
600     OH_Drawing_Point2D point2 = {100, 0};
601     OH_Drawing_Point2D point3 = {100, 100};
602     OH_Drawing_Point2D point4 = {0, 100};
603     OH_Drawing_Point2D points[4] = {point1, point2, point3, point4};
604     OH_Drawing_PathAddPolygon(path, points, 4, true);
605     // 5. Add a polygon to the path with the second parameter's y-coordinate as an integer or character type, which will
606     // succeed.
607     OH_Drawing_PathAddPolygon(path, points, 4, true);
608     // 6. Add a polygon to the path with the third parameter as a float or character type, which will succeed.
609     OH_Drawing_PathAddPolygon(path, points, 4.0f, true);
610     // 7. Free the memory.
611     OH_Drawing_PathDestroy(path);
612 }
613 
614 /*
615  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2504
616  * @tc.name: testPathAddPolygonMaximal
617  * @tc.desc: Test for adding a polygon to a path using maximal values.
618  * @tc.size  : SmallTest
619  * @tc.type  : Function
620  * @tc.level : Level 3
621  */
HWTEST_F(DrawingNativePathTest, testPathAddPolygonMaximal, TestSize.Level3)622 HWTEST_F(DrawingNativePathTest, testPathAddPolygonMaximal, TestSize.Level3) {
623     // 1. Create a path object using OH_Drawing_PathCreate.
624     OH_Drawing_Path *path = OH_Drawing_PathCreate();
625     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
626     OH_Drawing_PathMoveTo(path, 0, 0);
627     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
628     OH_Drawing_PathLineTo(path, 100, 100);
629     // 4. Add a polygon to the path with the second parameter's x-coordinate set to FLT_MAX + 1, no crash occurs.
630     OH_Drawing_Point2D point1 = {FLT_MAX + 1, 0};
631     OH_Drawing_Point2D point2 = {FLT_MAX + 1, 0};
632     OH_Drawing_Point2D point3 = {FLT_MAX + 1, 100};
633     OH_Drawing_Point2D point4 = {FLT_MAX + 1, 100};
634     OH_Drawing_Point2D points[4] = {point1, point2, point3, point4};
635     OH_Drawing_PathAddPolygon(path, points, 4, true);
636     // 5. Add a polygon to the path with the second parameter's y-coordinate set to FLT_MAX + 1, no crash occurs.
637     OH_Drawing_Point2D point5 = {0, FLT_MAX + 1};
638     OH_Drawing_Point2D point6 = {100, FLT_MAX + 1};
639     OH_Drawing_Point2D point7 = {100, FLT_MAX + 1};
640     OH_Drawing_Point2D point8 = {0, FLT_MAX + 1};
641     OH_Drawing_Point2D points2[4] = {point5, point6, point7, point8};
642     OH_Drawing_PathAddPolygon(path, points2, 4, true);
643     // 6. Free the memory.
644     OH_Drawing_PathDestroy(path);
645 }
646 
647 /*
648  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2600
649  * @tc.name: testPathAddCircleNormal
650  * @tc.desc: Test for adding a circle to a path using normal parameters.
651  * @tc.size  : SmallTest
652  * @tc.type  : Function
653  * @tc.level : Level 0
654  */
HWTEST_F(DrawingNativePathTest, testPathAddCircleNormal, TestSize.Level0)655 HWTEST_F(DrawingNativePathTest, testPathAddCircleNormal, TestSize.Level0) {
656     // 1. Create a path object using OH_Drawing_PathCreate.
657     OH_Drawing_Path *path = OH_Drawing_PathCreate();
658     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
659     OH_Drawing_PathMoveTo(path, 0, 0);
660     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
661     OH_Drawing_PathLineTo(path, 100, 100);
662     // 4. Add a circle to the path with the specified direction.
663     OH_Drawing_PathAddCircle(path, 50, 50, 10, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
664     OH_Drawing_PathAddCircle(path, 50, 50, 10, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
665     // 5. Free the memory.
666     OH_Drawing_PathDestroy(path);
667 }
668 
669 /*
670  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2601
671  * @tc.name: testPathAddCircleNull
672  * @tc.desc: Test for adding a circle to a path using NULL or invalid parameters.
673  * @tc.size  : SmallTest
674  * @tc.type  : Function
675  * @tc.level : Level 3
676  */
HWTEST_F(DrawingNativePathTest, testPathAddCircleNull, TestSize.Level3)677 HWTEST_F(DrawingNativePathTest, testPathAddCircleNull, TestSize.Level3) {
678     // 1. Create a path object using OH_Drawing_PathCreate.
679     OH_Drawing_Path *path = OH_Drawing_PathCreate();
680     // 2. Call OH_Drawing_PathAddCircle with a nullptr as the first parameter, expecting
681     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
682     OH_Drawing_PathAddCircle(nullptr, 50, 50, 10, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
683     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
684     // 3. Call OH_Drawing_PathAddCircle with the second parameter as 0.00, which will fail without crashing.
685     OH_Drawing_PathAddCircle(path, 0.00, 50, 10, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
686     // 4. Call OH_Drawing_PathAddCircle with the third parameter as 0.00, which will fail without crashing.
687     OH_Drawing_PathAddCircle(path, 50, 0.00, 10, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
688     // 5. Call OH_Drawing_PathAddCircle with the fourth parameter less than or equal to 0.00, expecting
689     // OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE error code.
690     OH_Drawing_PathAddCircle(path, 50, 50, 0.00, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
691     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE);
692     // 6. Free the memory.
693     OH_Drawing_PathDestroy(path);
694 }
695 
696 /*
697  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2602
698  * @tc.name: testPathAddCircleAbnormal
699  * @tc.desc: Test for adding a circle to a path using abnormal parameters.
700  * @tc.size  : SmallTest
701  * @tc.type  : Function
702  * @tc.level : Level 3
703  */
HWTEST_F(DrawingNativePathTest, testPathAddCircleAbnormal, TestSize.Level3)704 HWTEST_F(DrawingNativePathTest, testPathAddCircleAbnormal, TestSize.Level3) {
705     // 1. Create a path object using OH_Drawing_PathCreate.
706     OH_Drawing_Path *path = OH_Drawing_PathCreate();
707     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
708     OH_Drawing_PathMoveTo(path, 0, 0);
709     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
710     OH_Drawing_PathLineTo(path, 100, 100);
711     // 4. Add a circle to the path with the second parameter as an integer, which will succeed.
712     OH_Drawing_PathAddCircle(path, 50, 50.0f, 10.0f, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
713     // 5. Add a circle to the path with the third parameter as an integer, which will succeed.
714     OH_Drawing_PathAddCircle(path, 50.0f, 50, 10.0f, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
715     // 6. Add a circle to the path with the fourth parameter as an integer, which will succeed.
716     OH_Drawing_PathAddCircle(path, 50.0f, 50.0f, 10, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
717     // 7. Free the memory.
718     OH_Drawing_PathDestroy(path);
719 }
720 
721 /*
722  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2603
723  * @tc.name: testPathAddCircleMaximal
724  * @tc.desc: Test for adding a circle to a path using maximal values.
725  * @tc.size  : SmallTest
726  * @tc.type  : Function
727  * @tc.level : Level 3
728  */
HWTEST_F(DrawingNativePathTest, testPathAddCircleMaximal, TestSize.Level3)729 HWTEST_F(DrawingNativePathTest, testPathAddCircleMaximal, TestSize.Level3) {
730     // 1. Create a path object using OH_Drawing_PathCreate.
731     OH_Drawing_Path *path = OH_Drawing_PathCreate();
732     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
733     OH_Drawing_PathMoveTo(path, 0, 0);
734     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
735     OH_Drawing_PathLineTo(path, 100, 100);
736     // 4. Add a circle to the path with the second parameter set to FLT_MAX + 1, no crash occurs.
737     OH_Drawing_PathAddCircle(path, FLT_MAX + 1, 50, 10, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
738     // 5. Add a circle to the path with the third parameter set to FLT_MAX + 1, no crash occurs.
739     OH_Drawing_PathAddCircle(path, 50, FLT_MAX + 1, 10, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
740     // 6. Add a circle to the path with the fourth parameter set to FLT_MAX + 1, no crash occurs.
741     OH_Drawing_PathAddCircle(path, 50, 50, FLT_MAX + 1, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
742     // 7. Free the memory.
743     OH_Drawing_PathDestroy(path);
744 }
745 
746 /*
747  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2700
748  * @tc.name: testPathBuildFromSvgStringNormal
749  * @tc.desc: Test for building a path from an SVG string using normal parameters.
750  * @tc.size  : SmallTest
751  * @tc.type  : Function
752  * @tc.level : Level 0
753  */
HWTEST_F(DrawingNativePathTest, testPathBuildFromSvgStringNormal, TestSize.Level0)754 HWTEST_F(DrawingNativePathTest, testPathBuildFromSvgStringNormal, TestSize.Level0) {
755     // 1. Create a path object using OH_Drawing_PathCreate.
756     OH_Drawing_Path *path = OH_Drawing_PathCreate();
757     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
758     OH_Drawing_PathMoveTo(path, 0, 0);
759     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
760     OH_Drawing_PathLineTo(path, 100, 100);
761     // 4. Parse the path represented by the SVG string using OH_Drawing_PathBuildFromSvgString.
762     const char *svgString = "M 0 0 L 100 100";
763     OH_Drawing_PathBuildFromSvgString(path, svgString);
764     // 5. Free the memory.
765     OH_Drawing_PathDestroy(path);
766 }
767 
768 /*
769  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2701
770  * @tc.name: testPathBuildFromSvgStringNull
771  * @tc.desc: Test for building a path from an SVG string using NULL or invalid parameters.
772  * @tc.size  : SmallTest
773  * @tc.type  : Function
774  * @tc.level : Level 3
775  */
HWTEST_F(DrawingNativePathTest, testPathBuildFromSvgStringNull, TestSize.Level3)776 HWTEST_F(DrawingNativePathTest, testPathBuildFromSvgStringNull, TestSize.Level3) {
777     // 1. Create a path object using OH_Drawing_PathCreate.
778     OH_Drawing_Path *path = OH_Drawing_PathCreate();
779     // 2. Call OH_Drawing_PathBuildFromSvgString with a nullptr as the first parameter, expecting
780     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
781     OH_Drawing_PathBuildFromSvgString(nullptr, "M 0 0 L 100 100");
782     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
783     // 3. Call OH_Drawing_PathBuildFromSvgString with a nullptr as the second parameter, expecting
784     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
785     OH_Drawing_PathBuildFromSvgString(path, nullptr);
786     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
787     // 4. Free the memory.
788     OH_Drawing_PathDestroy(path);
789 }
790 
791 /*
792  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2800
793  * @tc.name: testPathContainsNormal
794  * @tc.desc: Test for checking if a path contains a specified point using normal parameters.
795  * @tc.size  : SmallTest
796  * @tc.type  : Function
797  * @tc.level : Level 0
798  */
HWTEST_F(DrawingNativePathTest, testPathContainsNormal, TestSize.Level0)799 HWTEST_F(DrawingNativePathTest, testPathContainsNormal, TestSize.Level0) {
800     // 1. Create a path object using OH_Drawing_PathCreate.
801     OH_Drawing_Path *path = OH_Drawing_PathCreate();
802     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
803     OH_Drawing_PathMoveTo(path, 0, 0);
804     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
805     OH_Drawing_PathLineTo(path, 100, 100);
806     // 4. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
807     OH_Drawing_PathLineTo(path, 100, 0);
808     // 5. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
809     OH_Drawing_PathLineTo(path, 0, 0);
810     // 6. Close the path using OH_Drawing_PathClose.
811     OH_Drawing_PathClose(path);
812     // 7. Check if the specified coordinates are contained in the path using OH_Drawing_PathContains.
813     EXPECT_EQ(OH_Drawing_PathContains(path, 50, 50), true);
814     // 8. Free the memory.
815     OH_Drawing_PathDestroy(path);
816 }
817 
818 /*
819  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2801
820  * @tc.name: testPathContainsNull
821  * @tc.desc: Test for checking if a path contains a specified point using NULL or invalid parameters.
822  * @tc.size  : SmallTest
823  * @tc.type  : Function
824  * @tc.level : Level 3
825  */
HWTEST_F(DrawingNativePathTest, testPathContainsNull, TestSize.Level3)826 HWTEST_F(DrawingNativePathTest, testPathContainsNull, TestSize.Level3) {
827     // 1. Create a path object using OH_Drawing_PathCreate.
828     OH_Drawing_Path *path = OH_Drawing_PathCreate();
829     // 2. Call OH_Drawing_PathContains with a nullptr as the first parameter, expecting
830     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
831     OH_Drawing_PathContains(nullptr, 50, 50);
832     // 3. Call OH_Drawing_PathContains with the second parameter as 0.00, the call fails without crashing.
833     OH_Drawing_PathContains(path, 0.0, 50);
834     // 4. Call OH_Drawing_PathContains with the third parameter as 0.00, the call fails without crashing.
835     OH_Drawing_PathContains(path, 50, 0.0);
836     // 5. Free the memory.
837     OH_Drawing_PathDestroy(path);
838 }
839 
840 /*
841  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2802
842  * @tc.name: testPathContainsAbnormal
843  * @tc.desc: Test for checking if a path contains a specified point using abnormal parameters.
844  * @tc.size  : SmallTest
845  * @tc.type  : Function
846  * @tc.level : Level 3
847  */
HWTEST_F(DrawingNativePathTest, testPathContainsAbnormal, TestSize.Level3)848 HWTEST_F(DrawingNativePathTest, testPathContainsAbnormal, TestSize.Level3) {
849     // 1. Create a path object using OH_Drawing_PathCreate.
850     OH_Drawing_Path *path = OH_Drawing_PathCreate();
851     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
852     OH_Drawing_PathMoveTo(path, 0, 0);
853     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
854     OH_Drawing_PathLineTo(path, 100, 100);
855     // 4. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
856     OH_Drawing_PathLineTo(path, 100, 0);
857     // 5. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
858     OH_Drawing_PathLineTo(path, 0, 0);
859     // 6. Close the path using OH_Drawing_PathClose.
860     OH_Drawing_PathClose(path);
861     // 7. Check if the specified coordinates are contained in the path using OH_Drawing_PathContains.
862     OH_Drawing_PathContains(path, 50, 50.0f);
863     // 8. Check if the specified coordinates are contained in the path using OH_Drawing_PathContains.
864     OH_Drawing_PathContains(path, 50.0f, 50);
865     // 9. Free the memory.
866     OH_Drawing_PathDestroy(path);
867 }
868 
869 /*
870  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2803
871  * @tc.name: testPathContainsMaximal
872  * @tc.desc: Test for checking if a path contains a specified point using maximal values.
873  * @tc.size  : SmallTest
874  * @tc.type  : Function
875  * @tc.level : Level 3
876  */
HWTEST_F(DrawingNativePathTest, testPathContainsMaximal, TestSize.Level3)877 HWTEST_F(DrawingNativePathTest, testPathContainsMaximal, TestSize.Level3) {
878     // 1. Create a path object using OH_Drawing_PathCreate.
879     OH_Drawing_Path *path = OH_Drawing_PathCreate();
880     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
881     OH_Drawing_PathMoveTo(path, 0, 0);
882     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
883     OH_Drawing_PathLineTo(path, 100, 0);
884     // 4. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
885     OH_Drawing_PathLineTo(path, 100, 100);
886     // 5. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
887     OH_Drawing_PathLineTo(path, 0, 100);
888     // 6. Close the path using OH_Drawing_PathClose.
889     OH_Drawing_PathClose(path);
890     // 7. Check if the specified coordinates are contained in the path using OH_Drawing_PathContains with the second
891     // parameter as FLT_MAX + 1.
892     OH_Drawing_PathContains(path, FLT_MAX + 1, 50);
893     // 8. Check if the specified coordinates are contained in the path using OH_Drawing_PathContains with the third
894     // parameter as FLT_MAX + 1.
895     OH_Drawing_PathContains(path, 50, FLT_MAX + 1);
896     // 9. Free the memory.
897     OH_Drawing_PathDestroy(path);
898 }
899 
900 /*
901  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2900
902  * @tc.name: testPathTransformNormal
903  * @tc.desc: Test for transforming a path using normal parameters.
904  * @tc.size  : SmallTest
905  * @tc.type  : Function
906  * @tc.level : Level 0
907  */
HWTEST_F(DrawingNativePathTest, testPathTransformNormal, TestSize.Level0)908 HWTEST_F(DrawingNativePathTest, testPathTransformNormal, TestSize.Level0) {
909     // 1. Create a path object using OH_Drawing_PathCreate.
910     OH_Drawing_Path *path = OH_Drawing_PathCreate();
911     // 2. Create a matrix object using OH_Drawing_MatrixCreate.
912     OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
913     OH_Drawing_MatrixSetMatrix(matrix, 1, 0, 0, 0, -1, 0, 0, 0, 1);
914     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
915     OH_Drawing_PathMoveTo(path, 0, 0);
916     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
917     OH_Drawing_PathLineTo(path, 100, 100);
918     // 5. Transform the path using OH_Drawing_PathTransform.
919     OH_Drawing_PathTransform(path, matrix);
920     // 6. Free the memory.
921     OH_Drawing_PathDestroy(path);
922     OH_Drawing_MatrixDestroy(matrix);
923 }
924 
925 /*
926  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_2901
927  * @tc.name: testPathTransformNull
928  * @tc.desc: Test for transforming a path using NULL or invalid parameters.
929  * @tc.size  : SmallTest
930  * @tc.type  : Function
931  * @tc.level : Level 3
932  */
HWTEST_F(DrawingNativePathTest, testPathTransformNull, TestSize.Level3)933 HWTEST_F(DrawingNativePathTest, testPathTransformNull, TestSize.Level3) {
934     // 1. Create a path object using OH_Drawing_PathCreate.
935     OH_Drawing_Path *path = OH_Drawing_PathCreate();
936     // 2. Create a matrix object using OH_Drawing_MatrixCreate.
937     OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
938     OH_Drawing_MatrixSetMatrix(matrix, 1, 0, 0, 0, -1, 0, 0, 0, 1);
939     // 3. Call OH_Drawing_PathTransform with a nullptr as the first parameter, expecting
940     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
941     OH_Drawing_PathTransform(nullptr, matrix);
942     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
943     // 4. Call OH_Drawing_PathTransform with a nullptr as the second parameter, expecting
944     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
945     OH_Drawing_PathTransform(path, nullptr);
946     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
947     // 5. Free the memory.
948     OH_Drawing_PathDestroy(path);
949     OH_Drawing_MatrixDestroy(matrix);
950 }
951 
952 /*
953  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3000
954  * @tc.name: testPathTransformWithPerspectiveClipNormal
955  * @tc.desc: Test for transforming a path with perspective clip using normal parameters.
956  * @tc.size  : SmallTest
957  * @tc.type  : Function
958  * @tc.level : Level 0
959  */
HWTEST_F(DrawingNativePathTest, testPathTransformWithPerspectiveClipNormal, TestSize.Level0)960 HWTEST_F(DrawingNativePathTest, testPathTransformWithPerspectiveClipNormal, TestSize.Level0) {
961     // 1. Create a path object src using OH_Drawing_PathCreate.
962     OH_Drawing_Path *src = OH_Drawing_PathCreate();
963     // 2. Create a matrix object using OH_Drawing_MatrixCreate.
964     OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
965     OH_Drawing_MatrixSetMatrix(matrix, 1, 0, 0, 0, -1, 0, 0, 0, 1);
966     // 3. Create a path object dst using OH_Drawing_PathCreate.
967     OH_Drawing_Path *dst = OH_Drawing_PathCreate();
968     // 4. Set the starting point of the path using OH_Drawing_PathMoveTo.
969     OH_Drawing_PathMoveTo(src, 0, 0);
970     // 5. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
971     OH_Drawing_PathLineTo(src, 100, 100);
972     // 6. Transform the path using OH_Drawing_PathTransformWithPerspectiveClip, with the fourth parameter set to true.
973     OH_Drawing_PathTransformWithPerspectiveClip(src, matrix, dst, true);
974     // 7. Free the memory.
975     OH_Drawing_PathDestroy(src);
976     OH_Drawing_PathDestroy(dst);
977     OH_Drawing_MatrixDestroy(matrix);
978 }
979 
980 /*
981  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3001
982  * @tc.name: testPathTransformWithPerspectiveClipNormal2
983  * @tc.desc: Test for transforming a path with perspective clip using normal parameters with false perspective clip.
984  * @tc.size  : SmallTest
985  * @tc.type  : Function
986  * @tc.level : Level 0
987  */
HWTEST_F(DrawingNativePathTest, testPathTransformWithPerspectiveClipNormal2, TestSize.Level0)988 HWTEST_F(DrawingNativePathTest, testPathTransformWithPerspectiveClipNormal2, TestSize.Level0) {
989     // 1. Create a path object src using OH_Drawing_PathCreate.
990     OH_Drawing_Path *src = OH_Drawing_PathCreate();
991     // 2. Create a matrix object using OH_Drawing_MatrixCreate.
992     OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
993     // 3. Create a path object dst using OH_Drawing_PathCreate.
994     OH_Drawing_Path *dst = OH_Drawing_PathCreate();
995     // 4. Set the starting point of the path using OH_Drawing_PathMoveTo.
996     OH_Drawing_PathMoveTo(src, 0, 0);
997     // 5. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
998     OH_Drawing_PathLineTo(src, 100, 100);
999     // 6. Transform the path using OH_Drawing_PathTransformWithPerspectiveClip, with the fourth parameter set to false.
1000     OH_Drawing_PathTransformWithPerspectiveClip(src, matrix, dst, false);
1001     // 7. Free the memory.
1002     OH_Drawing_PathDestroy(src);
1003     OH_Drawing_PathDestroy(dst);
1004     OH_Drawing_MatrixDestroy(matrix);
1005 }
1006 
1007 /*
1008  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3002
1009  * @tc.name: testPathTransformWithPerspectiveClipNull
1010  * @tc.desc: Test for transforming a path with perspective clip using NULL or invalid parameters.
1011  * @tc.size  : SmallTest
1012  * @tc.type  : Function
1013  * @tc.level : Level 3
1014  */
HWTEST_F(DrawingNativePathTest, testPathTransformWithPerspectiveClipNull, TestSize.Level3)1015 HWTEST_F(DrawingNativePathTest, testPathTransformWithPerspectiveClipNull, TestSize.Level3) {
1016     // 1. Create a path object src using OH_Drawing_PathCreate.
1017     OH_Drawing_Path *src = OH_Drawing_PathCreate();
1018     // 2. Create a matrix object using OH_Drawing_MatrixCreate.
1019     OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
1020     // 3. Create a path object dst using OH_Drawing_PathCreate.
1021     OH_Drawing_Path *dst = OH_Drawing_PathCreate();
1022     // 4. Call OH_Drawing_PathTransformWithPerspectiveClip with a nullptr as the first parameter, expecting
1023     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
1024     OH_Drawing_PathTransformWithPerspectiveClip(nullptr, matrix, dst, true);
1025     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
1026     // 5. Call OH_Drawing_PathTransformWithPerspectiveClip with a nullptr as the second parameter, expecting
1027     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
1028     OH_Drawing_PathTransformWithPerspectiveClip(src, nullptr, dst, true);
1029     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
1030     // 6. Call OH_Drawing_PathTransformWithPerspectiveClip with a nullptr as the third parameter, no crash.
1031     OH_Drawing_PathTransformWithPerspectiveClip(src, matrix, nullptr, true);
1032     // 7. Free the memory.
1033     OH_Drawing_PathDestroy(src);
1034     OH_Drawing_PathDestroy(dst);
1035     OH_Drawing_MatrixDestroy(matrix);
1036 }
1037 
1038 /*
1039  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3100
1040  * @tc.name: testPathSetFillTypeNormal
1041  * @tc.desc: Test for setting fill type of a path using normal parameters.
1042  * @tc.size  : SmallTest
1043  * @tc.type  : Function
1044  * @tc.level : Level 0
1045  */
HWTEST_F(DrawingNativePathTest, testPathSetFillTypeNormal, TestSize.Level0)1046 HWTEST_F(DrawingNativePathTest, testPathSetFillTypeNormal, TestSize.Level0) {
1047     // 1. Create a path object using OH_Drawing_PathCreate.
1048     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1049     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
1050     OH_Drawing_PathMoveTo(path, 0, 0);
1051     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1052     OH_Drawing_PathLineTo(path, 100, 100);
1053     // 4. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
1054     OH_Drawing_PathLineTo(path, 100, 0);
1055     // 5. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
1056     OH_Drawing_PathLineTo(path, 0, 0);
1057     // 6. Close the path using OH_Drawing_PathClose.
1058     OH_Drawing_PathClose(path);
1059     // 7. Set the fill type of the path using OH_Drawing_PathSetFillType, with the second parameter iterating through
1060     // the enumeration.
1061     OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_WINDING);
1062     OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_EVEN_ODD);
1063     OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_INVERSE_WINDING);
1064     OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_INVERSE_EVEN_ODD);
1065     // 8. Free the memory.
1066     OH_Drawing_PathDestroy(path);
1067 }
1068 
1069 /*
1070  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3101
1071  * @tc.name: testPathSetFillTypeNull
1072  * @tc.desc: Test for setting fill type of a path using NULL or invalid parameters.
1073  * @tc.size  : SmallTest
1074  * @tc.type  : Function
1075  * @tc.level : Level 3
1076  */
HWTEST_F(DrawingNativePathTest, testPathSetFillTypeNull, TestSize.Level3)1077 HWTEST_F(DrawingNativePathTest, testPathSetFillTypeNull, TestSize.Level3) {
1078     // 1. Create a path object using OH_Drawing_PathCreate.
1079     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1080     // 2. Call OH_Drawing_PathSetFillType with a nullptr as the first parameter, expecting
1081     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
1082     OH_Drawing_PathSetFillType(nullptr, OH_Drawing_PathFillType::PATH_FILL_TYPE_WINDING);
1083     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
1084     // 3. Call OH_Drawing_PathSetFillType with a value that is not within the enumeration range as the second parameter,
1085     // expecting OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE error code.
1086     OH_Drawing_PathSetFillType(path, static_cast<OH_Drawing_PathFillType>(-1));
1087     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE);
1088     // 4. Free the memory.
1089     OH_Drawing_PathDestroy(path);
1090 }
1091 
1092 /*
1093  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3102
1094  * @tc.name: testPathSetFillTypeMultipleCalls
1095  * @tc.desc: Test for setting fill type of a path with multiple calls.
1096  * @tc.size  : SmallTest
1097  * @tc.type  : Function
1098  * @tc.level : Level 3
1099  */
HWTEST_F(DrawingNativePathTest, testPathSetFillTypeMultipleCalls, TestSize.Level3)1100 HWTEST_F(DrawingNativePathTest, testPathSetFillTypeMultipleCalls, TestSize.Level3) {
1101     // 1. Create a path object using OH_Drawing_PathCreate.
1102     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1103     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
1104     OH_Drawing_PathMoveTo(path, 0, 0);
1105     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1106     OH_Drawing_PathLineTo(path, 100, 100);
1107     // 4. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
1108     OH_Drawing_PathLineTo(path, 100, 0);
1109     // 5. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
1110     OH_Drawing_PathLineTo(path, 0, 0);
1111     // 6. Close the path using OH_Drawing_PathClose.
1112     OH_Drawing_PathClose(path);
1113     // 7. Call OH_Drawing_PathSetFillType in a loop 10 times, iterating through the enumeration to set different fill
1114     // rules for the path.
1115     for (int i = 0; i < 10; i++) {
1116         OH_Drawing_PathSetFillType(path, static_cast<OH_Drawing_PathFillType>(i));
1117     }
1118     // 8. Free the memory.
1119     OH_Drawing_PathDestroy(path);
1120 }
1121 
1122 /*
1123  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3200
1124  * @tc.name: testPathGetLengthNormal
1125  * @tc.desc: Test for getting the length of a path using normal parameters with detailed length.
1126  * @tc.size  : SmallTest
1127  * @tc.type  : Function
1128  * @tc.level : Level 0
1129  */
HWTEST_F(DrawingNativePathTest, testPathGetLengthNormal, TestSize.Level0)1130 HWTEST_F(DrawingNativePathTest, testPathGetLengthNormal, TestSize.Level0) {
1131     // 1. Create a path object using OH_Drawing_PathCreate.
1132     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1133     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
1134     OH_Drawing_PathMoveTo(path, 0, 0);
1135     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1136     OH_Drawing_PathLineTo(path, 100, 100);
1137     // 4. Get the length of the current path by calling OH_Drawing_PathGetLength, with the second parameter set to true.
1138     float length = OH_Drawing_PathGetLength(path, true);
1139     EXPECT_NE(length, 0.0f);
1140     // 5. Free the memory.
1141     OH_Drawing_PathDestroy(path);
1142 }
1143 
1144 /*
1145  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3201
1146  * @tc.name: testPathGetLengthNormal2
1147  * @tc.desc: Test for getting the length of a path using normal parameters without detailed length.
1148  * @tc.size  : SmallTest
1149  * @tc.type  : Function
1150  * @tc.level : Level 0
1151  */
HWTEST_F(DrawingNativePathTest, testPathGetLengthNormal2, TestSize.Level0)1152 HWTEST_F(DrawingNativePathTest, testPathGetLengthNormal2, TestSize.Level0) {
1153     // 1. Create a path object using OH_Drawing_PathCreate.
1154     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1155     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
1156     OH_Drawing_PathMoveTo(path, 0, 0);
1157     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1158     OH_Drawing_PathLineTo(path, 100, 100);
1159     // 4. Get the length of the current path by calling OH_Drawing_PathGetLength, with the second parameter set to
1160     // false.
1161     float length = OH_Drawing_PathGetLength(path, false);
1162     EXPECT_NE(length, 0.0f);
1163     // 5. Free the memory.
1164     OH_Drawing_PathDestroy(path);
1165 }
1166 
1167 /*
1168  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3202
1169  * @tc.name: testPathGetLengthNull
1170  * @tc.desc: Test for getting the length of a path using NULL or invalid parameters.
1171  * @tc.size  : SmallTest
1172  * @tc.type  : Function
1173  * @tc.level : Level 3
1174  */
HWTEST_F(DrawingNativePathTest, testPathGetLengthNull, TestSize.Level3)1175 HWTEST_F(DrawingNativePathTest, testPathGetLengthNull, TestSize.Level3) {
1176     // 1. Create a path object using OH_Drawing_PathCreate.
1177     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1178     // 2. Call OH_Drawing_PathGetLength with a nullptr as the first parameter, expecting
1179     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
1180     OH_Drawing_PathGetLength(nullptr, true);
1181     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
1182     // 3. Free the memory.
1183     OH_Drawing_PathDestroy(path);
1184 }
1185 
1186 /*
1187  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3300
1188  * @tc.name: testPathGetBoundsNormal
1189  * @tc.desc: Test for getting the bounds of a path using normal parameters.
1190  * @tc.size  : SmallTest
1191  * @tc.type  : Function
1192  * @tc.level : Level 0
1193  */
HWTEST_F(DrawingNativePathTest, testPathGetBoundsNormal, TestSize.Level0)1194 HWTEST_F(DrawingNativePathTest, testPathGetBoundsNormal, TestSize.Level0) {
1195     // 1. Create a path object using OH_Drawing_PathCreate.
1196     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1197     // 2. Create a rectangle object using OH_Drawing_RectCreate.
1198     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
1199     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
1200     OH_Drawing_PathMoveTo(path, 0, 0);
1201     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1202     OH_Drawing_PathLineTo(path, 100, 100);
1203     // 5. Get the minimum bounding box that contains the path by calling OH_Drawing_PathGetBounds.
1204     OH_Drawing_PathGetBounds(path, rect);
1205     // 6. Free the memory.
1206     OH_Drawing_PathDestroy(path);
1207     OH_Drawing_RectDestroy(rect);
1208 }
1209 
1210 /*
1211  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3301
1212  * @tc.name: testPathGetBoundsNull
1213  * @tc.desc: Test for getting the bounds of a path using NULL or invalid parameters.
1214  * @tc.size  : SmallTest
1215  * @tc.type  : Function
1216  * @tc.level : Level 3
1217  */
HWTEST_F(DrawingNativePathTest, testPathGetBoundsNull, TestSize.Level3)1218 HWTEST_F(DrawingNativePathTest, testPathGetBoundsNull, TestSize.Level3) {
1219     // 1. Create a path object using OH_Drawing_PathCreate.
1220     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1221     // 2. Create a rectangle object using OH_Drawing_RectCreate.
1222     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
1223     // 3. Call OH_Drawing_PathGetBounds with a nullptr as the first parameter, expecting
1224     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
1225     OH_Drawing_PathGetBounds(nullptr, rect);
1226     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
1227     // 4. Call OH_Drawing_PathGetBounds with a nullptr as the second parameter, expecting
1228     // OH_DRAWING_ERROR_INVALID_PARAMETER error code.
1229     OH_Drawing_PathGetBounds(path, nullptr);
1230     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
1231     // 5. Free the memory.
1232     OH_Drawing_PathDestroy(path);
1233     OH_Drawing_RectDestroy(rect);
1234 }
1235 
1236 /*
1237  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3400
1238  * @tc.name: testPathCloseNormal
1239  * @tc.desc: test for testPathCloseNormal.
1240  * @tc.size  : SmallTest
1241  * @tc.type  : Function
1242  * @tc.level : Level 0
1243  */
HWTEST_F(DrawingNativePathTest, testPathCloseNormal, TestSize.Level0)1244 HWTEST_F(DrawingNativePathTest, testPathCloseNormal, TestSize.Level0) {
1245     // 1. Create a path object using OH_Drawing_PathCreate.
1246     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1247     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
1248     OH_Drawing_PathMoveTo(path, 0, 0);
1249     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1250     OH_Drawing_PathLineTo(path, 100, 100);
1251     // 4. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo.
1252     OH_Drawing_PathLineTo(path, 100, 0);
1253     // 5. Close the path by adding a line segment from the last point of the path to the starting point.
1254     OH_Drawing_PathClose(path);
1255     // 6. Free the memory.
1256     OH_Drawing_PathDestroy(path);
1257 }
1258 
1259 /*
1260  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3401
1261  * @tc.name: testPathCloseNull
1262  * @tc.desc: Test for closing a path using NULL or invalid parameters.
1263  * @tc.size  : SmallTest
1264  * @tc.type  : Function
1265  * @tc.level : Level 3
1266  */
HWTEST_F(DrawingNativePathTest, testPathCloseNull, TestSize.Level3)1267 HWTEST_F(DrawingNativePathTest, testPathCloseNull, TestSize.Level3) {
1268     // 1. Create a path object using OH_Drawing_PathCreate.
1269     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1270     // 2. Call OH_Drawing_PathClose with nullptr as the parameter, expecting OH_DRAWING_ERROR_INVALID_PARAMETER error
1271     // code.
1272     OH_Drawing_PathClose(nullptr);
1273     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
1274     // 3. Free the memory.
1275     OH_Drawing_PathDestroy(path);
1276 }
1277 
1278 /*
1279  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3500
1280  * @tc.name: testPathOffsetNormal
1281  * @tc.desc: Test for offsetting a path using normal parameters.
1282  * @tc.size  : SmallTest
1283  * @tc.type  : Function
1284  * @tc.level : Level 0
1285  */
HWTEST_F(DrawingNativePathTest, testPathOffsetNormal, TestSize.Level0)1286 HWTEST_F(DrawingNativePathTest, testPathOffsetNormal, TestSize.Level0) {
1287     // 1. Create a path object using OH_Drawing_PathCreate.
1288     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1289     // 2. Create a path object using OH_Drawing_PathCreate.
1290     OH_Drawing_Path *dst = OH_Drawing_PathCreate();
1291     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
1292     OH_Drawing_PathMoveTo(path, 0, 0);
1293     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1294     OH_Drawing_PathLineTo(path, 100, 100);
1295     // 5. Offset all points in the path by a certain distance along the x and y axes, and store the result in the
1296     // destination path object using OH_Drawing_PathOffset.
1297     OH_Drawing_PathOffset(path, dst, 10, 10);
1298     // 6. Free the memory.
1299     OH_Drawing_PathDestroy(path);
1300 }
1301 
1302 /*
1303  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3501
1304  * @tc.name: testPathOffsetNull
1305  * @tc.desc: Test for offsetting a path using NULL or invalid parameters.
1306  * @tc.size  : SmallTest
1307  * @tc.type  : Function
1308  * @tc.level : Level 3
1309  */
HWTEST_F(DrawingNativePathTest, testPathOffsetNull, TestSize.Level3)1310 HWTEST_F(DrawingNativePathTest, testPathOffsetNull, TestSize.Level3) {
1311     // 1. Create a path object using OH_Drawing_PathCreate.
1312     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1313     // 2. Create a path object using OH_Drawing_PathCreate.
1314     OH_Drawing_Path *dst = OH_Drawing_PathCreate();
1315     // 3. Call OH_Drawing_PathOffset with a nullptr as the first parameter, expecting OH_DRAWING_ERROR_INVALID_PARAMETER
1316     // error code.
1317     OH_Drawing_PathOffset(nullptr, dst, 10, 10);
1318     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
1319     // 4. Call OH_Drawing_PathOffset with a nullptr as the second parameter, expecting failure without crashing.
1320     OH_Drawing_PathOffset(path, nullptr, 10, 10);
1321     // 5. Call OH_Drawing_PathOffset with 0.00 as the third parameter, expecting failure without crashing.
1322     OH_Drawing_PathOffset(path, dst, 0.00, 10);
1323     // 6. Call OH_Drawing_PathOffset with 0.00 as the fourth parameter, expecting failure without crashing.
1324     OH_Drawing_PathOffset(path, dst, 10, 0.00);
1325     // 7. Free the memory.
1326     OH_Drawing_PathDestroy(path);
1327     OH_Drawing_PathDestroy(dst);
1328 }
1329 
1330 /*
1331  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3502
1332  * @tc.name: testPathOffsetAbnormal
1333  * @tc.desc: Test for offsetting a path with abnormal parameters (non-float values).
1334  * @tc.size  : SmallTest
1335  * @tc.type  : Function
1336  * @tc.level : Level 3
1337  */
HWTEST_F(DrawingNativePathTest, testPathOffsetAbnormal, TestSize.Level3)1338 HWTEST_F(DrawingNativePathTest, testPathOffsetAbnormal, TestSize.Level3) {
1339     // 1. Create a path object using OH_Drawing_PathCreate.
1340     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1341     // 2. Create a path object using OH_Drawing_PathCreate.
1342     OH_Drawing_Path *dst = OH_Drawing_PathCreate();
1343     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
1344     OH_Drawing_PathMoveTo(path, 0, 0);
1345     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1346     OH_Drawing_PathLineTo(path, 100, 100);
1347     // 5. Call OH_Drawing_PathOffset with an integer as the third parameter.
1348     OH_Drawing_PathOffset(path, dst, 10, 10.0f);
1349     // 6. Call OH_Drawing_PathOffset with an integer as the fourth parameter.
1350     OH_Drawing_PathOffset(path, dst, 10.0f, 10);
1351     // 7. Free the memory.
1352     OH_Drawing_PathDestroy(path);
1353     OH_Drawing_PathDestroy(dst);
1354 }
1355 
1356 /*
1357  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3503
1358  * @tc.name: testPathOffsetMaximal
1359  * @tc.desc: Test for offsetting a path with maximal values.
1360  * @tc.size  : SmallTest
1361  * @tc.type  : Function
1362  * @tc.level : Level 3
1363  */
HWTEST_F(DrawingNativePathTest, testPathOffsetMaximal, TestSize.Level3)1364 HWTEST_F(DrawingNativePathTest, testPathOffsetMaximal, TestSize.Level3) {
1365     // 1. Create a path object using OH_Drawing_PathCreate.
1366     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1367     // 2. Create a path object using OH_Drawing_PathCreate.
1368     OH_Drawing_Path *dst = OH_Drawing_PathCreate();
1369     // 3. Set the starting point of the path using OH_Drawing_PathMoveTo.
1370     OH_Drawing_PathMoveTo(path, 0, 0);
1371     // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1372     OH_Drawing_PathLineTo(path, 100, 100);
1373     // 5. Call OH_Drawing_PathOffset with the third parameter set to the maximum value FLT_MAX + 1.
1374     OH_Drawing_PathOffset(path, dst, FLT_MAX + 1, 10.0f);
1375     // 6. Call OH_Drawing_PathOffset with the fourth parameter set to the maximum value FLT_MAX + 1.
1376     OH_Drawing_PathOffset(path, dst, 10.0f, FLT_MAX + 1);
1377     // 7. Free the memory.
1378     OH_Drawing_PathDestroy(path);
1379     OH_Drawing_PathDestroy(dst);
1380 }
1381 
1382 /*
1383  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3600
1384  * @tc.name: testPathResetNormal
1385  * @tc.desc: Test for resetting a path using normal parameters.
1386  * @tc.size  : SmallTest
1387  * @tc.type  : Function
1388  * @tc.level : Level 0
1389  */
HWTEST_F(DrawingNativePathTest, testPathResetNormal, TestSize.Level0)1390 HWTEST_F(DrawingNativePathTest, testPathResetNormal, TestSize.Level0) {
1391     // 1. Create a path object using OH_Drawing_PathCreate.
1392     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1393     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
1394     OH_Drawing_PathMoveTo(path, 0, 0);
1395     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1396     OH_Drawing_PathLineTo(path, 100, 100);
1397     // 4. Reset the custom path data using OH_Drawing_PathReset.
1398     OH_Drawing_PathReset(path);
1399     // 5. Free the memory.
1400     OH_Drawing_PathDestroy(path);
1401 }
1402 
1403 /*
1404  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3601
1405  * @tc.name: testPathResetNull
1406  * @tc.desc: Test for resetting a path using NULL or invalid parameters.
1407  * @tc.size  : SmallTest
1408  * @tc.type  : Function
1409  * @tc.level : Level 3
1410  */
HWTEST_F(DrawingNativePathTest, testPathResetNull, TestSize.Level3)1411 HWTEST_F(DrawingNativePathTest, testPathResetNull, TestSize.Level3) {
1412     // 1. Create a path object using OH_Drawing_PathCreate.
1413     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1414     // 2. Call OH_Drawing_PathReset with nullptr as the parameter, expecting OH_DRAWING_ERROR_INVALID_PARAMETER error
1415     // code.
1416     OH_Drawing_PathReset(nullptr);
1417     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
1418     // 3. Free the memory.
1419     OH_Drawing_PathDestroy(path);
1420 }
1421 
1422 /*
1423  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3602
1424  * @tc.name: testPathResetMultipleCalls
1425  * @tc.desc: Test for resetting a path with multiple calls.
1426  * @tc.size  : SmallTest
1427  * @tc.type  : Function
1428  * @tc.level : Level 3
1429  */
HWTEST_F(DrawingNativePathTest, testPathResetMultipleCalls, TestSize.Level3)1430 HWTEST_F(DrawingNativePathTest, testPathResetMultipleCalls, TestSize.Level3) {
1431     // 1. Create a path object using OH_Drawing_PathCreate.
1432     OH_Drawing_Path *path = OH_Drawing_PathCreate();
1433     // 2. Set the starting point of the path using OH_Drawing_PathMoveTo.
1434     OH_Drawing_PathMoveTo(path, 0, 0);
1435     // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo.
1436     OH_Drawing_PathLineTo(path, 100, 100);
1437     // 4. Reset the custom path data using OH_Drawing_PathReset.
1438     OH_Drawing_PathReset(path);
1439     // 5. Loop through steps 2 to 4 for 10 times to verify success.
1440     for (int i = 0; i < 10; i++) {
1441         OH_Drawing_PathMoveTo(path, 0, 0);
1442         OH_Drawing_PathLineTo(path, 100, 100);
1443         OH_Drawing_PathReset(path);
1444     }
1445     // 6. Free the memory.
1446     OH_Drawing_PathDestroy(path);
1447 }
1448 
1449 } // namespace Drawing
1450 } // namespace Rosen
1451 } // namespace OHOS