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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/animation/path-constrainer.h>
23 #include <dali-test-suite-utils.h>
26 using namespace Dali::Internal;
31 static void SetupPath( Dali::Path& path)
33 path.AddPoint(Vector3( 30.0, 80.0, 0.0));
34 path.AddPoint(Vector3( 70.0, 120.0, 0.0));
35 path.AddPoint(Vector3(100.0, 100.0, 0.0));
37 //Control points for first segment
38 path.AddControlPoint( Vector3( 39.0, 90.0, 0.0) );
39 path.AddControlPoint(Vector3( 56.0, 119.0, 0.0) );
41 //Control points for second segment
42 path.AddControlPoint(Vector3( 78.0, 120.0, 0.0) );
43 path.AddControlPoint(Vector3( 93.0, 104.0, 0.0) );
46 static void SetupPathConstrainer( Dali::PathConstrainer& PathConstrainer)
48 PathConstrainer.SetProperty( Dali::PathConstrainer::Property::FORWARD, Vector3(1.0f,0.0f,0.0f) );
50 Dali::Property::Array points;
52 points[0] = Vector3( 30.0, 80.0, 0.0);
53 points[1] = Vector3( 70.0, 120.0, 0.0);
54 points[2] = Vector3(100.0, 100.0, 0.0);
55 PathConstrainer.SetProperty( Dali::PathConstrainer::Property::POINTS, points );
58 points[0] = Vector3( 39.0, 90.0, 0.0);
59 points[1] = Vector3( 56.0, 119.0, 0.0);
60 points[2] = Vector3( 78.0, 120.0, 0.0);
61 points[3] = Vector3( 93.0, 104.0, 0.0);
62 PathConstrainer.SetProperty( Dali::PathConstrainer::Property::CONTROL_POINTS, points );
65 static void SetupLinearConstrainerUniformProgress( Dali::LinearConstrainer& linearConstrainer)
67 Dali::Property::Array points;
72 linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::VALUE, points );
75 static void VerifyLinearConstrainerUniformProgress( Dali::LinearConstrainer& linearConstrainer )
77 Dali::Property::Array points;
83 Property::Value value = linearConstrainer.GetProperty( Dali::LinearConstrainer::Property::VALUE );
84 Property::Array* array = value.GetArray();
85 DALI_TEST_CHECK( array );
87 const unsigned int noOfPoints = points.Size();
88 for( unsigned int i = 0; i < noOfPoints; ++i )
90 DALI_TEST_EQUALS( ( *array )[i].Get< float >(), points[i].Get< float >(), TEST_LOCATION );
94 static void SetupLinearConstrainerNonUniformProgress( Dali::LinearConstrainer& linearConstrainer)
96 Dali::Property::Array points;
101 linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::VALUE, points );
106 linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::PROGRESS, points );
109 } // anonymous namespace
111 //PathConstrainer test cases
112 int UtcPathConstrainerApply(void)
114 TestApplication application;
116 Dali::Actor actor = Dali::Actor::New();
118 // Register a float property
119 Property::Index index = actor.RegisterProperty( "t", 0.0f );
121 application.GetScene().Add(actor);
124 Dali::Path path = Dali::Path::New();
127 //Create a PathConstrainer
128 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
129 SetupPathConstrainer( pathConstrainer );
131 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
132 Vector2 range( 0.0f, 1.0f );
133 pathConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION), Property(actor,index), range );
135 //Create an animation to animate the custom property
136 float durationSeconds(1.0f);
137 Dali::Animation animation = Dali::Animation::New(durationSeconds);
138 animation.AnimateTo(Dali::Property(actor,index),1.0f);
141 application.SendNotification();
142 application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 20% progress */);
144 Vector3 position, tangent;
145 path.Sample(0.2f, position, tangent );
146 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
148 application.SendNotification();
149 application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 40% progress */);
150 path.Sample(0.4f, position, tangent );
151 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
153 application.SendNotification();
154 application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 60% progress */);
155 path.Sample(0.6f, position, tangent );
156 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
158 application.SendNotification();
159 application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 80% progress */);
160 path.Sample(0.8f, position, tangent );
161 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
163 application.SendNotification();
164 application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 100% progress */);
165 path.Sample(1.0f, position, tangent );
166 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
168 application.SendNotification();
169 application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* beyond the animation duration*/);
170 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
175 int UtcPathConstrainerApplyRange(void)
177 TestApplication application;
179 Dali::Actor actor = Dali::Actor::New();
181 // Register a float property
182 Property::Index index = actor.RegisterProperty( "t", 0.0f );
183 application.GetScene().Add(actor);
186 Dali::Path path = Dali::Path::New();
189 //Create a PathConstrainer
190 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
191 SetupPathConstrainer( pathConstrainer );
193 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
194 Vector2 range( 100.0f, 300.0f );
195 pathConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION), Property(actor,index), range );
198 //Create an animation to animate the custom property
199 float durationSeconds(1.0f);
200 Dali::Animation animation = Dali::Animation::New(durationSeconds);
201 animation.AnimateTo(Dali::Property(actor,index),400.0f);
204 application.SendNotification();
205 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
208 Vector3 position, tangent;
210 actor.GetCurrentProperty( index ).Get(tValue);
211 float currentCursor = ( tValue - range.x ) / (range.y-range.x);
212 path.Sample(currentCursor, position, tangent );
213 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
215 application.SendNotification();
216 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
217 actor.GetCurrentProperty( index ).Get(tValue);
218 currentCursor = ( tValue - range.x ) / (range.y-range.x);
219 path.Sample(currentCursor, position, tangent );
220 path.Sample(0.5, position, tangent );
221 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
223 application.SendNotification();
224 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
225 actor.GetCurrentProperty( index ).Get( tValue );
226 currentCursor = ( tValue - range.x ) / (range.y-range.x);
227 path.Sample(currentCursor, position, tangent );
228 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
230 application.SendNotification();
231 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
232 actor.GetCurrentProperty( index ).Get( tValue );
233 currentCursor = ( tValue - range.x ) / (range.y-range.x);
234 path.Sample(currentCursor, position, tangent );
235 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
237 application.SendNotification();
238 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* beyond the animation duration*/);
239 actor.GetCurrentProperty( index ).Get( tValue );
240 currentCursor = ( tValue - range.x ) / (range.y-range.x);
241 path.Sample(currentCursor, position, tangent );
242 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
244 // Ensure GetProperty also returns the final result
245 actor.GetProperty( index ).Get( tValue );
246 currentCursor = ( tValue - range.x ) / (range.y-range.x);
247 path.Sample(currentCursor, position, tangent );
248 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
253 int UtcPathConstrainerDestroy(void)
255 TestApplication application;
257 Dali::Actor actor = Dali::Actor::New();
259 // Register a float property
260 Property::Index index = actor.RegisterProperty( "t", 0.0f );
261 application.GetScene().Add(actor);
265 Dali::Path path = Dali::Path::New();
268 //Create a PathConstrainer
269 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
270 SetupPathConstrainer( pathConstrainer );
272 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
273 Vector2 range( 0.0f, 1.0f );
274 pathConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION), Property(actor,index), range );
276 //Test that the constraint is correctly applied
277 actor.SetProperty(index,0.5f);
278 application.SendNotification();
279 application.Render(static_cast<unsigned int>(1.0f));
281 Vector3 position, tangent;
282 path.Sample(0.5f, position, tangent );
283 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
287 //PathConstrainer has been destroyed. Constraint in the actor should have been removed
288 actor.SetProperty(index,0.75f);
289 application.SendNotification();
290 application.Render(static_cast<unsigned int>(1.0f));
292 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), Vector3::ZERO, TEST_LOCATION );
297 int UtcPathConstrainerRemove(void)
299 TestApplication application;
301 Dali::Actor actor = Dali::Actor::New();
303 // Register a float property
304 Property::Index index = actor.RegisterProperty( "t", 0.0f );
305 application.GetScene().Add(actor);
308 Dali::Path path = Dali::Path::New();
311 //Create a PathConstrainer
312 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
313 SetupPathConstrainer( pathConstrainer );
315 //Apply the path constraint to the actor's position. The source property for the constraint will be the custom property "t"
316 Vector2 range( 0.0f, 1.0f );
317 pathConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION), Property(actor,index), range );
319 //Test that the constraint is correctly applied
320 actor.SetProperty(index,0.5f);
321 application.SendNotification();
322 application.Render(static_cast<unsigned int>(1.0f));
324 Vector3 position, tangent;
325 path.Sample(0.5f, position, tangent );
326 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), position, TEST_LOCATION );
329 pathConstrainer.Remove( actor );
330 actor.SetProperty(index,0.75f);
331 application.SendNotification();
332 application.Render(static_cast<unsigned int>(1.0f));
334 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ), Vector3::ZERO, TEST_LOCATION );
339 int UtcPathConstrainerProperties(void)
341 TestApplication application;
342 Dali::PathConstrainer pathConstrainer = Dali::PathConstrainer::New();
344 pathConstrainer.SetProperty( Dali::PathConstrainer::Property::FORWARD, Vector3( 1.0f,0.0f,0.0f ) );
345 DALI_TEST_EQUALS( pathConstrainer.GetProperty< Vector3 >( Dali::PathConstrainer::Property::FORWARD ), Vector3( 1.0f, 0.0f, 0.0f ), TEST_LOCATION );
346 DALI_TEST_EQUALS( pathConstrainer.GetCurrentProperty< Vector3 >( Dali::PathConstrainer::Property::FORWARD ), Vector3( 1.0f, 0.0f, 0.0f ), TEST_LOCATION );
348 Dali::Property::Array points;
350 points[0] = Vector3( 30.0, 80.0, 0.0);
351 points[1] = Vector3( 70.0, 120.0, 0.0);
352 points[2] = Vector3(100.0, 100.0, 0.0);
353 pathConstrainer.SetProperty( Dali::PathConstrainer::Property::POINTS, points );
356 Property::Value value = pathConstrainer.GetProperty( Dali::PathConstrainer::Property::POINTS );
357 Property::Array* array = value.GetArray();
358 DALI_TEST_CHECK( array );
360 const unsigned int noOfPoints = points.Size();
361 for( unsigned int i = 0; i < noOfPoints; ++i )
363 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
368 Property::Value value = pathConstrainer.GetCurrentProperty( Dali::PathConstrainer::Property::POINTS );
369 Property::Array* array = value.GetArray();
370 DALI_TEST_CHECK( array );
372 const unsigned int noOfPoints = points.Size();
373 for( unsigned int i = 0; i < noOfPoints; ++i )
375 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
380 points[0] = Vector3( 39.0, 90.0, 0.0);
381 points[1] = Vector3( 56.0, 119.0, 0.0);
382 points[2] = Vector3( 78.0, 120.0, 0.0);
383 points[3] = Vector3( 93.0, 104.0, 0.0);
384 pathConstrainer.SetProperty( Dali::PathConstrainer::Property::CONTROL_POINTS, points );
387 Property::Value value = pathConstrainer.GetProperty( Dali::PathConstrainer::Property::CONTROL_POINTS );
388 Property::Array* array = value.GetArray();
389 DALI_TEST_CHECK( array );
391 const unsigned int noOfPoints = points.Size();
392 for( unsigned int i = 0; i < noOfPoints; ++i )
394 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
399 Property::Value value = pathConstrainer.GetCurrentProperty( Dali::PathConstrainer::Property::CONTROL_POINTS );
400 Property::Array* array = value.GetArray();
401 DALI_TEST_CHECK( array );
403 const unsigned int noOfPoints = points.Size();
404 for( unsigned int i = 0; i < noOfPoints; ++i )
406 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
413 //LinearConstrainer test cases
414 int UtcLinearConstrainerDownCast(void)
416 TestApplication application;
417 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
419 BaseHandle handle( linearConstrainer );
420 Dali::LinearConstrainer linearConstrainer2 = Dali::LinearConstrainer::DownCast( handle );
421 DALI_TEST_EQUALS( (bool)linearConstrainer2, true, TEST_LOCATION );
424 Dali:: LinearConstrainer linearConstrainer3 = Dali::LinearConstrainer::DownCast( handle2 );
425 DALI_TEST_EQUALS( (bool)linearConstrainer3, false, TEST_LOCATION );
430 int UtcLinearConstrainerCopyConstructor(void)
432 TestApplication application;
433 Dali::LinearConstrainer linearConstrainer;
434 DALI_TEST_EQUALS( (bool)linearConstrainer, false, TEST_LOCATION );
436 linearConstrainer = Dali::LinearConstrainer::New();
437 DALI_TEST_EQUALS( (bool)linearConstrainer, true, TEST_LOCATION );
439 // call the copy constructor
440 Dali::LinearConstrainer linearConstrainer2( linearConstrainer );
441 DALI_TEST_EQUALS( (bool)linearConstrainer2, true, TEST_LOCATION );
446 int UtcLinearConstrainerMoveConstructor(void)
448 TestApplication application;
450 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
451 DALI_TEST_CHECK( linearConstrainer );
452 DALI_TEST_EQUALS( 1, linearConstrainer.GetBaseObject().ReferenceCount(), TEST_LOCATION );
454 SetupLinearConstrainerUniformProgress( linearConstrainer );
455 VerifyLinearConstrainerUniformProgress( linearConstrainer );
457 Dali::LinearConstrainer moved = std::move( linearConstrainer );
458 DALI_TEST_CHECK( moved );
459 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
460 VerifyLinearConstrainerUniformProgress( moved );
461 DALI_TEST_CHECK( !linearConstrainer );
466 int UtcLinearConstrainerMoveAssignment(void)
468 TestApplication application;
470 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
471 DALI_TEST_CHECK( linearConstrainer );
472 DALI_TEST_EQUALS( 1, linearConstrainer.GetBaseObject().ReferenceCount(), TEST_LOCATION );
474 SetupLinearConstrainerUniformProgress( linearConstrainer );
475 VerifyLinearConstrainerUniformProgress( linearConstrainer );
477 Dali::LinearConstrainer moved;
478 moved = std::move( linearConstrainer );
479 DALI_TEST_CHECK( moved );
480 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
481 VerifyLinearConstrainerUniformProgress( moved );
482 DALI_TEST_CHECK( !linearConstrainer );
487 int UtcLinearConstrainerApply(void)
489 TestApplication application;
491 Dali::Actor actor = Dali::Actor::New();
493 // Register a float property
494 Property::Index index = actor.RegisterProperty( "t", 0.0f );
496 application.GetScene().Add(actor);
499 //Create a LinearConstrainer without specifying progress for values
500 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
501 SetupLinearConstrainerUniformProgress( linearConstrainer );
503 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
504 Vector2 range( 0.0f, 1.0f );
505 linearConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION_X), Property(actor,index), range );
507 //Create an animation to animate the custom property
508 float durationSeconds(1.0f);
509 Dali::Animation animation = Dali::Animation::New(durationSeconds);
510 animation.AnimateTo(Dali::Property(actor,index),1.0f);
513 application.SendNotification();
514 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
516 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.5f, TEST_LOCATION );
518 application.SendNotification();
519 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
520 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 1.0f, TEST_LOCATION );
522 application.SendNotification();
523 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
524 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.5f, TEST_LOCATION );
526 application.SendNotification();
527 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
528 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.0f, TEST_LOCATION );
530 application.SendNotification();
531 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* beyond the animation duration*/);
532 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.0f, TEST_LOCATION );
534 //Setup a LinearConstrainer specifying the progress for each value
535 linearConstrainer.Remove(actor);
536 SetupLinearConstrainerNonUniformProgress( linearConstrainer );
537 linearConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION_X), Property(actor,index), range );
539 actor.SetProperty(index,0.0f);
541 application.SendNotification();
542 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
544 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 1.0f, TEST_LOCATION );
546 application.SendNotification();
547 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
548 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 2.0f/3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION );
550 application.SendNotification();
551 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
552 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 1.0f/3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION );
554 application.SendNotification();
555 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
556 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.0f, TEST_LOCATION );
558 application.SendNotification();
559 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* beyond the animation duration*/);
560 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.0f, TEST_LOCATION );
565 int UtcLinearConstrainerApplyRange(void)
567 TestApplication application;
569 Dali::Actor actor = Dali::Actor::New();
571 // Register a float property
572 Property::Index index = actor.RegisterProperty( "t", 100.0f );
573 application.GetScene().Add(actor);
575 //Create a LinearConstrainer
576 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
577 SetupLinearConstrainerUniformProgress( linearConstrainer );
579 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
580 Vector2 range( 100.0f, 300.0f );
581 linearConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION_X), Property(actor,index), range );
584 //Create an animation to animate the custom property
585 float durationSeconds(1.0f);
586 Dali::Animation animation = Dali::Animation::New(durationSeconds);
587 animation.AnimateTo(Dali::Property(actor,index),300.0f);
590 application.SendNotification();
591 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
593 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.5f, TEST_LOCATION );
595 application.SendNotification();
596 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
597 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 1.0f, TEST_LOCATION );
599 application.SendNotification();
600 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
601 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.5f, TEST_LOCATION );
603 application.SendNotification();
604 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
605 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.0f, TEST_LOCATION );
607 application.SendNotification();
608 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* beyond the animation duration*/);
609 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.0f, TEST_LOCATION );
614 int UtcLinearConstrainerDestroy(void)
616 TestApplication application;
618 Dali::Actor actor = Dali::Actor::New();
620 // Register a float property
621 Property::Index index = actor.RegisterProperty( "t", 0.0f );
622 application.GetScene().Add(actor);
625 //Create a LinearConstrainer
626 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
627 SetupLinearConstrainerUniformProgress( linearConstrainer );
629 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
630 Vector2 range( 0.0f, 1.0f );
631 linearConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION_X), Property(actor,index), range );
633 //Test that the constraint is correctly applied
634 actor.SetProperty(index,0.5f);
635 application.SendNotification();
636 application.Render(static_cast<unsigned int>(1.0f));
638 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 1.0f, TEST_LOCATION );
642 //LinearConstrainer has been destroyed. Constraint in the actor should have been removed
643 actor.SetProperty(index,0.75f);
644 application.SendNotification();
645 application.Render(static_cast<unsigned int>(1.0f));
647 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Dali::Actor::Property::POSITION ).x, 0.0f, TEST_LOCATION );
652 int UtcLinearConstrainerRemove(void)
654 TestApplication application;
656 Dali::Actor actor = Dali::Actor::New();
658 // Register a float property
659 Property::Index index = actor.RegisterProperty( "t", 0.0f );
660 application.GetScene().Add(actor);
662 //Create a LinearConstrainer
663 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
664 SetupLinearConstrainerUniformProgress( linearConstrainer );
666 //Apply the path 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.Remove( actor );
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 UtcLinearConstrainerProperties(void)
690 TestApplication application;
692 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
694 Dali::Property::Array points;
699 linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::VALUE, points );
702 Property::Value value = linearConstrainer.GetProperty( Dali::LinearConstrainer::Property::VALUE );
703 Property::Array* array = value.GetArray();
704 DALI_TEST_CHECK( array );
706 const unsigned int noOfPoints = points.Size();
707 for( unsigned int i = 0; i < noOfPoints; ++i )
709 DALI_TEST_EQUALS( ( *array )[i].Get< float >(), points[i].Get< float >(), TEST_LOCATION );
714 Property::Value value = linearConstrainer.GetCurrentProperty( Dali::LinearConstrainer::Property::VALUE );
715 Property::Array* array = value.GetArray();
716 DALI_TEST_CHECK( array );
718 const unsigned int noOfPoints = points.Size();
719 for( unsigned int i = 0; i < noOfPoints; ++i )
721 DALI_TEST_EQUALS( ( *array )[i].Get< Vector3 >(), points[i].Get< Vector3 >(), TEST_LOCATION );
728 linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::PROGRESS, points );
731 Property::Value value = linearConstrainer.GetProperty( Dali::LinearConstrainer::Property::PROGRESS );
732 Property::Array* array = value.GetArray();
733 DALI_TEST_CHECK( array );
735 const unsigned int noOfPoints = points.Size();
736 for( unsigned int i = 0; i < noOfPoints; ++i )
738 DALI_TEST_EQUALS( ( *array )[i].Get< float >(), points[i].Get< float >(), TEST_LOCATION );
743 Property::Value value = linearConstrainer.GetCurrentProperty( Dali::LinearConstrainer::Property::PROGRESS );
744 Property::Array* array = value.GetArray();
745 DALI_TEST_CHECK( array );
747 const unsigned int noOfPoints = points.Size();
748 for( unsigned int i = 0; i < noOfPoints; ++i )
750 DALI_TEST_EQUALS( ( *array )[i].Get< float >(), points[i].Get< float >(), TEST_LOCATION );
757 int UtcDaliLinearConstrainerDetectorRegisterProperty(void)
759 TestApplication application;
761 Dali::LinearConstrainer constrainer = Dali::LinearConstrainer::New();
763 Property::Index index = constrainer.RegisterProperty( "sceneProperty", 0 );
764 DALI_TEST_EQUALS( index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION );
765 DALI_TEST_EQUALS( constrainer.GetProperty< int32_t >( index ), 0, TEST_LOCATION );
767 constrainer.SetProperty( index, -123 );
768 DALI_TEST_EQUALS( constrainer.GetProperty< int32_t >( index ), -123, TEST_LOCATION );
770 using Dali::Animation;
771 Animation animation = Animation::New( 1.0f );
772 animation.AnimateTo( Property( constrainer, index ), 99 );
774 DALI_TEST_EQUALS( constrainer.GetProperty< int32_t >( index ), -123, TEST_LOCATION );
775 // Start the animation
778 application.SendNotification();
779 application.Render( 1000 /* 100% progress */);
780 DALI_TEST_EQUALS( constrainer.GetProperty< int32_t >( index ), 99, TEST_LOCATION );
785 int UtcDaliPathConstrainerDetectorRegisterProperty(void)
787 TestApplication application;
789 Dali::PathConstrainer constrainer = Dali::PathConstrainer::New();
791 Property::Index index = constrainer.RegisterProperty( "pathProperty", Vector2() );
792 DALI_TEST_EQUALS( index, (Property::Index)PROPERTY_CUSTOM_START_INDEX, TEST_LOCATION );
793 DALI_TEST_EQUALS( constrainer.GetProperty< Vector2 >( index ), Vector2(), TEST_LOCATION );
795 constrainer.SetProperty( index, Vector2(1,2) );
796 DALI_TEST_EQUALS( constrainer.GetProperty< Vector2 >( index ), Vector2(1,2), TEST_LOCATION );
798 using Dali::Animation;
799 Animation animation = Animation::New( 1.0f );
800 animation.AnimateTo( Property( constrainer, index ), Vector2(3,4) );
802 DALI_TEST_EQUALS( constrainer.GetProperty< Vector2 >( index ), Vector2(1,2), TEST_LOCATION );
803 // Start the animation
806 application.SendNotification();
807 application.Render( 1000 /* 100% progress */);
808 DALI_TEST_EQUALS( constrainer.GetProperty< Vector2 >( index ), Vector2(3,4), TEST_LOCATION );