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