• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <string>
17 
18 #include "gtest/gtest.h"
19 
20 #define private public
21 #define protected public
22 
23 #include "include/core/SkStream.h"
24 #include "test/mock/core/common/mock_container.h"
25 #include "test/mock/core/rosen/mock_canvas.h"
26 
27 #include "base/memory/ace_type.h"
28 #include "core/components/common/layout/constants.h"
29 #include "core/components/common/properties/color.h"
30 #include "core/components/declaration/svg/svg_animate_declaration.h"
31 #include "core/components/declaration/svg/svg_circle_declaration.h"
32 #include "core/components/declaration/svg/svg_declaration.h"
33 #include "core/components/declaration/svg/svg_ellipse_declaration.h"
34 #include "core/components/declaration/svg/svg_fe_blend_declaration.h"
35 #include "core/components/declaration/svg/svg_fe_colormatrix_declaration.h"
36 #include "core/components/declaration/svg/svg_fe_composite_declaration.h"
37 #include "core/components/declaration/svg/svg_fe_declaration.h"
38 #include "core/components/declaration/svg/svg_fe_flood_declaration.h"
39 #include "core/components/declaration/svg/svg_fe_gaussianblur_declaration.h"
40 #include "core/components/declaration/svg/svg_filter_declaration.h"
41 #include "core/components/declaration/svg/svg_gradient_declaration.h"
42 #include "core/components/declaration/svg/svg_image_declaration.h"
43 #include "core/components/declaration/svg/svg_line_declaration.h"
44 #include "core/components/declaration/svg/svg_mask_declaration.h"
45 #include "core/components/declaration/svg/svg_path_declaration.h"
46 #include "core/components/declaration/svg/svg_pattern_declaration.h"
47 #include "core/components/declaration/svg/svg_polygon_declaration.h"
48 #include "core/components/declaration/svg/svg_rect_declaration.h"
49 #include "core/components/declaration/svg/svg_stop_declaration.h"
50 #include "core/components_ng/render/drawing.h"
51 #include "core/components_ng/svg/parse/svg_animation.h"
52 #include "core/components_ng/svg/parse/svg_circle.h"
53 #include "core/components_ng/svg/parse/svg_clip_path.h"
54 #include "core/components_ng/svg/parse/svg_defs.h"
55 #include "core/components_ng/svg/parse/svg_ellipse.h"
56 #include "core/components_ng/svg/parse/svg_fe_blend.h"
57 #include "core/components_ng/svg/parse/svg_fe_color_matrix.h"
58 #include "core/components_ng/svg/parse/svg_fe_composite.h"
59 #include "core/components_ng/svg/parse/svg_fe_flood.h"
60 #include "core/components_ng/svg/parse/svg_fe_gaussian_blur.h"
61 #include "core/components_ng/svg/parse/svg_fe_offset.h"
62 #include "core/components_ng/svg/parse/svg_filter.h"
63 #include "core/components_ng/svg/parse/svg_g.h"
64 #include "core/components_ng/svg/parse/svg_gradient.h"
65 #include "core/components_ng/svg/parse/svg_image.h"
66 #include "core/components_ng/svg/parse/svg_line.h"
67 #include "core/components_ng/svg/parse/svg_mask.h"
68 #include "core/components_ng/svg/parse/svg_path.h"
69 #include "core/components_ng/svg/parse/svg_pattern.h"
70 #include "core/components_ng/svg/parse/svg_polygon.h"
71 #include "core/components_ng/svg/parse/svg_rect.h"
72 #include "core/components_ng/svg/parse/svg_stop.h"
73 #include "core/components_ng/svg/parse/svg_style.h"
74 #include "core/components_ng/svg/parse/svg_svg.h"
75 #include "core/components_ng/svg/parse/svg_transform.h"
76 #include "core/components_ng/svg/parse/svg_use.h"
77 #include "core/components_ng/svg/svg_dom.h"
78 
79 using namespace testing;
80 using namespace testing::ext;
81 
82 namespace OHOS::Ace::NG {
83 namespace {
84 
85 const std::string TRANSFORM_RECT_SVG_LABEL =
86     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
87     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
88     "stroke-width=\"1\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"rotate(34.56)\" "
89     "transform-origin=\"123.45px 99.99%\"/></svg>";
90 
91 const std::string TRANSFORM_SCALE_SVG_LABEL =
92     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
93     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
94     "stroke-width=\"1\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"scale(0.8, 0.8)\" "
95     "transform-origin=\"123.45px 99.99%\"/></svg>";
96 
97 const std::string ERROR_SVG =
98     "2224676..m,n<1111svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
99     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
100     "stroke-width=\"1\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"scale(0.8, 0.8)\" "
101     "transform-origin=\"123.45px 99.99%\"/></svg>"
102     "transform-origin=\"123.45px 99.99%\"/></svg22233tt766gfhgh////000";
103 
104 const std::string TRANSFORM_SKEW_SVG_LABEL =
105     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
106     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
107     "stroke-width=\"1\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"skewX(34.56) skewY(98.76)\" "
108     "transform-origin=\"123.45px 99.99%\"/></svg>";
109 
110 const std::string TRANSFORM_TRANSLATE_SVG_LABEL =
111     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
112     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
113     "stroke-width=\"1\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"translate(34.56)\" "
114     "transform-origin=\"123.45px 99.99%\"/></svg>";
115 
116 const std::string TRANSFORM_MATRIX_SVG_LABEL =
117     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
118     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
119     "stroke-width=\"1\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"matrix(1,0,0.577,1,0,0)\" "
120     "transform-origin=\"123.45px 99.99%\"/></svg>";
121 
122 const std::string TRANSFORM_INVALID_EMPTY_SVG_LABEL =
123     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
124     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
125     "stroke-width=\"16px\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"rotate()\" "
126     "transform-origin=\"123.45px 99.99%\"/></svg>";
127 
128 const std::string TRANSFORM_INVALID_PARA_SVG_LABEL =
129     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
130     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
131     "stroke-width=\"16px\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"rotate(abc)\" "
132     "transform-origin=\"123.45px 99.99%\"/></svg>";
133 
134 const std::string TRANSFORM_ORIGIN_INVALID_PARA_SVG_LABEL =
135     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
136     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
137     "stroke-width=\"16px\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"rotate(34.56)\" "
138     "transform-origin=\"abcd\"/></svg>";
139 
140 const std::string TRANSFORM_ORIGIN_INVALID_EMPTY_SVG_LABEL =
141     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
142     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
143     "stroke-width=\"16px\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"rotate(34.56)\" "
144     "transform-origin=\"\"/></svg>";
145 
146 const std::string TRANSFORM_ORIGIN_INVALID_SPACE_SVG_LABEL =
147     "<svg width=\"400px\" height=\"400px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"
148     "<rect x=\"60px\" y=\"200px\" width=\"50px\" height=\"50px\" fill=\"red\" opacity=\"0.5\" stroke=\"blue\" "
149     "stroke-width=\"16px\" stroke-opacity=\"0.3\" id=\"circleId\" transform=\"rotate(34.56)\" "
150     "transform-origin=\"   \"/></svg>";
151 
152 constexpr float IMAGE_COMPONENT_WIDTH = 100.0f;
153 constexpr float IMAGE_COMPONENT_HEIGHT = 100.0f;
154 } // namespace
155 
156 class SvgTransformTestNg : public testing::Test {
157 public:
158     void CallBack(Testing::MockCanvas& rSCanvas);
SetUpTestSuite()159     static void SetUpTestSuite()
160     {
161         MockContainer::SetUp();
162     }
TearDownTestSuite()163     static void TearDownTestSuite()
164     {
165         MockContainer::TearDown();
166     }
167 };
168 
CallBack(Testing::MockCanvas & rSCanvas)169 void SvgTransformTestNg::CallBack(Testing::MockCanvas& rSCanvas)
170 {
171     EXPECT_CALL(rSCanvas, AttachBrush(_)).WillRepeatedly(ReturnRef(rSCanvas));
172     EXPECT_CALL(rSCanvas, DetachBrush()).WillRepeatedly(ReturnRef(rSCanvas));
173     EXPECT_CALL(rSCanvas, AttachPen(_)).WillRepeatedly(ReturnRef(rSCanvas));
174     EXPECT_CALL(rSCanvas, DetachPen()).WillRepeatedly(ReturnRef(rSCanvas));
175     EXPECT_CALL(rSCanvas, DrawPath(_)).Times(AtLeast(1));
176 }
177 
178 /**
179  * @tc.name: ParseTransformTestRect
180  * @tc.desc: parse transform-origin label
181  * @tc.type: FUNC
182  */
183 HWTEST_F(SvgTransformTestNg, ParseTransformTestRect, TestSize.Level1)
184 {
185     auto svgStream = SkMemoryStream::MakeCopy(TRANSFORM_RECT_SVG_LABEL.c_str(), TRANSFORM_RECT_SVG_LABEL.length());
186     EXPECT_NE(svgStream, nullptr);
187     ImageSourceInfo src;
188     src.SetFillColor(Color::BLACK);
189     Testing::MockCanvas rSCanvas;
190     CallBack(rSCanvas);
191     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
192     EXPECT_NE(svgDom, nullptr);
193     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
194 
195     /* *
196      * @tc.steps: step1. get shape from svg.
197      * @tc.expected: shape is Effective.
198      */
199     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
200     EXPECT_NE(svgRect, nullptr);
201     svgDom->root_->SetSmoothEdge(1);
202     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
203 
204     /* *
205      * @tc.steps: step2. get transform function vector from the shape.
206      * @tc.expected: transform function vector value is equal to svg source.
207      */
208     auto attributes = svgRect->attributes_;
209     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
210     NG::TransformInfo element;
211     element = attributes.transformVec[0];
212     EXPECT_EQ(element.funcType, "rotate");
213     EXPECT_EQ(element.paramVec[0], "34.56");
214 }
215 
216 /**
217  * @tc.name: ParseTransformTestScale
218  * @tc.desc: parse transform-origin label
219  * @tc.type: FUNC
220  */
221 HWTEST_F(SvgTransformTestNg, ParseTransformTestScale, TestSize.Level1)
222 {
223     auto svgStream = SkMemoryStream::MakeCopy(TRANSFORM_SCALE_SVG_LABEL.c_str(), TRANSFORM_SCALE_SVG_LABEL.length());
224     EXPECT_NE(svgStream, nullptr);
225     ImageSourceInfo src;
226     src.SetFillColor(Color::BLACK);
227     Testing::MockCanvas rSCanvas;
228     CallBack(rSCanvas);
229     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
230     EXPECT_NE(svgDom, nullptr);
231     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
232 
233     /* *
234      * @tc.steps: step1. get shape from svg.
235      * @tc.expected: shape is Effective.
236      */
237     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
238     EXPECT_NE(svgRect, nullptr);
239     svgDom->root_->SetSmoothEdge(1);
240     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
241 
242     /* *
243      * @tc.steps: step2. get transform function vector from the shape.
244      * @tc.expected: transform function vector value is equal to svg source.
245      */
246     auto attributes = svgRect->attributes_;
247     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
248     NG::TransformInfo element;
249     element = attributes.transformVec[0];
250     EXPECT_EQ(element.funcType, "scale");
251     EXPECT_EQ(element.paramVec[0], "0.8");
252     EXPECT_EQ(element.paramVec[1], "0.8");
253 }
254 
255 /**
256  * @tc.name: ParseTransformTestSkew
257  * @tc.desc: parse transform-origin label
258  * @tc.type: FUNC
259  */
260 HWTEST_F(SvgTransformTestNg, ParseTransformTestSkew, TestSize.Level1)
261 {
262     auto svgStream = SkMemoryStream::MakeCopy(TRANSFORM_SKEW_SVG_LABEL.c_str(), TRANSFORM_SKEW_SVG_LABEL.length());
263     EXPECT_NE(svgStream, nullptr);
264     ImageSourceInfo src;
265     src.SetFillColor(Color::BLACK);
266     Testing::MockCanvas rSCanvas;
267     CallBack(rSCanvas);
268     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
269     EXPECT_NE(svgDom, nullptr);
270     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
271 
272     /* *
273      * @tc.steps: step1. get shape from svg.
274      * @tc.expected: shape is Effective.
275      */
276     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
277     EXPECT_NE(svgRect, nullptr);
278     svgDom->root_->SetSmoothEdge(1);
279     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
280 
281     /* *
282      * @tc.steps: step2. get transform function vector from the shape.
283      * @tc.expected: transform function vector value is equal to svg source.
284      */
285     auto attributes = svgRect->attributes_;
286     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
287     NG::TransformInfo element;
288     element = attributes.transformVec[0];
289     EXPECT_EQ(element.funcType, "skewX");
290     EXPECT_EQ(element.paramVec[0], "34.56");
291 
292     NG::TransformInfo element2;
293     element2 = attributes.transformVec[1];
294     EXPECT_EQ(element2.funcType, "skewY");
295     EXPECT_EQ(element2.paramVec[0], "98.76");
296 }
297 
298 /**
299  * @tc.name: ParseTransformTestTranslate
300  * @tc.desc: parse transform-origin label
301  * @tc.type: FUNC
302  */
303 HWTEST_F(SvgTransformTestNg, ParseTransformTestTranslate, TestSize.Level1)
304 {
305     auto svgStream =
306         SkMemoryStream::MakeCopy(TRANSFORM_TRANSLATE_SVG_LABEL.c_str(), TRANSFORM_TRANSLATE_SVG_LABEL.length());
307     EXPECT_NE(svgStream, nullptr);
308     ImageSourceInfo src;
309     src.SetFillColor(Color::BLACK);
310     Testing::MockCanvas rSCanvas;
311     CallBack(rSCanvas);
312     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
313     EXPECT_NE(svgDom, nullptr);
314     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
315 
316     /* *
317      * @tc.steps: step1. get shape from svg.
318      * @tc.expected: shape is Effective.
319      */
320     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
321     EXPECT_NE(svgRect, nullptr);
322     svgDom->root_->SetSmoothEdge(1);
323     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
324 
325     /* *
326      * @tc.steps: step2. get transform function vector from the shape.
327      * @tc.expected: transform function vector value is equal to svg source.
328      */
329     auto attributes = svgRect->attributes_;
330     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
331     NG::TransformInfo element;
332     element = attributes.transformVec[0];
333     EXPECT_EQ(element.funcType, "translate");
334     EXPECT_EQ(element.paramVec[0], "34.56");
335 }
336 
337 /**
338  * @tc.name: ParseTransformTestMatrix
339  * @tc.desc: parse transform-origin label
340  * @tc.type: FUNC
341  */
342 HWTEST_F(SvgTransformTestNg, ParseTransformTestMatrix, TestSize.Level1)
343 {
344     auto svgStream = SkMemoryStream::MakeCopy(TRANSFORM_MATRIX_SVG_LABEL.c_str(), TRANSFORM_MATRIX_SVG_LABEL.length());
345     EXPECT_NE(svgStream, nullptr);
346     ImageSourceInfo src;
347     src.SetFillColor(Color::BLACK);
348     Testing::MockCanvas rSCanvas;
349     CallBack(rSCanvas);
350     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
351     EXPECT_NE(svgDom, nullptr);
352     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
353 
354     /* *
355      * @tc.steps: step1. get shape from svg.
356      * @tc.expected: shape is Effective.
357      */
358     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
359     EXPECT_NE(svgRect, nullptr);
360     svgDom->root_->SetSmoothEdge(1);
361     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
362 
363     /* *
364      * @tc.steps: step2. get transform function vector from the shape.
365      * @tc.expected: transform function vector value is equal to svg source.
366      */
367     auto attributes = svgRect->attributes_;
368     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
369     NG::TransformInfo element;
370     element = attributes.transformVec[0];
371     EXPECT_EQ(element.funcType, "matrix");
372     EXPECT_EQ(element.paramVec[0], "1");
373     EXPECT_EQ(element.paramVec[1], "0");
374     EXPECT_EQ(element.paramVec[2], "0.577");
375     EXPECT_EQ(element.paramVec[3], "1");
376     EXPECT_EQ(element.paramVec[4], "0");
377     EXPECT_EQ(element.paramVec[5], "0");
378 }
379 
380 /**
381  * @tc.name: ParseTransformInvalidTest001
382  * @tc.desc: parse transform-origin label
383  * @tc.type: FUNC
384  */
385 HWTEST_F(SvgTransformTestNg, ParseTransformInvalidTest001, TestSize.Level1)
386 {
387     auto svgStream =
388         SkMemoryStream::MakeCopy(TRANSFORM_INVALID_EMPTY_SVG_LABEL.c_str(), TRANSFORM_INVALID_EMPTY_SVG_LABEL.length());
389     EXPECT_NE(svgStream, nullptr);
390     ImageSourceInfo src;
391     src.SetFillColor(Color::BLACK);
392     Testing::MockCanvas rSCanvas;
393     CallBack(rSCanvas);
394     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
395     EXPECT_NE(svgDom, nullptr);
396     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
397 
398     /* *
399      * @tc.steps: step1. get shape from svg.
400      * @tc.expected: shape is Effective.
401      */
402     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
403     EXPECT_NE(svgRect, nullptr);
404     svgDom->root_->SetSmoothEdge(1);
405     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
406 
407     /* *
408      * @tc.steps: step2. get transform function vector from the shape.
409      * @tc.expected: transform function vector value is equal to svg source.
410      */
411     auto attributes = svgRect->attributes_;
412     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
413     EXPECT_EQ(0, attributes.transformVec.size());
414 }
415 
416 /**
417  * @tc.name: ParseTransformInvalidTest002
418  * @tc.desc: parse transform-origin label
419  * @tc.type: FUNC
420  */
421 HWTEST_F(SvgTransformTestNg, ParseTransformInvalidTest002, TestSize.Level1)
422 {
423     auto svgStream =
424         SkMemoryStream::MakeCopy(TRANSFORM_INVALID_PARA_SVG_LABEL.c_str(), TRANSFORM_INVALID_PARA_SVG_LABEL.length());
425     EXPECT_NE(svgStream, nullptr);
426     ImageSourceInfo src;
427     src.SetFillColor(Color::BLACK);
428     Testing::MockCanvas rSCanvas;
429     CallBack(rSCanvas);
430     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
431     EXPECT_NE(svgDom, nullptr);
432     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
433 
434     /* *
435      * @tc.steps: step1. get shape from svg.
436      * @tc.expected: shape is Effective.
437      */
438     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
439     EXPECT_NE(svgRect, nullptr);
440     svgDom->root_->SetSmoothEdge(1);
441     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
442 
443     /* *
444      * @tc.steps: step2. get transform function vector from the shape.
445      * @tc.expected: transform function vector value is equal to svg source.
446      */
447     auto attributes = svgRect->attributes_;
448     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
449     EXPECT_EQ(0, attributes.transformVec.size());
450 }
451 
452 /**
453  * @tc.name: ParseTransformOriginTest001
454  * @tc.desc: parse transform-origin label
455  * @tc.type: FUNC
456  */
457 HWTEST_F(SvgTransformTestNg, ParseTransformOriginTest001, TestSize.Level1)
458 {
459     auto svgStream = SkMemoryStream::MakeCopy(TRANSFORM_RECT_SVG_LABEL.c_str(), TRANSFORM_RECT_SVG_LABEL.length());
460     EXPECT_NE(svgStream, nullptr);
461     ImageSourceInfo src;
462     src.SetFillColor(Color::BLACK);
463     Testing::MockCanvas rSCanvas;
464     CallBack(rSCanvas);
465     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
466     EXPECT_NE(svgDom, nullptr);
467     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
468 
469     /* *
470      * @tc.steps: step1. get shape from svg.
471      * @tc.expected: shape is Effective.
472      */
473     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
474     EXPECT_NE(svgRect, nullptr);
475     svgDom->root_->SetSmoothEdge(1);
476     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
477 
478     /* *
479      * @tc.steps: step2. get transform-origin value from the shape.
480      * @tc.expected: transform-origin value is equal to svg source.
481      */
482     auto attributes = svgRect->attributes_;
483     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
484 
485     EXPECT_EQ(Dimension(123.45_px), attributes.transformOrigin.first);
486     EXPECT_EQ(Dimension(0.9999_pct), attributes.transformOrigin.second);
487 }
488 
489 /**
490  * @tc.name: ParseTransformOriginInvalidTest001
491  * @tc.desc: parse transform-origin label
492  * @tc.type: FUNC
493  */
494 HWTEST_F(SvgTransformTestNg, ParseTransformOriginInvalidTest001, TestSize.Level1)
495 {
496     auto svgStream = SkMemoryStream::MakeCopy(
497         TRANSFORM_ORIGIN_INVALID_PARA_SVG_LABEL.c_str(), TRANSFORM_ORIGIN_INVALID_PARA_SVG_LABEL.length());
498     EXPECT_NE(svgStream, nullptr);
499     ImageSourceInfo src;
500     src.SetFillColor(Color::BLACK);
501     Testing::MockCanvas rSCanvas;
502     CallBack(rSCanvas);
503     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
504     EXPECT_NE(svgDom, nullptr);
505     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
506 
507     /* *
508      * @tc.steps: step1. get shape from svg.
509      * @tc.expected: shape is Effective.
510      */
511     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
512     EXPECT_NE(svgRect, nullptr);
513     svgDom->root_->SetSmoothEdge(1);
514     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
515 
516     /* *
517      * @tc.steps: step2. get transform-origin value from the shape.
518      * @tc.expected: transform-origin value is equal to svg source.
519      */
520     auto attributes = svgRect->attributes_;
521     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
522     EXPECT_EQ(Dimension(0.0f), attributes.transformOrigin.first);
523     EXPECT_EQ(Dimension(0.0_px), attributes.transformOrigin.second);
524 }
525 
526 /**
527  * @tc.name: ParseTransformOriginInvalidTest002
528  * @tc.desc: parse transform-origin label
529  * @tc.type: FUNC
530  */
531 HWTEST_F(SvgTransformTestNg, ParseTransformOriginInvalidTest002, TestSize.Level1)
532 {
533     auto svgStream = SkMemoryStream::MakeCopy(
534         TRANSFORM_ORIGIN_INVALID_EMPTY_SVG_LABEL.c_str(), TRANSFORM_ORIGIN_INVALID_EMPTY_SVG_LABEL.length());
535     EXPECT_NE(svgStream, nullptr);
536     ImageSourceInfo src;
537     src.SetFillColor(Color::BLACK);
538     Testing::MockCanvas rSCanvas;
539     CallBack(rSCanvas);
540     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
541     EXPECT_NE(svgDom, nullptr);
542     auto svg = AceType::DynamicCast<SvgSvg>(svgDom->root_);
543 
544     /* *
545      * @tc.steps: step1. get shape from svg.
546      * @tc.expected: shape is Effective.
547      */
548     auto svgRect = AceType::DynamicCast<SvgRect>(svg->children_.at(0));
549     EXPECT_NE(svgRect, nullptr);
550     svgDom->root_->SetSmoothEdge(1);
551     svgDom->root_->Draw(rSCanvas, Size(IMAGE_COMPONENT_WIDTH, IMAGE_COMPONENT_HEIGHT), Color::BLACK);
552 
553     /* *
554      * @tc.steps: step2. get transform-origin value from the shape.
555      * @tc.expected: transform-origin value is equal to svg source.
556      */
557     auto attributes = svgRect->attributes_;
558     std::vector<NG::TransformInfo> transformVec = attributes.transformVec;
559     EXPECT_EQ(Dimension(0.0f), attributes.transformOrigin.first);
560     EXPECT_EQ(Dimension(0.0_px), attributes.transformOrigin.second);
561 }
562 
563 /**
564  * @tc.name: ObjectBoundingBoxTransformTest001
565  * @tc.desc: ObjectBoundingBoxTransform test
566  * @tc.type: FUNC
567  */
568 HWTEST_F(SvgTransformTestNg, ObjectBoundingBoxTransformTest001, TestSize.Level1)
569 {
570     auto svgNode = AccessibilityManager::MakeRefPtr<SvgNode>();
571     Rect containerRect(0, 0, 2, 2);
572     Size viewPort(2, 2);
573     SvgCoordinateSystemContext context(containerRect, viewPort);
574     auto rule = svgNode->BuildContentScaleRule(context, OHOS::Ace::NG::SvgLengthScaleUnit::OBJECT_BOUNDING_BOX);
575     EXPECT_EQ(rule.GetLengthScaleUnit(), OHOS::Ace::NG::SvgLengthScaleUnit::OBJECT_BOUNDING_BOX);
576     SvgLengthType svgLengthType = SvgLengthType::HORIZONTAL;
577     double srcLength = 1.0;
578     auto dstLength = NGSvgTransform::ObjectBoundingBoxTransform(srcLength, rule, svgLengthType);
579     EXPECT_FLOAT_EQ(dstLength, 2.0);
580     svgLengthType = SvgLengthType::VERTICAL;
581     dstLength = NGSvgTransform::ObjectBoundingBoxTransform(srcLength, rule, svgLengthType);
582     EXPECT_FLOAT_EQ(dstLength, 2.0);
583     svgLengthType = SvgLengthType::OTHER;
584     dstLength = NGSvgTransform::ObjectBoundingBoxTransform(srcLength, rule, svgLengthType);
585     EXPECT_FLOAT_EQ(dstLength, 0.0);
586 }
587 
588 /**
589  * @tc.name: ObjectBoundingBoxTransformTest002
590  * @tc.desc: ObjectBoundingBoxTransform test
591  * @tc.type: FUNC
592  */
593 HWTEST_F(SvgTransformTestNg, ObjectBoundingBoxTransformTest002, TestSize.Level1)
594 {
595     auto svgNode = AccessibilityManager::MakeRefPtr<SvgNode>();
596     Rect containerRect(0, 0, 2, 2);
597     Size viewPort(2, 2);
598     SvgCoordinateSystemContext context(containerRect, viewPort);
599     auto rule = svgNode->BuildContentScaleRule(context, OHOS::Ace::NG::SvgLengthScaleUnit::USER_SPACE_ON_USE);
600     EXPECT_EQ(rule.GetLengthScaleUnit(), OHOS::Ace::NG::SvgLengthScaleUnit::USER_SPACE_ON_USE);
601     SvgLengthType svgLengthType = SvgLengthType::HORIZONTAL;
602     double srcLength = 1.0;
603     auto dstLength = NGSvgTransform::ObjectBoundingBoxTransform(srcLength, rule, svgLengthType);
604     EXPECT_FLOAT_EQ(dstLength, 1.0);
605     svgLengthType = SvgLengthType::VERTICAL;
606     dstLength = NGSvgTransform::ObjectBoundingBoxTransform(srcLength, rule, svgLengthType);
607     EXPECT_FLOAT_EQ(dstLength, 1.0);
608     svgLengthType = SvgLengthType::OTHER;
609     dstLength = NGSvgTransform::ObjectBoundingBoxTransform(srcLength, rule, svgLengthType);
610     EXPECT_FLOAT_EQ(dstLength, 0.0);
611 }
612 
613 /**
614  * @tc.name: ApplyTransformTest001
615  * @tc.desc: ApplyTransform paramVec empty test
616  * @tc.type: FUNC
617  */
618 HWTEST_F(SvgTransformTestNg, ApplyTransformTest001, TestSize.Level1)
619 {
620     auto svgNode = AccessibilityManager::MakeRefPtr<SvgNode>();
621     Rect containerRect(0, 0, 1, 1);
622     Size viewPort(1, 1);
623     SvgCoordinateSystemContext context(containerRect, viewPort);
624     auto rule = svgNode->BuildContentScaleRule(context, OHOS::Ace::NG::SvgLengthScaleUnit::USER_SPACE_ON_USE);
625     EXPECT_EQ(rule.GetLengthScaleUnit(), OHOS::Ace::NG::SvgLengthScaleUnit::USER_SPACE_ON_USE);
626     Testing::TestingPath rSPath;
627     svgNode->ApplyTransform(rSPath, rule);
628 }
629 
630 /**
631  * @tc.name: ApplyTransformTest002
632  * @tc.desc: ApplyTransform test
633  * @tc.type: FUNC
634  */
635 HWTEST_F(SvgTransformTestNg, ApplyTransformTest002, TestSize.Level1)
636 {
637     auto svgNode = AccessibilityManager::MakeRefPtr<SvgNode>();
638     Rect containerRect(0, 0, 1, 1);
639     Size viewPort(1, 1);
640     SvgCoordinateSystemContext context(containerRect, viewPort);
641     auto rule = svgNode->BuildContentScaleRule(context, OHOS::Ace::NG::SvgLengthScaleUnit::USER_SPACE_ON_USE);
642     EXPECT_EQ(rule.GetLengthScaleUnit(), OHOS::Ace::NG::SvgLengthScaleUnit::USER_SPACE_ON_USE);
643     Testing::TestingPath rSPath;
644     std::vector<std::string> paramVec;
645     paramVec.push_back("100");
646     NG::TransformInfo transformInfo { "translate", paramVec };
647     svgNode->attributes_.transformVec.push_back(transformInfo);
648     svgNode->ApplyTransform(rSPath, rule);
649 }
650 
651 /**
652  * @tc.name: ParseTransformOriginInvalidTest002
653  * @tc.desc: parse transform-origin label
654  * @tc.type: FUNC
655  */
656 HWTEST_F(SvgTransformTestNg, SvgFeOffsetTest001, TestSize.Level1)
657 {
658     auto feOffset = AceType::DynamicCast<SvgFeOffset>(SvgFeOffset::Create());
659     EXPECT_NE(feOffset, nullptr);
660     std::unordered_map<std::string, std::shared_ptr<RSImageFilter>> resultHash;
661     std::shared_ptr<RSImageFilter> imageFilter = nullptr;
662     SvgColorInterpolationType srcColor = SvgColorInterpolationType::SRGB;
663     SvgColorInterpolationType currentColor = SvgColorInterpolationType::LINEAR_RGB;
664     feOffset->filterContext_.primitiveRule_.lengthScaleUnit_ = SvgLengthScaleUnit::OBJECT_BOUNDING_BOX;
665     feOffset->OnAsImageFilter(imageFilter, srcColor, currentColor, resultHash, true);
666 
667     feOffset->filterContext_.primitiveRule_.lengthScaleUnit_ = SvgLengthScaleUnit::USER_SPACE_ON_USE;
668     feOffset->OnAsImageFilter(imageFilter, srcColor, currentColor, resultHash, true);
669     EXPECT_NE(imageFilter, nullptr);
670 }
671 
672 /**
673  * @tc.name: animationTest
674  * @tc.desc: Verify the property animation process for type double
675  * @tc.type: FUNC
676  */
677 HWTEST_F(SvgTransformTestNg, SvgFeOffsetTest002, TestSize.Level1)
678 {
679     auto svgFeOffset = AceType::DynamicCast<SvgFeOffset>(SvgFeOffset::Create());
680     EXPECT_NE(svgFeOffset, nullptr);
681 
682     std::shared_ptr<RSImageFilter> imageFilter = nullptr;
683     SvgColorInterpolationType type = SvgColorInterpolationType::SRGB;
684     SvgColorInterpolationType colorInterpolationType = SvgColorInterpolationType::SRGB;
685     std::unordered_map<std::string, std::shared_ptr<RSImageFilter>> resultHash;
686     Rect rect(10, 10, 50, 50);
687     Size size(80, 80);
688     SvgLengthScaleRule rule(rect, size, SvgLengthScaleUnit::USER_SPACE_ON_USE);
689     svgFeOffset->GetFilterContext().SetPrimitiveRule(rule);
690     svgFeOffset->OnAsImageFilter(imageFilter, type, colorInterpolationType, resultHash, true);
691     auto res = svgFeOffset->ParseAndSetSpecializedAttr("dx", "1");
692     EXPECT_TRUE(res);
693 
694     Rect rect1(10, 10, 50, 50);
695     Size size1(80, 80);
696     SvgLengthScaleRule rule1(rect1, size1, SvgLengthScaleUnit::OBJECT_BOUNDING_BOX);
697     svgFeOffset->GetFilterContext().SetPrimitiveRule(rule1);
698     svgFeOffset->OnAsImageFilter(imageFilter, type, colorInterpolationType, resultHash, true);
699     res = svgFeOffset->ParseAndSetSpecializedAttr("dx", "1");
700     EXPECT_TRUE(res);
701 }
702 
703 /**
704  * @tc.name: ParseFilterTest002
705  * @tc.desc: parse Filter label
706  * @tc.type: FUNC
707  */
708 HWTEST_F(SvgTransformTestNg, SvgFeBlendTest001, TestSize.Level1)
709 {
710     auto svgFeBlend = AceType::DynamicCast<SvgFeBlend>(SvgFeBlend::Create());
711     EXPECT_NE(svgFeBlend, nullptr);
712     std::unordered_map<std::string, std::shared_ptr<RSImageFilter>> resultHash;
713     std::shared_ptr<RSImageFilter> imageFilter = nullptr;
714     SvgColorInterpolationType srcColor = SvgColorInterpolationType::SRGB;
715     SvgColorInterpolationType currentColor = SvgColorInterpolationType::LINEAR_RGB;
716     svgFeBlend->filterContext_.primitiveRule_.lengthScaleUnit_ = SvgLengthScaleUnit::OBJECT_BOUNDING_BOX;
717     svgFeBlend->OnAsImageFilter(imageFilter, srcColor, currentColor, resultHash, true);
718 
719     svgFeBlend->filterContext_.primitiveRule_.lengthScaleUnit_ = SvgLengthScaleUnit::USER_SPACE_ON_USE;
720     svgFeBlend->OnAsImageFilter(imageFilter, srcColor, currentColor, resultHash, true);
721     EXPECT_NE(imageFilter, nullptr);
722 }
723 
724 /**
725  * @tc.name: ParseFilterTest002
726  * @tc.desc: parse Filter label
727  * @tc.type: FUNC
728  */
729 HWTEST_F(SvgTransformTestNg, SvgLineTest001, TestSize.Level1)
730 {
731     auto svgLine = AceType::DynamicCast<SvgLine>(SvgLine::Create());
732     EXPECT_NE(svgLine, nullptr);
733     svgLine->path_ = std::nullopt;
734     SvgLengthScaleRule rule;
735     Rect rect(0, 10, 20, 20);
736     rule.containerRect_ = rect;
737     rule.pathTransform_ = false;
738     svgLine->AsPath(rule);
739     rule.pathTransform_ = true;
740     svgLine->AsPath(rule);
741 
742     rule.containerRect_ = svgLine->lengthRule_.containerRect_;
743     rule.pathTransform_ = false;
744     svgLine->AsPath(rule);
745     rule.pathTransform_ = true;
746     svgLine->AsPath(rule);
747 
748     RSRecordingPath path;
749     svgLine->path_ = path;
750     rule.containerRect_ = rect;
751     rule.pathTransform_ = false;
752     svgLine->AsPath(rule);
753     rule.pathTransform_ = true;
754     svgLine->AsPath(rule);
755 
756     rule.containerRect_ = svgLine->lengthRule_.containerRect_;
757     rule.pathTransform_ = false;
758     svgLine->AsPath(rule);
759     rule.pathTransform_ = true;
760     svgLine->AsPath(rule);
761     EXPECT_TRUE(rule.UseFillColor());
762 }
763 
764 /**
765  * @tc.name: ParseFilterTest002
766  * @tc.desc: parse Filter label
767  * @tc.type: FUNC
768  */
769 HWTEST_F(SvgTransformTestNg, SvgRectTest001, TestSize.Level1)
770 {
771     auto svgLine = AceType::DynamicCast<SvgRect>(SvgRect::Create());
772     EXPECT_NE(svgLine, nullptr);
773     svgLine->path_ = std::nullopt;
774     SvgLengthScaleRule rule;
775     Rect rect(0, 10, 20, 20);
776     rule.containerRect_ = rect;
777     rule.pathTransform_ = false;
778     svgLine->AsPath(rule);
779     rule.pathTransform_ = true;
780     svgLine->AsPath(rule);
781 
782     rule.containerRect_ = svgLine->lengthRule_.containerRect_;
783     rule.pathTransform_ = false;
784     svgLine->AsPath(rule);
785     rule.pathTransform_ = true;
786     svgLine->AsPath(rule);
787 
788     RSRecordingPath path;
789     svgLine->path_ = path;
790     rule.containerRect_ = rect;
791     rule.pathTransform_ = false;
792     svgLine->AsPath(rule);
793     rule.pathTransform_ = true;
794     svgLine->AsPath(rule);
795 
796     rule.containerRect_ = svgLine->lengthRule_.containerRect_;
797     rule.pathTransform_ = false;
798     svgLine->AsPath(rule);
799     rule.pathTransform_ = true;
800     svgLine->AsPath(rule);
801     EXPECT_TRUE(rule.UseFillColor());
802 }
803 
804 /**
805  * @tc.name: ParseFilterTest002
806  * @tc.desc: parse Filter label
807  * @tc.type: FUNC
808  */
809 HWTEST_F(SvgTransformTestNg, SvgEllipseTest001, TestSize.Level1)
810 {
811     auto svgLine = AceType::DynamicCast<SvgEllipse>(SvgEllipse::Create());
812     EXPECT_NE(svgLine, nullptr);
813     svgLine->path_ = std::nullopt;
814     SvgLengthScaleRule rule;
815     Rect rect(0, 10, 20, 20);
816     rule.containerRect_ = rect;
817     rule.pathTransform_ = false;
818     svgLine->AsPath(rule);
819     rule.pathTransform_ = true;
820     svgLine->AsPath(rule);
821 
822     rule.containerRect_ = svgLine->lengthRule_.containerRect_;
823     rule.pathTransform_ = false;
824     svgLine->AsPath(rule);
825     rule.pathTransform_ = true;
826     svgLine->AsPath(rule);
827 
828     RSRecordingPath path;
829     svgLine->path_ = path;
830     rule.containerRect_ = rect;
831     rule.pathTransform_ = false;
832     svgLine->AsPath(rule);
833     rule.pathTransform_ = true;
834     svgLine->AsPath(rule);
835 
836     rule.containerRect_ = svgLine->lengthRule_.containerRect_;
837     rule.pathTransform_ = false;
838     svgLine->AsPath(rule);
839     rule.pathTransform_ = true;
840     svgLine->AsPath(rule);
841     EXPECT_TRUE(rule.UseFillColor());
842 }
843 
844 /**
845  * @tc.name: ParseFilterTest002
846  * @tc.desc: parse Filter label
847  * @tc.type: FUNC
848  */
849 HWTEST_F(SvgTransformTestNg, SvgCircleTest001, TestSize.Level1)
850 {
851     auto svgLine = AceType::DynamicCast<SvgCircle>(SvgCircle::Create());
852     EXPECT_NE(svgLine, nullptr);
853     svgLine->path_ = std::nullopt;
854     SvgLengthScaleRule rule;
855     Rect rect(0, 10, 20, 20);
856     rule.containerRect_ = rect;
857     rule.pathTransform_ = false;
858     svgLine->AsPath(rule);
859     rule.pathTransform_ = true;
860     svgLine->AsPath(rule);
861 
862     rule.containerRect_ = svgLine->lengthRule_.containerRect_;
863     rule.pathTransform_ = false;
864     svgLine->AsPath(rule);
865     rule.pathTransform_ = true;
866     svgLine->AsPath(rule);
867 
868     RSRecordingPath path;
869     svgLine->path_ = path;
870     rule.containerRect_ = rect;
871     rule.pathTransform_ = false;
872     svgLine->AsPath(rule);
873     rule.pathTransform_ = true;
874     svgLine->AsPath(rule);
875 
876     rule.containerRect_ = svgLine->lengthRule_.containerRect_;
877     rule.pathTransform_ = false;
878     svgLine->AsPath(rule);
879     rule.pathTransform_ = true;
880     svgLine->AsPath(rule);
881     EXPECT_TRUE(rule.UseFillColor());
882 }
883 
884 /**
885  * @tc.name: ParseFilterTest002
886  * @tc.desc: parse Filter label
887  * @tc.type: FUNC
888  */
889 HWTEST_F(SvgTransformTestNg, SvgGradientTest001, TestSize.Level1)
890 {
891     auto gradient = AceType::DynamicCast<SvgGradient>(SvgGradient::CreateLinearGradient());
892     EXPECT_NE(gradient, nullptr);
893     RefPtr<SvgNode> svgNode1 = nullptr;
894     RefPtr<SvgNode> svgNode2 = SvgPattern::Create();
895     svgNode2->drawTraversed_ = false;
896     RefPtr<SvgNode> svgNode3 = SvgPattern::Create();
897     svgNode3->drawTraversed_ = true;
898     gradient->children_.emplace_back(svgNode1);
899     gradient->children_.emplace_back(svgNode2);
900     gradient->children_.emplace_back(svgNode3);
901 
902     auto svgStop = AceType::DynamicCast<SvgStop>(SvgStop::Create());
903     gradient->children_.emplace_back(svgStop);
904     auto result = gradient->GetStopColors();
905     EXPECT_EQ(result.size(), 1);
906 }
907 
908 /**
909  * @tc.name: SvgImageTest001
910  * @tc.desc: parse Filter label
911  * @tc.type: FUNC
912  */
913 HWTEST_F(SvgTransformTestNg, SvgImageTest001, TestSize.Level1)
914 {
915     auto svgImage = AceType::DynamicCast<SvgImage>(SvgImage::Create());
916     EXPECT_NE(svgImage, nullptr);
917     RSCanvas canvas;
918     Size viewPort;
919 
920     std::optional<Color> color = Color::BLACK;
921     svgImage->imageAttr_.href = "";
922     svgImage->OnDraw(canvas, viewPort, color);
923 
924     svgImage->imageAttr_.href = "href";
925     svgImage->OnDraw(canvas, viewPort, color);
926 
927     svgImage->imageAttr_.width = 0.0_px;
928     svgImage->imageAttr_.height = 0.0_px;
929     svgImage->OnDraw(canvas, viewPort, color);
930 
931     svgImage->imageAttr_.width = 0.0_px;
932     svgImage->imageAttr_.height = 10.0_px;
933     svgImage->OnDraw(canvas, viewPort, color);
934 
935     svgImage->imageAttr_.width = 20.0_px;
936     svgImage->imageAttr_.height = 0.0_px;
937     svgImage->OnDraw(canvas, viewPort, color);
938 
939     svgImage->imageAttr_.width = 20.0_px;
940     svgImage->imageAttr_.height = 20.0_px;
941     svgImage->OnDraw(canvas, viewPort, color);
942 
943     svgImage->imageAttr_.href = "data:image/jpeg;base64$";
944     svgImage->OnDraw(canvas, viewPort, color);
945 
946     svgImage->imageAttr_.href = "";
947     svgImage->OnDraw(canvas, viewPort, color);
948     EXPECT_EQ(viewPort.Width(), 0);
949 }
950 
951 /**
952  * @tc.name: SvgImageTest001
953  * @tc.desc: parse Filter label
954  * @tc.type: FUNC
955  */
956 HWTEST_F(SvgTransformTestNg, SvgPatternTest001, TestSize.Level1)
957 {
958     auto pattern = AceType::DynamicCast<SvgPattern>(SvgPattern::Create());
959     EXPECT_NE(pattern, nullptr);
960     int32_t settingApiVersion = static_cast<int32_t>(PlatformVersion::VERSION_TWELVE);
961     int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();
962     MockContainer::Current()->SetApiTargetVersion(settingApiVersion);
963     RSCanvas canvas;
964     Size viewPort;
965     std::optional<Color> color;
966     pattern->OnDrawTraversedBefore(canvas, viewPort, color);
967     EXPECT_EQ(viewPort.Width(), 0);
968     MockContainer::Current()->SetApiTargetVersion(backupApiVersion);
969 }
970 
971 /**
972  * @tc.name: SvgImageTest001
973  * @tc.desc: parse Filter label
974  * @tc.type: FUNC
975  */
976 HWTEST_F(SvgTransformTestNg, SvgPatternTest002, TestSize.Level1)
977 {
978     auto pattern = AceType::DynamicCast<SvgPattern>(SvgPattern::Create());
979     EXPECT_NE(pattern, nullptr);
980     RSCanvas canvas;
981     Size viewPort;
982     std::optional<Color> color;
983     pattern->patternAttr_.patternContentUnits = SvgLengthScaleUnit::OBJECT_BOUNDING_BOX;
984     pattern->OnDrawTraversedBefore(canvas, viewPort, color);
985 
986     EXPECT_EQ(viewPort.Width(), 0);
987 }
988 
989 /**
990  * @tc.name: SvgImageTest001
991  * @tc.desc: parse Filter label
992  * @tc.type: FUNC
993  */
994 HWTEST_F(SvgTransformTestNg, SvgPatternTest003, TestSize.Level1)
995 {
996     auto pattern = AceType::DynamicCast<SvgPattern>(SvgPattern::Create());
997     EXPECT_NE(pattern, nullptr);
998     RSCanvas canvas;
999     RSBrush brush;
1000     Rect rect(10, 12, 13, 15);
1001     Size size(10, 10);
1002     SvgCoordinateSystemContext context(rect, size);
1003 
1004     RefPtr<SvgNode> svgNode1 = nullptr;
1005     RefPtr<SvgNode> svgNode2 = SvgPattern::Create();
1006     svgNode2->drawTraversed_ = false;
1007     RefPtr<SvgNode> svgNode3 = SvgPattern::Create();
1008     svgNode3->drawTraversed_ = true;
1009     pattern->children_.emplace_back(svgNode1);
1010     pattern->children_.emplace_back(svgNode2);
1011     pattern->children_.emplace_back(svgNode3);
1012 
1013     pattern->OnPatternEffect(canvas, brush, context);
1014     EXPECT_TRUE(context.UseFillColor());
1015 }
1016 
1017 /**
1018  * @tc.name: SvgImageTest001
1019  * @tc.desc: parse Filter label
1020  * @tc.type: FUNC
1021  */
1022 HWTEST_F(SvgTransformTestNg, SvgFeCompositeTest001, TestSize.Level1)
1023 {
1024     auto pattern = AceType::DynamicCast<SvgFeComposite>(SvgFeComposite::Create());
1025     EXPECT_NE(pattern, nullptr);
1026 
1027     auto result = pattern->BlendModeForOperator(SvgFeOperatorType::FE_ATOP);
1028     EXPECT_EQ(result, RSBlendMode::SRC_ATOP);
1029 }
1030 
1031 /**
1032  * @tc.name: SvgImageTest001
1033  * @tc.desc: parse Filter label
1034  * @tc.type: FUNC
1035  */
1036 HWTEST_F(SvgTransformTestNg, SvgFeCompositeTest002, TestSize.Level1)
1037 {
1038     auto pattern = AceType::DynamicCast<SvgFeComposite>(SvgFeComposite::Create());
1039     EXPECT_NE(pattern, nullptr);
1040     auto result = pattern->BlendModeForOperator(SvgFeOperatorType::FE_ATOP);
1041     std::shared_ptr<RSImageFilter> imageFilter = nullptr;
1042     SvgColorInterpolationType type = SvgColorInterpolationType::SRGB;
1043     SvgColorInterpolationType colorInterpolationType = SvgColorInterpolationType::SRGB;
1044     std::unordered_map<std::string, std::shared_ptr<RSImageFilter>> resultHash;
1045     pattern->feCompositeAttr_.operatorType = SvgFeOperatorType::FE_ARITHMETIC;
1046     pattern->OnAsImageFilter(imageFilter, type, colorInterpolationType, resultHash, false);
1047     pattern->feCompositeAttr_.operatorType = SvgFeOperatorType::FE_ARITHMETIC;
1048     pattern->OnAsImageFilter(imageFilter, type, colorInterpolationType, resultHash, true);
1049     pattern->feCompositeAttr_.operatorType = SvgFeOperatorType::FE_ATOP;
1050     pattern->OnAsImageFilter(imageFilter, type, colorInterpolationType, resultHash, true);
1051     EXPECT_EQ(result, RSBlendMode::SRC_ATOP);
1052 }
1053 
1054 /**
1055  * @tc.name: SvgAnimateTest
1056  * @tc.desc: Verify the property animation process for type double
1057  * @tc.type: FUNC
1058  */
1059 HWTEST_F(SvgTransformTestNg, SvgAnimationTest001, TestSize.Level1)
1060 {
1061     /**
1062      * @tc.steps: step1. init svg animate and animator
1063      */
1064     RefPtr<SvgAnimation> animation = AceType::DynamicCast<SvgAnimation>(SvgAnimation::Create());
1065     animation->SetAttributeName("opacity");
1066     animation->SetBegin(0);
1067     animation->SetDur(1600);
1068     animation->SetRepeatCount(1);
1069     animation->SetFillMode(Fill::FREEZE);
1070     animation->SetCalcMode(CalcMode::LINEAR);
1071     animation->SetFrom("0.1");
1072     animation->SetTo("1.0");
1073     std::vector<std::string> keyPoints;
1074     keyPoints.emplace_back("asd dfgfdg fdg000");
1075     keyPoints.emplace_back("asd dfgfdg fdg111");
1076     keyPoints.emplace_back("asd dfgfdg fdg222");
1077     animation->SetKeyPoints(keyPoints);
__anonf9812e780202(double num) 1078     auto callback = [](double num) { LOGE("action callback"); };
1079     animation->calcMode_ = static_cast<CalcMode>(100);
1080     animation->CreatePropertyAnimation<double>(19.0f, callback);
1081     EXPECT_NE(animation->animator_, nullptr);
1082 }
1083 
1084 /**
1085  * @tc.name: SvgAnimateTest
1086  * @tc.desc: Verify the property animation process for type double
1087  * @tc.type: FUNC
1088  */
1089 HWTEST_F(SvgTransformTestNg, SvgAnimationTest002, TestSize.Level1)
1090 {
1091     /**
1092      * @tc.steps: step1. init svg animate and animator
1093      */
1094     RefPtr<SvgAnimation> animation = AceType::DynamicCast<SvgAnimation>(SvgAnimation::Create());
1095     animation->SetAttributeName("width");
1096     animation->SetBegin(0);
1097     animation->SetDur(1600);
1098     animation->SetRepeatCount(1);
1099     animation->SetFillMode(Fill::FREEZE);
1100     animation->SetCalcMode(CalcMode::PACED);
1101     std::vector<std::string> values = { "50", "100", "200", "300" };
1102     animation->SetValues(values);
1103     std::vector<double> keyTimes = { 0.0, 0.2, 0.7, 1.0 };
1104     animation->SetKeyTimes(keyTimes);
1105     std::vector<std::string> keyPoints;
1106     keyPoints.emplace_back("asd dfgfdg fdg000");
1107     keyPoints.emplace_back("asd dfgfdg fdg111");
1108     keyPoints.emplace_back("asd dfgfdg fdg222");
1109     animation->SetKeyPoints(keyPoints);
__anonf9812e780302(double num) 1110     auto callback = [](double num) { LOGE("action callback"); };
1111     animation->calcMode_ = static_cast<CalcMode>(100);
1112     animation->CreatePropertyAnimation<double>(19.0f, callback);
1113     EXPECT_NE(animation->animator_, nullptr);
1114 }
1115 
1116 /**
1117  * @tc.name: animationTest
1118  * @tc.desc: Verify the property animation process for type double
1119  * @tc.type: FUNC
1120  */
1121 HWTEST_F(SvgTransformTestNg, SvgAnimationTest003, TestSize.Level1)
1122 {
1123     /**
1124      * @tc.steps: step1. init svg animate and animator
1125      */
1126     RefPtr<SvgAnimation> animation = AceType::DynamicCast<SvgAnimation>(SvgAnimation::Create());
1127     animation->SetBegin(0);
1128     animation->SetDur(1600);
1129     animation->SetFillMode(Fill::FREEZE);
1130     animation->SetRepeatCount(1);
1131     animation->SetCalcMode(CalcMode::LINEAR);
1132     std::vector<std::string> keyPoints = { "0", "0.5", "1" };
1133     animation->SetKeyPoints(keyPoints);
1134     std::vector<double> keyTimes = { 0.0, 0.4, 1.0 };
1135     animation->SetKeyTimes(keyTimes);
__anonf9812e780402(double num) 1136     auto callback = [](double num) { LOGE("action callback"); };
1137     animation->calcMode_ = static_cast<CalcMode>(100);
1138     animation->CreatePropertyAnimation<double>(19.0f, callback);
1139     EXPECT_NE(animation->animator_, nullptr);
1140 }
1141 
1142 /**
1143  * @tc.name: animationTest
1144  * @tc.desc: Verify the property animation process for type double
1145  * @tc.type: FUNC
1146  */
1147 HWTEST_F(SvgTransformTestNg, SvgAnimationTest004, TestSize.Level1)
1148 {
1149     /**
1150      * @tc.steps: step1. init svg animate and animator
1151      */
1152     RefPtr<SvgAnimation> animation = AceType::DynamicCast<SvgAnimation>(SvgAnimation::Create());
1153     animation->SetAttributeName("width");
1154     animation->SetBegin(0);
1155     animation->SetDur(1600);
1156     animation->SetRepeatCount(1);
1157     animation->SetFillMode(Fill::FREEZE);
1158     animation->SetCalcMode(CalcMode::DISCRETE);
1159     std::vector<std::string> values = { "100", "200", "300" };
1160     animation->SetValues(values);
1161     std::vector<double> keyTimes = { 0.0, 0.2, 0.7, 1.0 };
1162     animation->SetKeyTimes(keyTimes);
__anonf9812e780502(double num) 1163     auto callback = [](double num) { LOGE("action callback"); };
1164     animation->calcMode_ = static_cast<CalcMode>(100);
1165     animation->CreatePropertyAnimation<double>(19.0f, callback);
1166     EXPECT_NE(animation->animator_, nullptr);
1167 }
1168 
1169 /**
1170  * @tc.name: ParseTransformTestScale
1171  * @tc.desc: parse transform-origin label
1172  * @tc.type: FUNC
1173  */
1174 HWTEST_F(SvgTransformTestNg, SvgDomTest001, TestSize.Level1)
1175 {
1176     auto svgStream = SkMemoryStream::MakeCopy(ERROR_SVG.c_str(), ERROR_SVG.length());
1177     EXPECT_NE(svgStream, nullptr);
1178     ImageSourceInfo src;
1179     src.SetFillColor(Color::BLACK);
1180     auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
1181     EXPECT_EQ(svgDom, nullptr);
1182 }
1183 
1184 /**
1185  * @tc.name: animationTest
1186  * @tc.desc: Verify the property animation process for type double
1187  * @tc.type: FUNC
1188  */
1189 HWTEST_F(SvgTransformTestNg, SvgUseTest001, TestSize.Level1)
1190 {
1191     auto svgUse = AceType::DynamicCast<SvgUse>(SvgUse::Create());
1192     EXPECT_NE(svgUse, nullptr);
1193 
1194     svgUse->useAttr_.x = 1.0_px;
1195     svgUse->useAttr_.y = 2.0_px;
1196 
1197     svgUse->OnInitStyle();
1198     EXPECT_EQ(svgUse->useOffsetX_, 1.0);
1199     EXPECT_EQ(svgUse->useOffsetY_, 2.0);
1200 }
1201 
1202 /**
1203  * @tc.name: animationTest
1204  * @tc.desc: Verify the property animation process for type double
1205  * @tc.type: FUNC
1206  */
1207 HWTEST_F(SvgTransformTestNg, SvgUseTest002, TestSize.Level1)
1208 {
1209     auto svgUse = AceType::DynamicCast<SvgUse>(SvgUse::Create());
1210     EXPECT_NE(svgUse, nullptr);
1211 
1212     Rect rect(10, 10, 50, 50);
1213     Size size(80, 80);
1214     SvgLengthScaleRule rule(rect, size, SvgLengthScaleUnit::USER_SPACE_ON_USE);
1215     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1216     svgUse->SetContext(svgContext);
1217     auto path = svgUse->AsPath(rule);
1218     EXPECT_TRUE(path.BuildFromSVGString(""));
1219 
1220     svgUse->attributes_.href = "href";
1221     svgUse->isDrawingPath_ = false;
1222     path = svgUse->AsPath(rule);
1223     EXPECT_TRUE(path.BuildFromSVGString(""));
1224 
1225     svgUse->attributes_.href = "href";
1226     svgUse->isDrawingPath_ = true;
1227     path = svgUse->AsPath(rule);
1228     EXPECT_TRUE(path.BuildFromSVGString(""));
1229 
1230     auto svgPattern = AceType::MakeRefPtr<SvgPattern>();
1231     EXPECT_NE(svgPattern, nullptr);
1232     svgContext->Push("href", svgPattern);
1233     svgUse->SetContext(svgContext);
1234     path = svgUse->AsPath(rule);
1235     EXPECT_TRUE(path.BuildFromSVGString(""));
1236 }
1237 
1238 /**
1239  * @tc.name: SvgGTest001
1240  * @tc.desc: parse polygon and polyline label
1241  * @tc.type: FUNC
1242  */
1243 HWTEST_F(SvgTransformTestNg, SvgUseTest003, TestSize.Level1)
1244 {
1245     auto svgUse = AceType::DynamicCast<SvgUse>(SvgUse::Create());
1246     EXPECT_NE(svgUse, nullptr);
1247     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1248     svgUse->SetContext(svgContext);
1249 
1250     SvgLengthScaleRule lengthRule;
1251     RSCanvas canvas;
1252     svgUse->attributes_.hasOpacity = false;
1253     svgUse->ApplyOpacity(canvas);
1254 
1255     svgUse->attributes_.hasOpacity = true;
1256     svgUse->ApplyOpacity(canvas);
1257     svgUse->attributes_.href = "";
1258     svgUse->OnDraw(canvas, lengthRule);
1259     svgUse->attributes_.href = "href";
1260 
1261     auto svgPattern = AceType::MakeRefPtr<SvgPattern>();
1262     EXPECT_NE(svgPattern, nullptr);
1263     svgContext->Push("href", svgPattern);
1264     svgUse->useAttr_.x = 0.0_px;
1265     svgUse->useAttr_.y = 0.0_px;
1266     Size size;
1267     auto result = svgUse->AsPath(size);
1268     EXPECT_TRUE(result.BuildFromSVGString(""));
1269     result = svgUse->AsPath(lengthRule);
1270     EXPECT_TRUE(result.BuildFromSVGString(""));
1271 }
1272 
1273 /**
1274  * @tc.name: SvgGTest001
1275  * @tc.desc: parse polygon and polyline label
1276  * @tc.type: FUNC
1277  */
1278 HWTEST_F(SvgTransformTestNg, SvgUseTest004, TestSize.Level1)
1279 {
1280     auto svgUse = AceType::DynamicCast<SvgUse>(SvgUse::Create());
1281     EXPECT_NE(svgUse, nullptr);
1282     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1283     svgUse->SetContext(svgContext);
1284     SvgLengthScaleRule lengthRule;
1285     RSCanvas canvas;
1286     svgUse->attributes_.href = "";
1287     svgUse->OnDraw(canvas, lengthRule);
1288     svgUse->attributes_.href = "href";
1289 
1290     auto svgPattern = AceType::MakeRefPtr<SvgPattern>();
1291     EXPECT_NE(svgPattern, nullptr);
1292     svgContext->Push("href", svgPattern);
1293     svgUse->useAttr_.x = 0.0_px;
1294     svgUse->useAttr_.y = 0.0_px;
1295     svgUse->SetContext(svgContext);
1296     svgUse->OnDraw(canvas, lengthRule);
1297 
1298     svgUse->useAttr_.x = 1.0_px;
1299     svgUse->useAttr_.y = 0.0_px;
1300     svgUse->OnDraw(canvas, lengthRule);
1301 
1302     svgUse->useAttr_.x = 0.0_px;
1303     svgUse->useAttr_.y = 1.0_px;
1304     svgUse->OnDraw(canvas, lengthRule);
1305 
1306     svgUse->useAttr_.x = 1.0_px;
1307     svgUse->useAttr_.y = 10.0_px;
1308     svgUse->OnDraw(canvas, lengthRule);
1309     EXPECT_FALSE(lengthRule.GetPathTransform());
1310     auto res = svgUse->ParseAndSetSpecializedAttr("automirror", "true");
1311     EXPECT_TRUE(res);
1312 }
1313 
1314 /**
1315  * @tc.name: ParseTransformOriginInvalidTest002
1316  * @tc.desc: parse transform-origin label
1317  * @tc.type: FUNC
1318  */
1319 HWTEST_F(SvgTransformTestNg, SvgFeBlendTest002, TestSize.Level1)
1320 {
1321     auto feBlend = AceType::DynamicCast<SvgFeBlend>(SvgFeBlend::Create());
1322     EXPECT_NE(feBlend, nullptr);
1323     std::unordered_map<std::string, std::shared_ptr<RSImageFilter>> resultHash;
1324     std::shared_ptr<RSImageFilter> imageFilter = nullptr;
1325     SvgColorInterpolationType srcColor = SvgColorInterpolationType::SRGB;
1326     SvgColorInterpolationType currentColor = SvgColorInterpolationType::LINEAR_RGB;
1327     feBlend->filterContext_.primitiveRule_.lengthScaleUnit_ = SvgLengthScaleUnit::OBJECT_BOUNDING_BOX;
1328     feBlend->OnAsImageFilter(imageFilter, srcColor, currentColor, resultHash, true);
1329 
1330     feBlend->filterContext_.primitiveRule_.lengthScaleUnit_ = SvgLengthScaleUnit::USER_SPACE_ON_USE;
1331     feBlend->OnAsImageFilter(imageFilter, srcColor, currentColor, resultHash, true);
1332     EXPECT_NE(imageFilter, nullptr);
1333 }
1334 
1335 /**
1336  * @tc.name: ParseTransformOriginInvalidTest002
1337  * @tc.desc: parse transform-origin label
1338  * @tc.type: FUNC
1339  */
1340 HWTEST_F(SvgTransformTestNg, SvgClipPathTest001, TestSize.Level1)
1341 {
1342     auto svgClipPath = AceType::DynamicCast<SvgClipPath>(SvgClipPath::Create());
1343     EXPECT_NE(svgClipPath, nullptr);
1344     RefPtr<SvgNode> svgNode2 = SvgPattern::Create();
1345     svgNode2->drawTraversed_ = false;
1346     RefPtr<SvgNode> svgNode3 = SvgPattern::Create();
1347     svgNode3->drawTraversed_ = true;
1348     svgClipPath->children_.emplace_back(svgNode2);
1349     svgClipPath->children_.emplace_back(svgNode3);
1350     Rect rect(10, 10, 50, 50);
1351     Size size(80, 80);
1352     SvgLengthScaleRule rule(rect, size, SvgLengthScaleUnit::USER_SPACE_ON_USE);
1353     svgClipPath->attributes_.clipState.SetClipRule(SvgRuleType::SVG_RULE_EVENODD);
1354     auto path = svgClipPath->AsPath(rule);
1355     EXPECT_TRUE(path.BuildFromSVGString(""));
1356 
1357     svgClipPath->attributes_.clipState.SetClipRule(SvgRuleType::SVG_RULE_NONEZERO);
1358     path = svgClipPath->AsPath(rule);
1359     EXPECT_TRUE(path.BuildFromSVGString(""));
1360 }
1361 
1362 /**
1363  * @tc.name: ParseTransformOriginInvalidTest002
1364  * @tc.desc: parse transform-origin label
1365  * @tc.type: FUNC
1366  */
1367 HWTEST_F(SvgTransformTestNg, SvgImageTest002, TestSize.Level1)
1368 {
1369     auto svgImage = AceType::DynamicCast<SvgImage>(SvgImage::Create());
1370     EXPECT_NE(svgImage, nullptr);
1371     RSCanvas canvas;
1372     Rect rect(10, 10, 50, 50);
1373     Size size(80, 80);
1374     SvgLengthScaleRule rule(rect, size, SvgLengthScaleUnit::USER_SPACE_ON_USE);
1375     svgImage->imageAttr_.href = "";
1376     svgImage->OnDraw(canvas, rule);
1377     svgImage->imageAttr_.href = "href";
1378     svgImage->imageAttr_.x = 0.0_px;
1379     svgImage->imageAttr_.y = 0.0_px;
1380     svgImage->OnDraw(canvas, rule);
1381 
1382     svgImage->imageAttr_.x = 0.0_px;
1383     svgImage->imageAttr_.y = 1.0_px;
1384     svgImage->OnDraw(canvas, rule);
1385 
1386     svgImage->imageAttr_.x = 1.0_px;
1387     svgImage->imageAttr_.y = 0.0_px;
1388     svgImage->OnDraw(canvas, rule);
1389 
1390     svgImage->imageAttr_.x = 1.0_px;
1391     svgImage->imageAttr_.y = 10.0_px;
1392     svgImage->OnDraw(canvas, rule);
1393 
1394     svgImage->imageAttr_.href = "http://href";
1395     svgImage->OnDraw(canvas, rule);
1396 
1397     svgImage->imageAttr_.href = "https://href";
1398     svgImage->OnDraw(canvas, rule);
1399 
1400     svgImage->imageAttr_.href = "data:image/jpeg;base64";
1401     svgImage->OnDraw(canvas, rule);
1402     auto path = svgImage->AsPath(rule);
1403     EXPECT_TRUE(path.BuildFromSVGString(""));
1404     auto res = svgImage->ParseAndSetSpecializedAttr("xlink:href", "https://www.bilibili.com");
1405     EXPECT_TRUE(res);
1406 }
1407 
1408 /**
1409  * @tc.name: CalcDstRect001
1410  * @tc.desc: test function of SvgImage.
1411  * @tc.type: FUNC
1412  */
1413 HWTEST_F(SvgTransformTestNg, SvgImageTest003, TestSize.Level1)
1414 {
1415     int32_t settingApiVersion = static_cast<int32_t>(PlatformVersion::VERSION_TWELVE);
1416     int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();
1417     MockContainer::Current()->SetApiTargetVersion(settingApiVersion);
1418     auto svgImage = AceType::DynamicCast<SvgImage>(SvgImage::Create());
1419     EXPECT_NE(svgImage, nullptr);
1420     Size realSize(0.0f, 0.0f);
1421     Rect viewBox(10.0f, 10.0f, 100.0f, 100.0f);
1422     RSRect ret = svgImage->CalcDstRect(realSize, viewBox);
1423     realSize.SetSize(Size(0.0f, 1.0f));
1424     ret = svgImage->CalcDstRect(realSize, viewBox);
1425     realSize.SetSize(Size(1.0f, 0.0f));
1426     ret = svgImage->CalcDstRect(realSize, viewBox);
1427     realSize.SetSize(Size(1.0f, 1.0f));
1428     ret = svgImage->CalcDstRect(realSize, viewBox);
1429     EXPECT_NE(ret.left_, 0.0f);
1430     MockContainer::Current()->SetApiTargetVersion(backupApiVersion);
1431 }
1432 
1433 /**
1434  * @tc.name: CalcDstRect001
1435  * @tc.desc: test function of SvgImage.
1436  * @tc.type: FUNC
1437  */
1438 HWTEST_F(SvgTransformTestNg, SvgNodeTest001, TestSize.Level1)
1439 {
1440     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1441     EXPECT_NE(svgNode, nullptr);
1442     svgNode->SetAttr("clipPathUnits", "objectBoundingBox");
1443     EXPECT_EQ(svgNode->attributes_.clipState.GetClipPathUnits(), SvgLengthScaleUnit::OBJECT_BOUNDING_BOX);
1444     svgNode->SetAttr("clipPathUnits", "objectBoundingBox222");
1445     EXPECT_EQ(svgNode->attributes_.clipState.GetClipPathUnits(), SvgLengthScaleUnit::USER_SPACE_ON_USE);
1446     svgNode->SetAttr("stroke", "objectBoundingBox222");
1447     svgNode->SetAttr("transform", "(aaa(bbb)ccc)");
1448     EXPECT_EQ(svgNode->attributes_.transform, "(aaa(bbb)ccc)");
1449     svgNode->SetAttr("transform", "aaa(bbb)ccc)");
1450     EXPECT_EQ(svgNode->attributes_.transform, "aaa(bbb)ccc)");
1451     svgNode->SetAttr("transform", "");
1452     EXPECT_EQ(svgNode->attributes_.transform, "");
1453     svgNode->SetAttr("transform", "33432423");
1454     EXPECT_EQ(svgNode->attributes_.transform, "33432423");
1455     svgNode->SetAttr("transform", "412sfdsfdgdfcccc((()))");
1456     EXPECT_EQ(svgNode->attributes_.transform, "412sfdsfdgdfcccc((()))");
1457 }
1458 
1459 /**
1460  * @tc.name: CalcDstRect001
1461  * @tc.desc: test function of SvgImage.
1462  * @tc.type: FUNC
1463  */
1464 HWTEST_F(SvgTransformTestNg, SvgNodeTest002, TestSize.Level1)
1465 {
1466     int32_t settingApiVersion = static_cast<int32_t>(PlatformVersion::VERSION_EIGHTEEN);
1467     int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();
1468     MockContainer::Current()->SetApiTargetVersion(settingApiVersion);
1469     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1470     EXPECT_NE(svgNode, nullptr);
1471     svgNode->SetAttr("clipPathUnits", "objectBoundingBox");
1472     EXPECT_EQ(svgNode->attributes_.clipState.GetClipPathUnits(), SvgLengthScaleUnit::OBJECT_BOUNDING_BOX);
1473     svgNode->SetAttr("clipPathUnits", "objectBoundingBox222");
1474     EXPECT_EQ(svgNode->attributes_.clipState.GetClipPathUnits(), SvgLengthScaleUnit::USER_SPACE_ON_USE);
1475     svgNode->SetAttr("stroke", "url(https://www.baidu.com)");
1476     svgNode->SetAttr("stroke", "aliceblue");
1477     svgNode->SetAttr("stroke", "none");
1478     EXPECT_EQ(svgNode->attributes_.strokeState.GetHref(), "url(https://www.baidu.com)");
1479     MockContainer::Current()->SetApiTargetVersion(backupApiVersion);
1480 }
1481 
1482 /**
1483  * @tc.name: CalcDstRect001
1484  * @tc.desc: test function of SvgImage.
1485  * @tc.type: FUNC
1486  */
1487 HWTEST_F(SvgTransformTestNg, SvgNodeTest003, TestSize.Level1)
1488 {
1489     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1490     EXPECT_NE(svgNode, nullptr);
1491     SvgBaseAttribute attr;
1492     svgNode->InitStyleDfs(nullptr, attr);
1493     svgNode->isDrawing_ = true;
1494     Size size(10, 10);
1495     Color color = Color::TRANSPARENT;
1496     RSCanvas canvas;
1497     svgNode->Draw(canvas, size, color);
1498     svgNode->hrefFilterId_ = "href";
1499     svgNode->Draw(canvas, size, color);
1500     svgNode->isDrawing_ = false;
1501     svgNode->Draw(canvas, size, color);
1502     auto svgNode1 = AceType::MakeRefPtr<SvgNode>();
1503     EXPECT_NE(svgNode, nullptr);
1504     auto svgNode2 = AceType::MakeRefPtr<SvgNode>();
1505     EXPECT_NE(svgNode, nullptr);
1506     auto svgNode3 = AceType::MakeRefPtr<SvgNode>();
1507     EXPECT_NE(svgNode, nullptr);
1508     svgNode1->AppendChild(nullptr);
1509     svgNode1->AppendChild(svgNode2);
1510     svgNode1->AppendChild(svgNode3);
1511     svgNode1->AppendChild(nullptr);
1512     SvgInitStyleProcessInfo info;
1513     info.svgNode = svgNode1;
1514     std::stack<std::pair<SvgInitStyleProcessInfo, const SvgBaseAttribute*>> stack;
1515     auto res = svgNode->ProcessChildStyle(info, stack);
1516     EXPECT_FALSE(res);
1517 }
1518 
1519 /**
1520  * @tc.name: CalcDstRect001
1521  * @tc.desc: test function of SvgImage.
1522  * @tc.type: FUNC
1523  */
1524 HWTEST_F(SvgTransformTestNg, SvgNodeTest004, TestSize.Level1)
1525 {
1526     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1527     EXPECT_NE(svgNode, nullptr);
1528     svgNode->isDrawing_ = true;
1529     RSCanvas canvas;
1530     Rect rect(10, 10, 50, 50);
1531     Size size(80, 80);
1532     SvgLengthScaleRule rule(rect, size, SvgLengthScaleUnit::USER_SPACE_ON_USE);
1533     svgNode->Draw(canvas, rule);
1534     svgNode->isDrawing_ = false;
1535     svgNode->Draw(canvas, rule);
1536     svgNode->hrefClipPath_ = "111";
1537     svgNode->Draw(canvas, rule);
1538     svgNode->hrefClipPath_ = "";
1539     svgNode->isRootNode_ = false;
1540     svgNode->Draw(canvas, rule);
1541     svgNode->isRootNode_ = true;
1542     svgNode->Draw(canvas, rule);
1543     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1544     EXPECT_NE(svgContext, nullptr);
1545     svgNode->SetContext(svgContext);
1546     svgNode->isRootNode_ = true;
1547     svgNode->Draw(canvas, rule);
1548     svgNode->transform_ = "";
1549     svgNode->Draw(canvas, rule);
1550     svgNode->transform_ = "33";
1551     svgNode->Draw(canvas, rule);
1552     svgNode->transform_ = "";
1553     std::vector<float> vec;
1554     svgNode->animateTransform_.insert({ "hrefMap", vec });
1555     svgNode->Draw(canvas, rule);
1556     svgNode->transform_ = "href";
1557     svgNode->Draw(canvas, rule);
1558     svgNode->hrefMaskId_ = "";
1559     svgNode->Draw(canvas, rule);
1560     svgNode->hrefMaskId_ = "href";
1561     svgNode->Draw(canvas, rule);
1562     svgNode->hrefFilterId_ = "";
1563     svgNode->Draw(canvas, rule);
1564     svgNode->hrefFilterId_ = "href";
1565     svgNode->Draw(canvas, rule);
1566     auto path = svgNode->AsPath(rule);
1567     EXPECT_TRUE(path.BuildFromSVGString(""));
1568     auto res = svgNode->ParseAndSetSpecializedAttr("xlink:href", "https://www.bilibili.com");
1569     EXPECT_FALSE(res);
1570 }
1571 
1572 /**
1573  * @tc.name: CalcDstRect001
1574  * @tc.desc: test function of SvgImage.
1575  * @tc.type: FUNC
1576  */
1577 HWTEST_F(SvgTransformTestNg, SvgNodeTest006, TestSize.Level1)
1578 {
1579     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1580     EXPECT_NE(svgNode, nullptr);
1581     RSCanvas canvas;
1582     Rect rect(10, 10, 50, 50);
1583     Size size(80, 80);
1584     SvgLengthScaleRule rule(rect, size, SvgLengthScaleUnit::USER_SPACE_ON_USE);
1585     RefPtr<SvgNode> svgNode2 = SvgPattern::Create();
1586     svgNode2->drawTraversed_ = false;
1587     RefPtr<SvgNode> svgNode3 = SvgPattern::Create();
1588     svgNode3->drawTraversed_ = true;
1589     svgNode->children_.emplace_back(nullptr);
1590     svgNode->children_.emplace_back(svgNode2);
1591     svgNode->children_.emplace_back(svgNode3);
1592     svgNode->OnDrawTraversed(canvas, rule);
1593     svgNode->smoothEdge_ = 10.0f;
1594     svgNode->OnDrawTraversed(canvas, rule);
1595     EXPECT_EQ(svgNode->children_.size(), 3);
1596 }
1597 
1598 /**
1599  * @tc.name: CalcDstRect001
1600  * @tc.desc: test function of SvgImage.
1601  * @tc.type: FUNC
1602  */
1603 HWTEST_F(SvgTransformTestNg, SvgNodeTest005, TestSize.Level1)
1604 {
1605     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1606     EXPECT_NE(svgNode, nullptr);
1607     RSCanvas canvas;
1608     Rect rect(10, 12, 13, 15);
1609     Size size(10, 10);
1610     SvgCoordinateSystemContext context(rect, size);
1611     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1612     EXPECT_NE(svgContext, nullptr);
1613     RefPtr<SvgNode> svgNode2 = SvgPattern::Create();
1614     EXPECT_NE(svgNode2, nullptr);
1615     svgContext->Push("href", svgNode2);
1616     svgNode->SetContext(svgContext);
1617     svgNode->hrefClipPath_ = "href";
1618     svgNode->OnClipPath(canvas, context);
1619     svgNode->hrefClipPath_ = "href22";
1620     svgNode->OnClipPath(canvas, context);
1621     EXPECT_EQ(svgNode->hrefClipPath_, "href22");
1622 }
1623 
1624 /**
1625  * @tc.name: CalcDstRect001
1626  * @tc.desc: test function of SvgImage.
1627  * @tc.type: FUNC
1628  */
1629 HWTEST_F(SvgTransformTestNg, SvgNodeTest007, TestSize.Level1)
1630 {
1631     int32_t settingApiVersion = static_cast<int32_t>(PlatformVersion::VERSION_NINE);
1632     int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();
1633     MockContainer::Current()->SetApiTargetVersion(settingApiVersion);
1634     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1635     EXPECT_NE(svgNode, nullptr);
1636     RSCanvas canvas;
1637     Size size(10, 40);
1638     svgNode->OnFilter(canvas, size);
1639     EXPECT_EQ(size.Width(), 10);
1640     MockContainer::Current()->SetApiTargetVersion(backupApiVersion);
1641 }
1642 
1643 /**
1644  * @tc.name: CalcDstRect001
1645  * @tc.desc: test function of SvgImage.
1646  * @tc.type: FUNC
1647  */
1648 HWTEST_F(SvgTransformTestNg, SvgNodeTest008, TestSize.Level1)
1649 {
1650     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1651     EXPECT_NE(svgNode, nullptr);
1652     RSCanvas canvas;
1653     Size size(10, 10);
1654 
1655     svgNode->hrefFilterId_ = "href";
1656     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1657     EXPECT_NE(svgContext, nullptr);
1658     RefPtr<SvgNode> svgNode2 = SvgPattern::Create();
1659     EXPECT_NE(svgNode2, nullptr);
1660     svgContext->Push("href", svgNode2);
1661     svgNode->SetContext(svgContext);
1662     svgNode->OnFilter(canvas, size);
1663     EXPECT_EQ(size.Width(), 10);
1664 }
1665 
1666 /**
1667  * @tc.name: CalcDstRect001
1668  * @tc.desc: test function of SvgImage.
1669  * @tc.type: FUNC
1670  */
1671 HWTEST_F(SvgTransformTestNg, SvgNodeTest009, TestSize.Level1)
1672 {
1673     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1674     EXPECT_NE(svgNode, nullptr);
1675     RSCanvas canvas;
1676     Rect rect(10, 12, 13, 15);
1677     Size size(10, 10);
1678     SvgCoordinateSystemContext context(rect, size);
1679 
1680     svgNode->hrefFilterId_ = "href";
1681     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1682     EXPECT_NE(svgContext, nullptr);
1683     RefPtr<SvgNode> svgNode2 = SvgPattern::Create();
1684     EXPECT_NE(svgNode2, nullptr);
1685     svgContext->Push("href", svgNode2);
1686     svgNode->SetContext(svgContext);
1687     svgNode->OnFilter(canvas, context);
1688 
1689     svgNode->OnMask(canvas, size);
1690     EXPECT_EQ(size.Width(), 10);
1691 }
1692 
1693 /**
1694  * @tc.name: CalcDstRect001
1695  * @tc.desc: test function of SvgImage.
1696  * @tc.type: FUNC
1697  */
1698 HWTEST_F(SvgTransformTestNg, SvgNodeTest010, TestSize.Level1)
1699 {
1700     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1701     EXPECT_NE(svgNode, nullptr);
1702     RSCanvas canvas;
1703     Rect rect(10, 12, 13, 15);
1704     Size size(10, 10);
1705     SvgCoordinateSystemContext context(rect, size);
1706     svgNode->hrefMaskId_ = "href";
1707     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1708     EXPECT_NE(svgContext, nullptr);
1709     svgNode->SetContext(svgContext);
1710     svgNode->OnMask(canvas, context);
1711 
1712     RefPtr<SvgNode> svgNode2 = SvgPattern::Create();
1713     EXPECT_NE(svgNode2, nullptr);
1714     svgContext->Push("href", svgNode2);
1715     svgNode->SetContext(svgContext);
1716 
1717     svgNode->OnMask(canvas, context);
1718     EXPECT_EQ(size.Width(), 10);
1719 }
1720 
1721 /**
1722  * @tc.name: CalcDstRect001
1723  * @tc.desc: test function of SvgImage.
1724  * @tc.type: FUNC
1725  */
1726 HWTEST_F(SvgTransformTestNg, SvgNodeTest011, TestSize.Level1)
1727 {
1728     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1729     EXPECT_NE(svgNode, nullptr);
1730     RSCanvas canvas;
1731     Rect rect(10, 10, 50, 50);
1732     Size size(80, 80);
1733     SvgLengthScaleRule rule(rect, size, SvgLengthScaleUnit::USER_SPACE_ON_USE);
1734     svgNode->attributes_.href = "";
1735     svgNode->OnTransform(canvas, rule);
1736 
1737     svgNode->attributes_.href = "href";
1738     svgNode->OnTransform(canvas, rule);
1739 
1740     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1741     EXPECT_NE(svgContext, nullptr);
1742     svgNode->SetContext(svgContext);
1743     svgNode->attributes_.href = "";
1744     svgNode->OnTransform(canvas, rule);
1745 
1746     svgNode->attributes_.href = "href";
1747     svgNode->OnTransform(canvas, rule);
1748     EXPECT_EQ(size.Width(), 80);
1749 }
1750 
1751 /**
1752  * @tc.name: CalcDstRect001
1753  * @tc.desc: test function of SvgImage.
1754  * @tc.type: FUNC
1755  */
1756 HWTEST_F(SvgTransformTestNg, SvgNodeTest012, TestSize.Level1)
1757 {
1758     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1759     EXPECT_NE(svgNode, nullptr);
1760     RSCanvas canvas;
1761     Rect rect(10, 10, 50, 50);
1762     Size size(80, 80);
1763     SvgLengthScaleRule rule(rect, size, SvgLengthScaleUnit::OBJECT_BOUNDING_BOX);
1764     svgNode->attributes_.href = "";
1765     svgNode->OnTransform(canvas, rule);
1766 
1767     svgNode->attributes_.href = "href";
1768     svgNode->OnTransform(canvas, rule);
1769 
1770     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1771     EXPECT_NE(svgContext, nullptr);
1772     svgNode->SetContext(svgContext);
1773     svgNode->attributes_.href = "";
1774     svgNode->OnTransform(canvas, rule);
1775 
1776     svgNode->attributes_.href = "href";
1777     svgNode->OnTransform(canvas, rule);
1778 
1779     auto svgPattern = AceType::MakeRefPtr<SvgPattern>();
1780     EXPECT_NE(svgPattern, nullptr);
1781     svgContext->Push("href", svgPattern);
1782     svgNode->OnTransform(canvas, rule);
1783     EXPECT_EQ(size.Width(), 80);
1784 }
1785 
1786 /**
1787  * @tc.name: CalcDstRect001
1788  * @tc.desc: test function of SvgImage.
1789  * @tc.type: FUNC
1790  */
1791 HWTEST_F(SvgTransformTestNg, SvgNodeTest013, TestSize.Level1)
1792 {
1793     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1794     EXPECT_NE(svgNode, nullptr);
1795     Rect rect(10, 10, 50, 50);
1796     Size size(80, 80);
1797     Dimension dimension = 1.0_vp;
1798 
1799     SvgLengthScaleRule rule(rect, size, SvgLengthScaleUnit::OBJECT_BOUNDING_BOX);
1800     auto length = svgNode->GetMeasuredLength(dimension, rule, SvgLengthType::HORIZONTAL);
1801     EXPECT_EQ(length, 0.0f);
1802     length = svgNode->GetMeasuredLength(dimension, rule, SvgLengthType::VERTICAL);
1803     EXPECT_EQ(length, 0.0f);
1804 
1805     length = svgNode->GetMeasuredLength(dimension, rule, SvgLengthType::OTHER);
1806     EXPECT_EQ(length, 0.0f);
1807     length = svgNode->GetMeasuredLength(dimension, rule, static_cast<SvgLengthType>(-1));
1808     EXPECT_EQ(length, 0.0f);
1809     SvgLengthScaleRule rule1(rect, size, SvgLengthScaleUnit::USER_SPACE_ON_USE);
1810     length = svgNode->GetMeasuredLength(dimension, rule, SvgLengthType::VERTICAL);
1811     EXPECT_EQ(length, 0.0f);
1812 }
1813 
1814 /**
1815  * @tc.name: CalcDstRect001
1816  * @tc.desc: test function of SvgImage.
1817  * @tc.type: FUNC
1818  */
1819 HWTEST_F(SvgTransformTestNg, SvgNodeTest014, TestSize.Level1)
1820 {
1821     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1822     EXPECT_NE(svgNode, nullptr);
1823     auto rect = svgNode->GetSvgContainerRect();
1824     EXPECT_EQ(rect.Width(), 0.0f);
1825     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1826     EXPECT_NE(svgContext, nullptr);
1827     svgNode->SetContext(svgContext);
1828     rect = svgNode->GetSvgContainerRect();
1829     EXPECT_EQ(rect.Width(), 0.0f);
1830 }
1831 
1832 /**
1833  * @tc.name: CalcDstRect001
1834  * @tc.desc: test function of SvgImage.
1835  * @tc.type: FUNC
1836  */
1837 HWTEST_F(SvgTransformTestNg, SvgNodeTest015, TestSize.Level1)
1838 {
1839     auto svgNode = AceType::MakeRefPtr<SvgNode>();
1840     EXPECT_NE(svgNode, nullptr);
1841     Dimension firstDimension(0.5f, DimensionUnit::PERCENT);
1842     Dimension secondDimension(0.5f, DimensionUnit::PERCENT);
1843     std::pair<Dimension, Dimension> transformOrigin = { firstDimension, secondDimension };
1844     SvgLengthScaleRule lengthRule;
1845     auto offset = svgNode->CalcGlobalPivot(transformOrigin, lengthRule);
1846     EXPECT_EQ(offset.GetX(), 0.0f);
1847 
1848     Dimension firstDimension1(0.5f, DimensionUnit::PX);
1849     Dimension secondDimension2(0.5f, DimensionUnit::PX);
1850     std::pair<Dimension, Dimension> transformOrigin1 = { firstDimension1, secondDimension2 };
1851     SvgLengthScaleRule lengthRule2;
1852     auto svgContext = AceType::MakeRefPtr<SvgContext>();
1853     EXPECT_NE(svgContext, nullptr);
1854     Rect rootRect(0, 0, 10, 10);
1855     svgContext->SetRootViewBox(rootRect);
1856     svgNode->SetContext(svgContext);
1857     offset = svgNode->CalcGlobalPivot(transformOrigin1, lengthRule2);
1858     EXPECT_EQ(offset.GetX(), 0.5f);
1859 }
1860 } // namespace OHOS::Ace::NG