1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "gtest/gtest.h"
17
18 #include "base/json/json_util.h"
19 #include "base/utils/utils.h"
20 #include "core/components/common/layout/constants.h"
21 #include "frameworks/bridge/common/dom/dom_document.h"
22 #include "frameworks/bridge/common/dom/dom_svg.h"
23 #include "frameworks/bridge/common/dom/dom_svg_animate.h"
24 #include "frameworks/bridge/common/dom/dom_svg_animate_motion.h"
25 #include "frameworks/bridge/common/dom/dom_svg_circle.h"
26 #include "frameworks/bridge/common/dom/dom_svg_ellipse.h"
27 #include "frameworks/bridge/common/dom/dom_svg_line.h"
28 #include "frameworks/bridge/common/dom/dom_svg_path.h"
29 #include "frameworks/bridge/common/dom/dom_svg_polygon.h"
30 #include "frameworks/bridge/common/dom/dom_svg_polyline.h"
31 #include "frameworks/bridge/common/dom/dom_svg_rect.h"
32 #include "frameworks/bridge/test/unittest/jsfrontend/dom_node_factory.h"
33
34 using namespace testing;
35 using namespace testing::ext;
36
37 namespace OHOS::Ace::Framework {
38
39 class DomSvgTest : public testing::Test {
40 public:
41 static void SetUpTestCase();
42 static void TearDownTestCase();
43 void SetUp();
44 void TearDown();
45 void CheckPresentationAttrs(const RefPtr<SvgBaseDeclaration>& baseDeclaration);
46 };
47
SetUpTestCase()48 void DomSvgTest::SetUpTestCase() {}
TearDownTestCase()49 void DomSvgTest::TearDownTestCase() {}
SetUp()50 void DomSvgTest::SetUp() {}
TearDown()51 void DomSvgTest::TearDown() {}
52
CheckPresentationAttrs(const RefPtr<SvgBaseDeclaration> & baseDeclaration)53 void DomSvgTest::CheckPresentationAttrs(const RefPtr<SvgBaseDeclaration>& baseDeclaration)
54 {
55 /**
56 * @tc.steps: step1. Check styles and attributes of created node.
57 * @tc.expected: step1. The styles and attributes are as expected.
58 */
59 EXPECT_NEAR(baseDeclaration->GetOpacity(), 0.8, FLT_EPSILON);
60 ASSERT_TRUE(baseDeclaration->GetFillState().GetColor() == Color::RED);
61 EXPECT_NEAR(baseDeclaration->GetFillState().GetOpacity().GetValue(), 0.5, FLT_EPSILON);
62 ASSERT_TRUE(baseDeclaration->GetStrokeState().GetColor() == Color::BLUE);
63 EXPECT_NEAR(baseDeclaration->GetStrokeState().GetOpacity().GetValue(), 0.3, FLT_EPSILON);
64 EXPECT_NEAR(baseDeclaration->GetStrokeState().GetLineDash().dashOffset, 2.0, FLT_EPSILON);
65 ASSERT_TRUE(baseDeclaration->GetStrokeState().GetLineDash().lineDash.size() == 2);
66 EXPECT_NEAR(baseDeclaration->GetStrokeState().GetLineDash().lineDash.at(0), 8.0, FLT_EPSILON);
67 EXPECT_NEAR(baseDeclaration->GetStrokeState().GetLineDash().lineDash.at(1), 4.0, FLT_EPSILON);
68 ASSERT_TRUE(baseDeclaration->GetStrokeState().GetLineCap() == LineCapStyle::BUTT);
69 ASSERT_TRUE(baseDeclaration->GetStrokeState().GetLineJoin() == LineJoinStyle::MITER);
70 EXPECT_NEAR(baseDeclaration->GetStrokeState().GetMiterLimit(), 2.0, FLT_EPSILON);
71 }
72
73 /**
74 * @tc.name: DomSvgTest001
75 * @tc.desc: Verify that DomSvg can be created and set attrs correctly.
76 * @tc.type: FUNC
77 */
78 HWTEST_F(DomSvgTest, DomSvgTest001, TestSize.Level1)
79 {
80 const std::string jsonStr = ""
81 "{ "
82 " \"tag\": \"svg\", "
83 " \"attr\": [{ "
84 " \"x\" : \"10\" "
85 " }, "
86 " { "
87 " \"y\" : \"20\" "
88 " }, "
89 " { "
90 " \"width\" : \"100\" "
91 " }, "
92 " { "
93 " \"height\" : \"50\" "
94 " }, "
95 " { "
96 " \"viewbox\" : \"0 0 100 50\" "
97 " }] "
98 "}";
99
100 /**
101 * @tc.steps: step1. Construct string with right fields, then create svg node with it.
102 * @tc.expected: step1. svg node are created successfully.
103 */
104 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
105 ASSERT_TRUE(domNodeRoot != nullptr);
106 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
107 RefPtr<SvgComponent> svgComponent = AceType::DynamicCast<SvgComponent>(boxChild->GetChild());
108 ASSERT_TRUE(svgComponent != nullptr);
109 /**
110 * @tc.steps: step2. Check styles and attributes of created node.
111 * @tc.expected: step2. The styles and attributes are as expected.
112 */
113 EXPECT_NEAR(svgComponent->GetX().Value(), 10.0, FLT_EPSILON);
114 EXPECT_NEAR(svgComponent->GetY().Value(), 20.0, FLT_EPSILON);
115 EXPECT_NEAR(svgComponent->GetWidth().Value(), 100.0, FLT_EPSILON);
116 EXPECT_NEAR(svgComponent->GetHeight().Value(), 50.0, FLT_EPSILON);
117 ASSERT_TRUE(svgComponent->GetViewBox() == Rect(0.0, 0.0, 100.0, 50.0));
118 }
119
120 /**
121 * @tc.name: DomSvgTest002
122 * @tc.desc: Verify that DomSvg can be created and set common attrs correctly.
123 * @tc.type: FUNC
124 */
125 HWTEST_F(DomSvgTest, DomSvgTest002, TestSize.Level1)
126 {
127 /**
128 * @tc.steps: step1. Construct string with right fields, then create svg node with it.
129 * @tc.expected: step1. svg node are created successfully.
130 */
131 const std::string jsonStr = ""
132 "{ "
133 " \"tag\": \"svg\", "
134 " \"attr\": [{ "
135 " \"fill\" : \"red\" "
136 " }, "
137 " { "
138 " \"fillOpacity\" : \"0.5\" "
139 " }, "
140 " { "
141 " \"stroke\" : \"blue\" "
142 " }, "
143 " { "
144 " \"strokeWidth\" : \"5\" "
145 " }, "
146 " { "
147 " \"strokeDasharray\" : \"8 4\" "
148 " }, "
149 " { "
150 " \"strokeDashoffset\" : \"2\" "
151 " }, "
152 " { "
153 " \"strokeLinecap\" : \"butt\" "
154 " }, "
155 " { "
156 " \"strokeLinejoin\" : \"miter\""
157 " }, "
158 " { "
159 " \"strokeMiterlimit\" : \"2\" "
160 " }, "
161 " { "
162 " \"strokeOpacity\" : \"0.3\" "
163 " }, "
164 " { "
165 " \"opacity\" : \"0.8\" "
166 " }] "
167 "}";
168 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
169 ASSERT_TRUE(domNodeRoot != nullptr);
170 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
171 RefPtr<SvgComponent> svgComponent = AceType::DynamicCast<SvgComponent>(boxChild->GetChild());
172 ASSERT_TRUE(svgComponent != nullptr);
173 /**
174 * @tc.steps: step2. Check styles and attributes of created svg node.
175 * @tc.expected: step2. The styles and attributes are as expected.
176 */
177 CheckPresentationAttrs(svgComponent->GetDeclaration());
178 }
179
180 /**
181 * @tc.name: DomSvgTest003
182 * @tc.desc: Verify that DomSvgRect can be created and set attrs correctly.
183 * @tc.type: FUNC
184 */
185 HWTEST_F(DomSvgTest, DomSvgTest003, TestSize.Level1)
186 {
187 const std::string jsonStr = ""
188 "{ "
189 " \"tag\": \"rect\", "
190 " \"attr\": [{ "
191 " \"x\" : \"10\" "
192 " }, "
193 " { "
194 " \"y\" : \"20\" "
195 " }, "
196 " { "
197 " \"width\" : \"100\" "
198 " }, "
199 " { "
200 " \"height\" : \"50\" "
201 " }, "
202 " { "
203 " \"rx\" : \"5\" "
204 " }, "
205 " { "
206 " \"ry\" : \"3\" "
207 " }] "
208 "}";
209
210 /**
211 * @tc.steps: step1. Construct string with right fields, then create svg rect node with it.
212 * @tc.expected: step1. svg rect node are created successfully.
213 */
214 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
215 ASSERT_TRUE(domNodeRoot != nullptr);
216 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
217 RefPtr<SvgRectComponent> component = AceType::DynamicCast<SvgRectComponent>(boxChild->GetChild());
218 ASSERT_TRUE(component != nullptr);
219 /**
220 * @tc.steps: step2. Check styles and attributes of created rect node.
221 * @tc.expected: step2. The styles and attributes are as expected.
222 */
223 EXPECT_NEAR(component->GetX().Value(), 10.0, FLT_EPSILON);
224 EXPECT_NEAR(component->GetY().Value(), 20.0, FLT_EPSILON);
225 EXPECT_NEAR(component->GetWidth().Value(), 100.0, FLT_EPSILON);
226 EXPECT_NEAR(component->GetHeight().Value(), 50.0, FLT_EPSILON);
227 EXPECT_NEAR(component->GetRx().Value(), 5.0, FLT_EPSILON);
228 EXPECT_NEAR(component->GetRy().Value(), 3.0, FLT_EPSILON);
229 }
230
231 /**
232 * @tc.name: DomSvgTest004
233 * @tc.desc: Verify that DomSvgCircle can be created and set attrs correctly.
234 * @tc.type: FUNC
235 */
236 HWTEST_F(DomSvgTest, DomSvgTest004, TestSize.Level1)
237 {
238 const std::string jsonStr = ""
239 "{ "
240 " \"tag\": \"circle\", "
241 " \"attr\": [{ "
242 " \"cx\" : \"20\" "
243 " }, "
244 " { "
245 " \"cy\" : \"30\" "
246 " }, "
247 " { "
248 " \"r\" : \"50\" "
249 " }] "
250 "}";
251
252 /**
253 * @tc.steps: step1. Construct string with right fields, then create svg circle node with it.
254 * @tc.expected: step1. svg circle node are created successfully.
255 */
256 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
257 ASSERT_TRUE(domNodeRoot != nullptr);
258 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
259 RefPtr<SvgCircleComponent> component = AceType::DynamicCast<SvgCircleComponent>(boxChild->GetChild());
260 ASSERT_TRUE(component != nullptr);
261 /**
262 * @tc.steps: step2. Check styles and attributes of created circle node.
263 * @tc.expected: step2. The styles and attributes are as expected.
264 */
265 EXPECT_NEAR(component->GetCx().Value(), 20.0, FLT_EPSILON);
266 EXPECT_NEAR(component->GetCy().Value(), 30.0, FLT_EPSILON);
267 EXPECT_NEAR(component->GetR().Value(), 50.0, FLT_EPSILON);
268 }
269
270 /**
271 * @tc.name: DomSvgTest005
272 * @tc.desc: Verify that DomSvgEllipse can be created and set attrs correctly.
273 * @tc.type: FUNC
274 */
275 HWTEST_F(DomSvgTest, DomSvgTest005, TestSize.Level1)
276 {
277 const std::string jsonStr = ""
278 "{ "
279 " \"tag\": \"ellipse\", "
280 " \"attr\": [{ "
281 " \"cx\" : \"20\" "
282 " }, "
283 " { "
284 " \"cy\" : \"30\" "
285 " }, "
286 " { "
287 " \"rx\" : \"50\" "
288 " }, "
289 " { "
290 " \"ry\" : \"40\" "
291 " }] "
292 "}";
293
294 /**
295 * @tc.steps: step1. Construct string with right fields, then create svg ellipse node with it.
296 * @tc.expected: step1. svg ellipse node are created successfully.
297 */
298 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
299 ASSERT_TRUE(domNodeRoot != nullptr);
300 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
301 RefPtr<SvgEllipseComponent> component = AceType::DynamicCast<SvgEllipseComponent>(boxChild->GetChild());
302 ASSERT_TRUE(component != nullptr);
303 /**
304 * @tc.steps: step2. Check styles and attributes of created ellipse node.
305 * @tc.expected: step2. The styles and attributes are as expected.
306 */
307 EXPECT_NEAR(component->GetCx().Value(), 20.0, FLT_EPSILON);
308 EXPECT_NEAR(component->GetCy().Value(), 30.0, FLT_EPSILON);
309 EXPECT_NEAR(component->GetRx().Value(), 50.0, FLT_EPSILON);
310 EXPECT_NEAR(component->GetRy().Value(), 40.0, FLT_EPSILON);
311 }
312
313 /**
314 * @tc.name: DomSvgTest006
315 * @tc.desc: Verify that DomSvgPath can be created and set attrs correctly.
316 * @tc.type: FUNC
317 */
318 HWTEST_F(DomSvgTest, DomSvgTest006, TestSize.Level1)
319 {
320 const std::string jsonStr = ""
321 "{ "
322 " \"tag\": \"path\", "
323 " \"attr\": [{ "
324 " \"d\" : \"M20,50 C20,-50 180,150 180,50 C180,-50 20,150 20,50 z\""
325 " }] "
326 "}";
327
328 /**
329 * @tc.steps: step1. Construct string with right fields, then create svg path node with it.
330 * @tc.expected: step1. svg path node are created successfully.
331 */
332 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
333 ASSERT_TRUE(domNodeRoot != nullptr);
334 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
335 RefPtr<SvgPathComponent> component = AceType::DynamicCast<SvgPathComponent>(boxChild->GetChild());
336 ASSERT_TRUE(component != nullptr);
337 /**
338 * @tc.steps: step2. Check styles and attributes of created path node.
339 * @tc.expected: step2. The styles and attributes are as expected.
340 */
341 ASSERT_TRUE(component->GetD() == "M20,50 C20,-50 180,150 180,50 C180,-50 20,150 20,50 z");
342 }
343
344 /**
345 * @tc.name: DomSvgTest007
346 * @tc.desc: Verify that DomSvgLine can be created and set attrs correctly.
347 * @tc.type: FUNC
348 */
349 HWTEST_F(DomSvgTest, DomSvgTest007, TestSize.Level1)
350 {
351 const std::string jsonStr = ""
352 "{ "
353 " \"tag\": \"line\", "
354 " \"attr\": [{ "
355 " \"x1\" : \"10\" "
356 " }, "
357 " { "
358 " \"y1\" : \"20\" "
359 " }, "
360 " { "
361 " \"x2\" : \"60\" "
362 " }, "
363 " { "
364 " \"y2\" : \"50\" "
365 " }] "
366 "}";
367
368 /**
369 * @tc.steps: step1. Construct string with right fields, then create svg line node with it.
370 * @tc.expected: step1. svg line node are created successfully.
371 */
372 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
373 ASSERT_TRUE(domNodeRoot != nullptr);
374 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
375 RefPtr<SvgLineComponent> component = AceType::DynamicCast<SvgLineComponent>(boxChild->GetChild());
376 ASSERT_TRUE(component != nullptr);
377 /**
378 * @tc.steps: step2. Check styles and attributes of created line node.
379 * @tc.expected: step2. The styles and attributes are as expected.
380 */
381 EXPECT_NEAR(component->GetX1().Value(), 10.0, FLT_EPSILON);
382 EXPECT_NEAR(component->GetY1().Value(), 20.0, FLT_EPSILON);
383 EXPECT_NEAR(component->GetX2().Value(), 60.0, FLT_EPSILON);
384 EXPECT_NEAR(component->GetY2().Value(), 50.0, FLT_EPSILON);
385 }
386
387 /**
388 * @tc.name: DomSvgTest008
389 * @tc.desc: Verify that DomSvgPolyline can be created and set attrs correctly.
390 * @tc.type: FUNC
391 */
392 HWTEST_F(DomSvgTest, DomSvgTest008, TestSize.Level1)
393 {
394 const std::string jsonStr = ""
395 "{ "
396 " \"tag\": \"polyline\", "
397 " \"attr\": [{ "
398 " \"points\" : \"0,400 60,325 70,375 100,300\""
399 " }] "
400 "}";
401
402 /**
403 * @tc.steps: step1. Construct string with right fields, then create svg polyline node with it.
404 * @tc.expected: step1. svg polyline node are created successfully.
405 */
406 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
407 ASSERT_TRUE(domNodeRoot != nullptr);
408 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
409 RefPtr<SvgPolygonComponent> component = AceType::DynamicCast<SvgPolygonComponent>(boxChild->GetChild());
410 ASSERT_TRUE(component != nullptr);
411 /**
412 * @tc.steps: step2. Check styles and attributes of created polyline node.
413 * @tc.expected: step2. The styles and attributes are as expected.
414 */
415 ASSERT_TRUE(component->GetPoints() == "0,400 60,325 70,375 100,300");
416 }
417
418 /**
419 * @tc.name: DomSvgTest009
420 * @tc.desc: Verify that DomSvgPolygon can be created and set attrs correctly.
421 * @tc.type: FUNC
422 */
423 HWTEST_F(DomSvgTest, DomSvgTest009, TestSize.Level1)
424 {
425 const std::string jsonStr = ""
426 "{ "
427 " \"tag\": \"polygon\", "
428 " \"attr\": [{ "
429 " \"points\" : \"0,400 60,325 70,375 100,300\""
430 " }] "
431 "}";
432
433 /**
434 * @tc.steps: step1. Construct string with right fields, then create svg polygon node with it.
435 * @tc.expected: step1. svg polygon node are created successfully.
436 */
437 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
438 ASSERT_TRUE(domNodeRoot != nullptr);
439 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
440 RefPtr<SvgPolygonComponent> component = AceType::DynamicCast<SvgPolygonComponent>(boxChild->GetChild());
441 ASSERT_TRUE(component != nullptr);
442 /**
443 * @tc.steps: step2. Check styles and attributes of created polygon node.
444 * @tc.expected: step2. The styles and attributes are as expected.
445 */
446 ASSERT_TRUE(component->GetPoints() == "0,400 60,325 70,375 100,300");
447 }
448
449 /**
450 * @tc.name: DomSvgTest010
451 * @tc.desc: Verify that DomSvgAnimate can be created and set attrs correctly.
452 * @tc.type: FUNC
453 */
454 HWTEST_F(DomSvgTest, DomSvgTest010, TestSize.Level1)
455 {
456 const std::string jsonStr = ""
457 "{ "
458 " \"tag\": \"animate\", "
459 " \"attr\": [{ "
460 " \"begin\" : \"200\" "
461 " }, "
462 " { "
463 " \"dur\" : \"2000\" "
464 " }, "
465 " { "
466 " \"repeatcount\" : \"3\" "
467 " }, "
468 " { "
469 " \"fill\" : \"freeze\" "
470 " }, "
471 " { "
472 " \"calcmode\" : \"linear\" "
473 " }, "
474 " { "
475 " \"from\" : \"100\" "
476 " }, "
477 " { "
478 " \"to\" : \"300\" "
479 " }, "
480 " { "
481 " \"attributename\" : \"width\" "
482 " }] "
483 "}";
484
485 /**
486 * @tc.steps: step1. Construct string with right fields, then create svg animate node with it.
487 * @tc.expected: step1. svg animate node are created successfully.
488 */
489 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
490 ASSERT_TRUE(domNodeRoot != nullptr);
491 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
492 RefPtr<SvgAnimateComponent> component = AceType::DynamicCast<SvgAnimateComponent>(boxChild->GetChild());
493 ASSERT_TRUE(component != nullptr);
494 /**
495 * @tc.steps: step2. Check styles and attributes of created animate node.
496 * @tc.expected: step2. The styles and attributes are as expected.
497 */
498 ASSERT_TRUE(component->GetBegin() == 200);
499 ASSERT_TRUE(component->GetDur() == 2000);
500 ASSERT_TRUE(component->GetRepeatCount() == 3);
501 ASSERT_TRUE(component->GetFillMode() == FillMode::FORWARDS);
502 ASSERT_TRUE(component->GetCalcMode() == CalcMode::LINEAR);
503 ASSERT_TRUE(component->GetAttributeName() == "width");
504 ASSERT_TRUE(component->GetFrom() == "100");
505 ASSERT_TRUE(component->GetTo() == "300");
506 }
507
508 /**
509 * @tc.name: DomSvgTest011
510 * @tc.desc: Verify that DomSvgAnimateMotion can be created and set attrs correctly.
511 * @tc.type: FUNC
512 */
513 HWTEST_F(DomSvgTest, DomSvgTest011, TestSize.Level1)
514 {
515 const std::string jsonStr = ""
516 "{ "
517 " \"tag\": \"animatemotion\", "
518 " \"attr\": [{ "
519 " \"begin\" : \"200\" "
520 " }, "
521 " { "
522 " \"dur\" : \"2000\" "
523 " }, "
524 " { "
525 " \"repeatcount\" : \"3\" "
526 " }, "
527 " { "
528 " \"fill\" : \"freeze\" "
529 " }, "
530 " { "
531 " \"calcmode\" : \"spline\" "
532 " }, "
533 " { "
534 " \"keypoints\" : \"0;0.2;0.5;1\" "
535 " }, "
536 " { "
537 " \"keytimes\" : \"0;0.1;0.8;1\" "
538 " }, "
539 " { "
540 " \"path\" : \"M20,50 C20,-50 180,150 180,50 C180,-50 20,150 20,50 z\""
541 " }, "
542 " { "
543 " \"rotate\" : \"auto\" "
544 " }, "
545 " { "
546 " \"keysplines\" : \"0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1\" "
547 " }] "
548 "}";
549
550 /**
551 * @tc.steps: step1. Construct string with right fields, then create svg animate motion node with it.
552 * @tc.expected: step1. svg animate motion node are created successfully.
553 */
554 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
555 ASSERT_TRUE(domNodeRoot != nullptr);
556 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
557 RefPtr<SvgAnimateComponent> component = AceType::DynamicCast<SvgAnimateComponent>(boxChild->GetChild());
558 ASSERT_TRUE(component != nullptr);
559 /**
560 * @tc.steps: step2. Check styles and attributes of created animate motion node.
561 * @tc.expected: step2. The styles and attributes are as expected.
562 */
563 ASSERT_TRUE(component->GetBegin() == 200);
564 ASSERT_TRUE(component->GetDur() == 2000);
565 ASSERT_TRUE(component->GetRepeatCount() == 3);
566 ASSERT_TRUE(component->GetFillMode() == FillMode::FORWARDS);
567 ASSERT_TRUE(component->GetCalcMode() == CalcMode::SPLINE);
568 ASSERT_TRUE(component->GetKeyTimes().size() == 4);
569 EXPECT_NEAR(component->GetKeyTimes().at(0), 0.0, FLT_EPSILON);
570 EXPECT_NEAR(component->GetKeyTimes().at(1), 0.1, FLT_EPSILON);
571 EXPECT_NEAR(component->GetKeyTimes().at(2), 0.8, FLT_EPSILON);
572 EXPECT_NEAR(component->GetKeyTimes().at(3), 1.0, FLT_EPSILON);
573 ASSERT_TRUE(component->GetKeyPoints().size() == 4);
574 ASSERT_TRUE(component->GetKeyPoints().at(0) == "0");
575 ASSERT_TRUE(component->GetKeyPoints().at(1) == "0.2");
576 ASSERT_TRUE(component->GetKeyPoints().at(2) == "0.5");
577 ASSERT_TRUE(component->GetKeyPoints().at(3) == "1");
578 ASSERT_TRUE(component->GetKeySplines().size() == 3);
579 ASSERT_TRUE(component->GetKeySplines().at(0) == "0.5 0 0.5 1");
580 ASSERT_TRUE(component->GetKeySplines().at(1) == "0.5 0 0.5 1");
581 ASSERT_TRUE(component->GetKeySplines().at(2) == "0.5 0 0.5 1");
582 ASSERT_TRUE(component->GetPath() == "M20,50 C20,-50 180,150 180,50 C180,-50 20,150 20,50 z");
583 ASSERT_TRUE(component->GetRotate() == "auto");
584 }
585
586 } // namespace OHOS::Ace::Framework
587