2 * Copyright (c) 2024 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-test-suite-utils.h>
19 #include <dali/devel-api/animation/path-constrainer.h>
20 #include <dali/public-api/dali-core.h>
26 using namespace Dali::Internal;
30 static void SetupPath(Dali::Path& path)
32 path.AddPoint(Vector3(30.0, 80.0, 0.0));
33 path.AddPoint(Vector3(70.0, 120.0, 0.0));
34 path.AddPoint(Vector3(100.0, 100.0, 0.0));
36 //Control points for first segment
37 path.AddControlPoint(Vector3(39.0, 90.0, 0.0));
38 path.AddControlPoint(Vector3(56.0, 119.0, 0.0));
40 //Control points for second segment
41 path.AddControlPoint(Vector3(78.0, 120.0, 0.0));
42 path.AddControlPoint(Vector3(93.0, 104.0, 0.0));
45 static void SetupPathConstrainer(Dali::PathConstrainer& PathConstrainer)
47 PathConstrainer.SetProperty(Dali::PathConstrainer::Property::FORWARD, Vector3(1.0f, 0.0f, 0.0f));
49 Dali::Property::Array points;
51 points[0] = Vector3(30.0, 80.0, 0.0);
52 points[1] = Vector3(70.0, 120.0, 0.0);
53 points[2] = Vector3(100.0, 100.0, 0.0);
54 PathConstrainer.SetProperty(Dali::PathConstrainer::Property::POINTS, points);
57 points[0] = Vector3(39.0, 90.0, 0.0);
58 points[1] = Vector3(56.0, 119.0, 0.0);
59 points[2] = Vector3(78.0, 120.0, 0.0);
60 points[3] = Vector3(93.0, 104.0, 0.0);
61 PathConstrainer.SetProperty(Dali::PathConstrainer::Property::CONTROL_POINTS, points);
64 static void SetupLinearConstrainerUniformProgress(Dali::LinearConstrainer& linearConstrainer)
66 Dali::Property::Array points;
71 linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points);
74 static void VerifyLinearConstrainerUniformProgress(Dali::LinearConstrainer& linearConstrainer)
76 Dali::Property::Array points;
82 Property::Value value = linearConstrainer.GetProperty(Dali::LinearConstrainer::Property::VALUE);
83 Property::Array* array = value.GetArray();
84 DALI_TEST_CHECK(array);
86 const unsigned int noOfPoints = points.Size();
87 for(unsigned int i = 0; i < noOfPoints; ++i)
89 DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
93 static void SetupLinearConstrainerNonUniformProgress(Dali::LinearConstrainer& linearConstrainer)
95 Dali::Property::Array points;
100 linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points);
105 linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::PROGRESS, points);
108 static void SetupLinearConstrainerNonUniformProgressNonStartWithZero(Dali::LinearConstrainer& linearConstrainer)
110 Dali::Property::Array points;
115 linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points);
120 linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::PROGRESS, points);
123 } // anonymous namespace
125 //PathConstrainer test cases
126 int UtcPathConstrainerApply(void)
128 TestApplication application;
130 Dali::Actor actor = Dali::Actor::New();
132 // Register a float property
133 Property::Index index = actor.RegisterProperty("t", 0.0f);
135 application.GetScene().Add(actor);
138 Dali::Path path = Dali::Path::New();
141 //Create a PathConstrainer
142 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
143 SetupPathConstrainer(pathConstrainer);
145 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
146 Vector2 range(0.0f, 1.0f);
147 pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
149 //Create an animation to animate the custom property
150 float durationSeconds(1.0f);
151 Dali::Animation animation = Dali::Animation::New(durationSeconds);
152 animation.AnimateTo(Dali::Property(actor, index), 1.0f);
155 application.SendNotification();
156 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 20% progress */);
158 Vector3 position, tangent;
159 path.Sample(0.2f, position, tangent);
160 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
162 application.SendNotification();
163 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 40% progress */);
164 path.Sample(0.4f, position, tangent);
165 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
167 application.SendNotification();
168 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 60% progress */);
169 path.Sample(0.6f, position, tangent);
170 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
172 application.SendNotification();
173 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 80% progress */);
174 path.Sample(0.8f, position, tangent);
175 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
177 application.SendNotification();
178 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 100% progress */);
179 path.Sample(1.0f, position, tangent);
180 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
182 application.SendNotification();
183 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* beyond the animation duration*/);
184 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
189 int UtcPathConstrainerApplyRange(void)
191 TestApplication application;
193 Dali::Actor actor = Dali::Actor::New();
195 // Register a float property
196 Property::Index index = actor.RegisterProperty("t", 0.0f);
197 application.GetScene().Add(actor);
200 Dali::Path path = Dali::Path::New();
203 //Create a PathConstrainer
204 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
205 SetupPathConstrainer(pathConstrainer);
207 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
208 Vector2 range(100.0f, 300.0f);
209 pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
211 //Create an animation to animate the custom property
212 float durationSeconds(1.0f);
213 Dali::Animation animation = Dali::Animation::New(durationSeconds);
214 animation.AnimateTo(Dali::Property(actor, index), 400.0f);
217 application.SendNotification();
218 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
220 Vector3 position, tangent;
222 actor.GetCurrentProperty(index).Get(tValue);
223 float currentCursor = (tValue - range.x) / (range.y - range.x);
224 path.Sample(currentCursor, position, tangent);
225 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
227 application.SendNotification();
228 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
229 actor.GetCurrentProperty(index).Get(tValue);
230 currentCursor = (tValue - range.x) / (range.y - range.x);
231 path.Sample(currentCursor, position, tangent);
232 path.Sample(0.5, position, tangent);
233 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
235 application.SendNotification();
236 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
237 actor.GetCurrentProperty(index).Get(tValue);
238 currentCursor = (tValue - range.x) / (range.y - range.x);
239 path.Sample(currentCursor, position, tangent);
240 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
242 application.SendNotification();
243 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
244 actor.GetCurrentProperty(index).Get(tValue);
245 currentCursor = (tValue - range.x) / (range.y - range.x);
246 path.Sample(currentCursor, position, tangent);
247 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
249 application.SendNotification();
250 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
251 actor.GetCurrentProperty(index).Get(tValue);
252 currentCursor = (tValue - range.x) / (range.y - range.x);
253 path.Sample(currentCursor, position, tangent);
254 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
256 // Ensure GetProperty also returns the final result
257 actor.GetProperty(index).Get(tValue);
258 currentCursor = (tValue - range.x) / (range.y - range.x);
259 path.Sample(currentCursor, position, tangent);
260 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
265 int UtcPathConstrainerDestroy(void)
267 TestApplication application;
269 Dali::Actor actor = Dali::Actor::New();
271 // Register a float property
272 Property::Index index = actor.RegisterProperty("t", 0.0f);
273 application.GetScene().Add(actor);
277 Dali::Path path = Dali::Path::New();
280 //Create a PathConstrainer
281 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
282 SetupPathConstrainer(pathConstrainer);
284 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
285 Vector2 range(0.0f, 1.0f);
286 pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
288 //Test that the constraint is correctly applied
289 actor.SetProperty(index, 0.5f);
290 application.SendNotification();
291 application.Render(static_cast<unsigned int>(1.0f));
293 Vector3 position, tangent;
294 path.Sample(0.5f, position, tangent);
295 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
298 //PathConstrainer has been destroyed. Constraint in the actor should have been removed
299 actor.SetProperty(index, 0.75f);
300 application.SendNotification();
301 application.Render(static_cast<unsigned int>(1.0f));
303 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3::ZERO, TEST_LOCATION);
308 int UtcPathConstrainerRemove(void)
310 TestApplication application;
312 Dali::Actor actor = Dali::Actor::New();
314 // Register a float property
315 Property::Index index = actor.RegisterProperty("t", 0.0f);
316 application.GetScene().Add(actor);
319 Dali::Path path = Dali::Path::New();
322 //Create a PathConstrainer
323 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
324 SetupPathConstrainer(pathConstrainer);
326 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
327 Vector2 range(0.0f, 1.0f);
328 pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
330 //Test that the constraint is correctly applied
331 actor.SetProperty(index, 0.5f);
332 application.SendNotification();
333 application.Render(static_cast<unsigned int>(1.0f));
335 Vector3 position, tangent;
336 path.Sample(0.5f, position, tangent);
337 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
340 pathConstrainer.Remove(actor);
341 actor.SetProperty(index, 0.75f);
342 application.SendNotification();
343 application.Render(static_cast<unsigned int>(1.0f));
345 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3::ZERO, TEST_LOCATION);
350 int UtcPathConstrainerProperties(void)
352 TestApplication application;
353 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
355 pathConstrainer.SetProperty(Dali::PathConstrainer::Property::FORWARD, Vector3(1.0f, 0.0f, 0.0f));
356 DALI_TEST_EQUALS(pathConstrainer.GetProperty<Vector3>(Dali::PathConstrainer::Property::FORWARD), Vector3(1.0f, 0.0f, 0.0f), TEST_LOCATION);
357 DALI_TEST_EQUALS(pathConstrainer.GetCurrentProperty<Vector3>(Dali::PathConstrainer::Property::FORWARD), Vector3(1.0f, 0.0f, 0.0f), TEST_LOCATION);
359 Dali::Property::Array points;
361 points[0] = Vector3(30.0, 80.0, 0.0);
362 points[1] = Vector3(70.0, 120.0, 0.0);
363 points[2] = Vector3(100.0, 100.0, 0.0);
364 pathConstrainer.SetProperty(Dali::PathConstrainer::Property::POINTS, points);
367 Property::Value value = pathConstrainer.GetProperty(Dali::PathConstrainer::Property::POINTS);
368 Property::Array* array = value.GetArray();
369 DALI_TEST_CHECK(array);
371 const unsigned int noOfPoints = points.Size();
372 for(unsigned int i = 0; i < noOfPoints; ++i)
374 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
379 Property::Value value = pathConstrainer.GetCurrentProperty(Dali::PathConstrainer::Property::POINTS);
380 Property::Array* array = value.GetArray();
381 DALI_TEST_CHECK(array);
383 const unsigned int noOfPoints = points.Size();
384 for(unsigned int i = 0; i < noOfPoints; ++i)
386 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
391 points[0] = Vector3(39.0, 90.0, 0.0);
392 points[1] = Vector3(56.0, 119.0, 0.0);
393 points[2] = Vector3(78.0, 120.0, 0.0);
394 points[3] = Vector3(93.0, 104.0, 0.0);
395 pathConstrainer.SetProperty(Dali::PathConstrainer::Property::CONTROL_POINTS, points);
398 Property::Value value = pathConstrainer.GetProperty(Dali::PathConstrainer::Property::CONTROL_POINTS);
399 Property::Array* array = value.GetArray();
400 DALI_TEST_CHECK(array);
402 const unsigned int noOfPoints = points.Size();
403 for(unsigned int i = 0; i < noOfPoints; ++i)
405 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
410 Property::Value value = pathConstrainer.GetCurrentProperty(Dali::PathConstrainer::Property::CONTROL_POINTS);
411 Property::Array* array = value.GetArray();
412 DALI_TEST_CHECK(array);
414 const unsigned int noOfPoints = points.Size();
415 for(unsigned int i = 0; i < noOfPoints; ++i)
417 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
424 //LinearConstrainer test cases
425 int UtcLinearConstrainerDownCast(void)
427 TestApplication application;
428 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
430 BaseHandle handle(linearConstrainer);
431 Dali::LinearConstrainer linearConstrainer2 = Dali::LinearConstrainer::DownCast(handle);
432 DALI_TEST_EQUALS((bool)linearConstrainer2, true, TEST_LOCATION);
435 Dali::LinearConstrainer linearConstrainer3 = Dali::LinearConstrainer::DownCast(handle2);
436 DALI_TEST_EQUALS((bool)linearConstrainer3, false, TEST_LOCATION);
441 int UtcLinearConstrainerCopyConstructor(void)
443 TestApplication application;
444 Dali::LinearConstrainer linearConstrainer;
445 DALI_TEST_EQUALS((bool)linearConstrainer, false, TEST_LOCATION);
447 linearConstrainer = Dali::LinearConstrainer::New();
448 DALI_TEST_EQUALS((bool)linearConstrainer, true, TEST_LOCATION);
450 // call the copy constructor
451 Dali::LinearConstrainer linearConstrainer2(linearConstrainer);
452 DALI_TEST_EQUALS((bool)linearConstrainer2, true, TEST_LOCATION);
457 int UtcLinearConstrainerMoveConstructor(void)
459 TestApplication application;
461 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
462 DALI_TEST_CHECK(linearConstrainer);
463 DALI_TEST_EQUALS(1, linearConstrainer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
465 SetupLinearConstrainerUniformProgress(linearConstrainer);
466 VerifyLinearConstrainerUniformProgress(linearConstrainer);
468 Dali::LinearConstrainer moved = std::move(linearConstrainer);
469 DALI_TEST_CHECK(moved);
470 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
471 VerifyLinearConstrainerUniformProgress(moved);
472 DALI_TEST_CHECK(!linearConstrainer);
477 int UtcLinearConstrainerMoveAssignment(void)
479 TestApplication application;
481 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
482 DALI_TEST_CHECK(linearConstrainer);
483 DALI_TEST_EQUALS(1, linearConstrainer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
485 SetupLinearConstrainerUniformProgress(linearConstrainer);
486 VerifyLinearConstrainerUniformProgress(linearConstrainer);
488 Dali::LinearConstrainer moved;
489 moved = std::move(linearConstrainer);
490 DALI_TEST_CHECK(moved);
491 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
492 VerifyLinearConstrainerUniformProgress(moved);
493 DALI_TEST_CHECK(!linearConstrainer);
498 int UtcLinearConstrainerApply01(void)
500 TestApplication application;
502 Dali::Actor actor = Dali::Actor::New();
504 // Register a float property
505 Property::Index index = actor.RegisterProperty("t", 0.0f);
507 application.GetScene().Add(actor);
509 //Create a LinearConstrainer without specifying progress for values
510 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
511 SetupLinearConstrainerUniformProgress(linearConstrainer);
513 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
514 Vector2 range(0.0f, 1.0f);
515 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
517 //Create an animation to animate the custom property
518 float durationSeconds(1.0f);
519 Dali::Animation animation = Dali::Animation::New(durationSeconds);
520 animation.AnimateTo(Dali::Property(actor, index), 1.0f);
523 application.SendNotification();
524 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
526 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
528 application.SendNotification();
529 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
530 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
532 application.SendNotification();
533 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
534 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
536 application.SendNotification();
537 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
538 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
540 application.SendNotification();
541 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
542 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
544 //Setup a LinearConstrainer specifying the progress for each value
545 linearConstrainer.Remove(actor);
546 SetupLinearConstrainerNonUniformProgress(linearConstrainer);
547 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
549 actor.SetProperty(index, 0.0f);
551 application.SendNotification();
552 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
554 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
556 application.SendNotification();
557 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
558 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 2.0f / 3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
560 application.SendNotification();
561 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
562 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f / 3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
564 application.SendNotification();
565 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
566 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
568 application.SendNotification();
569 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
570 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
572 //Setup a LinearConstrainer specifying the progress for each value which is not start with 0.0f
573 linearConstrainer.Remove(actor);
574 SetupLinearConstrainerNonUniformProgressNonStartWithZero(linearConstrainer);
575 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
577 actor.SetProperty(index, 0.0f);
579 application.SendNotification();
580 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
582 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
584 application.SendNotification();
585 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
586 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
588 application.SendNotification();
589 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
590 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
592 application.SendNotification();
593 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
594 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
596 application.SendNotification();
597 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
598 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
603 int UtcLinearConstrainerApplyRange(void)
605 TestApplication application;
607 Dali::Actor actor = Dali::Actor::New();
609 // Register a float property
610 Property::Index index = actor.RegisterProperty("t", 100.0f);
611 application.GetScene().Add(actor);
613 //Create a LinearConstrainer
614 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
615 SetupLinearConstrainerUniformProgress(linearConstrainer);
617 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
618 Vector2 range(100.0f, 300.0f);
619 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
621 //Create an animation to animate the custom property
622 float durationSeconds(1.0f);
623 Dali::Animation animation = Dali::Animation::New(durationSeconds);
624 animation.AnimateTo(Dali::Property(actor, index), 300.0f);
627 application.SendNotification();
628 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
630 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
632 application.SendNotification();
633 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
634 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
636 application.SendNotification();
637 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
638 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
640 application.SendNotification();
641 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
642 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
644 application.SendNotification();
645 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
646 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
651 int UtcLinearConstrainerDestroy(void)
653 TestApplication application;
655 Dali::Actor actor = Dali::Actor::New();
657 // Register a float property
658 Property::Index index = actor.RegisterProperty("t", 0.0f);
659 application.GetScene().Add(actor);
662 //Create a LinearConstrainer
663 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
664 SetupLinearConstrainerUniformProgress(linearConstrainer);
666 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
667 Vector2 range(0.0f, 1.0f);
668 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
670 //Test that the constraint is correctly applied
671 actor.SetProperty(index, 0.5f);
672 application.SendNotification();
673 application.Render(static_cast<unsigned int>(1.0f));
675 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
678 //LinearConstrainer has been destroyed. Constraint in the actor should have been removed
679 actor.SetProperty(index, 0.75f);
680 application.SendNotification();
681 application.Render(static_cast<unsigned int>(1.0f));
683 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
688 int UtcLinearConstrainerRemove(void)
690 TestApplication application;
692 Dali::Actor actor = Dali::Actor::New();
694 // Register a float property
695 Property::Index index = actor.RegisterProperty("t", 0.0f);
696 application.GetScene().Add(actor);
698 //Create a LinearConstrainer
699 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
700 SetupLinearConstrainerUniformProgress(linearConstrainer);
702 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
703 Vector2 range(0.0f, 1.0f);
704 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
706 //Test that the constraint is correctly applied
707 actor.SetProperty(index, 0.5f);
708 application.SendNotification();
709 application.Render(static_cast<unsigned int>(1.0f));
711 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
714 linearConstrainer.Remove(actor);
715 actor.SetProperty(index, 0.75f);
716 application.SendNotification();
717 application.Render(static_cast<unsigned int>(1.0f));
719 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
724 int UtcLinearConstrainerProperties(void)
726 TestApplication application;
728 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
730 Dali::Property::Array points;
735 linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points);
738 Property::Value value = linearConstrainer.GetProperty(Dali::LinearConstrainer::Property::VALUE);
739 Property::Array* array = value.GetArray();
740 DALI_TEST_CHECK(array);
742 const unsigned int noOfPoints = points.Size();
743 for(unsigned int i = 0; i < noOfPoints; ++i)
745 DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
750 Property::Value value = linearConstrainer.GetCurrentProperty(Dali::LinearConstrainer::Property::VALUE);
751 Property::Array* array = value.GetArray();
752 DALI_TEST_CHECK(array);
754 const unsigned int noOfPoints = points.Size();
755 for(unsigned int i = 0; i < noOfPoints; ++i)
757 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
764 linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::PROGRESS, points);
767 Property::Value value = linearConstrainer.GetProperty(Dali::LinearConstrainer::Property::PROGRESS);
768 Property::Array* array = value.GetArray();
769 DALI_TEST_CHECK(array);
771 const unsigned int noOfPoints = points.Size();
772 for(unsigned int i = 0; i < noOfPoints; ++i)
774 DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
779 Property::Value value = linearConstrainer.GetCurrentProperty(Dali::LinearConstrainer::Property::PROGRESS);
780 Property::Array* array = value.GetArray();
781 DALI_TEST_CHECK(array);
783 const unsigned int noOfPoints = points.Size();
784 for(unsigned int i = 0; i < noOfPoints; ++i)
786 DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
793 int UtcDaliLinearConstrainerDetectorRegisterProperty(void)
795 TestApplication application;
797 Dali::LinearConstrainer constrainer = Dali::LinearConstrainer::New();
799 Property::Index index = constrainer.RegisterProperty("sceneProperty", 0);
800 DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
801 DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), 0, TEST_LOCATION);
803 constrainer.SetProperty(index, -123);
804 DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), -123, TEST_LOCATION);
806 using Dali::Animation;
807 Animation animation = Animation::New(1.0f);
808 animation.AnimateTo(Property(constrainer, index), 99);
810 DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), -123, TEST_LOCATION);
811 // Start the animation
814 application.SendNotification();
815 application.Render(1000 /* 100% progress */);
816 DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), 99, TEST_LOCATION);
821 int UtcDaliPathConstrainerDetectorRegisterProperty(void)
823 TestApplication application;
825 Dali::PathConstrainer constrainer = Dali::PathConstrainer::New();
827 Property::Index index = constrainer.RegisterProperty("pathProperty", Vector2());
828 DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
829 DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(), TEST_LOCATION);
831 constrainer.SetProperty(index, Vector2(1, 2));
832 DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(1, 2), TEST_LOCATION);
834 using Dali::Animation;
835 Animation animation = Animation::New(1.0f);
836 animation.AnimateTo(Property(constrainer, index), Vector2(3, 4));
838 DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(1, 2), TEST_LOCATION);
839 // Start the animation
842 application.SendNotification();
843 application.Render(1000 /* 100% progress */);
844 DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(3, 4), TEST_LOCATION);
849 int UtcDaliLinearConstrainerApplyNegative(void)
851 TestApplication application;
852 Dali::LinearConstrainer instance;
856 Dali::Property arg1(actor, Dali::Actor::Property::POSITION);
857 Dali::Property arg2(actor, Dali::Actor::Property::POSITION);
860 instance.Apply(arg1, arg2, arg3, arg4);
861 DALI_TEST_CHECK(false); // Should not get here
865 DALI_TEST_CHECK(true); // We expect an assert
870 int UtcDaliLinearConstrainerRemoveNegative(void)
872 TestApplication application;
873 Dali::LinearConstrainer instance;
877 instance.Remove(arg1);
878 DALI_TEST_CHECK(false); // Should not get here
882 DALI_TEST_CHECK(true); // We expect an assert