2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
21 #include "dali-scene3d/public-api/loader/animation-definition.h"
22 #include <dali-test-suite-utils.h>
25 using namespace Dali::Scene3D::Loader;
27 int UtcDaliAnimationDefinitionStopForModification(void)
30 auto anim = Animation::New(15.f);
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);
41 int UtcDaliAnimationDefinitionReAnimate(void)
44 auto actor = Actor::New();
45 actor.SetProperty(Actor::Property::NAME, "ChristopherPlummer");
47 auto getActor = [&actor](const Dali::Scene3D::Loader::AnimatedProperty& property) {
48 return actor.FindChildByName(property.mNodeName);
51 uint32_t animatedPropertyIndex = 0;
52 for (bool b: { false, true })
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{
65 std::unique_ptr<AnimatedProperty::Value>{ new AnimatedProperty::Value{
66 Property::Value{ Vector3::XAXIS * 100.f },
69 AlphaFunction::EASE_OUT,
70 TimePeriod(animDef.GetDuration())
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());
83 int UtcDaliAnimationDefinitionReAnimateKeyFrames(void)
86 auto actor = Actor::New();
87 actor.SetProperty(Actor::Property::NAME, "ChristopherPlummer");
89 auto getActor = [&actor](const Dali::Scene3D::Loader::AnimatedProperty& property) {
90 return actor.FindChildByName(property.mNodeName);
93 KeyFrames kf = KeyFrames::New();
94 kf.Add(0.f, Vector3::ZERO);
95 kf.Add(1.f, Vector3::XAXIS * 100.f);
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{
106 "ChristopherPlummer",
110 AlphaFunction::EASE_OUT,
111 TimePeriod(animDef.GetDuration())
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());