2 * Copyright (c) 2014 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 Stage::GetCurrent().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!
163 ///////////////////////////////////////////////////////////////////////////////
165 ///////////////////////////////////////////////////////////////////////////////
170 ///////////////////////////////////////////////////////////////////////////////
171 int UtcDaliConstraintNewFunctorP(void)
173 // Ensure that we can create a constraint using a functor and that it is called.
175 TestApplication application;
176 bool functorCalled = false;
178 Actor actor = Actor::New();
179 Stage::GetCurrent().Add( actor );
181 application.SendNotification();
182 application.Render();
184 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
187 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
188 DALI_TEST_CHECK( constraint );
191 application.SendNotification();
192 application.Render();
194 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
199 int UtcDaliConstraintNewFunctorN(void)
201 // Create a constraint with an uninitialised handle
203 TestApplication application;
204 bool functorCalled = false;
206 // Add a constraint with an uninitialised handle
209 Constraint constraint = Constraint::New< Vector3 >( Actor(), Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
210 DALI_TEST_CHECK( false ); // Should not reach here
214 DALI_TEST_CHECK( true ); // Should assert!
219 ///////////////////////////////////////////////////////////////////////////////
221 ///////////////////////////////////////////////////////////////////////////////
226 // void ( T::*memberFunction ) ( P&, const PropertyInputContainer& ) )
227 ///////////////////////////////////////////////////////////////////////////////
228 namespace UtcDaliConstraintNewFunctorMember
232 Functor( bool& positionCalled, bool& scaleCalled )
233 : mPositionCalled( positionCalled ),
234 mScaleCalled( scaleCalled )
238 void Position( Vector3& /* current */, const PropertyInputContainer& /* inputs */ )
240 mPositionCalled = true;
243 void Scale( Vector3& /* current */, const PropertyInputContainer& /* inputs */ )
248 bool& mPositionCalled;
251 } // namespace UtcDaliConstraintNewFunctorMember
253 int UtcDaliConstraintNewFunctorMemberP(void)
255 // Ensure that we can create a constraint using a functor and that it is called.
257 TestApplication application;
258 bool positionFunctorCalled = false;
259 bool sizeFunctorCalled = false;
261 Actor actor = Actor::New();
262 Stage::GetCurrent().Add( actor );
264 application.SendNotification();
265 application.Render();
267 DALI_TEST_EQUALS( positionFunctorCalled, false, TEST_LOCATION );
268 DALI_TEST_EQUALS( sizeFunctorCalled, false, TEST_LOCATION );
270 // Add a constraint that calls Functor::Position
271 Constraint constraint = Constraint::New< Vector3 >(
273 Actor::Property::POSITION,
274 UtcDaliConstraintNewFunctorMember::Functor( positionFunctorCalled, sizeFunctorCalled ),
275 &UtcDaliConstraintNewFunctorMember::Functor::Position );
276 DALI_TEST_CHECK( constraint );
279 application.SendNotification();
280 application.Render();
282 DALI_TEST_EQUALS( positionFunctorCalled, true, TEST_LOCATION );
283 DALI_TEST_EQUALS( sizeFunctorCalled, false, TEST_LOCATION );
285 // Add another constraint that calls Functor::Size
286 Constraint constraint2 = Constraint::New< Vector3 >(
288 Actor::Property::SCALE,
289 UtcDaliConstraintNewFunctorMember::Functor( positionFunctorCalled, sizeFunctorCalled ),
290 &UtcDaliConstraintNewFunctorMember::Functor::Scale );
291 DALI_TEST_CHECK( constraint2 );
294 application.SendNotification();
295 application.Render();
297 DALI_TEST_EQUALS( positionFunctorCalled, true, TEST_LOCATION );
298 DALI_TEST_EQUALS( sizeFunctorCalled, true, TEST_LOCATION );
303 int UtcDaliConstraintNewFunctorMemberN(void)
305 // Create a constraint with an uninitialised handle
307 TestApplication application;
308 bool positionFunctorCalled = false;
309 bool sizeFunctorCalled = false;
311 // Add a constraint with an uninitialised handle
314 Constraint constraint = Constraint::New< Vector3 >(
316 Actor::Property::POSITION,
317 UtcDaliConstraintNewFunctorMember::Functor( positionFunctorCalled, sizeFunctorCalled ),
318 &UtcDaliConstraintNewFunctorMember::Functor::Position );
319 DALI_TEST_CHECK( false ); // Should not reach here
321 catch ( Dali::DaliException& e )
323 DALI_TEST_CHECK( true ); // Should assert!
328 ///////////////////////////////////////////////////////////////////////////////
330 ///////////////////////////////////////////////////////////////////////////////
332 ///////////////////////////////////////////////////////////////////////////////
333 int UtcDaliConstraintCloneP(void)
335 // Ensure we can clone for another actor and it's called appropriately
337 TestApplication application;
340 Actor actor = Actor::New();
341 Actor clone = Actor::New();
343 Stage stage = Stage::GetCurrent();
347 application.SendNotification();
348 application.Render();
350 DALI_TEST_EQUALS( calledCount, 0, TEST_LOCATION );
352 // Add a constraint to actor
353 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, CalledCountFunctor< Vector3 >( calledCount ) );
354 DALI_TEST_CHECK( constraint );
357 // Create a clone but don't apply
358 Constraint constraintClone = constraint.Clone( clone );
360 application.SendNotification();
361 application.Render();
363 DALI_TEST_EQUALS( calledCount, 1, TEST_LOCATION );
368 application.SendNotification();
369 application.Render();
371 DALI_TEST_EQUALS( calledCount, 1, TEST_LOCATION );
373 // Apply the clone constraint
374 constraintClone.Apply();
376 application.SendNotification();
377 application.Render();
379 // Should be called once for the new constraint clone and once for the original constraint
380 DALI_TEST_EQUALS( calledCount, 3, TEST_LOCATION );
385 // Change the position of both actors
386 actor.SetPosition( 100.0f, 100.0f );
387 clone.SetPosition( 100.0f, 100.0f );
389 application.SendNotification();
390 application.Render();
392 // Functor should have been called twice
393 DALI_TEST_EQUALS( calledCount, 2, TEST_LOCATION );
398 int UtcDaliConstraintCloneN(void)
400 // Attempt to clone an uninitialised constraint should cause an assert
402 TestApplication application;
404 Constraint constraint;
408 Actor actor = Actor::New();
409 Constraint clone = constraint.Clone( actor );
410 DALI_TEST_CHECK( false );
414 DALI_TEST_CHECK( true );
420 namespace UtcDaliConstraintClone
422 void Function( Vector3& /* current */, const PropertyInputContainer& inputs )
424 DALI_TEST_EQUALS( inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION );
425 DALI_TEST_EQUALS( inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION );
426 DALI_TEST_EQUALS( inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION );
427 DALI_TEST_EQUALS( inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION );
429 } // namespace UtcDaliConstraintClone
431 int UtcDaliConstraintCloneCheckSourcesAndSetters(void)
433 // Ensure all sources, the tag and remove-action are cloned appropriately
435 TestApplication application;
437 Actor actor = Actor::New();
438 Actor clone = Actor::New();
440 Stage stage = Stage::GetCurrent();
444 application.SendNotification();
445 application.Render();
447 // Create a constraint, DON'T Apply it though
448 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintClone::Function );
449 constraint.AddSource( LocalSource( Actor::Property::SIZE ) );
450 constraint.AddSource( LocalSource( Actor::Property::ORIENTATION ) );
451 constraint.AddSource( LocalSource( Actor::Property::COLOR ) );
452 constraint.AddSource( LocalSource( Actor::Property::VISIBLE ) );
453 constraint.SetRemoveAction( Constraint::Discard );
454 constraint.SetTag( 123 );
456 // Clone the constraint & apply the clone
457 Constraint constraintClone = constraint.Clone( clone );
458 constraintClone.Apply();
460 application.SendNotification();
461 application.Render();
463 DALI_TEST_EQUALS( constraint.GetRemoveAction(), constraintClone.GetRemoveAction(), TEST_LOCATION );
464 DALI_TEST_EQUALS( constraint.GetTag(), constraintClone.GetTag(), TEST_LOCATION );
468 ///////////////////////////////////////////////////////////////////////////////
470 ///////////////////////////////////////////////////////////////////////////////
471 // Constraint::Constraint( const Constraint& )
472 // Constraint::operator=
473 ///////////////////////////////////////////////////////////////////////////////
474 int UtcDaliConstraintCopyAndAssignment(void)
476 // Ensure copy constructor & assignment operators work
478 TestApplication application;
480 Actor actor = Actor::New();
481 Stage::GetCurrent().Add( actor );
483 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
484 Constraint copied( constraint );
486 DALI_TEST_CHECK( constraint == copied );
487 DALI_TEST_CHECK( copied != assigned );
489 assigned = constraint;
490 DALI_TEST_CHECK( constraint == assigned );
494 ///////////////////////////////////////////////////////////////////////////////
496 ///////////////////////////////////////////////////////////////////////////////
497 // Constraint::DownCast
498 ///////////////////////////////////////////////////////////////////////////////
499 int UtcDaliConstraintDownCast(void)
501 // Ensure DownCast works as expected
503 TestApplication application;
505 Actor actor = Actor::New();
506 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
508 // Another BaseHandle type
509 Constraint downCast = Constraint::DownCast( actor );
510 DALI_TEST_CHECK( ! downCast );
513 downCast = Constraint::DownCast( constraint );
514 DALI_TEST_CHECK( downCast );
516 // An empty constraint
517 downCast = Constraint::DownCast( Constraint() );
518 DALI_TEST_CHECK( ! downCast );
522 ///////////////////////////////////////////////////////////////////////////////
524 ///////////////////////////////////////////////////////////////////////////////
525 // Constraint::GetTargetObject
526 ///////////////////////////////////////////////////////////////////////////////
527 int UtcDaliConstraintGetTargetObjectP(void)
529 TestApplication application;
531 Actor actor = Actor::New();
532 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
533 DALI_TEST_CHECK( constraint.GetTargetObject() == actor );
535 Actor actor2 = Actor::New();
536 DALI_TEST_CHECK( constraint.GetTargetObject() != actor2 );
541 int UtcDaliConstraintGetTargetObjectN(void)
543 // Attempt to retrieve from uninitialised constraint
545 TestApplication application;
547 Constraint constraint;
550 Handle handle = constraint.GetTargetObject();
551 DALI_TEST_CHECK( false ); // Should not reach here!
555 DALI_TEST_CHECK( true );
560 ///////////////////////////////////////////////////////////////////////////////
562 ///////////////////////////////////////////////////////////////////////////////
563 // Constraint::GetTargetProperty
564 ///////////////////////////////////////////////////////////////////////////////
565 int UtcDaliConstraintGetTargetPropertyP(void)
567 TestApplication application;
569 Actor actor = Actor::New();
570 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
571 DALI_TEST_EQUALS( constraint.GetTargetProperty(), (Property::Index)Actor::Property::POSITION, TEST_LOCATION );
576 int UtcDaliConstraintGetTargetPropertyN(void)
578 // Attempt to retrieve from uninitialised constraint
580 TestApplication application;
582 Constraint constraint;
585 Property::Index propertyIndex = constraint.GetTargetProperty();
586 ( void )propertyIndex;
587 DALI_TEST_CHECK( false ); // Should not reach here!
591 DALI_TEST_CHECK( true );
596 ///////////////////////////////////////////////////////////////////////////////
598 ///////////////////////////////////////////////////////////////////////////////
599 // Constraint::SetTag
600 // Constraint::GetTag
601 ///////////////////////////////////////////////////////////////////////////////
602 int UtcDaliConstraintTagP(void)
604 TestApplication application;
606 Actor actor = Actor::New();
607 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
608 DALI_TEST_EQUALS( constraint.GetTag(), 0u, TEST_LOCATION );
610 const unsigned int tag = 123;
611 constraint.SetTag( tag );
612 DALI_TEST_EQUALS( constraint.GetTag(), tag, TEST_LOCATION );
617 int UtcDaliConstraintSetTagN(void)
619 // Attempt to set from uninitialised constraint
621 TestApplication application;
623 Constraint constraint;
626 constraint.SetTag( 123 );
627 DALI_TEST_CHECK( false ); // Should not reach here!
631 DALI_TEST_CHECK( true );
637 int UtcDaliConstraintGetTagN(void)
639 // Attempt to retrieve from uninitialised constraint
641 TestApplication application;
643 Constraint constraint;
646 int tag = constraint.GetTag();
648 DALI_TEST_CHECK( false ); // Should not reach here!
652 DALI_TEST_CHECK( true );
658 ///////////////////////////////////////////////////////////////////////////////
660 ///////////////////////////////////////////////////////////////////////////////
661 // Constraint::SetRemoveAction
662 // Constraint::GetRemoveAction
663 ///////////////////////////////////////////////////////////////////////////////
664 int UtcDaliConstraintRemoveActionP(void)
666 TestApplication application;
668 Actor actor = Actor::New();
669 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
670 DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::DEFAULT_REMOVE_ACTION, TEST_LOCATION );
672 constraint.SetRemoveAction( Constraint::Discard );
673 DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Discard, TEST_LOCATION );
675 constraint.SetRemoveAction( Constraint::Bake );
676 DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Bake, TEST_LOCATION );
681 int UtcDaliConstraintSetRemoveActionN(void)
683 // Attempt to set from uninitialised constraint
685 TestApplication application;
687 Constraint constraint;
690 constraint.SetRemoveAction( Constraint::Discard );
691 DALI_TEST_CHECK( false ); // Should not reach here!
695 DALI_TEST_CHECK( true );
701 int UtcDaliConstraintGetRemoveActionN(void)
703 // Attempt to retrieve from uninitialised constraint
705 TestApplication application;
707 Constraint constraint;
710 Constraint::RemoveAction removeAction = constraint.GetRemoveAction();
711 ( void )removeAction;
712 DALI_TEST_CHECK( false ); // Should not reach here!
716 DALI_TEST_CHECK( true );
722 int UtcDaliConstraintBakeRemoveAction(void)
724 // Ensure value is baked when constraint is removed
726 TestApplication application;
728 Actor actor = Actor::New();
729 Stage::GetCurrent().Add( actor );
731 application.SendNotification();
732 application.Render();
734 // Should not equal position by default
735 Vector3 position( 10.0f, 20.0f, 30.0f );
736 DALI_TEST_CHECK( actor.GetCurrentPosition() != position );
738 // Create a constraint that constrains to position
739 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) );
740 constraint.SetRemoveAction( Constraint::Bake );
743 application.SendNotification();
744 application.Render();
746 DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION );
748 // Remove the constraint, it should still be at position
751 application.SendNotification();
752 application.Render();
754 DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION );
759 int UtcDaliConstraintDiscardRemoveAction(void)
761 // Ensure value is baked when constraint is removed
763 TestApplication application;
765 Actor actor = Actor::New();
766 Stage::GetCurrent().Add( actor );
768 application.SendNotification();
769 application.Render();
771 // Get and store current position
772 Vector3 originalPosition = actor.GetCurrentPosition();
774 // Should not equal position by default
775 Vector3 position( 10.0f, 20.0f, 30.0f );
776 DALI_TEST_CHECK( actor.GetCurrentPosition() != position );
778 // Create a constraint that constrains to position
779 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) );
780 constraint.SetRemoveAction( Constraint::Discard );
783 application.SendNotification();
784 application.Render();
786 DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION );
788 // Remove the constraint, it should still be at position
791 application.SendNotification();
792 application.Render();
794 DALI_TEST_EQUALS( actor.GetCurrentPosition(), originalPosition, TEST_LOCATION );
795 DALI_TEST_CHECK( actor.GetCurrentPosition() != position );
800 ///////////////////////////////////////////////////////////////////////////////
802 ///////////////////////////////////////////////////////////////////////////////
804 // Constraint::Remove
805 ///////////////////////////////////////////////////////////////////////////////
806 int UtcDaliConstraintApplyRemove(void)
808 // Ensure constraint functors are called appropriately
810 TestApplication application;
811 bool functorCalled = false;
813 Actor actor = Actor::New();
814 Stage::GetCurrent().Add( actor );
816 application.SendNotification();
817 application.Render();
819 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
821 // Create a constraint and apply, functor should be called
822 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
825 application.SendNotification();
826 application.Render();
828 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
831 functorCalled = false;
833 // Remove the constraint, functor should not be called
836 application.SendNotification();
837 application.Render();
839 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
841 // Re-apply the constraint, functor should be called again
844 application.SendNotification();
845 application.Render();
847 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
852 int UtcDaliConstraintApplyBeforeAddedToStage(void)
854 // Constraint gets applied to an off-stage actor.
855 // Constraint should be automatically applied when the actor is added to the stage and not before
857 TestApplication application;
858 bool functorCalled = false;
860 // Create an actor and a constraint and apply, DON'T add to stage just yet
861 Actor actor = Actor::New();
862 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
865 application.SendNotification();
866 application.Render();
868 // Should NOT be called
869 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
871 // Add actor to stage
872 Stage::GetCurrent().Add( actor );
874 application.SendNotification();
875 application.Render();
877 // Should now be called
878 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
883 int UtcDaliConstraintApplyAndRemoveBeforeAddedToStage(void)
885 // Constraint gets applied to an off-stage actor, then gets removed before it's added to the stage
886 // Constraint should NOT be called at all
888 TestApplication application;
889 bool functorCalled = false;
891 // Create an actor and a constraint and apply, DON'T add to stage just yet
892 Actor actor = Actor::New();
893 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
896 application.SendNotification();
897 application.Render();
899 // Should NOT be called
900 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
902 // Remove the constraint
905 // Add actor to stage
906 Stage::GetCurrent().Add( actor );
908 application.SendNotification();
909 application.Render();
911 // Still should NOT be called
912 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
917 int UtcDaliConstraintApplyActorStagedUnstaged(void)
919 // Apply a constraint to an actor which is staged and unstaged.
920 // Functor should only be called while the actor is staged.
922 TestApplication application;
923 bool functorCalled = false;
925 // Create an actor and add to stage
926 Actor actor = Actor::New();
927 Stage stage = Stage::GetCurrent();
930 // Create a constraint and apply
931 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
934 application.SendNotification();
935 application.Render();
937 // Constraint should be called
938 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
941 functorCalled = false;
943 // Remove actor from stage
944 stage.Remove( actor );
946 application.SendNotification();
947 application.Render();
949 // Constraint should NOT be called
950 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
955 application.SendNotification();
956 application.Render();
958 // Constraint should be called
959 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
964 int UtcDaliConstraintApplySeveralTimes(void)
966 // Apply the same constraint several times.
967 // Should not cause any problems (subsequent attempts should be no-ops)
969 TestApplication application;
972 // Create an actor and add to stage
973 Actor actor = Actor::New();
974 Stage stage = Stage::GetCurrent();
977 // Create a constraint and apply
978 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, CalledCountFunctor< Vector3 >( count ) );
982 constraint.Apply(); // no-op
984 application.SendNotification();
985 application.Render();
987 // Should only have been called once
988 DALI_TEST_EQUALS( count, 1, TEST_LOCATION );
994 constraint.Apply(); // no-op
996 application.SendNotification();
997 application.Render();
999 DALI_TEST_EQUALS( count, 1, TEST_LOCATION );
1004 // Change the position property, apply again
1005 actor.SetPosition( 10.0f, 10.0f );
1008 application.SendNotification();
1009 application.Render();
1011 // Constraint should have been called once
1012 DALI_TEST_EQUALS( count, 1, TEST_LOCATION );
1017 ///////////////////////////////////////////////////////////////////////////////
1019 ///////////////////////////////////////////////////////////////////////////////
1020 // Constraint::AddSource
1021 ///////////////////////////////////////////////////////////////////////////////
1022 namespace UtcDaliConstraintAddSource
1024 void Function( Vector3& /* current */, const PropertyInputContainer& inputs )
1026 DALI_TEST_EQUALS( inputs.Size(), 4u, TEST_LOCATION );
1027 DALI_TEST_EQUALS( inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION );
1028 DALI_TEST_EQUALS( inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION );
1029 DALI_TEST_EQUALS( inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION );
1030 DALI_TEST_EQUALS( inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION );
1032 } // namespace UtcDaliConstraintAddSource
1034 int UtcDaliConstraintAddSourceP(void)
1036 // Ensure all sources are in the correct order in the functor
1038 TestApplication application;
1040 Actor actor = Actor::New();
1041 Stage::GetCurrent().Add( actor );
1043 // Create a constraint, add sources
1044 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintAddSource::Function );
1045 constraint.AddSource( LocalSource( Actor::Property::SIZE ) );
1046 constraint.AddSource( LocalSource( Actor::Property::ORIENTATION ) );
1047 constraint.AddSource( LocalSource( Actor::Property::COLOR ) );
1048 constraint.AddSource( LocalSource( Actor::Property::VISIBLE ) );
1051 application.SendNotification();
1052 application.Render();
1057 int UtcDaliConstraintAddSourceN(void)
1059 // Attempt to set from uninitialised constraint
1061 TestApplication application;
1063 Constraint constraint;
1066 constraint.AddSource( LocalSource( Actor::Property::POSITION ) );
1067 DALI_TEST_CHECK( false ); // Should not reach here!
1071 DALI_TEST_CHECK( true );
1076 ///////////////////////////////////////////////////////////////////////////////
1078 ///////////////////////////////////////////////////////////////////////////////
1079 namespace TestChaining
1082 const Vector3 gFunction1Output( Vector3::ONE );
1083 void Function1( Vector3& current, const PropertyInputContainer& /* inputs */ )
1085 // current is original position
1086 DALI_TEST_EQUALS( current, Vector3::ZERO, TEST_LOCATION );
1087 current = gFunction1Output;
1090 const Vector3 gFunction2Output( 10.0f, 20.0f, 30.0f );
1091 void Function2( Vector3& current, const PropertyInputContainer& /* inputs */ )
1093 // current is output from Function1
1094 DALI_TEST_EQUALS( current, gFunction1Output, TEST_LOCATION );
1096 current = gFunction2Output;
1099 const Vector3 gFunction3Output( 10.0f, 20.0f, 30.0f );
1100 void Function3( Vector3& current, const PropertyInputContainer& /* inputs */ )
1102 // current is output from Function2
1103 DALI_TEST_EQUALS( current, gFunction2Output, TEST_LOCATION );
1105 current = gFunction3Output;
1108 const Vector3 gFunction4Output( 10.0f, 20.0f, 30.0f );
1109 void Function4( Vector3& current, const PropertyInputContainer& /* inputs */ )
1111 // current is output from Function3
1112 DALI_TEST_EQUALS( current, gFunction3Output, TEST_LOCATION );
1114 current = gFunction4Output;
1117 void Function5( Vector3& current, const PropertyInputContainer& /* inputs */ )
1119 // current is output from Function4
1120 DALI_TEST_EQUALS( current, gFunction4Output, TEST_LOCATION );
1122 current = Vector3::ZERO;
1125 } // namespace TestChaining
1127 int UtcDaliConstraintChaining(void)
1129 // Apply several constraints to the same property and ensure the functors are called in the correct order.
1131 TestApplication application;
1133 Actor actor = Actor::New();
1134 Stage::GetCurrent().Add( actor );
1136 Constraint constraint1 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function1 );
1137 Constraint constraint2 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function2 );
1138 Constraint constraint3 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function3 );
1139 Constraint constraint4 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function4 );
1140 Constraint constraint5 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function5 );
1142 constraint1.Apply();
1143 constraint2.Apply();
1144 constraint3.Apply();
1145 constraint4.Apply();
1146 constraint5.Apply();
1148 application.SendNotification();
1149 application.Render();
1153 ///////////////////////////////////////////////////////////////////////////////
1155 ///////////////////////////////////////////////////////////////////////////////
1156 namespace TestPropertyTypes
1158 template< typename T >
1159 void Execute( T value )
1161 TestApplication application;
1162 bool functorCalled = false;
1164 Actor actor = Actor::New();
1165 Property::Index index = actor.RegisterProperty( "TEMP_PROPERTY_NAME", value );
1167 Stage::GetCurrent().Add( actor );
1169 application.SendNotification();
1170 application.Render();
1172 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
1175 Constraint constraint = Constraint::New< T >( actor, index, BasicCalledFunctor< T >( functorCalled ) );
1176 DALI_TEST_CHECK( constraint );
1179 application.SendNotification();
1180 application.Render();
1182 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
1184 } // namespace UtcDaliConstraintNewFunctor
1186 int UtcDaliConstraintTestPropertyTypesP(void)
1188 // Ensure we can use a constraint functor with all supported property types
1190 TestPropertyTypes::Execute< bool >( false );
1191 TestPropertyTypes::Execute< int >( 0 );
1192 TestPropertyTypes::Execute< float >( 0.0f );
1193 TestPropertyTypes::Execute< Vector2 >( Vector2::ZERO );
1194 TestPropertyTypes::Execute< Vector3 >( Vector3::ZERO );
1195 TestPropertyTypes::Execute< Vector4 >( Vector4::ZERO );
1196 TestPropertyTypes::Execute< Quaternion >( Quaternion::IDENTITY );
1197 TestPropertyTypes::Execute< Matrix >( Matrix::IDENTITY );
1198 TestPropertyTypes::Execute< Matrix3 >( Matrix3::IDENTITY );
1203 ///////////////////////////////////////////////////////////////////////////////