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