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