Merge "Add cmake to the required system packages list in dali_env" into tizen
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-CustomActor.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <dali/public-api/dali-core.h>
21
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/mouse-wheel-event-integ.h>
25 #include <dali/integration-api/events/key-event-integ.h>
26
27 #include "dali-test-suite-utils/dali-test-suite-utils.h"
28
29 using namespace Dali;
30
31
32 void custom_actor_test_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void custom_actor_test_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 namespace
43 {
44
45 std::vector< std::string > MasterCallStack;
46
47 } // anon namespace
48
49 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
50 namespace Impl
51 {
52
53 struct TestCustomActor : public CustomActorImpl
54 {
55   /**
56    * Constructor
57    */
58   TestCustomActor()
59   : CustomActorImpl( true ), // requires touch
60     mDaliProperty( Property::INVALID_INDEX ),
61     mSizeSet( Vector3::ZERO ),
62     mTargetSize( Vector3::ZERO )
63   {
64     SetRequiresMouseWheelEvents(true);
65     SetRequiresHoverEvents(true);
66   }
67
68   /**
69    * Destructor
70    */
71   virtual ~TestCustomActor()
72   {
73   }
74
75   void Initialize( const char* name = NULL )
76   {
77     mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
78
79     OnInitialize( name );
80   }
81
82   virtual void OnInitialize( const char* name ) {}
83
84   /**
85    * Resets the call stack
86    */
87   void ResetCallStack()
88   {
89     mSizeSet = Vector3();
90     mTargetSize = Vector3();
91     mMethodsCalled.clear();
92   }
93
94   void AddToCallStacks( const char* method )
95   {
96     mMethodsCalled.push_back( method );
97
98     // Combine Actor name with method string
99     std::string nameAndMethod( Self().GetName() );
100     if ( 0 == nameAndMethod.size() )
101     {
102       nameAndMethod = "Unknown: ";
103     }
104     else
105     {
106       nameAndMethod += ": ";
107     }
108     nameAndMethod += method;
109
110     MasterCallStack.push_back( nameAndMethod );
111   }
112
113   // From CustomActorImpl
114   virtual void OnStageConnection()
115   {
116     AddToCallStacks("OnStageConnection");
117   }
118   virtual void OnStageDisconnection()
119   {
120     AddToCallStacks("OnStageDisconnection");
121   }
122   virtual void OnChildAdd(Actor& child)
123   {
124     AddToCallStacks("OnChildAdd");
125   }
126   virtual void OnChildRemove(Actor& child)
127   {
128     AddToCallStacks("OnChildRemove");
129   }
130   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
131   {
132     AddToCallStacks("OnPropertySet");
133   }
134   virtual void OnSizeSet(const Vector3& targetSize)
135   {
136     mSizeSet = targetSize;
137     AddToCallStacks("OnSizeSet");
138   }
139   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
140   {
141     mTargetSize = targetSize;
142     AddToCallStacks("OnSizeAnimation");
143   }
144   virtual bool OnTouchEvent(const TouchEvent& event)
145   {
146     AddToCallStacks("OnTouchEvent");
147     return true;
148   }
149   virtual bool OnHoverEvent(const HoverEvent& event)
150   {
151     AddToCallStacks("OnHoverEvent");
152     return true;
153   }
154   virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
155   {
156     AddToCallStacks("OnMouseWheelEvent");
157     return true;
158   }
159   virtual bool OnKeyEvent(const KeyEvent& event)
160   {
161     AddToCallStacks("OnKeyEvent");
162     return true;
163   }
164   virtual void OnKeyInputFocusGained()
165   {
166     AddToCallStacks("OnKeyInputFocusGained");
167   }
168   virtual void OnKeyInputFocusLost()
169   {
170     AddToCallStacks("OnKeyInputFocusLost");
171   }
172   virtual Vector3 GetNaturalSize()
173   {
174     return Vector3( 0.0f, 0.0f, 0.0f );
175   }
176
177   virtual float GetHeightForWidth( float width )
178   {
179     return 0.0f;
180   }
181
182   virtual float GetWidthForHeight( float height )
183   {
184     return 0.0f;
185   }
186
187   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
188   {
189   }
190
191   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
192   {
193   }
194
195   virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
196   {
197   }
198
199   virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
200   {
201     return 0.0f;
202   }
203
204   virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
205   {
206   }
207
208   virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
209   {
210     return false;
211   }
212
213   void SetDaliProperty(std::string s)
214   {
215     Self().SetProperty(mDaliProperty, s) ;
216   }
217
218   Property::Index mDaliProperty;
219   std::vector< std::string > mMethodsCalled;
220   Vector3 mSizeSet;
221   Vector3 mTargetSize;
222 };
223
224 /**
225  * Variant which adds a new child during OnStageConnection
226  */
227 struct TestCustomActorVariant1 : public TestCustomActor
228 {
229   /**
230    * Constructor
231    */
232   TestCustomActorVariant1( Actor childToAdd )
233   : mChildToAdd( childToAdd )
234   {
235   }
236
237   // From CustomActorImpl
238   virtual void OnStageConnection()
239   {
240     // Chain up first
241     TestCustomActor::OnStageConnection();
242
243     // Add the child
244     Self().Add( mChildToAdd );
245   }
246
247   Actor mChildToAdd;
248 };
249
250 /**
251  * Variant which removes children during OnStageConnection
252  */
253 struct TestCustomActorVariant2 : public TestCustomActor
254 {
255   /**
256    * Constructor
257    */
258   TestCustomActorVariant2()
259   {
260   }
261
262   // From CustomActorImpl
263   virtual void OnStageConnection()
264   {
265     // Chain up first
266     TestCustomActor::OnStageConnection();
267
268     // Remove all the children
269     for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
270     {
271       Self().Remove( Self().GetChildAt(0) );
272     }
273   }
274 };
275
276 /**
277  * Variant which adds a new child during OnStageDisconnection
278  */
279 struct TestCustomActorVariant3 : public TestCustomActor
280 {
281   /**
282    * Constructor
283    */
284   TestCustomActorVariant3( Actor childToAdd )
285   : mChildToAdd( childToAdd )
286   {
287   }
288
289   // From CustomActorImpl
290   virtual void OnStageDisconnection()
291   {
292     // Chain up first
293     TestCustomActor::OnStageDisconnection();
294
295     // Add the child
296     Self().Add( mChildToAdd );
297   }
298
299   Actor mChildToAdd;
300 };
301
302 /**
303  * Variant which removes children during OnStageDisconnection
304  */
305 struct TestCustomActorVariant4 : public TestCustomActor
306 {
307   /**
308    * Constructor
309    */
310   TestCustomActorVariant4()
311   {
312   }
313
314   // From CustomActorImpl
315   virtual void OnStageDisconnection()
316   {
317     // Chain up first
318     TestCustomActor::OnStageDisconnection();
319
320     // Remove all the children
321     for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
322     {
323       Self().Remove( Self().GetChildAt(0) );
324     }
325   }
326 };
327
328 /**
329  * Variant which removes its parent from Stage during OnStageConnection
330  */
331 struct TestCustomActorVariant5 : public TestCustomActor
332 {
333   /**
334    * Constructor
335    */
336   TestCustomActorVariant5()
337   {
338   }
339
340   // From CustomActorImpl
341   virtual void OnStageConnection()
342   {
343     // Chain up first
344     TestCustomActor::OnStageConnection();
345
346     // Take parent off-stage
347     Actor parent = Self().GetParent();
348     if ( parent )
349     {
350       Stage::GetCurrent().Remove( parent );
351     }
352   }
353 };
354
355 /**
356  * Variant which adds its parent to Stage during OnStageDisconnection
357  */
358 struct TestCustomActorVariant6 : public TestCustomActor
359 {
360   /**
361    * Constructor
362    */
363   TestCustomActorVariant6()
364   {
365   }
366
367   // From CustomActorImpl
368   virtual void OnStageDisconnection()
369   {
370     // Chain up first
371     TestCustomActor::OnStageDisconnection();
372
373     // Put parent on-stage
374     Actor parent = Self().GetParent();
375     if ( parent )
376     {
377       Stage::GetCurrent().Add( parent );
378     }
379   }
380 };
381
382 /**
383  * Variant which reparents its children into a separate container
384  */
385 struct TestCustomActorVariant7 : public TestCustomActor
386 {
387   /**
388    * Constructor
389    */
390   TestCustomActorVariant7()
391   {
392   }
393
394   virtual void OnInitialize( const char* name )
395   {
396     // We need to do this early, before the OnChildAdd is recorded
397     Self().SetName( name );
398
399     mContainer = Actor::New();
400     mContainer.SetName( "Container" );
401     Self().Add( mContainer );
402   }
403
404   // From CustomActorImpl
405   virtual void OnChildAdd(Actor& child)
406   {
407     // Chain up first
408     TestCustomActor::OnChildAdd(child);
409
410     // Reparent child
411     if ( child != mContainer )
412     {
413       mContainer.Add( child );
414     }
415   }
416
417   Actor mContainer;
418 };
419
420 /**
421  * Variant which attempts to interfere with the reparenting of a child to another container
422  */
423 struct TestCustomActorVariant8 : public TestCustomActor
424 {
425   /**
426    * Constructor
427    */
428   TestCustomActorVariant8( Actor rival )
429   : mRivalContainer( rival )
430   {
431   }
432
433   // From CustomActorImpl
434   virtual void OnChildRemove(Actor& child)
435   {
436     // Chain up first
437     TestCustomActor::OnChildRemove(child);
438
439     mRivalContainer.Remove( child ); // attempt to block reparenting to rival (should be a NOOP)
440   }
441
442   Actor mRivalContainer;
443 };
444
445 // Need a class that doesn't override virtual methods
446 class SimpleTestCustomActor : public CustomActorImpl
447 {
448 public:
449
450   /**
451    * Constructor
452    */
453   SimpleTestCustomActor()
454   : CustomActorImpl( true ) // requires touch
455   {
456   }
457
458   /**
459    * Destructor
460    */
461   virtual ~SimpleTestCustomActor()
462   {
463   }
464
465   // From CustomActorImpl
466   virtual void OnStageConnection()
467   {
468   }
469   virtual void OnStageDisconnection()
470   {
471   }
472   virtual void OnChildAdd(Actor& child)
473   {
474   }
475   virtual void OnChildRemove(Actor& child)
476   {
477   }
478   virtual void OnSizeSet(const Vector3& targetSize)
479   {
480   }
481   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
482   {
483   }
484   virtual bool OnTouchEvent(const TouchEvent& event)
485   {
486     return true;
487   }
488   virtual bool OnHoverEvent(const HoverEvent& event)
489   {
490     return true;
491   }
492   virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
493   {
494     return true;
495   }
496   virtual bool OnKeyEvent(const KeyEvent& event)
497   {
498     return true;
499   }
500   virtual void OnKeyInputFocusGained()
501   {
502   }
503   virtual void OnKeyInputFocusLost()
504   {
505   }
506
507   virtual Vector3 GetNaturalSize()
508   {
509     return Vector3( 0.0f, 0.0f, 0.0f );
510   }
511
512   virtual float GetHeightForWidth( float width )
513   {
514     return 0.0f;
515   }
516
517   virtual float GetWidthForHeight( float height )
518   {
519     return 0.0f;
520   }
521
522   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
523   {
524   }
525
526   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
527   {
528   }
529
530   virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
531   {
532   }
533
534   virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
535   {
536     return 0.0f;
537   }
538
539   virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
540   {
541   }
542
543   virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
544   {
545     return false;
546   }
547 };
548
549 } ; // namespace Impl
550
551
552 namespace
553 {
554
555 /**
556  * Test custom actor handle
557  */
558 class TestCustomActor : public CustomActor
559 {
560 public:
561
562   static TestCustomActor New()
563   {
564     Impl::TestCustomActor* impl = new Impl::TestCustomActor;
565     TestCustomActor custom( *impl ); // takes ownership
566
567     impl->Initialize();
568
569     return custom;
570   }
571
572   static TestCustomActor NewVariant1( Actor childToAdd )
573   {
574     Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd );
575     TestCustomActor custom( *impl ); // takes ownership
576
577     impl->Initialize();
578
579     return custom;
580   }
581
582   static TestCustomActor NewVariant2()
583   {
584     Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2();
585     TestCustomActor custom( *impl ); // takes ownership
586
587     impl->Initialize();
588
589     return custom;
590   }
591
592   static TestCustomActor NewVariant3( Actor childToAdd )
593   {
594     Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3( childToAdd );
595     TestCustomActor custom( *impl ); // takes ownership
596
597     impl->Initialize();
598
599     return custom;
600   }
601
602   static TestCustomActor NewVariant4()
603   {
604     Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4();
605     TestCustomActor custom( *impl ); // takes ownership
606
607     impl->Initialize();
608
609     return custom;
610   }
611
612   static TestCustomActor NewVariant5()
613   {
614     Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5();
615     TestCustomActor custom( *impl ); // takes ownership
616
617     impl->Initialize();
618
619     return custom;
620   }
621
622   static TestCustomActor NewVariant6()
623   {
624     Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6();
625     TestCustomActor custom( *impl ); // takes ownership
626
627     impl->Initialize();
628
629     return custom;
630   }
631
632   static TestCustomActor NewVariant7( const char* name )
633   {
634     Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7();
635     TestCustomActor custom( *impl ); // takes ownership
636
637     impl->Initialize( name );
638
639     return custom;
640   }
641
642   static TestCustomActor NewVariant8( Actor rival )
643   {
644     Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8( rival );
645     TestCustomActor custom( *impl ); // takes ownership
646
647     impl->Initialize();
648
649     return custom;
650   }
651
652   virtual ~TestCustomActor()
653   {
654   }
655
656   Impl::TestCustomActor& GetImpl()
657   {
658     return static_cast<Impl::TestCustomActor&>(GetImplementation());
659   }
660
661   std::vector< std::string >& GetMethodsCalled()
662   {
663     return GetImpl().mMethodsCalled;
664   }
665
666   void ResetCallStack()
667   {
668     GetImpl().ResetCallStack();
669   }
670
671   void SetDaliProperty(std::string s)
672   {
673     GetImpl().SetDaliProperty(s);
674   }
675
676   Vector3 GetSize()
677   {
678     return GetImpl().mSizeSet;
679   }
680
681   Vector3 GetTargetSize()
682   {
683     return GetImpl().mTargetSize;
684   }
685
686   virtual Vector3 GetNaturalSize()
687   {
688     return Vector3( 0.0f, 0.0f, 0.0f );
689   }
690
691   virtual float GetHeightForWidth( float width )
692   {
693     return 0.0f;
694   }
695
696   virtual float GetWidthForHeight( float height )
697   {
698     return 0.0f;
699   }
700
701   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
702   {
703   }
704
705   virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
706   {
707   }
708
709   virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
710   {
711   }
712
713 private:
714
715   TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl )
716   {
717   }
718 };
719
720
721
722 using namespace Dali;
723
724 BaseHandle CreateActor()
725 {
726   return TestCustomActor::New();
727 }
728
729 Dali::TypeRegistration mType( typeid(TestCustomActor), typeid(Dali::CustomActor), CreateActor );
730
731 } // anon namespace
732
733
734 int UtcDaliCustomActorDestructor(void)
735 {
736   TestApplication application;
737
738   CustomActor* actor = new CustomActor();
739   delete actor;
740
741   DALI_TEST_CHECK( true );
742   END_TEST;
743 }
744
745 int UtcDaliCustomActorImplDestructor(void)
746 {
747   TestApplication application;
748   CustomActorImpl* actor = new Impl::TestCustomActor();
749   delete actor;
750
751   DALI_TEST_CHECK( true );
752   END_TEST;
753 }
754
755 // Positive test case for a method
756 int UtcDaliCustomActorDownCast(void)
757 {
758   TestApplication application;
759   tet_infoline("Testing Dali::CustomActor::DownCast()");
760
761   TestCustomActor custom = TestCustomActor::New();
762
763   Actor anActor = Actor::New();
764   anActor.Add( custom );
765
766   Actor child = anActor.GetChildAt(0);
767   CustomActor customActor = CustomActor::DownCast( child );
768   DALI_TEST_CHECK( customActor );
769
770   customActor = NULL;
771   DALI_TEST_CHECK( !customActor );
772
773   customActor = DownCast< CustomActor >( child );
774   DALI_TEST_CHECK( customActor );
775   END_TEST;
776 }
777
778 // Negative test case for a method
779 int UtcDaliCustomActorDownCastNegative(void)
780 {
781   TestApplication application;
782   tet_infoline("Testing Dali::CustomActor::DownCast()");
783
784   Actor actor1 = Actor::New();
785   Actor anActor = Actor::New();
786   anActor.Add(actor1);
787
788   Actor child = anActor.GetChildAt(0);
789   CustomActor customActor = CustomActor::DownCast( child );
790   DALI_TEST_CHECK( !customActor );
791
792   Actor unInitialzedActor;
793   customActor = CustomActor::DownCast( unInitialzedActor );
794   DALI_TEST_CHECK( !customActor );
795
796   customActor = DownCast< CustomActor >( unInitialzedActor );
797   DALI_TEST_CHECK( !customActor );
798   END_TEST;
799 }
800
801 int UtcDaliCustomActorOnStageConnectionDisconnection(void)
802 {
803   TestApplication application;
804   tet_infoline("Testing Dali::CustomActor::OnStageConnection() & OnStageDisconnection");
805
806   TestCustomActor custom = TestCustomActor::New();
807   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
808
809   // add the custom actor to stage
810   Stage::GetCurrent().Add( custom );
811
812   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
813   DALI_TEST_EQUALS( "OnStageConnection", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
814
815   Stage::GetCurrent().Remove( custom );
816
817   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
818   DALI_TEST_EQUALS( "OnStageDisconnection", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
819
820   // Excercise the message passing to Update thread
821
822   application.SendNotification();
823   application.Render();
824   application.Render();
825   END_TEST;
826 }
827
828 int UtcDaliCustomActorOnStageConnectionOrder(void)
829 {
830   TestApplication application;
831   tet_infoline("Testing Dali::CustomActor::OnStageConnection() order");
832
833   MasterCallStack.clear();
834
835   /* Build tree of actors:
836    *
837    *       A (parent)
838    *      / \
839    *     B   C
840    *    / \   \
841    *   D   E   F
842    *
843    * OnStageConnection should be received for A, B, D, E, C, and finally F
844    */
845
846   TestCustomActor actorA = TestCustomActor::New();
847   actorA.SetName( "ActorA" );
848
849   TestCustomActor actorB = TestCustomActor::New();
850   actorB.SetName( "ActorB" );
851   actorA.Add( actorB );
852
853   TestCustomActor actorC = TestCustomActor::New();
854   actorC.SetName( "ActorC" );
855   actorA.Add( actorC );
856
857   TestCustomActor actorD = TestCustomActor::New();
858   actorD.SetName( "ActorD" );
859   actorB.Add( actorD );
860
861   TestCustomActor actorE = TestCustomActor::New();
862   actorE.SetName( "ActorE" );
863   actorB.Add( actorE );
864
865   TestCustomActor actorF = TestCustomActor::New();
866   actorF.SetName( "ActorF" );
867   actorC.Add( actorF );
868
869   // add the custom actor to stage
870   Stage::GetCurrent().Add( actorA );
871
872   DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
873   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
874   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
875   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
876
877   DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
878   DALI_TEST_EQUALS( "OnChildAdd",        actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
879   DALI_TEST_EQUALS( "OnChildAdd",        actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
880   DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
881
882   DALI_TEST_EQUALS( 2, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
883   DALI_TEST_EQUALS( "OnChildAdd",        actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
884   DALI_TEST_EQUALS( "OnStageConnection", actorC.GetMethodsCalled()[ 1 ], TEST_LOCATION );
885
886   DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
887   DALI_TEST_EQUALS( "OnStageConnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
888
889   DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
890   DALI_TEST_EQUALS( "OnStageConnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
891
892   DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
893   DALI_TEST_EQUALS( "OnStageConnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
894
895   // Check sequence is correct in MasterCallStack
896
897   DALI_TEST_EQUALS( 3+3+2+1+1+1, (int)(MasterCallStack.size()), TEST_LOCATION );
898
899   DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
900   DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
901   DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
902   DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 3 ], TEST_LOCATION );
903   DALI_TEST_EQUALS( "ActorC: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
904
905   DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 5 ], TEST_LOCATION );
906   DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 6 ], TEST_LOCATION );
907   DALI_TEST_EQUALS( "ActorD: OnStageConnection", MasterCallStack[ 7 ], TEST_LOCATION );
908   DALI_TEST_EQUALS( "ActorE: OnStageConnection", MasterCallStack[ 8 ], TEST_LOCATION );
909   DALI_TEST_EQUALS( "ActorC: OnStageConnection", MasterCallStack[ 9 ], TEST_LOCATION );
910   DALI_TEST_EQUALS( "ActorF: OnStageConnection", MasterCallStack[ 10 ], TEST_LOCATION );
911
912   // Excercise the message passing to Update thread
913
914   application.SendNotification();
915   application.Render();
916   application.Render();
917   END_TEST;
918 }
919
920 int UtcDaliCustomActorOnStageDisconnectionOrder(void)
921 {
922   TestApplication application;
923   tet_infoline("Testing Dali::CustomActor::OnStageDisconnection() order");
924
925   Stage stage = Stage::GetCurrent();
926
927   /* Build tree of actors:
928    *
929    *       A (parent)
930    *      / \
931    *     B   C
932    *    / \   \
933    *   D   E   F
934    *
935    * OnStageDisconnection should be received for D, E, B, F, C, and finally A.
936    */
937
938   TestCustomActor actorA = TestCustomActor::New();
939   actorA.SetName( "ActorA" );
940   stage.Add( actorA );
941
942   TestCustomActor actorB = TestCustomActor::New();
943   actorB.SetName( "ActorB" );
944   actorA.Add( actorB );
945
946   TestCustomActor actorC = TestCustomActor::New();
947   actorC.SetName( "ActorC" );
948   actorA.Add( actorC );
949
950   TestCustomActor actorD = TestCustomActor::New();
951   actorD.SetName( "ActorD" );
952   actorB.Add( actorD );
953
954   TestCustomActor actorE = TestCustomActor::New();
955   actorE.SetName( "ActorE" );
956   actorB.Add( actorE );
957
958   TestCustomActor actorF = TestCustomActor::New();
959   actorF.SetName( "ActorF" );
960   actorC.Add( actorF );
961
962   // Excercise the message passing to Update thread
963
964   application.SendNotification();
965   application.Render();
966   application.Render();
967
968   // Clear call stacks before disconnection
969   actorA.ResetCallStack();
970   actorB.ResetCallStack();
971   actorC.ResetCallStack();
972   actorD.ResetCallStack();
973   actorE.ResetCallStack();
974   actorF.ResetCallStack();
975   MasterCallStack.clear();
976
977   stage.Remove( actorA );
978
979   DALI_TEST_EQUALS( 1, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
980   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
981
982   DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
983   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
984
985   DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
986   DALI_TEST_EQUALS( "OnStageDisconnection", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
987
988   DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
989   DALI_TEST_EQUALS( "OnStageDisconnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
990
991   DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
992   DALI_TEST_EQUALS( "OnStageDisconnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
993
994   DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
995   DALI_TEST_EQUALS( "OnStageDisconnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
996
997   // Check sequence is correct in MasterCallStack
998
999   DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
1000
1001   DALI_TEST_EQUALS( "ActorD: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1002   DALI_TEST_EQUALS( "ActorE: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
1003   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 2 ], TEST_LOCATION );
1004   DALI_TEST_EQUALS( "ActorF: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1005   DALI_TEST_EQUALS( "ActorC: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
1006   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
1007
1008   // Excercise the message passing to Update thread
1009
1010   application.SendNotification();
1011   application.Render();
1012   application.Render();
1013   END_TEST;
1014 }
1015
1016 int UtcDaliCustomActorAddDuringOnStageConnection(void)
1017 {
1018   TestApplication application;
1019   tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageConnection() callback");
1020
1021   Stage stage = Stage::GetCurrent();
1022
1023   MasterCallStack.clear();
1024
1025   /* The actorA is a special variant which adds a child to itself during OnStageConnection()
1026    * The actorB is provided as the child
1027    */
1028
1029   TestCustomActor actorB = TestCustomActor::New();
1030   actorB.SetName( "ActorB" );
1031
1032   TestCustomActor actorA = TestCustomActor::NewVariant1( actorB );
1033   actorA.SetName( "ActorA" );
1034   stage.Add( actorA );
1035
1036   // Check callback sequence
1037
1038   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1039   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1040   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // Called from within OnStageConnection()
1041
1042   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1043   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1044
1045   DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
1046
1047   DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
1048   DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION ); // Occurs during Actor::Add from within from within OnStageConnection()
1049   DALI_TEST_EQUALS( "ActorA: OnChildAdd",        MasterCallStack[ 2 ], TEST_LOCATION ); // Occurs after Actor::Add from within from within OnStageConnection()
1050
1051   // Excercise the message passing to Update thread
1052
1053   application.SendNotification();
1054   application.Render();
1055   application.Render();
1056
1057   // Check everything is ok after Actors are removed
1058
1059   stage.Remove( actorA );
1060   application.SendNotification();
1061   application.Render();
1062   application.Render();
1063   END_TEST;
1064 }
1065
1066 int UtcDaliCustomActorRemoveDuringOnStageConnection(void)
1067 {
1068   TestApplication application;
1069   tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageConnection() callback");
1070
1071   Stage stage = Stage::GetCurrent();
1072
1073   MasterCallStack.clear();
1074
1075   /* The actorA is a special variant which removes its children during OnStageConnection()
1076    * Actors B & C are provided as the children
1077    */
1078
1079   TestCustomActor actorA = TestCustomActor::NewVariant2();
1080   actorA.SetName( "ActorA" );
1081
1082   TestCustomActor actorB = TestCustomActor::New();
1083   actorB.SetName( "ActorB" );
1084   actorA.Add( actorB );
1085
1086   TestCustomActor actorC = TestCustomActor::New();
1087   actorC.SetName( "ActorC" );
1088   actorA.Add( actorC );
1089
1090   stage.Add( actorA );
1091
1092   // Check callback sequence
1093
1094   DALI_TEST_EQUALS( 5, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1095   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1096   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1097   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1098   DALI_TEST_EQUALS( "OnChildRemove",     actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // Called from within OnStageConnection()
1099   DALI_TEST_EQUALS( "OnChildRemove",     actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION ); // Called from within OnStageConnection()
1100
1101   DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
1102
1103   DALI_TEST_EQUALS( "ActorA: OnChildAdd",        MasterCallStack[ 0 ], TEST_LOCATION );
1104   DALI_TEST_EQUALS( "ActorA: OnChildAdd",        MasterCallStack[ 1 ], TEST_LOCATION );
1105   DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
1106   DALI_TEST_EQUALS( "ActorA: OnChildRemove",     MasterCallStack[ 3 ], TEST_LOCATION );
1107   DALI_TEST_EQUALS( "ActorA: OnChildRemove",     MasterCallStack[ 4 ], TEST_LOCATION );
1108
1109   /* Actors B & C should be removed before the point where they could receive an OnStageConnection callback
1110    * Therefore they shouldn't receive either OnStageConnection or OnStageDisconnection
1111    */
1112   DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1113   DALI_TEST_EQUALS( 0, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
1114
1115   // Excercise the message passing to Update thread
1116
1117   application.SendNotification();
1118   application.Render();
1119   application.Render();
1120
1121   // Check everything is ok after last actor is removed
1122
1123   stage.Remove( actorA );
1124   application.SendNotification();
1125   application.Render();
1126   application.Render();
1127   END_TEST;
1128 }
1129
1130 int UtcDaliCustomActorAddDuringOnStageDisconnection(void)
1131 {
1132   TestApplication application;
1133   tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageDisonnection() callback");
1134
1135   Stage stage = Stage::GetCurrent();
1136
1137   /* The actorA is a special variant which adds a child to itself during OnStageDisconnection()
1138    * The actorB is provided as the child
1139    */
1140
1141   TestCustomActor actorB = TestCustomActor::New();
1142   actorB.SetName( "ActorB" );
1143
1144   TestCustomActor actorA = TestCustomActor::NewVariant3( actorB );
1145   actorA.SetName( "ActorA" );
1146   stage.Add( actorA );
1147
1148   // Excercise the message passing to Update thread
1149
1150   application.SendNotification();
1151   application.Render();
1152   application.Render();
1153
1154   // Clear call stacks before disconnection
1155   actorA.ResetCallStack();
1156   actorB.ResetCallStack();
1157   MasterCallStack.clear();
1158
1159   stage.Remove( actorA );
1160
1161   // Check callback sequence
1162
1163   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1164   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1165   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1166
1167   // Child was added after parent disconnection, so should not receive OnStageConnection()
1168   DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1169
1170   DALI_TEST_EQUALS( 2, (int)(MasterCallStack.size()), TEST_LOCATION );
1171
1172   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1173   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 1 ], TEST_LOCATION );
1174
1175   // Excercise the message passing to Update thread
1176
1177   application.SendNotification();
1178   application.Render();
1179   application.Render();
1180   END_TEST;
1181 }
1182
1183 int UtcDaliCustomActorRemoveDuringOnStageDisconnection(void)
1184 {
1185   TestApplication application;
1186   tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageDisconnection() callback");
1187
1188   Stage stage = Stage::GetCurrent();
1189
1190   /* The actorA is a special variant which removes its children during OnStageDisconnection()
1191    * The actorB is provided as the child
1192    */
1193
1194   TestCustomActor actorA = TestCustomActor::NewVariant4();
1195   actorA.SetName( "ActorA" );
1196   stage.Add( actorA );
1197
1198   TestCustomActor actorB = TestCustomActor::New();
1199   actorB.SetName( "ActorB" );
1200   actorA.Add( actorB );
1201
1202   // Excercise the message passing to Update thread
1203
1204   application.SendNotification();
1205   application.Render();
1206   application.Render();
1207
1208   // Clear call stacks before disconnection
1209   actorA.ResetCallStack();
1210   actorB.ResetCallStack();
1211   MasterCallStack.clear();
1212
1213   stage.Remove( actorA );
1214
1215   // Check callback sequence
1216
1217   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1218   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1219   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1220
1221   DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1222   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1223
1224   DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
1225
1226   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1227   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
1228   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 2 ], TEST_LOCATION );
1229
1230   // Excercise the message passing to Update thread
1231
1232   application.SendNotification();
1233   application.Render();
1234   application.Render();
1235   END_TEST;
1236 }
1237
1238 int UtcDaliCustomActorRemoveParentDuringOnStageConnection(void)
1239 {
1240   TestApplication application;
1241   tet_infoline("Weird test where child removes its own parent from Stage during Dali::CustomActor::OnStageConnection() callback");
1242
1243   Stage stage = Stage::GetCurrent();
1244
1245   MasterCallStack.clear();
1246
1247   /* The actorA is the parent of actorB
1248    * The actorB is a special variant which removes its own parent during OnStageConnection()
1249    * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnStageDisconnection()
1250    */
1251
1252   TestCustomActor actorA = TestCustomActor::New();
1253   actorA.SetName( "ActorA" );
1254
1255   TestCustomActor actorB = TestCustomActor::NewVariant5();
1256   actorB.SetName( "ActorB" );
1257   actorA.Add( actorB );
1258
1259   stage.Add( actorA );
1260
1261   // Check callback sequence
1262
1263   DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1264   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1265   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1266   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1267
1268   DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1269   DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1270
1271   DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
1272
1273   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 0 ], TEST_LOCATION );
1274   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
1275   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 2 ], TEST_LOCATION );
1276   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1277
1278   // Excercise the message passing to Update thread
1279
1280   application.SendNotification();
1281   application.Render();
1282   application.Render();
1283   END_TEST;
1284 }
1285
1286 int UtcDaliCustomActorAddParentDuringOnStageDisconnection(void)
1287 {
1288   TestApplication application;
1289   tet_infoline("Weird test where child adds its own parent to Stage during Dali::CustomActor::OnStageDisconnection() callback");
1290
1291   Stage stage = Stage::GetCurrent();
1292
1293   MasterCallStack.clear();
1294
1295   /* The actorA is the parent of actorB
1296    * The actorB is a special variant which (weirdly) adds its own parent during OnStageDisconnection()
1297    * The child actor is interrupting the disconnection, such that parent should not get a OnStageDisconnection()
1298    */
1299
1300   TestCustomActor actorA = TestCustomActor::New();
1301   actorA.SetName( "ActorA" );
1302   stage.Add( actorA );
1303
1304   TestCustomActor actorB = TestCustomActor::NewVariant6();
1305   actorB.SetName( "ActorB" );
1306   actorA.Add( actorB );
1307
1308   stage.Remove( actorA );
1309
1310   // Check callback sequence
1311
1312   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1313   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1314   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1315
1316   DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1317   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1318   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1319   // Disconnect was interrupted, so we should only get one OnStageConnection() for actorB
1320
1321   DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
1322
1323   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 0 ], TEST_LOCATION );
1324   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
1325   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 2 ], TEST_LOCATION );
1326   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1327
1328   // Excercise the message passing to Update thread
1329
1330   application.SendNotification();
1331   application.Render();
1332   application.Render();
1333   END_TEST;
1334 }
1335
1336 int UtcDaliCustomActorOnChildAddRemove(void)
1337 {
1338   TestApplication application;
1339   tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()");
1340
1341   TestCustomActor custom = TestCustomActor::New();
1342   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1343
1344   Actor aChild = Actor::New();
1345   custom.Add( aChild );
1346
1347   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1348   DALI_TEST_EQUALS( "OnChildAdd", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1349
1350   custom.Remove( aChild );
1351
1352   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1353   DALI_TEST_EQUALS( "OnChildRemove", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1354   END_TEST;
1355 }
1356
1357 int UtcDaliCustomActorReparentDuringOnChildAdd(void)
1358 {
1359   TestApplication application;
1360   tet_infoline("Testing Actor:Add (reparenting) behaviour during Dali::CustomActor::OnChildAdd() callback");
1361
1362   Stage stage = Stage::GetCurrent();
1363
1364   MasterCallStack.clear();
1365
1366   /* The actorA is a special variant which reparents children added into a separate container child
1367    * The actorB is the child of actorA
1368    */
1369
1370   TestCustomActor actorA = TestCustomActor::NewVariant7( "ActorA" );
1371   stage.Add( actorA );
1372
1373   TestCustomActor actorB = TestCustomActor::New();
1374   actorB.SetName( "ActorB" );
1375   actorA.Add( actorB );
1376
1377   // Check hierarchy is as follows:
1378   //  A
1379   //  |
1380   //  Container
1381   //  |
1382   //  B
1383
1384   DALI_TEST_EQUALS( 1, (int)(actorA.GetChildCount()), TEST_LOCATION );
1385
1386   Actor container = actorA.GetChildAt(0);
1387   Actor containerChild;
1388
1389   DALI_TEST_CHECK( container );
1390   if ( container )
1391   {
1392     DALI_TEST_EQUALS( "Container", container.GetName(), TEST_LOCATION );
1393     DALI_TEST_EQUALS( 1, (int)(container.GetChildCount()), TEST_LOCATION );
1394     containerChild = container.GetChildAt(0);
1395   }
1396
1397   DALI_TEST_CHECK( containerChild );
1398   if ( containerChild )
1399   {
1400     DALI_TEST_EQUALS( "ActorB", containerChild.GetName(), TEST_LOCATION );
1401     DALI_TEST_EQUALS( 0, (int)(containerChild.GetChildCount()), TEST_LOCATION );
1402   }
1403
1404   // Check callback sequence
1405
1406   DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1407   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
1408   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1409   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
1410   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
1411   // mContainer will then receive OnChildAdd
1412
1413   DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1414   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1415   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1416   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1417
1418   DALI_TEST_EQUALS( 7, (int)(MasterCallStack.size()), TEST_LOCATION );
1419
1420   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 0 ], TEST_LOCATION );
1421   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
1422   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 2 ], TEST_LOCATION );
1423   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 3 ], TEST_LOCATION );
1424   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
1425   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 5 ], TEST_LOCATION );
1426   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 6 ], TEST_LOCATION );
1427
1428   // Excercise the message passing to Update thread
1429
1430   application.SendNotification();
1431   application.Render();
1432   application.Render();
1433   END_TEST;
1434 }
1435
1436 /**
1437  * Test that Remove can be called (a NOOP) during the OnChildRemove
1438  * triggered when reparenting an actor
1439  */
1440 int UtcDaliCustomActorRemoveDuringOnChildRemove(void)
1441 {
1442   TestApplication application;
1443   tet_infoline("Testing Actor:Remove behaviour during OnChildRemove() callback triggered when reparenting");
1444
1445   Stage stage = Stage::GetCurrent();
1446
1447   MasterCallStack.clear();
1448
1449   /* The childActor will be reparented from actorA to actorB
1450    * The actorA is a special variant which attempts to remove a child from actorB, during the OnChildRemove callback()
1451    * This should be a NOOP since the reparenting has not occured yet
1452    */
1453
1454   TestCustomActor actorB = TestCustomActor::New();
1455   actorB.SetName( "ActorB" );
1456   stage.Add( actorB );
1457
1458   TestCustomActor actorA = TestCustomActor::NewVariant8( actorB );
1459   actorA.SetName( "ActorA" );
1460   stage.Add( actorA );
1461
1462   Actor childActor = Actor::New();
1463   childActor.SetName( "Child" );
1464   // Reparent from actorA to actorB
1465   actorA.Add( childActor );
1466   actorB.Add( childActor );
1467
1468   // Check hierarchy is as follows:
1469   //  A    B
1470   //       |
1471   //       Child
1472
1473   DALI_TEST_EQUALS( 0, (int)(actorA.GetChildCount()), TEST_LOCATION );
1474   DALI_TEST_EQUALS( 1, (int)(actorB.GetChildCount()), TEST_LOCATION );
1475   DALI_TEST_EQUALS( 0, (int)(childActor.GetChildCount()), TEST_LOCATION );
1476
1477   Actor child = actorB.GetChildAt(0);
1478
1479   DALI_TEST_CHECK( child );
1480   if ( child )
1481   {
1482     DALI_TEST_EQUALS( "Child", child.GetName(), TEST_LOCATION );
1483   }
1484
1485   // Check callback sequence
1486
1487   DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1488   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
1489   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1490   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
1491   // mContainer will then receive OnChildAdd
1492
1493   DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1494   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1495   DALI_TEST_EQUALS( "OnChildAdd",           actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1496
1497   DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
1498
1499   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 0 ], TEST_LOCATION );
1500   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
1501   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 2 ], TEST_LOCATION );
1502   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 3 ], TEST_LOCATION );
1503   DALI_TEST_EQUALS( "ActorB: OnChildAdd",           MasterCallStack[ 4 ], TEST_LOCATION );
1504
1505   // Excercise the message passing to Update thread
1506
1507   application.SendNotification();
1508   application.Render();
1509   application.Render();
1510   END_TEST;
1511 }
1512
1513 int UtcDaliCustomActorOnPropertySet(void)
1514 {
1515   TestApplication application;
1516   tet_infoline("Testing Dali::CustomActor::OnPropertySet()");
1517
1518   TestCustomActor custom = TestCustomActor::New();
1519   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1520
1521   custom.SetDaliProperty("yes") ;
1522
1523   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1524   DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1525   END_TEST;
1526 }
1527
1528 int UtcDaliCustomActorOnSizeSet(void)
1529 {
1530   TestApplication application;
1531   tet_infoline("Testing Dali::CustomActor::OnSizeSet()");
1532
1533   TestCustomActor custom = TestCustomActor::New();
1534   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1535
1536   custom.SetSize( Vector2( 9.0f, 10.0f ) );
1537   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1538   DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1539   DALI_TEST_EQUALS( 9.0f, custom.GetSize().width, TEST_LOCATION );
1540   DALI_TEST_EQUALS( 10.0f, custom.GetSize().height, TEST_LOCATION );
1541
1542   custom.SetSize( Vector3( 4.0f, 5.0f, 6.0f ) );
1543   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1544   DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1545   DALI_TEST_EQUALS( 4.0f, custom.GetSize().width, TEST_LOCATION );
1546   DALI_TEST_EQUALS( 5.0f, custom.GetSize().height, TEST_LOCATION );
1547   DALI_TEST_EQUALS( 6.0f, custom.GetSize().depth, TEST_LOCATION );
1548   END_TEST;
1549 }
1550
1551 int UtcDaliCustomActorOnSizeAnimation(void)
1552 {
1553   TestApplication application;
1554   tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
1555
1556   TestCustomActor custom = TestCustomActor::New();
1557   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1558
1559   Animation anim = Animation::New( 1.0f );
1560   anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) );
1561   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1562   DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1563   DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION );
1564   DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION );
1565   DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION );
1566   END_TEST;
1567 }
1568
1569 int UtcDaliCustomActorOnTouchEvent(void)
1570 {
1571   TestApplication application;
1572   tet_infoline("Testing Dali::CustomActor::OnTouchEvent()");
1573
1574   TestCustomActor custom = TestCustomActor::New();
1575   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1576
1577   // set size for custom actor
1578   custom.SetSize( 100, 100 );
1579   // add the custom actor to stage
1580   Stage::GetCurrent().Add( custom );
1581   custom.ResetCallStack();
1582
1583   // Render and notify a couple of times
1584   application.SendNotification();
1585   application.Render();
1586   application.SendNotification();
1587   application.Render();
1588
1589   // simulate a touch event
1590   Dali::TouchPoint point( 0, TouchPoint::Down, 1, 1 );
1591   Dali::Integration::TouchEvent event;
1592   event.AddPoint( point );
1593   application.ProcessEvent( event );
1594
1595   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1596   DALI_TEST_EQUALS( "OnTouchEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1597   END_TEST;
1598 }
1599
1600 int UtcDaliCustomActorOnHoverEvent(void)
1601 {
1602   TestApplication application;
1603   tet_infoline("Testing Dali::CustomActor::OnHoverEvent()");
1604
1605   TestCustomActor custom = TestCustomActor::New();
1606   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1607
1608   // set size for custom actor
1609   custom.SetSize( 100, 100 );
1610   // add the custom actor to stage
1611   Stage::GetCurrent().Add( custom );
1612   custom.ResetCallStack();
1613
1614   // Render and notify a couple of times
1615   application.SendNotification();
1616   application.Render();
1617   application.SendNotification();
1618   application.Render();
1619
1620   // simulate a hover event
1621   Dali::TouchPoint point( 0, TouchPoint::Motion, 1, 1 );
1622   Dali::Integration::HoverEvent event;
1623   event.AddPoint( point );
1624   application.ProcessEvent( event );
1625
1626   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1627   DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1628   END_TEST;
1629 }
1630
1631 int UtcDaliCustomActorOnMouseWheelEvent(void)
1632 {
1633   TestApplication application;
1634   tet_infoline("Testing Dali::CustomActor::OnMouseWheelEvent()");
1635
1636   TestCustomActor custom = TestCustomActor::New();
1637   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1638
1639   // set size for custom actor
1640   custom.SetSize( 100, 100 );
1641   // add the custom actor to stage
1642   Stage::GetCurrent().Add( custom );
1643   custom.ResetCallStack();
1644
1645   // Render and notify a couple of times
1646   application.SendNotification();
1647   application.Render();
1648   application.SendNotification();
1649   application.Render();
1650
1651   // simulate a mouse wheel event
1652   Vector2 screenCoordinates( 10.0f, 10.0f );
1653   Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u);
1654   application.ProcessEvent( event );
1655
1656   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1657   DALI_TEST_EQUALS( "OnMouseWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1658   END_TEST;
1659 }
1660
1661 int UtcDaliCustomActorImplOnPropertySet(void)
1662 {
1663   TestApplication application;
1664   CustomActorImpl* impl = new Impl::SimpleTestCustomActor();
1665
1666   impl->OnPropertySet( 0, 0 );
1667
1668   DALI_TEST_CHECK( true );
1669
1670   delete impl;
1671   END_TEST;
1672 }
1673
1674 int UtcDaliCustomActorGetImplementation(void)
1675 {
1676   TestApplication application;
1677
1678   TestCustomActor custom = TestCustomActor::New();
1679   CustomActorImpl& impl = custom.GetImplementation();
1680   impl.GetOwner();  // Test
1681
1682   const TestCustomActor constCustom = TestCustomActor::New();
1683   const CustomActorImpl& constImpl = constCustom.GetImplementation();
1684   constImpl.GetOwner();  // Test
1685
1686   DALI_TEST_CHECK( true );
1687   END_TEST;
1688 }
1689
1690 int UtcDaliCustomActorDoAction(void)
1691 {
1692   TestApplication application;
1693   tet_infoline("Testing Dali::CustomActor::DoAction()");
1694
1695   TestCustomActor custom = TestCustomActor::New();
1696
1697   BaseHandle customActorObject = custom;
1698
1699   DALI_TEST_CHECK(customActorObject);
1700
1701   std::vector<Property::Value> attributes;
1702
1703   // Check that an invalid command is not performed
1704   DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1705
1706   // Check that the custom actor is visible
1707   custom.SetVisible(true);
1708   DALI_TEST_CHECK(custom.IsVisible() == true);
1709
1710   // Check the custom actor performed an action to hide itself
1711   DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1712
1713   // flush the queue and render once
1714   application.SendNotification();
1715   application.Render();
1716
1717   // Check that the custom actor is now invisible
1718   DALI_TEST_CHECK(custom.IsVisible() == false);
1719
1720   // Check the custom actor performed an action to show itself
1721   DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1722
1723   // flush the queue and render once
1724   application.SendNotification();
1725   application.Render();
1726
1727   // Check that the custom actor is now visible
1728   DALI_TEST_CHECK(custom.IsVisible() == true);
1729   END_TEST;
1730 }