• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, 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 "gtest/gtest.h"
17 
18 #include "c/drawing_bitmap.h"
19 #include "c/drawing_brush.h"
20 #include "c/drawing_canvas.h"
21 #include "c/drawing_color.h"
22 #include "c/drawing_color_filter.h"
23 #include "c/drawing_filter.h"
24 #include "c/drawing_font.h"
25 #include "c/drawing_mask_filter.h"
26 #include "c/drawing_path.h"
27 #include "c/drawing_pen.h"
28 #include "c/drawing_point.h"
29 #include "c/drawing_rect.h"
30 #include "c/drawing_round_rect.h"
31 #include "c/drawing_shader_effect.h"
32 #include "c/drawing_text_blob.h"
33 #include "c/drawing_typeface.h"
34 
35 using namespace testing;
36 using namespace testing::ext;
37 
38 namespace OHOS {
39 namespace Rosen {
40 namespace Drawing {
41 class NativeDrawingCanvasTest : public testing::Test {
42 public:
43     static void SetUpTestCase();
44     static void TearDownTestCase();
45     void SetUp() override;
46     void TearDown() override;
47     protected:
48         OH_Drawing_Canvas *canvas_ = nullptr;
49         OH_Drawing_Brush *brush_ = nullptr;
50 };
51 
SetUpTestCase()52 void NativeDrawingCanvasTest::SetUpTestCase() {}
TearDownTestCase()53 void NativeDrawingCanvasTest::TearDownTestCase() {}
SetUp()54 void NativeDrawingCanvasTest::SetUp()
55 {
56     canvas_ = OH_Drawing_CanvasCreate();
57     ASSERT_NE(nullptr, canvas_);
58     OH_Drawing_CanvasClear(canvas_, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
59     brush_ = OH_Drawing_BrushCreate();
60     EXPECT_NE(brush_, nullptr);
61     OH_Drawing_BrushSetColor(brush_, 0xffff0000);
62     OH_Drawing_CanvasAttachBrush(canvas_, brush_);
63 }
64 
TearDown()65 void NativeDrawingCanvasTest::TearDown()
66 {
67     if (canvas_ != nullptr) {
68         OH_Drawing_CanvasDetachBrush(canvas_);
69         OH_Drawing_BrushDestroy(brush_);
70         brush_ = nullptr;
71         OH_Drawing_CanvasDestroy(canvas_);
72         canvas_ = nullptr;
73     }
74 }
75 
76 /*
77  * @tc.name: NativeDrawingCanvasTest_CanvasNULLPTR
78  * @tc.desc: test for OH_Drawing_CanvasBind.
79  * @tc.type: FUNC
80  * @tc.require: AR000GTO5R
81  */
82 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_CanvasNULLPTR, TestSize.Level1)
83 {
84     OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate();
85     EXPECT_NE(bitmap, nullptr);
86     OH_Drawing_CanvasBind(nullptr, bitmap);
87     OH_Drawing_BitmapDestroy(bitmap);
88     OH_Drawing_CanvasAttachPen(canvas_, nullptr);
89     OH_Drawing_CanvasTranslate(canvas_, INT32_MIN, INT32_MIN);
90     OH_Drawing_CanvasTranslate(canvas_, INT32_MAX, INT32_MAX);
91     OH_Drawing_CanvasDrawLine(nullptr, 0, 0, 20, 20);
92     OH_Drawing_CanvasDrawLine(canvas_, 0, 0, INT32_MAX, INT32_MAX);
93     OH_Drawing_CanvasDrawLine(canvas_, 0, 0, INT32_MIN, INT32_MIN);
94     OH_Drawing_Path* path = OH_Drawing_PathCreate();
95     OH_Drawing_PathMoveTo(path, INT32_MAX, INT32_MIN);
96     OH_Drawing_PathMoveTo(nullptr, 9999, -1000);
97     OH_Drawing_PathClose(nullptr);
98     OH_Drawing_PathClose(path);
99     OH_Drawing_CanvasDrawPath(nullptr, path);
100     OH_Drawing_CanvasDrawPath(canvas_, nullptr);
101     OH_Drawing_PathDestroy(path);
102 }
103 
104 /*
105  * @tc.name: NativeDrawingCanvasTest_CanvasBind
106  * @tc.desc: test for OH_Drawing_CanvasBind.
107  * @tc.type: FUNC
108  * @tc.require: AR000GTO5R
109  */
110 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_CanvasBind, TestSize.Level1)
111 {
112     OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate();
113     EXPECT_NE(bitmap, nullptr);
114     OH_Drawing_CanvasBind(canvas_, bitmap);
115     OH_Drawing_BitmapDestroy(bitmap);
116 }
117 
118 /*
119  * @tc.name: NativeDrawingCanvasTest_canvas002
120  * @tc.desc: test for OH_Drawing_CanvasAttachPen & OH_Drawing_CanvasDetachPen.
121  * @tc.type: FUNC
122  * @tc.require: AR000GTO5R
123  */
124 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_canvas002, TestSize.Level1)
125 {
126     OH_Drawing_Pen* pen = OH_Drawing_PenCreate();
127     EXPECT_NE(pen, nullptr);
128     OH_Drawing_CanvasAttachPen(canvas_, pen);
129     OH_Drawing_CanvasDetachPen(canvas_);
130     OH_Drawing_PenDestroy(pen);
131 }
132 
133 /*
134  * @tc.name: NativeDrawingCanvasTest_DrawLine
135  * @tc.desc: test for OH_Drawing_CanvasDrawLine.
136  * @tc.type: FUNC
137  * @tc.require: AR000GTO5R
138  */
139 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_DrawLine, TestSize.Level1)
140 {
141     OH_Drawing_CanvasDrawLine(canvas_, 0, 0, 20, 20);
142     OH_Drawing_CanvasDrawLine(canvas_, -15.2f, -1, 0, 20);
143 }
144 
145 /*
146  * @tc.name: NativeDrawingCanvasTest_DrawPath
147  * @tc.desc: test for OH_Drawing_CanvasDrawPath.
148  * @tc.type: FUNC
149  * @tc.require: AR000GTO5R
150  */
151 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_DrawPath, TestSize.Level1)
152 {
153     OH_Drawing_Path* path = OH_Drawing_PathCreate();
154     EXPECT_NE(path, nullptr);
155     constexpr int height = 300;
156     constexpr int width = 300;
157     constexpr float arc = 18.0f;
158     int len = height / 4;
159     float aX = width / 2;
160     float aY = height / 4;
161     float dX = aX - len * std::sin(arc);
162     float dY = aY + len * std::cos(arc);
163     float cX = aX + len * std::sin(arc);
164     float cY = dY;
165     float bX = aX + (len / 2.0);
166     float bY = aY + std::sqrt((cX - dX) * (cX - dX) + (len / 2.0) * (len / 2.0));
167     float eX = aX - (len / 2.0);
168     float eY = bY;
169     OH_Drawing_PathMoveTo(path, aX, aY);
170     OH_Drawing_PathLineTo(path, bX, bY);
171     OH_Drawing_PathLineTo(path, cX, cY);
172     OH_Drawing_PathLineTo(path, dX, dY);
173     OH_Drawing_PathLineTo(path, eX, eY);
174     OH_Drawing_PathClose(path);
175     OH_Drawing_CanvasDrawPath(canvas_, path);
176     OH_Drawing_PathDestroy(path);
177 }
178 
179 /*
180  * @tc.name: NativeDrawingCanvasTest_SaveAndRestore
181  * @tc.desc: test for OH_Drawing_CanvasSave & OH_Drawing_CanvasRestore.
182  * @tc.type: FUNC
183  * @tc.require: AR000GTO5R
184  */
185 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_SaveAndRestore, TestSize.Level1)
186 {
187     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(100, 200, 500, 300);
188     EXPECT_NE(nullptr, rect);
189     OH_Drawing_CanvasSave(nullptr);
190     OH_Drawing_CanvasSave(canvas_);
191     OH_Drawing_CanvasTranslate(nullptr, 100, 100);
192     OH_Drawing_CanvasTranslate(canvas_, 100, 100);
193     OH_Drawing_CanvasDrawArc(nullptr, rect, 10, 200);
194     OH_Drawing_CanvasDrawArc(canvas_, nullptr, 10, 200);
195     OH_Drawing_CanvasDrawArc(canvas_, rect, 10, 200);
196     OH_Drawing_CanvasRestore(nullptr);
197     OH_Drawing_CanvasRestore(canvas_);
198     OH_Drawing_CanvasTranslate(canvas_, 200, 200);
199     OH_Drawing_CanvasDrawOval(nullptr, rect);
200     OH_Drawing_CanvasDrawOval(canvas_, nullptr);
201     OH_Drawing_CanvasDrawOval(canvas_, rect);
202     OH_Drawing_RectDestroy(nullptr);
203     OH_Drawing_RectDestroy(rect);
204 }
205 
206 /*
207  * @tc.name: NativeDrawingCanvasTest_Clear
208  * @tc.desc: test for OH_Drawing_CanvasClear.
209  * @tc.type: FUNC
210  * @tc.require: AR000GTO5R
211  */
212 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_Clear, TestSize.Level1)
213 {
214     OH_Drawing_CanvasClear(nullptr, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
215     OH_Drawing_CanvasClear(canvas_, -100);
216     OH_Drawing_CanvasClear(canvas_, OH_Drawing_ColorSetArgb(INT32_MAX, INT32_MAX, INT32_MIN, INT32_MIN));
217     OH_Drawing_CanvasClear(canvas_, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
218 }
219 
220 /*
221  * @tc.name: NativeDrawingCanvasTest_RestoreToCount
222  * @tc.desc: test for OH_Drawing_CanvasRestoreToCount.
223  * @tc.type: FUNC
224  * @tc.require: AR000GTO5R
225  */
226 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_RestoreToCount, TestSize.Level1)
227 {
228     OH_Drawing_CanvasSave(canvas_);
229     OH_Drawing_CanvasTranslate(canvas_, 300, 300);
230     OH_Drawing_CanvasSave(canvas_);
231     OH_Drawing_CanvasTranslate(canvas_, 100, 100);
232     OH_Drawing_CanvasSave(canvas_);
233     OH_Drawing_CanvasTranslate(canvas_, 100, 100);
234     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
235     OH_Drawing_CanvasDrawRect(canvas_, rect);
236     int count = OH_Drawing_CanvasGetSaveCount(canvas_);
237     EXPECT_EQ(count, 4);
238     OH_Drawing_CanvasRestoreToCount(nullptr, count - 2);
239     OH_Drawing_CanvasRestoreToCount(canvas_, count - 2);
240     EXPECT_EQ(2, OH_Drawing_CanvasGetSaveCount(canvas_));
241     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(nullptr, 20, 20);
242     EXPECT_EQ(roundRect, nullptr);
243     roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
244     EXPECT_NE(roundRect, nullptr);
245     OH_Drawing_CanvasDrawRoundRect(nullptr, roundRect);
246     OH_Drawing_CanvasDrawRoundRect(canvas_, nullptr);
247     OH_Drawing_CanvasDrawRoundRect(canvas_, roundRect);
248     OH_Drawing_CanvasRestoreToCount(canvas_, 1);
249     OH_Drawing_CanvasDrawRect(canvas_, rect);
250     OH_Drawing_RoundRectDestroy(roundRect);
251     OH_Drawing_RectDestroy(rect);
252     OH_Drawing_RoundRectDestroy(nullptr);
253     OH_Drawing_RectDestroy(nullptr);
254 }
255 
256 /*
257  * @tc.name: NativeDrawingCanvasTest_Scale
258  * @tc.desc: test for OH_Drawing_CanvasScale.
259  * @tc.type: FUNC
260  * @tc.require: AR000GTO5R
261  */
262 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_Scale, TestSize.Level1)
263 {
264     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(10, 20, 60, 120);
265     OH_Drawing_CanvasTranslate(canvas_, 20, 20);
266     OH_Drawing_CanvasDrawRect(canvas_, rect);
267     OH_Drawing_CanvasScale(nullptr, 2, .5f);
268     OH_Drawing_CanvasScale(canvas_, 2, .5f);
269     OH_Drawing_BrushSetColor(nullptr, 0xFF67C23A);
270     OH_Drawing_BrushSetColor(brush_, 0xFF67C23A);
271     OH_Drawing_CanvasDrawRect(canvas_, rect);
272 }
273 
274 /*
275  * @tc.name: NativeDrawingCanvasTest_ClipRect
276  * @tc.desc: test for OH_Drawing_CanvasClipRect.
277  * @tc.type: FUNC
278  * @tc.require: AR000GTO5R
279  */
280 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_ClipRect, TestSize.Level1)
281 {
282     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 90, 90);
283     OH_Drawing_CanvasRotate(nullptr, 10, 0, 0);
284     OH_Drawing_CanvasRotate(canvas_, 10, 0, 0);
285     OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
286     OH_Drawing_BrushSetAntiAlias(nullptr, true);
287     OH_Drawing_BrushSetAntiAlias(brush_, true);
288     for (auto alias : {false, true}) {
289         OH_Drawing_CanvasSave(canvas_);
290         OH_Drawing_CanvasClipRect(nullptr, rect, OH_Drawing_CanvasClipOp::INTERSECT, alias);
291         OH_Drawing_CanvasClipRect(canvas_, nullptr, OH_Drawing_CanvasClipOp::INTERSECT, alias);
292         OH_Drawing_CanvasClipRect(canvas_, rect, OH_Drawing_CanvasClipOp::INTERSECT, alias);
293         OH_Drawing_CanvasDrawCircle(canvas_, nullptr, 60);
294         OH_Drawing_CanvasDrawCircle(nullptr, point, 60);
295         OH_Drawing_CanvasDrawCircle(canvas_, point, 60);
296         OH_Drawing_CanvasRestore(canvas_);
297         OH_Drawing_CanvasTranslate(canvas_, 80, 0);
298     }
299     OH_Drawing_RectDestroy(rect);
300     OH_Drawing_PointDestroy(point);
301 }
302 
303 /*
304  * @tc.name: NativeDrawingCanvasTest_ClipPath
305  * @tc.desc: test for OH_Drawing_CanvasClipPath.
306  * @tc.type: FUNC
307  * @tc.require: AR000GTO5R
308  */
309 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_ClipPath, TestSize.Level1)
310 {
311     OH_Drawing_Path *path = OH_Drawing_PathCreate();
312     OH_Drawing_PathMoveTo(path, 100, 300);
313     OH_Drawing_PathLineTo(path, 200, 300);
314     OH_Drawing_PathLineTo(path, 200, 400);
315     OH_Drawing_PathLineTo(path, 100, 350);
316     OH_Drawing_PathClose(nullptr);
317     OH_Drawing_PathClose(path);
318     OH_Drawing_CanvasClipPath(nullptr, path, OH_Drawing_CanvasClipOp::DIFFERENCE, true);
319     OH_Drawing_CanvasClipPath(canvas_, nullptr, OH_Drawing_CanvasClipOp::DIFFERENCE, true);
320     OH_Drawing_CanvasClipPath(canvas_, path, OH_Drawing_CanvasClipOp::DIFFERENCE, true);
321     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(100, 300, 200, 400);
322     OH_Drawing_CanvasDrawRect(canvas_, rect);
323     OH_Drawing_RectDestroy(rect);
324     OH_Drawing_PathDestroy(path);
325 }
326 
327 /*
328  * @tc.name: NativeDrawingCanvasTest_LinearGradient
329  * @tc.desc: test for LinearGradient
330  * @tc.type: FUNC
331  * @tc.require: AR000GTO5R
332  */
333 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_LinearGradient, TestSize.Level1)
334 {
335     OH_Drawing_Point* startPt = OH_Drawing_PointCreate(100, 400);
336     OH_Drawing_Point* endPt = OH_Drawing_PointCreate(200, 500);
337     uint32_t color[] = {0xffff0000, 0xff00ff00};
338     float pos[] = {0., 1.0};
339     OH_Drawing_ShaderEffect* linearGradient = OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt,
340         color, pos, 2, OH_Drawing_TileMode::CLAMP);
341     OH_Drawing_BrushSetShaderEffect(nullptr, linearGradient);
342     OH_Drawing_BrushSetShaderEffect(brush_, nullptr);
343     OH_Drawing_BrushSetShaderEffect(brush_, linearGradient);
344     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(200, 500, 300, 600);
345     OH_Drawing_CanvasDrawRect(canvas_, rect);
346     OH_Drawing_RectDestroy(rect);
347     OH_Drawing_ShaderEffectDestroy(nullptr);
348     OH_Drawing_ShaderEffectDestroy(linearGradient);
349     OH_Drawing_PointDestroy(startPt);
350     OH_Drawing_PointDestroy(endPt);
351 }
352 
353 /*
354  * @tc.name: NativeDrawingCanvasTest_SweepGradient
355  * @tc.desc: test for sweep gradient shader effect
356  * @tc.type: FUNC
357  * @tc.require: AR000GTO5R
358  */
359 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_SweepGradient, TestSize.Level1)
360 {
361     OH_Drawing_Point* centerPt = OH_Drawing_PointCreate(350, 450);
362     uint32_t colors[] = {0xffff00ff, 0xff00ff00};
363     float pos[] = {0., 1.0};
364     OH_Drawing_ShaderEffect* sweepGradient = OH_Drawing_ShaderEffectCreateSweepGradient(nullptr, nullptr,
365         nullptr, -2, OH_Drawing_TileMode::MIRROR);
366     EXPECT_EQ(sweepGradient, nullptr);
367     sweepGradient = OH_Drawing_ShaderEffectCreateSweepGradient(centerPt, colors,
368         pos, 2, OH_Drawing_TileMode::MIRROR);
369     EXPECT_NE(sweepGradient, nullptr);
370     OH_Drawing_BrushSetShaderEffect(brush_, sweepGradient);
371     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(300, 400, 500, 500);
372     OH_Drawing_CanvasDrawRect(canvas_, rect);
373     OH_Drawing_RectDestroy(rect);
374     OH_Drawing_ShaderEffectDestroy(sweepGradient);
375     OH_Drawing_PointDestroy(centerPt);
376 }
377 
378 /*
379  * @tc.name: NativeDrawingCanvasTest_RadialGradient
380  * @tc.desc: test for Radial gradient shader effect
381  * @tc.type: FUNC
382  * @tc.require: AR000GTO5R
383  */
384 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_RadialGradient, TestSize.Level1)
385 {
386     OH_Drawing_Point* centerPt = OH_Drawing_PointCreate(350, 450);
387     uint32_t colors[] = {0xffff00ff, 0xff00ff00};
388     float pos[] = {0., 1.0};
389     OH_Drawing_ShaderEffect* radialGradient = OH_Drawing_ShaderEffectCreateRadialGradient(nullptr, 20,
390         nullptr, nullptr, -2, OH_Drawing_TileMode::MIRROR);
391     EXPECT_EQ(radialGradient, nullptr);
392     radialGradient = OH_Drawing_ShaderEffectCreateRadialGradient(centerPt, 30, colors,
393         pos, 2, OH_Drawing_TileMode::MIRROR);
394     EXPECT_NE(radialGradient, nullptr);
395     OH_Drawing_BrushSetShaderEffect(brush_, radialGradient);
396     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(300, 400, 500, 500);
397     OH_Drawing_CanvasDrawRect(canvas_, rect);
398     OH_Drawing_RectDestroy(rect);
399     OH_Drawing_ShaderEffectDestroy(radialGradient);
400     OH_Drawing_PointDestroy(centerPt);
401 }
402 
403 /*
404  * @tc.name: NativeDrawingCanvasTest_MaskFilter
405  * @tc.desc: test for maskfilter
406  * @tc.type: FUNC
407  * @tc.require: AR000GTO5R
408  */
409 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_MaskFilter, TestSize.Level1)
410 {
411     EXPECT_EQ(OH_Drawing_BrushGetColor(brush_), 0xFFFF0000);
412     OH_Drawing_MaskFilter* maskFilter = OH_Drawing_MaskFilterCreateBlur(OH_Drawing_BlurType::NORMAL, 10, true);
413     OH_Drawing_Filter* filter = OH_Drawing_FilterCreate();
414     OH_Drawing_FilterSetMaskFilter(nullptr, maskFilter);
415     OH_Drawing_FilterSetMaskFilter(filter, nullptr);
416     OH_Drawing_FilterSetMaskFilter(filter, maskFilter);
417     OH_Drawing_BrushSetFilter(brush_, filter);
418     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(200, 500, 300, 600);
419     OH_Drawing_CanvasDrawRect(canvas_, rect);
420     OH_Drawing_RectDestroy(rect);
421     OH_Drawing_MaskFilterDestroy(maskFilter);
422     OH_Drawing_FilterDestroy(filter);
423 }
424 
425 /*
426  * @tc.name: NativeDrawingCanvasTest_ColorFilter
427  * @tc.desc: test for colorfilter create blend mode, linear to srgb gamma, luma, matrix
428  * @tc.type: FUNC
429  * @tc.require: AR000GTO5R
430  */
431 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_ColorFilterCreateBlendMode, TestSize.Level1)
432 {
433     EXPECT_EQ(OH_Drawing_BrushGetColor(brush_), 0xFFFF0000);
434     OH_Drawing_ColorFilter* colorFilter = OH_Drawing_ColorFilterCreateBlendMode(0xff0000ff,
435         OH_Drawing_BlendMode::BLEND_MODE_SRC);
436     OH_Drawing_Filter* filter = OH_Drawing_FilterCreate();
437     OH_Drawing_FilterSetColorFilter(nullptr, colorFilter);
438     OH_Drawing_FilterSetColorFilter(filter, nullptr);
439     OH_Drawing_FilterSetColorFilter(filter, colorFilter);
440     OH_Drawing_BrushSetFilter(brush_, nullptr);
441     OH_Drawing_BrushSetFilter(brush_, filter);
442     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
443     OH_Drawing_CanvasDrawRect(canvas_, rect);
444     OH_Drawing_ColorFilter* linear = OH_Drawing_ColorFilterCreateLinearToSrgbGamma();
445     OH_Drawing_FilterSetColorFilter(filter, linear);
446     OH_Drawing_CanvasTranslate(canvas_, 100, 100);
447     OH_Drawing_CanvasDrawRect(canvas_, rect);
448     OH_Drawing_ColorFilter* luma = OH_Drawing_ColorFilterCreateLuma();
449     OH_Drawing_FilterSetColorFilter(filter, luma);
450     OH_Drawing_CanvasTranslate(canvas_, 200, 200);
451     OH_Drawing_CanvasDrawRect(canvas_, rect);
452     const float matrix[20] = {
453         1, 0, 0, 0, 0,
454         0, 1, 0, 0, 0,
455         0, 0, 1, 0, 0,
456         0, 0, 0, 0.5f, 0
457     };
458     OH_Drawing_ColorFilter* matrixFilter = OH_Drawing_ColorFilterCreateMatrix(nullptr);
459     EXPECT_EQ(matrixFilter, nullptr);
460     matrixFilter = OH_Drawing_ColorFilterCreateMatrix(matrix);
461     EXPECT_NE(matrixFilter, nullptr);
462     OH_Drawing_FilterSetColorFilter(filter, matrixFilter);
463     OH_Drawing_CanvasTranslate(canvas_, 300, 300);
464     OH_Drawing_CanvasDrawRect(canvas_, rect);
465     OH_Drawing_RectDestroy(rect);
466     OH_Drawing_ColorFilterDestroy(colorFilter);
467     OH_Drawing_ColorFilterDestroy(luma);
468     OH_Drawing_ColorFilterDestroy(matrixFilter);
469     OH_Drawing_ColorFilterDestroy(linear);
470     OH_Drawing_FilterDestroy(filter);
471     OH_Drawing_FilterDestroy(nullptr);
472 }
473 
474 /*
475  * @tc.name: NativeDrawingCanvasTest_ColorFilterCreateCompose
476  * @tc.desc: test for create compose color filter
477  * @tc.type: FUNC
478  * @tc.require: AR000GTO5R
479  */
480 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_ColorFilterCreateCompose, TestSize.Level1)
481 {
482     EXPECT_EQ(OH_Drawing_BrushGetColor(brush_), 0xFFFF0000);
483     OH_Drawing_ColorFilter* outerFilter = OH_Drawing_ColorFilterCreateLuma();
484     OH_Drawing_ColorFilter* innerFilter = OH_Drawing_ColorFilterCreateSrgbGammaToLinear();
485     OH_Drawing_ColorFilter* compose = OH_Drawing_ColorFilterCreateCompose(nullptr, nullptr);
486     EXPECT_EQ(compose, nullptr);
487     compose = OH_Drawing_ColorFilterCreateCompose(outerFilter, innerFilter);
488     EXPECT_NE(compose, nullptr);
489     OH_Drawing_Filter* filter = OH_Drawing_FilterCreate();
490     OH_Drawing_FilterSetColorFilter(filter, compose);
491     OH_Drawing_BrushSetFilter(brush_, filter);
492     OH_Drawing_Canvas* canvas_ = OH_Drawing_CanvasCreate();
493     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(200, 500, 300, 600);
494     OH_Drawing_CanvasDrawRect(canvas_, rect);
495     OH_Drawing_RectDestroy(rect);
496     OH_Drawing_ColorFilterDestroy(outerFilter);
497     OH_Drawing_ColorFilterDestroy(innerFilter);
498     OH_Drawing_ColorFilterDestroy(compose);
499     OH_Drawing_FilterDestroy(filter);
500 }
501 
502 /*
503  * @tc.name: NativeDrawingCanvasTest_DrawBitmap
504  * @tc.desc: test for DrawBitmap
505  * @tc.type: FUNC
506  * @tc.require: AR000GTO5R
507  */
508 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_DrawBitmap, TestSize.Level1)
509 {
510     OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate();
511     OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
512     constexpr uint32_t width = 200;
513     constexpr uint32_t height = 200;
514     OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat);
515     OH_Drawing_CanvasBind(canvas_, bitmap);
516     OH_Drawing_CanvasDrawBitmap(canvas_, bitmap, 0, 0);
517     OH_Drawing_CanvasClear(canvas_, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
518     OH_Drawing_BitmapDestroy(bitmap);
519 }
520 
521 /*
522  * @tc.name: NativeDrawingCanvasTest_DrawTextBlob
523  * @tc.desc: test for DrawTextBlob
524  * @tc.type: FUNC
525  * @tc.require: AR000GTO5R
526  */
527 HWTEST_F(NativeDrawingCanvasTest, NativeDrawingCanvasTest_DrawTextBlob, TestSize.Level1)
528 {
529     OH_Drawing_Font *font = OH_Drawing_FontCreate();
530     OH_Drawing_FontSetFakeBoldText(font, true);
531     OH_Drawing_FontSetTextSize(font, 20);
532     OH_Drawing_FontSetTextSkewX(font, 0.25);
533     OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
534     OH_Drawing_FontSetTypeface(font, typeSurface);
535     auto *builder = OH_Drawing_TextBlobBuilderCreate();
536     EXPECT_EQ(nullptr, OH_Drawing_TextBlobBuilderAllocRunPos(nullptr, nullptr, INT32_MAX, nullptr));
537     EXPECT_EQ(nullptr, OH_Drawing_TextBlobBuilderAllocRunPos(builder, font, INT32_MIN, nullptr));
538     const OH_Drawing_RunBuffer* runBuffer = OH_Drawing_TextBlobBuilderAllocRunPos(builder, font, 9, nullptr);
539     ASSERT_NE(runBuffer, nullptr);
540     runBuffer->glyphs[0] = 65;
541     runBuffer->pos[0] = 0;
542     runBuffer->pos[1] = 0;
543     runBuffer->glyphs[1] = 227;
544     runBuffer->pos[2] = 14.9;
545     runBuffer->pos[3] = 0;
546     runBuffer->glyphs[2] = 283;
547     runBuffer->pos[4] = 25.84;
548     runBuffer->pos[5] = 0;
549     runBuffer->glyphs[3] = 283;
550     runBuffer->pos[6] = 30.62;
551     runBuffer->pos[7] = 0;
552     runBuffer->glyphs[4] = 299;
553     runBuffer->pos[8] = 35.4;
554     runBuffer->pos[9] = 0;
555     runBuffer->glyphs[5] = 2;
556     runBuffer->pos[10] = 47.22;
557     runBuffer->pos[11] = 0;
558     runBuffer->glyphs[6]= 94;
559     runBuffer->pos[12] = 52.62;
560     runBuffer->pos[13] = 0;
561     runBuffer->glyphs[7] = 37;
562     runBuffer->pos[14] = 67.42;
563     runBuffer->pos[15] = 0;
564     runBuffer->glyphs[8] = 84;
565     runBuffer->pos[16] = 81.7;
566     runBuffer->pos[17] = 0;
567     OH_Drawing_TextBlob *textBlob = OH_Drawing_TextBlobBuilderMake(builder);
568     OH_Drawing_CanvasDrawTextBlob(canvas_, textBlob, 100, 700);
569     OH_Drawing_TextBlobDestroy(textBlob);
570     OH_Drawing_TextBlobBuilderDestroy(builder);
571     OH_Drawing_FontDestroy(font);
572     OH_Drawing_TypefaceDestroy(typeSurface);
573     OH_Drawing_TextBlobDestroy(nullptr);
574     OH_Drawing_TextBlobBuilderDestroy(nullptr);
575     OH_Drawing_FontDestroy(nullptr);
576     OH_Drawing_TypefaceDestroy(nullptr);
577 }
578 
579 /*
580  * @tc.name: NativeDrawingTest001
581  * @tc.desc: test for fontSetLinearText
582  * @tc.type: FUNC
583  */
584 HWTEST_F(NativeDrawingCanvasTest, OH_Drawing_FontSetLinearText_001, TestSize.Level1)
585 {
586     OH_Drawing_Font *font = OH_Drawing_FontCreate();
587     OH_Drawing_FontSetTextSize(font, 20);
588     OH_Drawing_FontSetTextSkewX(font, 0.25);
589     OH_Drawing_FontSetLinearText(font, true);
590     OH_Drawing_FontDestroy(font);
591 }
592 
593 /*
594  * @tc.name: NativeDrawingTest002
595  * @tc.desc: test for penSetFilter
596  * @tc.type: FUNC
597  */
598 HWTEST_F(NativeDrawingCanvasTest, OH_Drawing_PenSetFilter_001, TestSize.Level1)
599 {
600     OH_Drawing_Canvas* canvas = OH_Drawing_CanvasCreate();
601     EXPECT_EQ(canvas == nullptr, false);
602     OH_Drawing_ColorFilter* colorFilter = OH_Drawing_ColorFilterCreateBlendMode(0xff0000ff,
603         OH_Drawing_BlendMode::BLEND_MODE_SRC);
604     OH_Drawing_Filter* filter = OH_Drawing_FilterCreate();
605     OH_Drawing_FilterSetColorFilter(filter, colorFilter);
606     OH_Drawing_Pen* pen = OH_Drawing_PenCreate();
607     OH_Drawing_PenSetColor(pen, 0xff00ff00);
608     OH_Drawing_PenSetFilter(pen, filter);
609     OH_Drawing_CanvasAttachPen(canvas, pen);
610     OH_Drawing_Rect* rect = OH_Drawing_RectCreate(100, 400, 200, 500);
611     OH_Drawing_CanvasDrawRect(canvas, rect);
612     OH_Drawing_RectDestroy(rect);
613     OH_Drawing_PenDestroy(pen);
614     OH_Drawing_ColorFilterDestroy(colorFilter);
615     OH_Drawing_FilterDestroy(filter);
616     OH_Drawing_CanvasDestroy(canvas);
617 }
618 
619 /*
620  * @tc.name: NativeDrawingTest003
621  * @tc.desc: test for penSetFilter
622  * @tc.type: FUNC
623  */
624 HWTEST_F(NativeDrawingCanvasTest, OH_Drawing_PenSetshaderEffect, TestSize.Level1)
625 {
626     OH_Drawing_Canvas* canvas = OH_Drawing_CanvasCreate();
627     EXPECT_EQ(canvas == nullptr, false);
628     OH_Drawing_Point* startPt = OH_Drawing_PointCreate(100, 400);
629     OH_Drawing_Point* endPt = OH_Drawing_PointCreate(200, 500);
630     uint32_t color[] = {0xffff0000, 0xff00ff00};
631     float pos[] = {0., 1.0};
632     OH_Drawing_ShaderEffect* linearGradient = OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt,
633         color, pos, 2, OH_Drawing_TileMode::CLAMP);
634     OH_Drawing_Pen* pen = OH_Drawing_PenCreate();
635     OH_Drawing_PenSetShaderEffect(pen, linearGradient);
636     OH_Drawing_CanvasAttachPen(canvas, pen);
637     OH_Drawing_Rect* rect = OH_Drawing_RectCreate(100, 400, 200, 500);
638     OH_Drawing_CanvasDrawRect(canvas, rect);
639     OH_Drawing_RectDestroy(rect);
640     OH_Drawing_PenDestroy(pen);
641     OH_Drawing_ShaderEffectDestroy(linearGradient);
642     OH_Drawing_PointDestroy(startPt);
643     OH_Drawing_PointDestroy(endPt);
644     OH_Drawing_CanvasDestroy(canvas);
645 }
646 } // namespace Drawing
647 } // namespace Rosen
648 } // namespace OHOS