2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.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 ///////////////////////////////////////////////////////////////////////////////
42 * A function to use for a constraint, no data collected.
45 void BasicFunction(T& /* current */, const PropertyInputContainer& /* inputs */)
50 * A functor which sets a given boolean when the functor is called.
53 struct BasicCalledFunctor
55 BasicCalledFunctor(bool& functorCalled)
56 : mCalled(functorCalled)
60 void operator()(T& /* current */, const PropertyInputContainer& /* inputs */)
69 * A functor which increments a given integer when the functor is called.
72 struct CalledCountFunctor
74 CalledCountFunctor(int& callCount)
75 : mCallCount(callCount)
79 void operator()(T& /* current */, const PropertyInputContainer& /* inputs */)
88 * A functor which sets the given value as the value required when the functor is called.
91 struct SetValueFunctor
93 SetValueFunctor(const T& value)
98 void operator()(T& current, const PropertyInputContainer& /* inputs */)
106 } // unnamed namespace
107 ///////////////////////////////////////////////////////////////////////////////
109 ///////////////////////////////////////////////////////////////////////////////
113 // void( *function )( T&, const PropertyInputContainer& ) )
114 ///////////////////////////////////////////////////////////////////////////////
115 namespace UtcDaliConstraintNewFunction
117 bool gConstraintFunctionCalled = false;
118 void ConstraintFunction(Vector3& /* current */, const PropertyInputContainer& /* inputs */)
120 gConstraintFunctionCalled = true;
122 } // namespace UtcDaliConstraintNewFunction
124 int UtcDaliConstraintNewFunctionP(void)
126 // Ensure that we can create a constraint using a C function and that it is called.
128 TestApplication application;
129 UtcDaliConstraintNewFunction::gConstraintFunctionCalled = false;
131 Actor actor = Actor::New();
132 application.GetScene().Add(actor);
134 application.SendNotification();
135 application.Render();
137 DALI_TEST_EQUALS(UtcDaliConstraintNewFunction::gConstraintFunctionCalled, false, TEST_LOCATION);
140 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &UtcDaliConstraintNewFunction::ConstraintFunction);
141 DALI_TEST_CHECK(constraint);
144 application.SendNotification();
145 application.Render();
147 DALI_TEST_EQUALS(UtcDaliConstraintNewFunction::gConstraintFunctionCalled, true, TEST_LOCATION);
152 int UtcDaliConstraintNewFunctionN(void)
154 // Create a constraint with an uninitialised handle
156 TestApplication application;
158 // Add a constraint with an uninitialised handle
161 Constraint constraint = Constraint::New<Vector3>(Actor(), Actor::Property::POSITION, &UtcDaliConstraintNewFunction::ConstraintFunction);
162 DALI_TEST_CHECK(false); // Should not reach here
166 DALI_TEST_CHECK(true); // Should assert!
172 // helper for next test
173 void StringConstraintFunction(std::string& /* current */, const PropertyInputContainer& /* inputs */)
177 int UtcDaliConstraintNewFunctionNonConstrainableTypeN(void)
179 // Ensure that we can create a constraint using a C function and that it is called.
181 TestApplication application;
182 UtcDaliConstraintNewFunction::gConstraintFunctionCalled = false;
184 Actor actor = Actor::New();
185 application.GetScene().Add(actor);
187 application.SendNotification();
188 application.Render();
193 Constraint constraint = Constraint::New<std::string>(actor, Actor::Property::COLOR_MODE, &StringConstraintFunction);
194 DALI_TEST_CHECK(constraint);
196 tet_result(TET_FAIL);
198 catch(Dali::DaliException& e)
200 DALI_TEST_ASSERT(e, "Property not constrainable", TEST_LOCATION);
206 ///////////////////////////////////////////////////////////////////////////////
208 ///////////////////////////////////////////////////////////////////////////////
213 ///////////////////////////////////////////////////////////////////////////////
214 int UtcDaliConstraintNewFunctorP(void)
216 // Ensure that we can create a constraint using a functor and that it is called.
218 TestApplication application;
219 bool functorCalled = false;
221 Actor actor = Actor::New();
222 application.GetScene().Add(actor);
224 application.SendNotification();
225 application.Render();
227 DALI_TEST_EQUALS(functorCalled, false, TEST_LOCATION);
230 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, BasicCalledFunctor<Vector3>(functorCalled));
231 DALI_TEST_CHECK(constraint);
234 application.SendNotification();
235 application.Render();
237 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
242 int UtcDaliConstraintNewFunctorN(void)
244 // Create a constraint with an uninitialised handle
246 TestApplication application;
247 bool functorCalled = false;
249 // Add a constraint with an uninitialised handle
252 Constraint constraint = Constraint::New<Vector3>(Actor(), Actor::Property::POSITION, BasicCalledFunctor<Vector3>(functorCalled));
253 DALI_TEST_CHECK(false); // Should not reach here
257 DALI_TEST_CHECK(true); // Should assert!
262 ///////////////////////////////////////////////////////////////////////////////
264 ///////////////////////////////////////////////////////////////////////////////
269 // void ( T::*memberFunction ) ( P&, const PropertyInputContainer& ) )
270 ///////////////////////////////////////////////////////////////////////////////
271 namespace UtcDaliConstraintNewFunctorMember
275 Functor(bool& positionCalled, bool& scaleCalled)
276 : mPositionCalled(positionCalled),
277 mScaleCalled(scaleCalled)
281 void Position(Vector3& /* current */, const PropertyInputContainer& /* inputs */)
283 mPositionCalled = true;
286 void Scale(Vector3& /* current */, const PropertyInputContainer& /* inputs */)
291 bool& mPositionCalled;
294 } // namespace UtcDaliConstraintNewFunctorMember
296 int UtcDaliConstraintNewFunctorMemberP(void)
298 // Ensure that we can create a constraint using a functor and that it is called.
300 TestApplication application;
301 bool positionFunctorCalled = false;
302 bool sizeFunctorCalled = false;
304 Actor actor = Actor::New();
305 application.GetScene().Add(actor);
307 application.SendNotification();
308 application.Render();
310 DALI_TEST_EQUALS(positionFunctorCalled, false, TEST_LOCATION);
311 DALI_TEST_EQUALS(sizeFunctorCalled, false, TEST_LOCATION);
313 // Add a constraint that calls Functor::Position
314 Constraint constraint = Constraint::New<Vector3>(
316 Actor::Property::POSITION,
317 UtcDaliConstraintNewFunctorMember::Functor(positionFunctorCalled, sizeFunctorCalled),
318 &UtcDaliConstraintNewFunctorMember::Functor::Position);
319 DALI_TEST_CHECK(constraint);
322 application.SendNotification();
323 application.Render();
325 DALI_TEST_EQUALS(positionFunctorCalled, true, TEST_LOCATION);
326 DALI_TEST_EQUALS(sizeFunctorCalled, false, TEST_LOCATION);
328 // Add another constraint that calls Functor::Size
329 Constraint constraint2 = Constraint::New<Vector3>(
331 Actor::Property::SCALE,
332 UtcDaliConstraintNewFunctorMember::Functor(positionFunctorCalled, sizeFunctorCalled),
333 &UtcDaliConstraintNewFunctorMember::Functor::Scale);
334 DALI_TEST_CHECK(constraint2);
337 application.SendNotification();
338 application.Render();
340 DALI_TEST_EQUALS(positionFunctorCalled, true, TEST_LOCATION);
341 DALI_TEST_EQUALS(sizeFunctorCalled, true, TEST_LOCATION);
346 int UtcDaliConstraintNewFunctorMemberN(void)
348 // Create a constraint with an uninitialised handle
350 TestApplication application;
351 bool positionFunctorCalled = false;
352 bool sizeFunctorCalled = false;
354 // Add a constraint with an uninitialised handle
357 Constraint constraint = Constraint::New<Vector3>(
359 Actor::Property::POSITION,
360 UtcDaliConstraintNewFunctorMember::Functor(positionFunctorCalled, sizeFunctorCalled),
361 &UtcDaliConstraintNewFunctorMember::Functor::Position);
362 DALI_TEST_CHECK(false); // Should not reach here
364 catch(Dali::DaliException& e)
366 DALI_TEST_CHECK(true); // Should assert!
371 ///////////////////////////////////////////////////////////////////////////////
373 ///////////////////////////////////////////////////////////////////////////////
375 ///////////////////////////////////////////////////////////////////////////////
376 int UtcDaliConstraintCloneP(void)
378 // Ensure we can clone for another actor and it's called appropriately
380 TestApplication application;
383 Actor actor = Actor::New();
384 Actor clone = Actor::New();
386 Integration::Scene stage = application.GetScene();
390 application.SendNotification();
391 application.Render();
393 DALI_TEST_EQUALS(calledCount, 0, TEST_LOCATION);
395 // Add a constraint to actor
396 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, CalledCountFunctor<Vector3>(calledCount));
397 DALI_TEST_CHECK(constraint);
400 // Create a clone but don't apply
401 Constraint constraintClone = constraint.Clone(clone);
403 application.SendNotification();
404 application.Render();
406 DALI_TEST_EQUALS(calledCount, 1, TEST_LOCATION);
411 application.SendNotification();
412 application.Render();
414 DALI_TEST_EQUALS(calledCount, 1, TEST_LOCATION);
416 // Apply the clone constraint
417 constraintClone.Apply();
419 application.SendNotification();
420 application.Render();
422 // Should be called once for the new constraint clone and once for the original constraint
423 DALI_TEST_EQUALS(calledCount, 3, TEST_LOCATION);
428 // Change the position of both actors
429 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
430 clone.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
432 application.SendNotification();
433 application.Render();
435 // Functor should have been called twice
436 DALI_TEST_EQUALS(calledCount, 2, TEST_LOCATION);
441 int UtcDaliConstraintCloneN(void)
443 // Attempt to clone an uninitialised constraint should cause an assert
445 TestApplication application;
447 Constraint constraint;
451 Actor actor = Actor::New();
452 Constraint clone = constraint.Clone(actor);
453 DALI_TEST_CHECK(false);
457 DALI_TEST_CHECK(true);
463 namespace UtcDaliConstraintClone
465 void Function(Vector3& /* current */, const PropertyInputContainer& inputs)
467 DALI_TEST_EQUALS(inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION);
468 DALI_TEST_EQUALS(inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION);
469 DALI_TEST_EQUALS(inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION);
470 DALI_TEST_EQUALS(inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION);
472 } // namespace UtcDaliConstraintClone
474 int UtcDaliConstraintCloneCheckSourcesAndSetters(void)
476 // Ensure all sources, the tag and remove-action are cloned appropriately
478 TestApplication application;
480 Actor actor = Actor::New();
481 Actor clone = Actor::New();
483 Integration::Scene stage = application.GetScene();
487 application.SendNotification();
488 application.Render();
490 // Create a constraint, DON'T Apply it though
491 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &UtcDaliConstraintClone::Function);
492 constraint.AddSource(LocalSource(Actor::Property::SIZE));
493 constraint.AddSource(LocalSource(Actor::Property::ORIENTATION));
494 constraint.AddSource(LocalSource(Actor::Property::COLOR));
495 constraint.AddSource(LocalSource(Actor::Property::VISIBLE));
496 constraint.SetRemoveAction(Constraint::DISCARD);
497 constraint.SetTag(123);
499 // Clone the constraint & apply the clone
500 Constraint constraintClone = constraint.Clone(clone);
501 constraintClone.Apply();
503 application.SendNotification();
504 application.Render();
506 DALI_TEST_EQUALS(constraint.GetRemoveAction(), constraintClone.GetRemoveAction(), TEST_LOCATION);
507 DALI_TEST_EQUALS(constraint.GetTag(), constraintClone.GetTag(), TEST_LOCATION);
511 ///////////////////////////////////////////////////////////////////////////////
513 ///////////////////////////////////////////////////////////////////////////////
514 // Constraint::Constraint( const Constraint& )
515 // Constraint::operator=
516 ///////////////////////////////////////////////////////////////////////////////
517 int UtcDaliConstraintCopyAndAssignment(void)
519 // Ensure copy constructor & assignment operators work
521 TestApplication application;
523 Actor actor = Actor::New();
524 application.GetScene().Add(actor);
526 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &BasicFunction<Vector3>);
527 Constraint copied(constraint);
529 DALI_TEST_CHECK(constraint == copied);
530 DALI_TEST_CHECK(copied != assigned);
532 assigned = constraint;
533 DALI_TEST_CHECK(constraint == assigned);
537 ///////////////////////////////////////////////////////////////////////////////
539 int UtcDaliConstraintMoveConstructor(void)
541 // Ensure copy constructor & assignment operators work
543 TestApplication application;
545 Actor actor = Actor::New();
546 application.GetScene().Add(actor);
548 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &BasicFunction<Vector3>);
549 DALI_TEST_CHECK(constraint);
550 DALI_TEST_EQUALS(1, constraint.GetBaseObject().ReferenceCount(), TEST_LOCATION);
551 DALI_TEST_CHECK(constraint.GetTargetObject() == actor);
553 Constraint moved = std::move(constraint);
554 DALI_TEST_CHECK(moved);
555 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
556 DALI_TEST_CHECK(moved.GetTargetObject() == actor);
557 DALI_TEST_CHECK(!constraint);
562 int UtcDaliConstraintMoveAssignment(void)
564 // Ensure copy constructor & assignment operators work
566 TestApplication application;
568 Actor actor = Actor::New();
569 application.GetScene().Add(actor);
571 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &BasicFunction<Vector3>);
572 DALI_TEST_CHECK(constraint);
573 DALI_TEST_EQUALS(1, constraint.GetBaseObject().ReferenceCount(), TEST_LOCATION);
574 DALI_TEST_CHECK(constraint.GetTargetObject() == actor);
577 moved = std::move(constraint);
578 DALI_TEST_CHECK(moved);
579 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
580 DALI_TEST_CHECK(moved.GetTargetObject() == actor);
581 DALI_TEST_CHECK(!constraint);
586 ///////////////////////////////////////////////////////////////////////////////
587 // Constraint::DownCast
588 ///////////////////////////////////////////////////////////////////////////////
589 int UtcDaliConstraintDownCast(void)
591 // Ensure DownCast works as expected
593 TestApplication application;
595 Actor actor = Actor::New();
596 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &BasicFunction<Vector3>);
598 // Another BaseHandle type
599 Constraint downCast = Constraint::DownCast(actor);
600 DALI_TEST_CHECK(!downCast);
603 downCast = Constraint::DownCast(constraint);
604 DALI_TEST_CHECK(downCast);
606 // An empty constraint
607 downCast = Constraint::DownCast(Constraint());
608 DALI_TEST_CHECK(!downCast);
612 ///////////////////////////////////////////////////////////////////////////////
614 ///////////////////////////////////////////////////////////////////////////////
615 // Constraint::GetTargetObject
616 ///////////////////////////////////////////////////////////////////////////////
617 int UtcDaliConstraintGetTargetObjectP(void)
619 TestApplication application;
621 Actor actor = Actor::New();
622 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &BasicFunction<Vector3>);
623 DALI_TEST_CHECK(constraint.GetTargetObject() == actor);
625 Actor actor2 = Actor::New();
626 DALI_TEST_CHECK(constraint.GetTargetObject() != actor2);
631 int UtcDaliConstraintGetTargetObjectN(void)
633 // Attempt to retrieve from uninitialised constraint
635 TestApplication application;
637 Constraint constraint;
640 Handle handle = constraint.GetTargetObject();
641 DALI_TEST_CHECK(false); // Should not reach here!
645 DALI_TEST_CHECK(true);
650 ///////////////////////////////////////////////////////////////////////////////
652 ///////////////////////////////////////////////////////////////////////////////
653 // Constraint::GetTargetProperty
654 ///////////////////////////////////////////////////////////////////////////////
655 int UtcDaliConstraintGetTargetPropertyP(void)
657 TestApplication application;
659 Actor actor = Actor::New();
660 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &BasicFunction<Vector3>);
661 DALI_TEST_EQUALS(constraint.GetTargetProperty(), (Property::Index)Actor::Property::POSITION, TEST_LOCATION);
666 int UtcDaliConstraintGetTargetPropertyN(void)
668 // Attempt to retrieve from uninitialised constraint
670 TestApplication application;
672 Constraint constraint;
675 Property::Index propertyIndex = constraint.GetTargetProperty();
677 DALI_TEST_CHECK(false); // Should not reach here!
681 DALI_TEST_CHECK(true);
686 ///////////////////////////////////////////////////////////////////////////////
688 ///////////////////////////////////////////////////////////////////////////////
689 // Constraint::SetTag
690 // Constraint::GetTag
691 ///////////////////////////////////////////////////////////////////////////////
692 int UtcDaliConstraintTagP(void)
694 TestApplication application;
696 Actor actor = Actor::New();
697 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &BasicFunction<Vector3>);
698 DALI_TEST_EQUALS(constraint.GetTag(), 0u, TEST_LOCATION);
700 const unsigned int tag = 123;
701 constraint.SetTag(tag);
702 DALI_TEST_EQUALS(constraint.GetTag(), tag, TEST_LOCATION);
707 int UtcDaliConstraintSetTagN(void)
709 // Attempt to set from uninitialised constraint
711 TestApplication application;
713 Constraint constraint;
716 constraint.SetTag(123);
717 DALI_TEST_CHECK(false); // Should not reach here!
721 DALI_TEST_CHECK(true);
727 int UtcDaliConstraintGetTagN(void)
729 // Attempt to retrieve from uninitialised constraint
731 TestApplication application;
733 Constraint constraint;
736 int tag = constraint.GetTag();
738 DALI_TEST_CHECK(false); // Should not reach here!
742 DALI_TEST_CHECK(true);
748 ///////////////////////////////////////////////////////////////////////////////
750 ///////////////////////////////////////////////////////////////////////////////
751 // Constraint::SetRemoveAction
752 // Constraint::GetRemoveAction
753 ///////////////////////////////////////////////////////////////////////////////
754 int UtcDaliConstraintRemoveActionP(void)
756 TestApplication application;
758 Actor actor = Actor::New();
759 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &BasicFunction<Vector3>);
760 DALI_TEST_EQUALS(constraint.GetRemoveAction(), Constraint::DEFAULT_REMOVE_ACTION, TEST_LOCATION);
762 constraint.SetRemoveAction(Constraint::DISCARD);
763 DALI_TEST_EQUALS(constraint.GetRemoveAction(), Constraint::DISCARD, TEST_LOCATION);
765 constraint.SetRemoveAction(Constraint::BAKE);
766 DALI_TEST_EQUALS(constraint.GetRemoveAction(), Constraint::BAKE, TEST_LOCATION);
771 int UtcDaliConstraintSetRemoveActionN(void)
773 // Attempt to set from uninitialised constraint
775 TestApplication application;
777 Constraint constraint;
780 constraint.SetRemoveAction(Constraint::DISCARD);
781 DALI_TEST_CHECK(false); // Should not reach here!
785 DALI_TEST_CHECK(true);
791 int UtcDaliConstraintGetRemoveActionN(void)
793 // Attempt to retrieve from uninitialised constraint
795 TestApplication application;
797 Constraint constraint;
800 Constraint::RemoveAction removeAction = constraint.GetRemoveAction();
802 DALI_TEST_CHECK(false); // Should not reach here!
806 DALI_TEST_CHECK(true);
812 int UtcDaliConstraintBakeRemoveAction(void)
814 // Ensure value is baked when constraint is removed
816 TestApplication application;
818 Actor actor = Actor::New();
819 application.GetScene().Add(actor);
821 application.SendNotification();
822 application.Render();
824 // Should not equal position by default
825 Vector3 position(10.0f, 20.0f, 30.0f);
826 DALI_TEST_CHECK(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION) != position);
828 // Create a constraint that constrains to position
829 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, SetValueFunctor<Vector3>(position));
830 constraint.SetRemoveAction(Constraint::BAKE);
833 application.SendNotification();
834 application.Render();
836 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), position, TEST_LOCATION);
838 // Remove the constraint, it should still be at position
841 application.SendNotification();
842 application.Render();
844 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), position, TEST_LOCATION);
849 int UtcDaliConstraintDiscardRemoveAction(void)
851 // Ensure value is baked when constraint is removed
853 TestApplication application;
855 Actor actor = Actor::New();
856 application.GetScene().Add(actor);
858 application.SendNotification();
859 application.Render();
861 // Get and store current position
862 Vector3 originalPosition = actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION);
864 // Should not equal position by default
865 Vector3 position(10.0f, 20.0f, 30.0f);
866 DALI_TEST_CHECK(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION) != position);
868 // Create a constraint that constrains to position
869 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, SetValueFunctor<Vector3>(position));
870 constraint.SetRemoveAction(Constraint::DISCARD);
873 application.SendNotification();
874 application.Render();
876 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), position, TEST_LOCATION);
878 // Remove the constraint, it should still be at position
881 application.SendNotification();
882 application.Render();
884 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), originalPosition, TEST_LOCATION);
885 DALI_TEST_CHECK(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION) != position);
890 ///////////////////////////////////////////////////////////////////////////////
892 ///////////////////////////////////////////////////////////////////////////////
894 // Constraint::Remove
895 ///////////////////////////////////////////////////////////////////////////////
896 int UtcDaliConstraintApplyRemove(void)
898 // Ensure constraint functors are called appropriately
900 TestApplication application;
901 bool functorCalled = false;
903 Actor actor = Actor::New();
904 application.GetScene().Add(actor);
906 application.SendNotification();
907 application.Render();
909 DALI_TEST_EQUALS(functorCalled, false, TEST_LOCATION);
911 // Create a constraint and apply, functor should be called
912 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, BasicCalledFunctor<Vector3>(functorCalled));
915 application.SendNotification();
916 application.Render();
918 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
921 functorCalled = false;
923 // Remove the constraint, functor should not be called
926 application.SendNotification();
927 application.Render();
929 DALI_TEST_EQUALS(functorCalled, false, TEST_LOCATION);
931 // Re-apply the constraint, functor should be called again
934 application.SendNotification();
935 application.Render();
937 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
942 int UtcDaliConstraintApplyBeforeAddedToStage(void)
944 // Constraint gets applied to an off-stage actor.
945 // Constraint should be automatically applied when the actor is added to the stage and not before
947 TestApplication application;
948 bool functorCalled = false;
950 // Create an actor and a constraint and apply, DON'T add to stage just yet
951 Actor actor = Actor::New();
952 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, BasicCalledFunctor<Vector3>(functorCalled));
955 application.SendNotification();
956 application.Render();
958 // Should NOT be called
959 DALI_TEST_EQUALS(functorCalled, false, TEST_LOCATION);
961 // Add actor to stage
962 application.GetScene().Add(actor);
964 application.SendNotification();
965 application.Render();
967 // Should now be called
968 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
973 int UtcDaliConstraintApplyAndRemoveBeforeAddedToStage(void)
975 // Constraint gets applied to an off-stage actor, then gets removed before it's added to the stage
976 // Constraint should NOT be called at all
978 TestApplication application;
979 bool functorCalled = false;
981 // Create an actor and a constraint and apply, DON'T add to stage just yet
982 Actor actor = Actor::New();
983 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, BasicCalledFunctor<Vector3>(functorCalled));
986 application.SendNotification();
987 application.Render();
989 // Should NOT be called
990 DALI_TEST_EQUALS(functorCalled, false, TEST_LOCATION);
992 // Remove the constraint
995 // Add actor to stage
996 application.GetScene().Add(actor);
998 application.SendNotification();
999 application.Render();
1001 // Still should NOT be called
1002 DALI_TEST_EQUALS(functorCalled, false, TEST_LOCATION);
1007 int UtcDaliConstraintApplyActorStagedUnstaged(void)
1009 // Apply a constraint to an actor which is staged and unstaged.
1010 // Functor should only be called while the actor is staged.
1012 TestApplication application;
1013 bool functorCalled = false;
1015 // Create an actor and add to stage
1016 Actor actor = Actor::New();
1017 Integration::Scene stage = application.GetScene();
1020 // Create a constraint and apply
1021 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, BasicCalledFunctor<Vector3>(functorCalled));
1024 application.SendNotification();
1025 application.Render();
1027 // Constraint should be called
1028 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1031 functorCalled = false;
1033 // Remove actor from stage
1034 stage.Remove(actor);
1036 application.SendNotification();
1037 application.Render();
1039 // Constraint should NOT be called
1040 DALI_TEST_EQUALS(functorCalled, false, TEST_LOCATION);
1045 application.SendNotification();
1046 application.Render();
1048 // Constraint should be called
1049 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1054 int UtcDaliConstraintApplySeveralTimes(void)
1056 // Apply the same constraint several times.
1057 // Should not cause any problems (subsequent attempts should be no-ops)
1059 TestApplication application;
1062 // Create an actor and add to stage
1063 Actor actor = Actor::New();
1064 Integration::Scene stage = application.GetScene();
1067 // Create a constraint and apply
1068 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, CalledCountFunctor<Vector3>(count));
1072 constraint.Apply(); // no-op
1074 application.SendNotification();
1075 application.Render();
1077 // Should only have been called once
1078 DALI_TEST_EQUALS(count, 1, TEST_LOCATION);
1084 constraint.Apply(); // no-op
1086 application.SendNotification();
1087 application.Render();
1089 DALI_TEST_EQUALS(count, 1, TEST_LOCATION);
1094 // Change the position property, apply again
1095 actor.SetProperty(Actor::Property::POSITION, Vector2(10.0f, 10.0f));
1098 application.SendNotification();
1099 application.Render();
1101 // Constraint should have been called once
1102 DALI_TEST_EQUALS(count, 1, TEST_LOCATION);
1107 ///////////////////////////////////////////////////////////////////////////////
1109 ///////////////////////////////////////////////////////////////////////////////
1110 // Constraint::AddSource
1111 ///////////////////////////////////////////////////////////////////////////////
1112 namespace UtcDaliConstraintAddSource
1114 void Function(Vector3& /* current */, const PropertyInputContainer& inputs)
1116 DALI_TEST_EQUALS(inputs.Size(), 4u, TEST_LOCATION);
1117 DALI_TEST_EQUALS(inputs[0]->GetType(), Property::VECTOR3, TEST_LOCATION);
1118 DALI_TEST_EQUALS(inputs[1]->GetType(), Property::ROTATION, TEST_LOCATION);
1119 DALI_TEST_EQUALS(inputs[2]->GetType(), Property::VECTOR4, TEST_LOCATION);
1120 DALI_TEST_EQUALS(inputs[3]->GetType(), Property::BOOLEAN, TEST_LOCATION);
1122 } // namespace UtcDaliConstraintAddSource
1124 int UtcDaliConstraintAddSourceP(void)
1126 // Ensure all sources are in the correct order in the functor
1128 TestApplication application;
1130 Actor actor = Actor::New();
1131 application.GetScene().Add(actor);
1133 // Create a constraint, add sources
1134 Constraint constraint = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &UtcDaliConstraintAddSource::Function);
1135 constraint.AddSource(LocalSource(Actor::Property::SIZE));
1136 constraint.AddSource(LocalSource(Actor::Property::ORIENTATION));
1137 constraint.AddSource(LocalSource(Actor::Property::COLOR));
1138 constraint.AddSource(LocalSource(Actor::Property::VISIBLE));
1141 application.SendNotification();
1142 application.Render();
1147 int UtcDaliConstraintAddSourceN(void)
1149 // Attempt to set from uninitialised constraint
1151 TestApplication application;
1153 Constraint constraint;
1156 constraint.AddSource(LocalSource(Actor::Property::POSITION));
1157 DALI_TEST_CHECK(false); // Should not reach here!
1161 DALI_TEST_CHECK(true);
1166 ///////////////////////////////////////////////////////////////////////////////
1168 ///////////////////////////////////////////////////////////////////////////////
1169 namespace TestChaining
1171 const Vector3 gFunction1Output(Vector3::ONE);
1172 void Function1(Vector3& current, const PropertyInputContainer& /* inputs */)
1174 // current is original position
1175 DALI_TEST_EQUALS(current, Vector3::ZERO, TEST_LOCATION);
1176 current = gFunction1Output;
1179 const Vector3 gFunction2Output(10.0f, 20.0f, 30.0f);
1180 void Function2(Vector3& current, const PropertyInputContainer& /* inputs */)
1182 // current is output from Function1
1183 DALI_TEST_EQUALS(current, gFunction1Output, TEST_LOCATION);
1185 current = gFunction2Output;
1188 const Vector3 gFunction3Output(10.0f, 20.0f, 30.0f);
1189 void Function3(Vector3& current, const PropertyInputContainer& /* inputs */)
1191 // current is output from Function2
1192 DALI_TEST_EQUALS(current, gFunction2Output, TEST_LOCATION);
1194 current = gFunction3Output;
1197 const Vector3 gFunction4Output(10.0f, 20.0f, 30.0f);
1198 void Function4(Vector3& current, const PropertyInputContainer& /* inputs */)
1200 // current is output from Function3
1201 DALI_TEST_EQUALS(current, gFunction3Output, TEST_LOCATION);
1203 current = gFunction4Output;
1206 void Function5(Vector3& current, const PropertyInputContainer& /* inputs */)
1208 // current is output from Function4
1209 DALI_TEST_EQUALS(current, gFunction4Output, TEST_LOCATION);
1211 current = Vector3::ZERO;
1214 } // namespace TestChaining
1216 int UtcDaliConstraintChaining(void)
1218 // Apply several constraints to the same property and ensure the functors are called in the correct order.
1220 TestApplication application;
1222 Actor actor = Actor::New();
1223 application.GetScene().Add(actor);
1225 Constraint constraint1 = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &TestChaining::Function1);
1226 Constraint constraint2 = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &TestChaining::Function2);
1227 Constraint constraint3 = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &TestChaining::Function3);
1228 Constraint constraint4 = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &TestChaining::Function4);
1229 Constraint constraint5 = Constraint::New<Vector3>(actor, Actor::Property::POSITION, &TestChaining::Function5);
1231 constraint1.Apply();
1232 constraint2.Apply();
1233 constraint3.Apply();
1234 constraint4.Apply();
1235 constraint5.Apply();
1237 application.SendNotification();
1238 application.Render();
1242 ///////////////////////////////////////////////////////////////////////////////
1244 ///////////////////////////////////////////////////////////////////////////////
1245 namespace TestPropertyTypes
1247 template<typename T>
1248 void Execute(T value)
1250 TestApplication application;
1251 bool functorCalled = false;
1253 Actor actor = Actor::New();
1254 Property::Index index = actor.RegisterProperty("TEMP_PROPERTY_NAME", value);
1256 application.GetScene().Add(actor);
1258 application.SendNotification();
1259 application.Render();
1261 DALI_TEST_EQUALS(functorCalled, false, TEST_LOCATION);
1264 Constraint constraint = Constraint::New<T>(actor, index, BasicCalledFunctor<T>(functorCalled));
1265 DALI_TEST_CHECK(constraint);
1268 application.SendNotification();
1269 application.Render();
1271 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1273 } // namespace TestPropertyTypes
1275 int UtcDaliConstraintTestPropertyTypesP(void)
1277 // Ensure we can use a constraint functor with all supported property types
1279 TestPropertyTypes::Execute<bool>(false);
1280 TestPropertyTypes::Execute<int>(0);
1281 TestPropertyTypes::Execute<float>(0.0f);
1282 TestPropertyTypes::Execute<Vector2>(Vector2::ZERO);
1283 TestPropertyTypes::Execute<Vector3>(Vector3::ZERO);
1284 TestPropertyTypes::Execute<Vector4>(Vector4::ZERO);
1285 TestPropertyTypes::Execute<Quaternion>(Quaternion::IDENTITY);
1286 TestPropertyTypes::Execute<Matrix>(Matrix::IDENTITY);
1287 TestPropertyTypes::Execute<Matrix3>(Matrix3::IDENTITY);
1292 ///////////////////////////////////////////////////////////////////////////////
1294 ///////////////////////////////////////////////////////////////////////////////
1297 void SetHalfOpacity(Vector4& current, const PropertyInputContainer& inputs)
1301 } // unnamed namespace
1303 int UtcDaliConstraintEnsureResetterAppliedOnSceneRemoval(void)
1305 // Ensure BOTH double-buffered values of our color property is reset when a constraint is applied to it.
1307 TestApplication application;
1309 Actor actor = Actor::New();
1310 application.GetScene().Add(actor);
1312 // Check initial value is fully opaque
1313 application.SendNotification();
1314 application.Render();
1315 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 1.0f, TEST_LOCATION);
1317 // Create a constraint whose value is discarded when it is removed
1318 Constraint constraint = Constraint::New<Vector4>(actor, Actor::Property::COLOR, SetHalfOpacity);
1319 constraint.SetRemoveAction(Constraint::RemoveAction::DISCARD);
1322 // Check value after one render, it should be constrained
1323 application.SendNotification();
1324 application.Render();
1325 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 0.5f, TEST_LOCATION);
1327 // Render another frame, ensure the other value has also been updated
1328 application.SendNotification();
1329 application.Render();
1330 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 0.5f, TEST_LOCATION);
1332 // Remove the actor from the stage and delete the constraint
1334 constraint.Remove();
1337 // Check value while off-stage, it should be fully opaque
1338 application.SendNotification();
1339 application.Render();
1340 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 1.0f, TEST_LOCATION);
1342 // Add the actor back to the stage and check the value, it should be fully opaque again
1343 application.GetScene().Add(actor);
1345 // Check value when back on-stage, it should be fully opaque as the constraint is no longer applied to it.
1346 application.SendNotification();
1347 application.Render();
1348 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 1.0f, TEST_LOCATION);
1350 // Render for another frame to ensure both buffers have the correct value
1351 application.SendNotification();
1352 application.Render();
1353 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 1.0f, TEST_LOCATION);
1358 int UtcDaliConstraintOnActorAddedAndRemoved(void)
1360 // Ensure adding and removing an actor from stage with a constraint still has it applied when it is re-added back to the stage
1362 TestApplication application;
1364 Actor actor = Actor::New();
1365 application.GetScene().Add(actor);
1367 // Check initial value is fully opaque
1368 application.SendNotification();
1369 application.Render();
1370 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 1.0f, TEST_LOCATION);
1372 // Create a constraint whose value is discarded when it is removed
1373 Constraint constraint = Constraint::New<Vector4>(actor, Actor::Property::COLOR, SetHalfOpacity);
1374 constraint.SetRemoveAction(Constraint::RemoveAction::DISCARD);
1377 // Check value after one render, it should be constrained
1378 application.SendNotification();
1379 application.Render();
1380 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 0.5f, TEST_LOCATION);
1382 // Render another frame, ensure the other value has also been updated
1383 application.SendNotification();
1384 application.Render();
1385 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 0.5f, TEST_LOCATION);
1387 // Remove the actor from the stage
1390 // Check value while off-stage, the constraint is no longer being applied as it's off-stage
1391 application.SendNotification();
1392 application.Render();
1393 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 1.0f, TEST_LOCATION);
1395 // Check the other buffer, the constraint should not be applied to this either.
1396 application.SendNotification();
1397 application.Render();
1398 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 1.0f, TEST_LOCATION);
1400 // Add the actor back to the stage and check the value, the constraint should have been re-applied
1401 application.GetScene().Add(actor);
1402 application.SendNotification();
1403 application.Render();
1404 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 0.5f, TEST_LOCATION);
1406 // Render for another frame to ensure both buffers have the correct value
1407 application.SendNotification();
1408 application.Render();
1409 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR).a, 0.5f, TEST_LOCATION);
1414 ///////////////////////////////////////////////////////////////////////////////
1416 int UtcDaliConstraintGetTargetObjectNegative(void)
1418 TestApplication application;
1419 Dali::Constraint instance;
1422 instance.GetTargetObject();
1423 DALI_TEST_CHECK(false); // Should not get here
1427 DALI_TEST_CHECK(true); // We expect an assert
1432 int UtcDaliConstraintSetRemoveActionNegative(void)
1434 TestApplication application;
1435 Dali::Constraint instance;
1438 Dali::Constraint::RemoveAction arg1(Constraint::BAKE);
1439 instance.SetRemoveAction(arg1);
1440 DALI_TEST_CHECK(false); // Should not get here
1444 DALI_TEST_CHECK(true); // We expect an assert
1449 int UtcDaliConstraintGetTargetPropertyNegative(void)
1451 TestApplication application;
1452 Dali::Constraint instance;
1455 instance.GetTargetProperty();
1456 DALI_TEST_CHECK(false); // Should not get here
1460 DALI_TEST_CHECK(true); // We expect an assert
1465 int UtcDaliConstraintApplyNegative(void)
1467 TestApplication application;
1468 Dali::Constraint instance;
1472 DALI_TEST_CHECK(false); // Should not get here
1476 DALI_TEST_CHECK(true); // We expect an assert
1481 int UtcDaliConstraintCloneNegative(void)
1483 TestApplication application;
1484 Dali::Constraint instance;
1488 instance.Clone(arg1);
1489 DALI_TEST_CHECK(false); // Should not get here
1493 DALI_TEST_CHECK(true); // We expect an assert
1498 int UtcDaliConstraintRemoveNegative(void)
1500 TestApplication application;
1501 Dali::Constraint instance;
1505 DALI_TEST_CHECK(false); // Should not get here
1509 DALI_TEST_CHECK(true); // We expect an assert
1514 int UtcDaliConstraintSetTagNegative(void)
1516 TestApplication application;
1517 Dali::Constraint instance;
1520 unsigned int arg1(0u);
1521 instance.SetTag(arg1);
1522 DALI_TEST_CHECK(false); // Should not get here
1526 DALI_TEST_CHECK(true); // We expect an assert
1531 int UtcDaliConstraintGetRemoveActionNegative(void)
1533 TestApplication application;
1534 Dali::Constraint instance;
1537 instance.GetRemoveAction();
1538 DALI_TEST_CHECK(false); // Should not get here
1542 DALI_TEST_CHECK(true); // We expect an assert
1547 int UtcDaliConstraintGetTagNegative(void)
1549 TestApplication application;
1550 Dali::Constraint instance;
1554 DALI_TEST_CHECK(false); // Should not get here
1558 DALI_TEST_CHECK(true); // We expect an assert