1 /*
2 * Copyright (c) 2021 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 * @tc.require: AR000FL0TG
78 * @tc.author: chenlien
79 */
80 HWTEST_F(DomSvgTest, DomSvgTest001, TestSize.Level1)
81 {
82 const std::string jsonStr = ""
83 "{ "
84 " \"tag\": \"svg\", "
85 " \"attr\": [{ "
86 " \"x\" : \"10\" "
87 " }, "
88 " { "
89 " \"y\" : \"20\" "
90 " }, "
91 " { "
92 " \"width\" : \"100\" "
93 " }, "
94 " { "
95 " \"height\" : \"50\" "
96 " }, "
97 " { "
98 " \"viewbox\" : \"0 0 100 50\" "
99 " }] "
100 "}";
101
102 /**
103 * @tc.steps: step1. Construct string with right fields, then create svg node with it.
104 * @tc.expected: step1. svg node are created successfully.
105 */
106 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
107 ASSERT_TRUE(domNodeRoot != nullptr);
108 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
109 RefPtr<SvgComponent> svgComponent = AceType::DynamicCast<SvgComponent>(boxChild->GetChild());
110 ASSERT_TRUE(svgComponent != nullptr);
111 /**
112 * @tc.steps: step2. Check styles and attributes of created node.
113 * @tc.expected: step2. The styles and attributes are as expected.
114 */
115 EXPECT_NEAR(svgComponent->GetX().Value(), 10.0, FLT_EPSILON);
116 EXPECT_NEAR(svgComponent->GetY().Value(), 20.0, FLT_EPSILON);
117 EXPECT_NEAR(svgComponent->GetWidth().Value(), 100.0, FLT_EPSILON);
118 EXPECT_NEAR(svgComponent->GetHeight().Value(), 50.0, FLT_EPSILON);
119 ASSERT_TRUE(svgComponent->GetViewBox() == Rect(0.0, 0.0, 100.0, 50.0));
120 }
121
122 /**
123 * @tc.name: DomSvgTest002
124 * @tc.desc: Verify that DomSvg can be created and set common attrs correctly.
125 * @tc.type: FUNC
126 * @tc.require: AR000FL0TG
127 * @tc.author: chenlien
128 */
129 HWTEST_F(DomSvgTest, DomSvgTest002, TestSize.Level1)
130 {
131 /**
132 * @tc.steps: step1. Construct string with right fields, then create svg node with it.
133 * @tc.expected: step1. svg node are created successfully.
134 */
135 const std::string jsonStr = ""
136 "{ "
137 " \"tag\": \"svg\", "
138 " \"attr\": [{ "
139 " \"fill\" : \"red\" "
140 " }, "
141 " { "
142 " \"fillOpacity\" : \"0.5\" "
143 " }, "
144 " { "
145 " \"stroke\" : \"blue\" "
146 " }, "
147 " { "
148 " \"strokeWidth\" : \"5\" "
149 " }, "
150 " { "
151 " \"strokeDasharray\" : \"8 4\" "
152 " }, "
153 " { "
154 " \"strokeDashoffset\" : \"2\" "
155 " }, "
156 " { "
157 " \"strokeLinecap\" : \"butt\" "
158 " }, "
159 " { "
160 " \"strokeLinejoin\" : \"miter\""
161 " }, "
162 " { "
163 " \"strokeMiterlimit\" : \"2\" "
164 " }, "
165 " { "
166 " \"strokeOpacity\" : \"0.3\" "
167 " }, "
168 " { "
169 " \"opacity\" : \"0.8\" "
170 " }] "
171 "}";
172 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
173 ASSERT_TRUE(domNodeRoot != nullptr);
174 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
175 RefPtr<SvgComponent> svgComponent = AceType::DynamicCast<SvgComponent>(boxChild->GetChild());
176 ASSERT_TRUE(svgComponent != nullptr);
177 /**
178 * @tc.steps: step2. Check styles and attributes of created svg node.
179 * @tc.expected: step2. The styles and attributes are as expected.
180 */
181 CheckPresentationAttrs(svgComponent->GetDeclaration());
182 }
183
184 /**
185 * @tc.name: DomSvgTest003
186 * @tc.desc: Verify that DomSvgRect can be created and set attrs correctly.
187 * @tc.type: FUNC
188 * @tc.require: AR000FL0TH
189 * @tc.author: chenlien
190 */
191 HWTEST_F(DomSvgTest, DomSvgTest003, TestSize.Level1)
192 {
193 const std::string jsonStr = ""
194 "{ "
195 " \"tag\": \"rect\", "
196 " \"attr\": [{ "
197 " \"x\" : \"10\" "
198 " }, "
199 " { "
200 " \"y\" : \"20\" "
201 " }, "
202 " { "
203 " \"width\" : \"100\" "
204 " }, "
205 " { "
206 " \"height\" : \"50\" "
207 " }, "
208 " { "
209 " \"rx\" : \"5\" "
210 " }, "
211 " { "
212 " \"ry\" : \"3\" "
213 " }] "
214 "}";
215
216 /**
217 * @tc.steps: step1. Construct string with right fields, then create svg rect node with it.
218 * @tc.expected: step1. svg rect node are created successfully.
219 */
220 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
221 ASSERT_TRUE(domNodeRoot != nullptr);
222 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
223 RefPtr<SvgRectComponent> component = AceType::DynamicCast<SvgRectComponent>(boxChild->GetChild());
224 ASSERT_TRUE(component != nullptr);
225 /**
226 * @tc.steps: step2. Check styles and attributes of created rect node.
227 * @tc.expected: step2. The styles and attributes are as expected.
228 */
229 EXPECT_NEAR(component->GetX().Value(), 10.0, FLT_EPSILON);
230 EXPECT_NEAR(component->GetY().Value(), 20.0, FLT_EPSILON);
231 EXPECT_NEAR(component->GetWidth().Value(), 100.0, FLT_EPSILON);
232 EXPECT_NEAR(component->GetHeight().Value(), 50.0, FLT_EPSILON);
233 EXPECT_NEAR(component->GetRx().Value(), 5.0, FLT_EPSILON);
234 EXPECT_NEAR(component->GetRy().Value(), 3.0, FLT_EPSILON);
235 }
236
237 /**
238 * @tc.name: DomSvgTest004
239 * @tc.desc: Verify that DomSvgCircle can be created and set attrs correctly.
240 * @tc.type: FUNC
241 * @tc.require: AR000FL0TH
242 * @tc.author: chenlien
243 */
244 HWTEST_F(DomSvgTest, DomSvgTest004, TestSize.Level1)
245 {
246 const std::string jsonStr = ""
247 "{ "
248 " \"tag\": \"circle\", "
249 " \"attr\": [{ "
250 " \"cx\" : \"20\" "
251 " }, "
252 " { "
253 " \"cy\" : \"30\" "
254 " }, "
255 " { "
256 " \"r\" : \"50\" "
257 " }] "
258 "}";
259
260 /**
261 * @tc.steps: step1. Construct string with right fields, then create svg circle node with it.
262 * @tc.expected: step1. svg circle node are created successfully.
263 */
264 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
265 ASSERT_TRUE(domNodeRoot != nullptr);
266 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
267 RefPtr<SvgCircleComponent> component = AceType::DynamicCast<SvgCircleComponent>(boxChild->GetChild());
268 ASSERT_TRUE(component != nullptr);
269 /**
270 * @tc.steps: step2. Check styles and attributes of created circle node.
271 * @tc.expected: step2. The styles and attributes are as expected.
272 */
273 EXPECT_NEAR(component->GetCx().Value(), 20.0, FLT_EPSILON);
274 EXPECT_NEAR(component->GetCy().Value(), 30.0, FLT_EPSILON);
275 EXPECT_NEAR(component->GetR().Value(), 50.0, FLT_EPSILON);
276 }
277
278 /**
279 * @tc.name: DomSvgTest005
280 * @tc.desc: Verify that DomSvgEllipse can be created and set attrs correctly.
281 * @tc.type: FUNC
282 * @tc.require: AR000FL0TJ
283 * @tc.author: chenlien
284 */
285 HWTEST_F(DomSvgTest, DomSvgTest005, TestSize.Level1)
286 {
287 const std::string jsonStr = ""
288 "{ "
289 " \"tag\": \"ellipse\", "
290 " \"attr\": [{ "
291 " \"cx\" : \"20\" "
292 " }, "
293 " { "
294 " \"cy\" : \"30\" "
295 " }, "
296 " { "
297 " \"rx\" : \"50\" "
298 " }, "
299 " { "
300 " \"ry\" : \"40\" "
301 " }] "
302 "}";
303
304 /**
305 * @tc.steps: step1. Construct string with right fields, then create svg ellipse node with it.
306 * @tc.expected: step1. svg ellipse node are created successfully.
307 */
308 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
309 ASSERT_TRUE(domNodeRoot != nullptr);
310 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
311 RefPtr<SvgEllipseComponent> component = AceType::DynamicCast<SvgEllipseComponent>(boxChild->GetChild());
312 ASSERT_TRUE(component != nullptr);
313 /**
314 * @tc.steps: step2. Check styles and attributes of created ellipse node.
315 * @tc.expected: step2. The styles and attributes are as expected.
316 */
317 EXPECT_NEAR(component->GetCx().Value(), 20.0, FLT_EPSILON);
318 EXPECT_NEAR(component->GetCy().Value(), 30.0, FLT_EPSILON);
319 EXPECT_NEAR(component->GetRx().Value(), 50.0, FLT_EPSILON);
320 EXPECT_NEAR(component->GetRy().Value(), 40.0, FLT_EPSILON);
321 }
322
323 /**
324 * @tc.name: DomSvgTest006
325 * @tc.desc: Verify that DomSvgPath can be created and set attrs correctly.
326 * @tc.type: FUNC
327 * @tc.require: AR000FL0TK
328 * @tc.author: chenlien
329 */
330 HWTEST_F(DomSvgTest, DomSvgTest006, TestSize.Level1)
331 {
332 const std::string jsonStr = ""
333 "{ "
334 " \"tag\": \"path\", "
335 " \"attr\": [{ "
336 " \"d\" : \"M20,50 C20,-50 180,150 180,50 C180,-50 20,150 20,50 z\""
337 " }] "
338 "}";
339
340 /**
341 * @tc.steps: step1. Construct string with right fields, then create svg path node with it.
342 * @tc.expected: step1. svg path node are created successfully.
343 */
344 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
345 ASSERT_TRUE(domNodeRoot != nullptr);
346 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
347 RefPtr<SvgPathComponent> component = AceType::DynamicCast<SvgPathComponent>(boxChild->GetChild());
348 ASSERT_TRUE(component != nullptr);
349 /**
350 * @tc.steps: step2. Check styles and attributes of created path node.
351 * @tc.expected: step2. The styles and attributes are as expected.
352 */
353 ASSERT_TRUE(component->GetD() == "M20,50 C20,-50 180,150 180,50 C180,-50 20,150 20,50 z");
354 }
355
356 /**
357 * @tc.name: DomSvgTest007
358 * @tc.desc: Verify that DomSvgLine can be created and set attrs correctly.
359 * @tc.type: FUNC
360 * @tc.require: AR000FL0TL
361 * @tc.author: chenlien
362 */
363 HWTEST_F(DomSvgTest, DomSvgTest007, TestSize.Level1)
364 {
365 const std::string jsonStr = ""
366 "{ "
367 " \"tag\": \"line\", "
368 " \"attr\": [{ "
369 " \"x1\" : \"10\" "
370 " }, "
371 " { "
372 " \"y1\" : \"20\" "
373 " }, "
374 " { "
375 " \"x2\" : \"60\" "
376 " }, "
377 " { "
378 " \"y2\" : \"50\" "
379 " }] "
380 "}";
381
382 /**
383 * @tc.steps: step1. Construct string with right fields, then create svg line node with it.
384 * @tc.expected: step1. svg line node are created successfully.
385 */
386 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
387 ASSERT_TRUE(domNodeRoot != nullptr);
388 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
389 RefPtr<SvgLineComponent> component = AceType::DynamicCast<SvgLineComponent>(boxChild->GetChild());
390 ASSERT_TRUE(component != nullptr);
391 /**
392 * @tc.steps: step2. Check styles and attributes of created line node.
393 * @tc.expected: step2. The styles and attributes are as expected.
394 */
395 EXPECT_NEAR(component->GetX1().Value(), 10.0, FLT_EPSILON);
396 EXPECT_NEAR(component->GetY1().Value(), 20.0, FLT_EPSILON);
397 EXPECT_NEAR(component->GetX2().Value(), 60.0, FLT_EPSILON);
398 EXPECT_NEAR(component->GetY2().Value(), 50.0, FLT_EPSILON);
399 }
400
401 /**
402 * @tc.name: DomSvgTest008
403 * @tc.desc: Verify that DomSvgPolyline can be created and set attrs correctly.
404 * @tc.type: FUNC
405 * @tc.require: AR000FL0TM
406 * @tc.author: chenlien
407 */
408 HWTEST_F(DomSvgTest, DomSvgTest008, TestSize.Level1)
409 {
410 const std::string jsonStr = ""
411 "{ "
412 " \"tag\": \"polyline\", "
413 " \"attr\": [{ "
414 " \"points\" : \"0,400 60,325 70,375 100,300\""
415 " }] "
416 "}";
417
418 /**
419 * @tc.steps: step1. Construct string with right fields, then create svg polyline node with it.
420 * @tc.expected: step1. svg polyline node are created successfully.
421 */
422 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
423 ASSERT_TRUE(domNodeRoot != nullptr);
424 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
425 RefPtr<SvgPolygonComponent> component = AceType::DynamicCast<SvgPolygonComponent>(boxChild->GetChild());
426 ASSERT_TRUE(component != nullptr);
427 /**
428 * @tc.steps: step2. Check styles and attributes of created polyline node.
429 * @tc.expected: step2. The styles and attributes are as expected.
430 */
431 ASSERT_TRUE(component->GetPoints() == "0,400 60,325 70,375 100,300");
432 }
433
434 /**
435 * @tc.name: DomSvgTest009
436 * @tc.desc: Verify that DomSvgPolygon can be created and set attrs correctly.
437 * @tc.type: FUNC
438 * @tc.require: AR000FL0TN
439 * @tc.author: chenlien
440 */
441 HWTEST_F(DomSvgTest, DomSvgTest009, TestSize.Level1)
442 {
443 const std::string jsonStr = ""
444 "{ "
445 " \"tag\": \"polygon\", "
446 " \"attr\": [{ "
447 " \"points\" : \"0,400 60,325 70,375 100,300\""
448 " }] "
449 "}";
450
451 /**
452 * @tc.steps: step1. Construct string with right fields, then create svg polygon node with it.
453 * @tc.expected: step1. svg polygon node are created successfully.
454 */
455 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
456 ASSERT_TRUE(domNodeRoot != nullptr);
457 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
458 RefPtr<SvgPolygonComponent> component = AceType::DynamicCast<SvgPolygonComponent>(boxChild->GetChild());
459 ASSERT_TRUE(component != nullptr);
460 /**
461 * @tc.steps: step2. Check styles and attributes of created polygon node.
462 * @tc.expected: step2. The styles and attributes are as expected.
463 */
464 ASSERT_TRUE(component->GetPoints() == "0,400 60,325 70,375 100,300");
465 }
466
467 /**
468 * @tc.name: DomSvgTest010
469 * @tc.desc: Verify that DomSvgAnimate can be created and set attrs correctly.
470 * @tc.type: FUNC
471 * @tc.require: AR000FL0TR
472 * @tc.author: chenlien
473 */
474 HWTEST_F(DomSvgTest, DomSvgTest010, TestSize.Level1)
475 {
476 const std::string jsonStr = ""
477 "{ "
478 " \"tag\": \"animate\", "
479 " \"attr\": [{ "
480 " \"begin\" : \"200\" "
481 " }, "
482 " { "
483 " \"dur\" : \"2000\" "
484 " }, "
485 " { "
486 " \"repeatcount\" : \"3\" "
487 " }, "
488 " { "
489 " \"fill\" : \"freeze\" "
490 " }, "
491 " { "
492 " \"calcmode\" : \"linear\" "
493 " }, "
494 " { "
495 " \"from\" : \"100\" "
496 " }, "
497 " { "
498 " \"to\" : \"300\" "
499 " }, "
500 " { "
501 " \"attributename\" : \"width\" "
502 " }] "
503 "}";
504
505 /**
506 * @tc.steps: step1. Construct string with right fields, then create svg animate node with it.
507 * @tc.expected: step1. svg animate node are created successfully.
508 */
509 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
510 ASSERT_TRUE(domNodeRoot != nullptr);
511 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
512 RefPtr<SvgAnimateComponent> component = AceType::DynamicCast<SvgAnimateComponent>(boxChild->GetChild());
513 ASSERT_TRUE(component != nullptr);
514 /**
515 * @tc.steps: step2. Check styles and attributes of created animate node.
516 * @tc.expected: step2. The styles and attributes are as expected.
517 */
518 ASSERT_TRUE(component->GetBegin() == 200);
519 ASSERT_TRUE(component->GetDur() == 2000);
520 ASSERT_TRUE(component->GetRepeatCount() == 3);
521 ASSERT_TRUE(component->GetFillMode() == FillMode::FORWARDS);
522 ASSERT_TRUE(component->GetCalcMode() == CalcMode::LINEAR);
523 ASSERT_TRUE(component->GetAttributeName() == "width");
524 ASSERT_TRUE(component->GetFrom() == "100");
525 ASSERT_TRUE(component->GetTo() == "300");
526 }
527
528 /**
529 * @tc.name: DomSvgTest011
530 * @tc.desc: Verify that DomSvgAnimateMotion can be created and set attrs correctly.
531 * @tc.type: FUNC
532 * @tc.require: AR000FL0TS
533 * @tc.author: chenlien
534 */
535 HWTEST_F(DomSvgTest, DomSvgTest011, TestSize.Level1)
536 {
537 const std::string jsonStr = ""
538 "{ "
539 " \"tag\": \"animatemotion\", "
540 " \"attr\": [{ "
541 " \"begin\" : \"200\" "
542 " }, "
543 " { "
544 " \"dur\" : \"2000\" "
545 " }, "
546 " { "
547 " \"repeatcount\" : \"3\" "
548 " }, "
549 " { "
550 " \"fill\" : \"freeze\" "
551 " }, "
552 " { "
553 " \"calcmode\" : \"spline\" "
554 " }, "
555 " { "
556 " \"keypoints\" : \"0;0.2;0.5;1\" "
557 " }, "
558 " { "
559 " \"keytimes\" : \"0;0.1;0.8;1\" "
560 " }, "
561 " { "
562 " \"path\" : \"M20,50 C20,-50 180,150 180,50 C180,-50 20,150 20,50 z\""
563 " }, "
564 " { "
565 " \"rotate\" : \"auto\" "
566 " }, "
567 " { "
568 " \"keysplines\" : \"0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1\" "
569 " }] "
570 "}";
571
572 /**
573 * @tc.steps: step1. Construct string with right fields, then create svg animate motion node with it.
574 * @tc.expected: step1. svg animate motion node are created successfully.
575 */
576 auto domNodeRoot = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(jsonStr);
577 ASSERT_TRUE(domNodeRoot != nullptr);
578 auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(domNodeRoot);
579 RefPtr<SvgAnimateComponent> component = AceType::DynamicCast<SvgAnimateComponent>(boxChild->GetChild());
580 ASSERT_TRUE(component != nullptr);
581 /**
582 * @tc.steps: step2. Check styles and attributes of created animate motion node.
583 * @tc.expected: step2. The styles and attributes are as expected.
584 */
585 ASSERT_TRUE(component->GetBegin() == 200);
586 ASSERT_TRUE(component->GetDur() == 2000);
587 ASSERT_TRUE(component->GetRepeatCount() == 3);
588 ASSERT_TRUE(component->GetFillMode() == FillMode::FORWARDS);
589 ASSERT_TRUE(component->GetCalcMode() == CalcMode::SPLINE);
590 ASSERT_TRUE(component->GetKeyTimes().size() == 4);
591 EXPECT_NEAR(component->GetKeyTimes().at(0), 0.0, FLT_EPSILON);
592 EXPECT_NEAR(component->GetKeyTimes().at(1), 0.1, FLT_EPSILON);
593 EXPECT_NEAR(component->GetKeyTimes().at(2), 0.8, FLT_EPSILON);
594 EXPECT_NEAR(component->GetKeyTimes().at(3), 1.0, FLT_EPSILON);
595 ASSERT_TRUE(component->GetKeyPoints().size() == 4);
596 ASSERT_TRUE(component->GetKeyPoints().at(0) == "0");
597 ASSERT_TRUE(component->GetKeyPoints().at(1) == "0.2");
598 ASSERT_TRUE(component->GetKeyPoints().at(2) == "0.5");
599 ASSERT_TRUE(component->GetKeyPoints().at(3) == "1");
600 ASSERT_TRUE(component->GetKeySplines().size() == 3);
601 ASSERT_TRUE(component->GetKeySplines().at(0) == "0.5 0 0.5 1");
602 ASSERT_TRUE(component->GetKeySplines().at(1) == "0.5 0 0.5 1");
603 ASSERT_TRUE(component->GetKeySplines().at(2) == "0.5 0 0.5 1");
604 ASSERT_TRUE(component->GetPath() == "M20,50 C20,-50 180,150 180,50 C180,-50 20,150 20,50 z");
605 ASSERT_TRUE(component->GetRotate() == "auto");
606 }
607
608 } // namespace OHOS::Ace::Framework
609