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