[dali_2.1.32] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-AnimationDefinition.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
20
21 #include "dali-scene3d/public-api/loader/animation-definition.h"
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25 using namespace Dali::Scene3D::Loader;
26
27 int UtcDaliAnimationDefinitionStopForModification(void)
28 {
29   TestApplication app;
30   auto anim = Animation::New(15.f);
31   anim.Play();
32
33   auto oldEndAction = AnimationDefinition::StopForModification(anim);
34   DALI_TEST_EQUAL(anim.GetState(), Animation::STOPPED);
35   DALI_TEST_EQUAL(oldEndAction, Animation::BAKE);
36   DALI_TEST_EQUAL(anim.GetEndAction(), Animation::DISCARD);
37
38   END_TEST;
39 }
40
41 int UtcDaliAnimationDefinitionReAnimate(void)
42 {
43   TestApplication app;
44   auto actor = Actor::New();
45   actor.SetProperty(Actor::Property::NAME, "ChristopherPlummer");
46
47   auto getActor = [&actor](const std::string& name) {
48     return actor.FindChildByName(name);
49   };
50
51   for (bool b: { false, true })
52   {
53     AnimationDefinition animDef;
54     animDef.mName = "WalkRight";
55     animDef.mDuration = 10.f;
56     animDef.mLoopCount = 2;
57     animDef.mEndAction = Animation::BAKE_FINAL;
58     animDef.mSpeedFactor = .7f;
59     animDef.mProperties.push_back(AnimatedProperty{
60      "ChristopherPlummer",
61      "position",
62      KeyFrames(),
63      std::unique_ptr<AnimatedProperty::Value>{ new AnimatedProperty::Value{
64        Property::Value{ Vector3::XAXIS * 100.f },
65        b
66      } },
67      AlphaFunction::EASE_OUT,
68      TimePeriod(animDef.mDuration)
69     });
70
71     auto anim = animDef.ReAnimate(getActor);
72     DALI_TEST_EQUAL(anim.GetDuration(), animDef.mDuration);
73     DALI_TEST_EQUAL(anim.GetEndAction(), animDef.mEndAction);
74     DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.mSpeedFactor);
75     DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.mLoopCount);
76   }
77
78   END_TEST;
79 }
80
81 int UtcDaliAnimationDefinitionReAnimateKeyFrames(void)
82 {
83   TestApplication app;
84   auto actor = Actor::New();
85   actor.SetProperty(Actor::Property::NAME, "ChristopherPlummer");
86
87   auto getActor = [&actor](const std::string& name) {
88     return actor.FindChildByName(name);
89   };
90
91   KeyFrames kf = KeyFrames::New();
92   kf.Add(0.f, Vector3::ZERO);
93   kf.Add(1.f, Vector3::XAXIS * 100.f);
94
95   AnimationDefinition animDef;
96   animDef.mName = "WalkRight";
97   animDef.mDuration = 10.f;
98   animDef.mLoopCount = 2;
99   animDef.mEndAction = Animation::BAKE_FINAL;
100   animDef.mSpeedFactor = .7f;
101   animDef.mProperties.push_back(AnimatedProperty{
102    "ChristopherPlummer",
103    "position",
104    kf,
105    nullptr,
106    AlphaFunction::EASE_OUT,
107    TimePeriod(animDef.mDuration)
108   });
109
110   auto anim = animDef.ReAnimate(getActor);
111   DALI_TEST_EQUAL(anim.GetDuration(), animDef.mDuration);
112   DALI_TEST_EQUAL(anim.GetEndAction(), animDef.mEndAction);
113   DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.mSpeedFactor);
114   DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.mLoopCount);
115
116   END_TEST;
117 }