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