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 NativeDrawingPathLargeValueTest : 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 NativeDrawingPathLargeValueTest::SetUpTestCase() {}
TearDownTestCase()41 void NativeDrawingPathLargeValueTest::TearDownTestCase() {}
SetUp()42 void NativeDrawingPathLargeValueTest::SetUp() {}
TearDown()43 void 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 */
52 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathCreate001, Function | MediumTest | 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 */
66 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathMoveTo002, Function | MediumTest | 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 */
81 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathLineTo003, Function | MediumTest | 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 */
96 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathReset004, Function | MediumTest | 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 */
111 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathArcTo005, Function | MediumTest | 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 */
126 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathQuadTo006, Function | MediumTest | 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 */
141 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathCubicTo007,
142 Function | MediumTest | Level1)
143 {
144 OH_Drawing_Path* path6 = OH_Drawing_PathCreate();
145 OH_Drawing_PathCubicTo(path6, 30, 40, 60, 0, 2160, 4096);
146 OH_Drawing_PathCubicTo(path6, -30, 40, 60, -30.6f, 50, -20);
147 OH_Drawing_PathDestroy(path6);
148 }
149
150 /*
151 * @tc.name: NativeDrawingPathLargeValueTest_pathClose008
152 * @tc.desc: test for PathClose func.
153 * @tc.size : MediumTest
154 * @tc.type : Function
155 * @tc.level : Level 1
156 */
157 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathClose008, Function | MediumTest | Level1)
158 {
159 OH_Drawing_Path* path7 = OH_Drawing_PathCreate();
160 OH_Drawing_PathLineTo(path7, 2160, 4096);
161 OH_Drawing_PathClose(path7);
162 OH_Drawing_PathDestroy(path7);
163 }
164
165 /*
166 * @tc.name: NativeDrawingPathLargeValueTest_pathCopy009
167 * @tc.desc: test for PathCopy func.
168 * @tc.size : MediumTest
169 * @tc.type : Function
170 * @tc.level : Level 1
171 */
172 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathCopy009, TestSize.Level1)
173 {
174 OH_Drawing_Path* path7 = OH_Drawing_PathCreate();
175 OH_Drawing_PathLineTo(path7, 2160, 4096);
176 OH_Drawing_PathClose(path7);
177 EXPECT_EQ(OH_Drawing_PathCopy(nullptr), nullptr);
178 OH_Drawing_Path* pathCopy = OH_Drawing_PathCopy(path7);
179 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(pathCopy)->GetBounds().GetWidth(), 2160.0));
180 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(pathCopy)->GetBounds().GetHeight(), 4096.0));
181 OH_Drawing_PathDestroy(path7);
182 OH_Drawing_PathDestroy(pathCopy);
183 }
184
185 /*
186 * @tc.name: NativeDrawingPathLargeValueTest_pathAddRect010
187 * @tc.desc: test for PathAddRect func.
188 * @tc.size : MediumTest
189 * @tc.type : Function
190 * @tc.level : Level 1
191 */
192 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathAddRect010,
193 Function | MediumTest | Level1)
194 {
195 OH_Drawing_Path* path = OH_Drawing_PathCreate();
196 OH_Drawing_PathAddRect(nullptr, 50, 50, 2160, 4096, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
197 OH_Drawing_PathAddRect(path, 50, 50, 2160, 4096, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
198 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 2110.0));
199 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 4046.0));
200 OH_Drawing_PathDestroy(path);
201 }
202
203 /*
204 * @tc.name: NativeDrawingPathLargeValueTest_pathAddRoundRect011
205 * @tc.desc: test for PathAddRoundRect func.
206 * @tc.size : MediumTest
207 * @tc.type : Function
208 * @tc.level : Level 1
209 */
210 HWTEST_F(NativeDrawingPathLargeValueTest, NativeDrawingPathLargeValueTest_pathAddRoundRect011,
211 Function | MediumTest | Level1)
212 {
213 OH_Drawing_Path* path = OH_Drawing_PathCreate();
214 OH_Drawing_PathAddRect(nullptr, 50, 50, 2160, 4096, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
215 OH_Drawing_Rect* rect = OH_Drawing_RectCreate(50, 50, 2160, 4096);
216 OH_Drawing_RoundRect* roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
217 OH_Drawing_PathAddRoundRect(path, roundRect, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
218 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetWidth(), 2110.0));
219 EXPECT_TRUE(IsScalarAlmostEqual(reinterpret_cast<Path*>(path)->GetBounds().GetHeight(), 4046.0));
220 OH_Drawing_PathDestroy(path);
221 OH_Drawing_RoundRectDestroy(roundRect);
222 OH_Drawing_RectDestroy(rect);
223 }
224 } // namespace Drawing
225 } // namespace Rosen
226 } // namespace OHOS