Remove std::vector from public api
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TypeRegistry.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <dali/public-api/dali-core.h>
21 #include <dali-test-suite-utils.h>
22 #include <dali/integration-api/events/long-press-gesture-event.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24 #include <dali/integration-api/events/pinch-gesture-event.h>
25 #include <dali/integration-api/events/tap-gesture-event.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/integration-api/events/hover-event-integ.h>
28
29 using namespace Dali;
30
31
32 namespace
33 {
34
35 // Stores data that is populated in the callback and will be read by the Test cases
36 struct SignalData
37 {
38   SignalData()
39   : functorCalled( false ),
40     voidFunctorCalled( false ),
41     receivedGesture( Gesture::Clear ),
42     pressedActor()
43   {}
44
45   void Reset()
46   {
47     functorCalled = false;
48     voidFunctorCalled = false;
49
50     receivedGesture.numberOfTouches = 0u;
51     receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
52     receivedGesture.localPoint = Vector2(0.0f, 0.0f);
53
54     pressedActor.Reset();
55   }
56
57   bool functorCalled;
58   bool voidFunctorCalled;
59   LongPressGesture receivedGesture;
60   Actor pressedActor;
61 };
62
63 // Functor that sets the data when called
64 struct GestureReceivedFunctor
65 {
66   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
67
68   void operator()(Actor actor, LongPressGesture longPress)
69   {
70     signalData.functorCalled = true;
71     signalData.receivedGesture = longPress;
72     signalData.pressedActor = actor;
73   }
74
75   void operator()()
76   {
77     signalData.voidFunctorCalled = true;
78   }
79
80   SignalData& signalData;
81 };
82
83 // Generate a LongPressGestureEvent to send to Core
84 Integration::LongPressGestureEvent GenerateLongPress(
85     Gesture::State state,
86     unsigned int numberOfTouches,
87     Vector2 point)
88 {
89   Integration::LongPressGestureEvent longPress( state );
90
91   longPress.numberOfTouches = numberOfTouches;
92   longPress.point = point;
93
94   return longPress;
95 }
96
97 // Generate a PanGestureEvent to send to Core
98 Integration::PanGestureEvent GeneratePan(
99     Gesture::State state,
100     Vector2 previousPosition,
101     Vector2 currentPosition,
102     unsigned long timeDelta,
103     unsigned int numberOfTouches = 1,
104     unsigned int time = 1u)
105 {
106   Integration::PanGestureEvent pan(state);
107
108   pan.previousPosition = previousPosition;
109   pan.currentPosition = currentPosition;
110   pan.timeDelta = timeDelta;
111   pan.numberOfTouches = numberOfTouches;
112   pan.time = time;
113
114   return pan;
115 }
116 // Generate a PinchGestureEvent to send to Core
117 Integration::PinchGestureEvent GeneratePinch(
118     Gesture::State state,
119     float scale,
120     float speed,
121     Vector2 centerpoint)
122 {
123   Integration::PinchGestureEvent pinch(state);
124
125   pinch.scale = scale;
126   pinch.speed = speed;
127   pinch.centerPoint = centerpoint;
128
129   return pinch;
130 }
131 // Generate a TapGestureEvent to send to Core
132 Integration::TapGestureEvent GenerateTap(
133     Gesture::State state,
134     unsigned int numberOfTaps,
135     unsigned int numberOfTouches,
136     Vector2 point)
137 {
138   Integration::TapGestureEvent tap( state );
139
140   tap.numberOfTaps = numberOfTaps;
141   tap.numberOfTouches = numberOfTouches;
142   tap.point = point;
143
144   return tap;
145 }
146
147 //
148 // Create function as Init function called
149 //
150 static bool CreateCustomInitCalled = false;
151 BaseHandle CreateCustomInit(void)
152 {
153   CreateCustomInitCalled = true;
154   return BaseHandle();
155 }
156
157 static bool CreateCustomNamedInitCalled = false;
158 BaseHandle CreateCustomNamedInit(void)
159 {
160   CreateCustomNamedInitCalled = true;
161   return BaseHandle();
162 }
163
164 const std::string scriptedName("PopupStyle");
165 static TypeRegistration scriptedType( scriptedName, typeid(Dali::CustomActor), CreateCustomNamedInit );
166
167 // Property Registration
168 bool setPropertyCalled = false;
169 bool getPropertyCalled = false;
170 void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
171 {
172   setPropertyCalled = true;
173 }
174 Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex )
175 {
176   getPropertyCalled = true;
177   return Property::Value( true );
178 }
179
180
181
182 /*******************************************************************************
183  *
184  * Custom Actor
185  *
186  ******************************************************************************/
187 namespace Impl
188 {
189 struct MyTestCustomActor : public CustomActorImpl
190 {
191   typedef Signal< void ()> SignalType;
192   typedef Signal< void (float)> SignalTypeFloat;
193
194   MyTestCustomActor() : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS ) )
195   { }
196
197   virtual ~MyTestCustomActor()
198   { }
199
200   void ResetCallStack()
201   {
202   }
203
204   // From CustomActorImpl
205   virtual void OnStageConnection()
206   {
207   }
208   virtual void OnStageDisconnection()
209   {
210   }
211   virtual void OnChildAdd(Actor& child)
212   {
213   }
214   virtual void OnChildRemove(Actor& child)
215   {
216   }
217   virtual void OnSizeSet(const Vector3& targetSize)
218   {
219   }
220   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
221   {
222   }
223   virtual bool OnTouchEvent(const TouchEvent& event)
224   {
225     return true;
226   }
227   virtual bool OnHoverEvent(const HoverEvent& event)
228   {
229     return true;
230   }
231   virtual bool OnWheelEvent(const WheelEvent& event)
232   {
233     return true;
234   }
235   virtual bool OnKeyEvent(const KeyEvent& event)
236   {
237     return true;
238   }
239   virtual void OnKeyInputFocusGained()
240   {
241   }
242   virtual void OnKeyInputFocusLost()
243   {
244   }
245   virtual Vector3 GetNaturalSize()
246   {
247     return Vector3( 0.0f, 0.0f, 0.0f );
248   }
249
250   virtual float GetHeightForWidth( float width )
251   {
252     return 0.0f;
253   }
254
255   virtual float GetWidthForHeight( float height )
256   {
257     return 0.0f;
258   }
259
260   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
261   {
262   }
263
264   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
265   {
266   }
267
268   virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
269   {
270   }
271
272   virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
273   {
274     return 0.0f;
275   }
276
277   virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
278   {
279   }
280
281   virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
282   {
283     return false;
284   }
285
286 public:
287
288   SignalType mSignal;
289 };
290
291 }; // namespace Impl
292
293 class MyTestCustomActor : public CustomActor
294 {
295 public:
296
297   typedef Signal< void ()> SignalType;
298   typedef Signal< void (float)> SignalTypeFloat;
299
300   MyTestCustomActor()
301   {
302   }
303
304   static MyTestCustomActor New()
305   {
306     Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
307     return MyTestCustomActor( *p ); // takes ownership
308   }
309
310   virtual ~MyTestCustomActor()
311   {
312   }
313
314   static MyTestCustomActor DownCast( BaseHandle handle )
315   {
316     MyTestCustomActor result;
317
318     CustomActor custom = Dali::CustomActor::DownCast( handle );
319     if ( custom )
320     {
321       CustomActorImpl& customImpl = custom.GetImplementation();
322
323       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
324
325       if (impl)
326       {
327         result = MyTestCustomActor(customImpl.GetOwner());
328       }
329     }
330
331     return result;
332   }
333
334   SignalType& GetCustomSignal()
335   {
336     Dali::RefObject& obj = GetImplementation();
337     return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
338   }
339
340 private:
341
342   MyTestCustomActor(Internal::CustomActor* internal)
343   : CustomActor(internal)
344   {
345   }
346
347   MyTestCustomActor( Impl::MyTestCustomActor& impl )
348   : CustomActor( impl )
349   {
350   }
351 };
352
353
354 class MyTestCustomActor2 : public CustomActor
355 {
356 public:
357
358   MyTestCustomActor2()
359   {
360   }
361
362   static MyTestCustomActor2 New()
363   {
364     return MyTestCustomActor2(); // takes ownership
365   }
366
367   virtual ~MyTestCustomActor2()
368   {
369   }
370
371   static MyTestCustomActor2 DownCast( BaseHandle handle )
372   {
373     MyTestCustomActor2 result;
374
375     CustomActor custom = Dali::CustomActor::DownCast( handle );
376     if ( custom )
377     {
378       CustomActorImpl& customImpl = custom.GetImplementation();
379
380       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
381
382       if (impl)
383       {
384         result = MyTestCustomActor2(customImpl.GetOwner());
385       }
386     }
387
388     return result;
389   }
390
391 private:
392
393   MyTestCustomActor2(Internal::CustomActor* internal)
394   : CustomActor(internal)
395   {
396   }
397
398   MyTestCustomActor2( Impl::MyTestCustomActor& impl )
399   : CustomActor( impl )
400   {
401   }
402 };
403
404 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
405
406
407 BaseHandle CreateCustom(void)
408 {
409   return MyTestCustomActor::New();
410 }
411
412 static std::string lastSignalConnectionCustom;
413
414 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
415 {
416   lastSignalConnectionCustom = signalName;
417
418   bool connected( true );
419
420   Dali::BaseHandle handle(object);
421   MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
422
423   if( "sig1" == signalName )
424   {
425     customActor.GetCustomSignal().Connect( tracker, functor );
426   }
427   else
428   {
429     // signalName does not match any signal
430     connected = false;
431   }
432
433   return connected;
434 }
435
436 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
437 {
438   lastSignalConnectionCustom = "failed";
439
440   return false; // This is supposed to fail
441 }
442
443 struct CustomTestFunctor
444 {
445   CustomTestFunctor()
446   {
447     ++mTotalInstanceCount;
448     ++mCurrentInstanceCount;
449   }
450
451   CustomTestFunctor( const CustomTestFunctor& copyMe )
452   {
453     ++mTotalInstanceCount;
454     ++mCurrentInstanceCount;
455   }
456
457   ~CustomTestFunctor()
458   {
459     --mCurrentInstanceCount;
460   }
461
462   void operator()()
463   {
464     ++mCallbackCount;
465   }
466
467   static int mTotalInstanceCount;
468   static int mCurrentInstanceCount;
469   static int mCallbackCount;
470 };
471
472 int CustomTestFunctor::mTotalInstanceCount = 0;
473 int CustomTestFunctor::mCurrentInstanceCount = 0;
474 int CustomTestFunctor::mCallbackCount = 0;
475
476 static void ResetFunctorCounts()
477 {
478   CustomTestFunctor::mTotalInstanceCount   = 0;
479   CustomTestFunctor::mCurrentInstanceCount = 0;
480   CustomTestFunctor::mCallbackCount        = 0;
481 }
482
483 static std::string lastActionCustom;
484 bool DoActionCustom(BaseObject* object, const std::string& actionName, const Property::Map& /*attributes*/)
485 {
486   lastActionCustom = actionName;
487   return true;
488 }
489
490 // Custom type registration
491 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
492
493 // Custom signals
494 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
495 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
496 static const int TEST_SIGNAL_COUNT = 2;
497
498 // Custom actions
499 static TypeAction customAction1( customType1, "act1", DoActionCustom);
500 static const int TEST_ACTION_COUNT = 1;
501
502 class TestConnectionTracker : public ConnectionTracker
503 {
504 public:
505
506   TestConnectionTracker()
507   {
508   }
509 };
510
511 BaseHandle CreateNamedActorType()
512 {
513   Actor actor = Actor::New();
514   actor.SetName( "NamedActor" );
515   return actor;
516 }
517
518 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
519 PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
520
521 } // Anonymous namespace
522
523 // Note: No negative test case for UtcDaliTypeRegistryGet can be implemented.
524 int UtcDaliTypeRegistryGetP(void)
525 {
526   TestApplication application;
527
528   TypeRegistry registry = TypeRegistry::Get();
529   DALI_TEST_CHECK( registry );
530
531   END_TEST;
532 }
533
534 // Note: No negative test case for UtcDaliTypeRegistryConstructor can be implemented.
535 int UtcDaliTypeRegistryConstructorP(void)
536 {
537   TestApplication application;
538
539   TypeRegistry registry;
540   DALI_TEST_CHECK( !registry );
541   END_TEST;
542 }
543
544 // Note: No negative test case for UtcDaliTypeRegistryCopyConstructor can be implemented.
545 int UtcDaliTypeRegistryCopyConstructorP(void)
546 {
547   TestApplication application;
548
549   TypeRegistry registry = TypeRegistry::Get();
550   DALI_TEST_CHECK( registry );
551
552   TypeRegistry copy( registry );
553   DALI_TEST_CHECK( copy );
554
555   DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
556
557   END_TEST;
558 }
559
560 // Note: No negative test case for UtcDaliTypeRegistryAssignmentOperator can be implemented.
561 int UtcDaliTypeRegistryAssignmentOperatorP(void)
562 {
563   TestApplication application;
564
565   TypeRegistry registry = TypeRegistry::Get();
566   DALI_TEST_CHECK( registry );
567
568   TypeRegistry copy = registry;
569   DALI_TEST_CHECK( copy );
570   DALI_TEST_CHECK( registry == copy );
571
572   DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
573
574   END_TEST;
575 }
576
577 int UtcDaliTypeRegistryAssignP(void)
578 {
579   TestApplication application;
580
581   TypeRegistry registry = TypeRegistry::Get();
582   TypeRegistry registry2;
583   registry2 = registry;
584   DALI_TEST_CHECK( registry2 );
585
586   DALI_TEST_CHECK( registry2.GetTypeInfo( "Actor" ).GetName() == registry2.GetTypeInfo( "Actor" ).GetName() );
587
588   END_TEST;
589 }
590
591 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameP(void)
592 {
593   TestApplication application;
594
595   TypeRegistry registry = TypeRegistry::Get();
596
597   TypeInfo type;
598
599   // image actor
600   type = registry.GetTypeInfo( "ImageActor" );
601   DALI_TEST_CHECK( type );
602   DALI_TEST_CHECK( type.GetCreator() );
603   DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
604   ImageActor ia = ImageActor::DownCast(type.CreateInstance());
605   DALI_TEST_CHECK( ia );
606   Stage::GetCurrent().Add( ia );
607   application.Render();
608
609   // camera actor
610   type = registry.GetTypeInfo( "CameraActor" );
611   DALI_TEST_CHECK( type );
612   CameraActor ca = CameraActor::DownCast(type.CreateInstance());
613   DALI_TEST_CHECK( ca );
614   Stage::GetCurrent().Add( ca );
615   application.Render();
616
617   // animations
618   type = registry.GetTypeInfo( "Animation" );
619   DALI_TEST_CHECK( type );
620   Animation an = Animation::DownCast(type.CreateInstance());
621   DALI_TEST_CHECK( an );
622   an.Play();
623   application.Render();
624
625   // shader effect
626   type = registry.GetTypeInfo( "ShaderEffect" );
627   DALI_TEST_CHECK( type );
628   ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
629   DALI_TEST_CHECK( ef );
630   application.Render();
631
632   END_TEST;
633 }
634
635 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameN(void)
636 {
637   TestApplication application;
638
639   TypeRegistry registry = TypeRegistry::Get();
640
641   TypeInfo type;
642
643   type = registry.GetTypeInfo( "MyDummyActor" );
644   DALI_TEST_CHECK( !type );
645
646   END_TEST;
647 }
648
649 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdP(void)
650 {
651   TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
652   TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
653
654   DALI_TEST_CHECK( named_type );
655   DALI_TEST_CHECK( typeinfo_type );
656
657   // Check named and typeid are equivalent
658   DALI_TEST_CHECK( named_type == typeinfo_type );
659
660   DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
661   DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
662
663   END_TEST;
664 }
665
666 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdN(void)
667 {
668   TestApplication application;
669   TypeRegistry typeRegistry = TypeRegistry::Get();
670
671   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(Vector2) );
672   DALI_TEST_CHECK( !typeInfo );
673
674   END_TEST;
675 }
676
677 int UtcDaliTypeRegistryGetTypeNameCountP(void)
678 {
679   TestApplication application;
680   TypeRegistry typeRegistry = TypeRegistry::Get();
681   TypeInfo type;
682
683   for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
684   {
685     type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
686     DALI_TEST_CHECK( type );
687   }
688
689   END_TEST;
690 }
691
692
693 int UtcDaliTypeRegistryGetTypeNamesP(void)
694 {
695   TestApplication application;
696   TypeRegistry typeRegistry = TypeRegistry::Get();
697   TypeInfo type;
698
699   for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
700   {
701     type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
702     DALI_TEST_CHECK( type );
703   }
704
705   END_TEST;
706 }
707
708
709 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
710 int UtcDaliTypeRegistryTypeRegistrationNotCallingCreateOnInitP(void)
711 {
712   ResetFunctorCounts();
713
714   TestApplication application;
715
716   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
717   DALI_TEST_CHECK( type );
718
719   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
720   DALI_TEST_CHECK( baseType );
721
722   BaseHandle handle = type.CreateInstance();
723   DALI_TEST_CHECK( handle );
724
725   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
726   DALI_TEST_CHECK( customHandle );
727
728   DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
729
730   DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
731
732   {
733     TestConnectionTracker tracker;
734
735     bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
736     DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
737     DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
738     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
739     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
740
741     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
742     customHandle.GetCustomSignal().Emit();
743     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
744     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
745     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
746   }
747   // tracker should automatically disconnect here
748   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
749   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
750
751   // Test that functor is disconnected
752   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
753   customHandle.GetCustomSignal().Emit();
754   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
755   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
756   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
757
758   Property::Map attributes;
759   handle.DoAction("act1", attributes);
760   DALI_TEST_CHECK( lastActionCustom == "act1" );
761   END_TEST;
762 }
763
764 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
765 int UtcDaliTypeRegistryTypeRegistrationCallingCreateOnInitP(void)
766 {
767   TestApplication application;
768
769   DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
770
771   DALI_TEST_CHECK( true == CreateCustomInitCalled );
772   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
773   DALI_TEST_CHECK( type );
774   END_TEST;
775 }
776
777 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
778 int UtcDaliTypeRegistryTypeRegistrationForNamedTypeP(void)
779 {
780   TestApplication application;
781
782   // Create Named Actor Type
783   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyNamedActor" );
784   DALI_TEST_CHECK( type );
785
786   BaseHandle namedHandle = type.CreateInstance();
787   DALI_TEST_CHECK( namedHandle );
788   Actor namedActor( Actor::DownCast( namedHandle ) );
789   DALI_TEST_CHECK( namedActor );
790
791   DALI_TEST_CHECK( namedActor.GetName() == "NamedActor" );
792   DALI_TEST_CHECK( type.GetName() == "MyNamedActor" );
793   DALI_TEST_CHECK( type.GetBaseName() == "Actor" );
794
795   END_TEST;
796 }
797
798 // Note: No negative test case for UtcDaliTypeRegistryRegisteredName can be implemented.
799 int UtcDaliTypeRegistryRegisteredNameP(void)
800 {
801   TestApplication application;
802
803   DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
804
805   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
806   DALI_TEST_CHECK( baseType );
807
808   BaseHandle handle = baseType.CreateInstance();
809
810   DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
811   TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
812   DALI_TEST_CHECK( type );
813   END_TEST;
814 }
815
816 int UtcDaliTypeRegistrySignalConnectorTypeP(void)
817 {
818   ResetFunctorCounts();
819
820   TestApplication application;
821
822   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
823   DALI_TEST_CHECK( type );
824
825   BaseHandle handle = type.CreateInstance();
826   DALI_TEST_CHECK( handle );
827
828   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
829   DALI_TEST_CHECK( customHandle );
830
831   {
832     TestConnectionTracker tracker;
833
834     bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
835     DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
836     DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
837     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
838     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
839
840     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
841     customHandle.GetCustomSignal().Emit();
842     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
843     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
844     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
845   }
846   // tracker should automatically disconnect here
847   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
848   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
849
850   // Test that functor is disconnected
851   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
852   customHandle.GetCustomSignal().Emit();
853   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
854   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
855   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
856
857   END_TEST;
858 }
859
860 int UtcDaliTypeRegistrySignalConnectorTypeN(void)
861 {
862   // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
863
864   ResetFunctorCounts();
865
866   TestApplication application;
867
868   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
869   DALI_TEST_CHECK( type );
870
871   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
872   DALI_TEST_CHECK( baseType );
873
874   BaseHandle handle = type.CreateInstance();
875   DALI_TEST_CHECK( handle );
876
877   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
878   DALI_TEST_CHECK( customHandle );
879
880   DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
881
882   DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
883
884   {
885     TestConnectionTracker tracker;
886
887     bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
888     DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
889     DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
890     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
891     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
892
893     // Should be a NOOP
894     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
895     customHandle.GetCustomSignal().Emit();
896     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
897   }
898   // tracker should have nothing to disconnect here
899
900   // Should be a NOOP
901   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
902   customHandle.GetCustomSignal().Emit();
903   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
904   END_TEST;
905 }
906
907 int UtcDaliTypeRegistryTypeActionP(void)
908 {
909   ResetFunctorCounts();
910
911   TestApplication application;
912
913   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
914   DALI_TEST_CHECK( type );
915
916   BaseHandle handle = type.CreateInstance();
917   DALI_TEST_CHECK( handle );
918
919   Property::Map attributes;
920   DALI_TEST_CHECK( handle.DoAction("act1", attributes) );
921   DALI_TEST_CHECK( lastActionCustom == "act1" );
922
923   END_TEST;
924 }
925
926 int UtcDaliTypeRegistryTypeActionN(void)
927 {
928   ResetFunctorCounts();
929
930   TestApplication application;
931
932   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
933   DALI_TEST_CHECK( type );
934
935   BaseHandle handle = type.CreateInstance();
936   DALI_TEST_CHECK( handle );
937
938   Property::Map attributes;
939   DALI_TEST_CHECK( !handle.DoAction( "unknown-action", attributes ) );
940
941   END_TEST;
942 }
943
944 int UtcDaliTypeRegistryPropertyRegistrationP(void)
945 {
946   TestApplication application;
947   TypeRegistry typeRegistry = TypeRegistry::Get();
948
949   // Check property count before property registration
950   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
951   DALI_TEST_CHECK( typeInfo );
952   BaseHandle handle = typeInfo.CreateInstance();
953   DALI_TEST_CHECK( handle );
954   Actor customActor = Actor::DownCast( handle );
955   DALI_TEST_CHECK( customActor );
956   unsigned int initialPropertyCount( customActor.GetPropertyCount() );
957
958   std::string propertyName( "prop-1" );
959   int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
960   Property::Type propertyType( Property::BOOLEAN );
961   PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
962
963   // Check property count after registration
964   unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
965   DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
966
967   // Add custom property and check property count
968   customActor.RegisterProperty( "custom-prop-1", true );
969   unsigned int customPropertyCount( customActor.GetPropertyCount() );
970   DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
971
972   // Set the property, ensure SetProperty called
973   DALI_TEST_CHECK( !setPropertyCalled );
974   customActor.SetProperty( propertyIndex, false );
975   DALI_TEST_CHECK( setPropertyCalled );
976
977   // Get the property, ensure GetProperty called
978   DALI_TEST_CHECK( !getPropertyCalled );
979   (void)customActor.GetProperty< bool >( propertyIndex );
980   DALI_TEST_CHECK( getPropertyCalled );
981
982   // Check the property name
983   DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
984   DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
985
986   // Check the property index
987   DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
988
989   // Check the property type
990   DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
991
992   // Check property count of type-info is 1
993   Property::IndexContainer indices;
994   typeInfo.GetPropertyIndices( indices );
995   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
996
997   // check property name count
998   DALI_TEST_CHECK( 1 == typeInfo.GetPropertyCount() );
999
1000   // Ensure indices returned from actor and customActor differ by two
1001   Actor actor = Actor::New();
1002   actor.GetPropertyIndices( indices );
1003   unsigned int actorIndices = indices.Size();
1004   customActor.GetPropertyIndices( indices );
1005   unsigned int customActorIndices = indices.Size();
1006   DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1007   END_TEST;
1008 }
1009
1010 int UtcDaliTypeRegistryPropertyRegistrationN(void)
1011 {
1012   TestApplication application;
1013   TypeRegistry typeRegistry = TypeRegistry::Get();
1014
1015   // Attempt to register a property type out-of-bounds index (less than)
1016   try
1017   {
1018     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1019     tet_result( TET_FAIL );
1020   }
1021   catch ( DaliException& e )
1022   {
1023     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1024   }
1025
1026   // Attempt to register a property type out-of-bounds index (greater than)
1027   try
1028   {
1029     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1030     tet_result( TET_FAIL );
1031   }
1032   catch ( DaliException& e )
1033   {
1034     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1035   }
1036
1037   END_TEST;
1038 }
1039
1040 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1041 {
1042   TestApplication application;
1043   TypeRegistry typeRegistry = TypeRegistry::Get();
1044
1045   // Check property count before property registration
1046   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1047   DALI_TEST_CHECK( typeInfo );
1048   BaseHandle handle = typeInfo.CreateInstance();
1049   DALI_TEST_CHECK( handle );
1050   Actor customActor = Actor::DownCast( handle );
1051   DALI_TEST_CHECK( customActor );
1052
1053   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1054
1055   // Register animatable property
1056   std::string animatablePropertyName( "animatable-prop-1" );
1057   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1058   Property::Type animatablePropertyType( Property::FLOAT );
1059   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1060
1061   // Check property count after registration
1062   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1063
1064   // Set the animatable property value
1065   customActor.SetProperty( animatablePropertyIndex, 25.0f );
1066
1067   // Render and notify
1068   application.SendNotification();
1069   application.Render();
1070
1071   // Check the animatable property value
1072   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
1073
1074   // Check the animatable property name
1075   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1076
1077   // Check the animatable property index
1078   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1079
1080   // Check the animatable property type
1081   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1082
1083   // Check property count of type-info is 1
1084   Property::IndexContainer indices;
1085   typeInfo.GetPropertyIndices( indices );
1086   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1087
1088   // Ensure indices returned from actor and customActor differ by one
1089   Actor actor = Actor::New();
1090   actor.GetPropertyIndices( indices );
1091   unsigned int actorIndices = indices.Size();
1092   customActor.GetPropertyIndices( indices );
1093   unsigned int customActorIndices = indices.Size();
1094   DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1095
1096   END_TEST;
1097 }
1098
1099 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1100 {
1101   TestApplication application;
1102   TypeRegistry typeRegistry = TypeRegistry::Get();
1103
1104   // Attempt to register an animatable property type out-of-bounds index (less than)
1105   try
1106   {
1107     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1108     tet_result( TET_FAIL );
1109   }
1110   catch ( DaliException& e )
1111   {
1112     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1113   }
1114
1115   // Attempt to register an animatable property type out-of-bounds index (greater than)
1116   try
1117   {
1118     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1119     tet_result( TET_FAIL );
1120   }
1121   catch ( DaliException& e )
1122   {
1123     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1124   }
1125
1126   END_TEST;
1127 }
1128
1129 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1130 {
1131   TestApplication application;
1132   TypeRegistry typeRegistry = TypeRegistry::Get();
1133
1134   // Check property count before property registration
1135   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1136   DALI_TEST_CHECK( typeInfo );
1137   BaseHandle handle = typeInfo.CreateInstance();
1138   DALI_TEST_CHECK( handle );
1139   Actor customActor = Actor::DownCast( handle );
1140   DALI_TEST_CHECK( customActor );
1141
1142   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1143
1144   // Register animatable property
1145   std::string animatablePropertyName( "animatable-prop-1" );
1146   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1147   Property::Type animatablePropertyType( Property::VECTOR2 );
1148   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1149
1150   // Check property count after registration
1151   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1152
1153   // Set the animatable property value
1154   customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1155
1156   // Render and notify
1157   application.SendNotification();
1158   application.Render();
1159
1160   // Check the animatable property value
1161   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1162
1163   // Check the animatable property name
1164   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1165
1166   // Check the animatable property index
1167   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1168
1169   // Check the animatable property type
1170   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1171
1172   // Check property count of type-info is 1
1173   Property::IndexContainer indices;
1174   typeInfo.GetPropertyIndices( indices );
1175   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1176
1177   // Register animatable property components
1178   std::string animatablePropertyComponentName1( "animatable-prop-1-x" );
1179   int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1180   AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1181
1182   std::string animatablePropertyComponentName2( "animatable-prop-1-y" );
1183   int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1184   AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1185
1186   // Check property count after registration
1187   DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1188
1189   // Check the animatable property component value
1190   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1191   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1192
1193   // Set the animatable property component value
1194   customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1195
1196   // Render and notify
1197   application.SendNotification();
1198   application.Render();
1199
1200   // Check the animatable property value
1201   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1202   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1203   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1204
1205   // Set the animatable property component value
1206   customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1207
1208   // Render and notify
1209   application.SendNotification();
1210   application.Render();
1211
1212   // Check the animatable property value
1213   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1214   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1215   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1216
1217   // Ensure indices returned from actor and customActor differ by three
1218   Actor actor = Actor::New();
1219   actor.GetPropertyIndices( indices );
1220   unsigned int actorIndices = indices.Size();
1221   customActor.GetPropertyIndices( indices );
1222   unsigned int customActorIndices = indices.Size();
1223   DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1224
1225   END_TEST;
1226 }
1227
1228 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1229 {
1230   TestApplication application;
1231   TypeRegistry typeRegistry = TypeRegistry::Get();
1232
1233   // Register animatable property with the type of Vector2
1234   int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1235   AnimatablePropertyRegistration animatableProperty1( customType1, "animatable-prop-1", animatablePropertyIndex1, Property::VECTOR2 );
1236
1237   // Attempt to register an animatable property component out-of-bounds index (less than)
1238   try
1239   {
1240     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1241     tet_result( TET_FAIL );
1242   }
1243   catch ( DaliException& e )
1244   {
1245     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1246   }
1247
1248   // Attempt to register an animatable property component out-of-bounds index (greater than)
1249   try
1250   {
1251     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1252     tet_result( TET_FAIL );
1253   }
1254   catch ( DaliException& e )
1255   {
1256     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1257   }
1258
1259   // Register an animatable property component
1260   AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1261
1262   // Attempt to register another animatable property component with the same component index
1263   try
1264   {
1265     AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatable-prop-1-y", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1266     tet_result( TET_FAIL );
1267   }
1268   catch ( DaliException& e )
1269   {
1270     DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1271   }
1272
1273   // Register animatable property with the type of boolean
1274   int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1275   AnimatablePropertyRegistration animatableProperty2( customType1, "animatable-prop-2", animatablePropertyIndex2, Property::BOOLEAN );
1276
1277   // Attempt to register an animatable property component for the above property with boolean type
1278   try
1279   {
1280     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-2-x", animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1281     tet_result( TET_FAIL );
1282   }
1283   catch ( DaliException& e )
1284   {
1285     DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1286   }
1287
1288   END_TEST;
1289 }
1290
1291
1292 /*******************************************************************************
1293  *
1294  * Action through the base handle
1295  *
1296  ******************************************************************************/
1297 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1298 {
1299   TestApplication application;
1300
1301   TypeInfo type;
1302
1303   type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1304   DALI_TEST_CHECK( type );
1305
1306   BaseHandle hdl = type.CreateInstance();
1307   DALI_TEST_CHECK( hdl );
1308
1309   Actor a = Actor::DownCast(hdl);
1310   DALI_TEST_CHECK( a );
1311
1312   a.SetVisible(false);
1313
1314   application.SendNotification();
1315   application.Render(0);
1316   DALI_TEST_CHECK(!a.IsVisible());
1317
1318   Property::Map attributes;
1319
1320   DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1321
1322   application.SendNotification();
1323   application.Render(0);
1324   DALI_TEST_CHECK(a.IsVisible());
1325
1326   DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
1327   END_TEST;
1328 }
1329
1330 int UtcDaliPropertyRegistrationFunctions(void)
1331 {
1332   TestApplication application;
1333   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1334
1335   // Attempt to register a property without a setter
1336   try
1337   {
1338     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1339     tet_result( TET_PASS );
1340   }
1341   catch ( DaliException& e )
1342   {
1343     tet_result( TET_FAIL );
1344   }
1345
1346   // Attempt to register a property without a getter
1347   try
1348   {
1349     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
1350     tet_result( TET_FAIL );
1351   }
1352   catch ( DaliException& e )
1353   {
1354     DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1355   }
1356   END_TEST;
1357 }
1358
1359 int UtcDaliPropertyRegistrationAddSameIndex(void)
1360 {
1361   TestApplication application;
1362   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1363
1364   // Add one property with a valid property index
1365   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1366
1367   // Attempt to add another property with the same index
1368   try
1369   {
1370     PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1371   }
1372   catch ( DaliException& e )
1373   {
1374     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1375   }
1376
1377   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1378
1379   // Add one property with a valid property index
1380   AnimatablePropertyRegistration property3( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1381
1382   // Attempt to add another property with the same index
1383   try
1384   {
1385     AnimatablePropertyRegistration property4( customType1, "anim-prop-name-2", animatablePropertyIndex, Property::BOOLEAN );
1386   }
1387   catch ( DaliException& e )
1388   {
1389     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1390   }
1391   END_TEST;
1392 }
1393
1394 int UtcDaliPropertyRegistrationPropertyWritable(void)
1395 {
1396   TestApplication application;
1397   int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1398   int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1399
1400   // Add two properties, one with SetProperty, one without
1401   PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1402   PropertyRegistration property2( customType1, "prop-name-readonly",  propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1403
1404   // Create custom-actor
1405   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1406   DALI_TEST_CHECK( typeInfo );
1407   BaseHandle handle = typeInfo.CreateInstance();
1408   DALI_TEST_CHECK( handle );
1409   Actor customActor = Actor::DownCast( handle );
1410   DALI_TEST_CHECK( customActor );
1411
1412   // Check whether properties are writable
1413   DALI_TEST_CHECK(   customActor.IsPropertyWritable( propertyIndex1 ) );
1414   DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1415   END_TEST;
1416 }
1417
1418 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1419 {
1420   TestApplication application;
1421   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1422   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1423
1424   // These properties are not animatable
1425   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1426
1427   // These properties are animatable
1428   AnimatablePropertyRegistration property2( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1429
1430   // Create custom-actor
1431   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1432   DALI_TEST_CHECK( typeInfo );
1433   BaseHandle handle = typeInfo.CreateInstance();
1434   DALI_TEST_CHECK( handle );
1435   Actor customActor = Actor::DownCast( handle );
1436   DALI_TEST_CHECK( customActor );
1437
1438   // Check if animatable
1439   DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1440   DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1441
1442   // Create another instance of custom-actor
1443   BaseHandle handle2 = typeInfo.CreateInstance();
1444   DALI_TEST_CHECK( handle2 );
1445   Actor customActor2 = Actor::DownCast( handle2 );
1446   DALI_TEST_CHECK( customActor2 );
1447
1448   // Check if animatable
1449   DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1450   DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1451   END_TEST;
1452 }
1453
1454 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1455 {
1456   TestApplication application;
1457   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1458   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1459
1460   // Create custom-actor
1461   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1462   DALI_TEST_CHECK( typeInfo );
1463   BaseHandle handle = typeInfo.CreateInstance();
1464   DALI_TEST_CHECK( handle );
1465   Actor customActor = Actor::DownCast( handle );
1466   DALI_TEST_CHECK( customActor );
1467
1468   // Try to set an index that hasn't been added
1469   try
1470   {
1471     customActor.SetProperty( propertyIndex, true );
1472     tet_result( TET_FAIL );
1473   }
1474   catch ( DaliException& e )
1475   {
1476     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1477   }
1478
1479   try
1480   {
1481     customActor.SetProperty( animatablePropertyIndex, true );
1482     tet_result( TET_FAIL );
1483   }
1484   catch ( DaliException& e )
1485   {
1486     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1487   }
1488
1489   // Try to get an index that hasn't been added
1490   try
1491   {
1492     (void) customActor.GetProperty< bool >( propertyIndex );
1493     tet_result( TET_FAIL );
1494   }
1495   catch ( DaliException& e )
1496   {
1497     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1498   }
1499
1500   try
1501   {
1502     (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1503     tet_result( TET_FAIL );
1504   }
1505   catch ( DaliException& e )
1506   {
1507     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1508   }
1509   END_TEST;
1510 }
1511
1512
1513 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1514 {
1515   TestApplication application;
1516
1517   Actor actor = Actor::New();
1518   actor.SetSize(100.0f, 100.0f);
1519   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1520   Stage::GetCurrent().Add(actor);
1521
1522   // Register Type
1523   TypeInfo type;
1524   type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1525   DALI_TEST_CHECK( type );
1526   BaseHandle handle = type.CreateInstance();
1527   DALI_TEST_CHECK( handle );
1528   LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1529   DALI_TEST_CHECK( detector );
1530
1531   // Attach actor to detector
1532   SignalData data;
1533   GestureReceivedFunctor functor( data );
1534   detector.Attach(actor);
1535
1536   // Connect to signal through type
1537   handle.ConnectSignal( &application, "long-press-detected", functor );
1538
1539   // Render and notify
1540   application.SendNotification();
1541   application.Render();
1542
1543   // Emit gesture
1544   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1545   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1546   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1547   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1548   END_TEST;
1549 }
1550
1551 int UtcDaliPanGestureDetectorTypeRegistry(void)
1552 {
1553   TestApplication application;
1554
1555   Actor actor = Actor::New();
1556   actor.SetSize(100.0f, 100.0f);
1557   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1558   Stage::GetCurrent().Add(actor);
1559
1560   // Register Type
1561   TypeInfo type;
1562   type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1563   DALI_TEST_CHECK( type );
1564   BaseHandle handle = type.CreateInstance();
1565   DALI_TEST_CHECK( handle );
1566   PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1567   DALI_TEST_CHECK( detector );
1568
1569   // Attach actor to detector
1570   SignalData data;
1571   GestureReceivedFunctor functor( data );
1572   detector.Attach(actor);
1573
1574   // Connect to signal through type
1575   handle.ConnectSignal( &application, "pan-detected", functor );
1576
1577   // Render and notify
1578   application.SendNotification();
1579   application.Render();
1580
1581   // Emit gesture
1582   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1583   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1584   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1585   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1586   END_TEST;
1587 }
1588
1589 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1590 {
1591   TestApplication application;
1592
1593   Actor actor = Actor::New();
1594   actor.SetSize(100.0f, 100.0f);
1595   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1596   Stage::GetCurrent().Add(actor);
1597
1598   // Register Type
1599   TypeInfo type;
1600   type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1601   DALI_TEST_CHECK( type );
1602   BaseHandle handle = type.CreateInstance();
1603   DALI_TEST_CHECK( handle );
1604   PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1605   DALI_TEST_CHECK( detector );
1606
1607   // Attach actor to detector
1608   SignalData data;
1609   GestureReceivedFunctor functor( data );
1610   detector.Attach(actor);
1611
1612   // Connect to signal through type
1613   handle.ConnectSignal( &application, "pinch-detected", functor );
1614
1615   // Render and notify
1616   application.SendNotification();
1617   application.Render();
1618
1619   // Emit gesture
1620   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1621   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1622   END_TEST;
1623 }
1624
1625 int UtcDaliTapGestureDetectorTypeRegistry(void)
1626 {
1627   TestApplication application;
1628
1629   Actor actor = Actor::New();
1630   actor.SetSize(100.0f, 100.0f);
1631   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1632   Stage::GetCurrent().Add(actor);
1633
1634   // Register Type
1635   TypeInfo type;
1636   type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1637   DALI_TEST_CHECK( type );
1638   BaseHandle handle = type.CreateInstance();
1639   DALI_TEST_CHECK( handle );
1640   TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1641   DALI_TEST_CHECK( detector );
1642
1643   // Attach actor to detector
1644   SignalData data;
1645   GestureReceivedFunctor functor( data );
1646   detector.Attach(actor);
1647
1648   // Connect to signal through type
1649   handle.ConnectSignal( &application, "tap-detected", functor );
1650
1651   // Render and notify
1652   application.SendNotification();
1653   application.Render();
1654
1655   // Emit gesture
1656   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1657   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1658   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1659   END_TEST;
1660 }
1661
1662 int UtcDaliTypeRegistryNamedType(void)
1663 {
1664   TestApplication application;
1665   TypeRegistry typeRegistry = TypeRegistry::Get();
1666
1667   // Create a normal actor
1668   BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1669   DALI_TEST_CHECK( actorHandle );
1670   Actor actor( Actor::DownCast( actorHandle ) );
1671   DALI_TEST_CHECK( actor );
1672   unsigned int actorPropertyCount( actor.GetPropertyCount() );
1673
1674   // Create Named Actor Type
1675   BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1676   DALI_TEST_CHECK( namedHandle );
1677   Actor namedActor( Actor::DownCast( namedHandle ) );
1678   DALI_TEST_CHECK( namedActor );
1679   unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1680
1681   DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1682   END_TEST;
1683 }