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_3700
41 * @tc.name: testPathIsClosedNormal
42 * @tc.desc: Test for checking if a path is closed using normal parameters.
43 * @tc.size : SmallTest
44 * @tc.type : Function
45 * @tc.level : Level 0
46 */
HWTEST_F(DrawingNativePathTest, testPathIsClosedNormal, TestSize.Level0)47 HWTEST_F(DrawingNativePathTest, testPathIsClosedNormal, TestSize.Level0) {
48 // 1. Create a path object using OH_Drawing_PathCreate
49 OH_Drawing_Path *path = OH_Drawing_PathCreate();
50 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo
51 OH_Drawing_PathMoveTo(path, 0, 0);
52 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
53 OH_Drawing_PathLineTo(path, 100, 100);
54 // 4. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo
55 OH_Drawing_PathLineTo(path, 0, 100);
56 // 5. Add a line segment from the last point of the path to the target point using OH_Drawing_PathLineTo
57 OH_Drawing_PathLineTo(path, 0, 0);
58 // 6. Close the path using OH_Drawing_PathClose
59 OH_Drawing_PathClose(path);
60 // 7. Check if the path is closed using OH_Drawing_PathIsClosed
61 bool isClosed = OH_Drawing_PathIsClosed(path, false);
62 EXPECT_EQ(isClosed, true);
63 // 8. Free the memory
64 OH_Drawing_PathDestroy(path);
65 }
66
67 /*
68 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3701
69 * @tc.name: testPathIsClosedNormal2
70 * @tc.desc: Test for checking if a path is closed without closing it.
71 * @tc.size : SmallTest
72 * @tc.type : Function
73 * @tc.level : Level 0
74 */
HWTEST_F(DrawingNativePathTest, testPathIsClosedNormal2, TestSize.Level0)75 HWTEST_F(DrawingNativePathTest, testPathIsClosedNormal2, TestSize.Level0) {
76 // 1. Create a path object using OH_Drawing_PathCreate
77 OH_Drawing_Path *path = OH_Drawing_PathCreate();
78 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo
79 OH_Drawing_PathMoveTo(path, 0, 0);
80 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
81 OH_Drawing_PathLineTo(path, 100, 100);
82 // 4. Check if the path is closed using OH_Drawing_PathIsClosed
83 bool isClosed = OH_Drawing_PathIsClosed(path, false);
84 EXPECT_EQ(isClosed, false);
85 // 5. Free the memory
86 OH_Drawing_PathDestroy(path);
87 }
88
89 /*
90 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3702
91 * @tc.name: testPathIsClosedNull
92 * @tc.desc: Test for checking if a path is closed with NULL or invalid parameters.
93 * @tc.size : SmallTest
94 * @tc.type : Function
95 * @tc.level : Level 3
96 */
HWTEST_F(DrawingNativePathTest, testPathIsClosedNull, TestSize.Level3)97 HWTEST_F(DrawingNativePathTest, testPathIsClosedNull, TestSize.Level3) {
98 // 1. Create a path object using OH_Drawing_PathCreate
99 OH_Drawing_Path *path = OH_Drawing_PathCreate();
100 // 2. Check if the path is closed using OH_Drawing_PathIsClosed with nullptr as the parameter, should return
101 // OH_DRAWING_ERROR_INVALID_PARAMETER
102 OH_Drawing_PathIsClosed(nullptr, false);
103 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
104 // 3. Free the memory
105 OH_Drawing_PathDestroy(path);
106 }
107
108 /*
109 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3800
110 * @tc.name: testPathGetPositionTangentNormal
111 * @tc.desc: Test for getting position and tangent of a path using normal parameters with tangent flag set to true.
112 * @tc.size : SmallTest
113 * @tc.type : Function
114 * @tc.level : Level 0
115 */
HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentNormal, TestSize.Level0)116 HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentNormal, TestSize.Level0) {
117 // 1. Create a path object using OH_Drawing_PathCreate
118 OH_Drawing_Path *path = OH_Drawing_PathCreate();
119 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo
120 OH_Drawing_PathMoveTo(path, 0, 0);
121 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
122 OH_Drawing_PathLineTo(path, 100, 100);
123 // 4. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the
124 // second parameter to true.
125 OH_Drawing_Point2D position;
126 OH_Drawing_Point2D tangent;
127 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
128 // 5. Free the memory
129 OH_Drawing_PathDestroy(path);
130 }
131
132 /*
133 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3801
134 * @tc.name: testPathGetPositionTangentNormal2
135 * @tc.desc: Test for getting position and tangent of a path using normal parameters with tangent flag set to false.
136 * @tc.size : SmallTest
137 * @tc.type : Function
138 * @tc.level : Level 0
139 */
HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentNormal2, TestSize.Level0)140 HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentNormal2, TestSize.Level0) {
141 // 1. Create a path object using OH_Drawing_PathCreate
142 OH_Drawing_Path *path = OH_Drawing_PathCreate();
143 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo
144 OH_Drawing_PathMoveTo(path, 0, 0);
145 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
146 OH_Drawing_PathLineTo(path, 100, 100);
147 // 4. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the
148 // second parameter to false.
149 OH_Drawing_Point2D position;
150 OH_Drawing_Point2D tangent;
151 OH_Drawing_PathGetPositionTangent(path, false, 50, &position, &tangent);
152 // 5. Free the memory
153 OH_Drawing_PathDestroy(path);
154 }
155
156 /*
157 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3802
158 * @tc.name: testPathGetPositionTangentNull
159 * @tc.desc: Test for getting position and tangent of a path using NULL or invalid parameters.
160 * @tc.size : SmallTest
161 * @tc.type : Function
162 * @tc.level : Level 3
163 */
HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentNull, TestSize.Level3)164 HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentNull, TestSize.Level3) {
165 // 1. Create a path object using OH_Drawing_PathCreate
166 OH_Drawing_Path *path = OH_Drawing_PathCreate();
167 // 2. Call OH_Drawing_PathGetPositionTangent with the first parameter as nullptr, expect
168 // OH_DRAWING_ERROR_INVALID_PARAMETER
169 OH_Drawing_PathGetPositionTangent(nullptr, true, 50, nullptr, nullptr);
170 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
171 // 3. Call OH_Drawing_PathGetPositionTangent with the third parameter as 0.00, no crash
172 OH_Drawing_Point2D position;
173 OH_Drawing_Point2D tangent;
174 OH_Drawing_PathGetPositionTangent(path, true, 0.00, &position, &tangent);
175 // 4. Call OH_Drawing_PathGetPositionTangent with the fourth parameter as nullptr, expect
176 // OH_DRAWING_ERROR_INVALID_PARAMETER
177 OH_Drawing_PathGetPositionTangent(path, true, 50, nullptr, &tangent);
178 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
179 // 5. Call OH_Drawing_PathGetPositionTangent with the fifth parameter as nullptr, expect
180 // OH_DRAWING_ERROR_INVALID_PARAMETER
181 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, nullptr);
182 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
183 // 6. Free the memory
184 OH_Drawing_PathDestroy(path);
185 }
186
187 /*
188 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3803
189 * @tc.name: testPathGetPositionTangentAbnormal
190 * @tc.desc: Test for getting position and tangent of a path with abnormal parameters (non-float values).
191 * @tc.size : SmallTest
192 * @tc.type : Function
193 * @tc.level : Level 3
194 */
HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentAbnormal, TestSize.Level3)195 HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentAbnormal, TestSize.Level3) {
196 // 1. Create a path object using OH_Drawing_PathCreate
197 OH_Drawing_Path *path = OH_Drawing_PathCreate();
198 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo
199 OH_Drawing_PathMoveTo(path, 0, 0);
200 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
201 OH_Drawing_PathLineTo(path, 100, 100);
202 // 4. Call OH_Drawing_PathGetPositionTangent with the third parameter as an integer or character type
203 OH_Drawing_Point2D position;
204 OH_Drawing_Point2D tangent;
205 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
206 // 5. Call OH_Drawing_PathGetPositionTangent with the x coordinate of the fourth parameter as an integer or
207 // character type
208 position = {10, 10.0f};
209 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
210 // 6. Call OH_Drawing_PathGetPositionTangent with the y coordinate of the fourth parameter as an integer or
211 // character type
212 position = {10.0f, 10};
213 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
214 // 7. Call OH_Drawing_PathGetPositionTangent with the x coordinate of the fifth parameter as an integer or character
215 // type
216 tangent = {10, 10.0f};
217 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
218 // 8. Call OH_Drawing_PathGetPositionTangent with the y coordinate of the fifth parameter as an integer or character
219 // type
220 tangent = {10.0f, 10};
221 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
222 // 9. Free the memory
223 OH_Drawing_PathDestroy(path);
224 }
225
226 /*
227 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3804
228 * @tc.name: testPathGetPositionTangentMaximal
229 * @tc.desc: Test for getting position and tangent of a path with maximal values.
230 * @tc.size : SmallTest
231 * @tc.type : Function
232 * @tc.level : Level 3
233 */
HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentMaximal, TestSize.Level3)234 HWTEST_F(DrawingNativePathTest, testPathGetPositionTangentMaximal, TestSize.Level3) {
235 // 1. Create a path object using OH_Drawing_PathCreate
236 OH_Drawing_Path *path = OH_Drawing_PathCreate();
237 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo
238 OH_Drawing_PathMoveTo(path, 0, 0);
239 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
240 OH_Drawing_PathLineTo(path, 100, 100);
241 // 4. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the
242 // third parameter to a large value FLT_MAX + 1.
243 OH_Drawing_Point2D position;
244 OH_Drawing_Point2D tangent;
245 OH_Drawing_PathGetPositionTangent(path, true, FLT_MAX + 1, &position, &tangent);
246 // 5. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the x
247 // coordinate of the fourth parameter to a large value FLT_MAX + 1.
248 position = {FLT_MAX + 1, 0.0f};
249 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
250 // 6. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the y
251 // coordinate of the fourth parameter to a large value FLT_MAX + 1.
252 position = {0.0f, FLT_MAX + 1};
253 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
254 // 7. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the x
255 // coordinate of the fifth parameter to a large value FLT_MAX + 1.
256 tangent = {FLT_MAX + 1, 0.0f};
257 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
258 // 8. Get the position and tangent of a point at a specified distance from the starting point of the path. Set the y
259 // coordinate of the fifth parameter to a large value FLT_MAX + 1.
260 tangent = {0.0f, FLT_MAX + 1};
261 OH_Drawing_PathGetPositionTangent(path, true, 50, &position, &tangent);
262 // 9. Free the memory
263 OH_Drawing_PathDestroy(path);
264 }
265
266 /*
267 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3900
268 * @tc.name: testPathOpNormal
269 * @tc.desc: Test for performing path operations using normal parameters.
270 * @tc.size : SmallTest
271 * @tc.type : Function
272 * @tc.level : Level 0
273 */
HWTEST_F(DrawingNativePathTest, testPathOpNormal, TestSize.Level0)274 HWTEST_F(DrawingNativePathTest, testPathOpNormal, TestSize.Level0) {
275 // 1. Create a path object using OH_Drawing_PathCreate
276 OH_Drawing_Path *path = OH_Drawing_PathCreate();
277 // 2. Set the starting point of the path using OH_Drawing_PathMoveTo
278 OH_Drawing_PathMoveTo(path, 0, 0);
279 // 3. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
280 OH_Drawing_PathLineTo(path, 100, 100);
281 // 4. Create a path object using OH_Drawing_PathCreate
282 OH_Drawing_Path *src = OH_Drawing_PathCreate();
283 // 5. Set the starting point of the path using OH_Drawing_PathMoveTo
284 OH_Drawing_PathMoveTo(src, 0, 0);
285 // 6. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
286 OH_Drawing_PathLineTo(src, 100, 100);
287 // 7. Perform a path operation on the two paths according to the specified path operation mode. The third parameter
288 // enumerates the possible path operation modes.
289 OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_INTERSECT);
290 OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_DIFFERENCE);
291 OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_UNION);
292 OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_XOR);
293 OH_Drawing_PathOp(path, src, OH_Drawing_PathOpMode::PATH_OP_MODE_REVERSE_DIFFERENCE);
294 // 8. Free the memory
295 OH_Drawing_PathDestroy(path);
296 }
297
298 /*
299 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_3901
300 * @tc.name: testPathOpNull
301 * @tc.desc: Test for performing path operations with NULL or invalid parameters.
302 * @tc.size : SmallTest
303 * @tc.type : Function
304 * @tc.level : Level 3
305 */
HWTEST_F(DrawingNativePathTest, testPathOpNull, TestSize.Level3)306 HWTEST_F(DrawingNativePathTest, testPathOpNull, TestSize.Level3) {
307 // 1. Create a path object using OH_Drawing_PathCreate
308 OH_Drawing_Path *path = OH_Drawing_PathCreate();
309 // 2. Create a path object using OH_Drawing_PathCreate
310 OH_Drawing_Path *src = OH_Drawing_PathCreate();
311 // 3. Call OH_Drawing_PathOp with the first parameter as nullptr, expect OH_DRAWING_ERROR_INVALID_PARAMETER
312 OH_Drawing_PathOp(nullptr, src, OH_Drawing_PathOpMode::PATH_OP_MODE_INTERSECT);
313 // 4. Call OH_Drawing_PathOp with the second parameter as nullptr, expect OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE
314 OH_Drawing_PathOp(path, nullptr, OH_Drawing_PathOpMode::PATH_OP_MODE_INTERSECT);
315 // 5. Free the memory
316 OH_Drawing_PathDestroy(path);
317 }
318
319 /*
320 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4000
321 * @tc.name: testPathGetMatrixNormal
322 * @tc.desc: Test for getting transformation matrix of a path using normal parameters with matrix flag set to true.
323 * @tc.size : SmallTest
324 * @tc.type : Function
325 * @tc.level : Level 0
326 */
HWTEST_F(DrawingNativePathTest, testPathGetMatrixNormal, TestSize.Level0)327 HWTEST_F(DrawingNativePathTest, testPathGetMatrixNormal, TestSize.Level0) {
328 // 1. Create a path object using OH_Drawing_PathCreate
329 OH_Drawing_Path *path = OH_Drawing_PathCreate();
330 // 2. Create a matrix object using OH_Drawing_MatrixCreate
331 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
332 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1);
333 // 3. Set the starting point of the path using OH_Drawing_PathMoveTo
334 OH_Drawing_PathMoveTo(path, 0, 0);
335 // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
336 OH_Drawing_PathLineTo(path, 100, 100);
337 // 5. Get the transformation matrix of a point at a specified distance from the starting point of the path. Set the
338 // second parameter to true. Enumerate the possible values of the fifth parameter to call the interface.
339 OH_Drawing_PathMeasureMatrixFlags flags[] = {
340 GET_POSITION_MATRIX,
341 GET_TANGENT_MATRIX,
342 GET_POSITION_AND_TANGENT_MATRIX,
343 };
344 for (int i = 0; i < 3; i++) {
345 OH_Drawing_PathGetMatrix(path, true, 50, matrix, flags[i]);
346 }
347 // 6. Free the memory
348 OH_Drawing_PathDestroy(path);
349 OH_Drawing_MatrixDestroy(matrix);
350 }
351
352 /*
353 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4001
354 * @tc.name: testPathGetMatrixNormal2
355 * @tc.desc: Test for getting transformation matrix of a path using normal parameters with matrix flag set to false.
356 * @tc.size : SmallTest
357 * @tc.type : Function
358 * @tc.level : Level 0
359 */
HWTEST_F(DrawingNativePathTest, testPathGetMatrixNormal2, TestSize.Level0)360 HWTEST_F(DrawingNativePathTest, testPathGetMatrixNormal2, TestSize.Level0) {
361 // 1. Create a path object using OH_Drawing_PathCreate
362 OH_Drawing_Path *path = OH_Drawing_PathCreate();
363 // 2. Create a matrix object using OH_Drawing_MatrixCreate
364 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
365 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1);
366 // 3. Set the starting point of the path using OH_Drawing_PathMoveTo
367 OH_Drawing_PathMoveTo(path, 0, 0);
368 // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
369 OH_Drawing_PathLineTo(path, 100, 100);
370 // 5. Get the transformation matrix of a point at a specified distance from the starting point of the path. Set the
371 // second parameter to false. Enumerate the possible values of the fifth parameter to call the interface.
372 OH_Drawing_PathMeasureMatrixFlags flags[] = {
373 GET_POSITION_MATRIX,
374 GET_TANGENT_MATRIX,
375 GET_POSITION_AND_TANGENT_MATRIX,
376 };
377 for (int i = 0; i < 3; i++) {
378 OH_Drawing_PathGetMatrix(path, false, 50, matrix, flags[i]);
379 }
380 // 6. Free the memory
381 OH_Drawing_PathDestroy(path);
382 OH_Drawing_MatrixDestroy(matrix);
383 }
384
385 /*
386 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4002
387 * @tc.name: testPathGetMatrixNull
388 * @tc.desc: Test for getting transformation matrix of a path using NULL or invalid parameters.
389 * @tc.size : SmallTest
390 * @tc.type : Function
391 * @tc.level : Level 3
392 */
HWTEST_F(DrawingNativePathTest, testPathGetMatrixNull, TestSize.Level3)393 HWTEST_F(DrawingNativePathTest, testPathGetMatrixNull, TestSize.Level3) {
394 // 1. Create a path object using OH_Drawing_PathCreate
395 OH_Drawing_Path *path = OH_Drawing_PathCreate();
396 // 2. Create a matrix object using OH_Drawing_MatrixCreate
397 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
398 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1);
399 // 3. Call OH_Drawing_PathGetMatrix with the first parameter as nullptr, expect OH_DRAWING_ERROR_INVALID_PARAMETER
400 OH_Drawing_PathGetMatrix(nullptr, true, 50, matrix, GET_POSITION_MATRIX);
401 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
402 // 4. Call OH_Drawing_PathGetMatrix with the third parameter as 0.00, the call should fail without crashing
403 OH_Drawing_PathGetMatrix(path, true, 0.00, matrix, GET_POSITION_MATRIX);
404 // 5. Call OH_Drawing_PathGetMatrix with the fourth parameter as nullptr, expect OH_DRAWING_ERROR_INVALID_PARAMETER
405 OH_Drawing_PathGetMatrix(path, true, 50, nullptr, GET_POSITION_MATRIX);
406 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
407 // 6. Free the memory
408 OH_Drawing_PathDestroy(path);
409 }
410
411 /*
412 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4003
413 * @tc.name: testPathGetMatrixAbnormal
414 * @tc.desc: Test for getting transformation matrix of a path with abnormal parameters (non-float values).
415 * @tc.size : SmallTest
416 * @tc.type : Function
417 * @tc.level : Level 3
418 */
HWTEST_F(DrawingNativePathTest, testPathGetMatrixAbnormal, TestSize.Level3)419 HWTEST_F(DrawingNativePathTest, testPathGetMatrixAbnormal, TestSize.Level3) {
420 // 1. Create a path object using OH_Drawing_PathCreate
421 OH_Drawing_Path *path = OH_Drawing_PathCreate();
422 // 2. Create a matrix object using OH_Drawing_MatrixCreate
423 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
424 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1);
425 // 3. Set the starting point of the path using OH_Drawing_PathMoveTo
426 OH_Drawing_PathMoveTo(path, 0, 0);
427 // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
428 OH_Drawing_PathLineTo(path, 100, 100);
429 // 5. Get the transformation matrix of a point at a specified distance from the starting point of the path. Set the
430 // third parameter to an integer value.
431 OH_Drawing_PathGetMatrix(path, true, 50, matrix, GET_POSITION_MATRIX);
432 // 6. Free the memory
433 OH_Drawing_PathDestroy(path);
434 }
435
436 /*
437 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_4004
438 * @tc.name: testPathGetMatrixMaximal
439 * @tc.desc: Test for getting transformation matrix of a path with maximal values.
440 * @tc.size : SmallTest
441 * @tc.type : Function
442 * @tc.level : Level 3
443 */
HWTEST_F(DrawingNativePathTest, testPathGetMatrixMaximal, TestSize.Level3)444 HWTEST_F(DrawingNativePathTest, testPathGetMatrixMaximal, TestSize.Level3) {
445 // 1. Create a path object using OH_Drawing_PathCreate
446 OH_Drawing_Path *path = OH_Drawing_PathCreate();
447 // 2. Create a matrix object using OH_Drawing_MatrixCreate
448 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
449 OH_Drawing_MatrixSetMatrix(matrix, 5, 4, 0, 0, -1, 0, 0, 0, 1);
450 // 3. Set the starting point of the path using OH_Drawing_PathMoveTo
451 OH_Drawing_PathMoveTo(path, 0, 0);
452 // 4. Add a line segment from the starting point to the target point using OH_Drawing_PathLineTo
453 OH_Drawing_PathLineTo(path, 100, 100);
454 // 5. Get the transformation matrix of a point at a specified distance from the starting point of the path. Set the
455 // third parameter to a large value FLT_MAX + 1.
456 OH_Drawing_PathGetMatrix(path, true, FLT_MAX + 1, matrix, GET_POSITION_MATRIX);
457 // 6. Free the memory
458 OH_Drawing_PathDestroy(path);
459 }
460
461 } // namespace Drawing
462 } // namespace Rosen
463 } // namespace OHOS