(AutomatedTests) Merged managed & unmanaged tests
[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
647 using namespace Dali;
648
649 BaseHandle CreateActor()
650 {
651   return TestCustomActor::New();
652 }
653
654 Dali::TypeRegistration mType( typeid(TestCustomActor), typeid(Dali::CustomActor), CreateActor );
655
656 } // anon namespace
657
658
659 int UtcDaliCustomActorDestructor(void)
660 {
661   TestApplication application;
662
663   CustomActor* actor = new CustomActor();
664   delete actor;
665
666   DALI_TEST_CHECK( true );
667   END_TEST;
668 }
669
670 int UtcDaliCustomActorImplDestructor(void)
671 {
672   TestApplication application;
673   CustomActorImpl* actor = new Impl::TestCustomActor();
674   delete actor;
675
676   DALI_TEST_CHECK( true );
677   END_TEST;
678 }
679
680 // Positive test case for a method
681 int UtcDaliCustomActorDownCast(void)
682 {
683   TestApplication application;
684   tet_infoline("Testing Dali::CustomActor::DownCast()");
685
686   TestCustomActor custom = TestCustomActor::New();
687
688   Actor anActor = Actor::New();
689   anActor.Add( custom );
690
691   Actor child = anActor.GetChildAt(0);
692   CustomActor customActor = CustomActor::DownCast( child );
693   DALI_TEST_CHECK( customActor );
694
695   customActor = NULL;
696   DALI_TEST_CHECK( !customActor );
697
698   customActor = DownCast< CustomActor >( child );
699   DALI_TEST_CHECK( customActor );
700   END_TEST;
701 }
702
703 // Negative test case for a method
704 int UtcDaliCustomActorDownCastNegative(void)
705 {
706   TestApplication application;
707   tet_infoline("Testing Dali::CustomActor::DownCast()");
708
709   Actor actor1 = Actor::New();
710   Actor anActor = Actor::New();
711   anActor.Add(actor1);
712
713   Actor child = anActor.GetChildAt(0);
714   CustomActor customActor = CustomActor::DownCast( child );
715   DALI_TEST_CHECK( !customActor );
716
717   Actor unInitialzedActor;
718   customActor = CustomActor::DownCast( unInitialzedActor );
719   DALI_TEST_CHECK( !customActor );
720
721   customActor = DownCast< CustomActor >( unInitialzedActor );
722   DALI_TEST_CHECK( !customActor );
723   END_TEST;
724 }
725
726 int UtcDaliCustomActorOnStageConnectionDisconnection(void)
727 {
728   TestApplication application;
729   tet_infoline("Testing Dali::CustomActor::OnStageConnection() & OnStageDisconnection");
730
731   TestCustomActor custom = TestCustomActor::New();
732   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
733
734   // add the custom actor to stage
735   Stage::GetCurrent().Add( custom );
736
737   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
738   DALI_TEST_EQUALS( "OnStageConnection", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
739
740   Stage::GetCurrent().Remove( custom );
741
742   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
743   DALI_TEST_EQUALS( "OnStageDisconnection", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
744
745   // Excercise the message passing to Update thread
746
747   application.SendNotification();
748   application.Render();
749   application.Render();
750   END_TEST;
751 }
752
753 int UtcDaliCustomActorOnStageConnectionOrder(void)
754 {
755   TestApplication application;
756   tet_infoline("Testing Dali::CustomActor::OnStageConnection() order");
757
758   MasterCallStack.clear();
759
760   /* Build tree of actors:
761    *
762    *       A (parent)
763    *      / \
764    *     B   C
765    *    / \   \
766    *   D   E   F
767    *
768    * OnStageConnection should be received for A, B, D, E, C, and finally F
769    */
770
771   TestCustomActor actorA = TestCustomActor::New();
772   actorA.SetName( "ActorA" );
773
774   TestCustomActor actorB = TestCustomActor::New();
775   actorB.SetName( "ActorB" );
776   actorA.Add( actorB );
777
778   TestCustomActor actorC = TestCustomActor::New();
779   actorC.SetName( "ActorC" );
780   actorA.Add( actorC );
781
782   TestCustomActor actorD = TestCustomActor::New();
783   actorD.SetName( "ActorD" );
784   actorB.Add( actorD );
785
786   TestCustomActor actorE = TestCustomActor::New();
787   actorE.SetName( "ActorE" );
788   actorB.Add( actorE );
789
790   TestCustomActor actorF = TestCustomActor::New();
791   actorF.SetName( "ActorF" );
792   actorC.Add( actorF );
793
794   // add the custom actor to stage
795   Stage::GetCurrent().Add( actorA );
796
797   DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
798   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
799   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
800   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
801
802   DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
803   DALI_TEST_EQUALS( "OnChildAdd",        actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
804   DALI_TEST_EQUALS( "OnChildAdd",        actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
805   DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
806
807   DALI_TEST_EQUALS( 2, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
808   DALI_TEST_EQUALS( "OnChildAdd",        actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
809   DALI_TEST_EQUALS( "OnStageConnection", actorC.GetMethodsCalled()[ 1 ], TEST_LOCATION );
810
811   DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
812   DALI_TEST_EQUALS( "OnStageConnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
813
814   DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
815   DALI_TEST_EQUALS( "OnStageConnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
816
817   DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
818   DALI_TEST_EQUALS( "OnStageConnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
819
820   // Check sequence is correct in MasterCallStack
821
822   DALI_TEST_EQUALS( 3+3+2+1+1+1, (int)(MasterCallStack.size()), TEST_LOCATION );
823
824   DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
825   DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
826   DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
827   DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 3 ], TEST_LOCATION );
828   DALI_TEST_EQUALS( "ActorC: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
829
830   DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 5 ], TEST_LOCATION );
831   DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 6 ], TEST_LOCATION );
832   DALI_TEST_EQUALS( "ActorD: OnStageConnection", MasterCallStack[ 7 ], TEST_LOCATION );
833   DALI_TEST_EQUALS( "ActorE: OnStageConnection", MasterCallStack[ 8 ], TEST_LOCATION );
834   DALI_TEST_EQUALS( "ActorC: OnStageConnection", MasterCallStack[ 9 ], TEST_LOCATION );
835   DALI_TEST_EQUALS( "ActorF: OnStageConnection", MasterCallStack[ 10 ], TEST_LOCATION );
836
837   // Excercise the message passing to Update thread
838
839   application.SendNotification();
840   application.Render();
841   application.Render();
842   END_TEST;
843 }
844
845 int UtcDaliCustomActorOnStageDisconnectionOrder(void)
846 {
847   TestApplication application;
848   tet_infoline("Testing Dali::CustomActor::OnStageDisconnection() order");
849
850   Stage stage = Stage::GetCurrent();
851
852   /* Build tree of actors:
853    *
854    *       A (parent)
855    *      / \
856    *     B   C
857    *    / \   \
858    *   D   E   F
859    *
860    * OnStageDisconnection should be received for D, E, B, F, C, and finally A.
861    */
862
863   TestCustomActor actorA = TestCustomActor::New();
864   actorA.SetName( "ActorA" );
865   stage.Add( actorA );
866
867   TestCustomActor actorB = TestCustomActor::New();
868   actorB.SetName( "ActorB" );
869   actorA.Add( actorB );
870
871   TestCustomActor actorC = TestCustomActor::New();
872   actorC.SetName( "ActorC" );
873   actorA.Add( actorC );
874
875   TestCustomActor actorD = TestCustomActor::New();
876   actorD.SetName( "ActorD" );
877   actorB.Add( actorD );
878
879   TestCustomActor actorE = TestCustomActor::New();
880   actorE.SetName( "ActorE" );
881   actorB.Add( actorE );
882
883   TestCustomActor actorF = TestCustomActor::New();
884   actorF.SetName( "ActorF" );
885   actorC.Add( actorF );
886
887   // Excercise the message passing to Update thread
888
889   application.SendNotification();
890   application.Render();
891   application.Render();
892
893   // Clear call stacks before disconnection
894   actorA.ResetCallStack();
895   actorB.ResetCallStack();
896   actorC.ResetCallStack();
897   actorD.ResetCallStack();
898   actorE.ResetCallStack();
899   actorF.ResetCallStack();
900   MasterCallStack.clear();
901
902   stage.Remove( actorA );
903
904   DALI_TEST_EQUALS( 1, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
905   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
906
907   DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
908   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
909
910   DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
911   DALI_TEST_EQUALS( "OnStageDisconnection", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
912
913   DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
914   DALI_TEST_EQUALS( "OnStageDisconnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
915
916   DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
917   DALI_TEST_EQUALS( "OnStageDisconnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
918
919   DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
920   DALI_TEST_EQUALS( "OnStageDisconnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
921
922   // Check sequence is correct in MasterCallStack
923
924   DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
925
926   DALI_TEST_EQUALS( "ActorD: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
927   DALI_TEST_EQUALS( "ActorE: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
928   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 2 ], TEST_LOCATION );
929   DALI_TEST_EQUALS( "ActorF: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
930   DALI_TEST_EQUALS( "ActorC: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
931   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
932
933   // Excercise the message passing to Update thread
934
935   application.SendNotification();
936   application.Render();
937   application.Render();
938   END_TEST;
939 }
940
941 int UtcDaliCustomActorAddDuringOnStageConnection(void)
942 {
943   TestApplication application;
944   tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageConnection() callback");
945
946   Stage stage = Stage::GetCurrent();
947
948   MasterCallStack.clear();
949
950   /* The actorA is a special variant which adds a child to itself during OnStageConnection()
951    * The actorB is provided as the child
952    */
953
954   TestCustomActor actorB = TestCustomActor::New();
955   actorB.SetName( "ActorB" );
956
957   TestCustomActor actorA = TestCustomActor::NewVariant1( actorB );
958   actorA.SetName( "ActorA" );
959   stage.Add( actorA );
960
961   // Check callback sequence
962
963   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
964   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
965   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // Called from within OnStageConnection()
966
967   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
968   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
969
970   DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
971
972   DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
973   DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION ); // Occurs during Actor::Add from within from within OnStageConnection()
974   DALI_TEST_EQUALS( "ActorA: OnChildAdd",        MasterCallStack[ 2 ], TEST_LOCATION ); // Occurs after Actor::Add from within from within OnStageConnection()
975
976   // Excercise the message passing to Update thread
977
978   application.SendNotification();
979   application.Render();
980   application.Render();
981
982   // Check everything is ok after Actors are removed
983
984   stage.Remove( actorA );
985   application.SendNotification();
986   application.Render();
987   application.Render();
988   END_TEST;
989 }
990
991 int UtcDaliCustomActorRemoveDuringOnStageConnection(void)
992 {
993   TestApplication application;
994   tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageConnection() callback");
995
996   Stage stage = Stage::GetCurrent();
997
998   MasterCallStack.clear();
999
1000   /* The actorA is a special variant which removes its children during OnStageConnection()
1001    * Actors B & C are provided as the children
1002    */
1003
1004   TestCustomActor actorA = TestCustomActor::NewVariant2();
1005   actorA.SetName( "ActorA" );
1006
1007   TestCustomActor actorB = TestCustomActor::New();
1008   actorB.SetName( "ActorB" );
1009   actorA.Add( actorB );
1010
1011   TestCustomActor actorC = TestCustomActor::New();
1012   actorC.SetName( "ActorC" );
1013   actorA.Add( actorC );
1014
1015   stage.Add( actorA );
1016
1017   // Check callback sequence
1018
1019   DALI_TEST_EQUALS( 5, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1020   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1021   DALI_TEST_EQUALS( "OnChildAdd",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1022   DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1023   DALI_TEST_EQUALS( "OnChildRemove",     actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // Called from within OnStageConnection()
1024   DALI_TEST_EQUALS( "OnChildRemove",     actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION ); // Called from within OnStageConnection()
1025
1026   DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
1027
1028   DALI_TEST_EQUALS( "ActorA: OnChildAdd",        MasterCallStack[ 0 ], TEST_LOCATION );
1029   DALI_TEST_EQUALS( "ActorA: OnChildAdd",        MasterCallStack[ 1 ], TEST_LOCATION );
1030   DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
1031   DALI_TEST_EQUALS( "ActorA: OnChildRemove",     MasterCallStack[ 3 ], TEST_LOCATION );
1032   DALI_TEST_EQUALS( "ActorA: OnChildRemove",     MasterCallStack[ 4 ], TEST_LOCATION );
1033
1034   /* Actors B & C should be removed before the point where they could receive an OnStageConnection callback
1035    * Therefore they shouldn't receive either OnStageConnection or OnStageDisconnection
1036    */
1037   DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1038   DALI_TEST_EQUALS( 0, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
1039
1040   // Excercise the message passing to Update thread
1041
1042   application.SendNotification();
1043   application.Render();
1044   application.Render();
1045
1046   // Check everything is ok after last actor is removed
1047
1048   stage.Remove( actorA );
1049   application.SendNotification();
1050   application.Render();
1051   application.Render();
1052   END_TEST;
1053 }
1054
1055 int UtcDaliCustomActorAddDuringOnStageDisconnection(void)
1056 {
1057   TestApplication application;
1058   tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageDisonnection() callback");
1059
1060   Stage stage = Stage::GetCurrent();
1061
1062   /* The actorA is a special variant which adds a child to itself during OnStageDisconnection()
1063    * The actorB is provided as the child
1064    */
1065
1066   TestCustomActor actorB = TestCustomActor::New();
1067   actorB.SetName( "ActorB" );
1068
1069   TestCustomActor actorA = TestCustomActor::NewVariant3( actorB );
1070   actorA.SetName( "ActorA" );
1071   stage.Add( actorA );
1072
1073   // Excercise the message passing to Update thread
1074
1075   application.SendNotification();
1076   application.Render();
1077   application.Render();
1078
1079   // Clear call stacks before disconnection
1080   actorA.ResetCallStack();
1081   actorB.ResetCallStack();
1082   MasterCallStack.clear();
1083
1084   stage.Remove( actorA );
1085
1086   // Check callback sequence
1087
1088   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1089   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1090   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1091
1092   // Child was added after parent disconnection, so should not receive OnStageConnection()
1093   DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1094
1095   DALI_TEST_EQUALS( 2, (int)(MasterCallStack.size()), TEST_LOCATION );
1096
1097   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1098   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 1 ], TEST_LOCATION );
1099
1100   // Excercise the message passing to Update thread
1101
1102   application.SendNotification();
1103   application.Render();
1104   application.Render();
1105   END_TEST;
1106 }
1107
1108 int UtcDaliCustomActorRemoveDuringOnStageDisconnection(void)
1109 {
1110   TestApplication application;
1111   tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageDisconnection() callback");
1112
1113   Stage stage = Stage::GetCurrent();
1114
1115   /* The actorA is a special variant which removes its children during OnStageDisconnection()
1116    * The actorB is provided as the child
1117    */
1118
1119   TestCustomActor actorA = TestCustomActor::NewVariant4();
1120   actorA.SetName( "ActorA" );
1121   stage.Add( actorA );
1122
1123   TestCustomActor actorB = TestCustomActor::New();
1124   actorB.SetName( "ActorB" );
1125   actorA.Add( actorB );
1126
1127   // Excercise the message passing to Update thread
1128
1129   application.SendNotification();
1130   application.Render();
1131   application.Render();
1132
1133   // Clear call stacks before disconnection
1134   actorA.ResetCallStack();
1135   actorB.ResetCallStack();
1136   MasterCallStack.clear();
1137
1138   stage.Remove( actorA );
1139
1140   // Check callback sequence
1141
1142   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1143   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1144   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1145
1146   DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1147   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1148
1149   DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
1150
1151   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1152   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
1153   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 2 ], TEST_LOCATION );
1154
1155   // Excercise the message passing to Update thread
1156
1157   application.SendNotification();
1158   application.Render();
1159   application.Render();
1160   END_TEST;
1161 }
1162
1163 int UtcDaliCustomActorRemoveParentDuringOnStageConnection(void)
1164 {
1165   TestApplication application;
1166   tet_infoline("Weird test where child removes its own parent from Stage during Dali::CustomActor::OnStageConnection() callback");
1167
1168   Stage stage = Stage::GetCurrent();
1169
1170   MasterCallStack.clear();
1171
1172   /* The actorA is the parent of actorB
1173    * The actorB is a special variant which removes its own parent during OnStageConnection()
1174    * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnStageDisconnection()
1175    */
1176
1177   TestCustomActor actorA = TestCustomActor::New();
1178   actorA.SetName( "ActorA" );
1179
1180   TestCustomActor actorB = TestCustomActor::NewVariant5();
1181   actorB.SetName( "ActorB" );
1182   actorA.Add( actorB );
1183
1184   stage.Add( actorA );
1185
1186   // Check callback sequence
1187
1188   DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1189   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1190   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1191   DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1192
1193   DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1194   DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1195
1196   DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
1197
1198   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 0 ], TEST_LOCATION );
1199   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
1200   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 2 ], TEST_LOCATION );
1201   DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1202
1203   // Excercise the message passing to Update thread
1204
1205   application.SendNotification();
1206   application.Render();
1207   application.Render();
1208   END_TEST;
1209 }
1210
1211 int UtcDaliCustomActorAddParentDuringOnStageDisconnection(void)
1212 {
1213   TestApplication application;
1214   tet_infoline("Weird test where child adds its own parent to Stage during Dali::CustomActor::OnStageDisconnection() callback");
1215
1216   Stage stage = Stage::GetCurrent();
1217
1218   MasterCallStack.clear();
1219
1220   /* The actorA is the parent of actorB
1221    * The actorB is a special variant which (weirdly) adds its own parent during OnStageDisconnection()
1222    * The child actor is interrupting the disconnection, such that parent should not get a OnStageDisconnection()
1223    */
1224
1225   TestCustomActor actorA = TestCustomActor::New();
1226   actorA.SetName( "ActorA" );
1227   stage.Add( actorA );
1228
1229   TestCustomActor actorB = TestCustomActor::NewVariant6();
1230   actorB.SetName( "ActorB" );
1231   actorA.Add( actorB );
1232
1233   stage.Remove( actorA );
1234
1235   // Check callback sequence
1236
1237   DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1238   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1239   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1240
1241   DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1242   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1243   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1244   // Disconnect was interrupted, so we should only get one OnStageConnection() for actorB
1245
1246   DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
1247
1248   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 0 ], TEST_LOCATION );
1249   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
1250   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 2 ], TEST_LOCATION );
1251   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1252
1253   // Excercise the message passing to Update thread
1254
1255   application.SendNotification();
1256   application.Render();
1257   application.Render();
1258   END_TEST;
1259 }
1260
1261 int UtcDaliCustomActorOnChildAddRemove(void)
1262 {
1263   TestApplication application;
1264   tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()");
1265
1266   TestCustomActor custom = TestCustomActor::New();
1267   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1268
1269   Actor aChild = Actor::New();
1270   custom.Add( aChild );
1271
1272   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1273   DALI_TEST_EQUALS( "OnChildAdd", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1274
1275   custom.Remove( aChild );
1276
1277   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1278   DALI_TEST_EQUALS( "OnChildRemove", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1279   END_TEST;
1280 }
1281
1282 int UtcDaliCustomActorReparentDuringOnChildAdd(void)
1283 {
1284   TestApplication application;
1285   tet_infoline("Testing Actor:Add (reparenting) behaviour during Dali::CustomActor::OnChildAdd() callback");
1286
1287   Stage stage = Stage::GetCurrent();
1288
1289   MasterCallStack.clear();
1290
1291   /* The actorA is a special variant which reparents children added into a separate container child
1292    * The actorB is the child of actorA
1293    */
1294
1295   TestCustomActor actorA = TestCustomActor::NewVariant7( "ActorA" );
1296   stage.Add( actorA );
1297
1298   TestCustomActor actorB = TestCustomActor::New();
1299   actorB.SetName( "ActorB" );
1300   actorA.Add( actorB );
1301
1302   // Check hierarchy is as follows:
1303   //  A
1304   //  |
1305   //  Container
1306   //  |
1307   //  B
1308
1309   DALI_TEST_EQUALS( 1, (int)(actorA.GetChildCount()), TEST_LOCATION );
1310
1311   Actor container = actorA.GetChildAt(0);
1312   Actor containerChild;
1313
1314   DALI_TEST_CHECK( container );
1315   if ( container )
1316   {
1317     DALI_TEST_EQUALS( "Container", container.GetName(), TEST_LOCATION );
1318     DALI_TEST_EQUALS( 1, (int)(container.GetChildCount()), TEST_LOCATION );
1319     containerChild = container.GetChildAt(0);
1320   }
1321
1322   DALI_TEST_CHECK( containerChild );
1323   if ( containerChild )
1324   {
1325     DALI_TEST_EQUALS( "ActorB", containerChild.GetName(), TEST_LOCATION );
1326     DALI_TEST_EQUALS( 0, (int)(containerChild.GetChildCount()), TEST_LOCATION );
1327   }
1328
1329   // Check callback sequence
1330
1331   DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1332   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
1333   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1334   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
1335   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
1336   // mContainer will then receive OnChildAdd
1337
1338   DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1339   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1340   DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1341   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1342
1343   DALI_TEST_EQUALS( 7, (int)(MasterCallStack.size()), TEST_LOCATION );
1344
1345   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 0 ], TEST_LOCATION );
1346   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
1347   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 2 ], TEST_LOCATION );
1348   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 3 ], TEST_LOCATION );
1349   DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
1350   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 5 ], TEST_LOCATION );
1351   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 6 ], TEST_LOCATION );
1352
1353   // Excercise the message passing to Update thread
1354
1355   application.SendNotification();
1356   application.Render();
1357   application.Render();
1358   END_TEST;
1359 }
1360
1361 /**
1362  * Test that Remove can be called (a NOOP) during the OnChildRemove
1363  * triggered when reparenting an actor
1364  */
1365 int UtcDaliCustomActorRemoveDuringOnChildRemove(void)
1366 {
1367   TestApplication application;
1368   tet_infoline("Testing Actor:Remove behaviour during OnChildRemove() callback triggered when reparenting");
1369
1370   Stage stage = Stage::GetCurrent();
1371
1372   MasterCallStack.clear();
1373
1374   /* The childActor will be reparented from actorA to actorB
1375    * The actorA is a special variant which attempts to remove a child from actorB, during the OnChildRemove callback()
1376    * This should be a NOOP since the reparenting has not occured yet
1377    */
1378
1379   TestCustomActor actorB = TestCustomActor::New();
1380   actorB.SetName( "ActorB" );
1381   stage.Add( actorB );
1382
1383   TestCustomActor actorA = TestCustomActor::NewVariant8( actorB );
1384   actorA.SetName( "ActorA" );
1385   stage.Add( actorA );
1386
1387   Actor childActor = Actor::New();
1388   childActor.SetName( "Child" );
1389   // Reparent from actorA to actorB
1390   actorA.Add( childActor );
1391   actorB.Add( childActor );
1392
1393   // Check hierarchy is as follows:
1394   //  A    B
1395   //       |
1396   //       Child
1397
1398   DALI_TEST_EQUALS( 0, (int)(actorA.GetChildCount()), TEST_LOCATION );
1399   DALI_TEST_EQUALS( 1, (int)(actorB.GetChildCount()), TEST_LOCATION );
1400   DALI_TEST_EQUALS( 0, (int)(childActor.GetChildCount()), TEST_LOCATION );
1401
1402   Actor child = actorB.GetChildAt(0);
1403
1404   DALI_TEST_CHECK( child );
1405   if ( child )
1406   {
1407     DALI_TEST_EQUALS( "Child", child.GetName(), TEST_LOCATION );
1408   }
1409
1410   // Check callback sequence
1411
1412   DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1413   DALI_TEST_EQUALS( "OnStageConnection",    actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
1414   DALI_TEST_EQUALS( "OnChildAdd",           actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1415   DALI_TEST_EQUALS( "OnChildRemove",        actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
1416   // mContainer will then receive OnChildAdd
1417
1418   DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1419   DALI_TEST_EQUALS( "OnStageConnection",    actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1420   DALI_TEST_EQUALS( "OnChildAdd",           actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1421
1422   DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
1423
1424   DALI_TEST_EQUALS( "ActorB: OnStageConnection",    MasterCallStack[ 0 ], TEST_LOCATION );
1425   DALI_TEST_EQUALS( "ActorA: OnStageConnection",    MasterCallStack[ 1 ], TEST_LOCATION );
1426   DALI_TEST_EQUALS( "ActorA: OnChildAdd",           MasterCallStack[ 2 ], TEST_LOCATION );
1427   DALI_TEST_EQUALS( "ActorA: OnChildRemove",        MasterCallStack[ 3 ], TEST_LOCATION );
1428   DALI_TEST_EQUALS( "ActorB: OnChildAdd",           MasterCallStack[ 4 ], TEST_LOCATION );
1429
1430   // Excercise the message passing to Update thread
1431
1432   application.SendNotification();
1433   application.Render();
1434   application.Render();
1435   END_TEST;
1436 }
1437
1438 int UtcDaliCustomActorOnPropertySet(void)
1439 {
1440   TestApplication application;
1441   tet_infoline("Testing Dali::CustomActor::OnPropertySet()");
1442
1443   TestCustomActor custom = TestCustomActor::New();
1444   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1445
1446   custom.SetDaliProperty("yes") ;
1447
1448   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1449   DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1450   END_TEST;
1451 }
1452
1453 int UtcDaliCustomActorOnSizeSet(void)
1454 {
1455   TestApplication application;
1456   tet_infoline("Testing Dali::CustomActor::OnSizeSet()");
1457
1458   TestCustomActor custom = TestCustomActor::New();
1459   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1460
1461   custom.SetSize( Vector2( 9.0f, 10.0f ) );
1462   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1463   DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1464   DALI_TEST_EQUALS( 9.0f, custom.GetSize().width, TEST_LOCATION );
1465   DALI_TEST_EQUALS( 10.0f, custom.GetSize().height, TEST_LOCATION );
1466
1467   custom.SetSize( Vector3( 4.0f, 5.0f, 6.0f ) );
1468   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1469   DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1470   DALI_TEST_EQUALS( 4.0f, custom.GetSize().width, TEST_LOCATION );
1471   DALI_TEST_EQUALS( 5.0f, custom.GetSize().height, TEST_LOCATION );
1472   DALI_TEST_EQUALS( 6.0f, custom.GetSize().depth, TEST_LOCATION );
1473   END_TEST;
1474 }
1475
1476 int UtcDaliCustomActorOnSizeAnimation(void)
1477 {
1478   TestApplication application;
1479   tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
1480
1481   TestCustomActor custom = TestCustomActor::New();
1482   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1483
1484   Animation anim = Animation::New( 1.0f );
1485   anim.Resize( custom, Vector3( 8.0f, 9.0f, 10.0f ) );
1486   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1487   DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1488   DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION );
1489   DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION );
1490   DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION );
1491
1492   anim.Resize( custom, 1.0f, 2.0f );
1493   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1494   DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1495   DALI_TEST_EQUALS( 1.0f, custom.GetTargetSize().width, TEST_LOCATION );
1496   DALI_TEST_EQUALS( 2.0f, custom.GetTargetSize().height, TEST_LOCATION );
1497   END_TEST;
1498 }
1499
1500 int UtcDaliCustomActorOnTouchEvent(void)
1501 {
1502   TestApplication application;
1503   tet_infoline("Testing Dali::CustomActor::OnTouchEvent()");
1504
1505   TestCustomActor custom = TestCustomActor::New();
1506   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1507
1508   // set size for custom actor
1509   custom.SetSize( 100, 100 );
1510   // add the custom actor to stage
1511   Stage::GetCurrent().Add( custom );
1512   custom.ResetCallStack();
1513
1514   // Render and notify a couple of times
1515   application.SendNotification();
1516   application.Render();
1517   application.SendNotification();
1518   application.Render();
1519
1520   // simulate a touch event
1521   Dali::TouchPoint point( 0, TouchPoint::Down, 1, 1 );
1522   Dali::Integration::TouchEvent event;
1523   event.AddPoint( point );
1524   application.ProcessEvent( event );
1525
1526   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1527   DALI_TEST_EQUALS( "OnTouchEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1528   END_TEST;
1529 }
1530
1531 int UtcDaliCustomActorOnHoverEvent(void)
1532 {
1533   TestApplication application;
1534   tet_infoline("Testing Dali::CustomActor::OnHoverEvent()");
1535
1536   TestCustomActor custom = TestCustomActor::New();
1537   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1538
1539   // set size for custom actor
1540   custom.SetSize( 100, 100 );
1541   // add the custom actor to stage
1542   Stage::GetCurrent().Add( custom );
1543   custom.ResetCallStack();
1544
1545   // Render and notify a couple of times
1546   application.SendNotification();
1547   application.Render();
1548   application.SendNotification();
1549   application.Render();
1550
1551   // simulate a hover event
1552   Dali::TouchPoint point( 0, TouchPoint::Motion, 1, 1 );
1553   Dali::Integration::HoverEvent event;
1554   event.AddPoint( point );
1555   application.ProcessEvent( event );
1556
1557   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1558   DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1559   END_TEST;
1560 }
1561
1562 int UtcDaliCustomActorOnMouseWheelEvent(void)
1563 {
1564   TestApplication application;
1565   tet_infoline("Testing Dali::CustomActor::OnMouseWheelEvent()");
1566
1567   TestCustomActor custom = TestCustomActor::New();
1568   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1569
1570   // set size for custom actor
1571   custom.SetSize( 100, 100 );
1572   // add the custom actor to stage
1573   Stage::GetCurrent().Add( custom );
1574   custom.ResetCallStack();
1575
1576   // Render and notify a couple of times
1577   application.SendNotification();
1578   application.Render();
1579   application.SendNotification();
1580   application.Render();
1581
1582   // simulate a mouse wheel event
1583   Vector2 screenCoordinates( 10.0f, 10.0f );
1584   Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u);
1585   application.ProcessEvent( event );
1586
1587   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1588   DALI_TEST_EQUALS( "OnMouseWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1589   END_TEST;
1590 }
1591
1592 int UtcDaliCustomActorFindChildByAlias(void)
1593 {
1594   TestApplication application;
1595   tet_infoline("Testing Dali::CustomActor::GetChildByAlias()");
1596
1597   TestCustomActor custom = TestCustomActor::New();
1598   DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1599
1600   custom.Add(Actor::New());
1601
1602   DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1603
1604   DALI_TEST_CHECK( !custom.FindChildByAlias("not-found") );
1605
1606   DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1607   DALI_TEST_EQUALS( "GetChildByAlias", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1608
1609   DALI_TEST_CHECK( custom.FindChildByAlias("found") );
1610   END_TEST;
1611 }
1612
1613 int UtcDaliCustomActorImplOnPropertySet(void)
1614 {
1615   TestApplication application;
1616   CustomActorImpl* impl = new Impl::SimpleTestCustomActor();
1617
1618   impl->OnPropertySet( 0, 0 );
1619
1620   DALI_TEST_CHECK( true );
1621
1622   delete impl;
1623   END_TEST;
1624 }
1625
1626 int UtcDaliCustomActorGetImplementation(void)
1627 {
1628   TestApplication application;
1629
1630   TestCustomActor custom = TestCustomActor::New();
1631   CustomActorImpl& impl = custom.GetImplementation();
1632   impl.GetOwner();  // Test
1633
1634   const TestCustomActor constCustom = TestCustomActor::New();
1635   const CustomActorImpl& constImpl = constCustom.GetImplementation();
1636   constImpl.GetOwner();  // Test
1637
1638   DALI_TEST_CHECK( true );
1639   END_TEST;
1640 }
1641
1642 int UtcDaliCustomActorDoAction(void)
1643 {
1644   TestApplication application;
1645   tet_infoline("Testing Dali::CustomActor::DoAction()");
1646
1647   TestCustomActor custom = TestCustomActor::New();
1648
1649   BaseHandle customActorObject = custom;
1650
1651   DALI_TEST_CHECK(customActorObject);
1652
1653   std::vector<Property::Value> attributes;
1654
1655   // Check that an invalid command is not performed
1656   DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1657
1658   // Check that the custom actor is visible
1659   custom.SetVisible(true);
1660   DALI_TEST_CHECK(custom.IsVisible() == true);
1661
1662   // Check the custom actor performed an action to hide itself
1663   DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1664
1665   // flush the queue and render once
1666   application.SendNotification();
1667   application.Render();
1668
1669   // Check that the custom actor is now invisible
1670   DALI_TEST_CHECK(custom.IsVisible() == false);
1671
1672   // Check the custom actor performed an action to show itself
1673   DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1674
1675   // flush the queue and render once
1676   application.SendNotification();
1677   application.Render();
1678
1679   // Check that the custom actor is now visible
1680   DALI_TEST_CHECK(custom.IsVisible() == true);
1681   END_TEST;
1682 }