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.
19 #include <dali/public-api/dali-core.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/hover-event-integ.h>
23 #include <dali-test-suite-utils.h>
31 void utc_dali_actor_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_actor_cleanup(void)
38 test_return_value = TET_PASS;
43 // Enumeration properties to test:
44 const Scripting::StringEnum< int > SIZE_MODE_VALUES[] =
46 { "USE_OWN_SIZE", USE_OWN_SIZE },
47 { "SIZE_EQUAL_TO_PARENT", SIZE_EQUAL_TO_PARENT },
48 { "SIZE_RELATIVE_TO_PARENT", SIZE_RELATIVE_TO_PARENT },
49 { "SIZE_FIXED_OFFSET_FROM_PARENT", SIZE_FIXED_OFFSET_FROM_PARENT },
51 const unsigned int SIZE_MODE_VALUES_COUNT = sizeof( SIZE_MODE_VALUES ) / sizeof( SIZE_MODE_VALUES[0] );
53 bool gTouchCallBackCalled=false;
54 bool gTouchCallBack2Called=false;
55 bool gHoverCallBackCalled=false;
58 * Simulates a Down Touch at 25.0, 25.0.
59 * @param[in] app Test Application instance.
61 int SimulateTouchForSetOverlayHitTest(TestApplication& app)
63 app.SendNotification();
65 app.SendNotification();
68 gTouchCallBackCalled = false;
69 gTouchCallBack2Called = false;
71 // simulate a touch event
72 Dali::TouchPoint point( 0, TouchPoint::Down, 25.0f, 25.0f );
73 Dali::Integration::TouchEvent event;
74 event.AddPoint( point );
75 app.ProcessEvent( event );
77 app.SendNotification();
79 app.SendNotification();
85 static bool gTestConstraintCalled;
89 Vector4 operator()(const Vector4& color)
91 gTestConstraintCalled = true;
92 return Vector4(color.x, color.y, color.z, 0.1f);
97 * TestConstraint reference.
98 * When constraint is called, the resultRef is updated
99 * with the value supplied.
102 struct TestConstraintRef
104 TestConstraintRef(unsigned int& resultRef, unsigned int value)
105 : mResultRef(resultRef),
110 T operator()(const T& current)
116 unsigned int& mResultRef;
120 bool wasConstraintCallbackCalled1 = false;
121 void TestConstraintCallback1( ActiveConstraint& constraint )
123 wasConstraintCallbackCalled1 = true;
126 bool wasConstraintCallbackCalled2 = false;
127 void TestConstraintCallback2( ActiveConstraint& constraint )
129 wasConstraintCallbackCalled2 = true;
132 bool wasConstraintCallbackCalled3 = false;
133 void TestConstraintCallback3( ActiveConstraint& constraint )
135 wasConstraintCallbackCalled3 = true;
138 static bool TestCallback(Actor actor, const TouchEvent& event)
140 gTouchCallBackCalled = true;
145 static bool TestCallback2(Actor actor, const TouchEvent& event)
147 gTouchCallBack2Called = true;
152 static bool TestCallback3(Actor actor, const HoverEvent& event)
154 gHoverCallBackCalled = true;
159 static Vector3 gSetSize;
160 static bool gSetSizeCallBackCalled;
161 void SetSizeCallback( Actor actor, const Vector3& size )
163 gSetSizeCallBackCalled = true;
166 // validation stuff for onstage & offstage signals
167 static std::vector< std::string > gActorNamesOnOffStage;
168 static int gOnStageCallBackCalled;
169 void OnStageCallback( Actor actor )
171 ++gOnStageCallBackCalled;
172 gActorNamesOnOffStage.push_back( actor.GetName() );
173 DALI_TEST_CHECK( actor.OnStage() == true );
175 static int gOffStageCallBackCalled;
176 void OffStageCallback( Actor actor )
178 ++gOffStageCallBackCalled;
179 gActorNamesOnOffStage.push_back( actor.GetName() );
180 DALI_TEST_CHECK( actor.OnStage() == false );
183 struct PositionComponentConstraint
185 PositionComponentConstraint(){}
187 Vector3 operator()(const Vector3& current, const PropertyInput& property)
189 const Matrix& m = property.GetMatrix();
193 m.GetTransformComponents(pos, rot, scale);
200 } // anonymous namespace
203 //& purpose: Testing New API
204 int UtcDaliActorNew(void)
206 TestApplication application;
208 Actor actor = Actor::New();
210 DALI_TEST_CHECK(actor);
214 //& purpose: Testing Dali::Actor::DownCast()
215 int UtcDaliActorDownCast(void)
217 TestApplication application;
218 tet_infoline("Testing Dali::Actor::DownCast()");
220 Actor actor = Actor::New();
221 BaseHandle object(actor);
222 Actor actor2 = Actor::DownCast(object);
223 DALI_TEST_CHECK(actor2);
227 //& purpose: Testing Dali::Actor::DownCast()
228 int UtcDaliActorDownCast2(void)
230 TestApplication application;
231 tet_infoline("Testing Dali::Actor::DownCast()");
233 BaseHandle unInitializedObject;
234 Actor actor = Actor::DownCast(unInitializedObject);
235 DALI_TEST_CHECK(!actor);
239 //& purpose: Testing Dali::Actor::GetName()
240 int UtcDaliActorGetName(void)
242 TestApplication application;
244 Actor actor = Actor::New();
246 DALI_TEST_CHECK(actor.GetName().empty());
250 //& purpose: Testing Dali::Actor::SetName()
251 int UtcDaliActorSetName(void)
253 TestApplication application;
255 string str("ActorName");
256 Actor actor = Actor::New();
259 DALI_TEST_CHECK(actor.GetName() == str);
263 int UtcDaliActorGetId(void)
265 tet_infoline("Testing Dali::Actor::UtcDaliActorGetId()");
266 TestApplication application;
268 Actor first = Actor::New();
269 Actor second = Actor::New();
270 Actor third = Actor::New();
272 DALI_TEST_CHECK(first.GetId() != second.GetId());
273 DALI_TEST_CHECK(second.GetId() != third.GetId());
277 int UtcDaliActorIsRoot(void)
279 TestApplication application;
281 Actor actor = Actor::New();
282 DALI_TEST_CHECK(!actor.IsRoot());
284 // get the root layer
285 actor = Stage::GetCurrent().GetLayer( 0 );
286 DALI_TEST_CHECK( actor.IsRoot() );
290 int UtcDaliActorOnStage(void)
292 TestApplication application;
294 Actor actor = Actor::New();
295 DALI_TEST_CHECK( !actor.OnStage() );
297 // get the root layer
298 actor = Stage::GetCurrent().GetLayer( 0 );
299 DALI_TEST_CHECK( actor.OnStage() );
303 int UtcDaliActorIsLayer(void)
305 TestApplication application;
307 Actor actor = Actor::New();
308 DALI_TEST_CHECK( !actor.IsLayer() );
310 // get the root layer
311 actor = Stage::GetCurrent().GetLayer( 0 );
312 DALI_TEST_CHECK( actor.IsLayer() );
316 int UtcDaliActorGetLayer(void)
318 TestApplication application;
320 Actor actor = Actor::New();
321 Stage::GetCurrent().Add(actor);
322 Layer layer = actor.GetLayer();
324 DALI_TEST_CHECK(layer);
326 // get the root layers layer
327 actor = Stage::GetCurrent().GetLayer( 0 );
328 DALI_TEST_CHECK( actor.GetLayer() );
332 int UtcDaliActorAdd(void)
334 tet_infoline("Testing Actor::Add");
335 TestApplication application;
337 Actor parent = Actor::New();
338 Actor child = Actor::New();
340 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
344 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
346 Actor parent2 = Actor::New();
347 parent2.Add( child );
349 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
350 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
352 // try Adding to same parent again, works
353 parent2.Add( child );
354 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
356 // try reparenting an orphaned child
358 Actor temporaryParent = Actor::New();
359 temporaryParent.Add( child );
360 DALI_TEST_EQUALS( parent2.GetChildCount(), 0u, TEST_LOCATION );
362 // temporaryParent has now died, reparent the orphaned child
363 parent2.Add( child );
364 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
369 parent2.Add( parent2 );
370 tet_printf("Assertion test failed - no Exception\n" );
371 tet_result(TET_FAIL);
373 catch(Dali::DaliException& e)
375 DALI_TEST_PRINT_ASSERT( e );
376 DALI_TEST_ASSERT(e, "this != &child", TEST_LOCATION);
377 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
381 tet_printf("Assertion test failed - wrong Exception\n" );
382 tet_result(TET_FAIL);
385 // try reparenting root
388 parent2.Add( Stage::GetCurrent().GetLayer( 0 ) );
389 tet_printf("Assertion test failed - no Exception\n" );
390 tet_result(TET_FAIL);
392 catch(Dali::DaliException& e)
394 DALI_TEST_PRINT_ASSERT( e );
395 DALI_TEST_ASSERT(e, "!child.IsRoot()", TEST_LOCATION);
396 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
400 tet_printf("Assertion test failed - wrong Exception\n" );
401 tet_result(TET_FAIL);
408 parent2.Add( empty );
409 tet_printf("Assertion test failed - no Exception\n" );
410 tet_result(TET_FAIL);
412 catch(Dali::DaliException& e)
414 DALI_TEST_PRINT_ASSERT( e );
415 DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
416 DALI_TEST_EQUALS( parent2.GetChildCount(), 1u, TEST_LOCATION );
420 tet_printf("Assertion test failed - wrong Exception\n" );
421 tet_result(TET_FAIL);
426 int UtcDaliActorInsert(void)
428 tet_infoline("Testing Actor::Insert");
429 TestApplication application;
431 Actor parent = Actor::New();
432 Stage::GetCurrent().Add( parent );
433 Actor first = Actor::New();
434 Actor second = Actor::New();
435 Actor third = Actor::New();
437 parent.Insert(1, first); // test insert beyond range
438 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
439 parent.Insert(0, second);
440 DALI_TEST_EQUALS( parent.GetChildCount(), 2u, TEST_LOCATION );
441 parent.Insert(1, third);
443 DALI_TEST_EQUALS( parent.GetChildCount(), 3u, TEST_LOCATION );
445 DALI_TEST_CHECK(parent.GetChildAt(0) == second);
446 DALI_TEST_CHECK(parent.GetChildAt(1) == third);
447 DALI_TEST_CHECK(parent.GetChildAt(2) == first);
453 int UtcDaliActorRemove01(void)
455 tet_infoline("Testing Actor::Remove");
456 TestApplication application;
458 Actor parent = Actor::New();
459 Actor child = Actor::New();
460 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
463 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
465 parent.Remove(child);
466 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
468 // remove again, no problem
469 parent.Remove(child);
470 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
474 // try illegal Remove
477 parent.Remove( parent );
478 tet_printf("Assertion test failed - no Exception\n" );
479 tet_result(TET_FAIL);
481 catch(Dali::DaliException& e)
483 DALI_TEST_PRINT_ASSERT( e );
484 DALI_TEST_ASSERT(e, "this != &child", TEST_LOCATION);
485 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
489 tet_printf("Assertion test failed - wrong Exception\n" );
490 tet_result(TET_FAIL);
497 parent.Remove( empty );
498 tet_printf("Assertion test failed - no Exception\n" );
499 tet_result(TET_FAIL);
501 catch(Dali::DaliException& e)
503 DALI_TEST_PRINT_ASSERT( e );
504 DALI_TEST_ASSERT(e, "actor", TEST_LOCATION);
505 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
509 tet_printf("Assertion test failed - wrong Exception\n" );
510 tet_result(TET_FAIL);
515 int UtcDaliActorRemove02(void)
517 TestApplication application;
519 Actor parent = Actor::New();
520 Actor child = Actor::New();
521 Actor random = Actor::New();
523 Stage::GetCurrent().Add( parent );
525 DALI_TEST_CHECK(parent.GetChildCount() == 0);
529 DALI_TEST_CHECK(parent.GetChildCount() == 1);
531 parent.Remove(random);
533 DALI_TEST_CHECK(parent.GetChildCount() == 1);
535 Stage::GetCurrent().Remove( parent );
537 DALI_TEST_CHECK(parent.GetChildCount() == 1);
541 int UtcDaliActorGetChildCount(void)
543 TestApplication application;
545 Actor parent = Actor::New();
546 Actor child = Actor::New();
548 DALI_TEST_CHECK(parent.GetChildCount() == 0);
552 DALI_TEST_CHECK(parent.GetChildCount() == 1);
556 int UtcDaliActorGetChildren01(void)
558 TestApplication application;
560 Actor parent = Actor::New();
561 Actor first = Actor::New();
562 Actor second = Actor::New();
563 Actor third = Actor::New();
569 DALI_TEST_CHECK(parent.GetChildAt(0) == first);
570 DALI_TEST_CHECK(parent.GetChildAt(1) == second);
571 DALI_TEST_CHECK(parent.GetChildAt(2) == third);
575 int UtcDaliActorGetChildren02(void)
577 TestApplication application;
579 Actor parent = Actor::New();
580 Actor first = Actor::New();
581 Actor second = Actor::New();
582 Actor third = Actor::New();
588 const Actor& constParent = parent;
590 DALI_TEST_CHECK(constParent.GetChildAt(0) == first);
591 DALI_TEST_CHECK(constParent.GetChildAt(1) == second);
592 DALI_TEST_CHECK(constParent.GetChildAt(2) == third);
596 int UtcDaliActorGetParent01(void)
598 TestApplication application;
600 Actor parent = Actor::New();
601 Actor child = Actor::New();
605 DALI_TEST_CHECK(child.GetParent() == parent);
609 int UtcDaliActorGetParent02(void)
611 TestApplication application;
613 Actor actor = Actor::New();
615 DALI_TEST_CHECK(!actor.GetParent());
619 int UtcDaliActorSetParentOrigin(void)
621 TestApplication application;
623 Actor actor = Actor::New();
625 Vector3 vector(0.7f, 0.8f, 0.9f);
626 DALI_TEST_CHECK(vector != actor.GetCurrentParentOrigin());
628 actor.SetParentOrigin(vector);
630 // flush the queue and render once
631 application.SendNotification();
632 application.Render();
634 DALI_TEST_CHECK(vector == actor.GetCurrentParentOrigin());
636 Stage::GetCurrent().Add( actor );
638 actor.SetParentOrigin( Vector3( 0.1f, 0.2f, 0.3f ) );
640 // flush the queue and render once
641 application.SendNotification();
642 application.Render();
644 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentParentOrigin(), TEST_LOCATION );
646 Stage::GetCurrent().Remove( actor );
650 int UtcDaliActorGetCurrentParentOrigin(void)
652 TestApplication application;
654 Actor actor = Actor::New();
656 Vector3 vector(0.7f, 0.8f, 0.9f);
657 DALI_TEST_CHECK(vector != actor.GetCurrentParentOrigin());
659 actor.SetParentOrigin(vector);
661 // flush the queue and render once
662 application.SendNotification();
663 application.Render();
665 DALI_TEST_CHECK(vector == actor.GetCurrentParentOrigin());
669 int UtcDaliActorSetAnchorPoint(void)
671 TestApplication application;
673 Actor actor = Actor::New();
675 Vector3 vector(0.7f, 0.8f, 0.9f);
676 DALI_TEST_CHECK(vector != actor.GetCurrentAnchorPoint());
678 actor.SetAnchorPoint(vector);
680 // flush the queue and render once
681 application.SendNotification();
682 application.Render();
684 DALI_TEST_CHECK(vector == actor.GetCurrentAnchorPoint());
686 Stage::GetCurrent().Add( actor );
688 actor.SetAnchorPoint( Vector3( 0.1f, 0.2f, 0.3f ) );
689 // flush the queue and render once
690 application.SendNotification();
691 application.Render();
693 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentAnchorPoint(), TEST_LOCATION );
695 Stage::GetCurrent().Remove( actor );
699 int UtcDaliActorGetCurrentAnchorPoint(void)
701 TestApplication application;
703 Actor actor = Actor::New();
705 Vector3 vector(0.7f, 0.8f, 0.9f);
706 DALI_TEST_CHECK(vector != actor.GetCurrentAnchorPoint());
708 actor.SetAnchorPoint(vector);
710 // flush the queue and render once
711 application.SendNotification();
712 application.Render();
714 DALI_TEST_CHECK(vector == actor.GetCurrentAnchorPoint());
718 // SetSize(float width, float height)
719 int UtcDaliActorSetSize01(void)
721 TestApplication application;
723 Actor actor = Actor::New();
724 Vector3 vector(100.0f, 100.0f, 100.0f);
726 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
728 actor.SetSize(vector.x, vector.y);
730 // flush the queue and render once
731 application.SendNotification();
732 application.Render();
734 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
738 // SetSize(float width, float height, float depth)
739 int UtcDaliActorSetSize02(void)
741 TestApplication application;
743 Actor actor = Actor::New();
744 Vector3 vector(100.0f, 100.0f, 100.0f);
746 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
748 actor.SetSize(vector.x, vector.y, vector.z);
750 // flush the queue and render once
751 application.SendNotification();
752 application.Render();
754 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
758 // SetSize(Vector2 size)
759 int UtcDaliActorSetSize03(void)
761 TestApplication application;
763 Actor actor = Actor::New();
764 Vector3 vector(100.0f, 100.0f, 100.0f);
766 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
768 actor.SetSize(Vector2(vector.x, vector.y));
770 // flush the queue and render once
771 application.SendNotification();
772 application.Render();
774 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
778 // SetSize(Vector3 size)
779 int UtcDaliActorSetSize04(void)
781 TestApplication application;
783 Actor actor = Actor::New();
784 Vector3 vector(100.0f, 100.0f, 100.0f);
786 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
788 actor.SetSize(vector);
790 // flush the queue and render once
791 application.SendNotification();
792 application.Render();
794 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
796 Stage::GetCurrent().Add( actor );
797 actor.SetSize( Vector3( 0.1f, 0.2f, 0.3f ) );
799 // flush the queue and render once
800 application.SendNotification();
801 application.Render();
803 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentSize(), TEST_LOCATION );
804 Stage::GetCurrent().Remove( actor );
808 int UtcDaliActorGetCurrentSize(void)
810 TestApplication application;
812 Actor actor = Actor::New();
813 Vector3 vector(100.0f, 100.0f, 20.0f);
815 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
817 actor.SetSize(vector);
819 // flush the queue and render once
820 application.SendNotification();
821 application.Render();
823 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
827 int UtcDaliActorGetNaturalSize(void)
829 TestApplication application;
831 Actor actor = Actor::New();
832 Vector3 vector( 0.0f, 0.0f, 0.0f );
834 DALI_TEST_CHECK( actor.GetNaturalSize() == vector );
839 int UtcDaliActorGetCurrentSizeImmediate(void)
841 TestApplication application;
843 Actor actor = Actor::New();
844 Vector3 vector(100.0f, 100.0f, 20.0f);
846 DALI_TEST_CHECK(vector != actor.GetSize());
847 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
849 actor.SetSize(vector);
851 DALI_TEST_CHECK(vector == actor.GetSize());
852 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
854 // flush the queue and render once
855 application.SendNotification();
856 application.Render();
858 DALI_TEST_CHECK(vector == actor.GetSize());
859 DALI_TEST_CHECK(vector == actor.GetCurrentSize());
862 // Build the animation
863 const float durationSeconds = 2.0f;
864 Animation animation = Animation::New( durationSeconds );
865 const Vector3 targetValue( 10.0f, 20.0f, 30.0f );
866 animation.AnimateTo( Property( actor, Actor::Property::SIZE ), targetValue );
868 DALI_TEST_CHECK( actor.GetSize() == targetValue );
870 // Start the animation
873 application.SendNotification();
874 application.Render( static_cast<unsigned int>( durationSeconds * 1000.0f ) );
876 DALI_TEST_CHECK( actor.GetSize() == targetValue );
881 // SetPosition(float x, float y)
882 int UtcDaliActorSetPosition01(void)
884 TestApplication application;
886 Actor actor = Actor::New();
888 // Set to random to start off with
889 actor.SetPosition(Vector3(120.0f, 120.0f, 0.0f));
891 Vector3 vector(100.0f, 100.0f, 0.0f);
893 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
895 actor.SetPosition(vector.x, vector.y);
896 // flush the queue and render once
897 application.SendNotification();
898 application.Render();
899 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
901 Stage::GetCurrent().Add( actor );
902 actor.SetPosition( Vector3( 0.1f, 0.2f, 0.3f ) );
903 // flush the queue and render once
904 application.SendNotification();
905 application.Render();
906 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentPosition(), TEST_LOCATION );
911 // flush the queue and render once
912 application.SendNotification();
913 application.Render();
914 DALI_TEST_EQUALS( Vector3( 1.0f, 1.1f, 1.2f ), actor.GetCurrentPosition(), TEST_LOCATION );
916 actor.TranslateBy( Vector3( 0.1f, 0.1f, 0.1f ) );
917 // flush the queue and render once
918 application.SendNotification();
919 application.Render();
920 DALI_TEST_EQUALS( Vector3( 1.1f, 1.2f, 1.3f ), actor.GetCurrentPosition(), Math::MACHINE_EPSILON_10000, TEST_LOCATION );
922 Stage::GetCurrent().Remove( actor );
926 // SetPosition(float x, float y, float z)
927 int UtcDaliActorSetPosition02(void)
929 TestApplication application;
931 Actor actor = Actor::New();
933 // Set to random to start off with
934 actor.SetPosition(Vector3(120.0f, 120.0f, 120.0f));
936 Vector3 vector(100.0f, 100.0f, 100.0f);
938 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
940 actor.SetPosition(vector.x, vector.y, vector.z);
942 // flush the queue and render once
943 application.SendNotification();
944 application.Render();
946 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
950 // SetPosition(Vector3 position)
951 int UtcDaliActorSetPosition03(void)
953 TestApplication application;
955 Actor actor = Actor::New();
957 // Set to random to start off with
958 actor.SetPosition(Vector3(120.0f, 120.0f, 120.0f));
960 Vector3 vector(100.0f, 100.0f, 100.0f);
962 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
964 actor.SetPosition(vector);
966 // flush the queue and render once
967 application.SendNotification();
968 application.Render();
970 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
974 int UtcDaliActorSetX(void)
976 TestApplication application;
978 Actor actor = Actor::New();
980 Vector3 vector(100.0f, 0.0f, 0.0f);
982 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
986 // flush the queue and render once
987 application.SendNotification();
988 application.Render();
990 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
994 int UtcDaliActorSetY(void)
996 TestApplication application;
998 Actor actor = Actor::New();
1000 Vector3 vector(0.0f, 100.0f, 0.0f);
1002 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1006 // flush the queue and render once
1007 application.SendNotification();
1008 application.Render();
1010 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1014 int UtcDaliActorSetZ(void)
1016 TestApplication application;
1018 Actor actor = Actor::New();
1020 Vector3 vector(0.0f, 0.0f, 100.0f);
1022 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1026 // flush the queue and render once
1027 application.SendNotification();
1028 application.Render();
1030 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1034 int UtcDaliActorTranslateBy(void)
1036 TestApplication application;
1038 Actor actor = Actor::New();
1039 Vector3 vector(100.0f, 100.0f, 100.0f);
1041 DALI_TEST_CHECK(vector != actor.GetCurrentPosition());
1043 actor.SetPosition(vector);
1045 // flush the queue and render once
1046 application.SendNotification();
1047 application.Render();
1049 DALI_TEST_CHECK(vector == actor.GetCurrentPosition());
1051 actor.TranslateBy(vector);
1053 // flush the queue and render once
1054 application.SendNotification();
1055 application.Render();
1057 DALI_TEST_CHECK(vector*2.0f == actor.GetCurrentPosition());
1061 int UtcDaliActorGetCurrentPosition(void)
1063 TestApplication application;
1065 Actor actor = Actor::New();
1066 Vector3 setVector(100.0f, 100.0f, 0.0f);
1067 actor.SetPosition(setVector);
1069 // flush the queue and render once
1070 application.SendNotification();
1071 application.Render();
1073 DALI_TEST_CHECK(actor.GetCurrentPosition() == setVector);
1077 int UtcDaliActorGetCurrentWorldPosition(void)
1079 TestApplication application;
1081 Actor parent = Actor::New();
1082 Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
1083 parent.SetPosition( parentPosition );
1084 parent.SetParentOrigin( ParentOrigin::CENTER );
1085 parent.SetAnchorPoint( AnchorPoint::CENTER );
1086 Stage::GetCurrent().Add( parent );
1088 Actor child = Actor::New();
1089 child.SetParentOrigin( ParentOrigin::CENTER );
1090 child.SetAnchorPoint( AnchorPoint::CENTER );
1091 Vector3 childPosition( 6.0f, 6.0f, 6.0f );
1092 child.SetPosition( childPosition );
1093 parent.Add( child );
1095 // The actors should not have a world position yet
1096 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1097 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1099 application.SendNotification();
1100 application.Render(0);
1102 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1103 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
1105 // The actors should have a world position now
1106 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1107 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childPosition, TEST_LOCATION );
1111 int UtcDaliActorInheritPosition(void)
1113 tet_infoline("Testing Actor::SetPositionInheritanceMode");
1114 TestApplication application;
1116 Actor parent = Actor::New();
1117 Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
1118 parent.SetPosition( parentPosition );
1119 parent.SetParentOrigin( ParentOrigin::CENTER );
1120 parent.SetAnchorPoint( AnchorPoint::CENTER );
1121 Stage::GetCurrent().Add( parent );
1123 Actor child = Actor::New();
1124 child.SetParentOrigin( ParentOrigin::CENTER );
1125 child.SetAnchorPoint( AnchorPoint::CENTER );
1126 Vector3 childPosition( 10.0f, 11.0f, 12.0f );
1127 child.SetPosition( childPosition );
1128 parent.Add( child );
1130 // The actors should not have a world position yet
1131 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1132 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
1134 // first test default, which is INHERIT_PARENT_POSITION
1135 DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::INHERIT_PARENT_POSITION, TEST_LOCATION );
1136 application.SendNotification();
1137 application.Render(0); // should only really call Update as Render is not required to update scene
1138 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1139 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
1140 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1141 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childPosition, TEST_LOCATION );
1143 // Change inheritance mode to use parent
1144 child.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
1145 DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::USE_PARENT_POSITION, TEST_LOCATION );
1146 application.SendNotification();
1147 application.Render(0); // should only really call Update as Render is not required to update scene
1148 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1149 DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
1150 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1151 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1153 // Change inheritance mode to use parent + offset
1154 child.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
1155 Vector3 childOffset( -1.0f, 1.0f, 0.0f );
1156 child.SetPosition( childOffset );
1157 DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::USE_PARENT_POSITION_PLUS_LOCAL_POSITION, TEST_LOCATION );
1158 application.SendNotification();
1159 application.Render(0); // should only really call Update as Render is not required to update scene
1160 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1161 DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
1162 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1163 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childOffset, TEST_LOCATION );
1165 // Change inheritance mode to not inherit
1166 child.SetPositionInheritanceMode( Dali::DONT_INHERIT_POSITION );
1167 DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::DONT_INHERIT_POSITION, TEST_LOCATION );
1168 application.SendNotification();
1169 application.Render(0); // should only really call Update as Render is not required to update scene
1170 DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
1171 DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
1172 DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
1173 DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), childOffset, TEST_LOCATION );
1177 int UtcDaliActorSizeMode(void)
1179 tet_infoline("Testing Actor::SetSizeMode");
1180 TestApplication application;
1182 // Create a parent and a child.
1183 Actor parent = Actor::New();
1184 parent.SetParentOrigin( ParentOrigin::CENTER );
1185 parent.SetAnchorPoint( AnchorPoint::CENTER );
1186 Vector3 parentPosition( 0.0f, 0.0f, 0.0f );
1187 parent.SetPosition( parentPosition );
1188 parent.SetSize( 10.0f, 20.0f, 40.0f );
1189 parent.SetSizeMode( USE_OWN_SIZE );
1190 Stage::GetCurrent().Add( parent );
1192 Actor child = Actor::New();
1193 child.SetParentOrigin( ParentOrigin::CENTER );
1194 child.SetAnchorPoint( AnchorPoint::CENTER );
1195 Vector3 childPosition( 0.0f, 0.0f, 0.0f );
1196 child.SetPosition( childPosition );
1197 child.SetSize( 1.0f, 2.0f, 4.0f );
1198 child.SetSizeMode( USE_OWN_SIZE );
1199 parent.Add( child );
1201 // Flush the queue and render once.
1202 application.SendNotification();
1203 application.Render();
1205 // Test USE_OWN_SIZE uses the user-set size value.
1206 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 1.0f, 2.0f, 4.0f ), TEST_LOCATION );
1207 // Render and check again to ensure double-buffering does not cause old value to reappear.
1208 application.Render();
1209 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 1.0f, 2.0f, 4.0f ), TEST_LOCATION );
1211 // Test SIZE_EQUAL_TO_PARENT overrides size with the parents size.
1212 child.SetSizeMode( SIZE_EQUAL_TO_PARENT );
1214 application.SendNotification();
1215 application.Render();
1216 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 10.0f, 20.0f, 40.0f ), TEST_LOCATION );
1217 // Render and check again to ensure double-buffering does not cause old value to reappear.
1218 application.Render();
1219 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 10.0f, 20.0f, 40.0f ), TEST_LOCATION );
1221 // Test SIZE_RELATIVE_TO_PARENT overrides size with parents size * SizeModeFactor.
1222 child.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
1224 application.SendNotification();
1225 application.Render();
1226 // First check without setting a relative factor, to confirm that the default factor (of 1.0f) is used.
1227 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 10.0f, 20.0f, 40.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1228 // Render and check again to ensure double-buffering does not cause old value to reappear.
1229 application.Render();
1230 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 10.0f, 20.0f, 40.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1232 // Set an arbitary relative factor to check against.
1233 child.SetSizeModeFactor( Vector3( 2.0f, 3.0f, 4.0f ) );
1235 application.SendNotification();
1236 application.Render();
1237 // Check with a valid relative factor.
1238 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 20.0f, 60.0f, 160.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1239 // Render and check again to ensure double-buffering does not cause old value to reappear.
1240 application.Render();
1241 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 20.0f, 60.0f, 160.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1243 // Test SIZE_FIXED_OFFSET_FROM_PARENT overrides size with parents size + SizeModeFactor.
1244 child.SetSizeMode( SIZE_FIXED_OFFSET_FROM_PARENT );
1246 application.SendNotification();
1247 application.Render();
1248 // Check with a valid relative factor.
1249 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 12.0f, 23.0f, 44.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1250 // Render and check again to ensure double-buffering does not cause old value to reappear.
1251 application.Render();
1252 DALI_TEST_EQUALS( child.GetCurrentSize(), Vector3( 12.0f, 23.0f, 44.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1254 application.SendNotification();
1256 // Test the calculation order in update by having a parent with a size-relative
1257 // factor and a rotation rotate a child anchored to one of the parents corners.
1259 // .-----. | .-----. The new child is parented from the top-left of its parent.
1260 // | '-|-' -----> | | We rotate the parent to confirm that the relative size calculation is
1261 // | p | Rotate | .-|-. done before rotation. If it wasn't, the childs resultant
1262 // '-----' parent '-----' | world-position would be incorrect.
1265 // Create a new parent and child, and a root parent which the parent can grab relative size from.
1266 Actor rootParent = Actor::New();
1267 rootParent.SetParentOrigin( ParentOrigin::CENTER );
1268 rootParent.SetAnchorPoint( AnchorPoint::CENTER );
1269 rootParent.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) );
1270 rootParent.SetSize( 10.0f, 10.0f, 10.0f );
1271 rootParent.SetSizeMode( USE_OWN_SIZE );
1272 Stage::GetCurrent().Add( rootParent );
1274 Actor newParent = Actor::New();
1275 newParent.SetParentOrigin( ParentOrigin::CENTER );
1276 newParent.SetAnchorPoint( AnchorPoint::CENTER );
1277 newParent.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) );
1278 newParent.SetSize( 10.0f, 10.0f, 10.0f );
1279 newParent.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
1280 newParent.SetSizeModeFactor( Vector3( 0.5f, 0.5f, 0.5f ) );
1281 rootParent.Add( newParent );
1283 Actor newChild = Actor::New();
1284 newChild.SetParentOrigin( ParentOrigin::TOP_RIGHT );
1285 newChild.SetAnchorPoint( AnchorPoint::CENTER );
1286 newChild.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) );
1287 newChild.SetSize( 1.0f, 1.0f, 1.0f );
1288 newChild.SetSizeMode( USE_OWN_SIZE );
1289 newParent.Add( newChild );
1291 // Set up the rotation by 90 degrees on Z.
1292 newParent.RotateBy( Radian( M_PI * 0.5f ), Vector3::ZAXIS );
1294 application.SendNotification();
1295 application.Render();
1296 DALI_TEST_EQUALS( newParent.GetCurrentSize(), Vector3( 5.0f, 5.0f, 5.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1297 DALI_TEST_EQUALS( newParent.GetCurrentWorldPosition(), Vector3( 0.0f, 0.0f, 0.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1298 DALI_TEST_EQUALS( newChild.GetCurrentWorldPosition(), Vector3( 2.5f, 2.5f, 0.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1300 // Test changing the parents size to check the child's size is updated.
1301 Actor newParent2 = Actor::New();
1302 newParent2.SetParentOrigin( ParentOrigin::CENTER );
1303 newParent2.SetAnchorPoint( AnchorPoint::CENTER );
1304 newParent2.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) );
1305 newParent2.SetSize( 10.0f, 10.0f, 10.0f );
1306 newParent2.SetSizeMode( USE_OWN_SIZE );
1307 rootParent.Add( newParent2 );
1309 Actor newChild2 = Actor::New();
1310 newChild2.SetParentOrigin( ParentOrigin::TOP_RIGHT );
1311 newChild2.SetAnchorPoint( AnchorPoint::CENTER );
1312 newChild2.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) );
1313 newChild2.SetSize( Vector3::ONE );
1314 newChild2.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
1315 newChild2.SetSizeModeFactor( Vector3( 0.5f, 0.5f, 0.5f ) );
1316 newParent2.Add( newChild2 );
1318 // Check the child has no size yet.
1319 DALI_TEST_EQUALS( newChild2.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
1321 // Check the child now has a relative size to the parent.
1322 application.SendNotification();
1323 application.Render();
1324 DALI_TEST_EQUALS( newChild2.GetCurrentSize(), Vector3( 5.0f, 5.0f, 5.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1326 // Change the parent's size and check the child's size changes also.
1327 newParent2.SetSize( 100.0f, 100.0f, 100.0f );
1328 application.SendNotification();
1329 application.Render();
1330 DALI_TEST_EQUALS( newChild2.GetCurrentSize(), Vector3( 50.0f, 50.0f, 50.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1331 // Confirm the child's size is still correct on the next frame.
1332 application.Render();
1333 DALI_TEST_EQUALS( newChild2.GetCurrentSize(), Vector3( 50.0f, 50.0f, 50.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1335 // Text that reparenting a child causes its size to update relative to its new parent.
1336 Actor newParent3 = Actor::New();
1337 newParent3.SetParentOrigin( ParentOrigin::CENTER );
1338 newParent3.SetAnchorPoint( AnchorPoint::CENTER );
1339 newParent3.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) );
1340 newParent3.SetSize( 400.0f, 400.0f, 400.0f );
1341 newParent3.SetSizeMode( USE_OWN_SIZE );
1342 rootParent.Add( newParent3 );
1344 // Reparent the child but don't update yet. Check it still has its old size.
1345 newParent3.Add( newChild2 );
1346 DALI_TEST_EQUALS( newChild2.GetCurrentSize(), Vector3( 50.0f, 50.0f, 50.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1348 // Check the child's size has updated based on the new parent.
1349 application.SendNotification();
1350 application.Render();
1351 DALI_TEST_EQUALS( newChild2.GetCurrentSize(), Vector3( 200.0f, 200.0f, 200.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1352 // Confirm the child's size is still correct on the next frame.
1353 application.Render();
1354 DALI_TEST_EQUALS( newChild2.GetCurrentSize(), Vector3( 200.0f, 200.0f, 200.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1357 // Test setting and getting the SizeMode property (by string).
1358 Actor propertyActor = Actor::New();
1359 propertyActor.SetParentOrigin( ParentOrigin::CENTER );
1360 propertyActor.SetAnchorPoint( AnchorPoint::CENTER );
1361 propertyActor.SetPosition( Vector3::ZERO );
1362 propertyActor.SetSize( Vector3::ONE );
1363 propertyActor.SetSizeMode( USE_OWN_SIZE );
1365 // Loop through each SizeMode enumeration.
1366 for( unsigned int propertyIndex = 0; propertyIndex < SIZE_MODE_VALUES_COUNT; ++propertyIndex )
1368 Property::Value inValue = SIZE_MODE_VALUES[ propertyIndex ].string;
1369 propertyActor.SetProperty( Actor::Property::SIZE_MODE, inValue );
1370 std::string outString = propertyActor.GetProperty( Actor::Property::SIZE_MODE ).Get< std::string >();
1371 DALI_TEST_EQUALS( inValue.Get< std::string >(), outString, TEST_LOCATION );
1374 // Test setting and getting the SizeModeFactor property.
1375 Vector3 testPropertySizeModeFactor( 1.0f, 2.0f, 3.0f );
1376 Property::Value inValueFactor = testPropertySizeModeFactor;
1377 propertyActor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, inValueFactor );
1378 Vector3 outValueFactor = propertyActor.GetProperty( Actor::Property::SIZE_MODE_FACTOR ).Get< Vector3 >();
1379 DALI_TEST_EQUALS( testPropertySizeModeFactor, outValueFactor, TEST_LOCATION );
1384 // SetOrientation(float angleRadians, Vector3 axis)
1385 int UtcDaliActorSetOrientation01(void)
1387 TestApplication application;
1389 Quaternion rotation(0.785f, Vector3(1.0f, 1.0f, 0.0f));
1390 Actor actor = Actor::New();
1392 actor.SetOrientation(rotation);
1394 // flush the queue and render once
1395 application.SendNotification();
1396 application.Render();
1398 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1402 int UtcDaliActorSetOrientation02(void)
1404 TestApplication application;
1406 Actor actor = Actor::New();
1408 float angle = 0.785f;
1409 Vector3 axis(1.0f, 1.0f, 0.0f);
1411 actor.SetOrientation(Radian( angle ), axis);
1412 Quaternion rotation( angle, axis );
1413 // flush the queue and render once
1414 application.SendNotification();
1415 application.Render();
1416 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1418 Stage::GetCurrent().Add( actor );
1419 actor.RotateBy( Degree( 360 ), axis);
1420 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1422 actor.SetOrientation( Degree( 0 ), Vector3( 1.0f, 0.0f, 0.0f ) );
1423 Quaternion result( 0, Vector3( 1.0f, 0.0f, 0.0f ) );
1424 // flush the queue and render once
1425 application.SendNotification();
1426 application.Render();
1427 DALI_TEST_EQUALS( result, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1429 actor.SetOrientation(Radian( angle ), axis);
1430 // flush the queue and render once
1431 application.SendNotification();
1432 application.Render();
1433 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1435 Stage::GetCurrent().Remove( actor );
1439 // RotateBy(float angleRadians, Vector3 axis)
1440 int UtcDaliActorRotateBy01(void)
1442 TestApplication application;
1444 Actor actor = Actor::New();
1446 float angle = M_PI * 0.25f;
1447 actor.RotateBy(Radian( angle ), Vector3::ZAXIS);
1448 // flush the queue and render once
1449 application.SendNotification();
1450 application.Render();
1451 DALI_TEST_EQUALS(Quaternion(M_PI*0.25f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1453 Stage::GetCurrent().Add( actor );
1455 actor.RotateBy(Radian( angle ), Vector3::ZAXIS);
1456 // flush the queue and render once
1457 application.SendNotification();
1458 application.Render();
1459 DALI_TEST_EQUALS(Quaternion(M_PI*0.5f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1461 Stage::GetCurrent().Remove( actor );
1465 // RotateBy(Quaternion relativeRotation)
1466 int UtcDaliActorRotateBy02(void)
1468 TestApplication application;
1470 Actor actor = Actor::New();
1472 Quaternion rotation(M_PI*0.25f, Vector3::ZAXIS);
1473 actor.RotateBy(rotation);
1474 // flush the queue and render once
1475 application.SendNotification();
1476 application.Render();
1477 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1479 actor.RotateBy(rotation);
1480 // flush the queue and render once
1481 application.SendNotification();
1482 application.Render();
1483 DALI_TEST_EQUALS(Quaternion(M_PI*0.5f, Vector3::ZAXIS), actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1487 int UtcDaliActorGetCurrentOrientation(void)
1489 TestApplication application;
1490 Actor actor = Actor::New();
1492 Quaternion rotation(0.785f, Vector3(1.0f, 1.0f, 0.0f));
1493 actor.SetOrientation(rotation);
1494 // flush the queue and render once
1495 application.SendNotification();
1496 application.Render();
1497 DALI_TEST_EQUALS(rotation, actor.GetCurrentOrientation(), 0.001, TEST_LOCATION);
1501 int UtcDaliActorGetCurrentWorldOrientation(void)
1503 tet_infoline("Testing Actor::GetCurrentWorldRotation");
1504 TestApplication application;
1506 Actor parent = Actor::New();
1507 Radian rotationAngle( Degree(90.0f) );
1508 Quaternion rotation( rotationAngle, Vector3::YAXIS );
1509 parent.SetOrientation( rotation );
1510 Stage::GetCurrent().Add( parent );
1512 Actor child = Actor::New();
1513 child.SetOrientation( rotation );
1514 parent.Add( child );
1516 // The actors should not have a world rotation yet
1517 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
1518 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion(0.0f, Vector3::YAXIS), 0.001, TEST_LOCATION );
1520 application.SendNotification();
1521 application.Render(0);
1523 DALI_TEST_EQUALS( parent.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
1524 DALI_TEST_EQUALS( child.GetCurrentOrientation(), rotation, 0.001, TEST_LOCATION );
1526 // The actors should have a world rotation now
1527 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
1528 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), Quaternion( rotationAngle * 2.0f, Vector3::YAXIS ), 0.001, TEST_LOCATION );
1530 // turn off child rotation inheritance
1531 child.SetInheritOrientation( false );
1532 DALI_TEST_EQUALS( child.IsOrientationInherited(), false, TEST_LOCATION );
1533 application.SendNotification();
1534 application.Render(0);
1536 // The actors should have a world rotation now
1537 DALI_TEST_EQUALS( parent.GetCurrentWorldOrientation(), Quaternion( rotationAngle, Vector3::YAXIS ), 0.001, TEST_LOCATION );
1538 DALI_TEST_EQUALS( child.GetCurrentWorldOrientation(), rotation, 0.001, TEST_LOCATION );
1542 // SetScale(float scale)
1543 int UtcDaliActorSetScale01(void)
1545 TestApplication application;
1547 Actor actor = Actor::New();
1549 // Set to random value first - GetCurrentScale() asserts if called before SetScale()
1550 actor.SetScale(0.25f);
1552 Vector3 scale(10.0f, 10.0f, 10.0f);
1553 DALI_TEST_CHECK(actor.GetCurrentScale() != scale);
1555 actor.SetScale(scale.x);
1557 // flush the queue and render once
1558 application.SendNotification();
1559 application.Render();
1561 DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1565 // SetScale(float scaleX, float scaleY, float scaleZ)
1566 int UtcDaliActorSetScale02(void)
1568 TestApplication application;
1569 Vector3 scale(10.0f, 10.0f, 10.0f);
1571 Actor actor = Actor::New();
1573 // Set to random value first - GetCurrentScale() asserts if called before SetScale()
1574 actor.SetScale(Vector3(12.0f, 1.0f, 2.0f));
1576 DALI_TEST_CHECK(actor.GetCurrentScale() != scale);
1578 actor.SetScale(scale.x, scale.y, scale.z);
1579 // flush the queue and render once
1580 application.SendNotification();
1581 application.Render();
1582 DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1584 // add to stage and test
1585 Stage::GetCurrent().Add( actor );
1586 actor.SetScale( 2.0f, 2.0f, 2.0f );
1587 // flush the queue and render once
1588 application.SendNotification();
1589 application.Render();
1590 DALI_TEST_EQUALS( Vector3( 2.0f, 2.0f, 2.0f ), actor.GetCurrentScale(), 0.001, TEST_LOCATION);
1592 Stage::GetCurrent().Remove( actor );
1597 // SetScale(Vector3 scale)
1598 int UtcDaliActorSetScale03(void)
1600 TestApplication application;
1601 Vector3 scale(10.0f, 10.0f, 10.0f);
1603 Actor actor = Actor::New();
1605 // Set to random value first - GetCurrentScale() asserts if called before SetScale()
1606 actor.SetScale(Vector3(12.0f, 1.0f, 2.0f));
1608 DALI_TEST_CHECK(actor.GetCurrentScale() != scale);
1610 actor.SetScale(scale);
1612 // flush the queue and render once
1613 application.SendNotification();
1614 application.Render();
1616 DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1620 int UtcDaliActorScaleBy(void)
1622 TestApplication application;
1623 Actor actor = Actor::New();
1624 Vector3 vector(100.0f, 100.0f, 100.0f);
1626 DALI_TEST_CHECK(vector != actor.GetCurrentScale());
1628 actor.SetScale(vector);
1630 // flush the queue and render once
1631 application.SendNotification();
1632 application.Render();
1634 DALI_TEST_CHECK(vector == actor.GetCurrentScale());
1636 actor.ScaleBy(vector);
1638 // flush the queue and render once
1639 application.SendNotification();
1640 application.Render();
1642 DALI_TEST_CHECK(vector*100.0f == actor.GetCurrentScale());
1646 int UtcDaliActorGetCurrentScale(void)
1648 TestApplication application;
1649 Vector3 scale(12.0f, 1.0f, 2.0f);
1651 Actor actor = Actor::New();
1653 actor.SetScale(scale);
1655 // flush the queue and render once
1656 application.SendNotification();
1657 application.Render();
1659 DALI_TEST_CHECK(actor.GetCurrentScale() == scale);
1663 int UtcDaliActorGetCurrentWorldScale(void)
1665 TestApplication application;
1667 Actor parent = Actor::New();
1668 Vector3 parentScale( 1.0f, 2.0f, 3.0f );
1669 parent.SetScale( parentScale );
1670 Stage::GetCurrent().Add( parent );
1672 Actor child = Actor::New();
1673 Vector3 childScale( 2.0f, 2.0f, 2.0f );
1674 child.SetScale( childScale );
1675 parent.Add( child );
1677 // The actors should not have a scale yet
1678 DALI_TEST_EQUALS( parent.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
1679 DALI_TEST_EQUALS( child.GetCurrentScale(), Vector3::ONE, TEST_LOCATION );
1681 // The actors should not have a world scale yet
1682 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
1683 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), Vector3::ONE, TEST_LOCATION );
1685 application.SendNotification();
1686 application.Render(0);
1688 DALI_TEST_EQUALS( parent.GetCurrentScale(), parentScale, TEST_LOCATION );
1689 DALI_TEST_EQUALS( child.GetCurrentScale(), childScale, TEST_LOCATION );
1691 // The actors should have a world scale now
1692 DALI_TEST_EQUALS( parent.GetCurrentWorldScale(), parentScale, TEST_LOCATION );
1693 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), parentScale * childScale, TEST_LOCATION );
1697 int UtcDaliActorInheritScale(void)
1699 tet_infoline("Testing Actor::SetInheritScale");
1700 TestApplication application;
1702 Actor parent = Actor::New();
1703 Vector3 parentScale( 1.0f, 2.0f, 3.0f );
1704 parent.SetScale( parentScale );
1705 Stage::GetCurrent().Add( parent );
1707 Actor child = Actor::New();
1708 Vector3 childScale( 2.0f, 2.0f, 2.0f );
1709 child.SetScale( childScale );
1710 parent.Add( child );
1712 application.SendNotification();
1713 application.Render(0);
1715 DALI_TEST_EQUALS( child.IsScaleInherited(), true, TEST_LOCATION );
1716 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), parentScale * childScale, TEST_LOCATION );
1718 child.SetInheritScale( false );
1719 DALI_TEST_EQUALS( child.IsScaleInherited(), false, TEST_LOCATION );
1721 application.SendNotification();
1722 application.Render(0);
1724 DALI_TEST_EQUALS( child.GetCurrentWorldScale(), childScale, TEST_LOCATION );
1728 int UtcDaliActorSetVisible(void)
1730 TestApplication application;
1732 Actor actor = Actor::New();
1733 actor.SetVisible(false);
1734 // flush the queue and render once
1735 application.SendNotification();
1736 application.Render();
1737 DALI_TEST_CHECK(actor.IsVisible() == false);
1739 actor.SetVisible(true);
1740 // flush the queue and render once
1741 application.SendNotification();
1742 application.Render();
1743 DALI_TEST_CHECK(actor.IsVisible() == true);
1745 // put actor on stage
1746 Stage::GetCurrent().Add( actor );
1747 actor.SetVisible(false);
1748 // flush the queue and render once
1749 application.SendNotification();
1750 application.Render();
1751 DALI_TEST_CHECK(actor.IsVisible() == false);
1755 int UtcDaliActorIsVisible(void)
1757 TestApplication application;
1759 Actor actor = Actor::New();
1761 DALI_TEST_CHECK(actor.IsVisible() == true);
1765 int UtcDaliActorSetOpacity(void)
1767 TestApplication application;
1769 Actor actor = Actor::New();
1770 // initial opacity is 1
1771 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 1.0f, TEST_LOCATION );
1773 actor.SetOpacity( 0.4f);
1774 // flush the queue and render once
1775 application.SendNotification();
1776 application.Render();
1777 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.4f, TEST_LOCATION );
1779 // change opacity, actor is on stage to change is not immediate
1780 actor.SetOpacity( actor.GetCurrentOpacity() + 0.1f );
1781 // flush the queue and render once
1782 application.SendNotification();
1783 application.Render();
1784 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.5f, TEST_LOCATION );
1786 // put actor on stage
1787 Stage::GetCurrent().Add( actor );
1789 // change opacity, actor is on stage to change is not immediate
1790 actor.SetOpacity( 0.9f );
1791 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.5f, TEST_LOCATION );
1792 // flush the queue and render once
1793 application.SendNotification();
1794 application.Render();
1795 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.9f, TEST_LOCATION );
1797 // change opacity, actor is on stage to change is not immediate
1798 actor.SetOpacity( actor.GetCurrentOpacity() - 0.9f );
1799 // flush the queue and render once
1800 application.SendNotification();
1801 application.Render();
1802 DALI_TEST_EQUALS(actor.GetCurrentOpacity(), 0.0f, TEST_LOCATION );
1806 int UtcDaliActorGetCurrentOpacity(void)
1808 TestApplication application;
1810 Actor actor = Actor::New();
1811 DALI_TEST_CHECK(actor.GetCurrentOpacity() != 0.5f);
1813 actor.SetOpacity(0.5f);
1814 // flush the queue and render once
1815 application.SendNotification();
1816 application.Render();
1817 DALI_TEST_CHECK(actor.GetCurrentOpacity() == 0.5f);
1821 int UtcDaliActorSetSensitive(void)
1823 TestApplication application;
1824 Actor actor = Actor::New();
1826 bool sensitive = !actor.IsSensitive();
1828 actor.SetSensitive(sensitive);
1830 DALI_TEST_CHECK(sensitive == actor.IsSensitive());
1834 int UtcDaliActorIsSensitive(void)
1836 TestApplication application;
1837 Actor actor = Actor::New();
1838 actor.SetSensitive(false);
1840 DALI_TEST_CHECK(false == actor.IsSensitive());
1844 int UtcDaliActorSetColor(void)
1846 TestApplication application;
1847 Actor actor = Actor::New();
1848 Vector4 color(1.0f, 1.0f, 1.0f, 0.5f);
1850 DALI_TEST_CHECK(color != actor.GetCurrentColor());
1852 actor.SetColor(color);
1853 // flush the queue and render once
1854 application.SendNotification();
1855 application.Render();
1856 DALI_TEST_CHECK(color == actor.GetCurrentColor());
1858 actor.SetColor( actor.GetCurrentColor() + Vector4( -0.4f, -0.5f, -0.6f, -0.4f ) );
1859 // flush the queue and render once
1860 application.SendNotification();
1861 application.Render();
1862 DALI_TEST_EQUALS( Vector4( 0.6f, 0.5f, 0.4f, 0.1f ), actor.GetCurrentColor(), TEST_LOCATION );
1864 Stage::GetCurrent().Add( actor );
1865 actor.SetColor( color );
1866 // flush the queue and render once
1867 application.SendNotification();
1868 application.Render();
1869 DALI_TEST_EQUALS( color, actor.GetCurrentColor(), TEST_LOCATION );
1871 actor.SetColor( actor.GetCurrentColor() + Vector4( 1.1f, 1.1f, 1.1f, 1.1f ) );
1872 // flush the queue and render once
1873 application.SendNotification();
1874 application.Render();
1875 // Actor color is not clamped
1876 DALI_TEST_EQUALS( Vector4( 2.1f, 2.1f, 2.1f, 1.6f ), actor.GetCurrentColor(), TEST_LOCATION );
1877 // world color is clamped
1878 DALI_TEST_EQUALS( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), actor.GetCurrentWorldColor(), TEST_LOCATION );
1880 Stage::GetCurrent().Remove( actor );
1884 int UtcDaliActorGetCurrentColor(void)
1886 TestApplication application;
1887 Actor actor = Actor::New();
1888 Vector4 color(1.0f, 1.0f, 1.0f, 0.5f);
1890 actor.SetColor(color);
1891 // flush the queue and render once
1892 application.SendNotification();
1893 application.Render();
1894 DALI_TEST_CHECK(color == actor.GetCurrentColor());
1898 int UtcDaliActorGetCurrentWorldColor(void)
1900 tet_infoline("Actor::GetCurrentWorldColor");
1901 TestApplication application;
1903 Actor parent = Actor::New();
1904 Vector4 parentColor( 1.0f, 0.5f, 0.0f, 0.8f );
1905 parent.SetColor( parentColor );
1906 Stage::GetCurrent().Add( parent );
1908 Actor child = Actor::New();
1909 Vector4 childColor( 0.5f, 0.6f, 0.5f, 1.0f );
1910 child.SetColor( childColor );
1911 parent.Add( child );
1913 DALI_TEST_EQUALS( parent.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
1914 DALI_TEST_EQUALS( child.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
1916 // verify the default color mode
1917 DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_ALPHA, child.GetColorMode(), TEST_LOCATION );
1919 // The actors should not have a world color yet
1920 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
1921 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Color::WHITE, TEST_LOCATION );
1923 application.SendNotification();
1924 application.Render(0);
1926 DALI_TEST_EQUALS( parent.GetCurrentColor(), parentColor, TEST_LOCATION );
1927 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
1929 // The actors should have a world color now
1930 DALI_TEST_EQUALS( parent.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
1931 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), Vector4( childColor.r, childColor.g, childColor.b, childColor.a * parentColor.a), TEST_LOCATION );
1934 child.SetColorMode( USE_OWN_COLOR );
1935 application.SendNotification();
1936 application.Render(0);
1937 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), childColor, TEST_LOCATION );
1940 child.SetColorMode( USE_PARENT_COLOR );
1941 application.SendNotification();
1942 application.Render(0);
1943 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
1944 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), parentColor, TEST_LOCATION );
1947 child.SetColorMode( USE_OWN_MULTIPLY_PARENT_ALPHA );
1948 application.SendNotification();
1949 application.Render(0);
1950 Vector4 expectedColor( childColor );
1951 expectedColor.a *= parentColor.a;
1952 DALI_TEST_EQUALS( child.GetCurrentColor(), childColor, TEST_LOCATION );
1953 DALI_TEST_EQUALS( child.GetCurrentWorldColor(), expectedColor, TEST_LOCATION );
1957 int UtcDaliActorSetColorMode(void)
1959 tet_infoline("Actor::SetColorMode");
1960 TestApplication application;
1961 Actor actor = Actor::New();
1962 Actor child = Actor::New();
1965 actor.SetColorMode( USE_OWN_COLOR );
1966 DALI_TEST_EQUALS( USE_OWN_COLOR, actor.GetColorMode(), TEST_LOCATION );
1968 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
1969 DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_COLOR, actor.GetColorMode(), TEST_LOCATION );
1971 actor.SetColorMode( USE_PARENT_COLOR );
1972 DALI_TEST_EQUALS( USE_PARENT_COLOR, actor.GetColorMode(), TEST_LOCATION );
1974 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_ALPHA );
1975 DALI_TEST_EQUALS( USE_OWN_MULTIPLY_PARENT_ALPHA, actor.GetColorMode(), TEST_LOCATION );
1979 int UtcDaliActorScreenToLocal(void)
1981 TestApplication application;
1982 Actor actor = Actor::New();
1983 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1984 actor.SetSize(100.0f, 100.0f);
1985 actor.SetPosition(10.0f, 10.0f);
1986 Stage::GetCurrent().Add(actor);
1988 // flush the queue and render once
1989 application.SendNotification();
1990 application.Render();
1995 DALI_TEST_CHECK( actor.ScreenToLocal(localX, localY, 50.0f, 50.0f) );
1997 DALI_TEST_EQUALS(localX, 40.0f, 0.01f, TEST_LOCATION);
1998 DALI_TEST_EQUALS(localY, 40.0f, 0.01f, TEST_LOCATION);
2002 int UtcDaliActorSetLeaveRequired(void)
2004 TestApplication application;
2006 Actor actor = Actor::New();
2008 actor.SetLeaveRequired(false);
2009 DALI_TEST_CHECK(actor.GetLeaveRequired() == false);
2011 actor.SetLeaveRequired(true);
2012 DALI_TEST_CHECK(actor.GetLeaveRequired() == true);
2016 int UtcDaliActorGetLeaveRequired(void)
2018 TestApplication application;
2020 Actor actor = Actor::New();
2022 DALI_TEST_CHECK(actor.GetLeaveRequired() == false);
2026 int UtcDaliActorSetKeyboardFocusable(void)
2028 TestApplication application;
2030 Actor actor = Actor::New();
2032 actor.SetKeyboardFocusable(true);
2033 DALI_TEST_CHECK(actor.IsKeyboardFocusable() == true);
2035 actor.SetKeyboardFocusable(false);
2036 DALI_TEST_CHECK(actor.IsKeyboardFocusable() == false);
2040 int UtcDaliActorIsKeyboardFocusable(void)
2042 TestApplication application;
2044 Actor actor = Actor::New();
2046 DALI_TEST_CHECK(actor.IsKeyboardFocusable() == false);
2051 int UtcDaliActorApplyConstraint(void)
2053 TestApplication application;
2055 gTestConstraintCalled = false;
2057 Actor actor = Actor::New();
2059 Constraint constraint = Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraint() );
2060 actor.ApplyConstraint(constraint);
2062 DALI_TEST_CHECK( gTestConstraintCalled == false );
2064 Stage::GetCurrent().Add( actor );
2066 // flush the queue and render once
2067 application.SendNotification();
2068 application.Render();
2070 DALI_TEST_CHECK( gTestConstraintCalled == true );
2075 int UtcDaliActorApplyConstraintAppliedCallback(void)
2077 TestApplication application;
2079 // Build a reusable constraint
2081 Actor parent = Actor::New();
2082 Vector3 parentSize( 100.0f, 100.0f, 100.0f );
2083 parent.SetSize( parentSize );
2084 Stage::GetCurrent().Add( parent );
2086 Constraint constraint = Constraint::New<Vector3>( Actor::Property::SIZE,
2087 Source( parent, Actor::Property::SIZE ),
2088 EqualToConstraint() );
2090 // Create some child actors
2092 Actor child1 = Actor::New();
2093 parent.Add( child1 );
2095 Actor child2 = Actor::New();
2096 parent.Add( child2 );
2098 Actor child3 = Actor::New();
2099 parent.Add( child3 );
2101 // Apply constraint with different timings - everything should be finished after 10 seconds
2103 wasConstraintCallbackCalled1 = false;
2104 wasConstraintCallbackCalled2 = false;
2105 wasConstraintCallbackCalled3 = false;
2107 constraint.SetApplyTime( 5.0f );
2108 ActiveConstraint activeConstraint1 = child1.ApplyConstraint( constraint );
2109 activeConstraint1.AppliedSignal().Connect( TestConstraintCallback1 );
2111 constraint.SetApplyTime( 10.0f );
2112 ActiveConstraint activeConstraint2 = child2.ApplyConstraint( constraint );
2113 activeConstraint2.AppliedSignal().Connect( TestConstraintCallback2 );
2115 constraint.SetApplyTime( TimePeriod( 2.0f/*delay*/, 5.0f/*duration*/ ) );
2116 ActiveConstraint activeConstraint3 = child3.ApplyConstraint( constraint );
2117 activeConstraint3.AppliedSignal().Connect( TestConstraintCallback3 );
2119 // Check event-side size
2120 DALI_TEST_EQUALS( child1.GetSize(), Vector3::ZERO, TEST_LOCATION );
2121 DALI_TEST_EQUALS( child2.GetSize(), Vector3::ZERO, TEST_LOCATION );
2122 DALI_TEST_EQUALS( child3.GetSize(), Vector3::ZERO, TEST_LOCATION );
2124 DALI_TEST_EQUALS( child1.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2125 DALI_TEST_EQUALS( child2.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2126 DALI_TEST_EQUALS( child3.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
2128 application.SendNotification();
2130 application.Render(static_cast<unsigned int>(1000.0f)); // 1 elapsed second
2132 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize*0.20f, TEST_LOCATION ); // 1 / 5 * 100 = 20%
2133 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.10f, TEST_LOCATION ); // 1 / 10 * 100 = 10%
2134 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.00f, TEST_LOCATION ); // 0%
2136 // Check signals have not fired
2137 application.SendNotification();
2138 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2139 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2140 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2142 application.Render(static_cast<unsigned int>(1000.0f)); // 2 elapsed seconds
2143 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize*0.40f, TEST_LOCATION ); // 2 / 5 * 100 = 40%
2144 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.20f, TEST_LOCATION ); // 2 / 10 * 100 = 20%
2145 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.00f, TEST_LOCATION ); // 0%
2147 // Check signals have not fired
2148 application.SendNotification();
2149 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2150 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2151 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2153 application.Render(static_cast<unsigned int>(1000.0f)); // 3 elapsed seconds
2154 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize*0.60f, TEST_LOCATION ); // 3 / 5 * 100 = 60%
2155 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.30f, TEST_LOCATION ); // 3 / 10 * 100 = 30%
2156 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.20f, TEST_LOCATION ); // (3 - 2) / 5 * 100 = 20%
2158 // Check signals have not fired
2159 application.SendNotification();
2160 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2161 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2162 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2164 application.Render(static_cast<unsigned int>(1000.0f)); // 4 elapsed seconds
2165 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize*0.80f, TEST_LOCATION ); // 4 / 5 * 100 = 80%
2166 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.40f, TEST_LOCATION ); // 4 / 10 * 100 = 40%
2167 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.40f, TEST_LOCATION ); // (4 - 2) / 5 * 100 = 40%
2169 // Check signals have not fired
2170 application.SendNotification();
2171 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2172 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2173 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2175 application.Render(static_cast<unsigned int>(1000.0f)); // 5 elapsed seconds
2176 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // 5 / 5 * 100 = 100%
2177 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.50f, TEST_LOCATION ); // 5 / 10 * 100 = 50%
2178 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.60f, TEST_LOCATION ); // (5 - 2) / 5 * 100 = 60%
2180 // Check signals have not fired
2181 application.SendNotification();
2182 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2183 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2184 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2186 application.Render(static_cast<unsigned int>(1000.0f)); // 6 elapsed seconds
2187 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% (signal 1 should fire)
2188 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.60f, TEST_LOCATION ); // 6 / 10 * 100 = 60%
2189 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.80f, TEST_LOCATION ); // (6 - 2) / 5 * 100 = 80%
2191 // 1st signal should have fired
2192 application.SendNotification();
2193 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, true, TEST_LOCATION );
2194 wasConstraintCallbackCalled1 = false;
2195 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2196 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2198 application.Render(static_cast<unsigned int>(1000.0f)); // 7 elapsed seconds
2199 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100%
2200 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.70f, TEST_LOCATION ); // 7 / 10 * 100 = 70%
2201 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); // (7 - 2) / 5 * 100 = 100%
2203 // Check signals have not fired
2204 application.SendNotification();
2205 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2206 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2207 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2209 application.Render(static_cast<unsigned int>(1000.0f)); // 8 elapsed seconds
2210 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100%
2211 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.80f, TEST_LOCATION ); // 8 / 10 * 100 = 80%
2212 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% (signal 3 should fire)
2214 // 3rd signal should have fired
2215 application.SendNotification();
2217 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2218 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2219 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, true, TEST_LOCATION );
2220 wasConstraintCallbackCalled3 = false;
2222 application.Render(static_cast<unsigned int>(1000.0f)); // 9 elapsed seconds
2223 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100%
2224 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.90f, TEST_LOCATION ); // 9 / 10 * 100 = 90%
2225 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100%
2227 // Check signals have not fired
2228 application.SendNotification();
2229 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2230 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2231 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2233 application.Render(static_cast<unsigned int>(1000.0f + 1.0f)); // over 10 elapsed seconds
2234 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100%
2235 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100% (signal 2 should fire)
2236 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION ); // Past 100%
2238 // 2nd signal should have fired
2239 application.SendNotification();
2240 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2241 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, true, TEST_LOCATION );
2242 wasConstraintCallbackCalled2 = false;
2243 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2245 // Check that nothing has changed after a couple of buffer swaps
2247 application.Render(0);
2248 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION );
2249 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize, TEST_LOCATION );
2250 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION );
2252 application.SendNotification();
2253 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2254 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2255 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2257 application.Render(0);
2258 DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize, TEST_LOCATION );
2259 DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize, TEST_LOCATION );
2260 DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize, TEST_LOCATION );
2262 application.SendNotification();
2263 DALI_TEST_EQUALS( wasConstraintCallbackCalled1, false, TEST_LOCATION );
2264 DALI_TEST_EQUALS( wasConstraintCallbackCalled2, false, TEST_LOCATION );
2265 DALI_TEST_EQUALS( wasConstraintCallbackCalled3, false, TEST_LOCATION );
2269 int UtcDaliActorRemoveConstraints(void)
2271 tet_infoline(" UtcDaliActorRemoveConstraints");
2272 TestApplication application;
2274 gTestConstraintCalled = false;
2276 Actor actor = Actor::New();
2278 Constraint constraint = Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraint() );
2279 actor.ApplyConstraint(constraint);
2280 actor.RemoveConstraints();
2282 DALI_TEST_CHECK( gTestConstraintCalled == false );
2284 Stage::GetCurrent().Add( actor );
2285 actor.ApplyConstraint(constraint);
2287 // flush the queue and render once
2288 application.SendNotification();
2289 application.Render();
2291 actor.RemoveConstraints();
2293 DALI_TEST_CHECK( gTestConstraintCalled == true );
2297 int UtcDaliActorRemoveConstraint(void)
2299 tet_infoline(" UtcDaliActorRemoveConstraint");
2300 TestApplication application;
2302 Actor actor = Actor::New();
2304 // 1. Apply Constraint1 and Constraint2, and test...
2305 unsigned int result1 = 0u;
2306 unsigned int result2 = 0u;
2307 ActiveConstraint activeConstraint1 = actor.ApplyConstraint( Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraintRef<Vector4>(result1, 1) ) );
2308 ActiveConstraint activeConstraint2 = actor.ApplyConstraint( Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraintRef<Vector4>(result2, 2) ) );
2310 Stage::GetCurrent().Add( actor );
2311 // flush the queue and render once
2312 application.SendNotification();
2313 application.Render();
2315 DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
2316 DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
2318 // 2. Remove Constraint1 and test...
2321 actor.RemoveConstraint(activeConstraint1);
2322 // make color property dirty, which will trigger constraints to be reapplied.
2323 actor.SetColor( Color::WHITE );
2324 // flush the queue and render once
2325 application.SendNotification();
2326 application.Render();
2328 DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now.
2329 DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
2331 // 3. Re-Apply Constraint1 and test...
2334 activeConstraint1 = actor.ApplyConstraint( Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraintRef<Vector4>(result1, 1) ) );
2335 // make color property dirty, which will trigger constraints to be reapplied.
2336 actor.SetColor( Color::WHITE );
2337 // flush the queue and render once
2338 application.SendNotification();
2339 application.Render();
2341 DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
2342 DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
2344 // 2. Remove Constraint2 and test...
2347 actor.RemoveConstraint(activeConstraint2);
2348 // make color property dirty, which will trigger constraints to be reapplied.
2349 actor.SetColor( Color::WHITE );
2350 // flush the queue and render once
2351 application.SendNotification();
2352 application.Render();
2354 DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
2355 DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
2357 // 2. Remove Constraint1 as well and test...
2360 actor.RemoveConstraint(activeConstraint1);
2361 // make color property dirty, which will trigger constraints to be reapplied.
2362 actor.SetColor( Color::WHITE );
2363 // flush the queue and render once
2364 application.SendNotification();
2365 application.Render();
2367 DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now.
2368 DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
2372 int UtcDaliActorRemoveConstraintTag(void)
2374 tet_infoline(" UtcDaliActorRemoveConstraintTag");
2375 TestApplication application;
2377 Actor actor = Actor::New();
2379 // 1. Apply Constraint1 and Constraint2, and test...
2380 unsigned int result1 = 0u;
2381 unsigned int result2 = 0u;
2383 unsigned constraint1Tag = 1u;
2384 Constraint constraint1 = Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraintRef<Vector4>(result1, 1) );
2385 constraint1.SetTag( constraint1Tag );
2386 actor.ApplyConstraint( constraint1 );
2388 unsigned constraint2Tag = 2u;
2389 Constraint constraint2 = Constraint::New<Vector4>( Actor::Property::COLOR, TestConstraintRef<Vector4>(result2, 2) );
2390 constraint2.SetTag( constraint2Tag );
2391 actor.ApplyConstraint( constraint2 );
2393 Stage::GetCurrent().Add( actor );
2394 // flush the queue and render once
2395 application.SendNotification();
2396 application.Render();
2398 DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
2399 DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
2401 // 2. Remove Constraint1 and test...
2404 actor.RemoveConstraints(constraint1Tag);
2405 // make color property dirty, which will trigger constraints to be reapplied.
2406 actor.SetColor( Color::WHITE );
2407 // flush the queue and render once
2408 application.SendNotification();
2409 application.Render();
2411 DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now.
2412 DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
2414 // 3. Re-Apply Constraint1 and test...
2417 actor.ApplyConstraint( constraint1 );
2418 // make color property dirty, which will trigger constraints to be reapplied.
2419 actor.SetColor( Color::WHITE );
2420 // flush the queue and render once
2421 application.SendNotification();
2422 application.Render();
2424 DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
2425 DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
2427 // 2. Remove Constraint2 and test...
2430 actor.RemoveConstraints(constraint2Tag);
2431 // make color property dirty, which will trigger constraints to be reapplied.
2432 actor.SetColor( Color::WHITE );
2433 // flush the queue and render once
2434 application.SendNotification();
2435 application.Render();
2437 DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
2438 DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
2440 // 2. Remove Constraint1 as well and test...
2443 actor.RemoveConstraints(constraint1Tag);
2444 // make color property dirty, which will trigger constraints to be reapplied.
2445 actor.SetColor( Color::WHITE );
2446 // flush the queue and render once
2447 application.SendNotification();
2448 application.Render();
2450 DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now.
2451 DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
2455 int UtcDaliActorTouchedSignal(void)
2457 TestApplication application;
2459 gTouchCallBackCalled = false;
2461 // get the root layer
2462 Actor actor = Stage::GetCurrent().GetRootLayer();
2463 DALI_TEST_CHECK( gTouchCallBackCalled == false );
2465 application.SendNotification();
2466 application.Render();
2468 // connect to its touch signal
2469 actor.TouchedSignal().Connect( TestCallback );
2471 // simulate a touch event in the middle of the screen
2472 Vector2 touchPoint( Stage::GetCurrent().GetSize() * 0.5 );
2473 Dali::TouchPoint point( 1, TouchPoint::Down, touchPoint.x, touchPoint.y );
2474 Dali::Integration::TouchEvent event;
2475 event.AddPoint( point );
2476 application.ProcessEvent( event );
2478 DALI_TEST_CHECK( gTouchCallBackCalled == true );
2482 int UtcDaliActorHoveredSignal(void)
2484 TestApplication application;
2486 gHoverCallBackCalled = false;
2488 // get the root layer
2489 Actor actor = Stage::GetCurrent().GetRootLayer();
2490 DALI_TEST_CHECK( gHoverCallBackCalled == false );
2492 application.SendNotification();
2493 application.Render();
2495 // connect to its hover signal
2496 actor.HoveredSignal().Connect( TestCallback3 );
2498 // simulate a hover event in the middle of the screen
2499 Vector2 touchPoint( Stage::GetCurrent().GetSize() * 0.5 );
2500 Dali::TouchPoint point( 1, TouchPoint::Motion, touchPoint.x, touchPoint.y );
2501 Dali::Integration::HoverEvent event;
2502 event.AddPoint( point );
2503 application.ProcessEvent( event );
2505 DALI_TEST_CHECK( gHoverCallBackCalled == true );
2509 int UtcDaliActorOnOffStageSignal(void)
2511 tet_infoline("Testing Dali::Actor::OnStageSignal() and OffStageSignal()");
2513 TestApplication application;
2516 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2517 gActorNamesOnOffStage.clear();
2519 Actor parent = Actor::New();
2520 parent.SetName( "parent" );
2521 parent.OnStageSignal().Connect( OnStageCallback );
2522 parent.OffStageSignal().Connect( OffStageCallback );
2524 DALI_TEST_CHECK( gOnStageCallBackCalled == 0 );
2525 DALI_TEST_CHECK( gOffStageCallBackCalled == 0 );
2527 // add parent to stage
2528 Stage::GetCurrent().Add( parent );
2529 // onstage emitted, offstage not
2530 DALI_TEST_EQUALS( gOnStageCallBackCalled, 1, TEST_LOCATION );
2531 DALI_TEST_EQUALS( gOffStageCallBackCalled, 0, TEST_LOCATION );
2532 DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2534 // test adding a child, should get onstage emitted
2536 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2537 gActorNamesOnOffStage.clear();
2539 Actor child = Actor::New();
2540 child.SetName( "child" );
2541 child.OnStageSignal().Connect( OnStageCallback );
2542 child.OffStageSignal().Connect( OffStageCallback );
2543 parent.Add( child ); // add child
2544 // onstage emitted, offstage not
2545 DALI_TEST_EQUALS( gOnStageCallBackCalled, 1, TEST_LOCATION );
2546 DALI_TEST_EQUALS( gOffStageCallBackCalled, 0, TEST_LOCATION );
2547 DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2549 // test removing parent from stage
2551 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2552 gActorNamesOnOffStage.clear();
2554 Stage::GetCurrent().Remove( parent );
2555 // onstage not emitted, offstage is
2556 DALI_TEST_EQUALS( gOnStageCallBackCalled, 0, TEST_LOCATION );
2557 DALI_TEST_EQUALS( gOffStageCallBackCalled, 2, TEST_LOCATION );
2558 DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2559 DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 1 ], TEST_LOCATION );
2561 // test adding parent back to stage
2563 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2564 gActorNamesOnOffStage.clear();
2566 Stage::GetCurrent().Add( parent );
2567 // onstage emitted, offstage not
2568 DALI_TEST_EQUALS( gOnStageCallBackCalled, 2, TEST_LOCATION );
2569 DALI_TEST_EQUALS( gOffStageCallBackCalled, 0, TEST_LOCATION );
2570 DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2571 DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 1 ], TEST_LOCATION );
2573 // test removing child
2575 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2576 gActorNamesOnOffStage.clear();
2578 parent.Remove( child );
2579 // onstage not emitted, offstage is
2580 DALI_TEST_EQUALS( gOnStageCallBackCalled, 0, TEST_LOCATION );
2581 DALI_TEST_EQUALS( gOffStageCallBackCalled, 1, TEST_LOCATION );
2582 DALI_TEST_EQUALS( "child", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2584 // test removing parent
2586 gOnStageCallBackCalled = gOffStageCallBackCalled = 0;
2587 gActorNamesOnOffStage.clear();
2589 Stage::GetCurrent().Remove( parent );
2590 // onstage not emitted, offstage is
2591 DALI_TEST_EQUALS( gOnStageCallBackCalled, 0, TEST_LOCATION );
2592 DALI_TEST_EQUALS( gOffStageCallBackCalled, 1, TEST_LOCATION );
2593 DALI_TEST_EQUALS( "parent", gActorNamesOnOffStage[ 0 ], TEST_LOCATION );
2597 int UtcDaliActorFindChildByName(void)
2599 tet_infoline("Testing Dali::Actor::FindChildByName()");
2600 TestApplication application;
2602 Actor parent = Actor::New();
2603 parent.SetName( "parent" );
2604 Actor first = Actor::New();
2605 first .SetName( "first" );
2606 Actor second = Actor::New();
2607 second.SetName( "second" );
2612 Actor found = parent.FindChildByName( "foo" );
2613 DALI_TEST_CHECK( !found );
2615 found = parent.FindChildByName( "parent" );
2616 DALI_TEST_CHECK( found == parent );
2618 found = parent.FindChildByName( "first" );
2619 DALI_TEST_CHECK( found == first );
2621 found = parent.FindChildByName( "second" );
2622 DALI_TEST_CHECK( found == second );
2626 int UtcDaliActorFindChildById(void)
2628 tet_infoline("Testing Dali::Actor::UtcDaliActorFindChildById()");
2629 TestApplication application;
2631 Actor parent = Actor::New();
2632 Actor first = Actor::New();
2633 Actor second = Actor::New();
2638 Actor found = parent.FindChildById( 100000 );
2639 DALI_TEST_CHECK( !found );
2641 found = parent.FindChildById( parent.GetId() );
2642 DALI_TEST_CHECK( found == parent );
2644 found = parent.FindChildById( first.GetId() );
2645 DALI_TEST_CHECK( found == first );
2647 found = parent.FindChildById( second.GetId() );
2648 DALI_TEST_CHECK( found == second );
2652 int UtcDaliActorHitTest(void)
2657 HitTestData( const Vector3& scale, const Vector2& touchPoint, bool result )
2659 mTouchPoint( touchPoint ),
2664 Vector2 mTouchPoint;
2668 TestApplication application;
2669 tet_infoline(" UtcDaliActorHitTest");
2671 // Fill a vector with different hit tests.
2672 struct HitTestData* hitTestData[] = {
2673 // scale touch point result
2674 new HitTestData( Vector3( 100.f, 100.f, 1.f ), Vector2( 289.f, 400.f ), true ), // touch point close to the right edge (inside)
2675 new HitTestData( Vector3( 100.f, 100.f, 1.f ), Vector2( 291.f, 400.f ), false ), // touch point close to the right edge (outside)
2676 new HitTestData( Vector3( 110.f, 100.f, 1.f ), Vector2( 291.f, 400.f ), true ), // same point as above with a wider scale. Should be inside.
2677 new HitTestData( Vector3( 100.f, 100.f, 1.f ), Vector2( 200.f, 451.f ), false ), // touch point close to the down edge (outside)
2678 new HitTestData( Vector3( 100.f, 110.f, 1.f ), Vector2( 200.f, 451.f ), true ), // same point as above with a wider scale. Should be inside.
2682 // get the root layer
2683 Actor actor = Actor::New();
2684 actor.SetAnchorPoint( AnchorPoint::CENTER );
2685 actor.SetParentOrigin( ParentOrigin::CENTER );
2687 Stage::GetCurrent().Add( actor );
2689 gTouchCallBackCalled = false;
2691 unsigned int index = 0;
2692 while( NULL != hitTestData[index] )
2694 actor.SetSize( 1.f, 1.f );
2695 actor.SetScale( hitTestData[index]->mScale.x, hitTestData[index]->mScale.y, hitTestData[index]->mScale.z );
2697 // flush the queue and render once
2698 application.SendNotification();
2699 application.Render();
2701 DALI_TEST_CHECK( !gTouchCallBackCalled );
2703 // connect to its touch signal
2704 actor.TouchedSignal().Connect(TestCallback);
2706 Dali::TouchPoint point( 0, TouchPoint::Down, hitTestData[index]->mTouchPoint.x, hitTestData[index]->mTouchPoint.y );
2707 Dali::Integration::TouchEvent event;
2708 event.AddPoint( point );
2710 // flush the queue and render once
2711 application.SendNotification();
2712 application.Render();
2713 application.ProcessEvent( event );
2715 DALI_TEST_CHECK( gTouchCallBackCalled == hitTestData[index]->mResult );
2717 if( gTouchCallBackCalled != hitTestData[index]->mResult )
2718 tet_printf("Test failed:\nScale %f %f %f\nTouchPoint %f, %f\nResult %d\n",
2719 hitTestData[index]->mScale.x, hitTestData[index]->mScale.y, hitTestData[index]->mScale.z,
2720 hitTestData[index]->mTouchPoint.x, hitTestData[index]->mTouchPoint.y,
2721 hitTestData[index]->mResult );
2723 gTouchCallBackCalled = false;
2729 int UtcDaliActorSetDrawMode(void)
2731 TestApplication app;
2732 tet_infoline(" UtcDaliActorSetDrawModeOverlay");
2734 Actor a = Actor::New();
2736 Stage::GetCurrent().Add(a);
2737 app.SendNotification();
2739 app.SendNotification();
2742 DALI_TEST_CHECK( DrawMode::NORMAL == a.GetDrawMode() ); // Ensure overlay is off by default
2744 a.SetDrawMode( DrawMode::OVERLAY );
2745 app.SendNotification();
2748 DALI_TEST_CHECK( DrawMode::OVERLAY == a.GetDrawMode() ); // Check Actor is overlay
2750 a.SetDrawMode( DrawMode::STENCIL );
2751 app.SendNotification();
2754 DALI_TEST_CHECK( DrawMode::STENCIL == a.GetDrawMode() ); // Check Actor is stencil, not overlay
2756 a.SetDrawMode( DrawMode::NORMAL );
2757 app.SendNotification();
2760 DALI_TEST_CHECK( DrawMode::NORMAL == a.GetDrawMode() ); // Check Actor is not stencil
2764 int UtcDaliActorSetDrawModeOverlayRender(void)
2766 TestApplication app;
2767 tet_infoline(" UtcDaliActorSetDrawModeOverlayRender");
2769 app.SendNotification();
2772 std::vector<GLuint> ids;
2773 ids.push_back( 8 ); // first rendered actor
2774 ids.push_back( 9 ); // second rendered actor
2775 ids.push_back( 10 ); // third rendered actor
2776 app.GetGlAbstraction().SetNextTextureIds( ids );
2778 BufferImage imageA = BufferImage::New(16, 16);
2779 BufferImage imageB = BufferImage::New(16, 16);
2780 BufferImage imageC = BufferImage::New(16, 16);
2781 ImageActor a = ImageActor::New( imageA );
2782 ImageActor b = ImageActor::New( imageB );
2783 ImageActor c = ImageActor::New( imageC );
2785 // Render a,b,c as regular non-overlays. so order will be:
2789 Stage::GetCurrent().Add(a);
2790 Stage::GetCurrent().Add(b);
2791 Stage::GetCurrent().Add(c);
2793 app.SendNotification();
2796 // Should be 3 textures changes.
2797 const std::vector<GLuint>& boundTextures = app.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
2798 typedef std::vector<GLuint>::size_type TextureSize;
2799 DALI_TEST_EQUALS( boundTextures.size(), static_cast<TextureSize>( 3 ), TEST_LOCATION );
2800 if( boundTextures.size() == 3 )
2802 DALI_TEST_CHECK( boundTextures[0] == 8u );
2803 DALI_TEST_CHECK( boundTextures[1] == 9u );
2804 DALI_TEST_CHECK( boundTextures[2] == 10u );
2807 // Now texture ids have been set, we can monitor their render order.
2808 // render a as an overlay (last), so order will be:
2812 a.SetDrawMode( DrawMode::OVERLAY );
2813 app.GetGlAbstraction().ClearBoundTextures();
2815 app.SendNotification();
2818 // Should be 3 texture changes.
2819 DALI_TEST_EQUALS( boundTextures.size(), static_cast<TextureSize>(3), TEST_LOCATION );
2820 if( boundTextures.size() == 3 )
2822 DALI_TEST_CHECK( boundTextures[0] == 9u );
2823 DALI_TEST_CHECK( boundTextures[1] == 10u );
2824 DALI_TEST_CHECK( boundTextures[2] == 8u );
2830 int UtcDaliActorSetDrawModeOverlayHitTest(void)
2832 TestApplication app;
2833 tet_infoline(" UtcDaliActorSetDrawModeOverlayHitTest");
2835 BufferImage imageA = BufferImage::New(16, 16);
2836 BufferImage imageB = BufferImage::New(16, 16);
2837 ImageActor a = ImageActor::New( imageA );
2838 ImageActor b = ImageActor::New( imageB );
2840 // Render a,b as regular non-overlays. so order will be:
2841 Stage::GetCurrent().Add(a);
2842 Stage::GetCurrent().Add(b);
2844 a.SetSize(Vector2(100.0f, 100.0f));
2845 b.SetSize(Vector2(100.0f, 100.0f));
2847 // position b overlapping a. (regular non-overlays)
2848 // hit test at point 'x'
2859 // note: b is on top, because it's Z position is higher.
2860 a.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
2861 b.SetPosition(Vector3(50.0f, 50.0f, 1.0f));
2863 // connect to their touch signals
2864 a.TouchedSignal().Connect(TestCallback);
2865 b.TouchedSignal().Connect(TestCallback2);
2867 a.SetDrawMode( DrawMode::NORMAL );
2868 b.SetDrawMode( DrawMode::NORMAL );
2869 SimulateTouchForSetOverlayHitTest(app);
2871 DALI_TEST_CHECK( gTouchCallBackCalled == false );
2872 DALI_TEST_CHECK( gTouchCallBack2Called == true );
2873 // Make Actor a an overlay.
2884 // note: a is on top, because it is an overlay.
2885 a.SetDrawMode( DrawMode::OVERLAY );
2886 b.SetDrawMode( DrawMode::NORMAL );
2887 SimulateTouchForSetOverlayHitTest(app);
2889 DALI_TEST_CHECK( gTouchCallBackCalled == true );
2890 DALI_TEST_CHECK( gTouchCallBack2Called == false );
2891 // Make both Actors as overlays
2902 // note: b is on top, because it is the 2nd child in the hierarchy.
2903 a.SetDrawMode( DrawMode::OVERLAY );
2904 b.SetDrawMode( DrawMode::OVERLAY );
2905 SimulateTouchForSetOverlayHitTest(app);
2907 DALI_TEST_CHECK( gTouchCallBackCalled == false );
2908 DALI_TEST_CHECK( gTouchCallBack2Called == true );
2912 int UtcDaliActorGetCurrentWorldMatrix(void)
2914 TestApplication app;
2915 tet_infoline(" UtcDaliActorGetCurrentWorldMatrix");
2917 Actor parent = Actor::New();
2918 parent.SetParentOrigin(ParentOrigin::CENTER);
2919 parent.SetAnchorPoint(AnchorPoint::CENTER);
2920 Vector3 parentPosition( 10.0f, 20.0f, 30.0f);
2921 Radian rotationAngle(Degree(85.0f));
2922 Quaternion parentRotation(rotationAngle, Vector3::ZAXIS);
2923 Vector3 parentScale( 1.0f, 2.0f, 3.0f );
2924 parent.SetPosition( parentPosition );
2925 parent.SetOrientation( parentRotation );
2926 parent.SetScale( parentScale );
2927 Stage::GetCurrent().Add( parent );
2929 Actor child = Actor::New();
2930 child.SetParentOrigin(ParentOrigin::CENTER);
2931 Vector3 childPosition( 0.0f, 0.0f, 100.0f );
2932 Radian childRotationAngle(Degree(23.0f));
2933 Quaternion childRotation( childRotationAngle, Vector3::YAXIS );
2934 Vector3 childScale( 2.0f, 2.0f, 2.0f );
2935 child.SetPosition( childPosition );
2936 child.SetOrientation( childRotation );
2937 child.SetScale( childScale );
2938 parent.Add( child );
2940 // The actors should not have a world matrix yet
2941 DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), Matrix::IDENTITY, 0.001, TEST_LOCATION );
2942 DALI_TEST_EQUALS( child.GetCurrentWorldMatrix(), Matrix::IDENTITY, 0.001, TEST_LOCATION );
2944 app.SendNotification();
2947 app.SendNotification();
2949 Matrix parentMatrix(false);
2950 parentMatrix.SetTransformComponents(parentScale, parentRotation, parentPosition);
2952 Vector3 childWorldPosition = parentPosition + parentRotation * parentScale * childPosition;
2953 Quaternion childWorldRotation = parentRotation * childRotation;
2954 Vector3 childWorldScale = parentScale * childScale;
2956 Matrix childWorldMatrix(false);
2957 childWorldMatrix.SetTransformComponents(childWorldScale, childWorldRotation, childWorldPosition);
2959 DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), parentMatrix, 0.001, TEST_LOCATION );
2960 DALI_TEST_EQUALS( child.GetCurrentWorldMatrix(), childWorldMatrix, 0.001, TEST_LOCATION );
2966 int UtcDaliActorConstrainedToWorldMatrix(void)
2968 TestApplication app;
2969 tet_infoline(" UtcDaliActorConstrainedToWorldMatrix");
2971 Actor parent = Actor::New();
2972 parent.SetParentOrigin(ParentOrigin::CENTER);
2973 parent.SetAnchorPoint(AnchorPoint::CENTER);
2974 Vector3 parentPosition( 10.0f, 20.0f, 30.0f);
2975 Radian rotationAngle(Degree(85.0f));
2976 Quaternion parentRotation(rotationAngle, Vector3::ZAXIS);
2977 Vector3 parentScale( 1.0f, 2.0f, 3.0f );
2978 parent.SetPosition( parentPosition );
2979 parent.SetOrientation( parentRotation );
2980 parent.SetScale( parentScale );
2981 Stage::GetCurrent().Add( parent );
2983 Actor child = Actor::New();
2984 child.SetParentOrigin(ParentOrigin::CENTER);
2985 Constraint posConstraint = Constraint::New<Vector3>( Actor::Property::POSITION, Source( parent, Actor::Property::WORLD_MATRIX), PositionComponentConstraint() );
2986 child.ApplyConstraint(posConstraint);
2988 Stage::GetCurrent().Add( child );
2990 // The actors should not have a world matrix yet
2991 DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), Matrix::IDENTITY, 0.001, TEST_LOCATION );
2992 DALI_TEST_EQUALS( child.GetCurrentWorldMatrix(), Matrix::IDENTITY, 0.001, TEST_LOCATION );
2994 app.SendNotification();
2997 app.SendNotification();
2999 Matrix parentMatrix(false);
3000 parentMatrix.SetTransformComponents(parentScale, parentRotation, parentPosition);
3002 DALI_TEST_EQUALS( parent.GetCurrentWorldMatrix(), parentMatrix, 0.001, TEST_LOCATION );
3003 DALI_TEST_EQUALS( child.GetCurrentPosition(), parent.GetCurrentPosition(), 0.001, TEST_LOCATION );
3007 int UtcDaliActorUnparent(void)
3009 TestApplication app;
3010 tet_infoline(" UtcDaliActorUnparent");
3012 Actor parent = Actor::New();
3013 Stage::GetCurrent().Add( parent );
3015 Actor child = Actor::New();
3017 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
3018 DALI_TEST_CHECK( !child.GetParent() );
3020 // Test that calling Unparent with no parent is a NOOP
3023 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
3024 DALI_TEST_CHECK( !child.GetParent() );
3026 // Test that Unparent works
3027 parent.Add( child );
3029 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
3030 DALI_TEST_CHECK( parent == child.GetParent() );
3034 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
3035 DALI_TEST_CHECK( !child.GetParent() );
3037 // Test that UnparentAndReset works
3038 parent.Add( child );
3040 DALI_TEST_EQUALS( parent.GetChildCount(), 1u, TEST_LOCATION );
3041 DALI_TEST_CHECK( parent == child.GetParent() );
3043 UnparentAndReset( child );
3045 DALI_TEST_EQUALS( parent.GetChildCount(), 0u, TEST_LOCATION );
3046 DALI_TEST_CHECK( !child );
3048 // Test that UnparentAndReset is a NOOP with empty handle
3049 UnparentAndReset( child );
3051 DALI_TEST_CHECK( !child );
3055 int UtcDaliActorGetChildAt(void)
3057 TestApplication app;
3058 tet_infoline(" UtcDaliActorGetChildAt");
3060 Actor parent = Actor::New();
3061 Stage::GetCurrent().Add( parent );
3063 Actor child0 = Actor::New();
3064 parent.Add( child0 );
3066 Actor child1 = Actor::New();
3067 parent.Add( child1 );
3069 Actor child2 = Actor::New();
3070 parent.Add( child2 );
3072 DALI_TEST_EQUALS( parent.GetChildAt( 0 ), child0, TEST_LOCATION );
3073 DALI_TEST_EQUALS( parent.GetChildAt( 1 ), child1, TEST_LOCATION );
3074 DALI_TEST_EQUALS( parent.GetChildAt( 2 ), child2, TEST_LOCATION );
3078 int UtcDaliActorSetGetOverlay(void)
3080 TestApplication app;
3081 tet_infoline(" UtcDaliActorSetGetOverlay");
3083 Actor parent = Actor::New();
3084 parent.SetDrawMode(DrawMode::OVERLAY );
3085 DALI_TEST_CHECK( parent.GetDrawMode() == DrawMode::OVERLAY );
3090 // Current Dynamics functions are crashing, so testing these sections are futile
3092 int UtcDaliActorDynamics(void)
3094 DALI_TEST_CHECK( true );
3098 int UtcDaliActorCreateDestroy(void)
3100 Actor* actor = new Actor;
3101 DALI_TEST_CHECK( actor );
3108 struct PropertyStringIndex
3110 const char * const name;
3111 const Property::Index index;
3112 const Property::Type type;
3115 const PropertyStringIndex PROPERTY_TABLE[] =
3117 { "parent-origin", Actor::Property::PARENT_ORIGIN, Property::VECTOR3 },
3118 { "parent-origin-x", Actor::Property::PARENT_ORIGIN_X, Property::FLOAT },
3119 { "parent-origin-y", Actor::Property::PARENT_ORIGIN_Y, Property::FLOAT },
3120 { "parent-origin-z", Actor::Property::PARENT_ORIGIN_Z, Property::FLOAT },
3121 { "anchor-point", Actor::Property::ANCHOR_POINT, Property::VECTOR3 },
3122 { "anchor-point-x", Actor::Property::ANCHOR_POINT_X, Property::FLOAT },
3123 { "anchor-point-y", Actor::Property::ANCHOR_POINT_Y, Property::FLOAT },
3124 { "anchor-point-z", Actor::Property::ANCHOR_POINT_Z, Property::FLOAT },
3125 { "size", Actor::Property::SIZE, Property::VECTOR3 },
3126 { "size-width", Actor::Property::SIZE_WIDTH, Property::FLOAT },
3127 { "size-height", Actor::Property::SIZE_HEIGHT, Property::FLOAT },
3128 { "size-depth", Actor::Property::SIZE_DEPTH, Property::FLOAT },
3129 { "position", Actor::Property::POSITION, Property::VECTOR3 },
3130 { "position-x", Actor::Property::POSITION_X, Property::FLOAT },
3131 { "position-y", Actor::Property::POSITION_Y, Property::FLOAT },
3132 { "position-z", Actor::Property::POSITION_Z, Property::FLOAT },
3133 { "world-position", Actor::Property::WORLD_POSITION, Property::VECTOR3 },
3134 { "world-position-x", Actor::Property::WORLD_POSITION_X, Property::FLOAT },
3135 { "world-position-y", Actor::Property::WORLD_POSITION_Y, Property::FLOAT },
3136 { "world-position-z", Actor::Property::WORLD_POSITION_Z, Property::FLOAT },
3137 { "orientation", Actor::Property::ORIENTATION, Property::ROTATION },
3138 { "world-orientation", Actor::Property::WORLD_ORIENTATION, Property::ROTATION },
3139 { "scale", Actor::Property::SCALE, Property::VECTOR3 },
3140 { "scale-x", Actor::Property::SCALE_X, Property::FLOAT },
3141 { "scale-y", Actor::Property::SCALE_Y, Property::FLOAT },
3142 { "scale-z", Actor::Property::SCALE_Z, Property::FLOAT },
3143 { "world-scale", Actor::Property::WORLD_SCALE, Property::VECTOR3 },
3144 { "visible", Actor::Property::VISIBLE, Property::BOOLEAN },
3145 { "color", Actor::Property::COLOR, Property::VECTOR4 },
3146 { "color-red", Actor::Property::COLOR_RED, Property::FLOAT },
3147 { "color-green", Actor::Property::COLOR_GREEN, Property::FLOAT },
3148 { "color-blue", Actor::Property::COLOR_BLUE, Property::FLOAT },
3149 { "color-alpha", Actor::Property::COLOR_ALPHA, Property::FLOAT },
3150 { "world-color", Actor::Property::WORLD_COLOR, Property::VECTOR4 },
3151 { "world-matrix", Actor::Property::WORLD_MATRIX, Property::MATRIX },
3152 { "name", Actor::Property::NAME, Property::STRING },
3153 { "sensitive", Actor::Property::SENSITIVE, Property::BOOLEAN },
3154 { "leave-required", Actor::Property::LEAVE_REQUIRED, Property::BOOLEAN },
3155 { "inherit-orientation", Actor::Property::INHERIT_ORIENTATION, Property::BOOLEAN },
3156 { "inherit-scale", Actor::Property::INHERIT_SCALE, Property::BOOLEAN },
3157 { "color-mode", Actor::Property::COLOR_MODE, Property::STRING },
3158 { "position-inheritance", Actor::Property::POSITION_INHERITANCE, Property::STRING },
3159 { "draw-mode", Actor::Property::DRAW_MODE, Property::STRING },
3160 { "size-mode", Actor::Property::SIZE_MODE, Property::STRING },
3161 { "size-mode-factor", Actor::Property::SIZE_MODE_FACTOR, Property::VECTOR3 },
3163 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
3164 } // unnamed namespace
3166 int UtcDaliActorProperties(void)
3168 TestApplication app;
3170 Actor actor = Actor::New();
3172 for ( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
3174 tet_printf( "Checking %s == %d\n", PROPERTY_TABLE[i].name, PROPERTY_TABLE[i].index );
3175 DALI_TEST_EQUALS( actor.GetPropertyName( PROPERTY_TABLE[i].index ), PROPERTY_TABLE[i].name, TEST_LOCATION );
3176 DALI_TEST_EQUALS( actor.GetPropertyIndex( PROPERTY_TABLE[i].name ), PROPERTY_TABLE[i].index, TEST_LOCATION );
3177 DALI_TEST_EQUALS( actor.GetPropertyType( PROPERTY_TABLE[i].index ), PROPERTY_TABLE[i].type, TEST_LOCATION );