1 /*
2 * Copyright (c) 2022 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, 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 <cstddef>
17 #include "core/SkPaint.h"
18 #include "gtest/gtest.h"
19 #include "skia_adapter/skia_paint.h"
20 #include "draw/brush.h"
21 #include "draw/color.h"
22 #include "draw/pen.h"
23 #include "effect/color_space.h"
24 #include "effect/filter.h"
25 #include "effect/mask_filter.h"
26 #include "effect/path_effect.h"
27 #include "effect/shader_effect.h"
28
29 using namespace testing;
30 using namespace testing::ext;
31
32 namespace OHOS {
33 namespace Rosen {
34 namespace Drawing {
35 class SkiaPaintTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41 };
42
SetUpTestCase()43 void SkiaPaintTest::SetUpTestCase() {}
TearDownTestCase()44 void SkiaPaintTest::TearDownTestCase() {}
SetUp()45 void SkiaPaintTest::SetUp() {}
TearDown()46 void SkiaPaintTest::TearDown() {}
47
48 /**
49 * @tc.name: BrushToSkPaint001
50 * @tc.desc:
51 * @tc.type: FUNC
52 * @tc.author:
53 */
54 HWTEST_F(SkiaPaintTest, BrushToSkPaint001, TestSize.Level1)
55 {
56 Brush brush;
57 SkPaint skPaint;
58 SkiaPaint skiaPath;
59 skiaPath.BrushToSkPaint(brush, skPaint);
60 }
61
62 /**
63 * @tc.name: BrushToSkPaint002
64 * @tc.desc:
65 * @tc.type: FUNC
66 * @tc.author:
67 */
68 HWTEST_F(SkiaPaintTest, BrushToSkPaint002, TestSize.Level1)
69 {
70 Brush brush;
71 SkPaint skPaint;
72 SkiaPaint skiaPath;
73 Color4f color4f;
74 std::shared_ptr<ColorSpace> colorSpace = ColorSpace::CreateSRGB();
75 brush.SetColor(color4f, colorSpace);
76 skiaPath.BrushToSkPaint(brush, skPaint);
77 }
78
79 /**
80 * @tc.name: BrushToSkPaint003
81 * @tc.desc:
82 * @tc.type: FUNC
83 * @tc.author:
84 */
85 HWTEST_F(SkiaPaintTest, BrushToSkPaint003, TestSize.Level1)
86 {
87 Brush brush;
88 SkPaint skPaint;
89 SkiaPaint skiaPath;
90 std::shared_ptr<ShaderEffect> shaderEffect = ShaderEffect::CreateColorShader(20);
91 brush.SetShaderEffect(shaderEffect);
92 skiaPath.BrushToSkPaint(brush, skPaint);
93 }
94
95 /**
96 * @tc.name: PenToSkPaint001
97 * @tc.desc:
98 * @tc.type: FUNC
99 * @tc.author:
100 */
101 HWTEST_F(SkiaPaintTest, PenToSkPaint001, TestSize.Level1)
102 {
103 Pen pen;
104 SkPaint paint;
105 SkiaPaint skiaPath;
106 skiaPath.PenToSkPaint(pen, paint);
107 }
108
109 /**
110 * @tc.name: PenToSkPaint002
111 * @tc.desc:
112 * @tc.type: FUNC
113 * @tc.author:
114 */
115 HWTEST_F(SkiaPaintTest, PenToSkPaint002, TestSize.Level1)
116 {
117 Pen pen;
118 SkPaint paint;
119 SkiaPaint skiaPath;
120 Color4f color4f;
121 std::shared_ptr<ColorSpace> colorSpace = ColorSpace::CreateSRGB();
122 pen.SetColor(color4f, colorSpace);
123 skiaPath.PenToSkPaint(pen, paint);
124 }
125
126 /**
127 * @tc.name: PenToSkPaint003
128 * @tc.desc:
129 * @tc.type: FUNC
130 * @tc.author:
131 */
132 HWTEST_F(SkiaPaintTest, PenToSkPaint003, TestSize.Level1)
133 {
134 Pen pen;
135 SkPaint paint;
136 SkiaPaint skiaPath;
137 pen.SetCapStyle(Pen::CapStyle::FLAT_CAP);
138 skiaPath.PenToSkPaint(pen, paint);
139 pen.SetCapStyle(Pen::CapStyle::SQUARE_CAP);
140 skiaPath.PenToSkPaint(pen, paint);
141 pen.SetCapStyle(Pen::CapStyle::ROUND_CAP);
142 skiaPath.PenToSkPaint(pen, paint);
143 }
144
145 /**
146 * @tc.name: PenToSkPaint004
147 * @tc.desc:
148 * @tc.type: FUNC
149 * @tc.author:
150 */
151 HWTEST_F(SkiaPaintTest, PenToSkPaint004, TestSize.Level1)
152 {
153 Pen pen;
154 SkPaint paint;
155 SkiaPaint skiaPath;
156 pen.SetJoinStyle(Pen::JoinStyle::BEVEL_JOIN);
157 skiaPath.PenToSkPaint(pen, paint);
158 pen.SetJoinStyle(Pen::JoinStyle::MITER_JOIN);
159 skiaPath.PenToSkPaint(pen, paint);
160 pen.SetJoinStyle(Pen::JoinStyle::ROUND_JOIN);
161 skiaPath.PenToSkPaint(pen, paint);
162 }
163
164 /**
165 * @tc.name: PenToSkPaint005
166 * @tc.desc:
167 * @tc.type: FUNC
168 * @tc.author:
169 */
170 HWTEST_F(SkiaPaintTest, PenToSkPaint005, TestSize.Level1)
171 {
172 Pen pen;
173 SkPaint paint;
174 SkiaPaint skiaPath;
175 skiaPath.PenToSkPaint(pen, paint);
176 }
177
178 /**
179 * @tc.name: PenToSkPaint006
180 * @tc.desc:
181 * @tc.type: FUNC
182 * @tc.author:
183 */
184 HWTEST_F(SkiaPaintTest, PenToSkPaint006, TestSize.Level1)
185 {
186 Pen pen;
187 SkPaint paint;
188 SkiaPaint skiaPath;
189 std::shared_ptr<ShaderEffect> shaderEffect = ShaderEffect::CreateColorShader(25);
190 pen.SetShaderEffect(shaderEffect);
191 skiaPath.PenToSkPaint(pen, paint);
192 }
193
194 /**
195 * @tc.name: PenToSkPaint007
196 * @tc.desc:
197 * @tc.type: FUNC
198 * @tc.author:
199 */
200 HWTEST_F(SkiaPaintTest, PenToSkPaint007, TestSize.Level1)
201 {
202 Pen pen;
203 SkPaint paint;
204 SkiaPaint skiaPath;
205 std::shared_ptr<PathEffect> pathEffect = PathEffect::CreateCornerPathEffect(25.0f);
206 pen.SetPathEffect(pathEffect);
207 skiaPath.PenToSkPaint(pen, paint);
208 }
209
210 /**
211 * @tc.name: GetSortedPaints001
212 * @tc.desc:
213 * @tc.type: FUNC
214 * @tc.author:
215 */
216 HWTEST_F(SkiaPaintTest, GetSortedPaints001, TestSize.Level1)
217 {
218 SkiaPaint skiaPath;
219 skiaPath.GetSortedPaints();
220 }
221
222 /**
223 * @tc.name: GetSortedPaints002
224 * @tc.desc:
225 * @tc.type: FUNC
226 * @tc.author:
227 */
228 HWTEST_F(SkiaPaintTest, GetSortedPaints002, TestSize.Level1)
229 {
230 Pen pen;
231 Brush brush;
232 SkiaPaint skiaPath;
233 skiaPath.SetStrokeFirst(true);
234 skiaPath.ApplyPenToStroke(pen);
235 skiaPath.ApplyBrushToFill(brush);
236 skiaPath.GetSortedPaints();
237 }
238
239 /**
240 * @tc.name: GetSortedPaints003
241 * @tc.desc:
242 * @tc.type: FUNC
243 * @tc.author:
244 */
245 HWTEST_F(SkiaPaintTest, GetSortedPaints003, TestSize.Level1)
246 {
247 Pen pen;
248 SkiaPaint skiaPath;
249 skiaPath.SetStrokeFirst(true);
250 skiaPath.ApplyPenToStroke(pen);
251 skiaPath.GetSortedPaints();
252 }
253
254 /**
255 * @tc.name: GetSortedPaints004
256 * @tc.desc:
257 * @tc.type: FUNC
258 * @tc.author:
259 */
260 HWTEST_F(SkiaPaintTest, GetSortedPaints004, TestSize.Level1)
261 {
262 Brush brush;
263 SkiaPaint skiaPath;
264 skiaPath.SetStrokeFirst(true);
265 skiaPath.ApplyBrushToFill(brush);
266 skiaPath.GetSortedPaints();
267 }
268
269 /**
270 * @tc.name: ApplyFilter001
271 * @tc.desc:
272 * @tc.type: FUNC
273 * @tc.author:
274 */
275 HWTEST_F(SkiaPaintTest, ApplyFilter001, TestSize.Level1)
276 {
277 Brush brush;
278 SkPaint paint;
279 SkiaPaint skiaPath;
280 skiaPath.BrushToSkPaint(brush, paint);
281 }
282
283 /**
284 * @tc.name: ApplyFilter002
285 * @tc.desc:
286 * @tc.type: FUNC
287 * @tc.author:
288 */
289 HWTEST_F(SkiaPaintTest, ApplyFilter002, TestSize.Level1)
290 {
291 Brush brush;
292 SkPaint paint;
293 Filter filter;
294 SkiaPaint skiaPath;
295 filter.SetFilterQuality(Filter::FilterQuality::LOW);
296 brush.SetFilter(filter);
297 skiaPath.BrushToSkPaint(brush, paint);
298 filter.SetFilterQuality(Filter::FilterQuality::MEDIUM);
299 brush.SetFilter(filter);
300 skiaPath.BrushToSkPaint(brush, paint);
301 filter.SetFilterQuality(Filter::FilterQuality::HIGH);
302 brush.SetFilter(filter);
303 skiaPath.BrushToSkPaint(brush, paint);
304 filter.SetFilterQuality(Filter::FilterQuality::NONE);
305 brush.SetFilter(filter);
306 skiaPath.BrushToSkPaint(brush, paint);
307 }
308
309 /**
310 * @tc.name: ApplyFilter003
311 * @tc.desc:
312 * @tc.type: FUNC
313 * @tc.author:
314 */
315 HWTEST_F(SkiaPaintTest, ApplyFilter003, TestSize.Level1)
316 {
317 Brush brush;
318 SkPaint paint;
319 Filter filter;
320 SkiaPaint skiaPath;
321 std::shared_ptr<MaskFilter> maskFilter = MaskFilter::CreateBlurMaskFilter(BlurType::INNER, 20.0f);
322 filter.SetMaskFilter(maskFilter);
323 skiaPath.BrushToSkPaint(brush, paint);
324 }
325
326 } // namespace Drawing
327 } // namespace Rosen
328 } // namespace OHOS