Change public member variable to private
[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 Dali::Scene3D::Loader::AnimatedProperty& property) {
48     return actor.FindChildByName(property.mNodeName);
49   };
50
51   uint32_t animatedPropertyIndex = 0;
52   for (bool b: { false, true })
53   {
54     AnimationDefinition animDef;
55     animDef.SetName("WalkRight");
56     animDef.SetDuration(10.f);
57     animDef.SetLoopCount(2);
58     animDef.SetEndAction(Animation::BAKE_FINAL);
59     animDef.SetSpeedFactor(.7f);
60     animDef.SetProperty(animatedPropertyIndex++,std::move(AnimatedProperty{
61      INVALID_INDEX,
62      "ChristopherPlummer",
63      "position",
64      KeyFrames(),
65      std::unique_ptr<AnimatedProperty::Value>{ new AnimatedProperty::Value{
66        Property::Value{ Vector3::XAXIS * 100.f },
67        b
68      } },
69      AlphaFunction::EASE_OUT,
70      TimePeriod(animDef.GetDuration())
71     }));
72
73     auto anim = animDef.ReAnimate(getActor);
74     DALI_TEST_EQUAL(anim.GetDuration(), animDef.GetDuration());
75     DALI_TEST_EQUAL(anim.GetEndAction(), animDef.GetEndAction());
76     DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.GetSpeedFactor());
77     DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.GetLoopCount());
78   }
79
80   END_TEST;
81 }
82
83 int UtcDaliAnimationDefinitionReAnimateKeyFrames(void)
84 {
85   TestApplication app;
86   auto actor = Actor::New();
87   actor.SetProperty(Actor::Property::NAME, "ChristopherPlummer");
88
89   auto getActor = [&actor](const Dali::Scene3D::Loader::AnimatedProperty& property) {
90     return actor.FindChildByName(property.mNodeName);
91   };
92
93   KeyFrames kf = KeyFrames::New();
94   kf.Add(0.f, Vector3::ZERO);
95   kf.Add(1.f, Vector3::XAXIS * 100.f);
96
97   uint32_t animatedPropertyIndex = 0;
98   AnimationDefinition animDef;
99   animDef.SetName("WalkRight");
100   animDef.SetDuration(10.f);
101   animDef.SetLoopCount(2);
102   animDef.SetEndAction(Animation::BAKE_FINAL);
103   animDef.SetSpeedFactor(.7f);
104   animDef.SetProperty(animatedPropertyIndex++, std::move(AnimatedProperty{
105    INVALID_INDEX,
106    "ChristopherPlummer",
107    "position",
108    kf,
109    nullptr,
110    AlphaFunction::EASE_OUT,
111    TimePeriod(animDef.GetDuration())
112   }));
113
114   auto anim = animDef.ReAnimate(getActor);
115   DALI_TEST_EQUAL(anim.GetDuration(), animDef.GetDuration());
116   DALI_TEST_EQUAL(anim.GetEndAction(), animDef.GetEndAction());
117   DALI_TEST_EQUAL(anim.GetSpeedFactor(), animDef.GetSpeedFactor());
118   DALI_TEST_EQUAL(anim.GetLoopCount(), animDef.GetLoopCount());
119
120   END_TEST;
121 }