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