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
26using namespace testing;
27using namespace testing::ext;
28
29namespace OHOS {
30namespace Rosen {
31namespace Drawing {
32class NativeDrawingPathLargeValueTest : public testing::Test {
33public:
34    static void SetUpTestCase();
35    static void TearDownTestCase();
36    void SetUp() override;
37    void TearDown() override;
38};
39
40void NativeDrawingPathLargeValueTest::SetUpTestCase() {}
41void NativeDrawingPathLargeValueTest::TearDownTestCase() {}
42void NativeDrawingPathLargeValueTest::SetUp() {}
43void NativeDrawingPathLargeValueTest::TearDown() {}
44
45/*
46 * @tc.name: NativeDrawingPathLargeValueTest_pathCreate001
47 * @tc.desc: test for create drawing_path.
48 * @tc.size  : MediumTest
49 * @tc.type  : Function
50 * @tc.level : Level 1
51 */
52HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_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: NativeDrawingPathLargeValueTest_pathMoveTo002
61 * @tc.desc: test for PathMoveTo func.
62 * @tc.size  : MediumTest
63 * @tc.type  : Function
64 * @tc.level : Level 1
65 */
66HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathMoveTo002, TestSize.Level1)
67{
68    OH_Drawing_Path* path1 = OH_Drawing_PathCreate();
69    OH_Drawing_PathMoveTo(path1, 2160, 4096);
70    OH_Drawing_PathMoveTo(path1, -1, 20.6f);
71    OH_Drawing_PathDestroy(path1);
72}
73
74/*
75 * @tc.name: NativeDrawingPathLargeValueTest_pathLineTo003
76 * @tc.desc: test for PathLineTo func.
77 * @tc.size  : MediumTest
78 * @tc.type  : Function
79 * @tc.level : Level 1
80 */
81HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathLineTo003, TestSize.Level1)
82{
83    OH_Drawing_Path* path2 = OH_Drawing_PathCreate();
84    OH_Drawing_PathLineTo(path2, 2160, 4096);
85    OH_Drawing_PathLineTo(path2, -50, 10.2f);
86    OH_Drawing_PathDestroy(path2);
87}
88
89/*
90 * @tc.name: NativeDrawingPathLargeValueTest_pathReset004
91 * @tc.desc: test for PathReset func.
92 * @tc.size  : MediumTest
93 * @tc.type  : Function
94 * @tc.level : Level 1
95 */
96HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathReset004, TestSize.Level1)
97{
98    OH_Drawing_Path* path3 = OH_Drawing_PathCreate();
99    OH_Drawing_PathMoveTo(path3, 2160, 4096);
100    OH_Drawing_PathReset(path3);
101    OH_Drawing_PathDestroy(path3);
102}
103
104/*
105 * @tc.name: NativeDrawingPathLargeValueTest_pathArcTo005
106 * @tc.desc: test for PathArcTo func.
107 * @tc.size  : MediumTest
108 * @tc.type  : Function
109 * @tc.level : Level 1
110 */
111HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathArcTo005, TestSize.Level1)
112{
113    OH_Drawing_Path* path4 = OH_Drawing_PathCreate();
114    OH_Drawing_PathArcTo(path4, 10, 10, 2160, 4096, 0, 90);
115    OH_Drawing_PathArcTo(path4, -10, 10, 10, -10, 0, 90);
116    OH_Drawing_PathDestroy(path4);
117}
118
119/*
120 * @tc.name: NativeDrawingPathLargeValueTest_pathQuadTo006
121 * @tc.desc: test for PathQuadTo func.
122 * @tc.size  : MediumTest
123 * @tc.type  : Function
124 * @tc.level : Level 1
125 */
126HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathQuadTo006, TestSize.Level1)
127{
128    OH_Drawing_Path* path5 = OH_Drawing_PathCreate();
129    OH_Drawing_PathQuadTo(path5, 0, 0, 2160, 4096);
130    OH_Drawing_PathQuadTo(path5, -20.5f, -20.5f, 30, 0);
131    OH_Drawing_PathDestroy(path5);
132}
133
134/*
135 * @tc.name: NativeDrawingPathLargeValueTest_pathCubicTo007
136 * @tc.desc: test for PathCubicTo func.
137 * @tc.size  : MediumTest
138 * @tc.type  : Function
139 * @tc.level : Level 1
140 */
141HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathCubicTo007, TestSize.Level1)
142{
143    OH_Drawing_Path* path6 = OH_Drawing_PathCreate();
144    OH_Drawing_PathCubicTo(path6, 30, 40, 60, 0, 2160, 4096);
145    OH_Drawing_PathCubicTo(path6, -30, 40, 60, -30.6f, 50, -20);
146    OH_Drawing_PathDestroy(path6);
147}
148
149/*
150 * @tc.name: NativeDrawingPathLargeValueTest_pathClose008
151 * @tc.desc: test for PathClose func.
152 * @tc.size  : MediumTest
153 * @tc.type  : Function
154 * @tc.level : Level 1
155 */
156HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathClose008, TestSize.Level1)
157{
158    OH_Drawing_Path* path7 = OH_Drawing_PathCreate();
159    OH_Drawing_PathLineTo(path7, 2160, 4096);
160    OH_Drawing_PathClose(path7);
161    OH_Drawing_PathDestroy(path7);
162}
163
164/*
165 * @tc.name: NativeDrawingPathLargeValueTest_pathCopy009
166 * @tc.desc: test for PathCopy func.
167 * @tc.size  : MediumTest
168 * @tc.type  : Function
169 * @tc.level : Level 1
170 */
171HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathCopy009, TestSize.Level1)
172{
173    OH_Drawing_Path* path7 = OH_Drawing_PathCreate();
174    OH_Drawing_PathLineTo(path7, 2160, 4096);
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(), 2160.0));
179    EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(pathCopy)->GetBounds().GetHeight(), 4096.0));
180    OH_Drawing_PathDestroy(path7);
181    OH_Drawing_PathDestroy(pathCopy);
182}
183
184/*
185 * @tc.name: NativeDrawingPathLargeValueTest_pathAddRect010
186 * @tc.desc: test for PathAddRect func.
187 * @tc.size  : MediumTest
188 * @tc.type  : Function
189 * @tc.level : Level 1
190 */
191HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathAddRect010, TestSize.Level1)
192{
193    OH_Drawing_Path* path = OH_Drawing_PathCreate();
194    OH_Drawing_PathAddRect(nullptr, 50, 50, 2160, 4096, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
195    OH_Drawing_PathAddRect(path, 50, 50, 2160, 4096, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
196    EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 2110.0));
197    EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 4046.0));
198    OH_Drawing_PathDestroy(path);
199}
200
201/*
202 * @tc.name: NativeDrawingPathLargeValueTest_pathAddRoundRect011
203 * @tc.desc: test for PathAddRoundRect  func.
204 * @tc.size  : MediumTest
205 * @tc.type  : Function
206 * @tc.level : Level 1
207 */
208HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathAddRoundRect011, TestSize.Level1)
209{
210    OH_Drawing_Path* path = OH_Drawing_PathCreate();
211    OH_Drawing_PathAddRect(nullptr, 50, 50, 2160, 4096, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
212    OH_Drawing_Rect* rect = OH_Drawing_RectCreate(50, 50, 2160, 4096);
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(), 2110.0));
216    EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 4046.0));
217    OH_Drawing_PathDestroy(path);
218    OH_Drawing_RoundRectDestroy(roundRect);
219    OH_Drawing_RectDestroy(rect);
220}
221} // namespace Drawing
222} // namespace Rosen
223} // namespace OHOS