1 /*
2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, Hardware
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 <cstdio>
17 #include "gtest/gtest.h"
18
19 #include "drawing_path.h"
20 #include "drawing_matrix.h"
21 #include "drawing_rect.h"
22 #include "drawing_round_rect.h"
23 #include "draw/path.h"
24 #include "utils/scalar.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31 namespace Drawing {
32 class NativeDrawingPathTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38 };
39
SetUpTestCase()40 void NativeDrawingPathTest::SetUpTestCase() {}
TearDownTestCase()41 void NativeDrawingPathTest::TearDownTestCase() {}
SetUp()42 void NativeDrawingPathTest::SetUp() {}
TearDown()43 void NativeDrawingPathTest::TearDown() {}
44
45 /*
46 * @tc.name: NativeDrawingPathTest_pathCreate001
47 * @tc.desc: test for create drawing_path.
48 * @tc.size : MediumTest
49 * @tc.type : Function
50 * @tc.level : Level 1
51 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathCreate001, TestSize.Level1)52 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathCreate001, TestSize.Level1)
53 {
54 OH_Drawing_Path* path = OH_Drawing_PathCreate();
55 EXPECT_EQ(path == nullptr, false);
56 OH_Drawing_PathDestroy(path);
57 }
58
59 /*
60 * @tc.name: NativeDrawingPathTest_pathMoveTo002
61 * @tc.desc: test for PathMoveTo func.
62 * @tc.size : MediumTest
63 * @tc.type : Function
64 * @tc.level : Level 1
65 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathMoveTo002, TestSize.Level1)66 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathMoveTo002, TestSize.Level1)
67 {
68 OH_Drawing_Path* path1 = OH_Drawing_PathCreate();
69 OH_Drawing_PathMoveTo(path1, 20, 20);
70 OH_Drawing_PathMoveTo(path1, -1, 20.6f);
71 OH_Drawing_PathDestroy(path1);
72 }
73
74 /*
75 * @tc.name: NativeDrawingPathTest_pathLineTo003
76 * @tc.desc: test for PathLineTo func.
77 * @tc.size : MediumTest
78 * @tc.type : Function
79 * @tc.level : Level 1
80 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathLineTo003, TestSize.Level1)81 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathLineTo003, TestSize.Level1)
82 {
83 OH_Drawing_Path* path2 = OH_Drawing_PathCreate();
84 OH_Drawing_PathLineTo(path2, 50, 40);
85 OH_Drawing_PathLineTo(path2, -50, 10.2f);
86 OH_Drawing_PathDestroy(path2);
87 }
88
89 /*
90 * @tc.name: NativeDrawingPathTest_pathReset004
91 * @tc.desc: test for PathReset func.
92 * @tc.size : MediumTest
93 * @tc.type : Function
94 * @tc.level : Level 1
95 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathReset004, TestSize.Level1)96 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathReset004, TestSize.Level1)
97 {
98 OH_Drawing_Path* path3 = OH_Drawing_PathCreate();
99 OH_Drawing_PathMoveTo(path3, 20, 20);
100 OH_Drawing_PathReset(path3);
101 OH_Drawing_PathDestroy(path3);
102 }
103
104 /*
105 * @tc.name: NativeDrawingPathTest_pathArcTo005
106 * @tc.desc: test for PathArcTo func.
107 * @tc.size : MediumTest
108 * @tc.type : Function
109 * @tc.level : Level 1
110 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathArcTo005, TestSize.Level1)111 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathArcTo005, TestSize.Level1)
112 {
113 OH_Drawing_Path* path4 = OH_Drawing_PathCreate();
114 OH_Drawing_PathArcTo(path4, 10, 10, 20, 0, 0, 90);
115 OH_Drawing_PathArcTo(path4, -10, 10, 10, -10, 0, 90);
116 OH_Drawing_PathDestroy(path4);
117 }
118
119 /*
120 * @tc.name: NativeDrawingPathTest_pathQuadTo006
121 * @tc.desc: test for PathQuadTo func.
122 * @tc.size : MediumTest
123 * @tc.type : Function
124 * @tc.level : Level 1
125 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathQuadTo006, TestSize.Level1)126 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathQuadTo006, TestSize.Level1)
127 {
128 OH_Drawing_Path* path5 = OH_Drawing_PathCreate();
129 OH_Drawing_PathQuadTo(path5, 0, 0, 30, 30);
130 OH_Drawing_PathQuadTo(path5, -20.5f, -20.5f, 30, 0);
131 OH_Drawing_PathDestroy(path5);
132 }
133
134 /*
135 * @tc.name: NativeDrawingPathTest_pathCubicTo007
136 * @tc.desc: test for PathCubicTo func.
137 * @tc.size : MediumTest
138 * @tc.type : Function
139 * @tc.level : Level 1
140 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathCubicTo007, TestSize.Level1)141 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathCubicTo007, TestSize.Level1)
142 {
143 OH_Drawing_Path* path6 = OH_Drawing_PathCreate();
144 OH_Drawing_PathCubicTo(path6, 30, 40, 60, 0, 50, 20);
145 OH_Drawing_PathCubicTo(path6, -30, 40, 60, -30.6f, 50, -20);
146 OH_Drawing_PathDestroy(path6);
147 }
148
149 /*
150 * @tc.name: NativeDrawingPathTest_pathClose008
151 * @tc.desc: test for PathClose func.
152 * @tc.size : MediumTest
153 * @tc.type : Function
154 * @tc.level : Level 1
155 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathClose008, TestSize.Level1)156 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathClose008, TestSize.Level1)
157 {
158 OH_Drawing_Path* path7 = OH_Drawing_PathCreate();
159 OH_Drawing_PathLineTo(path7, 50, 40);
160 OH_Drawing_PathClose(path7);
161 OH_Drawing_PathDestroy(path7);
162 }
163
164 /*
165 * @tc.name: NativeDrawingPathTest_pathCopy009
166 * @tc.desc: test for PathCopy func.
167 * @tc.size : MediumTest
168 * @tc.type : Function
169 * @tc.level : Level 1
170 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathCopy009, TestSize.Level1)171 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathCopy009, TestSize.Level1)
172 {
173 OH_Drawing_Path* path7 = OH_Drawing_PathCreate();
174 OH_Drawing_PathLineTo(path7, 50, 40);
175 OH_Drawing_PathClose(path7);
176 EXPECT_EQ(OH_Drawing_PathCopy(nullptr), nullptr);
177 OH_Drawing_Path* pathCopy = OH_Drawing_PathCopy(path7);
178 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(pathCopy)->GetBounds().GetWidth(), 50.0));
179 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(pathCopy)->GetBounds().GetHeight(), 40.0));
180 OH_Drawing_PathDestroy(path7);
181 OH_Drawing_PathDestroy(pathCopy);
182 }
183
184 /*
185 * @tc.name: NativeDrawingPathTest_pathAddRect010
186 * @tc.desc: test for PathAddRect func.
187 * @tc.size : MediumTest
188 * @tc.type : Function
189 * @tc.level : Level 1
190 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddRect010, TestSize.Level1)191 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddRect010, TestSize.Level1)
192 {
193 OH_Drawing_Path* path = OH_Drawing_PathCreate();
194 OH_Drawing_PathAddRect(nullptr, 50, 50, 250, 250, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
195 OH_Drawing_PathAddRect(path, 50, 50, 250, 250, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
196 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 200.0));
197 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 200.0));
198 OH_Drawing_PathDestroy(path);
199 }
200
201 /*
202 * @tc.name: NativeDrawingPathTest_pathAddRoundRect011
203 * @tc.desc: test for PathAddRoundRect func.
204 * @tc.size : MediumTest
205 * @tc.type : Function
206 * @tc.level : Level 1
207 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddRoundRect011, TestSize.Level1)208 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddRoundRect011, TestSize.Level1)
209 {
210 OH_Drawing_Path* path = OH_Drawing_PathCreate();
211 OH_Drawing_PathAddRect(nullptr, 50, 50, 250, 250, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
212 OH_Drawing_Rect* rect = OH_Drawing_RectCreate(50, 50, 250, 250);
213 OH_Drawing_RoundRect* roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
214 OH_Drawing_PathAddRoundRect(path, roundRect, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
215 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 200.0));
216 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 200.0));
217 OH_Drawing_PathDestroy(path);
218 OH_Drawing_RoundRectDestroy(roundRect);
219 OH_Drawing_RectDestroy(rect);
220 }
221
222 /*
223 * @tc.name: NativeDrawingPathTest_pathAddArc012
224 * @tc.desc: test for PathAddArc func.
225 * @tc.size : MediumTest
226 * @tc.type : Function
227 * @tc.level : Level 1
228 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddArc012, TestSize.Level1)229 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddArc012, TestSize.Level1)
230 {
231 OH_Drawing_Path* path = OH_Drawing_PathCreate();
232 OH_Drawing_Rect* rect = OH_Drawing_RectCreate(50, 50, 250, 250);
233 OH_Drawing_PathAddArc(nullptr, rect, 0, 180);
234 OH_Drawing_PathAddArc(path, nullptr, 0, 180);
235 OH_Drawing_PathAddArc(path, rect, 0, 180);
236 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 200.0));
237 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 100.0));
238 OH_Drawing_PathDestroy(path);
239 OH_Drawing_RectDestroy(rect);
240 }
241
242 /*
243 * @tc.name: NativeDrawingPathTest_pathContains013
244 * @tc.desc: test for PathContains func.
245 * @tc.size : MediumTest
246 * @tc.type : Function
247 * @tc.level : Level 1
248 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathContains013, TestSize.Level1)249 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathContains013, TestSize.Level1)
250 {
251 OH_Drawing_Path* path = OH_Drawing_PathCreate();
252 OH_Drawing_PathAddRect(path, 50, 50, 250, 250, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
253 OH_Drawing_PathContains(nullptr, 0, 0);
254 bool ret = OH_Drawing_PathContains(path, 0, 0);
255 EXPECT_EQ(ret, false);
256 ret = OH_Drawing_PathContains(path, 60, 60);
257 EXPECT_EQ(ret, true);
258 OH_Drawing_PathDestroy(path);
259 }
260
261 /*
262 * @tc.name: NativeDrawingPathTest_pathTransform014
263 * @tc.desc: test for PathTransform func.
264 * @tc.size : MediumTest
265 * @tc.type : Function
266 * @tc.level : Level 1
267 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathTransform014, TestSize.Level1)268 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathTransform014, TestSize.Level1)
269 {
270 OH_Drawing_Path* path = OH_Drawing_PathCreate();
271 OH_Drawing_PathAddRect(path, 50, 50, 250, 250, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
272 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateTranslation(1, 1);
273 OH_Drawing_PathTransform(nullptr, matrix);
274 OH_Drawing_PathTransform(path, nullptr);
275
276 bool ret = OH_Drawing_PathContains(path, 50, 50);
277 EXPECT_EQ(ret, true);
278 OH_Drawing_PathTransform(path, matrix);
279 ret = OH_Drawing_PathContains(path, 50, 50);
280 EXPECT_EQ(ret, false);
281 OH_Drawing_PathDestroy(path);
282 }
283
284 /*
285 * @tc.name: NativeDrawingPathTest_pathSetFilltype015
286 * @tc.desc: test for PathSetFillType func.
287 * @tc.size : MediumTest
288 * @tc.type : Function
289 * @tc.level : Level 1
290 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathSetFilltype015, TestSize.Level1)291 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathSetFilltype015, TestSize.Level1)
292 {
293 OH_Drawing_Path* path = OH_Drawing_PathCreate();
294 OH_Drawing_PathSetFillType(nullptr, PATH_FILL_TYPE_WINDING);
295 OH_Drawing_PathSetFillType(path, PATH_FILL_TYPE_WINDING);
296
297 OH_Drawing_PathLineTo(path, 50, 40);
298 OH_Drawing_PathClose(path);
299 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 50.0));
300 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 40.0));
301 float ret = OH_Drawing_PathGetLength(path, true);
302 EXPECT_TRUE(IsScalarAlmostEqual(ret, 128.062485)); // 128.062485 is length of path
303 OH_Drawing_PathDestroy(path);
304 }
305 /*
306 * @tc.name: NativeDrawingPathTest_pathConicTo016
307 * @tc.desc: test for PathConicTo func.
308 * @tc.size : MediumTest
309 * @tc.type : Function
310 * @tc.level : Level 1
311 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathConicTo016, TestSize.Level1)312 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathConicTo016, TestSize.Level1)
313 {
314 OH_Drawing_Path* path = OH_Drawing_PathCreate();
315 OH_Drawing_PathConicTo(path, 0, 0, 30, 30, 1);
316 OH_Drawing_PathConicTo(path, -20.5f, -20.5f, 30, 0, 1);
317 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 50.5));
318 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 50.5));
319 OH_Drawing_PathDestroy(path);
320 }
321
322 /*
323 * @tc.name: NativeDrawingPathTest_pathAddRectWithInitialCorner017
324 * @tc.desc: test for PathAddRectWithInitialCorner func.
325 * @tc.size : MediumTest
326 * @tc.type : Function
327 * @tc.level : Level 1
328 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddRectWithInitialCorner017, TestSize.Level1)329 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddRectWithInitialCorner017, TestSize.Level1)
330 {
331 OH_Drawing_Path* path = OH_Drawing_PathCreate();
332 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 200.0f, 300.0f);
333 OH_Drawing_PathAddRectWithInitialCorner(path, rect, PATH_DIRECTION_CW, 0);
334 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 200.0));
335 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 300.0));
336 OH_Drawing_PathClose(path);
337 OH_Drawing_PathDestroy(path);
338 OH_Drawing_RectDestroy(rect);
339 }
340
341 /*
342 * @tc.name: NativeDrawingPathTest_pathAddPathWithMode018
343 * @tc.desc: test for PathAddPathWithMode func.
344 * @tc.size : MediumTest
345 * @tc.type : Function
346 * @tc.level : Level 1
347 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddPathWithMode018, TestSize.Level1)348 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddPathWithMode018, TestSize.Level1)
349 {
350 OH_Drawing_Path* path = OH_Drawing_PathCreate();
351 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 200.0f, 300.0f);
352 OH_Drawing_PathAddRectWithInitialCorner(path, rect, PATH_DIRECTION_CW, 0);
353 OH_Drawing_Path* path2 = OH_Drawing_PathCreate();
354 OH_Drawing_PathAddPathWithMode(path2, path, PATH_ADD_MODE_APPEND);
355 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path2)->GetBounds().GetWidth(), 200.0));
356 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path2)->GetBounds().GetHeight(), 300.0));
357 OH_Drawing_PathDestroy(path);
358 OH_Drawing_RectDestroy(rect);
359 OH_Drawing_PathDestroy(path2);
360 }
361
362 /*
363 * @tc.name: NativeDrawingPathTest_pathAddPathWithOffsetAndMode019
364 * @tc.desc: test for PathAddPathWithOffsetAndMode func.
365 * @tc.size : MediumTest
366 * @tc.type : Function
367 * @tc.level : Level 1
368 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddPathWithOffsetAndMode019, TestSize.Level1)369 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddPathWithOffsetAndMode019, TestSize.Level1)
370 {
371 OH_Drawing_Path* path = OH_Drawing_PathCreate();
372 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 200.0f, 300.0f);
373 OH_Drawing_PathAddRectWithInitialCorner(path, rect, PATH_DIRECTION_CW, 0);
374 OH_Drawing_Path* path2 = OH_Drawing_PathCreate();
375 OH_Drawing_PathAddPathWithOffsetAndMode(path2, path, 0, 0, PATH_ADD_MODE_APPEND);
376 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path2)->GetBounds().GetWidth(), 200.0));
377 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path2)->GetBounds().GetHeight(), 300.0));
378 OH_Drawing_PathDestroy(path);
379 OH_Drawing_RectDestroy(rect);
380 OH_Drawing_PathDestroy(path2);
381 }
382
383 /*
384 * @tc.name: NativeDrawingPathTest_pathAddPathWithMatrixAndMode020
385 * @tc.desc: test for PathAddPathWithMatrixAndMode func.
386 * @tc.size : MediumTest
387 * @tc.type : Function
388 * @tc.level : Level 1
389 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddPathWithMatrixAndMode020, TestSize.Level1)390 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddPathWithMatrixAndMode020, TestSize.Level1)
391 {
392 OH_Drawing_Path* path = OH_Drawing_PathCreate();
393 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 200.0f, 300.0f);
394 OH_Drawing_PathAddRectWithInitialCorner(path, rect, PATH_DIRECTION_CW, 0);
395 OH_Drawing_Path* path2 = OH_Drawing_PathCreate();
396 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
397
398 OH_Drawing_PathAddPathWithMatrixAndMode(path2, path, matrix, PATH_ADD_MODE_APPEND);
399 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path2)->GetBounds().GetWidth(), 200.0));
400 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path2)->GetBounds().GetHeight(), 300.0));
401
402 OH_Drawing_Path* pathRect = OH_Drawing_PathCreate();
403 OH_Drawing_PathAddRect(pathRect, 0.0f, 0.0f, 200.0f, 300.0f, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
404 OH_Drawing_MatrixSetMatrix(
405 matrix,
406 5, 4, 0,
407 0, -1, 0,
408 0, 0, 1);
409 OH_Drawing_PathAddPath(pathRect, pathRect, nullptr);
410 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(pathRect)->GetBounds().GetWidth(), 200.0));
411 OH_Drawing_PathAddPath(pathRect, pathRect, matrix);
412 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(pathRect)->GetBounds().GetWidth(), 2200.0));
413 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(pathRect)->GetBounds().GetHeight(), 600.0));
414 OH_Drawing_PathAddPath(nullptr, pathRect, matrix);
415 OH_Drawing_PathAddPath(pathRect, nullptr, matrix);
416 OH_Drawing_PathDestroy(path);
417 OH_Drawing_RectDestroy(rect);
418 OH_Drawing_PathDestroy(path2);
419 OH_Drawing_PathDestroy(pathRect);
420 OH_Drawing_MatrixDestroy(matrix);
421 }
422
423 /*
424 * @tc.name: NativeDrawingPathTest_pathOffset021
425 * @tc.desc: test for PathOffset func.
426 * @tc.size : MediumTest
427 * @tc.type : Function
428 * @tc.level : Level 1
429 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathOffset021, TestSize.Level1)430 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathOffset021, TestSize.Level1)
431 {
432 OH_Drawing_Path* path = OH_Drawing_PathCreate();
433 OH_Drawing_Path* path2 = OH_Drawing_PathCreate();
434 OH_Drawing_PathOffset(path, path2, 50, 40);
435 OH_Drawing_PathReset(path);
436 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 0.0));
437 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 0.0));
438 OH_Drawing_PathDestroy(path);
439 OH_Drawing_PathDestroy(path2);
440 }
441
442 /*
443 * @tc.name: NativeDrawingPathTest_pathAddOvalWithInitialPoint022
444 * @tc.desc: test for PathAddOvalWithInitialPoint func.
445 * @tc.size : MediumTest
446 * @tc.type : Function
447 * @tc.level : Level 1
448 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddOvalWithInitialPoint022, TestSize.Level1)449 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddOvalWithInitialPoint022, TestSize.Level1)
450 {
451 OH_Drawing_Path* path9 = OH_Drawing_PathCreate();
452 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 100, 500, 400);
453 OH_Drawing_PathAddOvalWithInitialPoint(path9, rect, 10, PATH_DIRECTION_CW);
454 OH_Drawing_PathClose(path9);
455 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path9)->GetBounds().GetWidth(), 500.0));
456 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path9)->GetBounds().GetHeight(), 300.0));
457 OH_Drawing_PathDestroy(path9);
458 OH_Drawing_RectDestroy(rect);
459 }
460
461 /*
462 * @tc.name: NativeDrawingPathTest_pathRMoveTo023
463 * @tc.desc: test for PathRMoveTo func.
464 * @tc.size : MediumTest
465 * @tc.type : Function
466 * @tc.level : Level 1
467 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRMoveTo023, TestSize.Level1)468 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRMoveTo023, TestSize.Level1)
469 {
470 OH_Drawing_Path* path10 = OH_Drawing_PathCreate();
471 OH_Drawing_PathRMoveTo(path10, 100, 100);
472 OH_Drawing_PathLineTo(path10, 300, 300);
473 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path10)->GetBounds().GetWidth(), 200.0));
474 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path10)->GetBounds().GetHeight(), 200.0));
475 OH_Drawing_PathDestroy(path10);
476 }
477
478 /*
479 * @tc.name: NativeDrawingPathTest_pathRLineTo024
480 * @tc.desc: test for PathRLineTo func.
481 * @tc.size : MediumTest
482 * @tc.type : Function
483 * @tc.level : Level 1
484 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRLineTo024, TestSize.Level1)485 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRLineTo024, TestSize.Level1)
486 {
487 OH_Drawing_Path* path11 = OH_Drawing_PathCreate();
488 OH_Drawing_PathMoveTo(path11, 100, 100);
489 OH_Drawing_PathRLineTo(path11, 300, 300);
490 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path11)->GetBounds().GetWidth(), 300.0));
491 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path11)->GetBounds().GetHeight(), 300.0));
492 OH_Drawing_PathDestroy(path11);
493 }
494
495 /*
496 * @tc.name: NativeDrawingPathTest_pathRQuadTo025
497 * @tc.desc: test for PathRQuadTo func.
498 * @tc.size : MediumTest
499 * @tc.type : Function
500 * @tc.level : Level 1
501 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRQuadTo025, TestSize.Level1)502 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRQuadTo025, TestSize.Level1)
503 {
504 OH_Drawing_Path* path12 = OH_Drawing_PathCreate();
505 OH_Drawing_PathQuadTo(path12, 0, 0, 30, 30);
506 OH_Drawing_PathRQuadTo(path12, 100, 100, 100, 300);
507 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path12)->GetBounds().GetWidth(), 130.0));
508 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path12)->GetBounds().GetHeight(), 330.0));
509 OH_Drawing_PathDestroy(path12);
510 }
511
512 /*
513 * @tc.name: NativeDrawingPathTest_pathRConicTo026
514 * @tc.desc: test for PathRConicTo func.
515 * @tc.size : MediumTest
516 * @tc.type : Function
517 * @tc.level : Level 1
518 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRConicTo026, TestSize.Level1)519 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRConicTo026, TestSize.Level1)
520 {
521 OH_Drawing_Path* path13 = OH_Drawing_PathCreate();
522 OH_Drawing_PathRConicTo(path13, 100, 100, 100, 300, 5);
523 OH_Drawing_PathRConicTo(path13, 100, 100, 100, 300, 5);
524 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path13)->GetBounds().GetWidth(), 200.0));
525 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path13)->GetBounds().GetHeight(), 600.0));
526 OH_Drawing_PathDestroy(path13);
527 }
528
529 /*
530 * @tc.name: NativeDrawingPathTest_pathRCubicTo027
531 * @tc.desc: test for PathRCubicTo func.
532 * @tc.size : MediumTest
533 * @tc.type : Function
534 * @tc.level : Level 1
535 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRCubicTo027, TestSize.Level1)536 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathRCubicTo027, TestSize.Level1)
537 {
538 OH_Drawing_Path* path14 = OH_Drawing_PathCreate();
539 OH_Drawing_PathCubicTo(path14, 30, 40, 60, 0, 50, 20);
540 OH_Drawing_PathRCubicTo(path14, 30, 40, 60, 0, 50, 20);
541 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path14)->GetBounds().GetWidth(), 110.0));
542 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path14)->GetBounds().GetHeight(), 60.0));
543 OH_Drawing_PathDestroy(path14);
544 }
545
546 /*
547 * @tc.name: NativeDrawingPathTest_pathTransformWithPerspectiveClip028
548 * @tc.desc: test for PathTransformWithPerspectiveClip func.
549 * @tc.size : MediumTest
550 * @tc.type : Function
551 * @tc.level : Level 1
552 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathTransformWithPerspectiveClip028, TestSize.Level1)553 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathTransformWithPerspectiveClip028, TestSize.Level1)
554 {
555 OH_Drawing_Path* path15 = OH_Drawing_PathCreate();
556 OH_Drawing_PathAddRect(path15, 100, 500, 500, 100, PATH_DIRECTION_CW);
557 OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateTranslation(100, 100);
558 OH_Drawing_PathTransformWithPerspectiveClip(path15, matrix, path15, true);
559 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path15)->GetBounds().GetWidth(), 400.0));
560 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path15)->GetBounds().GetHeight(), 400.0));
561 OH_Drawing_PathDestroy(path15);
562 OH_Drawing_MatrixDestroy(matrix);
563 }
564 /*
565 * @tc.name : NativeDrawingPathTest_pathAddPath029
566 * @tc.desc : test for PathAddPath func.
567 * @tc.size : MediumTest
568 * @tc.type : Function
569 * @tc.level : Level 1
570 */
HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddPath029, TestSize.Level1)571 HWTEST_F(NativeDrawingPathTest, NativeDrawingPathTest_pathAddPath029, TestSize.Level1)
572 {
573 OH_Drawing_Path* path16 = OH_Drawing_PathCreate();
574 OH_Drawing_PathAddRect(path16, 100, 500, 500, 100, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
575 OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate();
576 OH_Drawing_MatrixSetMatrix(
577 matrix,
578 1, 0, 0,
579 0, -1, 0,
580 0, 0, 1);
581 OH_Drawing_PathAddPath(path16, path16, matrix);
582 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path16)->GetBounds().GetWidth(), 400.0));
583 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path16)->GetBounds().GetHeight(), 1000.0));
584 OH_Drawing_PathDestroy(path16);
585 OH_Drawing_MatrixDestroy(matrix);
586 }
587 } // namespace Drawing
588 } // namespace Rosen
589 } // namespace OHOS