1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "rs_animation_base_test.h"
17 #include "rs_animation_test_utils.h"
18 
19 #include "animation/rs_animation_callback.h"
20 #include "animation/rs_animation_group.h"
21 #include "animation/rs_animation_timing_protocol.h"
22 #include "animation/rs_curve_animation.h"
23 #include "animation/rs_keyframe_animation.h"
24 #include "animation/rs_path_animation.h"
25 #include "animation/rs_spring_animation.h"
26 #include "animation/rs_transition.h"
27 #include "animation/rs_implicit_animation_param.h"
28 #include "animation/rs_render_animation.h"
29 #include "animation/rs_keyframe_animation.h"
30 #include "modifier/rs_modifier_manager.h"
31 #include "transaction/rs_interfaces.h"
32 #include "render/rs_blur_filter.h"
33 #include "render/rs_material_filter.h"
34 #include "render/rs_path.h"
35 #include "render/rs_light_up_effect_filter.h"
36 #include "ui/rs_canvas_node.h"
37 #include "ui/rs_display_node.h"
38 #include "ui/rs_proxy_node.h"
39 #include "ui/rs_ui_director.h"
40 
41 using namespace testing;
42 using namespace testing::ext;
43 
44 namespace OHOS {
45 namespace Rosen {
46 using namespace ANIMATIONTEST;
47 class RSAnimationTest : public RSAnimationBaseTest {
48 };
49 
50 class RSAnimationMock : public RSAnimation {
51 public:
RSAnimationMock()52     RSAnimationMock() : RSAnimation() {}
53     ~RSAnimationMock() = default;
StartInner(const std::shared_ptr<RSNode> & target)54     void StartInner(const std::shared_ptr<RSNode>& target)
55     {
56         RSAnimation::StartInner(target);
57     }
58 
OnStart()59     void OnStart() override
60     {
61         RSAnimation::OnStart();
62     }
63 
OnReverse()64     void OnReverse() override
65     {
66         RSAnimation::OnReverse();
67     }
68 
OnPause()69     void OnPause() override
70     {
71         RSAnimation::OnPause();
72     }
73 
OnResume()74     void OnResume() override
75     {
76         RSAnimation::OnResume();
77     }
78 
OnFinish()79     void OnFinish() override
80     {
81         RSAnimation::OnFinish();
82     }
83 
OnSetFraction(float fraction)84     void OnSetFraction(float fraction) override
85     {
86         RSAnimation::OnSetFraction(fraction);
87     }
88 
OnUpdateStagingValue(bool isFirstStart)89     void OnUpdateStagingValue(bool isFirstStart) override
90     {
91         RSAnimation::OnUpdateStagingValue(isFirstStart);
92     }
93 
GetPropertyId() const94     PropertyId GetPropertyId() const override
95     {
96         return RSAnimation::GetPropertyId();
97     }
98 
IsReversed() const99     bool IsReversed() const
100     {
101         return RSAnimation::IsReversed();
102     }
103 
UpdateParamToRenderAnimation(const std::shared_ptr<RSRenderAnimation> & animation)104     void UpdateParamToRenderAnimation(const std::shared_ptr<RSRenderAnimation>& animation)
105     {
106         RSAnimation::UpdateParamToRenderAnimation(animation);
107     }
108 
StartCustomAnimation(const std::shared_ptr<RSRenderAnimation> & animation)109     void StartCustomAnimation(const std::shared_ptr<RSRenderAnimation>& animation)
110     {
111         RSAnimation::StartCustomAnimation(animation);
112     }
113 };
114 
115 class RSRenderAnimationMock : public RSRenderAnimation {
116 public:
RSRenderAnimationMock(AnimationId id)117     RSRenderAnimationMock(AnimationId id) : RSRenderAnimation(id) {}
118     ~RSRenderAnimationMock() = default;
119 };
120 
121 class RSAnimationGroupMock : public RSAnimationGroup {
122 public:
RSAnimationGroupMock()123     RSAnimationGroupMock() : RSAnimationGroup() {}
124     ~RSAnimationGroupMock() = default;
125 
OnStart()126     void OnStart() override
127     {
128         RSAnimationGroup::OnStart();
129     }
130 
OnPause()131     void OnPause() override
132     {
133         RSAnimationGroup::OnPause();
134     }
135 
OnResume()136     void OnResume() override
137     {
138         RSAnimationGroup::OnResume();
139     }
140 
OnFinish()141     void OnFinish() override
142     {
143         RSAnimationGroup::OnFinish();
144     }
145 
OnReverse()146     void OnReverse() override
147     {
148         RSAnimationGroup::OnReverse();
149     }
150 
OnSetFraction(float fraction)151     void OnSetFraction(float fraction) override
152     {
153         RSAnimationGroup::OnSetFraction(fraction);
154     }
155 
GetPropertyId() const156     PropertyId GetPropertyId() const override
157     {
158         return RSAnimationGroup::GetPropertyId();
159     }
160 
StartInner(const std::shared_ptr<RSNode> & target)161     void StartInner(const std::shared_ptr<RSNode>& target)
162     {
163         RSAnimation::StartInner(target);
164     }
165 };
166 
167 class RSKeyframeAnimationMock : public RSKeyframeAnimation {
168 public:
RSKeyframeAnimationMock(std::shared_ptr<RSPropertyBase> property)169     explicit RSKeyframeAnimationMock(std::shared_ptr<RSPropertyBase> property) : RSKeyframeAnimation(property) {}
170     ~RSKeyframeAnimationMock() = default;
171 
OnStart()172     void OnStart() override
173     {
174         RSKeyframeAnimation::OnStart();
175     }
176 
InitInterpolationValue()177     void InitInterpolationValue() override
178     {
179         RSKeyframeAnimation::InitInterpolationValue();
180     }
181 };
182 
183 /**
184  * @tc.name: AnimationSupplementTest001
185  * @tc.desc: Verify the setcallback of Animation
186  * @tc.type: FUNC
187  */
188 HWTEST_F(RSAnimationTest, AnimationSupplementTest001, TestSize.Level1)
189 {
190     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest001 start";
191     /**
192      * @tc.steps: step1. init
193      */
194     auto animation = std::make_shared<RSAnimationMock>();
195     std::function<void()> callback = nullptr;
196     animation->SetFinishCallback(callback);
__anona9ac6d9e0102() 197     callback = []() {
198         std::cout << "RSAnimationTest AnimationSupplementTest001 callback" << std::endl;
199     };
200     animation->SetFinishCallback(callback);
201     EXPECT_TRUE(animation != nullptr);
202     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest001 end";
203 }
204 
205 /**
206  * @tc.name: AnimationSupplementTest002
207  * @tc.desc: Verify the setcallback of Animation
208  * @tc.type: FUNC
209  */
210 HWTEST_F(RSAnimationTest, AnimationSupplementTest002, TestSize.Level1)
211 {
212     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest002 start";
213     /**
214      * @tc.steps: step1. init
215      */
216     auto animation = std::make_shared<RSAnimationMock>();
217     EXPECT_TRUE(!animation->IsStarted());
218     EXPECT_TRUE(!animation->IsRunning());
219     EXPECT_TRUE(!animation->IsPaused());
220     EXPECT_TRUE(!animation->IsFinished());
221     EXPECT_TRUE(!animation->IsReversed());
222     std::shared_ptr<RSNode> node = nullptr;
223     animation->Reverse();
224     animation->Finish();
225     animation->Pause();
226     animation->Start(node);
227     animation->StartInner(node);
228     animation->Resume();
229     animation->Pause();
230     animation->OnPause();
231     animation->Resume();
232     animation->OnResume();
233     animation->Finish();
234     animation->OnFinish();
235     animation->Reverse();
236     animation->OnReverse();
237     node = RSCanvasNode::Create();
238     node->AddAnimation(animation);
239     animation->Pause();
240     animation->OnPause();
241     animation->Resume();
242     animation->OnResume();
243     animation->Finish();
244     animation->OnFinish();
245     animation->Reverse();
246     animation->OnReverse();
247     EXPECT_TRUE(animation != nullptr);
248     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest002 end";
249 }
250 
251 /**
252  * @tc.name: AnimationSupplementTest003
253  * @tc.desc: Verify the setcallback of Animation
254  * @tc.type: FUNC
255  */
256 HWTEST_F(RSAnimationTest, AnimationSupplementTest003, TestSize.Level1)
257 {
258     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest003 start";
259     /**
260      * @tc.steps: step1. init
261      */
262     auto animation = std::make_shared<RSAnimationMock>();
263     auto renderAnimation = std::make_shared<RSRenderAnimationMock>(animation->GetId());
264     animation->SetFraction(-1.0f);
265     animation->SetFraction(0.5f);
266     animation->Pause();
267     animation->SetFraction(0.5f);
268     animation->OnSetFraction(0.5f);
269     animation->StartCustomAnimation(renderAnimation);
270     std::shared_ptr<RSNode> node = RSCanvasNode::Create();
271     node->AddAnimation(animation);
272     animation->SetFraction(-1.0f);
273     animation->SetFraction(0.5f);
274     animation->Pause();
275     animation->SetFraction(0.5f);
276     animation->OnSetFraction(0.5f);
277     animation->StartCustomAnimation(renderAnimation);
278     EXPECT_TRUE(animation != nullptr);
279     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest003 end";
280 }
281 
282 /**
283  * @tc.name: AnimationSupplementTest004
284  * @tc.desc: Verify the setcallback of Animation
285  * @tc.type: FUNC
286  */
287 HWTEST_F(RSAnimationTest, AnimationSupplementTest004, TestSize.Level1)
288 {
289     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest004 start";
290     /**
291      * @tc.steps: step1. init
292      */
293     auto implicitAnimator = std::make_shared<RSImplicitAnimator>();
294     auto animations = implicitAnimator->CloseImplicitAnimation();
295     EXPECT_TRUE(animations.empty());
296     implicitAnimator->BeginImplicitKeyFrameAnimation(0.1f, RSAnimationTimingCurve::LINEAR);
297     implicitAnimator->BeginImplicitKeyFrameAnimation(0.2f);
298     implicitAnimator->EndImplicitKeyFrameAnimation();
299     std::shared_ptr<RSMotionPathOption> motionPathOption;
300     implicitAnimator->BeginImplicitPathAnimation(motionPathOption);
301     implicitAnimator->EndImplicitPathAnimation();
302     std::shared_ptr<const RSTransitionEffect> effect;
303     implicitAnimator->BeginImplicitTransition(effect, true);
304     implicitAnimator->EndImplicitTransition();
305     implicitAnimator->BeginImplicitTransition(effect, false);
306     implicitAnimator->EndImplicitTransition();
307     std::shared_ptr<RSNode> node;
308     std::shared_ptr<RSPropertyBase> property = std::make_shared<RSAnimatableProperty<float>>(0.1f);
309     std::shared_ptr<RSPropertyBase> startValue = std::make_shared<RSAnimatableProperty<float>>(2.f);
310     std::shared_ptr<RSPropertyBase> endValue = std::make_shared<RSAnimatableProperty<float>>(10.0f);
311     implicitAnimator->CreateImplicitAnimation(node, property, startValue, endValue);
312     RSAnimationTimingProtocol protocol;
313     protocol.SetDuration(100);
314     implicitAnimator->OpenImplicitAnimation(protocol, RSAnimationTimingCurve::LINEAR, nullptr);
315     implicitAnimator->CreateImplicitAnimation(node, property, startValue, endValue);
316     implicitAnimator->CreateImplicitTransition(*node);
317     implicitAnimator->CloseImplicitAnimation();
318     implicitAnimator->EndImplicitKeyFrameAnimation();
319     implicitAnimator->EndImplicitTransition();
320     implicitAnimator->EndImplicitPathAnimation();
321 
322     node = RSCanvasNode::Create();
323     implicitAnimator->CreateImplicitAnimation(node, property, startValue, endValue);
324     implicitAnimator->OpenImplicitAnimation(protocol, RSAnimationTimingCurve::LINEAR, nullptr);
325     implicitAnimator->CreateImplicitAnimation(node, property, startValue, endValue);
326     implicitAnimator->CreateImplicitTransition(*node);
327     implicitAnimator->CloseImplicitAnimation();
328     implicitAnimator->EndImplicitKeyFrameAnimation();
329     implicitAnimator->EndImplicitTransition();
330     implicitAnimator->EndImplicitPathAnimation();
331     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest004 end";
332 }
333 
334 class RSPathAnimationMock : public RSPathAnimation {
335 public:
RSPathAnimationMock(std::shared_ptr<RSPropertyBase> property,const std::shared_ptr<RSPath> & animationPath)336     RSPathAnimationMock(std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPath>& animationPath)
337         : RSPathAnimation(property, animationPath)
338     {}
RSPathAnimationMock(std::shared_ptr<RSPropertyBase> property,const std::string & path,const std::shared_ptr<RSPropertyBase> & startValue,const std::shared_ptr<RSPropertyBase> & endValue)339     RSPathAnimationMock(std::shared_ptr<RSPropertyBase> property, const std::string& path,
340         const std::shared_ptr<RSPropertyBase>& startValue,
341         const std::shared_ptr<RSPropertyBase>& endValue)
342         : RSPathAnimation(property, path, startValue, endValue) {}
343     ~RSPathAnimationMock() = default;
344 
OnStart()345     void OnStart()
346     {
347         RSPathAnimation::OnStart();
348     }
349 
InitInterpolationValue()350     void InitInterpolationValue()
351     {
352         RSPathAnimation::InitInterpolationValue();
353     }
354 
OnUpdateStagingValue(bool isFirstStart)355     void OnUpdateStagingValue(bool isFirstStart)
356     {
357         RSPathAnimation::OnUpdateStagingValue(isFirstStart);
358     }
359 
InitRotationId(const std::shared_ptr<RSNode> & node)360     void InitRotationId(const std::shared_ptr<RSNode>& node)
361     {
362         RSPathAnimation::InitRotationId(node);
363     }
364 
GetRotationPropertyId(const std::shared_ptr<RSNode> & node)365     PropertyId GetRotationPropertyId(const std::shared_ptr<RSNode>& node)
366     {
367         return RSPathAnimation::GetRotationPropertyId(node);
368     }
369 
SetRotation(const std::shared_ptr<RSNode> & node,const float rotation)370     void SetRotation(const std::shared_ptr<RSNode>& node, const float rotation)
371     {
372         RSPathAnimation::SetRotation(node, rotation);
373     }
374 
OnCallFinishCallback()375     void OnCallFinishCallback()
376     {
377         RSPathAnimation::OnCallFinishCallback();
378     }
379 };
380 
381 /**
382  * @tc.name: AnimationSupplementTest005
383  * @tc.desc: Verify the setcallback of Animation
384  * @tc.type: FUNC
385  */
386 HWTEST_F(RSAnimationTest, AnimationSupplementTest005, TestSize.Level1)
387 {
388     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest005 start";
389     /**
390      * @tc.steps: step1. init
391      */
392     Vector4f data(1.f, 1.f, 1.f, 1.f);
393     auto property = std::make_shared<RSAnimatableProperty<Vector4f>>(data);
394     std::shared_ptr<RSPath> path;
395     auto animation = std::make_shared<RSPathAnimationMock>(property, path);
396     EXPECT_TRUE(animation != nullptr);
397     animation->SetTimingCurve(RSAnimationTimingCurve::LINEAR);
398     auto curve = animation->GetTimingCurve();
399     animation->SetTimingCurve(curve);
400     animation->SetRotationMode(RotationMode::ROTATE_AUTO);
401     animation->SetBeginFraction(-0.1f);
402     animation->SetEndFraction(-0.1f);
403     animation->SetEndFraction(1.0f);
404     animation->SetBeginFraction(0.1f);
405     animation->SetPathNeedAddOrigin(true);
406     auto begin = animation->GetBeginFraction();
407     auto end = animation->GetEndFraction();
408     animation->SetBeginFraction(begin);
409     animation->SetEndFraction(end);
410     auto needAddOrigin = animation->GetPathNeedAddOrigin();
411     animation->SetPathNeedAddOrigin(needAddOrigin);
412     animation->OnStart();
413     std::shared_ptr<RSNode> node = RSCanvasNode::Create();
414     animation->Start(node);
415     animation->SetRotationMode(RotationMode::ROTATE_AUTO);
416     animation->SetEndFraction(1.f);
417     animation->SetBeginFraction(0.1f);
418     animation->SetPathNeedAddOrigin(true);
419     animation->InitInterpolationValue();
420     animation->OnStart();
421 
422     Vector4f startData(0.f, 1.f, 2.f, 3.f);
423     auto startValue = std::make_shared<RSAnimatableProperty<Vector4f>>(startData);
424     Vector4f endData(5.f, 6.f, 2.f, 3.f);
425     auto endValue = std::make_shared<RSAnimatableProperty<Vector4f>>(endData);
426     auto animation2 = std::make_shared<RSPathAnimationMock>(property, "abc", startValue, endValue);
427     animation2->InitInterpolationValue();
428     animation2->OnUpdateStagingValue(true);
429     animation2->SetDirection(false);
430     animation2->Start(node);
431     animation2->OnStart();
432     animation2->OnUpdateStagingValue(false);
433     animation2->SetAutoReverse(true);
434     animation2->SetRepeatCount(2);
435     animation2->OnUpdateStagingValue(false);
436     animation2->SetRotationMode(RotationMode::ROTATE_NONE);
437     animation2->OnUpdateStagingValue(false);
438     animation2->SetRotationMode(RotationMode::ROTATE_AUTO);
439     animation2->OnUpdateStagingValue(false);
440     animation2->SetRotationMode(RotationMode::ROTATE_AUTO_REVERSE);
441     animation2->OnUpdateStagingValue(false);
442     animation2->SetDirection(true);
443     animation2->OnUpdateStagingValue(false);
444 
445     auto id = animation2->GetRotationPropertyId(node);
446     animation2->InitRotationId(node);
447     animation2->SetRotation(node, 1.f);
448     auto rotationProperty = std::make_shared<RSAnimatableProperty<float>>(10.f);
449     auto rotationModifier = std::make_shared<RSRotationModifier>(rotationProperty);
450     node->AddModifier(rotationModifier);
451     auto alphaProperty = std::make_shared<RSAnimatableProperty<float>>(0.1f);
452     auto alphaModifier = std::make_shared<RSRotationModifier>(rotationProperty);
453     node->AddModifier(alphaModifier);
454     id = animation2->GetRotationPropertyId(node);
455     EXPECT_TRUE(id != rotationModifier->GetPropertyId());
456     animation2->SetRotation(node, 1.f);
457     animation2->InitRotationId(node);
458     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest005 end";
459 }
460 
461 /**
462  * @tc.name: AnimationSupplementTest006
463  * @tc.desc: Verify the setcallback of Animation
464  * @tc.type: FUNC
465  */
466 HWTEST_F(RSAnimationTest, AnimationSupplementTest006, TestSize.Level1)
467 {
468     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest006 start";
469     /**
470      * @tc.steps: step1. init
471      */
472     auto property = std::make_shared<RSAnimatableProperty<float>>(10.f);
473     auto modifier = std::make_shared<RSAlphaModifier>(property);
474     auto modifierManager = std::make_shared<RSModifierManager>();
475     modifierManager->AddModifier(modifier);
476     auto animation = std::make_shared<RSAnimationMock>();
477     auto renderAnimation = std::make_shared<RSRenderAnimationMock>(animation->GetId());
478     EXPECT_TRUE(animation != nullptr);
479     modifierManager->RemoveAnimation(animation->GetId());
480     modifierManager->AddAnimation(renderAnimation);
481     modifierManager->Animate(0);
482     modifierManager->Draw();
483     modifierManager->RemoveAnimation(animation->GetId());
484     modifierManager->AddAnimation(renderAnimation);
485     modifierManager->AddAnimation(renderAnimation);
486     auto uiAnimation2 = std::make_shared<RSAnimationMock>();
487     auto animation2 = std::make_shared<RSRenderAnimationMock>(uiAnimation2->GetId());
488     modifierManager->RemoveAnimation(uiAnimation2->GetId());
489     modifierManager->RemoveAnimation(animation->GetId());
490     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest006 end";
491 }
492 
493 /**
494  * @tc.name: AnimationSupplementTest007
495  * @tc.desc: Verify the setcallback of Animation
496  * @tc.type: FUNC
497  */
498 HWTEST_F(RSAnimationTest, AnimationSupplementTest007, TestSize.Level1)
499 {
500     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest007 start";
501     /**
502      * @tc.steps: step1. init
503      */
504     RSAnimationTimingProtocol protocol;
505     protocol.SetDuration(100);
506     auto keyframeParam = std::make_shared<RSImplicitKeyframeAnimationParam>(
507         protocol, RSAnimationTimingCurve::LINEAR, 0.1f, 0);
508     EXPECT_TRUE(keyframeParam != nullptr);
509     std::shared_ptr<RSAnimation> animation;
510     Vector4f startData(0.f, 1.f, 2.f, 3.f);
511     auto startValue = std::make_shared<RSAnimatableProperty<Vector4f>>(startData);
512     Vector4f endData(5.f, 6.f, 2.f, 3.f);
513     auto endValue = std::make_shared<RSAnimatableProperty<Vector4f>>(endData);
514     keyframeParam->AddKeyframe(animation, startValue, endValue);
515     animation = std::make_shared<RSKeyframeAnimation>(startValue);
516     keyframeParam->AddKeyframe(animation, startValue, endValue);
517     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest007 end";
518 }
519 
520 /**
521  * @tc.name: AnimationSupplementTest008
522  * @tc.desc: Verify the setcallback of Animation
523  * @tc.type: FUNC
524  */
525 HWTEST_F(RSAnimationTest, AnimationSupplementTest008, TestSize.Level1)
526 {
527     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest008 start";
528     /**
529      * @tc.steps: step1. init
530      */
531     RSAnimationTimingProtocol protocol;
532     protocol.SetDuration(100);
533     std::shared_ptr<RSMotionPathOption> option;
534     auto pathParam = std::make_shared<RSImplicitPathAnimationParam>(
535         protocol, RSAnimationTimingCurve::LINEAR, option);
536     EXPECT_TRUE(pathParam != nullptr);
537     Vector4f startData(0.f, 1.f, 2.f, 3.f);
538     auto property = std::make_shared<RSAnimatableProperty<Vector4f>>(startData);
539     auto startValue = std::make_shared<RSAnimatableProperty<Vector4f>>(startData);
540     Vector4f endData(5.f, 6.f, 2.f, 3.f);
541     auto endValue = std::make_shared<RSAnimatableProperty<Vector4f>>(endData);
542     auto animation = pathParam->CreateAnimation(property, startValue, endValue);
543 
544     option = std::make_shared<RSMotionPathOption>("abc");
545     auto pathParam2 = std::make_shared<RSImplicitPathAnimationParam>(
546         protocol, RSAnimationTimingCurve::LINEAR, option);
547     auto animation2 = pathParam->CreateAnimation(property, startValue, endValue);
548 
549     auto springParam = std::make_shared<RSImplicitSpringAnimationParam>(protocol, RSAnimationTimingCurve::LINEAR);
550     auto animation3 = springParam->CreateAnimation(property, startValue, endValue);
551     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest008 end";
552 }
553 
554 class RSTransitionTest : public RSTransition {
555 public:
RSTransitionTest(const std::shared_ptr<const RSTransitionEffect> & effect,bool isTransitionIn)556     RSTransitionTest(const std::shared_ptr<const RSTransitionEffect>& effect, bool isTransitionIn)
557         : RSTransition(effect, isTransitionIn)
558     {}
559     virtual ~RSTransitionTest() = default;
560 };
561 
562 class RSTransitionMock : public RSTransition {
563 public:
RSTransitionMock(const std::shared_ptr<const RSTransitionEffect> & effect,bool isTransitionIn)564     RSTransitionMock(const std::shared_ptr<const RSTransitionEffect>& effect, bool isTransitionIn)
565         : RSTransition(effect, isTransitionIn)
566     {}
567     virtual ~RSTransitionMock() = default;
568 
OnStart()569     void OnStart()
570     {
571         RSTransition::OnStart();
572     }
573 };
574 
575 /**
576  * @tc.name: AnimationSupplementTest009
577  * @tc.desc: Verify the setcallback of Animation
578  * @tc.type: FUNC
579  */
580 HWTEST_F(RSAnimationTest, AnimationSupplementTest009, TestSize.Level1)
581 {
582     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest009 start";
583     /**
584      * @tc.steps: step1. init
585      */
586     std::shared_ptr<const RSTransitionEffect> effect;
587     auto animation = std::make_shared<RSTransitionMock>(effect, true);
588     EXPECT_TRUE(animation != nullptr);
589     animation->OnStart();
590     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest009 end";
591 }
592 
593 /**
594  * @tc.name: AnimationSupplementTest010
595  * @tc.desc: Verify the setcallback of Animation
596  * @tc.type: FUNC
597  */
598 HWTEST_F(RSAnimationTest, AnimationSupplementTest010, TestSize.Level1)
599 {
600     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest010 start";
601     /**
602      * @tc.steps: step1. init
603      */
604     std::function<void()> callback;
605     AnimationFinishCallback* finishCallback1 = new AnimationFinishCallback(callback);
606     delete finishCallback1;
__anona9ac6d9e0202() 607     callback = []() {
608         std::cout << "RSAnimationTest AnimationSupplementTest010" << std::endl;
609     };
610     EXPECT_TRUE(callback != nullptr);
611     AnimationFinishCallback* finishCallback2 = new AnimationFinishCallback(callback);
612     delete finishCallback2;
613     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest010 end";
614 }
615 
616 /**
617  * @tc.name: AnimationSupplementTest011
618  * @tc.desc: Verify the setcallback of Animation
619  * @tc.type: FUNC
620  */
621 HWTEST_F(RSAnimationTest, AnimationSupplementTest011, TestSize.Level1)
622 {
623     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest011 start";
624     /**
625      * @tc.steps: step1. init
626      */
627     std::shared_ptr<RSAnimationMock> animation;
628     std::shared_ptr<RSAnimationGroupMock> animationGroup = std::make_shared<RSAnimationGroupMock>();
629     animationGroup->AddAnimation(animation);
630     animationGroup->RemoveAnimation(animation);
631     animation = std::make_shared<RSAnimationMock>();
632     std::shared_ptr<RSNode> node = RSCanvasNode::Create();
633     animationGroup->StartInner(node);
634     animationGroup->AddAnimation(animation);
635     animationGroup->RemoveAnimation(animation);
636     animationGroup->Pause();
637     animation->StartInner(node);
638     animationGroup->AddAnimation(animation);
639     animationGroup->RemoveAnimation(animation);
640     animation->Pause();
641     animationGroup->AddAnimation(animation);
642     animationGroup->AddAnimation(animation);
643     animationGroup->RemoveAnimation(animation);
644     animationGroup->RemoveAnimation(animation);
645     auto id = animationGroup->GetPropertyId();
646     EXPECT_TRUE(id == 0);
647     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest011 end";
648 }
649 
650 /**
651  * @tc.name: AnimationSupplementTest012
652  * @tc.desc: Verify the setcallback of Animation
653  * @tc.type: FUNC
654  */
655 HWTEST_F(RSAnimationTest, AnimationSupplementTest012, TestSize.Level1)
656 {
657     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest012 start";
658     /**
659      * @tc.steps: step1. init
660      */
661     std::shared_ptr<RSAnimationGroupMock> animationGroup = std::make_shared<RSAnimationGroupMock>();
662     animationGroup->OnStart();
663     animationGroup->OnPause();
664     animationGroup->OnResume();
665     animationGroup->OnFinish();
666     animationGroup->OnReverse();
667     animationGroup->OnSetFraction(0.1f);
668     std::shared_ptr<RSAnimationMock> animation = std::make_shared<RSAnimationMock>();
669     animationGroup->AddAnimation(animation);
670     animationGroup->OnStart();
671     std::shared_ptr<RSNode> node = RSCanvasNode::Create();
672     animationGroup->StartInner(node);
673     animationGroup->OnStart();
674     animationGroup->OnPause();
675     animationGroup->OnResume();
676     animationGroup->OnFinish();
677     animationGroup->OnReverse();
678     animationGroup->OnSetFraction(0.1f);
679     EXPECT_TRUE(animationGroup != nullptr);
680     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest012 end";
681 }
682 
683 /**
684  * @tc.name: AnimationSupplementTest013
685  * @tc.desc: Verify the setcallback of Animation
686  * @tc.type: FUNC
687  */
688 HWTEST_F(RSAnimationTest, AnimationSupplementTest013, TestSize.Level1)
689 {
690     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest013 start";
691     /**
692      * @tc.steps: step1. init
693      */
694     std::shared_ptr<RSPropertyBase> property = std::make_shared<RSAnimatableProperty<float>>(0.1f);
695     std::shared_ptr<RSKeyframeAnimationMock> animation = std::make_shared<RSKeyframeAnimationMock>(property);
696     std::shared_ptr<RSPropertyBase> value1 = std::make_shared<RSAnimatableProperty<float>>(0.2f);
697     std::vector<std::tuple<float, std::shared_ptr<RSPropertyBase>, RSAnimationTimingCurve>> keyframes;
698     keyframes.push_back({ 0.5f, value1, RSAnimationTimingCurve::LINEAR });
699     animation->AddKeyFrame(-0.1f, value1, RSAnimationTimingCurve::LINEAR);
700     animation->AddKeyFrame(0.2f, value1, RSAnimationTimingCurve::LINEAR);
701     animation->AddKeyFrames(keyframes);
702     std::shared_ptr<RSNode> node = RSCanvasNode::Create();
703     animation->Start(node);
704     animation->AddKeyFrame(0.3f, value1, RSAnimationTimingCurve::LINEAR);
705     animation->AddKeyFrames(keyframes);
706     EXPECT_TRUE(animation != nullptr);
707     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest013 end";
708 }
709 
710 /**
711  * @tc.name: AnimationSupplementTest014
712  * @tc.desc: Verify the setcallback of Animation
713  * @tc.type: FUNC
714  */
715 HWTEST_F(RSAnimationTest, AnimationSupplementTest014, TestSize.Level1)
716 {
717     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest014 start";
718     /**
719      * @tc.steps: step1. init
720      */
721     std::shared_ptr<RSPropertyBase> property = std::make_shared<RSAnimatableProperty<float>>(0.1f);
722     std::shared_ptr<RSKeyframeAnimationMock> animation = std::make_shared<RSKeyframeAnimationMock>(property);
723     animation->InitInterpolationValue();
724     animation->OnStart();
725     std::shared_ptr<RSPropertyBase> value1 = std::make_shared<RSAnimatableProperty<float>>(0.2f);
726     animation->AddKeyFrame(0.2f, value1, RSAnimationTimingCurve::LINEAR);
727     animation->InitInterpolationValue();
728     animation->AddKeyFrame(0.f, value1, RSAnimationTimingCurve::LINEAR);
729     animation->InitInterpolationValue();
730     animation->OnStart();
731     animation->SetIsCustom(true);
732     animation->OnStart();
733     animation->SetIsCustom(false);
734     std::shared_ptr<RSNode> node1 = RSCanvasNode::Create();
735     struct RSSurfaceNodeConfig surfaceNodeConfig = {.SurfaceNodeName = "test"};
736     std::shared_ptr<RSNode> node2 = RSSurfaceNode::Create(surfaceNodeConfig, false);
737     std::shared_ptr<RSNode> node3 = RSSurfaceNode::Create(surfaceNodeConfig, true);
738     animation->Start(node1);
739     animation->OnStart();
740     EXPECT_TRUE(animation != nullptr);
741     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest014 end";
742 }
743 
744 /**
745  * @tc.name: AnimationSupplementTest015
746  * @tc.desc: Verify the setcallback of Animation
747  * @tc.type: FUNC
748  */
749 HWTEST_F(RSAnimationTest, AnimationSupplementTest015, TestSize.Level1)
750 {
751     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest015 start";
752     /**
753      * @tc.steps: step1. init
754      */
755     std::shared_ptr<RSPropertyBase> property = std::make_shared<RSAnimatableProperty<float>>(0.1f);
756     std::shared_ptr<RSKeyframeAnimationMock> animation1 = std::make_shared<RSKeyframeAnimationMock>(property);
757     std::shared_ptr<RSKeyframeAnimationMock> animation2 = std::make_shared<RSKeyframeAnimationMock>(property);
758     std::shared_ptr<RSKeyframeAnimationMock> animation3 = std::make_shared<RSKeyframeAnimationMock>(property);
759     std::shared_ptr<RSNode> node1 = RSCanvasNode::Create();
760     struct RSSurfaceNodeConfig surfaceNodeConfig = {.SurfaceNodeName = "test"};
761     std::shared_ptr<RSNode> node2 = RSSurfaceNode::Create(surfaceNodeConfig, false);
762     std::shared_ptr<RSNode> node3 = RSSurfaceNode::Create(surfaceNodeConfig, true);
763     animation1->Start(node1);
764     animation1->OnStart();
765     animation1->SetIsCustom(true);
766     animation1->OnStart();
767     animation2->Start(node1);
768     animation2->OnStart();
769     animation2->SetIsCustom(true);
770     animation2->OnStart();
771     animation3->Start(node1);
772     animation3->OnStart();
773     animation3->SetIsCustom(true);
774     animation3->OnStart();
775     EXPECT_TRUE(animation1 != nullptr);
776     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest015 end";
777 }
778 
779 /**
780  * @tc.name: AnimationSupplementTest016
781  * @tc.desc: Verify the setcallback of Animation
782  * @tc.type: FUNC
783  */
784 HWTEST_F(RSAnimationTest, AnimationSupplementTest016, TestSize.Level1)
785 {
786     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest016 start";
787     /**
788      * @tc.steps: step1. init
789      */
790     Vector4f data(1.f, 1.f, 1.f, 1.f);
791     auto property = std::make_shared<RSAnimatableProperty<Vector4f>>(data);
792     Vector4f startData(0.f, 1.f, 2.f, 3.f);
793     auto startValue = std::make_shared<RSAnimatableProperty<Vector4f>>(startData);
794     Vector4f endData(0.f, 1.f, 2.f, 3.f);
795     auto endValue = std::make_shared<RSAnimatableProperty<Vector4f>>(endData);
796     auto animation = std::make_shared<RSPathAnimationMock>(property, "abc", startValue, endValue);
797     animation->InitInterpolationValue();
798     animation->OnUpdateStagingValue(true);
799     animation->SetDirection(false);
800     std::shared_ptr<RSNode> node = RSCanvasNode::Create();
801     animation->Start(node);
802     animation->OnStart();
803     animation->OnUpdateStagingValue(false);
804     animation->SetAutoReverse(true);
805     animation->SetRepeatCount(2);
806     animation->OnUpdateStagingValue(false);
807     animation->InitInterpolationValue();
808     auto rotationProperty = std::make_shared<RSAnimatableProperty<float>>(10.f);
809     auto rotationModifier = std::make_shared<RSRotationModifier>(rotationProperty);
810     node->AddModifier(rotationModifier);
811     animation->GetRotationPropertyId(node);
812     animation->SetRotation(node, 1.f);
813     animation->InitInterpolationValue();
814     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest016 end";
815 }
816 
817 /**
818  * @tc.name: AnimationSupplementTest017
819  * @tc.desc: Verify the setcallback of Animation
820  * @tc.type: FUNC
821  */
822 HWTEST_F(RSAnimationTest, AnimationSupplementTest017, TestSize.Level1)
823 {
824     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest017 start";
825     /**
826      * @tc.steps: step1. init
827      */
828     Vector4f data(1.f, 1.f, 1.f, 1.f);
829     std::shared_ptr<RSAnimatableProperty<Vector4f>> property;
830     std::shared_ptr<RSPath> path = std::make_shared<RSPath>();
831     auto animation1 = std::make_shared<RSPathAnimationMock>(property, path);
832     animation1->OnCallFinishCallback();
833     property = std::make_shared<RSAnimatableProperty<Vector4f>>(data);
834     Vector2f startData(0.f, 1.f);
835     auto startValue = std::make_shared<RSAnimatableProperty<Vector2f>>(startData);
836     Vector2f endData(5.f, 6.f);
837     auto endValue = std::make_shared<RSAnimatableProperty<Vector2f>>(endData);
838     auto animation = std::make_shared<RSPathAnimationMock>(property, "abc", startValue, endValue);
839     EXPECT_TRUE(animation != nullptr);
840     animation->SetTimingCurve(RSAnimationTimingCurve::LINEAR);
841     auto curve = animation->GetTimingCurve();
842     animation->SetTimingCurve(curve);
843     animation->SetRotationMode(RotationMode::ROTATE_AUTO);
844     animation->SetBeginFraction(-0.1f);
845     animation->SetEndFraction(-0.1f);
846     animation->SetEndFraction(1.0f);
847     animation->SetBeginFraction(0.1f);
848     animation->SetPathNeedAddOrigin(true);
849     animation->OnStart();
850     animation->InitInterpolationValue();
851     animation->OnCallFinishCallback();
852     std::shared_ptr<RSNode> node = RSCanvasNode::Create();
853     animation->Start(node);
854     animation->SetRotationMode(RotationMode::ROTATE_AUTO);
855     animation->SetEndFraction(1.f);
856     animation->SetBeginFraction(0.1f);
857     animation->SetPathNeedAddOrigin(true);
858     animation->InitInterpolationValue();
859     animation->OnStart();
860     animation->SetAutoReverse(true);
861     animation->SetRepeatCount(2);
862     animation->OnUpdateStagingValue(true);
863     animation->OnUpdateStagingValue(false);
864     animation->SetAutoReverse(false);
865     animation->SetRepeatCount(1);
866     animation->OnUpdateStagingValue(true);
867     animation->OnUpdateStagingValue(false);
868     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest017 end";
869 }
870 
871 /**
872  * @tc.name: AnimationSupplementTest018
873  * @tc.desc: Verify the setcallback of Animation
874  * @tc.type: FUNC
875  */
876 HWTEST_F(RSAnimationTest, AnimationSupplementTest018, TestSize.Level1)
877 {
878     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest018 start";
879     /**
880      * @tc.steps: step1. init
881      */
882     Vector4f data(1.f, 1.f, 1.f, 1.f);
883     auto property = std::make_shared<RSAnimatableProperty<Vector4f>>(data);
884     Vector2f startData(0.f, 1.f);
885     auto startValue = std::make_shared<RSAnimatableProperty<Vector2f>>(startData);
886     Vector2f endData(5.f, 6.f);
887     auto endValue = std::make_shared<RSAnimatableProperty<Vector2f>>(endData);
888     auto animation = std::make_shared<RSPathAnimationMock>(property, "abc", startValue, endValue);
889     animation->InitInterpolationValue();
890 
891     std::shared_ptr<RSPathAnimationMock> animation1 =
892         std::make_shared<RSPathAnimationMock>(property, "abc", startValue, endValue);
893     std::shared_ptr<RSPathAnimationMock> animation2 =
894         std::make_shared<RSPathAnimationMock>(property, "abc", startValue, endValue);
895     struct RSSurfaceNodeConfig surfaceNodeConfig = {.SurfaceNodeName = "test"};
896     std::shared_ptr<RSNode> node1 = RSSurfaceNode::Create(surfaceNodeConfig, false);
897     std::shared_ptr<RSNode> node2 = RSSurfaceNode::Create(surfaceNodeConfig, true);
898     animation1->Start(node1);
899     animation1->OnStart();
900     animation2->Start(node1);
901     animation2->OnStart();
902     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest018 end";
903 }
904 
905 class RSSpringAnimationMock : public RSSpringAnimation {
906 public:
RSSpringAnimationMock(std::shared_ptr<RSPropertyBase> property,const std::shared_ptr<RSPropertyBase> & byValue)907     RSSpringAnimationMock(std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPropertyBase>& byValue)
908         : RSSpringAnimation(property, byValue) {}
909 
RSSpringAnimationMock(std::shared_ptr<RSPropertyBase> property,const std::shared_ptr<RSPropertyBase> & startValue,const std::shared_ptr<RSPropertyBase> & endValue)910     RSSpringAnimationMock(std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPropertyBase>& startValue,
911         const std::shared_ptr<RSPropertyBase>& endValue)
912         : RSSpringAnimation(property, startValue, endValue) {}
913     ~RSSpringAnimationMock() = default;
914 
OnStart()915     void OnStart() override
916     {
917         RSSpringAnimation::OnStart();
918     }
919 };
920 
921 /**
922  * @tc.name: AnimationSupplementTest019
923  * @tc.desc: Verify the setcallback of Animation
924  * @tc.type: FUNC
925  */
926 HWTEST_F(RSAnimationTest, AnimationSupplementTest019, TestSize.Level1)
927 {
928     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest019 start";
929     /**
930      * @tc.steps: step1. init
931      */
932     auto property = std::make_shared<RSAnimatableProperty<float>>(1.f);
933     auto value1 = std::make_shared<RSAnimatableProperty<float>>(2.f);
934     auto value2 = std::make_shared<RSAnimatableProperty<float>>(3.f);
935     std::shared_ptr<RSSpringAnimationMock> animation1 = std::make_shared<RSSpringAnimationMock>(property, value1);
936     std::shared_ptr<RSSpringAnimationMock> animation2 =
937         std::make_shared<RSSpringAnimationMock>(property, value1, value2);
938     animation1->SetTimingCurve(RSAnimationTimingCurve::LINEAR);
939     auto curve = RSAnimationTimingCurve::CreateSpringCurve(1.f, 2.f, 3.f, 4.f);
940     animation1->SetTimingCurve(curve);
941     animation1->SetIsCustom(true);
942     animation1->OnStart();
943     animation1->SetIsCustom(false);
944     animation1->OnStart();
945     std::shared_ptr<RSNode> node = RSCanvasNode::Create();
946     animation1->Start(node);
947     animation1->SetIsCustom(true);
948     animation1->OnStart();
949     animation1->SetIsCustom(false);
950     animation1->OnStart();
951 
952     std::shared_ptr<RSSpringAnimationMock> animation3 =
953         std::make_shared<RSSpringAnimationMock>(property, value1, value2);
954     struct RSSurfaceNodeConfig surfaceNodeConfig = {.SurfaceNodeName = "test"};
955     std::shared_ptr<RSNode> node1 = RSSurfaceNode::Create(surfaceNodeConfig, false);
956     std::shared_ptr<RSNode> node2 = RSSurfaceNode::Create(surfaceNodeConfig, true);
957     animation2->Start(node1);
958     animation2->OnStart();
959     animation3->Start(node1);
960     animation3->OnStart();
961     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest019 end";
962 }
963 
964 class MyData : public RSAnimatableArithmetic<MyData> {
965 public:
MyData()966     MyData() : data(0.f) {}
MyData(const float num)967     explicit MyData(const float num) : data(num) {}
968     virtual ~MyData() = default;
969 
Add(const MyData & value) const970     MyData Add(const MyData& value) const override
971     {
972         float res = data + value.data;
973         return MyData(res);
974     }
Minus(const MyData & value) const975     MyData Minus(const MyData& value) const override
976     {
977         float res = data - value.data;
978         return MyData(res);
979     }
Multiply(const float scale) const980     MyData Multiply(const float scale) const override
981     {
982         float res = data * scale;
983         return MyData(res);
984     }
IsEqual(const MyData & value) const985     bool IsEqual(const MyData& value) const override
986     {
987         return data == value.data;
988     }
989 
990     float data;
991 };
992 
993 /**
994  * @tc.name: AnimationSupplementTest020
995  * @tc.desc: Verify the setcallback of Animation
996  * @tc.type: FUNC
997  */
998 HWTEST_F(RSAnimationTest, AnimationSupplementTest020, TestSize.Level1)
999 {
1000     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest020 start";
1001     /**
1002      * @tc.steps: step1. init
1003      */
1004     auto data1 = MyData();
1005     auto data2 = MyData();
1006     [[maybe_unused]] bool ret = data1 == data2;
1007 
1008     RSFilter filter1;
1009     filter1.IsNearEqual(nullptr, ANIMATION_DEFAULT_VALUE);
1010     filter1.IsNearZero(ANIMATION_DEFAULT_VALUE);
1011     filter1.IsEqual(nullptr);
1012     filter1.IsEqualZero();
1013 
1014     RSImageBase imageBase;
1015     Parcel parcel;
1016     imageBase.Marshalling(parcel);
1017 
1018     RRectT<float> rect1;
1019     RRectT<float> rect2;
1020     auto tmp = rect1 * ANIMATION_END_VALUE;
1021     tmp *= ANIMATION_END_VALUE;
1022     [[maybe_unused]] bool ret1 = tmp != rect2;
1023     rect1.IsNearEqual(rect2, ANIMATION_DEFAULT_VALUE);
1024 
1025     RectT<float> rect3;
1026     RectT<float> rect4;
1027     rect3.Intersect(rect4);
1028 
1029     RSDisplayNodeConfig config = { 0, false, 0 };
1030     RSDisplayNode::SharedPtr displayNode = RSDisplayNode::Create(config);
1031     displayNode->Marshalling(parcel);
1032 
1033     auto& rsInterfaces = RSInterfaces::GetInstance();
1034     rsInterfaces.EnableCacheForRotation();
1035     rsInterfaces.DisableCacheForRotation();
1036 
1037     auto mask = RSMask::Unmarshalling(parcel);
1038     delete mask;
1039 
1040     RSLightUpEffectFilter filter3(ANIMATION_DEFAULT_VALUE);
1041     filter3.IsNearEqual(nullptr, ANIMATION_DEFAULT_VALUE);
1042     filter3.IsNearZero(ANIMATION_DEFAULT_VALUE);
1043     filter3.IsEqual(nullptr);
1044     filter3.IsEqualZero();
1045 
1046     NodeId id = 1;
1047     RSModifierExtractor extractor(id);
1048     extractor.GetCameraDistance();
1049     extractor.GetShadowMask();
1050     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest020 end";
1051 }
1052 
1053 /**
1054  * @tc.name: AnimationSupplementTest021
1055  * @tc.desc: Verify the setcallback of Animation
1056  * @tc.type: FUNC
1057  */
1058 HWTEST_F(RSAnimationTest, AnimationSupplementTest021, TestSize.Level1)
1059 {
1060     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest021 start";
1061     /**
1062      * @tc.steps: step1. init
1063      */
1064     RSPropertyBase property;
1065     [[maybe_unused]] auto tmp = property.GetThreshold();
1066     property.SetValueFromRender(nullptr);
1067 
1068     RSModifierManager modifierManager;
1069     modifierManager.HasUIRunningAnimation();
1070     auto animatablProperty = std::make_shared<RSAnimatableProperty<float>>(1.f);
1071     auto value = std::make_shared<RSAnimatableProperty<float>>(1.f);
1072     auto springAnimation = std::make_shared<RSSpringAnimationMock>(animatablProperty, value);
1073     modifierManager.RegisterSpringAnimation(springAnimation->GetPropertyId(), springAnimation->GetId());
1074     modifierManager.UnregisterSpringAnimation(springAnimation->GetPropertyId(), springAnimation->GetId());
1075 
1076     std::string str;
1077     RSMotionPathOption option(str);
1078     option.SetRotationMode(RotationMode::ROTATE_AUTO);
1079     option.GetRotationMode();
1080     option.SetPathNeedAddOrigin(true);
1081     option.GetPathNeedAddOrigin();
1082 
1083     RSBlurFilter filter(0, 0);
1084     filter.IsEqual(nullptr);
1085     filter.IsEqualZero();
1086 
1087     float dipScale = 1.0;
1088     BLUR_COLOR_MODE mode = BLUR_COLOR_MODE::DEFAULT;
1089     MATERIAL_BLUR_STYLE style = static_cast<MATERIAL_BLUR_STYLE>(0);
1090     float ratio = 1.0;
1091     RSMaterialFilter rsMaterialFilter(style, dipScale, mode, ratio);
1092     rsMaterialFilter.IsEqual(nullptr);
1093     rsMaterialFilter.IsEqualZero();
1094 
1095     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest021 end";
1096 }
1097 
1098 /**
1099  * @tc.name: AnimationSupplementTest022
1100  * @tc.desc: Verify the setcallback of Animation
1101  * @tc.type: FUNC
1102  */
1103 HWTEST_F(RSAnimationTest, AnimationSupplementTest022, TestSize.Level1)
1104 {
1105     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest022 start";
1106     /**
1107      * @tc.steps: step1. init
1108      */
1109     auto property = std::make_shared<RSAnimatableProperty<float>>(1.f);
1110     property->GetStagingValue();
1111     auto stagingValue = property->Get();
1112     property->Set(stagingValue);
1113     property->GetShowingValueAndCancelAnimation();
1114     property->RequestCancelAnimation();
1115     auto propertyUnit_ { RSPropertyUnit::UNKNOWN };
1116     property->SetPropertyUnit(propertyUnit_);
1117     auto base = std::make_shared<RSRenderPropertyBase>();
1118     property->SetValueFromRender(base);
1119     property->SetUpdateCallback(nullptr);
1120     RSAnimationTimingProtocol timingProtocol;
1121     RSAnimationTimingCurve timingCurve;
1122     timingProtocol.SetFinishCallbackType(FinishCallbackType::TIME_SENSITIVE);
1123     std::shared_ptr<RSPropertyBase> targetValue = std::make_shared<RSAnimatableProperty<float>>(0.1f);
1124     property->AnimateWithInitialVelocity(timingProtocol, timingCurve, targetValue);
1125 
1126     std::shared_ptr<RSNode> node = RSCanvasNode::Create();
1127     node->SetShadowMask(true);
1128     node->IsImplicitAnimationOpen();
1129     node->GetChildIdByIndex(1);
1130     std::string nodeName = "nodeName";
1131     node->SetNodeName(nodeName);
1132     PropertyCallback callback;
__anona9ac6d9e0302() 1133     callback = []() {
1134     };
1135     node->AddDurationKeyFrame(100, timingCurve, callback); // 100 Set duration is 100ms
1136     NodeId id1 = 0;
1137     NodeId id2 = 1;
1138     node->RegisterTransitionPair(id1, id2);
1139     node->UnregisterTransitionPair(id1, id2);
1140     node->AnimateWithCurrentCallback(timingProtocol, timingCurve, callback);
1141     std::optional<Vector2f> vec(Vector2f(1.f, 1.f));
1142     node->SetSandBox(vec);
1143     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest022 end";
1144 }
1145 
1146 /**
1147  * @tc.name: AnimationSupplementTest023
1148  * @tc.desc: Verify the setcallback of Animation
1149  * @tc.type: FUNC
1150  */
1151 HWTEST_F(RSAnimationTest, AnimationSupplementTest023, TestSize.Level1)
1152 {
1153     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest023 start";
1154     /**
1155      * @tc.steps: step1. init
1156      */
1157     Vector4f vec1(1.f, 1.f, 1.f, 1.f);
1158     NodeId nodeId = 1;
1159     NodeId childNode = 2; // 2 is childNode
1160     auto node = RSProxyNode::Create(nodeId);
1161     auto child = RSProxyNode::Create(childNode);
1162     node->SetBounds(vec1);
1163     node->SetFrame(vec1);
1164     node->SetBounds(1.f, 1.f, 1.f, 1.f);
1165     node->SetBoundsWidth(1.f);
1166     node->SetBoundsHeight(1.f);
1167     node->SetFrame(1.f, 1.f, 1.f, 1.f);
1168     node->SetFramePositionX(1.f);
1169     node->SetFramePositionY(1.f);
1170     node->GetType();
1171     node->AddChild(child, 1);
1172     node->RemoveChild(child);
1173     node->ClearChildren();
1174 
1175     auto rsUiDirector = RSUIDirector::Create();
1176     rsUiDirector->FlushAnimationStartTime(1);
1177     rsUiDirector->HasUIRunningAnimation();
1178 
1179     Vector4 vec = { 0.f, 0.f, 0.f, 0.f };
1180     vec.IsNearEqual(vec1, 1.f);
1181     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest023 end";
1182 }
1183 
1184 class MyNewData : public RSArithmetic<MyNewData> {
1185 public:
MyNewData()1186     MyNewData() : data(0.f) {}
MyNewData(const float num)1187     explicit MyNewData(const float num) : data(num) {}
1188     virtual ~MyNewData() = default;
IsEqual(const MyNewData & value) const1189     bool IsEqual(const MyNewData& value) const override
1190     {
1191         return data == value.data;
1192     }
1193 
1194     float data;
1195 };
1196 
1197 HWTEST_F(RSAnimationTest, AnimationSupplementTest024, TestSize.Level1)
1198 {
1199     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest024 start";
1200     /**
1201      * @tc.steps: step1. init
1202      */
1203     Vector2f data(1.f, 1.f);
1204     RRectT<float> rect1;
1205     RRectT<float> rect2;
1206     RectT<float> rect3;
1207     RectT<float> rect4;
1208     rect1.SetValues(rect3, &data);
1209     rect2.SetValues(rect4, &data);
1210     rect1.IsNearEqual(rect2);
1211     auto temp1 = rect1 - rect2;
1212     rect1 = temp1 + rect2;
1213     temp1 = rect1 * (1.f);
1214     temp1 = temp1 / (1.f);
1215     temp1 += rect1;
1216     temp1 -= rect1;
1217     temp1 *= (1.f);
1218     temp1 = rect1;
1219     [[maybe_unused]] bool ret = (temp1 != rect2);
1220     ret = (temp1 == rect2);
1221 
1222     auto data1 = MyData();
1223     auto data2 = MyData();
1224     auto temp2 = data1 + data2;
1225     temp2 += data1;
1226     temp2 -= data1;
1227     data1 = temp2 - data2;
1228     temp2 = data1 * (1.f);
1229     temp2 *= (1.f);
1230 
1231     auto data3 = MyNewData();
1232     auto data4 = MyNewData();
1233     ret = (data3 == data4);
1234     ret = (data3 != data4);
1235 
1236     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest024 end";
1237 }
1238 
1239 /**
1240  * @tc.name: AnimationSupplementTest025
1241  * @tc.desc: Verify the CloseImplicitCancelAnimation of Animation
1242  * @tc.type: FUNC
1243  */
1244 HWTEST_F(RSAnimationTest, AnimationSupplementTest025, TestSize.Level1)
1245 {
1246     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest025 start";
1247     /**
1248      * @tc.steps: step1. init
1249      */
1250     bool success = false;
1251     auto implicitAnimator = std::make_shared<RSImplicitAnimator>();
1252     success = implicitAnimator->CloseImplicitCancelAnimation();
1253     EXPECT_TRUE(!success);
1254 
1255     RSAnimationTimingProtocol protocol;
1256     protocol.SetDuration(100);
1257     implicitAnimator->OpenImplicitAnimation(protocol, RSAnimationTimingCurve::LINEAR, nullptr);
1258     success = implicitAnimator->CloseImplicitCancelAnimation();
1259     EXPECT_TRUE(!success);
1260 
1261     protocol.SetDuration(0);
1262     implicitAnimator->OpenImplicitAnimation(protocol, RSAnimationTimingCurve::LINEAR, nullptr);
1263     success = implicitAnimator->CloseImplicitCancelAnimation();
1264     EXPECT_TRUE(!success);
1265     GTEST_LOG_(INFO) << "RSAnimationTest AnimationSupplementTest025 end";
1266 }
1267 } // namespace Rosen
1268 } // namespace OHOS