Dali 3D User Interface Engine
utc-Dali-CustomActor.cpp
Go to the documentation of this file.
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>
21 
26 
27 #include "dali-test-suite-utils/dali-test-suite-utils.h"
28 
29 using namespace Dali;
30 
31 
33 {
35 }
36 
38 {
40 }
41 
42 namespace
43 {
44 
45 std::vector< std::string > MasterCallStack;
46 bool gOnRelayout = false;
47 
48 } // anon namespace
49 
50 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
51 namespace Impl
52 {
53 
55 {
60  : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS | DISABLE_SIZE_NEGOTIATION ) ),
61  mDaliProperty( Property::INVALID_INDEX ),
62  mSizeSet( Vector3::ZERO ),
63  mTargetSize( Vector3::ZERO ),
64  mNego( false ),
65  mDepth(0u)
66  {
67  }
68 
69  TestCustomActor(bool nego)
70  : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS ) ),
71  mDaliProperty( Property::INVALID_INDEX ),
72  mSizeSet( Vector3::ZERO ),
73  mTargetSize( Vector3::ZERO ),
74  mNego( nego )
75  {
76  }
80  virtual ~TestCustomActor()
81  {
82  }
83 
84  void Initialize( const char* name = NULL )
85  {
86  mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
87 
88  OnInitialize( name );
89  }
90 
91  virtual void OnInitialize( const char* name ) {}
92 
96  void ResetCallStack()
97  {
98  mSizeSet = Vector3();
99  mTargetSize = Vector3();
100  mMethodsCalled.clear();
101  }
102 
103  void AddToCallStacks( const char* method )
104  {
105  mMethodsCalled.push_back( method );
106 
107  // Combine Actor name with method string
108  std::string nameAndMethod( Self().GetName() );
109  if ( 0 == nameAndMethod.size() )
110  {
111  nameAndMethod = "Unknown: ";
112  }
113  else
114  {
115  nameAndMethod += ": ";
116  }
117  nameAndMethod += method;
118 
119  MasterCallStack.push_back( nameAndMethod );
120  }
121 
122  // From CustomActorImpl
123  virtual void OnStageConnection( int depth )
124  {
125  AddToCallStacks("OnStageConnection");
126  mDepth = depth;
127  }
128  virtual void OnStageDisconnection()
129  {
130  AddToCallStacks("OnStageDisconnection");
131  }
132  virtual void OnChildAdd(Actor& child)
133  {
134  AddToCallStacks("OnChildAdd");
135  }
136  virtual void OnChildRemove(Actor& child)
137  {
138  AddToCallStacks("OnChildRemove");
139  }
140  virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
141  {
142  AddToCallStacks("OnPropertySet");
143  }
144  virtual void OnSizeSet(const Vector3& targetSize)
145  {
146  mSizeSet = targetSize;
147  AddToCallStacks("OnSizeSet");
148  }
149  virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
150  {
151  mTargetSize = targetSize;
152  AddToCallStacks("OnSizeAnimation");
153  }
154  virtual bool OnTouchEvent(const TouchEvent& event)
155  {
156  AddToCallStacks("OnTouchEvent");
157  return true;
158  }
159  virtual bool OnHoverEvent(const HoverEvent& event)
160  {
161  AddToCallStacks("OnHoverEvent");
162  return true;
163  }
164  virtual bool OnWheelEvent(const WheelEvent& event)
165  {
166  AddToCallStacks("OnWheelEvent");
167  return true;
168  }
169  virtual bool OnKeyEvent(const KeyEvent& event)
170  {
171  AddToCallStacks("OnKeyEvent");
172  return true;
173  }
174  virtual void OnKeyInputFocusGained()
175  {
176  AddToCallStacks("OnKeyInputFocusGained");
177  }
178  virtual void OnKeyInputFocusLost()
179  {
180  AddToCallStacks("OnKeyInputFocusLost");
181  }
182  virtual Vector3 GetNaturalSize()
183  {
184  return Vector3( 0.0f, 0.0f, 0.0f );
185  }
186 
187  virtual float GetHeightForWidth( float width )
188  {
189  return 0.0f;
190  }
191 
192  virtual float GetWidthForHeight( float height )
193  {
194  return 0.0f;
195  }
196 
197  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
198  {
199  gOnRelayout = true;
200  }
201 
202  virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
203  {
204  }
205 
206  virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
207  {
208  }
209 
210  virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
211  {
212  return 0.0f;
213  }
214 
215  virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
216  {
217  }
218 
219  virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
220  {
221  return false;
222  }
223 
224  void SetDaliProperty(std::string s)
225  {
226  Self().SetProperty(mDaliProperty, s);
227  }
228  void TestRelayoutRequest()
229  {
230  RelayoutRequest();
231  }
232 
233  float TestGetHeightForWidthBase( float width )
234  {
235  return GetHeightForWidthBase( width );
236  }
237 
238  float TestGetWidthForHeightBase( float height )
239  {
240  return GetWidthForHeightBase( height );
241  }
242 
243  float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
244  {
245  return CalculateChildSizeBase( child, dimension );
246  }
247 
248  bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
249  {
250  return RelayoutDependentOnChildrenBase( dimension );
251  }
252 
254  std::vector< std::string > mMethodsCalled;
257  bool mNego;
258  unsigned int mDepth;
259 };
260 
265 {
270  : mChildToAdd( childToAdd )
271  {
272  }
273 
274  // From CustomActorImpl
275  virtual void OnStageConnection( int depth )
276  {
277  // Chain up first
278  TestCustomActor::OnStageConnection( depth );
279 
280  // Add the child
281  Self().Add( mChildToAdd );
282  }
283 
285 };
286 
291 {
296  {
297  }
298 
299  // From CustomActorImpl
300  virtual void OnStageConnection( int depth )
301  {
302  // Chain up first
303  TestCustomActor::OnStageConnection( depth );
304 
305  // Remove all the children
306  for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
307  {
308  Self().Remove( Self().GetChildAt(0) );
309  }
310  }
311 };
312 
317 {
322  : mChildToAdd( childToAdd )
323  {
324  }
325 
326  // From CustomActorImpl
327  virtual void OnStageDisconnection()
328  {
329  // Chain up first
330  TestCustomActor::OnStageDisconnection();
331 
332  // Add the child
333  Self().Add( mChildToAdd );
334  }
335 
337 };
338 
343 {
348  {
349  }
350 
351  // From CustomActorImpl
352  virtual void OnStageDisconnection()
353  {
354  // Chain up first
355  TestCustomActor::OnStageDisconnection();
356 
357  // Remove all the children
358  for( unsigned int i=0, num=Self().GetChildCount(); i<num; ++i )
359  {
360  Self().Remove( Self().GetChildAt(0) );
361  }
362  }
363 };
364 
369 {
374  {
375  }
376 
377  // From CustomActorImpl
378  virtual void OnStageConnection( int depth )
379  {
380  // Chain up first
381  TestCustomActor::OnStageConnection( depth );
382 
383  // Take parent off-stage
384  Actor parent = Self().GetParent();
385  if ( parent )
386  {
387  Stage::GetCurrent().Remove( parent );
388  }
389  }
390 };
391 
396 {
401  {
402  }
403 
404  // From CustomActorImpl
405  virtual void OnStageDisconnection()
406  {
407  // Chain up first
408  TestCustomActor::OnStageDisconnection();
409 
410  // Put parent on-stage
411  Actor parent = Self().GetParent();
412  if ( parent )
413  {
414  Stage::GetCurrent().Add( parent );
415  }
416  }
417 };
418 
423 {
428  {
429  }
430 
431  virtual void OnInitialize( const char* name )
432  {
433  // We need to do this early, before the OnChildAdd is recorded
434  Self().SetName( name );
435 
436  mContainer = Actor::New();
437  mContainer.SetName( "Container" );
438  Self().Add( mContainer );
439  }
440 
441  // From CustomActorImpl
442  virtual void OnChildAdd(Actor& child)
443  {
444  // Chain up first
445  TestCustomActor::OnChildAdd(child);
446 
447  // Reparent child
448  if ( child != mContainer )
449  {
450  mContainer.Add( child );
451  }
452  }
453 
455 };
456 
461 {
466  : mRivalContainer( rival )
467  {
468  }
469 
470  // From CustomActorImpl
471  virtual void OnChildRemove(Actor& child)
472  {
473  // Chain up first
474  TestCustomActor::OnChildRemove(child);
475 
476  mRivalContainer.Remove( child ); // attempt to block reparenting to rival (should be a NOOP)
477  }
478 
480 };
481 
482 // Need a class that doesn't override virtual methods
484 {
485 public:
486 
491  : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | DISABLE_SIZE_NEGOTIATION ) )
492  {
493  }
494 
499  {
500  }
501 
502  // From CustomActorImpl
503  virtual void OnStageConnection( int depth )
504  {
505  }
506  virtual void OnStageDisconnection()
507  {
508  }
509  virtual void OnChildAdd(Actor& child)
510  {
511  }
512  virtual void OnChildRemove(Actor& child)
513  {
514  }
515  virtual void OnSizeSet(const Vector3& targetSize)
516  {
517  }
518  virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
519  {
520  }
521  virtual bool OnTouchEvent(const TouchEvent& event)
522  {
523  return true;
524  }
525  virtual bool OnHoverEvent(const HoverEvent& event)
526  {
527  return true;
528  }
529  virtual bool OnWheelEvent(const WheelEvent& event)
530  {
531  return true;
532  }
533  virtual bool OnKeyEvent(const KeyEvent& event)
534  {
535  return true;
536  }
537  virtual void OnKeyInputFocusGained()
538  {
539  }
540  virtual void OnKeyInputFocusLost()
541  {
542  }
543 
544  virtual Vector3 GetNaturalSize()
545  {
546  return Vector3( 0.0f, 0.0f, 0.0f );
547  }
548 
549  virtual float GetHeightForWidth( float width )
550  {
551  return 0.0f;
552  }
553 
554  virtual float GetWidthForHeight( float height )
555  {
556  return 0.0f;
557  }
558 
559  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
560  {
561  }
562 
563  virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
564  {
565  }
566 
567  virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
568  {
569  }
570 
571  virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
572  {
573  return 0.0f;
574  }
575 
576  virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
577  {
578  }
579 
580  virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
581  {
582  return false;
583  }
584 };
585 
586 } ; // namespace Impl
587 
588 
589 namespace
590 {
591 
596 {
597 public:
598 
600  {
602  TestCustomActor custom( *impl ); // takes ownership
603 
604  impl->Initialize();
605 
606  return custom;
607  }
608 
609  static TestCustomActor NewNegoSize()
610  {
611  Impl::TestCustomActor* impl = new Impl::TestCustomActor( true );
612  TestCustomActor custom( *impl ); // takes ownership
613  custom.SetName( "SizeNegotiationActor" );
614 
615  impl->Initialize();
616 
617  return custom;
618  }
619 
620  static TestCustomActor NewVariant1( Actor childToAdd )
621  {
622  Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd );
623  TestCustomActor custom( *impl ); // takes ownership
624 
625  impl->Initialize();
626 
627  return custom;
628  }
629 
630  static TestCustomActor NewVariant2()
631  {
633  TestCustomActor custom( *impl ); // takes ownership
634 
635  impl->Initialize();
636 
637  return custom;
638  }
639 
640  static TestCustomActor NewVariant3( Actor childToAdd )
641  {
642  Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3( childToAdd );
643  TestCustomActor custom( *impl ); // takes ownership
644 
645  impl->Initialize();
646 
647  return custom;
648  }
649 
650  static TestCustomActor NewVariant4()
651  {
653  TestCustomActor custom( *impl ); // takes ownership
654 
655  impl->Initialize();
656 
657  return custom;
658  }
659 
660  static TestCustomActor NewVariant5()
661  {
663  TestCustomActor custom( *impl ); // takes ownership
664 
665  impl->Initialize();
666 
667  return custom;
668  }
669 
670  static TestCustomActor NewVariant6()
671  {
673  TestCustomActor custom( *impl ); // takes ownership
674 
675  impl->Initialize();
676 
677  return custom;
678  }
679 
680  static TestCustomActor NewVariant7( const char* name )
681  {
683  TestCustomActor custom( *impl ); // takes ownership
684 
685  impl->Initialize( name );
686 
687  return custom;
688  }
689 
690  static TestCustomActor NewVariant8( Actor rival )
691  {
693  TestCustomActor custom( *impl ); // takes ownership
694 
695  impl->Initialize();
696 
697  return custom;
698  }
699 
700  virtual ~TestCustomActor()
701  {
702  }
703 
705  {
706  return static_cast<Impl::TestCustomActor&>(GetImplementation());
707  }
708 
709  std::vector< std::string >& GetMethodsCalled()
710  {
711  return GetImpl().mMethodsCalled;
712  }
713 
714  void ResetCallStack()
715  {
716  GetImpl().ResetCallStack();
717  }
718 
719  void SetDaliProperty(std::string s)
720  {
721  GetImpl().SetDaliProperty(s);
722  }
723 
724  Vector3 GetSize()
725  {
726  return GetImpl().mSizeSet;
727  }
728 
729  Vector3 GetTargetSize()
730  {
731  return GetImpl().mTargetSize;
732  }
733 
734  virtual Vector3 GetNaturalSize()
735  {
736  return Vector3( 0.0f, 0.0f, 0.0f );
737  }
738 
739  virtual float GetHeightForWidth( float width )
740  {
741  return 0.0f;
742  }
743 
744  virtual float GetWidthForHeight( float height )
745  {
746  return 0.0f;
747  }
748 
749  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
750  {
751  }
752 
753  virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
754  {
755  }
756 
757  virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
758  {
759  }
760 
761  void TestRelayoutRequest()
762  {
763  GetImpl().TestRelayoutRequest();
764  }
765 
766  float TestGetHeightForWidthBase( float width )
767  {
768  return GetImpl().TestGetHeightForWidthBase( width );
769  }
770 
771  float TestGetWidthForHeightBase( float height )
772  {
773  return GetImpl().TestGetWidthForHeightBase( height );
774  }
775 
776  float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension )
777  {
778  return GetImpl().TestCalculateChildSizeBase( child, dimension );
779  }
780 
781  bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension )
782  {
783  return GetImpl().TestRelayoutDependentOnChildrenBase( dimension );
784  }
785 
786  unsigned int GetDepth()
787  {
788  return GetImpl().mDepth;
789  }
790 private:
791 
793  {
794  }
795 };
796 
797 
798 
799 using namespace Dali;
800 
802 {
803  return TestCustomActor::New();
804 }
805 
806 Dali::TypeRegistration mType( typeid(TestCustomActor), typeid(Dali::CustomActor), CreateActor );
807 
808 } // anon namespace
809 
810 
812 {
813  TestApplication application;
814 
815  CustomActor* actor = new CustomActor();
816  delete actor;
817 
818  DALI_TEST_CHECK( true );
819  END_TEST;
820 }
821 
823 {
824  TestApplication application;
825  CustomActorImpl* actor = new Impl::TestCustomActor();
826  delete actor;
827 
828  DALI_TEST_CHECK( true );
829  END_TEST;
830 }
831 
832 // Positive test case for a method
834 {
835  TestApplication application;
836  tet_infoline("Testing Dali::CustomActor::DownCast()");
837 
838  TestCustomActor custom = TestCustomActor::New();
839 
840  Actor anActor = Actor::New();
841  anActor.Add( custom );
842 
843  Actor child = anActor.GetChildAt(0);
844  CustomActor customActor = CustomActor::DownCast( child );
845  DALI_TEST_CHECK( customActor );
846 
847  customActor = NULL;
848  DALI_TEST_CHECK( !customActor );
849 
850  customActor = DownCast< CustomActor >( child );
851  DALI_TEST_CHECK( customActor );
852  END_TEST;
853 }
854 
855 // Negative test case for a method
857 {
858  TestApplication application;
859  tet_infoline("Testing Dali::CustomActor::DownCast()");
860 
861  Actor actor1 = Actor::New();
862  Actor anActor = Actor::New();
863  anActor.Add(actor1);
864 
865  Actor child = anActor.GetChildAt(0);
866  CustomActor customActor = CustomActor::DownCast( child );
867  DALI_TEST_CHECK( !customActor );
868 
869  Actor unInitialzedActor;
870  customActor = CustomActor::DownCast( unInitialzedActor );
871  DALI_TEST_CHECK( !customActor );
872 
873  customActor = DownCast< CustomActor >( unInitialzedActor );
874  DALI_TEST_CHECK( !customActor );
875  END_TEST;
876 }
877 
879 {
880  TestApplication application;
881  tet_infoline("Testing Dali::CustomActor::OnStageConnection() & OnStageDisconnection");
882 
883  TestCustomActor custom = TestCustomActor::New();
884  DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
885 
886  // add the custom actor to stage
887  Stage::GetCurrent().Add( custom );
888 
889  DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
890  DALI_TEST_EQUALS( "OnStageConnection", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
891 
892  Stage::GetCurrent().Remove( custom );
893 
894  DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
895  DALI_TEST_EQUALS( "OnStageDisconnection", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
896 
897  // Excercise the message passing to Update thread
898 
899  application.SendNotification();
900  application.Render();
901  application.Render();
902  END_TEST;
903 }
904 
906 {
907  TestApplication application;
908  tet_infoline("Testing Dali::CustomActor::OnStageConnection() order");
909 
910  MasterCallStack.clear();
911 
912  /* Build tree of actors:
913  *
914  * A (parent)
915  * / \
916  * B C
917  * / \ \
918  * D E F
919  *
920  * OnStageConnection should be received for A, B, D, E, C, and finally F
921  */
922 
923  TestCustomActor actorA = TestCustomActor::New();
924  actorA.SetName( "ActorA" );
925 
926  TestCustomActor actorB = TestCustomActor::New();
927  actorB.SetName( "ActorB" );
928  actorA.Add( actorB );
929 
930  TestCustomActor actorC = TestCustomActor::New();
931  actorC.SetName( "ActorC" );
932  actorA.Add( actorC );
933 
934  TestCustomActor actorD = TestCustomActor::New();
935  actorD.SetName( "ActorD" );
936  actorB.Add( actorD );
937 
938  TestCustomActor actorE = TestCustomActor::New();
939  actorE.SetName( "ActorE" );
940  actorB.Add( actorE );
941 
942  TestCustomActor actorF = TestCustomActor::New();
943  actorF.SetName( "ActorF" );
944  actorC.Add( actorF );
945 
946  // add the custom actor to stage
947  Stage::GetCurrent().Add( actorA );
948 
949  DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
950  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
951  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
952  DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
953 
954  DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
955  DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
956  DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
957  DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
958 
959  DALI_TEST_EQUALS( 2, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
960  DALI_TEST_EQUALS( "OnChildAdd", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
961  DALI_TEST_EQUALS( "OnStageConnection", actorC.GetMethodsCalled()[ 1 ], TEST_LOCATION );
962 
963  DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
964  DALI_TEST_EQUALS( "OnStageConnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
965 
966  DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
967  DALI_TEST_EQUALS( "OnStageConnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
968 
969  DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
970  DALI_TEST_EQUALS( "OnStageConnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
971 
972  // Check sequence is correct in MasterCallStack
973 
974  DALI_TEST_EQUALS( 3+3+2+1+1+1, (int)(MasterCallStack.size()), TEST_LOCATION );
975 
976  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
977  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
978  DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
979  DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 3 ], TEST_LOCATION );
980  DALI_TEST_EQUALS( "ActorC: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
981 
982  DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 5 ], TEST_LOCATION );
983  DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 6 ], TEST_LOCATION );
984  DALI_TEST_EQUALS( "ActorD: OnStageConnection", MasterCallStack[ 7 ], TEST_LOCATION );
985  DALI_TEST_EQUALS( "ActorE: OnStageConnection", MasterCallStack[ 8 ], TEST_LOCATION );
986  DALI_TEST_EQUALS( "ActorC: OnStageConnection", MasterCallStack[ 9 ], TEST_LOCATION );
987  DALI_TEST_EQUALS( "ActorF: OnStageConnection", MasterCallStack[ 10 ], TEST_LOCATION );
988 
989  // Excercise the message passing to Update thread
990 
991  application.SendNotification();
992  application.Render();
993  application.Render();
994  END_TEST;
995 }
996 
998 {
999  TestApplication application;
1000  tet_infoline("Testing Dali::CustomActor::OnStageDisconnection() order");
1001 
1002  Stage stage = Stage::GetCurrent();
1003 
1004  /* Build tree of actors:
1005  *
1006  * A (parent)
1007  * / \
1008  * B C
1009  * / \ \
1010  * D E F
1011  *
1012  * OnStageDisconnection should be received for D, E, B, F, C, and finally A.
1013  */
1014 
1015  TestCustomActor actorA = TestCustomActor::New();
1016  actorA.SetName( "ActorA" );
1017  stage.Add( actorA );
1018 
1019  TestCustomActor actorB = TestCustomActor::New();
1020  actorB.SetName( "ActorB" );
1021  actorA.Add( actorB );
1022 
1023  TestCustomActor actorC = TestCustomActor::New();
1024  actorC.SetName( "ActorC" );
1025  actorA.Add( actorC );
1026 
1027  TestCustomActor actorD = TestCustomActor::New();
1028  actorD.SetName( "ActorD" );
1029  actorB.Add( actorD );
1030 
1031  TestCustomActor actorE = TestCustomActor::New();
1032  actorE.SetName( "ActorE" );
1033  actorB.Add( actorE );
1034 
1035  TestCustomActor actorF = TestCustomActor::New();
1036  actorF.SetName( "ActorF" );
1037  actorC.Add( actorF );
1038 
1039  // Excercise the message passing to Update thread
1040 
1041  application.SendNotification();
1042  application.Render();
1043  application.Render();
1044 
1045  // Clear call stacks before disconnection
1046  actorA.ResetCallStack();
1047  actorB.ResetCallStack();
1048  actorC.ResetCallStack();
1049  actorD.ResetCallStack();
1050  actorE.ResetCallStack();
1051  actorF.ResetCallStack();
1052  MasterCallStack.clear();
1053 
1054  stage.Remove( actorA );
1055 
1056  DALI_TEST_EQUALS( 1, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1057  DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1058 
1059  DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1060  DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1061 
1062  DALI_TEST_EQUALS( 1, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
1063  DALI_TEST_EQUALS( "OnStageDisconnection", actorC.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1064 
1065  DALI_TEST_EQUALS( 1, (int)(actorD.GetMethodsCalled().size()), TEST_LOCATION );
1066  DALI_TEST_EQUALS( "OnStageDisconnection", actorD.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1067 
1068  DALI_TEST_EQUALS( 1, (int)(actorE.GetMethodsCalled().size()), TEST_LOCATION );
1069  DALI_TEST_EQUALS( "OnStageDisconnection", actorE.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1070 
1071  DALI_TEST_EQUALS( 1, (int)(actorF.GetMethodsCalled().size()), TEST_LOCATION );
1072  DALI_TEST_EQUALS( "OnStageDisconnection", actorF.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1073 
1074  // Check sequence is correct in MasterCallStack
1075 
1076  DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION );
1077 
1078  DALI_TEST_EQUALS( "ActorD: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1079  DALI_TEST_EQUALS( "ActorE: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
1080  DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 2 ], TEST_LOCATION );
1081  DALI_TEST_EQUALS( "ActorF: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1082  DALI_TEST_EQUALS( "ActorC: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
1083  DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 5 ], TEST_LOCATION );
1084 
1085  // Excercise the message passing to Update thread
1086 
1087  application.SendNotification();
1088  application.Render();
1089  application.Render();
1090  END_TEST;
1091 }
1092 
1094 {
1095  TestApplication application;
1096  tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageConnection() callback");
1097 
1098  Stage stage = Stage::GetCurrent();
1099 
1100  MasterCallStack.clear();
1101 
1102  /* The actorA is a special variant which adds a child to itself during OnStageConnection()
1103  * The actorB is provided as the child
1104  */
1105 
1106  TestCustomActor actorB = TestCustomActor::New();
1107  actorB.SetName( "ActorB" );
1108 
1109  TestCustomActor actorA = TestCustomActor::NewVariant1( actorB );
1110  actorA.SetName( "ActorA" );
1111  stage.Add( actorA );
1112 
1113  // Check callback sequence
1114 
1115  DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1116  DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1117  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION ); // Called from within OnStageConnection()
1118 
1119  DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1120  DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1121 
1122  DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
1123 
1124  DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
1125  DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION ); // Occurs during Actor::Add from within from within OnStageConnection()
1126  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION ); // Occurs after Actor::Add from within from within OnStageConnection()
1127 
1128  // Excercise the message passing to Update thread
1129 
1130  application.SendNotification();
1131  application.Render();
1132  application.Render();
1133 
1134  // Check everything is ok after Actors are removed
1135 
1136  stage.Remove( actorA );
1137  application.SendNotification();
1138  application.Render();
1139  application.Render();
1140  END_TEST;
1141 }
1142 
1144 {
1145  TestApplication application;
1146  tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageConnection() callback");
1147 
1148  Stage stage = Stage::GetCurrent();
1149 
1150  MasterCallStack.clear();
1151 
1152  /* The actorA is a special variant which removes its children during OnStageConnection()
1153  * Actors B & C are provided as the children
1154  */
1155 
1156  TestCustomActor actorA = TestCustomActor::NewVariant2();
1157  actorA.SetName( "ActorA" );
1158 
1159  TestCustomActor actorB = TestCustomActor::New();
1160  actorB.SetName( "ActorB" );
1161  actorA.Add( actorB );
1162 
1163  TestCustomActor actorC = TestCustomActor::New();
1164  actorC.SetName( "ActorC" );
1165  actorA.Add( actorC );
1166 
1167  stage.Add( actorA );
1168 
1169  // Check callback sequence
1170 
1171  DALI_TEST_EQUALS( 5, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1172  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1173  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1174  DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1175  DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION ); // Called from within OnStageConnection()
1176  DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 4 ], TEST_LOCATION ); // Called from within OnStageConnection()
1177 
1178  DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
1179 
1180  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
1181  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
1182  DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
1183  DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 3 ], TEST_LOCATION );
1184  DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 4 ], TEST_LOCATION );
1185 
1186  /* Actors B & C should be removed before the point where they could receive an OnStageConnection callback
1187  * Therefore they shouldn't receive either OnStageConnection or OnStageDisconnection
1188  */
1189  DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1190  DALI_TEST_EQUALS( 0, (int)(actorC.GetMethodsCalled().size()), TEST_LOCATION );
1191 
1192  // Excercise the message passing to Update thread
1193 
1194  application.SendNotification();
1195  application.Render();
1196  application.Render();
1197 
1198  // Check everything is ok after last actor is removed
1199 
1200  stage.Remove( actorA );
1201  application.SendNotification();
1202  application.Render();
1203  application.Render();
1204  END_TEST;
1205 }
1206 
1208 {
1209  TestApplication application;
1210  tet_infoline("Testing Actor::Add behaviour during Dali::CustomActor::OnStageDisonnection() callback");
1211 
1212  Stage stage = Stage::GetCurrent();
1213 
1214  /* The actorA is a special variant which adds a child to itself during OnStageDisconnection()
1215  * The actorB is provided as the child
1216  */
1217 
1218  TestCustomActor actorB = TestCustomActor::New();
1219  actorB.SetName( "ActorB" );
1220 
1221  TestCustomActor actorA = TestCustomActor::NewVariant3( actorB );
1222  actorA.SetName( "ActorA" );
1223  stage.Add( actorA );
1224 
1225  // Excercise the message passing to Update thread
1226 
1227  application.SendNotification();
1228  application.Render();
1229  application.Render();
1230 
1231  // Clear call stacks before disconnection
1232  actorA.ResetCallStack();
1233  actorB.ResetCallStack();
1234  MasterCallStack.clear();
1235 
1236  stage.Remove( actorA );
1237 
1238  // Check callback sequence
1239 
1240  DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1241  DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1242  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1243 
1244  // Child was added after parent disconnection, so should not receive OnStageConnection()
1245  DALI_TEST_EQUALS( 0, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1246 
1247  DALI_TEST_EQUALS( 2, (int)(MasterCallStack.size()), TEST_LOCATION );
1248 
1249  DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1250  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 1 ], TEST_LOCATION );
1251 
1252  // Excercise the message passing to Update thread
1253 
1254  application.SendNotification();
1255  application.Render();
1256  application.Render();
1257  END_TEST;
1258 }
1259 
1261 {
1262  TestApplication application;
1263  tet_infoline("Testing Actor::Remove behaviour during Dali::CustomActor::OnStageDisconnection() callback");
1264 
1265  Stage stage = Stage::GetCurrent();
1266 
1267  /* The actorA is a special variant which removes its children during OnStageDisconnection()
1268  * The actorB is provided as the child
1269  */
1270 
1271  TestCustomActor actorA = TestCustomActor::NewVariant4();
1272  actorA.SetName( "ActorA" );
1273  stage.Add( actorA );
1274 
1275  TestCustomActor actorB = TestCustomActor::New();
1276  actorB.SetName( "ActorB" );
1277  actorA.Add( actorB );
1278 
1279  // Excercise the message passing to Update thread
1280 
1281  application.SendNotification();
1282  application.Render();
1283  application.Render();
1284 
1285  // Clear call stacks before disconnection
1286  actorA.ResetCallStack();
1287  actorB.ResetCallStack();
1288  MasterCallStack.clear();
1289 
1290  stage.Remove( actorA );
1291 
1292  // Check callback sequence
1293 
1294  DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1295  DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1296  DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1297 
1298  DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1299  DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1300 
1301  DALI_TEST_EQUALS( 3, (int)(MasterCallStack.size()), TEST_LOCATION );
1302 
1303  DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 0 ], TEST_LOCATION );
1304  DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 1 ], TEST_LOCATION );
1305  DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 2 ], TEST_LOCATION );
1306 
1307  // Excercise the message passing to Update thread
1308 
1309  application.SendNotification();
1310  application.Render();
1311  application.Render();
1312  END_TEST;
1313 }
1314 
1316 {
1317  TestApplication application;
1318  tet_infoline("Weird test where child removes its own parent from Stage during Dali::CustomActor::OnStageConnection() callback");
1319 
1320  Stage stage = Stage::GetCurrent();
1321 
1322  MasterCallStack.clear();
1323 
1324  /* The actorA is the parent of actorB
1325  * The actorB is a special variant which removes its own parent during OnStageConnection()
1326  * The child actor is interrupting the parent's connection to stage, therefore the parent should not get an OnStageDisconnection()
1327  */
1328 
1329  TestCustomActor actorA = TestCustomActor::New();
1330  actorA.SetName( "ActorA" );
1331 
1332  TestCustomActor actorB = TestCustomActor::NewVariant5();
1333  actorB.SetName( "ActorB" );
1334  actorA.Add( actorB );
1335 
1336  stage.Add( actorA );
1337 
1338  // Check callback sequence
1339 
1340  DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1341  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1342  DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1343  DALI_TEST_EQUALS( "OnStageDisconnection", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1344 
1345  DALI_TEST_EQUALS( 1, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1346  DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1347 
1348  DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
1349 
1350  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
1351  DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
1352  DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
1353  DALI_TEST_EQUALS( "ActorA: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1354 
1355  // Excercise the message passing to Update thread
1356 
1357  application.SendNotification();
1358  application.Render();
1359  application.Render();
1360  END_TEST;
1361 }
1362 
1364 {
1365  TestApplication application;
1366  tet_infoline("Weird test where child adds its own parent to Stage during Dali::CustomActor::OnStageDisconnection() callback");
1367 
1368  Stage stage = Stage::GetCurrent();
1369 
1370  MasterCallStack.clear();
1371 
1372  /* The actorA is the parent of actorB
1373  * The actorB is a special variant which (weirdly) adds its own parent during OnStageDisconnection()
1374  * The child actor is interrupting the disconnection, such that parent should not get a OnStageDisconnection()
1375  */
1376 
1377  TestCustomActor actorA = TestCustomActor::New();
1378  actorA.SetName( "ActorA" );
1379  stage.Add( actorA );
1380 
1381  TestCustomActor actorB = TestCustomActor::NewVariant6();
1382  actorB.SetName( "ActorB" );
1383  actorA.Add( actorB );
1384 
1385  stage.Remove( actorA );
1386 
1387  // Check callback sequence
1388 
1389  DALI_TEST_EQUALS( 2, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1390  DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1391  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1392 
1393  DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1394  DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1395  DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1396  // Disconnect was interrupted, so we should only get one OnStageConnection() for actorB
1397 
1398  DALI_TEST_EQUALS( 4, (int)(MasterCallStack.size()), TEST_LOCATION );
1399 
1400  DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
1401  DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
1402  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
1403  DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 3 ], TEST_LOCATION );
1404 
1405  // Excercise the message passing to Update thread
1406 
1407  application.SendNotification();
1408  application.Render();
1409  application.Render();
1410  END_TEST;
1411 }
1412 
1414 {
1415  TestApplication application;
1416  tet_infoline("Testing Dali::CustomActor::OnChildAdd() & OnChildRemove()");
1417 
1418  TestCustomActor custom = TestCustomActor::New();
1419  DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1420 
1421  Actor aChild = Actor::New();
1422  custom.Add( aChild );
1423 
1424  DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1425  DALI_TEST_EQUALS( "OnChildAdd", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1426 
1427  custom.Remove( aChild );
1428 
1429  DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1430  DALI_TEST_EQUALS( "OnChildRemove", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1431  END_TEST;
1432 }
1433 
1435 {
1436  TestApplication application;
1437  tet_infoline("Testing Actor:Add (reparenting) behaviour during Dali::CustomActor::OnChildAdd() callback");
1438 
1439  Stage stage = Stage::GetCurrent();
1440 
1441  MasterCallStack.clear();
1442 
1443  /* The actorA is a special variant which reparents children added into a separate container child
1444  * The actorB is the child of actorA
1445  */
1446 
1447  TestCustomActor actorA = TestCustomActor::NewVariant7( "ActorA" );
1448  stage.Add( actorA );
1449 
1450  TestCustomActor actorB = TestCustomActor::New();
1451  actorB.SetName( "ActorB" );
1452  actorA.Add( actorB );
1453 
1454  // Check hierarchy is as follows:
1455  // A
1456  // |
1457  // Container
1458  // |
1459  // B
1460 
1461  DALI_TEST_EQUALS( 1, (int)(actorA.GetChildCount()), TEST_LOCATION );
1462 
1463  Actor container = actorA.GetChildAt(0);
1464  Actor containerChild;
1465 
1466  DALI_TEST_CHECK( container );
1467  if ( container )
1468  {
1469  DALI_TEST_EQUALS( "Container", container.GetName(), TEST_LOCATION );
1470  DALI_TEST_EQUALS( 1, (int)(container.GetChildCount()), TEST_LOCATION );
1471  containerChild = container.GetChildAt(0);
1472  }
1473 
1474  DALI_TEST_CHECK( containerChild );
1475  if ( containerChild )
1476  {
1477  DALI_TEST_EQUALS( "ActorB", containerChild.GetName(), TEST_LOCATION );
1478  DALI_TEST_EQUALS( 0, (int)(containerChild.GetChildCount()), TEST_LOCATION );
1479  }
1480 
1481  // Check callback sequence
1482 
1483  DALI_TEST_EQUALS( 4, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1484  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
1485  DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1486  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
1487  DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 3 ], TEST_LOCATION );
1488  // mContainer will then receive OnChildAdd
1489 
1490  DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1491  DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1492  DALI_TEST_EQUALS( "OnStageDisconnection", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1493  DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION );
1494 
1495  DALI_TEST_EQUALS( 7, (int)(MasterCallStack.size()), TEST_LOCATION );
1496 
1497  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 0 ], TEST_LOCATION );
1498  DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
1499  DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 2 ], TEST_LOCATION );
1500  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 3 ], TEST_LOCATION );
1501  DALI_TEST_EQUALS( "ActorB: OnStageDisconnection", MasterCallStack[ 4 ], TEST_LOCATION );
1502  DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 5 ], TEST_LOCATION );
1503  DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 6 ], TEST_LOCATION );
1504 
1505  // Excercise the message passing to Update thread
1506 
1507  application.SendNotification();
1508  application.Render();
1509  application.Render();
1510  END_TEST;
1511 }
1512 
1518 {
1519  TestApplication application;
1520  tet_infoline("Testing Actor:Remove behaviour during OnChildRemove() callback triggered when reparenting");
1521 
1522  Stage stage = Stage::GetCurrent();
1523 
1524  MasterCallStack.clear();
1525 
1526  /* The childActor will be reparented from actorA to actorB
1527  * The actorA is a special variant which attempts to remove a child from actorB, during the OnChildRemove callback()
1528  * This should be a NOOP since the reparenting has not occured yet
1529  */
1530 
1531  TestCustomActor actorB = TestCustomActor::New();
1532  actorB.SetName( "ActorB" );
1533  stage.Add( actorB );
1534 
1535  TestCustomActor actorA = TestCustomActor::NewVariant8( actorB );
1536  actorA.SetName( "ActorA" );
1537  stage.Add( actorA );
1538 
1539  Actor childActor = Actor::New();
1540  childActor.SetName( "Child" );
1541  // Reparent from actorA to actorB
1542  actorA.Add( childActor );
1543  actorB.Add( childActor );
1544 
1545  // Check hierarchy is as follows:
1546  // A B
1547  // |
1548  // Child
1549 
1550  DALI_TEST_EQUALS( 0, (int)(actorA.GetChildCount()), TEST_LOCATION );
1551  DALI_TEST_EQUALS( 1, (int)(actorB.GetChildCount()), TEST_LOCATION );
1552  DALI_TEST_EQUALS( 0, (int)(childActor.GetChildCount()), TEST_LOCATION );
1553 
1554  Actor child = actorB.GetChildAt(0);
1555 
1556  DALI_TEST_CHECK( child );
1557  if ( child )
1558  {
1559  DALI_TEST_EQUALS( "Child", child.GetName(), TEST_LOCATION );
1560  }
1561 
1562  // Check callback sequence
1563 
1564  DALI_TEST_EQUALS( 3, (int)(actorA.GetMethodsCalled().size()), TEST_LOCATION );
1565  DALI_TEST_EQUALS( "OnStageConnection", actorA.GetMethodsCalled()[ 0 ], TEST_LOCATION ); // The mContainer added to actorA
1566  DALI_TEST_EQUALS( "OnChildAdd", actorA.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1567  DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA
1568  // mContainer will then receive OnChildAdd
1569 
1570  DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION );
1571  DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1572  DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1573 
1574  DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION );
1575 
1576  DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION );
1577  DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION );
1578  DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION );
1579  DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 3 ], TEST_LOCATION );
1580  DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION );
1581 
1582  // Excercise the message passing to Update thread
1583 
1584  application.SendNotification();
1585  application.Render();
1586  application.Render();
1587  END_TEST;
1588 }
1589 
1591 {
1592  TestApplication application;
1593  tet_infoline("Testing Dali::CustomActor::OnPropertySet()");
1594 
1595  TestCustomActor custom = TestCustomActor::New();
1596  DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1597 
1598  custom.SetDaliProperty("yes");
1599 
1600  DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1601  DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1602  END_TEST;
1603 }
1604 
1606 {
1607  TestApplication application;
1608  tet_infoline("Testing Dali::CustomActor::OnSizeSet()");
1609 
1610  TestCustomActor custom = TestCustomActor::New();
1611  DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1612 
1613  custom.SetSize( Vector2( 9.0f, 10.0f ) );
1614  DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1615  DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1616  DALI_TEST_EQUALS( 9.0f, custom.GetSize().width, TEST_LOCATION );
1617  DALI_TEST_EQUALS( 10.0f, custom.GetSize().height, TEST_LOCATION );
1618 
1619  custom.SetSize( Vector3( 4.0f, 5.0f, 6.0f ) );
1620  DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1621  DALI_TEST_EQUALS( "OnSizeSet", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION );
1622  DALI_TEST_EQUALS( 4.0f, custom.GetSize().width, TEST_LOCATION );
1623  DALI_TEST_EQUALS( 5.0f, custom.GetSize().height, TEST_LOCATION );
1624  DALI_TEST_EQUALS( 6.0f, custom.GetSize().depth, TEST_LOCATION );
1625  END_TEST;
1626 }
1627 
1629 {
1630  TestApplication application;
1631  tet_infoline("Testing Dali::CustomActor::OnSizeAnimation()");
1632 
1633  TestCustomActor custom = TestCustomActor::New();
1634  DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1635 
1636  Animation anim = Animation::New( 1.0f );
1637  anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) );
1638  DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1639  DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1640  DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION );
1641  DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION );
1642  DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION );
1643  END_TEST;
1644 }
1645 
1647 {
1648  TestApplication application;
1649  tet_infoline("Testing Dali::CustomActor::OnTouchEvent()");
1650 
1651  TestCustomActor custom = TestCustomActor::New();
1652  DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1653 
1654  // set size for custom actor
1655  custom.SetSize( 100, 100 );
1656  // add the custom actor to stage
1657  Stage::GetCurrent().Add( custom );
1658  custom.ResetCallStack();
1659 
1660  // Render and notify a couple of times
1661  application.SendNotification();
1662  application.Render();
1663  application.SendNotification();
1664  application.Render();
1665 
1666  // simulate a touch event
1667  Dali::TouchPoint point( 0, TouchPoint::Down, 1, 1 );
1668  Dali::Integration::TouchEvent event;
1669  event.AddPoint( point );
1670  application.ProcessEvent( event );
1671 
1672  DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1673  DALI_TEST_EQUALS( "OnTouchEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1674  END_TEST;
1675 }
1676 
1678 {
1679  TestApplication application;
1680  tet_infoline("Testing Dali::CustomActor::OnHoverEvent()");
1681 
1682  TestCustomActor custom = TestCustomActor::New();
1683  DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1684 
1685  // set size for custom actor
1686  custom.SetSize( 100, 100 );
1687  // add the custom actor to stage
1688  Stage::GetCurrent().Add( custom );
1689  custom.ResetCallStack();
1690 
1691  // Render and notify a couple of times
1692  application.SendNotification();
1693  application.Render();
1694  application.SendNotification();
1695  application.Render();
1696 
1697  // simulate a hover event
1698  Dali::TouchPoint point( 0, TouchPoint::Motion, 1, 1 );
1699  Dali::Integration::HoverEvent event;
1700  event.AddPoint( point );
1701  application.ProcessEvent( event );
1702 
1703  DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1704  DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1705  END_TEST;
1706 }
1707 
1709 {
1710  TestApplication application;
1711  tet_infoline("Testing Dali::CustomActor::OnWheelEvent()");
1712 
1713  TestCustomActor custom = TestCustomActor::New();
1714  DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1715 
1716  // set size for custom actor
1717  custom.SetSize( 100, 100 );
1718  // add the custom actor to stage
1719  Stage::GetCurrent().Add( custom );
1720  custom.ResetCallStack();
1721 
1722  // Render and notify a couple of times
1723  application.SendNotification();
1724  application.Render();
1725  application.SendNotification();
1726  application.Render();
1727 
1728  // simulate a wheel event
1729  Vector2 screenCoordinates( 10.0f, 10.0f );
1730  Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u );
1731  application.ProcessEvent( event );
1732 
1733  DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION );
1734  DALI_TEST_EQUALS( "OnWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION );
1735  END_TEST;
1736 }
1737 
1739 {
1740  TestApplication application;
1742 
1743  impl->OnPropertySet( 0, 0 );
1744 
1745  DALI_TEST_CHECK( true );
1746 
1747  delete impl;
1748  END_TEST;
1749 }
1750 
1752 {
1753  TestApplication application;
1754 
1755  TestCustomActor custom = TestCustomActor::New();
1756  CustomActorImpl& impl = custom.GetImplementation();
1757  impl.GetOwner(); // Test
1758 
1759  const TestCustomActor constCustom = TestCustomActor::New();
1760  const CustomActorImpl& constImpl = constCustom.GetImplementation();
1761  constImpl.GetOwner(); // Test
1762 
1763  DALI_TEST_CHECK( true );
1764  END_TEST;
1765 }
1766 
1768 {
1769  TestApplication application;
1770  tet_infoline("Testing Dali::CustomActor::DoAction()");
1771 
1772  TestCustomActor custom = TestCustomActor::New();
1773 
1774  BaseHandle customActorObject = custom;
1775 
1776  DALI_TEST_CHECK(customActorObject);
1777 
1778  Property::Map attributes;
1779 
1780  // Check that an invalid command is not performed
1781  DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
1782 
1783  // Check that the custom actor is visible
1784  custom.SetVisible(true);
1785  DALI_TEST_CHECK(custom.IsVisible() == true);
1786 
1787  // Check the custom actor performed an action to hide itself
1788  DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
1789 
1790  // flush the queue and render once
1791  application.SendNotification();
1792  application.Render();
1793 
1794  // Check that the custom actor is now invisible
1795  DALI_TEST_CHECK(custom.IsVisible() == false);
1796 
1797  // Check the custom actor performed an action to show itself
1798  DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
1799 
1800  // flush the queue and render once
1801  application.SendNotification();
1802  application.Render();
1803 
1804  // Check that the custom actor is now visible
1805  DALI_TEST_CHECK(custom.IsVisible() == true);
1806  END_TEST;
1807 }
1808 
1810 {
1811  Dali::CustomActor customA;
1812  Dali::CustomActor customB( customA );
1813 
1814  DALI_TEST_CHECK( customA == customB );
1815 
1816  END_TEST;
1817 }
1818 
1820 {
1821  TestApplication application;
1822 
1823  DALI_TEST_CHECK( gOnRelayout == false );
1824 
1825  TestCustomActor custom = TestCustomActor::NewNegoSize();
1826  Stage::GetCurrent().Add(custom);
1827 
1828  application.SendNotification();
1829  application.Render();
1830 
1831  DALI_TEST_CHECK( gOnRelayout == true );
1832  gOnRelayout = false;
1833 
1834  custom.TestRelayoutRequest();
1835  application.SendNotification();
1836  application.Render();
1837 
1838  DALI_TEST_CHECK( gOnRelayout == true );
1839 
1840  END_TEST;
1841 }
1842 
1844 {
1845  TestApplication application;
1846  TestCustomActor custom = TestCustomActor::NewNegoSize();
1847 
1848  float width = 300.0f;
1849  float v = 0.0f;
1850 
1851  application.SendNotification();
1852  application.Render();
1853 
1854  v = custom.TestGetHeightForWidthBase( width );
1855 
1856  DALI_TEST_CHECK( v == width );
1857 
1858  END_TEST;
1859 }
1860 
1862 {
1863  TestApplication application;
1864  TestCustomActor custom = TestCustomActor::NewNegoSize();
1865 
1866  float height = 300.0f;
1867  float v = 0.0f;
1868 
1869  application.SendNotification();
1870  application.Render();
1871 
1872  v = custom.TestGetWidthForHeightBase( height );
1873 
1874  DALI_TEST_CHECK( v == height );
1875 
1876  END_TEST;
1877 }
1878 
1880 {
1881  TestApplication application;
1882  TestCustomActor custom = TestCustomActor::NewNegoSize();
1883 
1884  Actor child = Actor::New();
1886  child.SetSize(150, 150);
1887 
1888  application.SendNotification();
1889  application.Render();
1890 
1891  float v = 9.99f;
1892  v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS );
1893  DALI_TEST_CHECK( v == 0.0f );
1894 
1895  END_TEST;
1896 }
1897 
1899 {
1900  TestApplication application;
1901  TestCustomActor custom = TestCustomActor::NewNegoSize();
1903 
1904  bool v = false;
1905 
1906  v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS );
1907  application.SendNotification();
1908  application.Render();
1909 
1910  DALI_TEST_CHECK( v == true );
1911 
1913  v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH );
1914  application.SendNotification();
1915  application.Render();
1916  DALI_TEST_CHECK( v == false );
1917 
1918  END_TEST;
1919 }
1920 
1922 {
1923  TestApplication application;
1924 
1925  // Register Type
1926  TypeInfo type;
1927  type = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
1928  DALI_TEST_CHECK( type );
1929  BaseHandle handle = type.CreateInstance();
1930 
1931  std::string name;
1932  std::string exception;
1933 
1934  try
1935  {
1936  name = handle.GetTypeName();
1938  }
1939  catch( DaliException& e )
1940  {
1941  exception = e.condition;
1942  DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION );
1943  }
1944 
1945  END_TEST;
1946 }
1947 
1948 
1950 {
1951  TestApplication application;
1952 
1953  TestCustomActor custom = TestCustomActor::NewVariant5();
1954 
1955  DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() );
1956 
1957  END_TEST;
1958 }
1959 
1961 {
1962  TestApplication application;
1963  tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth");
1964 
1965  Stage stage = Stage::GetCurrent();
1966 
1967  /* Build tree of actors:
1968  *
1969  * Depth
1970  *
1971  * A (parent) 1
1972  * / \
1973  * B C 2
1974  * / \ \
1975  * D E F 3
1976  *
1977  * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F.
1978  */
1979 
1980  TestCustomActor actorA = TestCustomActor::New();
1981  stage.Add( actorA );
1982 
1983  TestCustomActor actorB = TestCustomActor::New();
1984  actorA.Add( actorB );
1985 
1986  TestCustomActor actorC = TestCustomActor::New();
1987  actorA.Add( actorC );
1988 
1989  TestCustomActor actorD = TestCustomActor::New();
1990  actorB.Add( actorD );
1991 
1992  TestCustomActor actorE = TestCustomActor::New();
1993  actorB.Add( actorE );
1994 
1995  TestCustomActor actorF = TestCustomActor::New();
1996  actorC.Add( actorF );
1997 
1998  // Excercise the message passing to Update thread
1999  application.SendNotification();
2000  application.Render();
2001  application.Render();
2002 
2003  DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION );
2004  DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION );
2005  DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION );
2006  DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION );
2007  DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION );
2008  DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION );
2009 
2010  END_TEST;
2011 }
Dali Docs Home
Read more about Dali