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 // Ensure constraint isn't called again if scene doesn't change
369 application.SendNotification();
370 application.Render();
372 DALI_TEST_EQUALS( calledCount, 0, TEST_LOCATION );
374 // Apply the clone constraint
375 constraintClone.Apply();
377 application.SendNotification();
378 application.Render();
380 // Should only be called once for the new constraint clone ONLY
381 DALI_TEST_EQUALS( calledCount, 1, TEST_LOCATION );
386 // Change the position of both actors
387 actor.SetPosition( 100.0f, 100.0f );
388 clone.SetPosition( 100.0f, 100.0f );
390 application.SendNotification();
391 application.Render();
393 // Functor should have been called twice
394 DALI_TEST_EQUALS( calledCount, 2, TEST_LOCATION );
399 int UtcDaliConstraintCloneN(void)
401 // Attempt to clone an uninitialised constraint should cause an assert
403 TestApplication application;
405 Constraint constraint;
409 Actor actor = Actor::New();
410 Constraint clone = constraint.Clone( actor );
411 DALI_TEST_CHECK( false );
415 DALI_TEST_CHECK( true );
421 namespace UtcDaliConstraintClone
423 void Function( Vector3& /* current */, const PropertyInputContainer& inputs )
425 DALI_TEST_EQUALS( inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION );
426 DALI_TEST_EQUALS( inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION );
427 DALI_TEST_EQUALS( inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION );
428 DALI_TEST_EQUALS( inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION );
430 } // namespace UtcDaliConstraintClone
432 int UtcDaliConstraintCloneCheckSourcesAndSetters(void)
434 // Ensure all sources, the tag and remove-action are cloned appropriately
436 TestApplication application;
438 Actor actor = Actor::New();
439 Actor clone = Actor::New();
441 Stage stage = Stage::GetCurrent();
445 application.SendNotification();
446 application.Render();
448 // Create a constraint, DON'T Apply it though
449 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintClone::Function );
450 constraint.AddSource( LocalSource( Actor::Property::SIZE ) );
451 constraint.AddSource( LocalSource( Actor::Property::ORIENTATION ) );
452 constraint.AddSource( LocalSource( Actor::Property::COLOR ) );
453 constraint.AddSource( LocalSource( Actor::Property::VISIBLE ) );
454 constraint.SetRemoveAction( Constraint::Discard );
455 constraint.SetTag( 123 );
457 // Clone the constraint & apply the clone
458 Constraint constraintClone = constraint.Clone( clone );
459 constraintClone.Apply();
461 application.SendNotification();
462 application.Render();
464 DALI_TEST_EQUALS( constraint.GetRemoveAction(), constraintClone.GetRemoveAction(), TEST_LOCATION );
465 DALI_TEST_EQUALS( constraint.GetTag(), constraintClone.GetTag(), TEST_LOCATION );
469 ///////////////////////////////////////////////////////////////////////////////
471 ///////////////////////////////////////////////////////////////////////////////
472 // Constraint::Constraint( const Constraint& )
473 // Constraint::operator=
474 ///////////////////////////////////////////////////////////////////////////////
475 int UtcDaliConstraintCopyAndAssignment(void)
477 // Ensure copy constructor & assignment operators work
479 TestApplication application;
481 Actor actor = Actor::New();
482 Stage::GetCurrent().Add( actor );
484 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
485 Constraint copied( constraint );
487 DALI_TEST_CHECK( constraint == copied );
488 DALI_TEST_CHECK( copied != assigned );
490 assigned = constraint;
491 DALI_TEST_CHECK( constraint == assigned );
495 ///////////////////////////////////////////////////////////////////////////////
497 ///////////////////////////////////////////////////////////////////////////////
498 // Constraint::DownCast
499 ///////////////////////////////////////////////////////////////////////////////
500 int UtcDaliConstraintDownCast(void)
502 // Ensure DownCast works as expected
504 TestApplication application;
506 Actor actor = Actor::New();
507 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
509 // Another BaseHandle type
510 Constraint downCast = Constraint::DownCast( actor );
511 DALI_TEST_CHECK( ! downCast );
514 downCast = Constraint::DownCast( constraint );
515 DALI_TEST_CHECK( downCast );
517 // An empty constraint
518 downCast = Constraint::DownCast( Constraint() );
519 DALI_TEST_CHECK( ! downCast );
523 ///////////////////////////////////////////////////////////////////////////////
525 ///////////////////////////////////////////////////////////////////////////////
526 // Constraint::GetTargetObject
527 ///////////////////////////////////////////////////////////////////////////////
528 int UtcDaliConstraintGetTargetObjectP(void)
530 TestApplication application;
532 Actor actor = Actor::New();
533 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
534 DALI_TEST_CHECK( constraint.GetTargetObject() == actor );
536 Actor actor2 = Actor::New();
537 DALI_TEST_CHECK( constraint.GetTargetObject() != actor2 );
542 int UtcDaliConstraintGetTargetObjectN(void)
544 // Attempt to retrieve from uninitialised constraint
546 TestApplication application;
548 Constraint constraint;
551 Handle handle = constraint.GetTargetObject();
552 DALI_TEST_CHECK( false ); // Should not reach here!
556 DALI_TEST_CHECK( true );
561 ///////////////////////////////////////////////////////////////////////////////
563 ///////////////////////////////////////////////////////////////////////////////
564 // Constraint::GetTargetProperty
565 ///////////////////////////////////////////////////////////////////////////////
566 int UtcDaliConstraintGetTargetPropertyP(void)
568 TestApplication application;
570 Actor actor = Actor::New();
571 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
572 DALI_TEST_EQUALS( constraint.GetTargetProperty(), Actor::Property::POSITION, TEST_LOCATION );
577 int UtcDaliConstraintGetTargetPropertyN(void)
579 // Attempt to retrieve from uninitialised constraint
581 TestApplication application;
583 Constraint constraint;
586 Property::Index propertyIndex = constraint.GetTargetProperty();
587 ( void )propertyIndex;
588 DALI_TEST_CHECK( false ); // Should not reach here!
592 DALI_TEST_CHECK( true );
597 ///////////////////////////////////////////////////////////////////////////////
599 ///////////////////////////////////////////////////////////////////////////////
600 // Constraint::SetTag
601 // Constraint::GetTag
602 ///////////////////////////////////////////////////////////////////////////////
603 int UtcDaliConstraintTagP(void)
605 TestApplication application;
607 Actor actor = Actor::New();
608 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
609 DALI_TEST_EQUALS( constraint.GetTag(), 0, TEST_LOCATION );
612 constraint.SetTag( tag );
613 DALI_TEST_EQUALS( constraint.GetTag(), tag, TEST_LOCATION );
618 int UtcDaliConstraintSetTagN(void)
620 // Attempt to set from uninitialised constraint
622 TestApplication application;
624 Constraint constraint;
627 constraint.SetTag( 123 );
628 DALI_TEST_CHECK( false ); // Should not reach here!
632 DALI_TEST_CHECK( true );
638 int UtcDaliConstraintGetTagN(void)
640 // Attempt to retrieve from uninitialised constraint
642 TestApplication application;
644 Constraint constraint;
647 int tag = constraint.GetTag();
649 DALI_TEST_CHECK( false ); // Should not reach here!
653 DALI_TEST_CHECK( true );
659 ///////////////////////////////////////////////////////////////////////////////
661 ///////////////////////////////////////////////////////////////////////////////
662 // Constraint::SetRemoveAction
663 // Constraint::GetRemoveAction
664 ///////////////////////////////////////////////////////////////////////////////
665 int UtcDaliConstraintRemoveActionP(void)
667 TestApplication application;
669 Actor actor = Actor::New();
670 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
671 DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::DEFAULT_REMOVE_ACTION, TEST_LOCATION );
673 constraint.SetRemoveAction( Constraint::Discard );
674 DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Discard, TEST_LOCATION );
676 constraint.SetRemoveAction( Constraint::Bake );
677 DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Bake, TEST_LOCATION );
682 int UtcDaliConstraintSetRemoveActionN(void)
684 // Attempt to set from uninitialised constraint
686 TestApplication application;
688 Constraint constraint;
691 constraint.SetRemoveAction( Constraint::Discard );
692 DALI_TEST_CHECK( false ); // Should not reach here!
696 DALI_TEST_CHECK( true );
702 int UtcDaliConstraintGetRemoveActionN(void)
704 // Attempt to retrieve from uninitialised constraint
706 TestApplication application;
708 Constraint constraint;
711 Constraint::RemoveAction removeAction = constraint.GetRemoveAction();
712 ( void )removeAction;
713 DALI_TEST_CHECK( false ); // Should not reach here!
717 DALI_TEST_CHECK( true );
723 int UtcDaliConstraintBakeRemoveAction(void)
725 // Ensure value is baked when constraint is removed
727 TestApplication application;
729 Actor actor = Actor::New();
730 Stage::GetCurrent().Add( actor );
732 application.SendNotification();
733 application.Render();
735 // Should not equal position by default
736 Vector3 position( 10.0f, 20.0f, 30.0f );
737 DALI_TEST_CHECK( actor.GetCurrentPosition() != position );
739 // Create a constraint that constrains to position
740 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) );
741 constraint.SetRemoveAction( Constraint::Bake );
744 application.SendNotification();
745 application.Render();
747 DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION );
749 // Remove the constraint, it should still be at position
752 application.SendNotification();
753 application.Render();
755 DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION );
760 int UtcDaliConstraintDiscardRemoveAction(void)
762 // Ensure value is baked when constraint is removed
764 TestApplication application;
766 Actor actor = Actor::New();
767 Stage::GetCurrent().Add( actor );
769 application.SendNotification();
770 application.Render();
772 // Get and store current position
773 Vector3 originalPosition = actor.GetCurrentPosition();
775 // Should not equal position by default
776 Vector3 position( 10.0f, 20.0f, 30.0f );
777 DALI_TEST_CHECK( actor.GetCurrentPosition() != position );
779 // Create a constraint that constrains to position
780 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) );
781 constraint.SetRemoveAction( Constraint::Discard );
784 application.SendNotification();
785 application.Render();
787 DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION );
789 // Remove the constraint, it should still be at position
792 application.SendNotification();
793 application.Render();
795 DALI_TEST_EQUALS( actor.GetCurrentPosition(), originalPosition, TEST_LOCATION );
796 DALI_TEST_CHECK( actor.GetCurrentPosition() != position );
801 ///////////////////////////////////////////////////////////////////////////////
803 ///////////////////////////////////////////////////////////////////////////////
805 // Constraint::Remove
806 ///////////////////////////////////////////////////////////////////////////////
807 int UtcDaliConstraintApplyRemove(void)
809 // Ensure constraint functors are called appropriately
811 TestApplication application;
812 bool functorCalled = false;
814 Actor actor = Actor::New();
815 Stage::GetCurrent().Add( actor );
817 application.SendNotification();
818 application.Render();
820 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
822 // Create a constraint and apply, functor should be called
823 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
826 application.SendNotification();
827 application.Render();
829 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
832 functorCalled = false;
834 // Remove the constraint, functor should not be called
837 application.SendNotification();
838 application.Render();
840 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
842 // Re-apply the constraint, functor should be called again
845 application.SendNotification();
846 application.Render();
848 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
853 int UtcDaliConstraintApplyBeforeAddedToStage(void)
855 // Constraint gets applied to an off-stage actor.
856 // Constraint should be automatically applied when the actor is added to the stage and not before
858 TestApplication application;
859 bool functorCalled = false;
861 // Create an actor and a constraint and apply, DON'T add to stage just yet
862 Actor actor = Actor::New();
863 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
866 application.SendNotification();
867 application.Render();
869 // Should NOT be called
870 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
872 // Add actor to stage
873 Stage::GetCurrent().Add( actor );
875 application.SendNotification();
876 application.Render();
878 // Should now be called
879 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
884 int UtcDaliConstraintApplyAndRemoveBeforeAddedToStage(void)
886 // Constraint gets applied to an off-stage actor, then gets removed before it's added to the stage
887 // Constraint should NOT be called at all
889 TestApplication application;
890 bool functorCalled = false;
892 // Create an actor and a constraint and apply, DON'T add to stage just yet
893 Actor actor = Actor::New();
894 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
897 application.SendNotification();
898 application.Render();
900 // Should NOT be called
901 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
903 // Remove the constraint
906 // Add actor to stage
907 Stage::GetCurrent().Add( actor );
909 application.SendNotification();
910 application.Render();
912 // Still should NOT be called
913 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
918 int UtcDaliConstraintApplyActorStagedUnstaged(void)
920 // Apply a constraint to an actor which is staged and unstaged.
921 // Functor should only be called while the actor is staged.
923 TestApplication application;
924 bool functorCalled = false;
926 // Create an actor and add to stage
927 Actor actor = Actor::New();
928 Stage stage = Stage::GetCurrent();
931 // Create a constraint and apply
932 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, BasicCalledFunctor< Vector3 >( functorCalled ) );
935 application.SendNotification();
936 application.Render();
938 // Constraint should be called
939 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
942 functorCalled = false;
944 // Remove actor from stage
945 stage.Remove( actor );
947 application.SendNotification();
948 application.Render();
950 // Constraint should NOT be called
951 DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
956 application.SendNotification();
957 application.Render();
959 // Constraint should be called
960 DALI_TEST_EQUALS( functorCalled, true, TEST_LOCATION );
965 int UtcDaliConstraintApplySeveralTimes(void)
967 // Apply the same constraint several times.
968 // Should not cause any problems (subsequent attempts should be no-ops)
970 TestApplication application;
973 // Create an actor and add to stage
974 Actor actor = Actor::New();
975 Stage stage = Stage::GetCurrent();
978 // Create a constraint and apply
979 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, CalledCountFunctor< Vector3 >( count ) );
983 constraint.Apply(); // no-op
985 application.SendNotification();
986 application.Render();
988 // Should only have been called once
989 DALI_TEST_EQUALS( count, 1, TEST_LOCATION );
995 constraint.Apply(); // no-op
997 application.SendNotification();
998 application.Render();
1000 // Constraint should not have been called as the input-properties (none) have not changed for the constraint
1001 DALI_TEST_EQUALS( count, 0, TEST_LOCATION );
1006 // Change the position property, apply again
1007 actor.SetPosition( 10.0f, 10.0f );
1010 application.SendNotification();
1011 application.Render();
1013 // Constraint should have been called once
1014 DALI_TEST_EQUALS( count, 1, TEST_LOCATION );
1019 ///////////////////////////////////////////////////////////////////////////////
1021 ///////////////////////////////////////////////////////////////////////////////
1022 // Constraint::AddSource
1023 ///////////////////////////////////////////////////////////////////////////////
1024 namespace UtcDaliConstraintAddSource
1026 void Function( Vector3& /* current */, const PropertyInputContainer& inputs )
1028 DALI_TEST_EQUALS( inputs.Size(), 4u, TEST_LOCATION );
1029 DALI_TEST_EQUALS( inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION );
1030 DALI_TEST_EQUALS( inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION );
1031 DALI_TEST_EQUALS( inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION );
1032 DALI_TEST_EQUALS( inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION );
1034 } // namespace UtcDaliConstraintAddSource
1036 int UtcDaliConstraintAddSourceP(void)
1038 // Ensure all sources are in the correct order in the functor
1040 TestApplication application;
1042 Actor actor = Actor::New();
1043 Stage::GetCurrent().Add( actor );
1045 // Create a constraint, add sources
1046 Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintAddSource::Function );
1047 constraint.AddSource( LocalSource( Actor::Property::SIZE ) );
1048 constraint.AddSource( LocalSource( Actor::Property::ORIENTATION ) );
1049 constraint.AddSource( LocalSource( Actor::Property::COLOR ) );
1050 constraint.AddSource( LocalSource( Actor::Property::VISIBLE ) );
1053 application.SendNotification();
1054 application.Render();
1059 int UtcDaliConstraintAddSourceN(void)
1061 // Attempt to set from uninitialised constraint
1063 TestApplication application;
1065 Constraint constraint;
1068 constraint.AddSource( LocalSource( Actor::Property::POSITION ) );
1069 DALI_TEST_CHECK( false ); // Should not reach here!
1073 DALI_TEST_CHECK( true );
1078 ///////////////////////////////////////////////////////////////////////////////
1080 ///////////////////////////////////////////////////////////////////////////////
1081 namespace TestChaining
1084 const Vector3 gFunction1Output( Vector3::ONE );
1085 void Function1( Vector3& current, const PropertyInputContainer& /* inputs */ )
1087 // current is original position
1088 DALI_TEST_EQUALS( current, Vector3::ZERO, TEST_LOCATION );
1089 current = gFunction1Output;
1092 const Vector3 gFunction2Output( 10.0f, 20.0f, 30.0f );
1093 void Function2( Vector3& current, const PropertyInputContainer& /* inputs */ )
1095 // current is output from Function1
1096 DALI_TEST_EQUALS( current, gFunction1Output, TEST_LOCATION );
1098 current = gFunction2Output;
1101 const Vector3 gFunction3Output( 10.0f, 20.0f, 30.0f );
1102 void Function3( Vector3& current, const PropertyInputContainer& /* inputs */ )
1104 // current is output from Function2
1105 DALI_TEST_EQUALS( current, gFunction2Output, TEST_LOCATION );
1107 current = gFunction3Output;
1110 const Vector3 gFunction4Output( 10.0f, 20.0f, 30.0f );
1111 void Function4( Vector3& current, const PropertyInputContainer& /* inputs */ )
1113 // current is output from Function3
1114 DALI_TEST_EQUALS( current, gFunction3Output, TEST_LOCATION );
1116 current = gFunction4Output;
1119 void Function5( Vector3& current, const PropertyInputContainer& /* inputs */ )
1121 // current is output from Function4
1122 DALI_TEST_EQUALS( current, gFunction4Output, TEST_LOCATION );
1124 current = Vector3::ZERO;
1127 } // namespace TestChaining
1129 int UtcDaliConstraintChaining(void)
1131 // Apply several constraints to the same property and ensure the functors are called in the correct order.
1133 TestApplication application;
1135 Actor actor = Actor::New();
1136 Stage::GetCurrent().Add( actor );
1138 Constraint constraint1 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function1 );
1139 Constraint constraint2 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function2 );
1140 Constraint constraint3 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function3 );
1141 Constraint constraint4 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function4 );
1142 Constraint constraint5 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function5 );
1144 constraint1.Apply();
1145 constraint2.Apply();
1146 constraint3.Apply();
1147 constraint4.Apply();
1148 constraint5.Apply();
1150 application.SendNotification();
1151 application.Render();
1155 ///////////////////////////////////////////////////////////////////////////////