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-test-suite-utils.h>
26 ///////////////////////////////////////////////////////////////////////////////
27 void utc_dali_constraint_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_constraint_cleanup(void)
34 test_return_value = TET_PASS;
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
43 * A function to use for a constraint, no data collected.
45 template< typename T >
46 void BasicFunction( T& /* current */, const PropertyInputContainer& /* inputs */ )
51 * A functor which sets a given boolean when the functor is called.
53 template< typename T >
54 struct BasicCalledFunctor
56 BasicCalledFunctor( bool& functorCalled ) : mCalled( functorCalled ) { }
58 void operator()( T& /* current */, const PropertyInputContainer& /* inputs */ )
67 * A functor which increments a given integer when the functor is called.
69 template< typename T >
70 struct CalledCountFunctor
72 CalledCountFunctor( int& callCount ) : mCallCount( callCount ) { }
74 void operator()( T& /* current */, const PropertyInputContainer& /* inputs */ )
83 * A functor which sets the given value as the value required when the functor is called.
85 template< typename T >
86 struct SetValueFunctor
88 SetValueFunctor( const T& value ) : mValue( value ) { }
90 void operator()( T& current, const PropertyInputContainer& /* inputs */ )
98 } // unnamed namespace
99 ///////////////////////////////////////////////////////////////////////////////
101 ///////////////////////////////////////////////////////////////////////////////
105 // void( *function )( T&, const PropertyInputContainer& ) )
106 ///////////////////////////////////////////////////////////////////////////////
107 namespace UtcDaliConstraintNewFunction
109 bool gConstraintFunctionCalled = false;
110 void ConstraintFunction( Vector3& /* current */, const PropertyInputContainer& /* inputs */ )
112 gConstraintFunctionCalled = true;
114 } // namespace UtcDaliConstraintNewFunction
116 int UtcDaliConstraintNewFunctionP(void)
118 // Ensure that we can create a constraint using a C function and that it is called.
120 TestApplication application;
121 UtcDaliConstraintNewFunction::gConstraintFunctionCalled = false;
123 Actor actor = Actor::New();
124 application.GetScene().Add( actor );
126 application.SendNotification();
127 application.Render();
129 DALI_TEST_EQUALS( UtcDaliConstraintNewFunction::gConstraintFunctionCalled, false, TEST_LOCATION );
132 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintNewFunction::ConstraintFunction );
133 DALI_TEST_CHECK( constraint );
136 application.SendNotification();
137 application.Render();
139 DALI_TEST_EQUALS( UtcDaliConstraintNewFunction::gConstraintFunctionCalled, true, TEST_LOCATION );
144 int UtcDaliConstraintNewFunctionN(void)
146 // Create a constraint with an uninitialised handle
148 TestApplication application;
150 // Add a constraint with an uninitialised handle
153 Constraint constraint = Constraint::New< Vector3 >( Actor(), Actor::Property::POSITION, &UtcDaliConstraintNewFunction::ConstraintFunction );
154 DALI_TEST_CHECK( false ); // Should not reach here
158 DALI_TEST_CHECK( true ); // Should assert!
164 // helper for next test
165 void StringConstraintFunction( std::string& /* current */, const PropertyInputContainer& /* inputs */ )
169 int UtcDaliConstraintNewFunctionNonConstrainableTypeN(void)
171 // Ensure that we can create a constraint using a C function and that it is called.
173 TestApplication application;
174 UtcDaliConstraintNewFunction::gConstraintFunctionCalled = false;
176 Actor actor = Actor::New();
177 application.GetScene().Add( actor );
179 application.SendNotification();
180 application.Render();
185 Constraint constraint = Constraint::New< std::string >( actor, Actor::Property::COLOR_MODE, &StringConstraintFunction );
186 DALI_TEST_CHECK( constraint );
188 tet_result(TET_FAIL);
190 catch ( Dali::DaliException& e )
192 DALI_TEST_ASSERT( e, "Property not constrainable", TEST_LOCATION );
198 ///////////////////////////////////////////////////////////////////////////////
200 ///////////////////////////////////////////////////////////////////////////////
205 ///////////////////////////////////////////////////////////////////////////////
206 int UtcDaliConstraintNewFunctorP(void)
208 // Ensure that we can create a constraint using a functor and that it is called.
210 TestApplication application;
211 bool functorCalled = false;
213 Actor actor = Actor::New();
214 application.GetScene().Add( actor );
216 application.SendNotification();
217 application.Render();
219 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
222 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
223 DALI_TEST_CHECK( constraint );
226 application.SendNotification();
227 application.Render();
229 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
234 int UtcDaliConstraintNewFunctorN(void)
236 // Create a constraint with an uninitialised handle
238 TestApplication application;
239 bool functorCalled = false;
241 // Add a constraint with an uninitialised handle
244 Constraint constraint = Constraint::New< Vector3 >( Actor(), Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
245 DALI_TEST_CHECK( false ); // Should not reach here
249 DALI_TEST_CHECK( true ); // Should assert!
254 ///////////////////////////////////////////////////////////////////////////////
256 ///////////////////////////////////////////////////////////////////////////////
261 // void ( T::*memberFunction ) ( P&, const PropertyInputContainer& ) )
262 ///////////////////////////////////////////////////////////////////////////////
263 namespace UtcDaliConstraintNewFunctorMember
267 Functor( bool& positionCalled, bool& scaleCalled )
268 : mPositionCalled( positionCalled ),
269 mScaleCalled( scaleCalled )
273 void Position( Vector3& /* current */, const PropertyInputContainer& /* inputs */ )
275 mPositionCalled = true;
278 void Scale( Vector3& /* current */, const PropertyInputContainer& /* inputs */ )
283 bool& mPositionCalled;
286 } // namespace UtcDaliConstraintNewFunctorMember
288 int UtcDaliConstraintNewFunctorMemberP(void)
290 // Ensure that we can create a constraint using a functor and that it is called.
292 TestApplication application;
293 bool positionFunctorCalled = false;
294 bool sizeFunctorCalled = false;
296 Actor actor = Actor::New();
297 application.GetScene().Add( actor );
299 application.SendNotification();
300 application.Render();
302 DALI_TEST_EQUALS( positionFunctorCalled, false, TEST_LOCATION );
303 DALI_TEST_EQUALS( sizeFunctorCalled, false, TEST_LOCATION );
305 // Add a constraint that calls Functor::Position
306 Constraint constraint = Constraint::New< Vector3 >(
308 Actor::Property::POSITION,
309 UtcDaliConstraintNewFunctorMember::Functor( positionFunctorCalled, sizeFunctorCalled ),
310 &UtcDaliConstraintNewFunctorMember::Functor::Position );
311 DALI_TEST_CHECK( constraint );
314 application.SendNotification();
315 application.Render();
317 DALI_TEST_EQUALS( positionFunctorCalled, true, TEST_LOCATION );
318 DALI_TEST_EQUALS( sizeFunctorCalled, false, TEST_LOCATION );
320 // Add another constraint that calls Functor::Size
321 Constraint constraint2 = Constraint::New< Vector3 >(
323 Actor::Property::SCALE,
324 UtcDaliConstraintNewFunctorMember::Functor( positionFunctorCalled, sizeFunctorCalled ),
325 &UtcDaliConstraintNewFunctorMember::Functor::Scale );
326 DALI_TEST_CHECK( constraint2 );
329 application.SendNotification();
330 application.Render();
332 DALI_TEST_EQUALS( positionFunctorCalled, true, TEST_LOCATION );
333 DALI_TEST_EQUALS( sizeFunctorCalled, true, TEST_LOCATION );
338 int UtcDaliConstraintNewFunctorMemberN(void)
340 // Create a constraint with an uninitialised handle
342 TestApplication application;
343 bool positionFunctorCalled = false;
344 bool sizeFunctorCalled = false;
346 // Add a constraint with an uninitialised handle
349 Constraint constraint = Constraint::New< Vector3 >(
351 Actor::Property::POSITION,
352 UtcDaliConstraintNewFunctorMember::Functor( positionFunctorCalled, sizeFunctorCalled ),
353 &UtcDaliConstraintNewFunctorMember::Functor::Position );
354 DALI_TEST_CHECK( false ); // Should not reach here
356 catch ( Dali::DaliException& e )
358 DALI_TEST_CHECK( true ); // Should assert!
363 ///////////////////////////////////////////////////////////////////////////////
365 ///////////////////////////////////////////////////////////////////////////////
367 ///////////////////////////////////////////////////////////////////////////////
368 int UtcDaliConstraintCloneP(void)
370 // Ensure we can clone for another actor and it's called appropriately
372 TestApplication application;
375 Actor actor = Actor::New();
376 Actor clone = Actor::New();
378 Integration::Scene stage = application.GetScene();
382 application.SendNotification();
383 application.Render();
385 DALI_TEST_EQUALS( calledCount, 0, TEST_LOCATION );
387 // Add a constraint to actor
388 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, CalledCountFunctor< Vector3 >( calledCount ) );
389 DALI_TEST_CHECK( constraint );
392 // Create a clone but don't apply
393 Constraint constraintClone = constraint.Clone( clone );
395 application.SendNotification();
396 application.Render();
398 DALI_TEST_EQUALS( calledCount, 1, TEST_LOCATION );
403 application.SendNotification();
404 application.Render();
406 DALI_TEST_EQUALS( calledCount, 1, TEST_LOCATION );
408 // Apply the clone constraint
409 constraintClone.Apply();
411 application.SendNotification();
412 application.Render();
414 // Should be called once for the new constraint clone and once for the original constraint
415 DALI_TEST_EQUALS( calledCount, 3, TEST_LOCATION );
420 // Change the position of both actors
421 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
422 clone.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
424 application.SendNotification();
425 application.Render();
427 // Functor should have been called twice
428 DALI_TEST_EQUALS( calledCount, 2, TEST_LOCATION );
433 int UtcDaliConstraintCloneN(void)
435 // Attempt to clone an uninitialised constraint should cause an assert
437 TestApplication application;
439 Constraint constraint;
443 Actor actor = Actor::New();
444 Constraint clone = constraint.Clone( actor );
445 DALI_TEST_CHECK( false );
449 DALI_TEST_CHECK( true );
455 namespace UtcDaliConstraintClone
457 void Function( Vector3& /* current */, const PropertyInputContainer& inputs )
459 DALI_TEST_EQUALS( inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION );
460 DALI_TEST_EQUALS( inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION );
461 DALI_TEST_EQUALS( inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION );
462 DALI_TEST_EQUALS( inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION );
464 } // namespace UtcDaliConstraintClone
466 int UtcDaliConstraintCloneCheckSourcesAndSetters(void)
468 // Ensure all sources, the tag and remove-action are cloned appropriately
470 TestApplication application;
472 Actor actor = Actor::New();
473 Actor clone = Actor::New();
475 Integration::Scene stage = application.GetScene();
479 application.SendNotification();
480 application.Render();
482 // Create a constraint, DON'T Apply it though
483 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintClone::Function );
484 constraint.AddSource( LocalSource( Actor::Property::SIZE ) );
485 constraint.AddSource( LocalSource( Actor::Property::ORIENTATION ) );
486 constraint.AddSource( LocalSource( Actor::Property::COLOR ) );
487 constraint.AddSource( LocalSource( Actor::Property::VISIBLE ) );
488 constraint.SetRemoveAction( Constraint::Discard );
489 constraint.SetTag( 123 );
491 // Clone the constraint & apply the clone
492 Constraint constraintClone = constraint.Clone( clone );
493 constraintClone.Apply();
495 application.SendNotification();
496 application.Render();
498 DALI_TEST_EQUALS( constraint.GetRemoveAction(), constraintClone.GetRemoveAction(), TEST_LOCATION );
499 DALI_TEST_EQUALS( constraint.GetTag(), constraintClone.GetTag(), TEST_LOCATION );
503 ///////////////////////////////////////////////////////////////////////////////
505 ///////////////////////////////////////////////////////////////////////////////
506 // Constraint::Constraint( const Constraint& )
507 // Constraint::operator=
508 ///////////////////////////////////////////////////////////////////////////////
509 int UtcDaliConstraintCopyAndAssignment(void)
511 // Ensure copy constructor & assignment operators work
513 TestApplication application;
515 Actor actor = Actor::New();
516 application.GetScene().Add( actor );
518 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
519 Constraint copied( constraint );
521 DALI_TEST_CHECK( constraint == copied );
522 DALI_TEST_CHECK( copied != assigned );
524 assigned = constraint;
525 DALI_TEST_CHECK( constraint == assigned );
529 ///////////////////////////////////////////////////////////////////////////////
531 int UtcDaliConstraintMoveConstructor(void)
533 // Ensure copy constructor & assignment operators work
535 TestApplication application;
537 Actor actor = Actor::New();
538 application.GetScene().Add( actor );
540 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
541 DALI_TEST_CHECK( constraint );
542 DALI_TEST_EQUALS( 1, constraint.GetBaseObject().ReferenceCount(), TEST_LOCATION );
543 DALI_TEST_CHECK( constraint.GetTargetObject() == actor );
545 Constraint moved = std::move( constraint );
546 DALI_TEST_CHECK( moved );
547 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
548 DALI_TEST_CHECK( moved.GetTargetObject() == actor );
549 DALI_TEST_CHECK( !constraint );
554 int UtcDaliConstraintMoveAssignment(void)
556 // Ensure copy constructor & assignment operators work
558 TestApplication application;
560 Actor actor = Actor::New();
561 application.GetScene().Add( actor );
563 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
564 DALI_TEST_CHECK( constraint );
565 DALI_TEST_EQUALS( 1, constraint.GetBaseObject().ReferenceCount(), TEST_LOCATION );
566 DALI_TEST_CHECK( constraint.GetTargetObject() == actor );
569 moved = std::move( constraint );
570 DALI_TEST_CHECK( moved );
571 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
572 DALI_TEST_CHECK( moved.GetTargetObject() == actor );
573 DALI_TEST_CHECK( !constraint );
578 ///////////////////////////////////////////////////////////////////////////////
579 // Constraint::DownCast
580 ///////////////////////////////////////////////////////////////////////////////
581 int UtcDaliConstraintDownCast(void)
583 // Ensure DownCast works as expected
585 TestApplication application;
587 Actor actor = Actor::New();
588 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
590 // Another BaseHandle type
591 Constraint downCast = Constraint::DownCast( actor );
592 DALI_TEST_CHECK( ! downCast );
595 downCast = Constraint::DownCast( constraint );
596 DALI_TEST_CHECK( downCast );
598 // An empty constraint
599 downCast = Constraint::DownCast( Constraint() );
600 DALI_TEST_CHECK( ! downCast );
604 ///////////////////////////////////////////////////////////////////////////////
606 ///////////////////////////////////////////////////////////////////////////////
607 // Constraint::GetTargetObject
608 ///////////////////////////////////////////////////////////////////////////////
609 int UtcDaliConstraintGetTargetObjectP(void)
611 TestApplication application;
613 Actor actor = Actor::New();
614 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
615 DALI_TEST_CHECK( constraint.GetTargetObject() == actor );
617 Actor actor2 = Actor::New();
618 DALI_TEST_CHECK( constraint.GetTargetObject() != actor2 );
623 int UtcDaliConstraintGetTargetObjectN(void)
625 // Attempt to retrieve from uninitialised constraint
627 TestApplication application;
629 Constraint constraint;
632 Handle handle = constraint.GetTargetObject();
633 DALI_TEST_CHECK( false ); // Should not reach here!
637 DALI_TEST_CHECK( true );
642 ///////////////////////////////////////////////////////////////////////////////
644 ///////////////////////////////////////////////////////////////////////////////
645 // Constraint::GetTargetProperty
646 ///////////////////////////////////////////////////////////////////////////////
647 int UtcDaliConstraintGetTargetPropertyP(void)
649 TestApplication application;
651 Actor actor = Actor::New();
652 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
653 DALI_TEST_EQUALS( constraint.GetTargetProperty(), (Property::Index)Actor::Property::POSITION, TEST_LOCATION );
658 int UtcDaliConstraintGetTargetPropertyN(void)
660 // Attempt to retrieve from uninitialised constraint
662 TestApplication application;
664 Constraint constraint;
667 Property::Index propertyIndex = constraint.GetTargetProperty();
668 ( void )propertyIndex;
669 DALI_TEST_CHECK( false ); // Should not reach here!
673 DALI_TEST_CHECK( true );
678 ///////////////////////////////////////////////////////////////////////////////
680 ///////////////////////////////////////////////////////////////////////////////
681 // Constraint::SetTag
682 // Constraint::GetTag
683 ///////////////////////////////////////////////////////////////////////////////
684 int UtcDaliConstraintTagP(void)
686 TestApplication application;
688 Actor actor = Actor::New();
689 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
690 DALI_TEST_EQUALS( constraint.GetTag(), 0u, TEST_LOCATION );
692 const unsigned int tag = 123;
693 constraint.SetTag( tag );
694 DALI_TEST_EQUALS( constraint.GetTag(), tag, TEST_LOCATION );
699 int UtcDaliConstraintSetTagN(void)
701 // Attempt to set from uninitialised constraint
703 TestApplication application;
705 Constraint constraint;
708 constraint.SetTag( 123 );
709 DALI_TEST_CHECK( false ); // Should not reach here!
713 DALI_TEST_CHECK( true );
719 int UtcDaliConstraintGetTagN(void)
721 // Attempt to retrieve from uninitialised constraint
723 TestApplication application;
725 Constraint constraint;
728 int tag = constraint.GetTag();
730 DALI_TEST_CHECK( false ); // Should not reach here!
734 DALI_TEST_CHECK( true );
740 ///////////////////////////////////////////////////////////////////////////////
742 ///////////////////////////////////////////////////////////////////////////////
743 // Constraint::SetRemoveAction
744 // Constraint::GetRemoveAction
745 ///////////////////////////////////////////////////////////////////////////////
746 int UtcDaliConstraintRemoveActionP(void)
748 TestApplication application;
750 Actor actor = Actor::New();
751 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
752 DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::DEFAULT_REMOVE_ACTION, TEST_LOCATION );
754 constraint.SetRemoveAction( Constraint::Discard );
755 DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Discard, TEST_LOCATION );
757 constraint.SetRemoveAction( Constraint::Bake );
758 DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Bake, TEST_LOCATION );
763 int UtcDaliConstraintSetRemoveActionN(void)
765 // Attempt to set from uninitialised constraint
767 TestApplication application;
769 Constraint constraint;
772 constraint.SetRemoveAction( Constraint::Discard );
773 DALI_TEST_CHECK( false ); // Should not reach here!
777 DALI_TEST_CHECK( true );
783 int UtcDaliConstraintGetRemoveActionN(void)
785 // Attempt to retrieve from uninitialised constraint
787 TestApplication application;
789 Constraint constraint;
792 Constraint::RemoveAction removeAction = constraint.GetRemoveAction();
793 ( void )removeAction;
794 DALI_TEST_CHECK( false ); // Should not reach here!
798 DALI_TEST_CHECK( true );
804 int UtcDaliConstraintBakeRemoveAction(void)
806 // Ensure value is baked when constraint is removed
808 TestApplication application;
810 Actor actor = Actor::New();
811 application.GetScene().Add( actor );
813 application.SendNotification();
814 application.Render();
816 // Should not equal position by default
817 Vector3 position( 10.0f, 20.0f, 30.0f );
818 DALI_TEST_CHECK( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) != position );
820 // Create a constraint that constrains to position
821 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) );
822 constraint.SetRemoveAction( Constraint::Bake );
825 application.SendNotification();
826 application.Render();
828 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), position, TEST_LOCATION );
830 // Remove the constraint, it should still be at position
833 application.SendNotification();
834 application.Render();
836 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), position, TEST_LOCATION );
841 int UtcDaliConstraintDiscardRemoveAction(void)
843 // Ensure value is baked when constraint is removed
845 TestApplication application;
847 Actor actor = Actor::New();
848 application.GetScene().Add( actor );
850 application.SendNotification();
851 application.Render();
853 // Get and store current position
854 Vector3 originalPosition = actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
856 // Should not equal position by default
857 Vector3 position( 10.0f, 20.0f, 30.0f );
858 DALI_TEST_CHECK( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) != position );
860 // Create a constraint that constrains to position
861 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) );
862 constraint.SetRemoveAction( Constraint::Discard );
865 application.SendNotification();
866 application.Render();
868 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), position, TEST_LOCATION );
870 // Remove the constraint, it should still be at position
873 application.SendNotification();
874 application.Render();
876 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), originalPosition, TEST_LOCATION );
877 DALI_TEST_CHECK( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) != position );
882 ///////////////////////////////////////////////////////////////////////////////
884 ///////////////////////////////////////////////////////////////////////////////
886 // Constraint::Remove
887 ///////////////////////////////////////////////////////////////////////////////
888 int UtcDaliConstraintApplyRemove(void)
890 // Ensure constraint functors are called appropriately
892 TestApplication application;
893 bool functorCalled = false;
895 Actor actor = Actor::New();
896 application.GetScene().Add( actor );
898 application.SendNotification();
899 application.Render();
901 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
903 // Create a constraint and apply, functor should be called
904 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
907 application.SendNotification();
908 application.Render();
910 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
913 functorCalled = false;
915 // Remove the constraint, functor should not be called
918 application.SendNotification();
919 application.Render();
921 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
923 // Re-apply the constraint, functor should be called again
926 application.SendNotification();
927 application.Render();
929 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
934 int UtcDaliConstraintApplyBeforeAddedToStage(void)
936 // Constraint gets applied to an off-stage actor.
937 // Constraint should be automatically applied when the actor is added to the stage and not before
939 TestApplication application;
940 bool functorCalled = false;
942 // Create an actor and a constraint and apply, DON'T add to stage just yet
943 Actor actor = Actor::New();
944 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
947 application.SendNotification();
948 application.Render();
950 // Should NOT be called
951 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
953 // Add actor to stage
954 application.GetScene().Add( actor );
956 application.SendNotification();
957 application.Render();
959 // Should now be called
960 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
965 int UtcDaliConstraintApplyAndRemoveBeforeAddedToStage(void)
967 // Constraint gets applied to an off-stage actor, then gets removed before it's added to the stage
968 // Constraint should NOT be called at all
970 TestApplication application;
971 bool functorCalled = false;
973 // Create an actor and a constraint and apply, DON'T add to stage just yet
974 Actor actor = Actor::New();
975 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
978 application.SendNotification();
979 application.Render();
981 // Should NOT be called
982 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
984 // Remove the constraint
987 // Add actor to stage
988 application.GetScene().Add( actor );
990 application.SendNotification();
991 application.Render();
993 // Still should NOT be called
994 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
999 int UtcDaliConstraintApplyActorStagedUnstaged(void)
1001 // Apply a constraint to an actor which is staged and unstaged.
1002 // Functor should only be called while the actor is staged.
1004 TestApplication application;
1005 bool functorCalled = false;
1007 // Create an actor and add to stage
1008 Actor actor = Actor::New();
1009 Integration::Scene stage = application.GetScene();
1012 // Create a constraint and apply
1013 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
1016 application.SendNotification();
1017 application.Render();
1019 // Constraint should be called
1020 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
1023 functorCalled = false;
1025 // Remove actor from stage
1026 stage.Remove( actor );
1028 application.SendNotification();
1029 application.Render();
1031 // Constraint should NOT be called
1032 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
1037 application.SendNotification();
1038 application.Render();
1040 // Constraint should be called
1041 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
1046 int UtcDaliConstraintApplySeveralTimes(void)
1048 // Apply the same constraint several times.
1049 // Should not cause any problems (subsequent attempts should be no-ops)
1051 TestApplication application;
1054 // Create an actor and add to stage
1055 Actor actor = Actor::New();
1056 Integration::Scene stage = application.GetScene();
1059 // Create a constraint and apply
1060 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, CalledCountFunctor< Vector3 >( count ) );
1064 constraint.Apply(); // no-op
1066 application.SendNotification();
1067 application.Render();
1069 // Should only have been called once
1070 DALI_TEST_EQUALS( count, 1, TEST_LOCATION );
1076 constraint.Apply(); // no-op
1078 application.SendNotification();
1079 application.Render();
1081 DALI_TEST_EQUALS( count, 1, TEST_LOCATION );
1086 // Change the position property, apply again
1087 actor.SetProperty( Actor::Property::POSITION, Vector2( 10.0f, 10.0f ));
1090 application.SendNotification();
1091 application.Render();
1093 // Constraint should have been called once
1094 DALI_TEST_EQUALS( count, 1, TEST_LOCATION );
1099 ///////////////////////////////////////////////////////////////////////////////
1101 ///////////////////////////////////////////////////////////////////////////////
1102 // Constraint::AddSource
1103 ///////////////////////////////////////////////////////////////////////////////
1104 namespace UtcDaliConstraintAddSource
1106 void Function( Vector3& /* current */, const PropertyInputContainer& inputs )
1108 DALI_TEST_EQUALS( inputs.Size(), 4u, TEST_LOCATION );
1109 DALI_TEST_EQUALS( inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION );
1110 DALI_TEST_EQUALS( inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION );
1111 DALI_TEST_EQUALS( inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION );
1112 DALI_TEST_EQUALS( inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION );
1114 } // namespace UtcDaliConstraintAddSource
1116 int UtcDaliConstraintAddSourceP(void)
1118 // Ensure all sources are in the correct order in the functor
1120 TestApplication application;
1122 Actor actor = Actor::New();
1123 application.GetScene().Add( actor );
1125 // Create a constraint, add sources
1126 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintAddSource::Function );
1127 constraint.AddSource( LocalSource( Actor::Property::SIZE ) );
1128 constraint.AddSource( LocalSource( Actor::Property::ORIENTATION ) );
1129 constraint.AddSource( LocalSource( Actor::Property::COLOR ) );
1130 constraint.AddSource( LocalSource( Actor::Property::VISIBLE ) );
1133 application.SendNotification();
1134 application.Render();
1139 int UtcDaliConstraintAddSourceN(void)
1141 // Attempt to set from uninitialised constraint
1143 TestApplication application;
1145 Constraint constraint;
1148 constraint.AddSource( LocalSource( Actor::Property::POSITION ) );
1149 DALI_TEST_CHECK( false ); // Should not reach here!
1153 DALI_TEST_CHECK( true );
1158 ///////////////////////////////////////////////////////////////////////////////
1160 ///////////////////////////////////////////////////////////////////////////////
1161 namespace TestChaining
1164 const Vector3 gFunction1Output( Vector3::ONE );
1165 void Function1( Vector3& current, const PropertyInputContainer& /* inputs */ )
1167 // current is original position
1168 DALI_TEST_EQUALS( current, Vector3::ZERO, TEST_LOCATION );
1169 current = gFunction1Output;
1172 const Vector3 gFunction2Output( 10.0f, 20.0f, 30.0f );
1173 void Function2( Vector3& current, const PropertyInputContainer& /* inputs */ )
1175 // current is output from Function1
1176 DALI_TEST_EQUALS( current, gFunction1Output, TEST_LOCATION );
1178 current = gFunction2Output;
1181 const Vector3 gFunction3Output( 10.0f, 20.0f, 30.0f );
1182 void Function3( Vector3& current, const PropertyInputContainer& /* inputs */ )
1184 // current is output from Function2
1185 DALI_TEST_EQUALS( current, gFunction2Output, TEST_LOCATION );
1187 current = gFunction3Output;
1190 const Vector3 gFunction4Output( 10.0f, 20.0f, 30.0f );
1191 void Function4( Vector3& current, const PropertyInputContainer& /* inputs */ )
1193 // current is output from Function3
1194 DALI_TEST_EQUALS( current, gFunction3Output, TEST_LOCATION );
1196 current = gFunction4Output;
1199 void Function5( Vector3& current, const PropertyInputContainer& /* inputs */ )
1201 // current is output from Function4
1202 DALI_TEST_EQUALS( current, gFunction4Output, TEST_LOCATION );
1204 current = Vector3::ZERO;
1207 } // namespace TestChaining
1209 int UtcDaliConstraintChaining(void)
1211 // Apply several constraints to the same property and ensure the functors are called in the correct order.
1213 TestApplication application;
1215 Actor actor = Actor::New();
1216 application.GetScene().Add( actor );
1218 Constraint constraint1 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function1 );
1219 Constraint constraint2 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function2 );
1220 Constraint constraint3 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function3 );
1221 Constraint constraint4 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function4 );
1222 Constraint constraint5 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function5 );
1224 constraint1.Apply();
1225 constraint2.Apply();
1226 constraint3.Apply();
1227 constraint4.Apply();
1228 constraint5.Apply();
1230 application.SendNotification();
1231 application.Render();
1235 ///////////////////////////////////////////////////////////////////////////////
1237 ///////////////////////////////////////////////////////////////////////////////
1238 namespace TestPropertyTypes
1240 template< typename T >
1241 void Execute( T value )
1243 TestApplication application;
1244 bool functorCalled = false;
1246 Actor actor = Actor::New();
1247 Property::Index index = actor.RegisterProperty( "TEMP_PROPERTY_NAME", value );
1249 application.GetScene().Add( actor );
1251 application.SendNotification();
1252 application.Render();
1254 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
1257 Constraint constraint = Constraint::New< T >( actor, index, BasicCalledFunctor< T >( functorCalled ) );
1258 DALI_TEST_CHECK( constraint );
1261 application.SendNotification();
1262 application.Render();
1264 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
1266 } // namespace UtcDaliConstraintNewFunctor
1268 int UtcDaliConstraintTestPropertyTypesP(void)
1270 // Ensure we can use a constraint functor with all supported property types
1272 TestPropertyTypes::Execute< bool >( false );
1273 TestPropertyTypes::Execute< int >( 0 );
1274 TestPropertyTypes::Execute< float >( 0.0f );
1275 TestPropertyTypes::Execute< Vector2 >( Vector2::ZERO );
1276 TestPropertyTypes::Execute< Vector3 >( Vector3::ZERO );
1277 TestPropertyTypes::Execute< Vector4 >( Vector4::ZERO );
1278 TestPropertyTypes::Execute< Quaternion >( Quaternion::IDENTITY );
1279 TestPropertyTypes::Execute< Matrix >( Matrix::IDENTITY );
1280 TestPropertyTypes::Execute< Matrix3 >( Matrix3::IDENTITY );
1285 ///////////////////////////////////////////////////////////////////////////////
1287 ///////////////////////////////////////////////////////////////////////////////
1290 void SetHalfOpacity( Vector4& current, const PropertyInputContainer& inputs )
1294 } // unnamed namespace
1296 int UtcDaliConstraintEnsureResetterAppliedOnSceneRemoval(void)
1298 // Ensure BOTH double-buffered values of our color property is reset when a constraint is applied to it.
1300 TestApplication application;
1302 Actor actor = Actor::New();
1303 application.GetScene().Add( actor );
1305 // Check initial value is fully opaque
1306 application.SendNotification();
1307 application.Render();
1308 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
1310 // Create a constraint whose value is discarded when it is removed
1311 Constraint constraint = Constraint::New< Vector4 >( actor, Actor::Property::COLOR, SetHalfOpacity );
1312 constraint.SetRemoveAction( Constraint::RemoveAction::Discard );
1315 // Check value after one render, it should be constrained
1316 application.SendNotification();
1317 application.Render();
1318 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
1320 // Render another frame, ensure the other value has also been updated
1321 application.SendNotification();
1322 application.Render();
1323 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
1325 // Remove the actor from the stage and delete the constraint
1327 constraint.Remove();
1330 // Check value while off-stage, it should be fully opaque
1331 application.SendNotification();
1332 application.Render();
1333 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
1335 // Add the actor back to the stage and check the value, it should be fully opaque again
1336 application.GetScene().Add( actor );
1338 // Check value when back on-stage, it should be fully opaque as the constraint is no longer applied to it.
1339 application.SendNotification();
1340 application.Render();
1341 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
1343 // Render for another frame to ensure both buffers have the correct value
1344 application.SendNotification();
1345 application.Render();
1346 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
1351 int UtcDaliConstraintOnActorAddedAndRemoved(void)
1353 // Ensure adding and removing an actor from stage with a constraint still has it applied when it is re-added back to the stage
1355 TestApplication application;
1357 Actor actor = Actor::New();
1358 application.GetScene().Add( actor );
1360 // Check initial value is fully opaque
1361 application.SendNotification();
1362 application.Render();
1363 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
1365 // Create a constraint whose value is discarded when it is removed
1366 Constraint constraint = Constraint::New< Vector4 >( actor, Actor::Property::COLOR, SetHalfOpacity );
1367 constraint.SetRemoveAction( Constraint::RemoveAction::Discard );
1370 // Check value after one render, it should be constrained
1371 application.SendNotification();
1372 application.Render();
1373 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
1375 // Render another frame, ensure the other value has also been updated
1376 application.SendNotification();
1377 application.Render();
1378 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
1380 // Remove the actor from the stage
1383 // Check value while off-stage, the constraint is no longer being applied as it's off-stage
1384 application.SendNotification();
1385 application.Render();
1386 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
1388 // Check the other buffer, the constraint should not be applied to this either.
1389 application.SendNotification();
1390 application.Render();
1391 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
1393 // Add the actor back to the stage and check the value, the constraint should have been re-applied
1394 application.GetScene().Add( actor );
1395 application.SendNotification();
1396 application.Render();
1397 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
1399 // Render for another frame to ensure both buffers have the correct value
1400 application.SendNotification();
1401 application.Render();
1402 DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
1407 ///////////////////////////////////////////////////////////////////////////////
1409 int UtcDaliConstraintGetTargetObjectNegative(void)
1411 TestApplication application;
1412 Dali::Constraint instance;
1415 instance.GetTargetObject();
1416 DALI_TEST_CHECK(false); // Should not get here
1420 DALI_TEST_CHECK(true); // We expect an assert
1425 int UtcDaliConstraintSetRemoveActionNegative(void)
1427 TestApplication application;
1428 Dali::Constraint instance;
1431 Dali::Constraint::RemoveAction arg1(Constraint::Bake);
1432 instance.SetRemoveAction(arg1);
1433 DALI_TEST_CHECK(false); // Should not get here
1437 DALI_TEST_CHECK(true); // We expect an assert
1442 int UtcDaliConstraintGetTargetPropertyNegative(void)
1444 TestApplication application;
1445 Dali::Constraint instance;
1448 instance.GetTargetProperty();
1449 DALI_TEST_CHECK(false); // Should not get here
1453 DALI_TEST_CHECK(true); // We expect an assert
1458 int UtcDaliConstraintApplyNegative(void)
1460 TestApplication application;
1461 Dali::Constraint instance;
1465 DALI_TEST_CHECK(false); // Should not get here
1469 DALI_TEST_CHECK(true); // We expect an assert
1474 int UtcDaliConstraintCloneNegative(void)
1476 TestApplication application;
1477 Dali::Constraint instance;
1481 instance.Clone(arg1);
1482 DALI_TEST_CHECK(false); // Should not get here
1486 DALI_TEST_CHECK(true); // We expect an assert
1491 int UtcDaliConstraintRemoveNegative(void)
1493 TestApplication application;
1494 Dali::Constraint instance;
1498 DALI_TEST_CHECK(false); // Should not get here
1502 DALI_TEST_CHECK(true); // We expect an assert
1507 int UtcDaliConstraintSetTagNegative(void)
1509 TestApplication application;
1510 Dali::Constraint instance;
1513 unsigned int arg1(0u);
1514 instance.SetTag(arg1);
1515 DALI_TEST_CHECK(false); // Should not get here
1519 DALI_TEST_CHECK(true); // We expect an assert
1524 int UtcDaliConstraintGetRemoveActionNegative(void)
1526 TestApplication application;
1527 Dali::Constraint instance;
1530 instance.GetRemoveAction();
1531 DALI_TEST_CHECK(false); // Should not get here
1535 DALI_TEST_CHECK(true); // We expect an assert
1540 int UtcDaliConstraintGetTagNegative(void)
1542 TestApplication application;
1543 Dali::Constraint instance;
1547 DALI_TEST_CHECK(false); // Should not get here
1551 DALI_TEST_CHECK(true); // We expect an assert