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