2 * Copyright (c) 2023 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 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-scene3d/public-api/model-motion/motion-value.h>
24 #include <dali/devel-api/animation/key-frames-devel.h>
27 using namespace Dali::Toolkit;
28 using namespace Dali::Scene3D;
30 void model_motion_motion_value_startup(void)
32 test_return_value = TET_UNDEF;
35 void model_motion_motion_value_cleanup(void)
37 test_return_value = TET_PASS;
44 // Positive test case for a method
45 int UtcDaliMotionValueNew(void)
47 ToolkitTestApplication application;
48 tet_infoline(" UtcDaliMotionValueNew");
50 MotionValue motionValue = MotionValue::New();
51 DALI_TEST_CHECK(motionValue);
55 // Positive test case for a method
56 int UtcDaliMotionValueDownCast(void)
58 ToolkitTestApplication application;
59 tet_infoline(" UtcDaliMotionValueDownCast");
61 MotionValue motionValue = MotionValue::New();
62 BaseHandle handle(motionValue);
64 MotionValue motionValue2 = MotionValue::DownCast(handle);
65 DALI_TEST_CHECK(motionValue);
66 DALI_TEST_CHECK(motionValue2);
67 DALI_TEST_CHECK(motionValue2 == motionValue);
71 int UtcDaliMotionValueTypeRegistry(void)
73 ToolkitTestApplication application;
75 TypeRegistry typeRegistry = TypeRegistry::Get();
76 DALI_TEST_CHECK(typeRegistry);
78 TypeInfo typeInfo = typeRegistry.GetTypeInfo("MotionValue");
79 DALI_TEST_CHECK(typeInfo);
81 BaseHandle handle = typeInfo.CreateInstance();
82 DALI_TEST_CHECK(handle);
84 MotionValue motionValue = MotionValue::DownCast(handle);
85 DALI_TEST_CHECK(motionValue);
90 int UtcDaliMotionValueCopyAndAssignment(void)
92 ToolkitTestApplication application;
94 MotionValue motionValue = MotionValue::New(1);
95 DALI_TEST_CHECK(motionValue);
96 DALI_TEST_CHECK(motionValue.GetValueType() == MotionValue::ValueType::PROPERTY_VALUE);
98 MotionValue copy(motionValue);
99 DALI_TEST_CHECK(motionValue == copy);
100 DALI_TEST_CHECK(copy.GetValueType() == MotionValue::ValueType::PROPERTY_VALUE);
103 DALI_TEST_CHECK(!assign);
106 DALI_TEST_CHECK(assign == motionValue);
107 DALI_TEST_CHECK(assign.GetValueType() == MotionValue::ValueType::PROPERTY_VALUE);
112 int UtcDaliMotionValueMoveConstructor(void)
114 ToolkitTestApplication application;
116 MotionValue motionValue = MotionValue::New(3.0f);
117 DALI_TEST_EQUALS(1, motionValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
118 DALI_TEST_CHECK(motionValue.GetValueType() == MotionValue::ValueType::PROPERTY_VALUE);
120 MotionValue moved = std::move(motionValue);
121 DALI_TEST_CHECK(moved);
122 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
123 DALI_TEST_CHECK(moved.GetValueType() == MotionValue::ValueType::PROPERTY_VALUE);
124 DALI_TEST_CHECK(!motionValue);
129 int UtcDaliMotionValueMoveAssignment(void)
131 ToolkitTestApplication application;
133 MotionValue motionValue = MotionValue::New(KeyFrames::New());
134 DALI_TEST_EQUALS(1, motionValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
135 DALI_TEST_CHECK(motionValue.GetValueType() == MotionValue::ValueType::KEY_FRAMES);
138 moved = std::move(motionValue);
139 DALI_TEST_CHECK(moved);
140 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
141 DALI_TEST_CHECK(moved.GetValueType() == MotionValue::ValueType::KEY_FRAMES);
148 int UtcDaliMotionValueGetSetValue(void)
150 ToolkitTestApplication application;
152 MotionValue motionValue = MotionValue::New();
153 DALI_TEST_CHECK(motionValue.GetValueType() == MotionValue::ValueType::INVALID);
154 DALI_TEST_CHECK(motionValue.GetPropertyValue().GetType() == Property::Type::NONE);
155 DALI_TEST_CHECK(!motionValue.GetKeyFrames());
157 float expectValue = 3.0f;
158 motionValue.SetValue(expectValue);
159 DALI_TEST_CHECK(motionValue.GetValueType() == MotionValue::ValueType::PROPERTY_VALUE);
160 DALI_TEST_CHECK(motionValue.GetPropertyValue().GetType() == Property::Type::FLOAT);
161 DALI_TEST_CHECK(motionValue.GetPropertyValue().Get<float>() == expectValue);
163 // Check the converted KeyFrames
164 auto convertedKeyFrames = motionValue.GetKeyFrames();
165 DALI_TEST_CHECK(convertedKeyFrames);
166 auto convertedKeyFrameCount = DevelKeyFrames::GetKeyFrameCount(convertedKeyFrames);
167 for(auto i = 0u; i < convertedKeyFrameCount; ++i)
170 Property::Value value;
171 DevelKeyFrames::GetKeyFrame(convertedKeyFrames, i, progress, value);
173 // Check all value has same as expect property.
174 DALI_TEST_EQUALS(value.Get<float>(), expectValue, TEST_LOCATION);
177 KeyFrames expectKeyFrames = KeyFrames::New();
179 expectKeyFrames.Add(0.0f, expectValue - 1.0f);
180 expectKeyFrames.Add(1.0f, expectValue);
181 motionValue.SetValue(expectKeyFrames);
183 DALI_TEST_CHECK(motionValue.GetValueType() == MotionValue::ValueType::KEY_FRAMES);
184 DALI_TEST_CHECK(motionValue.GetKeyFrames() == expectKeyFrames);
186 // Check property value return last frame value.
187 DALI_TEST_CHECK(motionValue.GetPropertyValue().GetType() == Property::Type::FLOAT);
188 DALI_TEST_EQUALS(motionValue.GetPropertyValue().Get<float>(), expectValue, TEST_LOCATION);
190 // Check invalidate value.
191 motionValue.Invalidate();
192 DALI_TEST_CHECK(motionValue.GetValueType() == MotionValue::ValueType::INVALID);
193 DALI_TEST_CHECK(motionValue.GetPropertyValue().GetType() == Property::Type::NONE);
194 DALI_TEST_CHECK(!motionValue.GetKeyFrames());
196 motionValue.SetValue(expectKeyFrames);
197 DALI_TEST_CHECK(motionValue.GetValueType() == MotionValue::ValueType::KEY_FRAMES);
198 DALI_TEST_CHECK(motionValue.GetKeyFrames() == expectKeyFrames);
200 // Check invalidate value by Clear().
202 DALI_TEST_CHECK(motionValue.GetValueType() == MotionValue::ValueType::INVALID);
203 DALI_TEST_CHECK(motionValue.GetPropertyValue().GetType() == Property::Type::NONE);
204 DALI_TEST_CHECK(!motionValue.GetKeyFrames());