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.
20 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/hover-event-integ.h>
24 #include <dali/integration-api/events/wheel-event-integ.h>
25 #include <dali/integration-api/events/key-event-integ.h>
27 #include "dali-test-suite-utils/dali-test-suite-utils.h"
32 void custom_actor_test_startup(void)
34 test_return_value = TET_UNDEF;
37 void custom_actor_test_cleanup(void)
39 test_return_value = TET_PASS;
45 std::vector< std::string > MasterCallStack;
46 bool gOnRelayout = false;
50 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
54 struct TestCustomActor : public CustomActorImpl
60 : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS | DISABLE_SIZE_NEGOTIATION ) ),
61 mDaliProperty( Property::INVALID_INDEX ),
62 mSizeSet( Vector3::ZERO ),
63 mTargetSize( Vector3::ZERO ),
69 TestCustomActor(bool nego)
70 : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS ) ),
71 mDaliProperty( Property::INVALID_INDEX ),
72 mSizeSet( Vector3::ZERO ),
73 mTargetSize( Vector3::ZERO ),
80 virtual ~TestCustomActor()
84 void Initialize( const char* name = NULL )
86 mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
91 virtual void OnInitialize( const char* name ) {}
94 * Resets the call stack
99 mTargetSize = Vector3();
100 mMethodsCalled.clear();
103 void AddToCallStacks( const char* method )
105 mMethodsCalled.push_back( method );
107 // Combine Actor name with method string
108 std::string nameAndMethod( Self().GetName() );
109 if ( 0 == nameAndMethod.size() )
111 nameAndMethod = "Unknown: ";
115 nameAndMethod += ": ";
117 nameAndMethod += method;
119 MasterCallStack.push_back( nameAndMethod );
122 // From CustomActorImpl
123 virtual void OnStageConnection( int depth )
125 AddToCallStacks("OnStageConnection");
128 virtual void OnStageDisconnection()
130 AddToCallStacks("OnStageDisconnection");
132 virtual void OnChildAdd(Actor& child)
134 AddToCallStacks("OnChildAdd");
136 virtual void OnChildRemove(Actor& child)
138 AddToCallStacks("OnChildRemove");
140 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
142 AddToCallStacks("OnPropertySet");
144 virtual void OnSizeSet(const Vector3& targetSize)
146 mSizeSet = targetSize;
147 AddToCallStacks("OnSizeSet");
149 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
151 mTargetSize = targetSize;
152 AddToCallStacks("OnSizeAnimation");
154 virtual bool OnTouchEvent(const TouchEvent& event)
156 AddToCallStacks("OnTouchEvent");
159 virtual bool OnHoverEvent(const HoverEvent& event)
161 AddToCallStacks("OnHoverEvent");
164 virtual bool OnWheelEvent(const WheelEvent& event)
166 AddToCallStacks("OnWheelEvent");
169 virtual bool OnKeyEvent(const KeyEvent& event)
171 AddToCallStacks("OnKeyEvent");
174 virtual void OnKeyInputFocusGained()
176 AddToCallStacks("OnKeyInputFocusGained");
178 virtual void OnKeyInputFocusLost()
180 AddToCallStacks("OnKeyInputFocusLost");
182 virtual Vector3 GetNaturalSize()
184 return Vector3( 0.0f, 0.0f, 0.0f );
187 virtual float GetHeightForWidth( float width )
192 virtual float GetWidthForHeight( float height )
197 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
202 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
206 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
210 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
215 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
219 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
224 void SetDaliProperty(std::string s)
226 Self().SetProperty(mDaliProperty, s);
228 void TestRelayoutRequest()
233 float TestGetHeightForWidthBase( float width )
235 return GetHeightForWidthBase( width );
238 float TestGetWidthForHeightBase( float height )
240 return GetWidthForHeightBase( height );
243 float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
245 return CalculateChildSizeBase( child, dimension );
248 bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
250 return RelayoutDependentOnChildrenBase( dimension );
253 Property::Index mDaliProperty;
254 std::vector< std::string > mMethodsCalled;
262 * Variant which adds a new child during OnStageConnection
264 struct TestCustomActorVariant1 : public TestCustomActor
269 TestCustomActorVariant1( Actor childToAdd )
270 : mChildToAdd( childToAdd )
274 // From CustomActorImpl
275 virtual void OnStageConnection( int depth )
278 TestCustomActor::OnStageConnection( depth );
281 Self().Add( mChildToAdd );
288 * Variant which removes children during OnStageConnection
290 struct TestCustomActorVariant2 : public TestCustomActor
295 TestCustomActorVariant2()
299 // From CustomActorImpl
300 virtual void OnStageConnection( int depth )
303 TestCustomActor::OnStageConnection( depth );
305 // Remove all the children
306 for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
308 Self().Remove( Self().GetChildAt(0) );
314 * Variant which adds a new child during OnStageDisconnection
316 struct TestCustomActorVariant3 : public TestCustomActor
321 TestCustomActorVariant3( Actor childToAdd )
322 : mChildToAdd( childToAdd )
326 // From CustomActorImpl
327 virtual void OnStageDisconnection()
330 TestCustomActor::OnStageDisconnection();
333 Self().Add( mChildToAdd );
340 * Variant which removes children during OnStageDisconnection
342 struct TestCustomActorVariant4 : public TestCustomActor
347 TestCustomActorVariant4()
351 // From CustomActorImpl
352 virtual void OnStageDisconnection()
355 TestCustomActor::OnStageDisconnection();
357 // Remove all the children
358 for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
360 Self().Remove( Self().GetChildAt(0) );
366 * Variant which removes its parent from Stage during OnStageConnection
368 struct TestCustomActorVariant5 : public TestCustomActor
373 TestCustomActorVariant5()
377 // From CustomActorImpl
378 virtual void OnStageConnection( int depth )
381 TestCustomActor::OnStageConnection( depth );
383 // Take parent off-stage
384 Actor parent = Self().GetParent();
387 Stage::GetCurrent().Remove( parent );
393 * Variant which adds its parent to Stage during OnStageDisconnection
395 struct TestCustomActorVariant6 : public TestCustomActor
400 TestCustomActorVariant6()
404 // From CustomActorImpl
405 virtual void OnStageDisconnection()
408 TestCustomActor::OnStageDisconnection();
410 // Put parent on-stage
411 Actor parent = Self().GetParent();
414 Stage::GetCurrent().Add( parent );
420 * Variant which reparents its children into a separate container
422 struct TestCustomActorVariant7 : public TestCustomActor
427 TestCustomActorVariant7()
431 virtual void OnInitialize( const char* name )
433 // We need to do this early, before the OnChildAdd is recorded
434 Self().SetName( name );
436 mContainer = Actor::New();
437 mContainer.SetName( "Container" );
438 Self().Add( mContainer );
441 // From CustomActorImpl
442 virtual void OnChildAdd(Actor& child)
445 TestCustomActor::OnChildAdd(child);
448 if ( child != mContainer )
450 mContainer.Add( child );
458 * Variant which attempts to interfere with the reparenting of a child to another container
460 struct TestCustomActorVariant8 : public TestCustomActor
465 TestCustomActorVariant8( Actor rival )
466 : mRivalContainer( rival )
470 // From CustomActorImpl
471 virtual void OnChildRemove(Actor& child)
474 TestCustomActor::OnChildRemove(child);
476 mRivalContainer.Remove( child ); // attempt to block reparenting to rival (should be a NOOP)
479 Actor mRivalContainer;
482 // Need a class that doesn't override virtual methods
483 class SimpleTestCustomActor : public CustomActorImpl
490 SimpleTestCustomActor()
491 : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | DISABLE_SIZE_NEGOTIATION ) )
498 virtual ~SimpleTestCustomActor()
502 // From CustomActorImpl
503 virtual void OnStageConnection( int depth )
506 virtual void OnStageDisconnection()
509 virtual void OnChildAdd(Actor& child)
512 virtual void OnChildRemove(Actor& child)
515 virtual void OnSizeSet(const Vector3& targetSize)
518 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
521 virtual bool OnTouchEvent(const TouchEvent& event)
525 virtual bool OnHoverEvent(const HoverEvent& event)
529 virtual bool OnWheelEvent(const WheelEvent& event)
533 virtual bool OnKeyEvent(const KeyEvent& event)
537 virtual void OnKeyInputFocusGained()
540 virtual void OnKeyInputFocusLost()
544 virtual Vector3 GetNaturalSize()
546 return Vector3( 0.0f, 0.0f, 0.0f );
549 virtual float GetHeightForWidth( float width )
554 virtual float GetWidthForHeight( float height )
559 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
563 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
567 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
571 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
576 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
580 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
586 } ; // namespace Impl
593 * Test custom actor handle
595 class TestCustomActor : public CustomActor
599 static TestCustomActor New()
601 Impl::TestCustomActor* impl = new Impl::TestCustomActor;
602 TestCustomActor custom( *impl ); // takes ownership
609 static TestCustomActor NewNegoSize()
611 Impl::TestCustomActor* impl = new Impl::TestCustomActor( true );
612 TestCustomActor custom( *impl ); // takes ownership
613 custom.SetName( "SizeNegotiationActor" );
620 static TestCustomActor NewVariant1( Actor childToAdd )
622 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd );
623 TestCustomActor custom( *impl ); // takes ownership
630 static TestCustomActor NewVariant2()
632 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2();
633 TestCustomActor custom( *impl ); // takes ownership
640 static TestCustomActor NewVariant3( Actor childToAdd )
642 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3( childToAdd );
643 TestCustomActor custom( *impl ); // takes ownership
650 static TestCustomActor NewVariant4()
652 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4();
653 TestCustomActor custom( *impl ); // takes ownership
660 static TestCustomActor NewVariant5()
662 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5();
663 TestCustomActor custom( *impl ); // takes ownership
670 static TestCustomActor NewVariant6()
672 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6();
673 TestCustomActor custom( *impl ); // takes ownership
680 static TestCustomActor NewVariant7( const char* name )
682 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7();
683 TestCustomActor custom( *impl ); // takes ownership
685 impl->Initialize( name );
690 static TestCustomActor NewVariant8( Actor rival )
692 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8( rival );
693 TestCustomActor custom( *impl ); // takes ownership
700 virtual ~TestCustomActor()
704 Impl::TestCustomActor& GetImpl()
706 return static_cast<Impl::TestCustomActor&>(GetImplementation());
709 std::vector< std::string >& GetMethodsCalled()
711 return GetImpl().mMethodsCalled;
714 void ResetCallStack()
716 GetImpl().ResetCallStack();
719 void SetDaliProperty(std::string s)
721 GetImpl().SetDaliProperty(s);
726 return GetImpl().mSizeSet;
729 Vector3 GetTargetSize()
731 return GetImpl().mTargetSize;
734 virtual Vector3 GetNaturalSize()
736 return Vector3( 0.0f, 0.0f, 0.0f );
739 virtual float GetHeightForWidth( float width )
744 virtual float GetWidthForHeight( float height )
749 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
753 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
757 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
761 void TestRelayoutRequest()
763 GetImpl().TestRelayoutRequest();
766 float TestGetHeightForWidthBase( float width )
768 return GetImpl().TestGetHeightForWidthBase( width );
771 float TestGetWidthForHeightBase( float height )
773 return GetImpl().TestGetWidthForHeightBase( height );
776 float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
778 return GetImpl().TestCalculateChildSizeBase( child, dimension );
781 bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
783 return GetImpl().TestRelayoutDependentOnChildrenBase( dimension );
786 unsigned int GetDepth()
788 return GetImpl().mDepth;
792 TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl )
799 using namespace Dali;
801 BaseHandle CreateActor()
803 return TestCustomActor::New();
806 Dali::TypeRegistration mType( typeid(TestCustomActor), typeid(Dali::CustomActor), CreateActor );
811 int UtcDaliCustomActorDestructor(void)
813 TestApplication application;
815 CustomActor* actor = new CustomActor();
818 DALI_TEST_CHECK( true );
822 int UtcDaliCustomActorImplDestructor(void)
824 TestApplication application;
825 CustomActorImpl* actor = new Impl::TestCustomActor();
828 DALI_TEST_CHECK( true );
832 // Positive test case for a method
833 int UtcDaliCustomActorDownCast(void)
835 TestApplication application;
836 tet_infoline("Testing Dali::CustomActor::DownCast()");
838 TestCustomActor custom = TestCustomActor::New();
840 Actor anActor = Actor::New();
841 anActor.Add( custom );
843 Actor child = anActor.GetChildAt(0);
844 CustomActor customActor = CustomActor::DownCast( child );
845 DALI_TEST_CHECK( customActor );
848 DALI_TEST_CHECK( !customActor );
850 customActor = DownCast< CustomActor >( child );
851 DALI_TEST_CHECK( customActor );
855 // Negative test case for a method
856 int UtcDaliCustomActorDownCastNegative(void)
858 TestApplication application;
859 tet_infoline("Testing Dali::CustomActor::DownCast()");
861 Actor actor1 = Actor::New();
862 Actor anActor = Actor::New();
865 Actor child = anActor.GetChildAt(0);
866 CustomActor customActor = CustomActor::DownCast( child );
867 DALI_TEST_CHECK( !customActor );
869 Actor unInitialzedActor;
870 customActor = CustomActor::DownCast( unInitialzedActor );
871 DALI_TEST_CHECK( !customActor );
873 customActor = DownCast< CustomActor >( unInitialzedActor );
874 DALI_TEST_CHECK( !customActor );
878 int UtcDaliCustomActorOnStageConnectionDisconnection(void)
880 TestApplication application;
881 tet_infoline("Testing Dali::CustomActor::OnStageConnection() & OnStageDisconnection");
883 TestCustomActor custom = TestCustomActor::New();
884 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
886 // add the custom actor to stage
887 Stage::GetCurrent().Add( custom );
889 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
890 DALI_TEST_EQUALS( "OnStageConnection", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
892 Stage::GetCurrent().Remove( custom );
894 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
895 DALI_TEST_EQUALS( "OnStageDisconnection", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
897 // Excercise the message passing to Update thread
899 application.SendNotification();
900 application.Render();
901 application.Render();
905 int UtcDaliCustomActorOnStageConnectionOrder(void)
907 TestApplication application;
908 tet_infoline("Testing Dali::CustomActor::OnStageConnection() order");
910 MasterCallStack.clear();
912 /* Build tree of actors:
920 * OnStageConnection should be received for A, B, D, E, C, and finally F
923 TestCustomActor actorA = TestCustomActor::New();
924 actorA.SetName( "ActorA" );
926 TestCustomActor actorB = TestCustomActor::New();
927 actorB.SetName( "ActorB" );
928 actorA.Add( actorB );
930 TestCustomActor actorC = TestCustomActor::New();
931 actorC.SetName( "ActorC" );
932 actorA.Add( actorC );
934 TestCustomActor actorD = TestCustomActor::New();
935 actorD.SetName( "ActorD" );
936 actorB.Add( actorD );
938 TestCustomActor actorE = TestCustomActor::New();
939 actorE.SetName( "ActorE" );
940 actorB.Add( actorE );
942 TestCustomActor actorF = TestCustomActor::New();
943 actorF.SetName( "ActorF" );
944 actorC.Add( actorF );
946 // add the custom actor to stage
947 Stage::GetCurrent().Add( actorA );
949 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
950 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
951 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
952 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
954 DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
955 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
956 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
957 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
959 DALI_TEST_EQUALS( 2, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
960 DALI_TEST_EQUALS( "OnChildAdd", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
961 DALI_TEST_EQUALS( "OnStageConnection", actorC.GetMethodsCalled()[ 1 ], TEST_LOCATION );
963 DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
964 DALI_TEST_EQUALS( "OnStageConnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
966 DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
967 DALI_TEST_EQUALS( "OnStageConnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
969 DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
970 DALI_TEST_EQUALS( "OnStageConnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
972 // Check sequence is correct in MasterCallStack
974 DALI_TEST_EQUALS( 3+3+2+1+1+1, (int)(MasterCallStack.size()), TEST_LOCATION );
976 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
977 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
978 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
979 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 3 ], TEST_LOCATION );
980 DALI_TEST_EQUALS( "ActorC: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
982 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 5 ], TEST_LOCATION );
983 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 6 ], TEST_LOCATION );
984 DALI_TEST_EQUALS( "ActorD: OnStageConnection", MasterCallStack[ 7 ], TEST_LOCATION );
985 DALI_TEST_EQUALS( "ActorE: OnStageConnection", MasterCallStack[ 8 ], TEST_LOCATION );
986 DALI_TEST_EQUALS( "ActorC: OnStageConnection", MasterCallStack[ 9 ], TEST_LOCATION );
987 DALI_TEST_EQUALS( "ActorF: OnStageConnection", MasterCallStack[ 10 ], TEST_LOCATION );
989 // Excercise the message passing to Update thread
991 application.SendNotification();
992 application.Render();
993 application.Render();
997 int UtcDaliCustomActorOnStageDisconnectionOrder(void)
999 TestApplication application;
1000 tet_infoline("Testing Dali::CustomActor::OnStageDisconnection() order");
1002 Stage stage = Stage::GetCurrent();
1004 /* Build tree of actors:
1012 * OnStageDisconnection should be received for D, E, B, F, C, and finally A.
1015 TestCustomActor actorA = TestCustomActor::New();
1016 actorA.SetName( "ActorA" );
1017 stage.Add( actorA );
1019 TestCustomActor actorB = TestCustomActor::New();
1020 actorB.SetName( "ActorB" );
1021 actorA.Add( actorB );
1023 TestCustomActor actorC = TestCustomActor::New();
1024 actorC.SetName( "ActorC" );
1025 actorA.Add( actorC );
1027 TestCustomActor actorD = TestCustomActor::New();
1028 actorD.SetName( "ActorD" );
1029 actorB.Add( actorD );
1031 TestCustomActor actorE = TestCustomActor::New();
1032 actorE.SetName( "ActorE" );
1033 actorB.Add( actorE );
1035 TestCustomActor actorF = TestCustomActor::New();
1036 actorF.SetName( "ActorF" );
1037 actorC.Add( actorF );
1039 // Excercise the message passing to Update thread
1041 application.SendNotification();
1042 application.Render();
1043 application.Render();
1045 // Clear call stacks before disconnection
1046 actorA.ResetCallStack();
1047 actorB.ResetCallStack();
1048 actorC.ResetCallStack();
1049 actorD.ResetCallStack();
1050 actorE.ResetCallStack();
1051 actorF.ResetCallStack();
1052 MasterCallStack.clear();
1054 stage.Remove( actorA );
1056 DALI_TEST_EQUALS( 1, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1057 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1059 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1060 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1062 DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
1063 DALI_TEST_EQUALS( "OnStageDisconnection", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1065 DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
1066 DALI_TEST_EQUALS( "OnStageDisconnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1068 DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
1069 DALI_TEST_EQUALS( "OnStageDisconnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1071 DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
1072 DALI_TEST_EQUALS( "OnStageDisconnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1074 // Check sequence is correct in MasterCallStack
1076 DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
1078 DALI_TEST_EQUALS( "ActorD: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1079 DALI_TEST_EQUALS( "ActorE: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
1080 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 2 ], TEST_LOCATION );
1081 DALI_TEST_EQUALS( "ActorF: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1082 DALI_TEST_EQUALS( "ActorC: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
1083 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
1085 // Excercise the message passing to Update thread
1087 application.SendNotification();
1088 application.Render();
1089 application.Render();
1093 int UtcDaliCustomActorAddDuringOnStageConnection(void)
1095 TestApplication application;
1096 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageConnection() callback");
1098 Stage stage = Stage::GetCurrent();
1100 MasterCallStack.clear();
1102 /* The actorA is a special variant which adds a child to itself during OnStageConnection()
1103 * The actorB is provided as the child
1106 TestCustomActor actorB = TestCustomActor::New();
1107 actorB.SetName( "ActorB" );
1109 TestCustomActor actorA = TestCustomActor::NewVariant1( actorB );
1110 actorA.SetName( "ActorA" );
1111 stage.Add( actorA );
1113 // Check callback sequence
1115 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1116 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1117 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // Called from within OnStageConnection()
1119 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1120 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1122 DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
1124 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
1125 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION ); // Occurs during Actor::Add from within from within OnStageConnection()
1126 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION ); // Occurs after Actor::Add from within from within OnStageConnection()
1128 // Excercise the message passing to Update thread
1130 application.SendNotification();
1131 application.Render();
1132 application.Render();
1134 // Check everything is ok after Actors are removed
1136 stage.Remove( actorA );
1137 application.SendNotification();
1138 application.Render();
1139 application.Render();
1143 int UtcDaliCustomActorRemoveDuringOnStageConnection(void)
1145 TestApplication application;
1146 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageConnection() callback");
1148 Stage stage = Stage::GetCurrent();
1150 MasterCallStack.clear();
1152 /* The actorA is a special variant which removes its children during OnStageConnection()
1153 * Actors B & C are provided as the children
1156 TestCustomActor actorA = TestCustomActor::NewVariant2();
1157 actorA.SetName( "ActorA" );
1159 TestCustomActor actorB = TestCustomActor::New();
1160 actorB.SetName( "ActorB" );
1161 actorA.Add( actorB );
1163 TestCustomActor actorC = TestCustomActor::New();
1164 actorC.SetName( "ActorC" );
1165 actorA.Add( actorC );
1167 stage.Add( actorA );
1169 // Check callback sequence
1171 DALI_TEST_EQUALS( 5, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1172 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1173 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1174 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1175 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // Called from within OnStageConnection()
1176 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION ); // Called from within OnStageConnection()
1178 DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
1180 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
1181 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
1182 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
1183 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 3 ], TEST_LOCATION );
1184 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 4 ], TEST_LOCATION );
1186 /* Actors B & C should be removed before the point where they could receive an OnStageConnection callback
1187 * Therefore they shouldn't receive either OnStageConnection or OnStageDisconnection
1189 DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1190 DALI_TEST_EQUALS( 0, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
1192 // Excercise the message passing to Update thread
1194 application.SendNotification();
1195 application.Render();
1196 application.Render();
1198 // Check everything is ok after last actor is removed
1200 stage.Remove( actorA );
1201 application.SendNotification();
1202 application.Render();
1203 application.Render();
1207 int UtcDaliCustomActorAddDuringOnStageDisconnection(void)
1209 TestApplication application;
1210 tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageDisonnection() callback");
1212 Stage stage = Stage::GetCurrent();
1214 /* The actorA is a special variant which adds a child to itself during OnStageDisconnection()
1215 * The actorB is provided as the child
1218 TestCustomActor actorB = TestCustomActor::New();
1219 actorB.SetName( "ActorB" );
1221 TestCustomActor actorA = TestCustomActor::NewVariant3( actorB );
1222 actorA.SetName( "ActorA" );
1223 stage.Add( actorA );
1225 // Excercise the message passing to Update thread
1227 application.SendNotification();
1228 application.Render();
1229 application.Render();
1231 // Clear call stacks before disconnection
1232 actorA.ResetCallStack();
1233 actorB.ResetCallStack();
1234 MasterCallStack.clear();
1236 stage.Remove( actorA );
1238 // Check callback sequence
1240 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1241 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1242 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1244 // Child was added after parent disconnection, so should not receive OnStageConnection()
1245 DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1247 DALI_TEST_EQUALS( 2, (int)(MasterCallStack.size()), TEST_LOCATION );
1249 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1250 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
1252 // Excercise the message passing to Update thread
1254 application.SendNotification();
1255 application.Render();
1256 application.Render();
1260 int UtcDaliCustomActorRemoveDuringOnStageDisconnection(void)
1262 TestApplication application;
1263 tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageDisconnection() callback");
1265 Stage stage = Stage::GetCurrent();
1267 /* The actorA is a special variant which removes its children during OnStageDisconnection()
1268 * The actorB is provided as the child
1271 TestCustomActor actorA = TestCustomActor::NewVariant4();
1272 actorA.SetName( "ActorA" );
1273 stage.Add( actorA );
1275 TestCustomActor actorB = TestCustomActor::New();
1276 actorB.SetName( "ActorB" );
1277 actorA.Add( actorB );
1279 // Excercise the message passing to Update thread
1281 application.SendNotification();
1282 application.Render();
1283 application.Render();
1285 // Clear call stacks before disconnection
1286 actorA.ResetCallStack();
1287 actorB.ResetCallStack();
1288 MasterCallStack.clear();
1290 stage.Remove( actorA );
1292 // Check callback sequence
1294 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1295 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1296 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1298 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1299 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1301 DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
1303 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1304 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
1305 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 2 ], TEST_LOCATION );
1307 // Excercise the message passing to Update thread
1309 application.SendNotification();
1310 application.Render();
1311 application.Render();
1315 int UtcDaliCustomActorRemoveParentDuringOnStageConnection(void)
1317 TestApplication application;
1318 tet_infoline("Weird test where child removes its own parent from Stage during Dali::CustomActor::OnStageConnection() callback");
1320 Stage stage = Stage::GetCurrent();
1322 MasterCallStack.clear();
1324 /* The actorA is the parent of actorB
1325 * The actorB is a special variant which removes its own parent during OnStageConnection()
1326 * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnStageDisconnection()
1329 TestCustomActor actorA = TestCustomActor::New();
1330 actorA.SetName( "ActorA" );
1332 TestCustomActor actorB = TestCustomActor::NewVariant5();
1333 actorB.SetName( "ActorB" );
1334 actorA.Add( actorB );
1336 stage.Add( actorA );
1338 // Check callback sequence
1340 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1341 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1342 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1343 DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1345 DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1346 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1348 DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
1350 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
1351 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
1352 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
1353 DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1355 // Excercise the message passing to Update thread
1357 application.SendNotification();
1358 application.Render();
1359 application.Render();
1363 int UtcDaliCustomActorAddParentDuringOnStageDisconnection(void)
1365 TestApplication application;
1366 tet_infoline("Weird test where child adds its own parent to Stage during Dali::CustomActor::OnStageDisconnection() callback");
1368 Stage stage = Stage::GetCurrent();
1370 MasterCallStack.clear();
1372 /* The actorA is the parent of actorB
1373 * The actorB is a special variant which (weirdly) adds its own parent during OnStageDisconnection()
1374 * The child actor is interrupting the disconnection, such that parent should not get a OnStageDisconnection()
1377 TestCustomActor actorA = TestCustomActor::New();
1378 actorA.SetName( "ActorA" );
1379 stage.Add( actorA );
1381 TestCustomActor actorB = TestCustomActor::NewVariant6();
1382 actorB.SetName( "ActorB" );
1383 actorA.Add( actorB );
1385 stage.Remove( actorA );
1387 // Check callback sequence
1389 DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1390 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1391 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1393 DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1394 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1395 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1396 // Disconnect was interrupted, so we should only get one OnStageConnection() for actorB
1398 DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
1400 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
1401 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
1402 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
1403 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1405 // Excercise the message passing to Update thread
1407 application.SendNotification();
1408 application.Render();
1409 application.Render();
1413 int UtcDaliCustomActorOnChildAddRemove(void)
1415 TestApplication application;
1416 tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()");
1418 TestCustomActor custom = TestCustomActor::New();
1419 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1421 Actor aChild = Actor::New();
1422 custom.Add( aChild );
1424 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1425 DALI_TEST_EQUALS( "OnChildAdd", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1427 custom.Remove( aChild );
1429 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1430 DALI_TEST_EQUALS( "OnChildRemove", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1434 int UtcDaliCustomActorReparentDuringOnChildAdd(void)
1436 TestApplication application;
1437 tet_infoline("Testing Actor:Add (reparenting) behaviour during Dali::CustomActor::OnChildAdd() callback");
1439 Stage stage = Stage::GetCurrent();
1441 MasterCallStack.clear();
1443 /* The actorA is a special variant which reparents children added into a separate container child
1444 * The actorB is the child of actorA
1447 TestCustomActor actorA = TestCustomActor::NewVariant7( "ActorA" );
1448 stage.Add( actorA );
1450 TestCustomActor actorB = TestCustomActor::New();
1451 actorB.SetName( "ActorB" );
1452 actorA.Add( actorB );
1454 // Check hierarchy is as follows:
1461 DALI_TEST_EQUALS( 1, (int)(actorA.GetChildCount()), TEST_LOCATION );
1463 Actor container = actorA.GetChildAt(0);
1464 Actor containerChild;
1466 DALI_TEST_CHECK( container );
1469 DALI_TEST_EQUALS( "Container", container.GetName(), TEST_LOCATION );
1470 DALI_TEST_EQUALS( 1, (int)(container.GetChildCount()), TEST_LOCATION );
1471 containerChild = container.GetChildAt(0);
1474 DALI_TEST_CHECK( containerChild );
1475 if ( containerChild )
1477 DALI_TEST_EQUALS( "ActorB", containerChild.GetName(), TEST_LOCATION );
1478 DALI_TEST_EQUALS( 0, (int)(containerChild.GetChildCount()), TEST_LOCATION );
1481 // Check callback sequence
1483 DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1484 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
1485 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1486 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
1487 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
1488 // mContainer will then receive OnChildAdd
1490 DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1491 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1492 DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1493 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1495 DALI_TEST_EQUALS( 7, (int)(MasterCallStack.size()), TEST_LOCATION );
1497 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
1498 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
1499 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
1500 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 3 ], TEST_LOCATION );
1501 DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
1502 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 5 ], TEST_LOCATION );
1503 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 6 ], TEST_LOCATION );
1505 // Excercise the message passing to Update thread
1507 application.SendNotification();
1508 application.Render();
1509 application.Render();
1514 * Test that Remove can be called (a NOOP) during the OnChildRemove
1515 * triggered when reparenting an actor
1517 int UtcDaliCustomActorRemoveDuringOnChildRemove(void)
1519 TestApplication application;
1520 tet_infoline("Testing Actor:Remove behaviour during OnChildRemove() callback triggered when reparenting");
1522 Stage stage = Stage::GetCurrent();
1524 MasterCallStack.clear();
1526 /* The childActor will be reparented from actorA to actorB
1527 * The actorA is a special variant which attempts to remove a child from actorB, during the OnChildRemove callback()
1528 * This should be a NOOP since the reparenting has not occured yet
1531 TestCustomActor actorB = TestCustomActor::New();
1532 actorB.SetName( "ActorB" );
1533 stage.Add( actorB );
1535 TestCustomActor actorA = TestCustomActor::NewVariant8( actorB );
1536 actorA.SetName( "ActorA" );
1537 stage.Add( actorA );
1539 Actor childActor = Actor::New();
1540 childActor.SetName( "Child" );
1541 // Reparent from actorA to actorB
1542 actorA.Add( childActor );
1543 actorB.Add( childActor );
1545 // Check hierarchy is as follows:
1550 DALI_TEST_EQUALS( 0, (int)(actorA.GetChildCount()), TEST_LOCATION );
1551 DALI_TEST_EQUALS( 1, (int)(actorB.GetChildCount()), TEST_LOCATION );
1552 DALI_TEST_EQUALS( 0, (int)(childActor.GetChildCount()), TEST_LOCATION );
1554 Actor child = actorB.GetChildAt(0);
1556 DALI_TEST_CHECK( child );
1559 DALI_TEST_EQUALS( "Child", child.GetName(), TEST_LOCATION );
1562 // Check callback sequence
1564 DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1565 DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
1566 DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1567 DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
1568 // mContainer will then receive OnChildAdd
1570 DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1571 DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1572 DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1574 DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
1576 DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
1577 DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
1578 DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
1579 DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 3 ], TEST_LOCATION );
1580 DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
1582 // Excercise the message passing to Update thread
1584 application.SendNotification();
1585 application.Render();
1586 application.Render();
1590 int UtcDaliCustomActorOnPropertySet(void)
1592 TestApplication application;
1593 tet_infoline("Testing Dali::CustomActor::OnPropertySet()");
1595 TestCustomActor custom = TestCustomActor::New();
1596 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1598 custom.SetDaliProperty("yes");
1600 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1601 DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1605 int UtcDaliCustomActorOnSizeSet(void)
1607 TestApplication application;
1608 tet_infoline("Testing Dali::CustomActor::OnSizeSet()");
1610 TestCustomActor custom = TestCustomActor::New();
1611 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1613 custom.SetSize( Vector2( 9.0f, 10.0f ) );
1614 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1615 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1616 DALI_TEST_EQUALS( 9.0f, custom.GetSize().width, TEST_LOCATION );
1617 DALI_TEST_EQUALS( 10.0f, custom.GetSize().height, TEST_LOCATION );
1619 custom.SetSize( Vector3( 4.0f, 5.0f, 6.0f ) );
1620 DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1621 DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1622 DALI_TEST_EQUALS( 4.0f, custom.GetSize().width, TEST_LOCATION );
1623 DALI_TEST_EQUALS( 5.0f, custom.GetSize().height, TEST_LOCATION );
1624 DALI_TEST_EQUALS( 6.0f, custom.GetSize().depth, TEST_LOCATION );
1628 int UtcDaliCustomActorOnSizeAnimation(void)
1630 TestApplication application;
1631 tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
1633 TestCustomActor custom = TestCustomActor::New();
1634 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1636 Animation anim = Animation::New( 1.0f );
1637 anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) );
1638 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1639 DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1640 DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION );
1641 DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION );
1642 DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION );
1646 int UtcDaliCustomActorOnTouchEvent(void)
1648 TestApplication application;
1649 tet_infoline("Testing Dali::CustomActor::OnTouchEvent()");
1651 TestCustomActor custom = TestCustomActor::New();
1652 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1654 // set size for custom actor
1655 custom.SetSize( 100, 100 );
1656 // add the custom actor to stage
1657 Stage::GetCurrent().Add( custom );
1658 custom.ResetCallStack();
1660 // Render and notify a couple of times
1661 application.SendNotification();
1662 application.Render();
1663 application.SendNotification();
1664 application.Render();
1666 // simulate a touch event
1667 Dali::TouchPoint point( 0, TouchPoint::Down, 1, 1 );
1668 Dali::Integration::TouchEvent event;
1669 event.AddPoint( point );
1670 application.ProcessEvent( event );
1672 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1673 DALI_TEST_EQUALS( "OnTouchEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1677 int UtcDaliCustomActorOnHoverEvent(void)
1679 TestApplication application;
1680 tet_infoline("Testing Dali::CustomActor::OnHoverEvent()");
1682 TestCustomActor custom = TestCustomActor::New();
1683 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1685 // set size for custom actor
1686 custom.SetSize( 100, 100 );
1687 // add the custom actor to stage
1688 Stage::GetCurrent().Add( custom );
1689 custom.ResetCallStack();
1691 // Render and notify a couple of times
1692 application.SendNotification();
1693 application.Render();
1694 application.SendNotification();
1695 application.Render();
1697 // simulate a hover event
1698 Dali::TouchPoint point( 0, TouchPoint::Motion, 1, 1 );
1699 Dali::Integration::HoverEvent event;
1700 event.AddPoint( point );
1701 application.ProcessEvent( event );
1703 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1704 DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1708 int UtcDaliCustomActorOnWheelEvent(void)
1710 TestApplication application;
1711 tet_infoline("Testing Dali::CustomActor::OnWheelEvent()");
1713 TestCustomActor custom = TestCustomActor::New();
1714 DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1716 // set size for custom actor
1717 custom.SetSize( 100, 100 );
1718 // add the custom actor to stage
1719 Stage::GetCurrent().Add( custom );
1720 custom.ResetCallStack();
1722 // Render and notify a couple of times
1723 application.SendNotification();
1724 application.Render();
1725 application.SendNotification();
1726 application.Render();
1728 // simulate a wheel event
1729 Vector2 screenCoordinates( 10.0f, 10.0f );
1730 Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
1731 application.ProcessEvent( event );
1733 DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1734 DALI_TEST_EQUALS( "OnWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1738 int UtcDaliCustomActorImplOnPropertySet(void)
1740 TestApplication application;
1741 CustomActorImpl* impl = new Impl::SimpleTestCustomActor();
1743 impl->OnPropertySet( 0, 0 );
1745 DALI_TEST_CHECK( true );
1751 int UtcDaliCustomActorGetImplementation(void)
1753 TestApplication application;
1755 TestCustomActor custom = TestCustomActor::New();
1756 CustomActorImpl& impl = custom.GetImplementation();
1757 impl.GetOwner(); // Test
1759 const TestCustomActor constCustom = TestCustomActor::New();
1760 const CustomActorImpl& constImpl = constCustom.GetImplementation();
1761 constImpl.GetOwner(); // Test
1763 DALI_TEST_CHECK( true );
1767 int UtcDaliCustomActorDoAction(void)
1769 TestApplication application;
1770 tet_infoline("Testing Dali::CustomActor::DoAction()");
1772 TestCustomActor custom = TestCustomActor::New();
1774 BaseHandle customActorObject = custom;
1776 DALI_TEST_CHECK(customActorObject);
1778 Property::Map attributes;
1780 // Check that an invalid command is not performed
1781 DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1783 // Check that the custom actor is visible
1784 custom.SetVisible(true);
1785 DALI_TEST_CHECK(custom.IsVisible() == true);
1787 // Check the custom actor performed an action to hide itself
1788 DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1790 // flush the queue and render once
1791 application.SendNotification();
1792 application.Render();
1794 // Check that the custom actor is now invisible
1795 DALI_TEST_CHECK(custom.IsVisible() == false);
1797 // Check the custom actor performed an action to show itself
1798 DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1800 // flush the queue and render once
1801 application.SendNotification();
1802 application.Render();
1804 // Check that the custom actor is now visible
1805 DALI_TEST_CHECK(custom.IsVisible() == true);
1809 int UtcDaliCustomActorCustomActor(void)
1811 Dali::CustomActor customA;
1812 Dali::CustomActor customB( customA );
1814 DALI_TEST_CHECK( customA == customB );
1819 int UtcDaliCustomActorImplRelayoutRequest(void)
1821 TestApplication application;
1823 DALI_TEST_CHECK( gOnRelayout == false );
1825 TestCustomActor custom = TestCustomActor::NewNegoSize();
1826 Stage::GetCurrent().Add(custom);
1828 application.SendNotification();
1829 application.Render();
1831 DALI_TEST_CHECK( gOnRelayout == true );
1832 gOnRelayout = false;
1834 custom.TestRelayoutRequest();
1835 application.SendNotification();
1836 application.Render();
1838 DALI_TEST_CHECK( gOnRelayout == true );
1843 int UtcDaliCustomActorImplGetHeightForWidthBase(void)
1845 TestApplication application;
1846 TestCustomActor custom = TestCustomActor::NewNegoSize();
1848 float width = 300.0f;
1851 application.SendNotification();
1852 application.Render();
1854 v = custom.TestGetHeightForWidthBase( width );
1856 DALI_TEST_CHECK( v == width );
1861 int UtcDaliCustomActorImplGetWidthForHeightBase(void)
1863 TestApplication application;
1864 TestCustomActor custom = TestCustomActor::NewNegoSize();
1866 float height = 300.0f;
1869 application.SendNotification();
1870 application.Render();
1872 v = custom.TestGetWidthForHeightBase( height );
1874 DALI_TEST_CHECK( v == height );
1879 int UtcDaliCustomActorImplCalculateChildSizeBase(void)
1881 TestApplication application;
1882 TestCustomActor custom = TestCustomActor::NewNegoSize();
1884 Actor child = Actor::New();
1885 child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1886 child.SetSize(150, 150);
1888 application.SendNotification();
1889 application.Render();
1892 v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS );
1893 DALI_TEST_CHECK( v == 0.0f );
1898 int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void)
1900 TestApplication application;
1901 TestCustomActor custom = TestCustomActor::NewNegoSize();
1902 custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS);
1906 v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS );
1907 application.SendNotification();
1908 application.Render();
1910 DALI_TEST_CHECK( v == true );
1912 custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS);
1913 v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH );
1914 application.SendNotification();
1915 application.Render();
1916 DALI_TEST_CHECK( v == false );
1921 int UtcDaliCustomActorTypeRegistry(void)
1923 TestApplication application;
1927 type = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
1928 DALI_TEST_CHECK( type );
1929 BaseHandle handle = type.CreateInstance();
1932 std::string exception;
1936 name = handle.GetTypeName();
1937 tet_result(TET_FAIL);
1939 catch( DaliException& e )
1941 exception = e.condition;
1942 DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION );
1949 int UtcDaliCustomActorGetExtensionP(void)
1951 TestApplication application;
1953 TestCustomActor custom = TestCustomActor::NewVariant5();
1955 DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() );
1960 int UtcDaliCustomActorOnConnectionDepth(void)
1962 TestApplication application;
1963 tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth");
1965 Stage stage = Stage::GetCurrent();
1967 /* Build tree of actors:
1977 * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1980 TestCustomActor actorA = TestCustomActor::New();
1981 stage.Add( actorA );
1983 TestCustomActor actorB = TestCustomActor::New();
1984 actorA.Add( actorB );
1986 TestCustomActor actorC = TestCustomActor::New();
1987 actorA.Add( actorC );
1989 TestCustomActor actorD = TestCustomActor::New();
1990 actorB.Add( actorD );
1992 TestCustomActor actorE = TestCustomActor::New();
1993 actorB.Add( actorE );
1995 TestCustomActor actorF = TestCustomActor::New();
1996 actorC.Add( actorF );
1998 // Excercise the message passing to Update thread
1999 application.SendNotification();
2000 application.Render();
2001 application.Render();
2003 DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
2004 DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
2005 DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
2006 DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
2007 DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
2008 DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );