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 #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 } // anonymous namespace
110 //PathConstrainer test cases
111 int UtcPathConstrainerApply(void)
113 TestApplication application;
115 Dali::Actor actor = Dali::Actor::New();
117 // Register a float property
118 Property::Index index = actor.RegisterProperty("t", 0.0f);
120 application.GetScene().Add(actor);
123 Dali::Path path = Dali::Path::New();
126 //Create a PathConstrainer
127 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
128 SetupPathConstrainer(pathConstrainer);
130 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
131 Vector2 range(0.0f, 1.0f);
132 pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
134 //Create an animation to animate the custom property
135 float durationSeconds(1.0f);
136 Dali::Animation animation = Dali::Animation::New(durationSeconds);
137 animation.AnimateTo(Dali::Property(actor, index), 1.0f);
140 application.SendNotification();
141 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 20% progress */);
143 Vector3 position, tangent;
144 path.Sample(0.2f, position, tangent);
145 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
147 application.SendNotification();
148 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 40% progress */);
149 path.Sample(0.4f, position, tangent);
150 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
152 application.SendNotification();
153 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 60% progress */);
154 path.Sample(0.6f, position, tangent);
155 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
157 application.SendNotification();
158 application.Render(static_cast<unsigned int>(durationSeconds * 200.0f) /* 80% progress */);
159 path.Sample(0.8f, 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) /* 100% progress */);
164 path.Sample(1.0f, 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) /* beyond the animation duration*/);
169 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
174 int UtcPathConstrainerApplyRange(void)
176 TestApplication application;
178 Dali::Actor actor = Dali::Actor::New();
180 // Register a float property
181 Property::Index index = actor.RegisterProperty("t", 0.0f);
182 application.GetScene().Add(actor);
185 Dali::Path path = Dali::Path::New();
188 //Create a PathConstrainer
189 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
190 SetupPathConstrainer(pathConstrainer);
192 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
193 Vector2 range(100.0f, 300.0f);
194 pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
196 //Create an animation to animate the custom property
197 float durationSeconds(1.0f);
198 Dali::Animation animation = Dali::Animation::New(durationSeconds);
199 animation.AnimateTo(Dali::Property(actor, index), 400.0f);
202 application.SendNotification();
203 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
205 Vector3 position, tangent;
207 actor.GetCurrentProperty(index).Get(tValue);
208 float currentCursor = (tValue - range.x) / (range.y - range.x);
209 path.Sample(currentCursor, position, tangent);
210 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
212 application.SendNotification();
213 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
214 actor.GetCurrentProperty(index).Get(tValue);
215 currentCursor = (tValue - range.x) / (range.y - range.x);
216 path.Sample(currentCursor, position, tangent);
217 path.Sample(0.5, position, tangent);
218 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
220 application.SendNotification();
221 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
222 actor.GetCurrentProperty(index).Get(tValue);
223 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) /* 100% progress */);
229 actor.GetCurrentProperty(index).Get(tValue);
230 currentCursor = (tValue - range.x) / (range.y - range.x);
231 path.Sample(currentCursor, position, tangent);
232 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
234 application.SendNotification();
235 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
236 actor.GetCurrentProperty(index).Get(tValue);
237 currentCursor = (tValue - range.x) / (range.y - range.x);
238 path.Sample(currentCursor, position, tangent);
239 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
241 // Ensure GetProperty also returns the final result
242 actor.GetProperty(index).Get(tValue);
243 currentCursor = (tValue - range.x) / (range.y - range.x);
244 path.Sample(currentCursor, position, tangent);
245 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
250 int UtcPathConstrainerDestroy(void)
252 TestApplication application;
254 Dali::Actor actor = Dali::Actor::New();
256 // Register a float property
257 Property::Index index = actor.RegisterProperty("t", 0.0f);
258 application.GetScene().Add(actor);
262 Dali::Path path = Dali::Path::New();
265 //Create a PathConstrainer
266 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
267 SetupPathConstrainer(pathConstrainer);
269 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
270 Vector2 range(0.0f, 1.0f);
271 pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
273 //Test that the constraint is correctly applied
274 actor.SetProperty(index, 0.5f);
275 application.SendNotification();
276 application.Render(static_cast<unsigned int>(1.0f));
278 Vector3 position, tangent;
279 path.Sample(0.5f, position, tangent);
280 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
283 //PathConstrainer has been destroyed. Constraint in the actor should have been removed
284 actor.SetProperty(index, 0.75f);
285 application.SendNotification();
286 application.Render(static_cast<unsigned int>(1.0f));
288 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3::ZERO, TEST_LOCATION);
293 int UtcPathConstrainerRemove(void)
295 TestApplication application;
297 Dali::Actor actor = Dali::Actor::New();
299 // Register a float property
300 Property::Index index = actor.RegisterProperty("t", 0.0f);
301 application.GetScene().Add(actor);
304 Dali::Path path = Dali::Path::New();
307 //Create a PathConstrainer
308 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
309 SetupPathConstrainer(pathConstrainer);
311 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
312 Vector2 range(0.0f, 1.0f);
313 pathConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION), Property(actor, index), range);
315 //Test that the constraint is correctly applied
316 actor.SetProperty(index, 0.5f);
317 application.SendNotification();
318 application.Render(static_cast<unsigned int>(1.0f));
320 Vector3 position, tangent;
321 path.Sample(0.5f, position, tangent);
322 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), position, TEST_LOCATION);
325 pathConstrainer.Remove(actor);
326 actor.SetProperty(index, 0.75f);
327 application.SendNotification();
328 application.Render(static_cast<unsigned int>(1.0f));
330 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION), Vector3::ZERO, TEST_LOCATION);
335 int UtcPathConstrainerProperties(void)
337 TestApplication application;
338 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
340 pathConstrainer.SetProperty(Dali::PathConstrainer::Property::FORWARD, Vector3(1.0f, 0.0f, 0.0f));
341 DALI_TEST_EQUALS(pathConstrainer.GetProperty<Vector3>(Dali::PathConstrainer::Property::FORWARD), Vector3(1.0f, 0.0f, 0.0f), TEST_LOCATION);
342 DALI_TEST_EQUALS(pathConstrainer.GetCurrentProperty<Vector3>(Dali::PathConstrainer::Property::FORWARD), Vector3(1.0f, 0.0f, 0.0f), TEST_LOCATION);
344 Dali::Property::Array points;
346 points[0] = Vector3(30.0, 80.0, 0.0);
347 points[1] = Vector3(70.0, 120.0, 0.0);
348 points[2] = Vector3(100.0, 100.0, 0.0);
349 pathConstrainer.SetProperty(Dali::PathConstrainer::Property::POINTS, points);
352 Property::Value value = pathConstrainer.GetProperty(Dali::PathConstrainer::Property::POINTS);
353 Property::Array* array = value.GetArray();
354 DALI_TEST_CHECK(array);
356 const unsigned int noOfPoints = points.Size();
357 for(unsigned int i = 0; i < noOfPoints; ++i)
359 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
364 Property::Value value = pathConstrainer.GetCurrentProperty(Dali::PathConstrainer::Property::POINTS);
365 Property::Array* array = value.GetArray();
366 DALI_TEST_CHECK(array);
368 const unsigned int noOfPoints = points.Size();
369 for(unsigned int i = 0; i < noOfPoints; ++i)
371 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
376 points[0] = Vector3(39.0, 90.0, 0.0);
377 points[1] = Vector3(56.0, 119.0, 0.0);
378 points[2] = Vector3(78.0, 120.0, 0.0);
379 points[3] = Vector3(93.0, 104.0, 0.0);
380 pathConstrainer.SetProperty(Dali::PathConstrainer::Property::CONTROL_POINTS, points);
383 Property::Value value = pathConstrainer.GetProperty(Dali::PathConstrainer::Property::CONTROL_POINTS);
384 Property::Array* array = value.GetArray();
385 DALI_TEST_CHECK(array);
387 const unsigned int noOfPoints = points.Size();
388 for(unsigned int i = 0; i < noOfPoints; ++i)
390 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
395 Property::Value value = pathConstrainer.GetCurrentProperty(Dali::PathConstrainer::Property::CONTROL_POINTS);
396 Property::Array* array = value.GetArray();
397 DALI_TEST_CHECK(array);
399 const unsigned int noOfPoints = points.Size();
400 for(unsigned int i = 0; i < noOfPoints; ++i)
402 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
409 //LinearConstrainer test cases
410 int UtcLinearConstrainerDownCast(void)
412 TestApplication application;
413 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
415 BaseHandle handle(linearConstrainer);
416 Dali::LinearConstrainer linearConstrainer2 = Dali::LinearConstrainer::DownCast(handle);
417 DALI_TEST_EQUALS((bool)linearConstrainer2, true, TEST_LOCATION);
420 Dali::LinearConstrainer linearConstrainer3 = Dali::LinearConstrainer::DownCast(handle2);
421 DALI_TEST_EQUALS((bool)linearConstrainer3, false, TEST_LOCATION);
426 int UtcLinearConstrainerCopyConstructor(void)
428 TestApplication application;
429 Dali::LinearConstrainer linearConstrainer;
430 DALI_TEST_EQUALS((bool)linearConstrainer, false, TEST_LOCATION);
432 linearConstrainer = Dali::LinearConstrainer::New();
433 DALI_TEST_EQUALS((bool)linearConstrainer, true, TEST_LOCATION);
435 // call the copy constructor
436 Dali::LinearConstrainer linearConstrainer2(linearConstrainer);
437 DALI_TEST_EQUALS((bool)linearConstrainer2, true, TEST_LOCATION);
442 int UtcLinearConstrainerMoveConstructor(void)
444 TestApplication application;
446 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
447 DALI_TEST_CHECK(linearConstrainer);
448 DALI_TEST_EQUALS(1, linearConstrainer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
450 SetupLinearConstrainerUniformProgress(linearConstrainer);
451 VerifyLinearConstrainerUniformProgress(linearConstrainer);
453 Dali::LinearConstrainer moved = std::move(linearConstrainer);
454 DALI_TEST_CHECK(moved);
455 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
456 VerifyLinearConstrainerUniformProgress(moved);
457 DALI_TEST_CHECK(!linearConstrainer);
462 int UtcLinearConstrainerMoveAssignment(void)
464 TestApplication application;
466 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
467 DALI_TEST_CHECK(linearConstrainer);
468 DALI_TEST_EQUALS(1, linearConstrainer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
470 SetupLinearConstrainerUniformProgress(linearConstrainer);
471 VerifyLinearConstrainerUniformProgress(linearConstrainer);
473 Dali::LinearConstrainer moved;
474 moved = std::move(linearConstrainer);
475 DALI_TEST_CHECK(moved);
476 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
477 VerifyLinearConstrainerUniformProgress(moved);
478 DALI_TEST_CHECK(!linearConstrainer);
483 int UtcLinearConstrainerApply(void)
485 TestApplication application;
487 Dali::Actor actor = Dali::Actor::New();
489 // Register a float property
490 Property::Index index = actor.RegisterProperty("t", 0.0f);
492 application.GetScene().Add(actor);
494 //Create a LinearConstrainer without specifying progress for values
495 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
496 SetupLinearConstrainerUniformProgress(linearConstrainer);
498 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
499 Vector2 range(0.0f, 1.0f);
500 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
502 //Create an animation to animate the custom property
503 float durationSeconds(1.0f);
504 Dali::Animation animation = Dali::Animation::New(durationSeconds);
505 animation.AnimateTo(Dali::Property(actor, index), 1.0f);
508 application.SendNotification();
509 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
511 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
513 application.SendNotification();
514 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
515 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
517 application.SendNotification();
518 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
519 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
521 application.SendNotification();
522 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
523 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
525 application.SendNotification();
526 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
527 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
529 //Setup a LinearConstrainer specifying the progress for each value
530 linearConstrainer.Remove(actor);
531 SetupLinearConstrainerNonUniformProgress(linearConstrainer);
532 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
534 actor.SetProperty(index, 0.0f);
536 application.SendNotification();
537 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
539 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
541 application.SendNotification();
542 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
543 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 2.0f / 3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
545 application.SendNotification();
546 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
547 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f / 3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION);
549 application.SendNotification();
550 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
551 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
553 application.SendNotification();
554 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
555 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
560 int UtcLinearConstrainerApplyRange(void)
562 TestApplication application;
564 Dali::Actor actor = Dali::Actor::New();
566 // Register a float property
567 Property::Index index = actor.RegisterProperty("t", 100.0f);
568 application.GetScene().Add(actor);
570 //Create a LinearConstrainer
571 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
572 SetupLinearConstrainerUniformProgress(linearConstrainer);
574 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
575 Vector2 range(100.0f, 300.0f);
576 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
578 //Create an animation to animate the custom property
579 float durationSeconds(1.0f);
580 Dali::Animation animation = Dali::Animation::New(durationSeconds);
581 animation.AnimateTo(Dali::Property(actor, index), 300.0f);
584 application.SendNotification();
585 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 25% progress */);
587 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
589 application.SendNotification();
590 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 50% progress */);
591 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
593 application.SendNotification();
594 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 75% progress */);
595 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.5f, TEST_LOCATION);
597 application.SendNotification();
598 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* 100% progress */);
599 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
601 application.SendNotification();
602 application.Render(static_cast<unsigned int>(durationSeconds * 250.0f) /* beyond the animation duration*/);
603 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
608 int UtcLinearConstrainerDestroy(void)
610 TestApplication application;
612 Dali::Actor actor = Dali::Actor::New();
614 // Register a float property
615 Property::Index index = actor.RegisterProperty("t", 0.0f);
616 application.GetScene().Add(actor);
619 //Create a LinearConstrainer
620 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
621 SetupLinearConstrainerUniformProgress(linearConstrainer);
623 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
624 Vector2 range(0.0f, 1.0f);
625 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
627 //Test that the constraint is correctly applied
628 actor.SetProperty(index, 0.5f);
629 application.SendNotification();
630 application.Render(static_cast<unsigned int>(1.0f));
632 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
635 //LinearConstrainer has been destroyed. Constraint in the actor should have been removed
636 actor.SetProperty(index, 0.75f);
637 application.SendNotification();
638 application.Render(static_cast<unsigned int>(1.0f));
640 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
645 int UtcLinearConstrainerRemove(void)
647 TestApplication application;
649 Dali::Actor actor = Dali::Actor::New();
651 // Register a float property
652 Property::Index index = actor.RegisterProperty("t", 0.0f);
653 application.GetScene().Add(actor);
655 //Create a LinearConstrainer
656 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
657 SetupLinearConstrainerUniformProgress(linearConstrainer);
659 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
660 Vector2 range(0.0f, 1.0f);
661 linearConstrainer.Apply(Property(actor, Dali::Actor::Property::POSITION_X), Property(actor, index), range);
663 //Test that the constraint is correctly applied
664 actor.SetProperty(index, 0.5f);
665 application.SendNotification();
666 application.Render(static_cast<unsigned int>(1.0f));
668 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 1.0f, TEST_LOCATION);
671 linearConstrainer.Remove(actor);
672 actor.SetProperty(index, 0.75f);
673 application.SendNotification();
674 application.Render(static_cast<unsigned int>(1.0f));
676 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Dali::Actor::Property::POSITION).x, 0.0f, TEST_LOCATION);
681 int UtcLinearConstrainerProperties(void)
683 TestApplication application;
685 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
687 Dali::Property::Array points;
692 linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::VALUE, points);
695 Property::Value value = linearConstrainer.GetProperty(Dali::LinearConstrainer::Property::VALUE);
696 Property::Array* array = value.GetArray();
697 DALI_TEST_CHECK(array);
699 const unsigned int noOfPoints = points.Size();
700 for(unsigned int i = 0; i < noOfPoints; ++i)
702 DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
707 Property::Value value = linearConstrainer.GetCurrentProperty(Dali::LinearConstrainer::Property::VALUE);
708 Property::Array* array = value.GetArray();
709 DALI_TEST_CHECK(array);
711 const unsigned int noOfPoints = points.Size();
712 for(unsigned int i = 0; i < noOfPoints; ++i)
714 DALI_TEST_EQUALS((*array)[i].Get<Vector3>(), points[i].Get<Vector3>(), TEST_LOCATION);
721 linearConstrainer.SetProperty(Dali::LinearConstrainer::Property::PROGRESS, points);
724 Property::Value value = linearConstrainer.GetProperty(Dali::LinearConstrainer::Property::PROGRESS);
725 Property::Array* array = value.GetArray();
726 DALI_TEST_CHECK(array);
728 const unsigned int noOfPoints = points.Size();
729 for(unsigned int i = 0; i < noOfPoints; ++i)
731 DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
736 Property::Value value = linearConstrainer.GetCurrentProperty(Dali::LinearConstrainer::Property::PROGRESS);
737 Property::Array* array = value.GetArray();
738 DALI_TEST_CHECK(array);
740 const unsigned int noOfPoints = points.Size();
741 for(unsigned int i = 0; i < noOfPoints; ++i)
743 DALI_TEST_EQUALS((*array)[i].Get<float>(), points[i].Get<float>(), TEST_LOCATION);
750 int UtcDaliLinearConstrainerDetectorRegisterProperty(void)
752 TestApplication application;
754 Dali::LinearConstrainer constrainer = Dali::LinearConstrainer::New();
756 Property::Index index = constrainer.RegisterProperty("sceneProperty", 0);
757 DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
758 DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), 0, TEST_LOCATION);
760 constrainer.SetProperty(index, -123);
761 DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), -123, TEST_LOCATION);
763 using Dali::Animation;
764 Animation animation = Animation::New(1.0f);
765 animation.AnimateTo(Property(constrainer, index), 99);
767 DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), -123, TEST_LOCATION);
768 // Start the animation
771 application.SendNotification();
772 application.Render(1000 /* 100% progress */);
773 DALI_TEST_EQUALS(constrainer.GetProperty<int32_t>(index), 99, TEST_LOCATION);
778 int UtcDaliPathConstrainerDetectorRegisterProperty(void)
780 TestApplication application;
782 Dali::PathConstrainer constrainer = Dali::PathConstrainer::New();
784 Property::Index index = constrainer.RegisterProperty("pathProperty", Vector2());
785 DALI_TEST_EQUALS(index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION);
786 DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(), TEST_LOCATION);
788 constrainer.SetProperty(index, Vector2(1, 2));
789 DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(1, 2), TEST_LOCATION);
791 using Dali::Animation;
792 Animation animation = Animation::New(1.0f);
793 animation.AnimateTo(Property(constrainer, index), Vector2(3, 4));
795 DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(1, 2), TEST_LOCATION);
796 // Start the animation
799 application.SendNotification();
800 application.Render(1000 /* 100% progress */);
801 DALI_TEST_EQUALS(constrainer.GetProperty<Vector2>(index), Vector2(3, 4), TEST_LOCATION);
806 int UtcDaliLinearConstrainerApplyNegative(void)
808 TestApplication application;
809 Dali::LinearConstrainer instance;
813 Dali::Property arg1(actor, Dali::Actor::Property::POSITION);
814 Dali::Property arg2(actor, Dali::Actor::Property::POSITION);
817 instance.Apply(arg1, arg2, arg3, arg4);
818 DALI_TEST_CHECK(false); // Should not get here
822 DALI_TEST_CHECK(true); // We expect an assert
827 int UtcDaliLinearConstrainerRemoveNegative(void)
829 TestApplication application;
830 Dali::LinearConstrainer instance;
834 instance.Remove(arg1);
835 DALI_TEST_CHECK(false); // Should not get here
839 DALI_TEST_CHECK(true); // We expect an assert