d38de864b12b156f1b00f9c283f8312a61744491
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TypeRegistry.cpp
1 /*
2  * Copyright (c) 2016 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 <limits>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <dali/integration-api/events/long-press-gesture-event.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25 #include <dali/integration-api/events/pinch-gesture-event.h>
26 #include <dali/integration-api/events/tap-gesture-event.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28 #include <dali/integration-api/events/hover-event-integ.h>
29
30 using namespace Dali;
31
32
33 namespace
34 {
35
36 // Stores data that is populated in the callback and will be read by the Test cases
37 struct SignalData
38 {
39   SignalData()
40   : functorCalled( false ),
41     voidFunctorCalled( false ),
42     receivedGesture( Gesture::Clear ),
43     pressedActor()
44   {}
45
46   void Reset()
47   {
48     functorCalled = false;
49     voidFunctorCalled = false;
50
51     receivedGesture.numberOfTouches = 0u;
52     receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
53     receivedGesture.localPoint = Vector2(0.0f, 0.0f);
54
55     pressedActor.Reset();
56   }
57
58   bool functorCalled;
59   bool voidFunctorCalled;
60   LongPressGesture receivedGesture;
61   Actor pressedActor;
62 };
63
64 // Functor that sets the data when called
65 struct GestureReceivedFunctor
66 {
67   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
68
69   void operator()(Actor actor, LongPressGesture longPress)
70   {
71     signalData.functorCalled = true;
72     signalData.receivedGesture = longPress;
73     signalData.pressedActor = actor;
74   }
75
76   void operator()()
77   {
78     signalData.voidFunctorCalled = true;
79   }
80
81   SignalData& signalData;
82 };
83
84 // Generate a LongPressGestureEvent to send to Core
85 Integration::LongPressGestureEvent GenerateLongPress(
86     Gesture::State state,
87     unsigned int numberOfTouches,
88     Vector2 point)
89 {
90   Integration::LongPressGestureEvent longPress( state );
91
92   longPress.numberOfTouches = numberOfTouches;
93   longPress.point = point;
94
95   return longPress;
96 }
97
98 // Generate a PanGestureEvent to send to Core
99 Integration::PanGestureEvent GeneratePan(
100     Gesture::State state,
101     Vector2 previousPosition,
102     Vector2 currentPosition,
103     unsigned long timeDelta,
104     unsigned int numberOfTouches = 1,
105     unsigned int time = 1u)
106 {
107   Integration::PanGestureEvent pan(state);
108
109   pan.previousPosition = previousPosition;
110   pan.currentPosition = currentPosition;
111   pan.timeDelta = timeDelta;
112   pan.numberOfTouches = numberOfTouches;
113   pan.time = time;
114
115   return pan;
116 }
117 // Generate a PinchGestureEvent to send to Core
118 Integration::PinchGestureEvent GeneratePinch(
119     Gesture::State state,
120     float scale,
121     float speed,
122     Vector2 centerpoint)
123 {
124   Integration::PinchGestureEvent pinch(state);
125
126   pinch.scale = scale;
127   pinch.speed = speed;
128   pinch.centerPoint = centerpoint;
129
130   return pinch;
131 }
132 // Generate a TapGestureEvent to send to Core
133 Integration::TapGestureEvent GenerateTap(
134     Gesture::State state,
135     unsigned int numberOfTaps,
136     unsigned int numberOfTouches,
137     Vector2 point)
138 {
139   Integration::TapGestureEvent tap( state );
140
141   tap.numberOfTaps = numberOfTaps;
142   tap.numberOfTouches = numberOfTouches;
143   tap.point = point;
144
145   return tap;
146 }
147
148 //
149 // Create function as Init function called
150 //
151 static bool CreateCustomInitCalled = false;
152 BaseHandle CreateCustomInit(void)
153 {
154   CreateCustomInitCalled = true;
155   return BaseHandle();
156 }
157
158 static bool CreateCustomNamedInitCalled = false;
159 BaseHandle CreateCustomNamedInit(void)
160 {
161   CreateCustomNamedInitCalled = true;
162   return BaseHandle();
163 }
164
165 const std::string scriptedName("PopupStyle");
166 static TypeRegistration scriptedType( scriptedName, typeid(Dali::CustomActor), CreateCustomNamedInit );
167
168 // Property Registration
169 bool setPropertyCalled = false;
170 bool getPropertyCalled = false;
171 void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
172 {
173   setPropertyCalled = true;
174 }
175 Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex )
176 {
177   getPropertyCalled = true;
178   return Property::Value( true );
179 }
180
181
182
183 /*******************************************************************************
184  *
185  * Custom Actor
186  *
187  ******************************************************************************/
188 namespace Impl
189 {
190 struct MyTestCustomActor : public CustomActorImpl
191 {
192   typedef Signal< void ()> SignalType;
193   typedef Signal< void (float)> SignalTypeFloat;
194
195   MyTestCustomActor() : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS ) )
196   { }
197
198   virtual ~MyTestCustomActor()
199   { }
200
201   void ResetCallStack()
202   {
203   }
204
205   // From CustomActorImpl
206   virtual void OnStageConnection( int depth )
207   {
208   }
209   virtual void OnStageDisconnection()
210   {
211   }
212   virtual void OnChildAdd(Actor& child)
213   {
214   }
215   virtual void OnChildRemove(Actor& child)
216   {
217   }
218   virtual void OnSizeSet(const Vector3& targetSize)
219   {
220   }
221   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
222   {
223   }
224   virtual bool OnTouchEvent(const TouchEvent& event)
225   {
226     return true;
227   }
228   virtual bool OnHoverEvent(const HoverEvent& event)
229   {
230     return true;
231   }
232   virtual bool OnWheelEvent(const WheelEvent& event)
233   {
234     return true;
235   }
236   virtual bool OnKeyEvent(const KeyEvent& event)
237   {
238     return true;
239   }
240   virtual void OnKeyInputFocusGained()
241   {
242   }
243   virtual void OnKeyInputFocusLost()
244   {
245   }
246   virtual Vector3 GetNaturalSize()
247   {
248     return Vector3( 0.0f, 0.0f, 0.0f );
249   }
250
251   virtual float GetHeightForWidth( float width )
252   {
253     return 0.0f;
254   }
255
256   virtual float GetWidthForHeight( float height )
257   {
258     return 0.0f;
259   }
260
261   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
262   {
263   }
264
265   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
266   {
267   }
268
269   virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
270   {
271   }
272
273   virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
274   {
275     return 0.0f;
276   }
277
278   virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
279   {
280   }
281
282   virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
283   {
284     return false;
285   }
286
287 public:
288
289   SignalType mSignal;
290 };
291
292 }; // namespace Impl
293
294 class MyTestCustomActor : public CustomActor
295 {
296 public:
297
298   typedef Signal< void ()> SignalType;
299   typedef Signal< void (float)> SignalTypeFloat;
300
301   MyTestCustomActor()
302   {
303   }
304
305   static MyTestCustomActor New()
306   {
307     Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
308     return MyTestCustomActor( *p ); // takes ownership
309   }
310
311   virtual ~MyTestCustomActor()
312   {
313   }
314
315   static MyTestCustomActor DownCast( BaseHandle handle )
316   {
317     MyTestCustomActor result;
318
319     CustomActor custom = Dali::CustomActor::DownCast( handle );
320     if ( custom )
321     {
322       CustomActorImpl& customImpl = custom.GetImplementation();
323
324       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
325
326       if (impl)
327       {
328         result = MyTestCustomActor(customImpl.GetOwner());
329       }
330     }
331
332     return result;
333   }
334
335   SignalType& GetCustomSignal()
336   {
337     Dali::RefObject& obj = GetImplementation();
338     return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
339   }
340
341 private:
342
343   MyTestCustomActor(Internal::CustomActor* internal)
344   : CustomActor(internal)
345   {
346   }
347
348   MyTestCustomActor( Impl::MyTestCustomActor& impl )
349   : CustomActor( impl )
350   {
351   }
352 };
353
354
355 class MyTestCustomActor2 : public CustomActor
356 {
357 public:
358
359   struct Property
360   {
361     enum
362     {
363       P1=Dali::PROPERTY_REGISTRATION_START_INDEX,
364       P2
365     };
366   };
367
368
369   MyTestCustomActor2()
370   {
371   }
372
373   static MyTestCustomActor2 New()
374   {
375     return MyTestCustomActor2(); // takes ownership
376   }
377
378   virtual ~MyTestCustomActor2()
379   {
380   }
381
382   static MyTestCustomActor2 DownCast( BaseHandle handle )
383   {
384     MyTestCustomActor2 result;
385
386     CustomActor custom = Dali::CustomActor::DownCast( handle );
387     if ( custom )
388     {
389       CustomActorImpl& customImpl = custom.GetImplementation();
390
391       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
392
393       if (impl)
394       {
395         result = MyTestCustomActor2(customImpl.GetOwner());
396       }
397     }
398
399     return result;
400   }
401
402 private:
403
404   MyTestCustomActor2(Internal::CustomActor* internal)
405   : CustomActor(internal)
406   {
407   }
408
409   MyTestCustomActor2( Impl::MyTestCustomActor& impl )
410   : CustomActor( impl )
411   {
412   }
413 };
414
415 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
416
417 PropertyRegistration P1( customTypeInit, "propertyOne", MyTestCustomActor2::Property::P1, Property::INTEGER, &SetProperty, &GetProperty );
418 PropertyRegistration P2( customTypeInit, "propertyTwo", MyTestCustomActor2::Property::P2, Property::STRING, &SetProperty, &GetProperty );
419
420
421 class MyTestCustomActor3 : public CustomActor
422 {
423 public:
424   MyTestCustomActor3()
425   {
426   }
427
428   static MyTestCustomActor3 New()
429   {
430     return MyTestCustomActor3(); // takes ownership
431   }
432
433   virtual ~MyTestCustomActor3()
434   {
435   }
436
437   static MyTestCustomActor3 DownCast( BaseHandle handle )
438   {
439     MyTestCustomActor3 result;
440
441     CustomActor custom = Dali::CustomActor::DownCast( handle );
442     if ( custom )
443     {
444       CustomActorImpl& customImpl = custom.GetImplementation();
445
446       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
447
448       if (impl)
449       {
450         result = MyTestCustomActor3(customImpl.GetOwner());
451       }
452     }
453
454     return result;
455   }
456
457 private:
458
459   MyTestCustomActor3(Internal::CustomActor* internal)
460   : CustomActor(internal)
461   {
462   }
463
464   MyTestCustomActor3( Impl::MyTestCustomActor& impl )
465   : CustomActor( impl )
466   {
467   }
468 };
469
470 static TypeRegistration customTypeBadInit( typeid(MyTestCustomActor3), typeid(Dali::CustomActor), NULL, false );
471
472 BaseHandle CreateCustom(void)
473 {
474   return MyTestCustomActor::New();
475 }
476
477 static std::string lastSignalConnectionCustom;
478
479 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
480 {
481   lastSignalConnectionCustom = signalName;
482
483   bool connected( true );
484
485   Dali::BaseHandle handle(object);
486   MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
487
488   if( "sig1" == signalName )
489   {
490     customActor.GetCustomSignal().Connect( tracker, functor );
491   }
492   else
493   {
494     // signalName does not match any signal
495     connected = false;
496   }
497
498   return connected;
499 }
500
501 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
502 {
503   lastSignalConnectionCustom = "failed";
504
505   return false; // This is supposed to fail
506 }
507
508 struct CustomTestFunctor
509 {
510   CustomTestFunctor()
511   {
512     ++mTotalInstanceCount;
513     ++mCurrentInstanceCount;
514   }
515
516   CustomTestFunctor( const CustomTestFunctor& copyMe )
517   {
518     ++mTotalInstanceCount;
519     ++mCurrentInstanceCount;
520   }
521
522   ~CustomTestFunctor()
523   {
524     --mCurrentInstanceCount;
525   }
526
527   void operator()()
528   {
529     ++mCallbackCount;
530   }
531
532   static int mTotalInstanceCount;
533   static int mCurrentInstanceCount;
534   static int mCallbackCount;
535 };
536
537 int CustomTestFunctor::mTotalInstanceCount = 0;
538 int CustomTestFunctor::mCurrentInstanceCount = 0;
539 int CustomTestFunctor::mCallbackCount = 0;
540
541 static void ResetFunctorCounts()
542 {
543   CustomTestFunctor::mTotalInstanceCount   = 0;
544   CustomTestFunctor::mCurrentInstanceCount = 0;
545   CustomTestFunctor::mCallbackCount        = 0;
546 }
547
548 static std::string lastActionCustom;
549 bool DoActionCustom(BaseObject* object, const std::string& actionName, const Property::Map& /*attributes*/)
550 {
551   lastActionCustom = actionName;
552   return true;
553 }
554
555 // Custom type registration
556 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
557
558 // Custom signals
559 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
560 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
561 static const int TEST_SIGNAL_COUNT = 2;
562
563 // Custom actions
564 static TypeAction customAction1( customType1, "act1", DoActionCustom);
565 static const int TEST_ACTION_COUNT = 1;
566
567 class TestConnectionTracker : public ConnectionTracker
568 {
569 public:
570
571   TestConnectionTracker()
572   {
573   }
574 };
575
576 BaseHandle CreateNamedActorType()
577 {
578   Actor actor = Actor::New();
579   actor.SetName( "NamedActor" );
580   return actor;
581 }
582
583 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
584 PropertyRegistration namedActorPropertyOne( namedActorType, "propName",  PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
585
586 } // Anonymous namespace
587
588 // Note: No negative test case for UtcDaliTypeRegistryGet can be implemented.
589 int UtcDaliTypeRegistryGetP(void)
590 {
591   TestApplication application;
592
593   TypeRegistry registry = TypeRegistry::Get();
594   DALI_TEST_CHECK( registry );
595
596   END_TEST;
597 }
598
599 // Note: No negative test case for UtcDaliTypeRegistryConstructor can be implemented.
600 int UtcDaliTypeRegistryConstructorP(void)
601 {
602   TestApplication application;
603
604   TypeRegistry registry;
605   DALI_TEST_CHECK( !registry );
606   END_TEST;
607 }
608
609 // Note: No negative test case for UtcDaliTypeRegistryCopyConstructor can be implemented.
610 int UtcDaliTypeRegistryCopyConstructorP(void)
611 {
612   TestApplication application;
613
614   TypeRegistry registry = TypeRegistry::Get();
615   DALI_TEST_CHECK( registry );
616
617   TypeRegistry copy( registry );
618   DALI_TEST_CHECK( copy );
619
620   DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
621
622   END_TEST;
623 }
624
625 // Note: No negative test case for UtcDaliTypeRegistryAssignmentOperator can be implemented.
626 int UtcDaliTypeRegistryAssignmentOperatorP(void)
627 {
628   TestApplication application;
629
630   TypeRegistry registry = TypeRegistry::Get();
631   DALI_TEST_CHECK( registry );
632
633   TypeRegistry copy = registry;
634   DALI_TEST_CHECK( copy );
635   DALI_TEST_CHECK( registry == copy );
636
637   DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
638
639   END_TEST;
640 }
641
642 int UtcDaliTypeRegistryAssignP(void)
643 {
644   TestApplication application;
645
646   TypeRegistry registry = TypeRegistry::Get();
647   TypeRegistry registry2;
648   registry2 = registry;
649   DALI_TEST_CHECK( registry2 );
650
651   DALI_TEST_CHECK( registry2.GetTypeInfo( "Actor" ).GetName() == registry2.GetTypeInfo( "Actor" ).GetName() );
652
653   END_TEST;
654 }
655
656 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameP(void)
657 {
658   TestApplication application;
659
660   TypeRegistry registry = TypeRegistry::Get();
661
662   TypeInfo type;
663
664   // camera actor
665   type = registry.GetTypeInfo( "CameraActor" );
666   DALI_TEST_CHECK( type );
667   CameraActor ca = CameraActor::DownCast(type.CreateInstance());
668   DALI_TEST_CHECK( ca );
669   Stage::GetCurrent().Add( ca );
670   application.Render();
671
672   // animations
673   type = registry.GetTypeInfo( "Animation" );
674   DALI_TEST_CHECK( type );
675   Animation an = Animation::DownCast(type.CreateInstance());
676   DALI_TEST_CHECK( an );
677   an.Play();
678   application.Render();
679
680   END_TEST;
681 }
682
683 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameN(void)
684 {
685   TestApplication application;
686
687   TypeRegistry registry = TypeRegistry::Get();
688
689   TypeInfo type;
690
691   type = registry.GetTypeInfo( "MyDummyActor" );
692   DALI_TEST_CHECK( !type );
693
694   END_TEST;
695 }
696
697 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdP(void)
698 {
699   TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "CameraActor" );
700   TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::CameraActor) );
701
702   DALI_TEST_CHECK( named_type );
703   DALI_TEST_CHECK( typeinfo_type );
704
705   // Check named and typeid are equivalent
706   DALI_TEST_CHECK( named_type == typeinfo_type );
707
708   DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
709   DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
710
711   END_TEST;
712 }
713
714 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdN(void)
715 {
716   TestApplication application;
717   TypeRegistry typeRegistry = TypeRegistry::Get();
718
719   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(Vector2) );
720   DALI_TEST_CHECK( !typeInfo );
721
722   END_TEST;
723 }
724
725 int UtcDaliTypeRegistryGetTypeNameCountP(void)
726 {
727   TestApplication application;
728   TypeRegistry typeRegistry = TypeRegistry::Get();
729   TypeInfo type;
730
731   for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
732   {
733     type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
734     DALI_TEST_CHECK( type );
735   }
736
737   END_TEST;
738 }
739
740
741 int UtcDaliTypeRegistryGetTypeNamesP(void)
742 {
743   TestApplication application;
744   TypeRegistry typeRegistry = TypeRegistry::Get();
745   TypeInfo type;
746
747   for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
748   {
749     type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
750     DALI_TEST_CHECK( type );
751   }
752
753   END_TEST;
754 }
755
756
757 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
758 int UtcDaliTypeRegistryTypeRegistrationNotCallingCreateOnInitP(void)
759 {
760   ResetFunctorCounts();
761
762   TestApplication application;
763
764   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
765   DALI_TEST_CHECK( type );
766
767   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
768   DALI_TEST_CHECK( baseType );
769
770   BaseHandle handle = type.CreateInstance();
771   DALI_TEST_CHECK( handle );
772
773   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
774   DALI_TEST_CHECK( customHandle );
775
776   DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
777
778   DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
779
780   {
781     TestConnectionTracker tracker;
782
783     bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
784     DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
785     DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
786     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
787     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
788
789     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
790     customHandle.GetCustomSignal().Emit();
791     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
792     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
793     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
794   }
795   // tracker should automatically disconnect here
796   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
797   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
798
799   // Test that functor is disconnected
800   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
801   customHandle.GetCustomSignal().Emit();
802   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
803   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
804   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
805
806   Property::Map attributes;
807   handle.DoAction("act1", attributes);
808   DALI_TEST_CHECK( lastActionCustom == "act1" );
809   END_TEST;
810 }
811
812 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
813 int UtcDaliTypeRegistryTypeRegistrationCallingCreateOnInitP(void)
814 {
815   TestApplication application;
816
817   DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
818
819   DALI_TEST_CHECK( true == CreateCustomInitCalled );
820   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
821   DALI_TEST_CHECK( type );
822   END_TEST;
823 }
824
825 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
826 int UtcDaliTypeRegistryTypeRegistrationForNamedTypeP(void)
827 {
828   TestApplication application;
829
830   // Create Named Actor Type
831   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyNamedActor" );
832   DALI_TEST_CHECK( type );
833
834   BaseHandle namedHandle = type.CreateInstance();
835   DALI_TEST_CHECK( namedHandle );
836   Actor namedActor( Actor::DownCast( namedHandle ) );
837   DALI_TEST_CHECK( namedActor );
838
839   DALI_TEST_CHECK( namedActor.GetName() == "NamedActor" );
840   DALI_TEST_CHECK( type.GetName() == "MyNamedActor" );
841   DALI_TEST_CHECK( type.GetBaseName() == "Actor" );
842
843   END_TEST;
844 }
845
846 // Note: No negative test case for UtcDaliTypeRegistryRegisteredName can be implemented.
847 int UtcDaliTypeRegistryRegisteredNameP(void)
848 {
849   TestApplication application;
850
851   DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
852
853   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
854   DALI_TEST_CHECK( baseType );
855
856   BaseHandle handle = baseType.CreateInstance();
857
858   DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
859   TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
860   DALI_TEST_CHECK( type );
861   END_TEST;
862 }
863
864 int UtcDaliTypeRegistrySignalConnectorTypeP(void)
865 {
866   ResetFunctorCounts();
867
868   TestApplication application;
869
870   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
871   DALI_TEST_CHECK( type );
872
873   BaseHandle handle = type.CreateInstance();
874   DALI_TEST_CHECK( handle );
875
876   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
877   DALI_TEST_CHECK( customHandle );
878
879   {
880     TestConnectionTracker tracker;
881
882     bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
883     DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
884     DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
885     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
886     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
887
888     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
889     customHandle.GetCustomSignal().Emit();
890     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
891     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
892     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
893   }
894   // tracker should automatically disconnect here
895   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
896   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
897
898   // Test that functor is disconnected
899   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
900   customHandle.GetCustomSignal().Emit();
901   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
902   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
903   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
904
905   END_TEST;
906 }
907
908 int UtcDaliTypeRegistrySignalConnectorTypeN(void)
909 {
910   // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
911
912   ResetFunctorCounts();
913
914   TestApplication application;
915
916   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
917   DALI_TEST_CHECK( type );
918
919   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
920   DALI_TEST_CHECK( baseType );
921
922   BaseHandle handle = type.CreateInstance();
923   DALI_TEST_CHECK( handle );
924
925   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
926   DALI_TEST_CHECK( customHandle );
927
928   DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
929
930   DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
931
932   {
933     TestConnectionTracker tracker;
934
935     bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
936     DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
937     DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
938     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
939     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
940
941     // Should be a NOOP
942     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
943     customHandle.GetCustomSignal().Emit();
944     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
945   }
946   // tracker should have nothing to disconnect here
947
948   // Should be a NOOP
949   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
950   customHandle.GetCustomSignal().Emit();
951   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
952   END_TEST;
953 }
954
955 int UtcDaliTypeRegistryTypeActionP(void)
956 {
957   ResetFunctorCounts();
958
959   TestApplication application;
960
961   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
962   DALI_TEST_CHECK( type );
963
964   BaseHandle handle = type.CreateInstance();
965   DALI_TEST_CHECK( handle );
966
967   Property::Map attributes;
968   DALI_TEST_CHECK( handle.DoAction("act1", attributes) );
969   DALI_TEST_CHECK( lastActionCustom == "act1" );
970
971   END_TEST;
972 }
973
974 int UtcDaliTypeRegistryTypeActionN(void)
975 {
976   ResetFunctorCounts();
977
978   TestApplication application;
979
980   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
981   DALI_TEST_CHECK( type );
982
983   BaseHandle handle = type.CreateInstance();
984   DALI_TEST_CHECK( handle );
985
986   Property::Map attributes;
987   DALI_TEST_CHECK( !handle.DoAction( "unknownAction",  attributes ) );
988
989   END_TEST;
990 }
991
992 int UtcDaliTypeRegistryPropertyRegistrationP(void)
993 {
994   TestApplication application;
995   TypeRegistry typeRegistry = TypeRegistry::Get();
996
997   // Check property count before property registration
998   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
999   DALI_TEST_CHECK( typeInfo );
1000   BaseHandle handle = typeInfo.CreateInstance();
1001   DALI_TEST_CHECK( handle );
1002   Actor customActor = Actor::DownCast( handle );
1003   DALI_TEST_CHECK( customActor );
1004   unsigned int initialPropertyCount( customActor.GetPropertyCount() );
1005
1006   std::string propertyName( "prop1" );
1007   int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
1008   Property::Type propertyType( Property::BOOLEAN );
1009   PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
1010
1011   // Check property count after registration
1012   unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
1013   DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
1014
1015   // Add custom property and check property count
1016   customActor.RegisterProperty( "customProp1",   true );
1017   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1018   DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
1019
1020   // Set the property, ensure SetProperty called
1021   DALI_TEST_CHECK( !setPropertyCalled );
1022   customActor.SetProperty( propertyIndex, false );
1023   DALI_TEST_CHECK( setPropertyCalled );
1024
1025   // Get the property, ensure GetProperty called
1026   DALI_TEST_CHECK( !getPropertyCalled );
1027   (void)customActor.GetProperty< bool >( propertyIndex );
1028   DALI_TEST_CHECK( getPropertyCalled );
1029
1030   // Check the property name
1031   DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
1032   DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
1033
1034   // Check the property index
1035   DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
1036
1037   // Check the property type
1038   DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
1039
1040   // Check property count of type-info is 1
1041   Property::IndexContainer indices;
1042   typeInfo.GetPropertyIndices( indices );
1043
1044   size_t typePropertyCount = typeInfo.GetPropertyCount();
1045   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1046   DALI_TEST_EQUALS( indices.Size(), typePropertyCount, TEST_LOCATION );
1047
1048   // Ensure indices returned from actor and customActor differ by two
1049   Actor actor = Actor::New();
1050   actor.GetPropertyIndices( indices );
1051   unsigned int actorIndices = indices.Size();
1052   customActor.GetPropertyIndices( indices );
1053   unsigned int customActorIndices = indices.Size();
1054   DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1055   END_TEST;
1056 }
1057
1058 int UtcDaliTypeRegistryPropertyRegistrationN(void)
1059 {
1060   TestApplication application;
1061   TypeRegistry typeRegistry = TypeRegistry::Get();
1062
1063   // Attempt to register a property type out-of-bounds index (less than)
1064   try
1065   {
1066     PropertyRegistration property1( customType1, "propName",  PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1067     tet_result( TET_FAIL );
1068   }
1069   catch ( DaliException& e )
1070   {
1071     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1072   }
1073
1074   // Attempt to register a property type out-of-bounds index (greater than)
1075   try
1076   {
1077     PropertyRegistration property1( customType1, "propName",  PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1078     tet_result( TET_FAIL );
1079   }
1080   catch ( DaliException& e )
1081   {
1082     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1083   }
1084
1085   END_TEST;
1086 }
1087
1088 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1089 {
1090   TestApplication application;
1091   TypeRegistry typeRegistry = TypeRegistry::Get();
1092
1093   // Check property count before property registration
1094   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1095   DALI_TEST_CHECK( typeInfo );
1096   BaseHandle handle = typeInfo.CreateInstance();
1097   DALI_TEST_CHECK( handle );
1098   Actor customActor = Actor::DownCast( handle );
1099   DALI_TEST_CHECK( customActor );
1100   Stage::GetCurrent().Add(customActor);
1101
1102   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1103
1104   // Register animatable property
1105   std::string animatablePropertyName( "animatableProp1" );
1106   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1107   Property::Type animatablePropertyType( Property::FLOAT );
1108   AnimatablePropertyRegistration animatableProperty( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1109
1110   // Check property count after registration
1111   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1112
1113   // Set the animatable property value
1114   customActor.SetProperty( animatablePropertyIndex, 25.0f );
1115
1116   // Render and notify
1117   application.SendNotification();
1118   application.Render();
1119
1120   // Check the animatable property value
1121   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.f, TEST_LOCATION );
1122
1123   // Check the animatable property name
1124   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1125
1126   // Check the animatable property index
1127   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1128
1129   // Check the animatable property type
1130   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1131
1132   // Check property count of type-info is 1
1133   Property::IndexContainer indices;
1134   typeInfo.GetPropertyIndices( indices );
1135   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1136
1137   // Ensure indices returned from actor and customActor differ by one
1138   Actor actor = Actor::New();
1139   actor.GetPropertyIndices( indices );
1140   unsigned int actorIndices = indices.Size();
1141   customActor.GetPropertyIndices( indices );
1142   unsigned int customActorIndices = indices.Size();
1143   DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1144
1145   // check that the property is animatable
1146   Animation animation = Animation::New(0.2f);
1147   animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 15.f, AlphaFunction::LINEAR );
1148   animation.Play();
1149   // Render and notify, animation play for 0.05 seconds
1150   application.SendNotification();
1151   application.Render(50);
1152   DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
1153   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 22.5f, TEST_LOCATION );
1154   // Render and notify, animation play for another 0.1 seconds
1155   application.SendNotification();
1156   application.Render(100);
1157   DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
1158   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
1159
1160   END_TEST;
1161 }
1162
1163 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1164 {
1165   TestApplication application;
1166   TypeRegistry typeRegistry = TypeRegistry::Get();
1167
1168   // Attempt to register an animatable property type out-of-bounds index (less than)
1169   try
1170   {
1171     AnimatablePropertyRegistration property1( customType1, "animPropName",   ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1172     tet_result( TET_FAIL );
1173   }
1174   catch ( DaliException& e )
1175   {
1176     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1177   }
1178
1179   // Attempt to register an animatable property type out-of-bounds index (greater than)
1180   try
1181   {
1182     AnimatablePropertyRegistration property1( customType1, "animPropName",   ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1183     tet_result( TET_FAIL );
1184   }
1185   catch ( DaliException& e )
1186   {
1187     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1188   }
1189
1190   END_TEST;
1191 }
1192
1193 int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultP(void)
1194 {
1195   TestApplication application;
1196   TypeRegistry typeRegistry = TypeRegistry::Get();
1197
1198   // Check property count before property registration
1199   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1200   DALI_TEST_CHECK( typeInfo );
1201   BaseHandle handle = typeInfo.CreateInstance();
1202   DALI_TEST_CHECK( handle );
1203   Actor customActor = Actor::DownCast( handle );
1204   DALI_TEST_CHECK( customActor );
1205   Stage::GetCurrent().Add(customActor);
1206
1207   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1208
1209   // Register animatable property
1210   std::string animatablePropertyName( "animatableProp1" );
1211   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1212   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, 10.f );
1213
1214   // Check property count after registration
1215   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1216
1217   // Render and notify
1218   application.SendNotification();
1219   application.Render();
1220
1221   // Check the animatable property value
1222   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 10.f, TEST_LOCATION );
1223
1224   // Check the animatable property name
1225   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1226
1227   // Check the animatable property index
1228   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1229
1230   // Check the animatable property type
1231   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), Property::FLOAT, TEST_LOCATION );
1232
1233   // Check property count of type-info is 1
1234   Property::IndexContainer indices;
1235   typeInfo.GetPropertyIndices( indices );
1236   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1237
1238   // Ensure indices returned from actor and customActor differ by one
1239   Actor actor = Actor::New();
1240   actor.GetPropertyIndices( indices );
1241   unsigned int actorIndices = indices.Size();
1242   customActor.GetPropertyIndices( indices );
1243   unsigned int customActorIndices = indices.Size();
1244   DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1245
1246   // check that the property is animatable
1247   Animation animation = Animation::New(0.2f);
1248   animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 20.f, AlphaFunction::LINEAR );
1249   animation.Play();
1250   // Render and notify, animation play for 0.05 seconds
1251   application.SendNotification();
1252   application.Render(50);
1253   DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
1254   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 12.5f, TEST_LOCATION );
1255   // Render and notify, animation play for another 0.1 seconds
1256   application.SendNotification();
1257   application.Render(100);
1258   DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
1259   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
1260
1261   END_TEST;
1262 }
1263
1264 int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultN(void)
1265 {
1266   TestApplication application;
1267   TypeRegistry typeRegistry = TypeRegistry::Get();
1268
1269   // Attempt to register an animatable property type out-of-bounds index (less than)
1270   try
1271   {
1272     AnimatablePropertyRegistration property1( customType1, "animPropName",   ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, false );
1273     tet_result( TET_FAIL );
1274   }
1275   catch ( DaliException& e )
1276   {
1277     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1278   }
1279
1280   // Attempt to register an animatable property type out-of-bounds index (greater than)
1281   try
1282   {
1283     AnimatablePropertyRegistration property1( customType1, "animPropName",   ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, true );
1284     tet_result( TET_FAIL );
1285   }
1286   catch ( DaliException& e )
1287   {
1288     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1289   }
1290
1291   END_TEST;
1292 }
1293
1294 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1295 {
1296   TestApplication application;
1297   TypeRegistry typeRegistry = TypeRegistry::Get();
1298
1299   // Check property count before property registration
1300   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1301   DALI_TEST_CHECK( typeInfo );
1302   BaseHandle handle = typeInfo.CreateInstance();
1303   DALI_TEST_CHECK( handle );
1304   Actor customActor = Actor::DownCast( handle );
1305   DALI_TEST_CHECK( customActor );
1306
1307   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1308
1309   // Register animatable property
1310   std::string animatablePropertyName( "animatableProp1" );
1311   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1312   Property::Type animatablePropertyType( Property::VECTOR2 );
1313   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1314
1315   // Check property count after registration
1316   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1317
1318   // Set the animatable property value
1319   customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1320
1321   // Render and notify
1322   application.SendNotification();
1323   application.Render();
1324
1325   // Check the animatable property value
1326   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1327
1328   // Check the animatable property name
1329   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1330
1331   // Check the animatable property index
1332   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1333
1334   // Check the animatable property type
1335   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1336
1337   // Check property count of type-info is 1
1338   Property::IndexContainer indices;
1339   typeInfo.GetPropertyIndices( indices );
1340   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1341
1342   // Register animatable property components
1343   std::string animatablePropertyComponentName1( "animatableProp1X" );
1344   int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1345   AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1346
1347   std::string animatablePropertyComponentName2( "animatableProp1Y" );
1348   int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1349   AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1350
1351   // Check property count after registration
1352   DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1353
1354   // Check the animatable property component value
1355   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1356   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1357
1358   // Set the animatable property component value
1359   customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1360
1361   // Render and notify
1362   application.SendNotification();
1363   application.Render();
1364
1365   // Check the animatable property value
1366   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1367   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1368   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1369
1370   // Set the animatable property component value
1371   customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1372
1373   // Render and notify
1374   application.SendNotification();
1375   application.Render();
1376
1377   // Check the animatable property value
1378   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1379   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1380   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1381
1382   // Ensure indices returned from actor and customActor differ by three
1383   Actor actor = Actor::New();
1384   actor.GetPropertyIndices( indices );
1385   unsigned int actorIndices = indices.Size();
1386   customActor.GetPropertyIndices( indices );
1387   unsigned int customActorIndices = indices.Size();
1388   DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1389
1390   END_TEST;
1391 }
1392
1393 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1394 {
1395   TestApplication application;
1396   TypeRegistry typeRegistry = TypeRegistry::Get();
1397
1398   // Register animatable property with the type of Vector2
1399   int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1400   AnimatablePropertyRegistration animatableProperty1( customType1, "animatableProp1",   animatablePropertyIndex1, Property::VECTOR2 );
1401
1402   // Attempt to register an animatable property component out-of-bounds index (less than)
1403   try
1404   {
1405     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X",    ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1406     tet_result( TET_FAIL );
1407   }
1408   catch ( DaliException& e )
1409   {
1410     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1411   }
1412
1413   // Attempt to register an animatable property component out-of-bounds index (greater than)
1414   try
1415   {
1416     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X",    ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1417     tet_result( TET_FAIL );
1418   }
1419   catch ( DaliException& e )
1420   {
1421     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1422   }
1423
1424   // Register an animatable property component
1425   AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X",    ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1426
1427   // Attempt to register another animatable property component with the same component index
1428   try
1429   {
1430     AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatableProp1Y",    ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1431     tet_result( TET_FAIL );
1432   }
1433   catch ( DaliException& e )
1434   {
1435     DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1436   }
1437
1438   // Register animatable property with the type of boolean
1439   int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1440   AnimatablePropertyRegistration animatableProperty2( customType1, "animatableProp2",   animatablePropertyIndex2, Property::BOOLEAN );
1441
1442   // Attempt to register an animatable property component for the above property with boolean type
1443   try
1444   {
1445     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp2X",    animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1446     tet_result( TET_FAIL );
1447   }
1448   catch ( DaliException& e )
1449   {
1450     DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1451   }
1452
1453   END_TEST;
1454 }
1455
1456 int UtcDaliTypeRegistryChildPropertyRegistrationP(void)
1457 {
1458   TestApplication application;
1459   TypeRegistry typeRegistry = TypeRegistry::Get();
1460
1461   // Check property count before property registration
1462   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1463   DALI_TEST_CHECK( typeInfo );
1464   BaseHandle handle = typeInfo.CreateInstance();
1465   DALI_TEST_CHECK( handle );
1466   Actor customActor = Actor::DownCast( handle );
1467   DALI_TEST_CHECK( customActor );
1468   unsigned int initialPropertyCount( customActor.GetPropertyCount() );
1469
1470   // Register child properties to the parent
1471   std::string propertyName( "childProp1" );
1472   int propertyIndex( CHILD_PROPERTY_REGISTRATION_START_INDEX );
1473   Property::Type propertyType( Property::BOOLEAN );
1474   ChildPropertyRegistration childProperty1( customType1, propertyName, propertyIndex, propertyType );
1475
1476   std::string propertyName2( "childProp2" );
1477   int propertyIndex2( CHILD_PROPERTY_REGISTRATION_START_INDEX + 1 );
1478   Property::Type propertyType2( Property::INTEGER );
1479   ChildPropertyRegistration childProperty2( customType1, propertyName2, propertyIndex2, propertyType2 );
1480
1481   std::string propertyName3( "childProp3" );
1482   int propertyIndex3( CHILD_PROPERTY_REGISTRATION_START_INDEX + 2 );
1483   Property::Type propertyType3( Property::FLOAT );
1484   ChildPropertyRegistration childProperty3( customType1, propertyName3, propertyIndex3, propertyType3 );
1485
1486   std::string propertyName4( "childProp4" );
1487   int propertyIndex4( CHILD_PROPERTY_REGISTRATION_START_INDEX + 3 );
1488   Property::Type propertyType4( Property::INTEGER );
1489   ChildPropertyRegistration childProperty4( customType1, propertyName4, propertyIndex4, propertyType4 );
1490
1491   // Check property count are not changed because the child properties will not be created for the parent
1492   DALI_TEST_EQUALS( initialPropertyCount, customActor.GetPropertyCount(), TEST_LOCATION );
1493
1494   // Create a child actor
1495   Actor childActor = Actor::New();
1496   DALI_TEST_CHECK( childActor );
1497   unsigned int initialChildActorPropertyCount( childActor.GetPropertyCount() );
1498
1499   // The type of child properties should be Property::None as the child hasn't registered any child property yet.
1500   DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex ), Property::NONE, TEST_LOCATION );
1501   DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex2 ), Property::NONE, TEST_LOCATION );
1502   DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex3 ), Property::NONE, TEST_LOCATION );
1503   DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex4 ), Property::NONE, TEST_LOCATION );
1504
1505   // Set the value for the first child property when the child actor doesn't have a parent yet
1506   childActor.SetProperty(propertyIndex, true);
1507
1508   // Check that the first child property is dynamically created
1509   DALI_TEST_EQUALS( initialChildActorPropertyCount + 1u, childActor.GetPropertyCount(), TEST_LOCATION );
1510
1511   // Check the first child property value
1512   DALI_TEST_EQUALS( childActor.GetProperty< bool >( propertyIndex ), true, TEST_LOCATION );
1513
1514   // Check the first child property type
1515   DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
1516
1517   // Check that the first child property have no name, as it doesn't have a parent yet.
1518   DALI_TEST_EQUALS( childActor.GetPropertyName( propertyIndex ), "", TEST_LOCATION );
1519
1520   // Check that the first property can't be accessed through its name, as it doesn't have a parent yet.
1521   DALI_TEST_EQUALS( childActor.GetPropertyIndex( propertyName ), Property::INVALID_INDEX, TEST_LOCATION );
1522
1523   // Create a custom property for the child with the same name as the second child property registered to the parent
1524   Property::Index customPropertyIndex = childActor.RegisterProperty(propertyName2, 100, Property::READ_WRITE);
1525
1526   // Check that the custom property is created
1527   DALI_TEST_EQUALS( initialChildActorPropertyCount + 2u, childActor.GetPropertyCount(), TEST_LOCATION );
1528
1529   // Check the property value
1530   DALI_TEST_EQUALS( childActor.GetProperty< int >( customPropertyIndex ), 100, TEST_LOCATION );
1531
1532   // Check the property index
1533   DALI_TEST_EQUALS( childActor.GetPropertyIndex( propertyName2 ), customPropertyIndex, TEST_LOCATION );
1534
1535   // Check the property type
1536   DALI_TEST_EQUALS( childActor.GetPropertyType( customPropertyIndex ), propertyType2, TEST_LOCATION );
1537
1538   // Check the property name
1539   DALI_TEST_EQUALS( childActor.GetPropertyName( customPropertyIndex ), propertyName2, TEST_LOCATION );
1540
1541   // Now add the child actor to the parent
1542   customActor.Add( childActor );
1543
1544   // Check that the first child property now has the correct name as previously registered to the parent
1545   DALI_TEST_EQUALS( childActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
1546
1547   // Check that the child property index for the first child property can now be retrieved through its child property name
1548   DALI_TEST_EQUALS( childActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
1549
1550   // Check that the second child property now has the correct index as previously registered to the parent
1551   DALI_TEST_EQUALS( childActor.GetPropertyName( propertyIndex2 ), propertyName2, TEST_LOCATION );
1552
1553   // Check that the second child property can be accessed through both its custom property index and its child property index
1554   DALI_TEST_EQUALS( childActor.GetProperty< int >( customPropertyIndex ), 100, TEST_LOCATION );
1555   DALI_TEST_EQUALS( childActor.GetProperty< int >( propertyIndex2 ), 100, TEST_LOCATION );
1556   DALI_TEST_EQUALS( childActor.GetPropertyType( customPropertyIndex ), propertyType2, TEST_LOCATION );
1557   DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex2 ), propertyType2, TEST_LOCATION );
1558
1559   // Check that the child property index for the second child property can now be retrieved through its child property name
1560   DALI_TEST_EQUALS( childActor.GetPropertyIndex( propertyName2 ), propertyIndex2, TEST_LOCATION );
1561
1562   // Set the value for the third child property when the child actor is already added to the parent
1563   childActor.SetProperty(propertyIndex3, 0.15f);
1564
1565   // Check that the third child property is dynamically created
1566   DALI_TEST_EQUALS( initialChildActorPropertyCount + 3u, childActor.GetPropertyCount(), TEST_LOCATION );
1567
1568   // Check the third child property value
1569   DALI_TEST_EQUALS( childActor.GetProperty< float >( propertyIndex3 ), 0.15f, TEST_LOCATION );
1570
1571   // Check the third child property type
1572   DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex3 ), propertyType3, TEST_LOCATION );
1573
1574   // Check the third child property name
1575   DALI_TEST_EQUALS( childActor.GetPropertyName( propertyIndex3 ), propertyName3, TEST_LOCATION );
1576
1577   // Check the third child property index.
1578   DALI_TEST_EQUALS( childActor.GetPropertyIndex( propertyName3 ), propertyIndex3, TEST_LOCATION );
1579
1580   // Create a custom property for the child with the same name as the fourth child property registered to the parent
1581   Property::Index customPropertyIndex2 = childActor.RegisterProperty(propertyName4, 20, Property::READ_WRITE);
1582
1583   // Check that the custom property is created
1584   DALI_TEST_EQUALS( initialChildActorPropertyCount + 4u, childActor.GetPropertyCount(), TEST_LOCATION );
1585
1586   // Check the fourth child property value
1587   DALI_TEST_EQUALS( childActor.GetProperty< int >( propertyIndex4 ), 20, TEST_LOCATION );
1588   DALI_TEST_EQUALS( childActor.GetProperty< int >( customPropertyIndex2 ), 20, TEST_LOCATION );
1589
1590   // Check the fourth child property type
1591   DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex4 ), propertyType4, TEST_LOCATION );
1592   DALI_TEST_EQUALS( childActor.GetPropertyType( customPropertyIndex2 ), propertyType4, TEST_LOCATION );
1593
1594   // Check the fourth child property name
1595   DALI_TEST_EQUALS( childActor.GetPropertyName( propertyIndex4 ), propertyName4, TEST_LOCATION );
1596   DALI_TEST_EQUALS( childActor.GetPropertyName( customPropertyIndex2 ), propertyName4, TEST_LOCATION );
1597
1598   // Check the fourth child property index.
1599   DALI_TEST_EQUALS( childActor.GetPropertyIndex( propertyName4 ), propertyIndex4, TEST_LOCATION );
1600
1601   // Now create another parent actor with different child properties registered
1602   TypeInfo typeInfo2 = typeRegistry.GetTypeInfo( "MyNamedActor" );
1603   DALI_TEST_CHECK( typeInfo2 );
1604   BaseHandle handle2 = typeInfo2.CreateInstance();
1605   DALI_TEST_CHECK( handle2 );
1606   Actor customActor2 = Actor::DownCast( handle2 );
1607   DALI_TEST_CHECK( customActor2 );
1608
1609   // Register child properties to the new parent
1610   std::string newPropertyName( "newChildProp" );
1611   int newPropertyIndex( CHILD_PROPERTY_REGISTRATION_START_INDEX ); // The same index as the first child property "childProp1" in the old parent
1612   Property::Type newPropertyType( Property::VECTOR2 );
1613   ChildPropertyRegistration newChildProperty( namedActorType, newPropertyName, newPropertyIndex, newPropertyType );
1614
1615   std::string newPropertyName2( "childProp3" ); // The same name as the third child property in the old parent
1616   int newPropertyIndex2( CHILD_PROPERTY_REGISTRATION_START_INDEX + 1 ); // The same index as the second child property "childProp2" in the old parent
1617   Property::Type newPropertyType2( Property::FLOAT ); // The same type as the third child property in the old parent
1618   ChildPropertyRegistration newChildProperty2( namedActorType, newPropertyName2, newPropertyIndex2, newPropertyType2 );
1619
1620   // Now move the child actor to the new parent
1621   customActor2.Add( childActor );
1622
1623   // "childProp1" is not a valid child property supported by the new parent, so nothing changed
1624   DALI_TEST_EQUALS( childActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
1625   DALI_TEST_EQUALS( childActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
1626   DALI_TEST_EQUALS( childActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
1627
1628   // "childProp3" is a valid child property supported by the new parent
1629   // So it should get its new child property index and should just work
1630   DALI_TEST_EQUALS( childActor.GetPropertyType( newPropertyIndex2 ), newPropertyType2, TEST_LOCATION );
1631   DALI_TEST_EQUALS( childActor.GetPropertyName( newPropertyIndex2 ), newPropertyName2, TEST_LOCATION );
1632   DALI_TEST_EQUALS( childActor.GetPropertyIndex( newPropertyName2 ), newPropertyIndex2, TEST_LOCATION );
1633   DALI_TEST_EQUALS( childActor.GetProperty< float >( newPropertyIndex2 ), 0.15f, TEST_LOCATION );
1634
1635   // Now register a custom property called "newChildProp"
1636   Property::Index customPropertyIndex3 = childActor.RegisterProperty("newChildProp", Vector2( 10.0f, 10.0f ), Property::READ_WRITE);
1637
1638   // Check that the custom property is created
1639   DALI_TEST_EQUALS( initialChildActorPropertyCount + 5u, childActor.GetPropertyCount(), TEST_LOCATION );
1640
1641   // This is a valid child property registered to the new parent
1642   // So should be able to access it through both its custom property index and its registered child property index
1643   DALI_TEST_EQUALS( childActor.GetPropertyType( newPropertyIndex ), newPropertyType, TEST_LOCATION );
1644   DALI_TEST_EQUALS( childActor.GetPropertyType( customPropertyIndex3 ), newPropertyType, TEST_LOCATION );
1645   DALI_TEST_EQUALS( childActor.GetPropertyName( newPropertyIndex ), newPropertyName, TEST_LOCATION ); // This should return the new name, although the child property index remains the same
1646   DALI_TEST_EQUALS( childActor.GetPropertyName( customPropertyIndex3 ), newPropertyName, TEST_LOCATION );
1647   DALI_TEST_EQUALS( childActor.GetProperty< Vector2 >( newPropertyIndex ), Vector2( 10.0f, 10.0f ), TEST_LOCATION );
1648   DALI_TEST_EQUALS( childActor.GetProperty< Vector2 >( customPropertyIndex3 ), Vector2( 10.0f, 10.0f ), TEST_LOCATION );
1649
1650   // Should return the child property index by given its name
1651   DALI_TEST_EQUALS( childActor.GetPropertyIndex( newPropertyName ), newPropertyIndex, TEST_LOCATION );
1652
1653   END_TEST;
1654 }
1655
1656 int UtcDaliTypeRegistryChildPropertyRegistrationN(void)
1657 {
1658   TestApplication application;
1659   TypeRegistry typeRegistry = TypeRegistry::Get();
1660
1661   // Attempt to register a child property type out-of-bounds index (less than)
1662   try
1663   {
1664     ChildPropertyRegistration property1( customType1, "propName",  CHILD_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1665     tet_result( TET_FAIL );
1666   }
1667   catch ( DaliException& e )
1668   {
1669     DALI_TEST_ASSERT( e, "( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1670   }
1671
1672   // Attempt to register a child property type out-of-bounds index (greater than)
1673   try
1674   {
1675     ChildPropertyRegistration property1( customType1, "propName",  CHILD_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1676     tet_result( TET_FAIL );
1677   }
1678   catch ( DaliException& e )
1679   {
1680     DALI_TEST_ASSERT( e, "( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1681   }
1682
1683   END_TEST;
1684 }
1685
1686
1687 /*******************************************************************************
1688  *
1689  * Action through the base handle
1690  *
1691  ******************************************************************************/
1692 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1693 {
1694   TestApplication application;
1695
1696   TypeInfo type;
1697
1698   type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1699   DALI_TEST_CHECK( type );
1700
1701   BaseHandle hdl = type.CreateInstance();
1702   DALI_TEST_CHECK( hdl );
1703
1704   Actor a = Actor::DownCast(hdl);
1705   DALI_TEST_CHECK( a );
1706
1707   a.SetVisible(false);
1708
1709   application.SendNotification();
1710   application.Render(0);
1711   DALI_TEST_CHECK(!a.IsVisible());
1712
1713   Property::Map attributes;
1714
1715   DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1716
1717   application.SendNotification();
1718   application.Render(0);
1719   DALI_TEST_CHECK(a.IsVisible());
1720
1721   DALI_TEST_CHECK(!hdl.DoAction("unknownAction",  attributes));
1722   END_TEST;
1723 }
1724
1725 int UtcDaliPropertyRegistrationFunctions(void)
1726 {
1727   TestApplication application;
1728   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1729
1730   // Attempt to register a property without a setter
1731   try
1732   {
1733     PropertyRegistration property1( customType1, "propName",  propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1734     tet_result( TET_PASS );
1735   }
1736   catch ( DaliException& e )
1737   {
1738     tet_result( TET_FAIL );
1739   }
1740
1741   // Attempt to register a property without a getter
1742   try
1743   {
1744     PropertyRegistration property1( customType1, "propName",  propertyIndex++, Property::BOOLEAN, NULL, NULL );
1745     tet_result( TET_FAIL );
1746   }
1747   catch ( DaliException& e )
1748   {
1749     DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1750   }
1751   END_TEST;
1752 }
1753
1754 int UtcDaliPropertyRegistrationAddSameIndex(void)
1755 {
1756   TestApplication application;
1757   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1758
1759   // Add one property with a valid property index
1760   PropertyRegistration property1( customType1, "propName",  propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1761
1762   // Attempt to add another property with the same index
1763   try
1764   {
1765     PropertyRegistration property2( customType1, "propName2",   propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1766   }
1767   catch ( DaliException& e )
1768   {
1769     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1770   }
1771
1772   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1773
1774   // Add one property with a valid property index
1775   AnimatablePropertyRegistration property3( customType1, "animPropName",   animatablePropertyIndex, Property::BOOLEAN );
1776
1777   // Attempt to add another property with the same index
1778   try
1779   {
1780     AnimatablePropertyRegistration property4( customType1, "animPropName2",    animatablePropertyIndex, Property::BOOLEAN );
1781   }
1782   catch ( DaliException& e )
1783   {
1784     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1785   }
1786   END_TEST;
1787 }
1788
1789 int UtcDaliPropertyRegistrationPropertyWritable(void)
1790 {
1791   TestApplication application;
1792   int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1793   int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1794
1795   // Add two properties, one with SetProperty, one without
1796   PropertyRegistration property1( customType1, "propNameReadwrite",   propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1797   PropertyRegistration property2( customType1, "propNameReadonly",    propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1798
1799   // Create custom-actor
1800   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1801   DALI_TEST_CHECK( typeInfo );
1802   BaseHandle handle = typeInfo.CreateInstance();
1803   DALI_TEST_CHECK( handle );
1804   Actor customActor = Actor::DownCast( handle );
1805   DALI_TEST_CHECK( customActor );
1806
1807   // Check whether properties are writable
1808   DALI_TEST_CHECK(   customActor.IsPropertyWritable( propertyIndex1 ) );
1809   DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1810   END_TEST;
1811 }
1812
1813 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1814 {
1815   TestApplication application;
1816   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1817   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1818
1819   // These properties are not animatable
1820   PropertyRegistration property1( customType1, "propName",  propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1821
1822   // These properties are animatable
1823   AnimatablePropertyRegistration property2( customType1, "animPropName",   animatablePropertyIndex, Property::BOOLEAN );
1824
1825   // Create custom-actor
1826   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1827   DALI_TEST_CHECK( typeInfo );
1828   BaseHandle handle = typeInfo.CreateInstance();
1829   DALI_TEST_CHECK( handle );
1830   Actor customActor = Actor::DownCast( handle );
1831   DALI_TEST_CHECK( customActor );
1832
1833   // Check if animatable
1834   DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1835   DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1836
1837   // Create another instance of custom-actor
1838   BaseHandle handle2 = typeInfo.CreateInstance();
1839   DALI_TEST_CHECK( handle2 );
1840   Actor customActor2 = Actor::DownCast( handle2 );
1841   DALI_TEST_CHECK( customActor2 );
1842
1843   // Check if animatable
1844   DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1845   DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1846   END_TEST;
1847 }
1848
1849 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1850 {
1851   TestApplication application;
1852   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1853   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1854
1855   // Create custom-actor
1856   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1857   DALI_TEST_CHECK( typeInfo );
1858   BaseHandle handle = typeInfo.CreateInstance();
1859   DALI_TEST_CHECK( handle );
1860   Actor customActor = Actor::DownCast( handle );
1861   DALI_TEST_CHECK( customActor );
1862
1863   // Try to set an index that hasn't been added
1864   try
1865   {
1866     customActor.SetProperty( propertyIndex, true );
1867     tet_result( TET_FAIL );
1868   }
1869   catch ( DaliException& e )
1870   {
1871     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1872   }
1873
1874   try
1875   {
1876     customActor.SetProperty( animatablePropertyIndex, true );
1877     tet_result( TET_FAIL );
1878   }
1879   catch ( DaliException& e )
1880   {
1881     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1882   }
1883
1884   // Try to get an index that hasn't been added
1885   try
1886   {
1887     (void) customActor.GetProperty< bool >( propertyIndex );
1888     tet_result( TET_FAIL );
1889   }
1890   catch ( DaliException& e )
1891   {
1892     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1893   }
1894
1895   try
1896   {
1897     (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1898     tet_result( TET_FAIL );
1899   }
1900   catch ( DaliException& e )
1901   {
1902     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1903   }
1904   END_TEST;
1905 }
1906
1907
1908 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1909 {
1910   TestApplication application;
1911
1912   Actor actor = Actor::New();
1913   actor.SetSize(100.0f, 100.0f);
1914   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1915   Stage::GetCurrent().Add(actor);
1916
1917   // Register Type
1918   TypeInfo type;
1919   type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1920   DALI_TEST_CHECK( type );
1921   BaseHandle handle = type.CreateInstance();
1922   DALI_TEST_CHECK( handle );
1923   LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1924   DALI_TEST_CHECK( detector );
1925
1926   // Attach actor to detector
1927   SignalData data;
1928   GestureReceivedFunctor functor( data );
1929   detector.Attach(actor);
1930
1931   // Connect to signal through type
1932   handle.ConnectSignal( &application, "longPressDetected",   functor );
1933
1934   // Render and notify
1935   application.SendNotification();
1936   application.Render();
1937
1938   // Emit gesture
1939   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1940   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1941   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1942   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1943   END_TEST;
1944 }
1945
1946 int UtcDaliPanGestureDetectorTypeRegistry(void)
1947 {
1948   TestApplication application;
1949
1950   Actor actor = Actor::New();
1951   actor.SetSize(100.0f, 100.0f);
1952   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1953   Stage::GetCurrent().Add(actor);
1954
1955   // Register Type
1956   TypeInfo type;
1957   type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1958   DALI_TEST_CHECK( type );
1959   BaseHandle handle = type.CreateInstance();
1960   DALI_TEST_CHECK( handle );
1961   PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1962   DALI_TEST_CHECK( detector );
1963
1964   // Attach actor to detector
1965   SignalData data;
1966   GestureReceivedFunctor functor( data );
1967   detector.Attach(actor);
1968
1969   // Connect to signal through type
1970   handle.ConnectSignal( &application, "panDetected",  functor );
1971
1972   // Render and notify
1973   application.SendNotification();
1974   application.Render();
1975
1976   // Emit gesture
1977   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1978   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1979   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1980   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1981   END_TEST;
1982 }
1983
1984 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1985 {
1986   TestApplication application;
1987
1988   Actor actor = Actor::New();
1989   actor.SetSize(100.0f, 100.0f);
1990   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1991   Stage::GetCurrent().Add(actor);
1992
1993   // Register Type
1994   TypeInfo type;
1995   type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1996   DALI_TEST_CHECK( type );
1997   BaseHandle handle = type.CreateInstance();
1998   DALI_TEST_CHECK( handle );
1999   PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
2000   DALI_TEST_CHECK( detector );
2001
2002   // Attach actor to detector
2003   SignalData data;
2004   GestureReceivedFunctor functor( data );
2005   detector.Attach(actor);
2006
2007   // Connect to signal through type
2008   handle.ConnectSignal( &application, "pinchDetected",  functor );
2009
2010   // Render and notify
2011   application.SendNotification();
2012   application.Render();
2013
2014   // Emit gesture
2015   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
2016   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
2017   END_TEST;
2018 }
2019
2020 int UtcDaliTapGestureDetectorTypeRegistry(void)
2021 {
2022   TestApplication application;
2023
2024   Actor actor = Actor::New();
2025   actor.SetSize(100.0f, 100.0f);
2026   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2027   Stage::GetCurrent().Add(actor);
2028
2029   // Register Type
2030   TypeInfo type;
2031   type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
2032   DALI_TEST_CHECK( type );
2033   BaseHandle handle = type.CreateInstance();
2034   DALI_TEST_CHECK( handle );
2035   TapGestureDetector detector = TapGestureDetector::DownCast( handle );
2036   DALI_TEST_CHECK( detector );
2037
2038   // Attach actor to detector
2039   SignalData data;
2040   GestureReceivedFunctor functor( data );
2041   detector.Attach(actor);
2042
2043   // Connect to signal through type
2044   handle.ConnectSignal( &application, "tapDetected",  functor );
2045
2046   // Render and notify
2047   application.SendNotification();
2048   application.Render();
2049
2050   // Emit gesture
2051   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
2052   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
2053   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
2054   END_TEST;
2055 }
2056
2057 int UtcDaliTypeRegistryNamedType(void)
2058 {
2059   TestApplication application;
2060   TypeRegistry typeRegistry = TypeRegistry::Get();
2061
2062   // Create a normal actor
2063   BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
2064   DALI_TEST_CHECK( actorHandle );
2065   Actor actor( Actor::DownCast( actorHandle ) );
2066   DALI_TEST_CHECK( actor );
2067   unsigned int actorPropertyCount( actor.GetPropertyCount() );
2068
2069   // Create Named Actor Type
2070   BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
2071   DALI_TEST_CHECK( namedHandle );
2072   Actor namedActor( Actor::DownCast( namedHandle ) );
2073   DALI_TEST_CHECK( namedActor );
2074   unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
2075
2076   DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
2077   END_TEST;
2078 }
2079
2080 int UtcDaliTypeInfoGetActionNameP(void)
2081 {
2082   TestApplication application;
2083   TypeRegistry typeRegistry = TypeRegistry::Get();
2084
2085   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
2086   DALI_TEST_CHECK( typeInfo );
2087
2088   DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
2089
2090   std::string name = typeInfo.GetActionName(0);
2091
2092   DALI_TEST_EQUALS( name, "show", TEST_LOCATION );
2093
2094   END_TEST;
2095 }
2096
2097 int UtcDaliTypeInfoGetActionNameN(void)
2098 {
2099   TestApplication application;
2100   TypeRegistry typeRegistry = TypeRegistry::Get();
2101
2102   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
2103   DALI_TEST_CHECK( typeInfo );
2104
2105   DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
2106
2107   std::string name = typeInfo.GetActionName(std::numeric_limits<size_t>::max());
2108
2109   DALI_TEST_EQUALS( 0u, name.size(), TEST_LOCATION );
2110
2111   END_TEST;
2112 }
2113
2114 int UtcDaliTypeInfoGetSignalNameP(void)
2115 {
2116   TestApplication application;
2117   TypeRegistry typeRegistry = TypeRegistry::Get();
2118
2119   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
2120   DALI_TEST_CHECK( typeInfo );
2121
2122   DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
2123
2124   std::string name = typeInfo.GetSignalName(0);
2125
2126   DALI_TEST_EQUALS( name, "touched", TEST_LOCATION );
2127
2128   END_TEST;
2129 }
2130
2131 int UtcDaliTypeInfoGetSignalNameN(void)
2132 {
2133   TestApplication application;
2134   TypeRegistry typeRegistry = TypeRegistry::Get();
2135
2136   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
2137   DALI_TEST_CHECK( typeInfo );
2138
2139   DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
2140
2141   std::string name = typeInfo.GetSignalName(std::numeric_limits<size_t>::max());
2142
2143   DALI_TEST_EQUALS( 0u, name.size(), TEST_LOCATION );
2144
2145   END_TEST;
2146 }
2147
2148
2149 int UtcDaliTypeInfoGetCreatorP(void)
2150 {
2151   TestApplication application;
2152   TypeRegistry typeRegistry = TypeRegistry::Get();
2153
2154   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
2155   DALI_TEST_CHECK( typeInfo );
2156
2157   TypeInfo::CreateFunction createFn = typeInfo.GetCreator();
2158   DALI_TEST_EQUALS( createFn != NULL, true, TEST_LOCATION );
2159   if( createFn )
2160   {
2161     // try calling it:
2162     BaseHandle handle = createFn();
2163     DALI_TEST_EQUALS( (bool)handle, true, TEST_LOCATION );
2164   }
2165
2166   END_TEST;
2167 }
2168
2169 int UtcDaliTypeInfoGetCreatorN(void)
2170 {
2171   TestApplication application;
2172   TypeRegistry typeRegistry = TypeRegistry::Get();
2173
2174   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "MyTestCustomActor3" );
2175   DALI_TEST_CHECK( typeInfo );
2176
2177   TypeInfo::CreateFunction createFn = typeInfo.GetCreator();
2178   DALI_TEST_EQUALS( createFn == NULL, true, TEST_LOCATION );
2179
2180   END_TEST;
2181 }
2182
2183 int UtcDaliTypeInfoGetPropertyCountP1(void)
2184 {
2185   TestApplication application;
2186   TypeRegistry typeRegistry = TypeRegistry::Get();
2187
2188   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
2189   DALI_TEST_CHECK( typeInfo );
2190   size_t actorPropertyCount = typeInfo.GetPropertyCount();
2191
2192   DALI_TEST_EQUALS( actorPropertyCount == 0 , true, TEST_LOCATION ); // No event only props
2193   END_TEST;
2194 }
2195
2196 int UtcDaliTypeInfoGetPropertyCountP2(void)
2197 {
2198   TestApplication application;
2199   TypeRegistry typeRegistry = TypeRegistry::Get();
2200
2201   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "MyTestCustomActor2" );
2202   DALI_TEST_CHECK( typeInfo );
2203   size_t propertyCount = typeInfo.GetPropertyCount();
2204   Property::IndexContainer indices;
2205   typeInfo.GetPropertyIndices( indices );
2206
2207   DALI_TEST_EQUALS( propertyCount > 0 && propertyCount <= indices.Size(), true, TEST_LOCATION );
2208   DALI_TEST_EQUALS( propertyCount == 2, true, TEST_LOCATION );
2209
2210   END_TEST;
2211 }