Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[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 <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()
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   MyTestCustomActor2()
360   {
361   }
362
363   static MyTestCustomActor2 New()
364   {
365     return MyTestCustomActor2(); // takes ownership
366   }
367
368   virtual ~MyTestCustomActor2()
369   {
370   }
371
372   static MyTestCustomActor2 DownCast( BaseHandle handle )
373   {
374     MyTestCustomActor2 result;
375
376     CustomActor custom = Dali::CustomActor::DownCast( handle );
377     if ( custom )
378     {
379       CustomActorImpl& customImpl = custom.GetImplementation();
380
381       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
382
383       if (impl)
384       {
385         result = MyTestCustomActor2(customImpl.GetOwner());
386       }
387     }
388
389     return result;
390   }
391
392 private:
393
394   MyTestCustomActor2(Internal::CustomActor* internal)
395   : CustomActor(internal)
396   {
397   }
398
399   MyTestCustomActor2( Impl::MyTestCustomActor& impl )
400   : CustomActor( impl )
401   {
402   }
403 };
404
405 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
406
407
408 BaseHandle CreateCustom(void)
409 {
410   return MyTestCustomActor::New();
411 }
412
413 static std::string lastSignalConnectionCustom;
414
415 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
416 {
417   lastSignalConnectionCustom = signalName;
418
419   bool connected( true );
420
421   Dali::BaseHandle handle(object);
422   MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
423
424   if( "sig1" == signalName )
425   {
426     customActor.GetCustomSignal().Connect( tracker, functor );
427   }
428   else
429   {
430     // signalName does not match any signal
431     connected = false;
432   }
433
434   return connected;
435 }
436
437 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
438 {
439   lastSignalConnectionCustom = "failed";
440
441   return false; // This is supposed to fail
442 }
443
444 struct CustomTestFunctor
445 {
446   CustomTestFunctor()
447   {
448     ++mTotalInstanceCount;
449     ++mCurrentInstanceCount;
450   }
451
452   CustomTestFunctor( const CustomTestFunctor& copyMe )
453   {
454     ++mTotalInstanceCount;
455     ++mCurrentInstanceCount;
456   }
457
458   ~CustomTestFunctor()
459   {
460     --mCurrentInstanceCount;
461   }
462
463   void operator()()
464   {
465     ++mCallbackCount;
466   }
467
468   static int mTotalInstanceCount;
469   static int mCurrentInstanceCount;
470   static int mCallbackCount;
471 };
472
473 int CustomTestFunctor::mTotalInstanceCount = 0;
474 int CustomTestFunctor::mCurrentInstanceCount = 0;
475 int CustomTestFunctor::mCallbackCount = 0;
476
477 static void ResetFunctorCounts()
478 {
479   CustomTestFunctor::mTotalInstanceCount   = 0;
480   CustomTestFunctor::mCurrentInstanceCount = 0;
481   CustomTestFunctor::mCallbackCount        = 0;
482 }
483
484 static std::string lastActionCustom;
485 bool DoActionCustom(BaseObject* object, const std::string& actionName, const Property::Map& /*attributes*/)
486 {
487   lastActionCustom = actionName;
488   return true;
489 }
490
491 // Custom type registration
492 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
493
494 // Custom signals
495 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
496 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
497 static const int TEST_SIGNAL_COUNT = 2;
498
499 // Custom actions
500 static TypeAction customAction1( customType1, "act1", DoActionCustom);
501 static const int TEST_ACTION_COUNT = 1;
502
503 class TestConnectionTracker : public ConnectionTracker
504 {
505 public:
506
507   TestConnectionTracker()
508   {
509   }
510 };
511
512 BaseHandle CreateNamedActorType()
513 {
514   Actor actor = Actor::New();
515   actor.SetName( "NamedActor" );
516   return actor;
517 }
518
519 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
520 PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
521
522 } // Anonymous namespace
523
524 // Note: No negative test case for UtcDaliTypeRegistryGet can be implemented.
525 int UtcDaliTypeRegistryGetP(void)
526 {
527   TestApplication application;
528
529   TypeRegistry registry = TypeRegistry::Get();
530   DALI_TEST_CHECK( registry );
531
532   END_TEST;
533 }
534
535 // Note: No negative test case for UtcDaliTypeRegistryConstructor can be implemented.
536 int UtcDaliTypeRegistryConstructorP(void)
537 {
538   TestApplication application;
539
540   TypeRegistry registry;
541   DALI_TEST_CHECK( !registry );
542   END_TEST;
543 }
544
545 // Note: No negative test case for UtcDaliTypeRegistryCopyConstructor can be implemented.
546 int UtcDaliTypeRegistryCopyConstructorP(void)
547 {
548   TestApplication application;
549
550   TypeRegistry registry = TypeRegistry::Get();
551   DALI_TEST_CHECK( registry );
552
553   TypeRegistry copy( registry );
554   DALI_TEST_CHECK( copy );
555
556   DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
557
558   END_TEST;
559 }
560
561 // Note: No negative test case for UtcDaliTypeRegistryAssignmentOperator can be implemented.
562 int UtcDaliTypeRegistryAssignmentOperatorP(void)
563 {
564   TestApplication application;
565
566   TypeRegistry registry = TypeRegistry::Get();
567   DALI_TEST_CHECK( registry );
568
569   TypeRegistry copy = registry;
570   DALI_TEST_CHECK( copy );
571   DALI_TEST_CHECK( registry == copy );
572
573   DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
574
575   END_TEST;
576 }
577
578 int UtcDaliTypeRegistryAssignP(void)
579 {
580   TestApplication application;
581
582   TypeRegistry registry = TypeRegistry::Get();
583   TypeRegistry registry2;
584   registry2 = registry;
585   DALI_TEST_CHECK( registry2 );
586
587   DALI_TEST_CHECK( registry2.GetTypeInfo( "Actor" ).GetName() == registry2.GetTypeInfo( "Actor" ).GetName() );
588
589   END_TEST;
590 }
591
592 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameP(void)
593 {
594   TestApplication application;
595
596   TypeRegistry registry = TypeRegistry::Get();
597
598   TypeInfo type;
599
600   // image actor
601   type = registry.GetTypeInfo( "ImageActor" );
602   DALI_TEST_CHECK( type );
603   DALI_TEST_CHECK( type.GetCreator() );
604   DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
605   ImageActor ia = ImageActor::DownCast(type.CreateInstance());
606   DALI_TEST_CHECK( ia );
607   Stage::GetCurrent().Add( ia );
608   application.Render();
609
610   // camera actor
611   type = registry.GetTypeInfo( "CameraActor" );
612   DALI_TEST_CHECK( type );
613   CameraActor ca = CameraActor::DownCast(type.CreateInstance());
614   DALI_TEST_CHECK( ca );
615   Stage::GetCurrent().Add( ca );
616   application.Render();
617
618   // animations
619   type = registry.GetTypeInfo( "Animation" );
620   DALI_TEST_CHECK( type );
621   Animation an = Animation::DownCast(type.CreateInstance());
622   DALI_TEST_CHECK( an );
623   an.Play();
624   application.Render();
625
626   // shader effect
627   type = registry.GetTypeInfo( "ShaderEffect" );
628   DALI_TEST_CHECK( type );
629   ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
630   DALI_TEST_CHECK( ef );
631   application.Render();
632
633   END_TEST;
634 }
635
636 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameN(void)
637 {
638   TestApplication application;
639
640   TypeRegistry registry = TypeRegistry::Get();
641
642   TypeInfo type;
643
644   type = registry.GetTypeInfo( "MyDummyActor" );
645   DALI_TEST_CHECK( !type );
646
647   END_TEST;
648 }
649
650 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdP(void)
651 {
652   TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
653   TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
654
655   DALI_TEST_CHECK( named_type );
656   DALI_TEST_CHECK( typeinfo_type );
657
658   // Check named and typeid are equivalent
659   DALI_TEST_CHECK( named_type == typeinfo_type );
660
661   DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
662   DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
663
664   END_TEST;
665 }
666
667 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdN(void)
668 {
669   TestApplication application;
670   TypeRegistry typeRegistry = TypeRegistry::Get();
671
672   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(Vector2) );
673   DALI_TEST_CHECK( !typeInfo );
674
675   END_TEST;
676 }
677
678 int UtcDaliTypeRegistryGetTypeNameCountP(void)
679 {
680   TestApplication application;
681   TypeRegistry typeRegistry = TypeRegistry::Get();
682   TypeInfo type;
683
684   for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
685   {
686     type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
687     DALI_TEST_CHECK( type );
688   }
689
690   END_TEST;
691 }
692
693
694 int UtcDaliTypeRegistryGetTypeNamesP(void)
695 {
696   TestApplication application;
697   TypeRegistry typeRegistry = TypeRegistry::Get();
698   TypeInfo type;
699
700   for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
701   {
702     type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
703     DALI_TEST_CHECK( type );
704   }
705
706   END_TEST;
707 }
708
709
710 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
711 int UtcDaliTypeRegistryTypeRegistrationNotCallingCreateOnInitP(void)
712 {
713   ResetFunctorCounts();
714
715   TestApplication application;
716
717   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
718   DALI_TEST_CHECK( type );
719
720   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
721   DALI_TEST_CHECK( baseType );
722
723   BaseHandle handle = type.CreateInstance();
724   DALI_TEST_CHECK( handle );
725
726   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
727   DALI_TEST_CHECK( customHandle );
728
729   DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
730
731   DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
732
733   {
734     TestConnectionTracker tracker;
735
736     bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
737     DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
738     DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
739     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
740     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
741
742     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
743     customHandle.GetCustomSignal().Emit();
744     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
745     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
746     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
747   }
748   // tracker should automatically disconnect here
749   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
750   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
751
752   // Test that functor is disconnected
753   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
754   customHandle.GetCustomSignal().Emit();
755   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
756   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
757   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
758
759   Property::Map attributes;
760   handle.DoAction("act1", attributes);
761   DALI_TEST_CHECK( lastActionCustom == "act1" );
762   END_TEST;
763 }
764
765 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
766 int UtcDaliTypeRegistryTypeRegistrationCallingCreateOnInitP(void)
767 {
768   TestApplication application;
769
770   DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
771
772   DALI_TEST_CHECK( true == CreateCustomInitCalled );
773   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
774   DALI_TEST_CHECK( type );
775   END_TEST;
776 }
777
778 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
779 int UtcDaliTypeRegistryTypeRegistrationForNamedTypeP(void)
780 {
781   TestApplication application;
782
783   // Create Named Actor Type
784   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyNamedActor" );
785   DALI_TEST_CHECK( type );
786
787   BaseHandle namedHandle = type.CreateInstance();
788   DALI_TEST_CHECK( namedHandle );
789   Actor namedActor( Actor::DownCast( namedHandle ) );
790   DALI_TEST_CHECK( namedActor );
791
792   DALI_TEST_CHECK( namedActor.GetName() == "NamedActor" );
793   DALI_TEST_CHECK( type.GetName() == "MyNamedActor" );
794   DALI_TEST_CHECK( type.GetBaseName() == "Actor" );
795
796   END_TEST;
797 }
798
799 // Note: No negative test case for UtcDaliTypeRegistryRegisteredName can be implemented.
800 int UtcDaliTypeRegistryRegisteredNameP(void)
801 {
802   TestApplication application;
803
804   DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
805
806   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
807   DALI_TEST_CHECK( baseType );
808
809   BaseHandle handle = baseType.CreateInstance();
810
811   DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
812   TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
813   DALI_TEST_CHECK( type );
814   END_TEST;
815 }
816
817 int UtcDaliTypeRegistrySignalConnectorTypeP(void)
818 {
819   ResetFunctorCounts();
820
821   TestApplication application;
822
823   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
824   DALI_TEST_CHECK( type );
825
826   BaseHandle handle = type.CreateInstance();
827   DALI_TEST_CHECK( handle );
828
829   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
830   DALI_TEST_CHECK( customHandle );
831
832   {
833     TestConnectionTracker tracker;
834
835     bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
836     DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
837     DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
838     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
839     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
840
841     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
842     customHandle.GetCustomSignal().Emit();
843     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
844     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
845     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
846   }
847   // tracker should automatically disconnect here
848   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
849   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
850
851   // Test that functor is disconnected
852   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
853   customHandle.GetCustomSignal().Emit();
854   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
855   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
856   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
857
858   END_TEST;
859 }
860
861 int UtcDaliTypeRegistrySignalConnectorTypeN(void)
862 {
863   // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
864
865   ResetFunctorCounts();
866
867   TestApplication application;
868
869   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
870   DALI_TEST_CHECK( type );
871
872   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
873   DALI_TEST_CHECK( baseType );
874
875   BaseHandle handle = type.CreateInstance();
876   DALI_TEST_CHECK( handle );
877
878   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
879   DALI_TEST_CHECK( customHandle );
880
881   DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
882
883   DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
884
885   {
886     TestConnectionTracker tracker;
887
888     bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
889     DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
890     DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
891     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
892     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
893
894     // Should be a NOOP
895     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
896     customHandle.GetCustomSignal().Emit();
897     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
898   }
899   // tracker should have nothing to disconnect here
900
901   // Should be a NOOP
902   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
903   customHandle.GetCustomSignal().Emit();
904   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
905   END_TEST;
906 }
907
908 int UtcDaliTypeRegistryTypeActionP(void)
909 {
910   ResetFunctorCounts();
911
912   TestApplication application;
913
914   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
915   DALI_TEST_CHECK( type );
916
917   BaseHandle handle = type.CreateInstance();
918   DALI_TEST_CHECK( handle );
919
920   Property::Map attributes;
921   DALI_TEST_CHECK( handle.DoAction("act1", attributes) );
922   DALI_TEST_CHECK( lastActionCustom == "act1" );
923
924   END_TEST;
925 }
926
927 int UtcDaliTypeRegistryTypeActionN(void)
928 {
929   ResetFunctorCounts();
930
931   TestApplication application;
932
933   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
934   DALI_TEST_CHECK( type );
935
936   BaseHandle handle = type.CreateInstance();
937   DALI_TEST_CHECK( handle );
938
939   Property::Map attributes;
940   DALI_TEST_CHECK( !handle.DoAction( "unknown-action", attributes ) );
941
942   END_TEST;
943 }
944
945 int UtcDaliTypeRegistryPropertyRegistrationP(void)
946 {
947   TestApplication application;
948   TypeRegistry typeRegistry = TypeRegistry::Get();
949
950   // Check property count before property registration
951   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
952   DALI_TEST_CHECK( typeInfo );
953   BaseHandle handle = typeInfo.CreateInstance();
954   DALI_TEST_CHECK( handle );
955   Actor customActor = Actor::DownCast( handle );
956   DALI_TEST_CHECK( customActor );
957   unsigned int initialPropertyCount( customActor.GetPropertyCount() );
958
959   std::string propertyName( "prop-1" );
960   int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
961   Property::Type propertyType( Property::BOOLEAN );
962   PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
963
964   // Check property count after registration
965   unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
966   DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
967
968   // Add custom property and check property count
969   customActor.RegisterProperty( "custom-prop-1", true );
970   unsigned int customPropertyCount( customActor.GetPropertyCount() );
971   DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
972
973   // Set the property, ensure SetProperty called
974   DALI_TEST_CHECK( !setPropertyCalled );
975   customActor.SetProperty( propertyIndex, false );
976   DALI_TEST_CHECK( setPropertyCalled );
977
978   // Get the property, ensure GetProperty called
979   DALI_TEST_CHECK( !getPropertyCalled );
980   (void)customActor.GetProperty< bool >( propertyIndex );
981   DALI_TEST_CHECK( getPropertyCalled );
982
983   // Check the property name
984   DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
985   DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
986
987   // Check the property index
988   DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
989
990   // Check the property type
991   DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
992
993   // Check property count of type-info is 1
994   Property::IndexContainer indices;
995   typeInfo.GetPropertyIndices( indices );
996   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
997
998   // Ensure indices returned from actor and customActor differ by two
999   Actor actor = Actor::New();
1000   actor.GetPropertyIndices( indices );
1001   unsigned int actorIndices = indices.Size();
1002   customActor.GetPropertyIndices( indices );
1003   unsigned int customActorIndices = indices.Size();
1004   DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1005   END_TEST;
1006 }
1007
1008 int UtcDaliTypeRegistryPropertyRegistrationN(void)
1009 {
1010   TestApplication application;
1011   TypeRegistry typeRegistry = TypeRegistry::Get();
1012
1013   // Attempt to register a property type out-of-bounds index (less than)
1014   try
1015   {
1016     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1017     tet_result( TET_FAIL );
1018   }
1019   catch ( DaliException& e )
1020   {
1021     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1022   }
1023
1024   // Attempt to register a property type out-of-bounds index (greater than)
1025   try
1026   {
1027     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1028     tet_result( TET_FAIL );
1029   }
1030   catch ( DaliException& e )
1031   {
1032     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1033   }
1034
1035   END_TEST;
1036 }
1037
1038 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1039 {
1040   TestApplication application;
1041   TypeRegistry typeRegistry = TypeRegistry::Get();
1042
1043   // Check property count before property registration
1044   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1045   DALI_TEST_CHECK( typeInfo );
1046   BaseHandle handle = typeInfo.CreateInstance();
1047   DALI_TEST_CHECK( handle );
1048   Actor customActor = Actor::DownCast( handle );
1049   DALI_TEST_CHECK( customActor );
1050
1051   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1052
1053   // Register animatable property
1054   std::string animatablePropertyName( "animatable-prop-1" );
1055   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1056   Property::Type animatablePropertyType( Property::FLOAT );
1057   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1058
1059   // Check property count after registration
1060   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1061
1062   // Set the animatable property value
1063   customActor.SetProperty( animatablePropertyIndex, 25.0f );
1064
1065   // Render and notify
1066   application.SendNotification();
1067   application.Render();
1068
1069   // Check the animatable property value
1070   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
1071
1072   // Check the animatable property name
1073   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1074
1075   // Check the animatable property index
1076   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1077
1078   // Check the animatable property type
1079   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1080
1081   // Check property count of type-info is 1
1082   Property::IndexContainer indices;
1083   typeInfo.GetPropertyIndices( indices );
1084   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1085
1086   // Ensure indices returned from actor and customActor differ by one
1087   Actor actor = Actor::New();
1088   actor.GetPropertyIndices( indices );
1089   unsigned int actorIndices = indices.Size();
1090   customActor.GetPropertyIndices( indices );
1091   unsigned int customActorIndices = indices.Size();
1092   DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1093
1094   END_TEST;
1095 }
1096
1097 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1098 {
1099   TestApplication application;
1100   TypeRegistry typeRegistry = TypeRegistry::Get();
1101
1102   // Attempt to register an animatable property type out-of-bounds index (less than)
1103   try
1104   {
1105     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1106     tet_result( TET_FAIL );
1107   }
1108   catch ( DaliException& e )
1109   {
1110     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1111   }
1112
1113   // Attempt to register an animatable property type out-of-bounds index (greater than)
1114   try
1115   {
1116     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1117     tet_result( TET_FAIL );
1118   }
1119   catch ( DaliException& e )
1120   {
1121     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1122   }
1123
1124   END_TEST;
1125 }
1126
1127 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1128 {
1129   TestApplication application;
1130   TypeRegistry typeRegistry = TypeRegistry::Get();
1131
1132   // Check property count before property registration
1133   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1134   DALI_TEST_CHECK( typeInfo );
1135   BaseHandle handle = typeInfo.CreateInstance();
1136   DALI_TEST_CHECK( handle );
1137   Actor customActor = Actor::DownCast( handle );
1138   DALI_TEST_CHECK( customActor );
1139
1140   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1141
1142   // Register animatable property
1143   std::string animatablePropertyName( "animatable-prop-1" );
1144   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1145   Property::Type animatablePropertyType( Property::VECTOR2 );
1146   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1147
1148   // Check property count after registration
1149   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1150
1151   // Set the animatable property value
1152   customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1153
1154   // Render and notify
1155   application.SendNotification();
1156   application.Render();
1157
1158   // Check the animatable property value
1159   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1160
1161   // Check the animatable property name
1162   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1163
1164   // Check the animatable property index
1165   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1166
1167   // Check the animatable property type
1168   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1169
1170   // Check property count of type-info is 1
1171   Property::IndexContainer indices;
1172   typeInfo.GetPropertyIndices( indices );
1173   DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1174
1175   // Register animatable property components
1176   std::string animatablePropertyComponentName1( "animatable-prop-1-x" );
1177   int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1178   AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1179
1180   std::string animatablePropertyComponentName2( "animatable-prop-1-y" );
1181   int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1182   AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1183
1184   // Check property count after registration
1185   DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1186
1187   // Check the animatable property component value
1188   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1189   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1190
1191   // Set the animatable property component value
1192   customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1193
1194   // Render and notify
1195   application.SendNotification();
1196   application.Render();
1197
1198   // Check the animatable property value
1199   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1200   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1201   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1202
1203   // Set the animatable property component value
1204   customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1205
1206   // Render and notify
1207   application.SendNotification();
1208   application.Render();
1209
1210   // Check the animatable property value
1211   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1212   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1213   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1214
1215   // Ensure indices returned from actor and customActor differ by three
1216   Actor actor = Actor::New();
1217   actor.GetPropertyIndices( indices );
1218   unsigned int actorIndices = indices.Size();
1219   customActor.GetPropertyIndices( indices );
1220   unsigned int customActorIndices = indices.Size();
1221   DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1222
1223   END_TEST;
1224 }
1225
1226 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1227 {
1228   TestApplication application;
1229   TypeRegistry typeRegistry = TypeRegistry::Get();
1230
1231   // Register animatable property with the type of Vector2
1232   int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1233   AnimatablePropertyRegistration animatableProperty1( customType1, "animatable-prop-1", animatablePropertyIndex1, Property::VECTOR2 );
1234
1235   // Attempt to register an animatable property component out-of-bounds index (less than)
1236   try
1237   {
1238     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1239     tet_result( TET_FAIL );
1240   }
1241   catch ( DaliException& e )
1242   {
1243     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1244   }
1245
1246   // Attempt to register an animatable property component out-of-bounds index (greater than)
1247   try
1248   {
1249     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1250     tet_result( TET_FAIL );
1251   }
1252   catch ( DaliException& e )
1253   {
1254     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1255   }
1256
1257   // Register an animatable property component
1258   AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1259
1260   // Attempt to register another animatable property component with the same component index
1261   try
1262   {
1263     AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatable-prop-1-y", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1264     tet_result( TET_FAIL );
1265   }
1266   catch ( DaliException& e )
1267   {
1268     DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1269   }
1270
1271   // Register animatable property with the type of boolean
1272   int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1273   AnimatablePropertyRegistration animatableProperty2( customType1, "animatable-prop-2", animatablePropertyIndex2, Property::BOOLEAN );
1274
1275   // Attempt to register an animatable property component for the above property with boolean type
1276   try
1277   {
1278     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-2-x", animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1279     tet_result( TET_FAIL );
1280   }
1281   catch ( DaliException& e )
1282   {
1283     DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1284   }
1285
1286   END_TEST;
1287 }
1288
1289
1290 /*******************************************************************************
1291  *
1292  * Action through the base handle
1293  *
1294  ******************************************************************************/
1295 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1296 {
1297   TestApplication application;
1298
1299   TypeInfo type;
1300
1301   type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1302   DALI_TEST_CHECK( type );
1303
1304   BaseHandle hdl = type.CreateInstance();
1305   DALI_TEST_CHECK( hdl );
1306
1307   Actor a = Actor::DownCast(hdl);
1308   DALI_TEST_CHECK( a );
1309
1310   a.SetVisible(false);
1311
1312   application.SendNotification();
1313   application.Render(0);
1314   DALI_TEST_CHECK(!a.IsVisible());
1315
1316   Property::Map attributes;
1317
1318   DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1319
1320   application.SendNotification();
1321   application.Render(0);
1322   DALI_TEST_CHECK(a.IsVisible());
1323
1324   DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
1325   END_TEST;
1326 }
1327
1328 int UtcDaliPropertyRegistrationFunctions(void)
1329 {
1330   TestApplication application;
1331   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1332
1333   // Attempt to register a property without a setter
1334   try
1335   {
1336     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1337     tet_result( TET_PASS );
1338   }
1339   catch ( DaliException& e )
1340   {
1341     tet_result( TET_FAIL );
1342   }
1343
1344   // Attempt to register a property without a getter
1345   try
1346   {
1347     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
1348     tet_result( TET_FAIL );
1349   }
1350   catch ( DaliException& e )
1351   {
1352     DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1353   }
1354   END_TEST;
1355 }
1356
1357 int UtcDaliPropertyRegistrationAddSameIndex(void)
1358 {
1359   TestApplication application;
1360   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1361
1362   // Add one property with a valid property index
1363   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1364
1365   // Attempt to add another property with the same index
1366   try
1367   {
1368     PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1369   }
1370   catch ( DaliException& e )
1371   {
1372     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1373   }
1374
1375   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1376
1377   // Add one property with a valid property index
1378   AnimatablePropertyRegistration property3( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1379
1380   // Attempt to add another property with the same index
1381   try
1382   {
1383     AnimatablePropertyRegistration property4( customType1, "anim-prop-name-2", animatablePropertyIndex, Property::BOOLEAN );
1384   }
1385   catch ( DaliException& e )
1386   {
1387     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1388   }
1389   END_TEST;
1390 }
1391
1392 int UtcDaliPropertyRegistrationPropertyWritable(void)
1393 {
1394   TestApplication application;
1395   int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1396   int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1397
1398   // Add two properties, one with SetProperty, one without
1399   PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1400   PropertyRegistration property2( customType1, "prop-name-readonly",  propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1401
1402   // Create custom-actor
1403   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1404   DALI_TEST_CHECK( typeInfo );
1405   BaseHandle handle = typeInfo.CreateInstance();
1406   DALI_TEST_CHECK( handle );
1407   Actor customActor = Actor::DownCast( handle );
1408   DALI_TEST_CHECK( customActor );
1409
1410   // Check whether properties are writable
1411   DALI_TEST_CHECK(   customActor.IsPropertyWritable( propertyIndex1 ) );
1412   DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1413   END_TEST;
1414 }
1415
1416 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1417 {
1418   TestApplication application;
1419   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1420   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1421
1422   // These properties are not animatable
1423   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1424
1425   // These properties are animatable
1426   AnimatablePropertyRegistration property2( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1427
1428   // Create custom-actor
1429   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1430   DALI_TEST_CHECK( typeInfo );
1431   BaseHandle handle = typeInfo.CreateInstance();
1432   DALI_TEST_CHECK( handle );
1433   Actor customActor = Actor::DownCast( handle );
1434   DALI_TEST_CHECK( customActor );
1435
1436   // Check if animatable
1437   DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1438   DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1439
1440   // Create another instance of custom-actor
1441   BaseHandle handle2 = typeInfo.CreateInstance();
1442   DALI_TEST_CHECK( handle2 );
1443   Actor customActor2 = Actor::DownCast( handle2 );
1444   DALI_TEST_CHECK( customActor2 );
1445
1446   // Check if animatable
1447   DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1448   DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1449   END_TEST;
1450 }
1451
1452 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1453 {
1454   TestApplication application;
1455   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1456   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1457
1458   // Create custom-actor
1459   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1460   DALI_TEST_CHECK( typeInfo );
1461   BaseHandle handle = typeInfo.CreateInstance();
1462   DALI_TEST_CHECK( handle );
1463   Actor customActor = Actor::DownCast( handle );
1464   DALI_TEST_CHECK( customActor );
1465
1466   // Try to set an index that hasn't been added
1467   try
1468   {
1469     customActor.SetProperty( propertyIndex, true );
1470     tet_result( TET_FAIL );
1471   }
1472   catch ( DaliException& e )
1473   {
1474     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1475   }
1476
1477   try
1478   {
1479     customActor.SetProperty( animatablePropertyIndex, true );
1480     tet_result( TET_FAIL );
1481   }
1482   catch ( DaliException& e )
1483   {
1484     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1485   }
1486
1487   // Try to get an index that hasn't been added
1488   try
1489   {
1490     (void) customActor.GetProperty< bool >( propertyIndex );
1491     tet_result( TET_FAIL );
1492   }
1493   catch ( DaliException& e )
1494   {
1495     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1496   }
1497
1498   try
1499   {
1500     (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1501     tet_result( TET_FAIL );
1502   }
1503   catch ( DaliException& e )
1504   {
1505     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1506   }
1507   END_TEST;
1508 }
1509
1510
1511 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1512 {
1513   TestApplication application;
1514
1515   Actor actor = Actor::New();
1516   actor.SetSize(100.0f, 100.0f);
1517   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1518   Stage::GetCurrent().Add(actor);
1519
1520   // Register Type
1521   TypeInfo type;
1522   type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1523   DALI_TEST_CHECK( type );
1524   BaseHandle handle = type.CreateInstance();
1525   DALI_TEST_CHECK( handle );
1526   LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1527   DALI_TEST_CHECK( detector );
1528
1529   // Attach actor to detector
1530   SignalData data;
1531   GestureReceivedFunctor functor( data );
1532   detector.Attach(actor);
1533
1534   // Connect to signal through type
1535   handle.ConnectSignal( &application, "long-press-detected", functor );
1536
1537   // Render and notify
1538   application.SendNotification();
1539   application.Render();
1540
1541   // Emit gesture
1542   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1543   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1544   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1545   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1546   END_TEST;
1547 }
1548
1549 int UtcDaliPanGestureDetectorTypeRegistry(void)
1550 {
1551   TestApplication application;
1552
1553   Actor actor = Actor::New();
1554   actor.SetSize(100.0f, 100.0f);
1555   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1556   Stage::GetCurrent().Add(actor);
1557
1558   // Register Type
1559   TypeInfo type;
1560   type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1561   DALI_TEST_CHECK( type );
1562   BaseHandle handle = type.CreateInstance();
1563   DALI_TEST_CHECK( handle );
1564   PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1565   DALI_TEST_CHECK( detector );
1566
1567   // Attach actor to detector
1568   SignalData data;
1569   GestureReceivedFunctor functor( data );
1570   detector.Attach(actor);
1571
1572   // Connect to signal through type
1573   handle.ConnectSignal( &application, "pan-detected", functor );
1574
1575   // Render and notify
1576   application.SendNotification();
1577   application.Render();
1578
1579   // Emit gesture
1580   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1581   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1582   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1583   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1584   END_TEST;
1585 }
1586
1587 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1588 {
1589   TestApplication application;
1590
1591   Actor actor = Actor::New();
1592   actor.SetSize(100.0f, 100.0f);
1593   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1594   Stage::GetCurrent().Add(actor);
1595
1596   // Register Type
1597   TypeInfo type;
1598   type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1599   DALI_TEST_CHECK( type );
1600   BaseHandle handle = type.CreateInstance();
1601   DALI_TEST_CHECK( handle );
1602   PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1603   DALI_TEST_CHECK( detector );
1604
1605   // Attach actor to detector
1606   SignalData data;
1607   GestureReceivedFunctor functor( data );
1608   detector.Attach(actor);
1609
1610   // Connect to signal through type
1611   handle.ConnectSignal( &application, "pinch-detected", functor );
1612
1613   // Render and notify
1614   application.SendNotification();
1615   application.Render();
1616
1617   // Emit gesture
1618   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1619   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1620   END_TEST;
1621 }
1622
1623 int UtcDaliTapGestureDetectorTypeRegistry(void)
1624 {
1625   TestApplication application;
1626
1627   Actor actor = Actor::New();
1628   actor.SetSize(100.0f, 100.0f);
1629   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1630   Stage::GetCurrent().Add(actor);
1631
1632   // Register Type
1633   TypeInfo type;
1634   type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1635   DALI_TEST_CHECK( type );
1636   BaseHandle handle = type.CreateInstance();
1637   DALI_TEST_CHECK( handle );
1638   TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1639   DALI_TEST_CHECK( detector );
1640
1641   // Attach actor to detector
1642   SignalData data;
1643   GestureReceivedFunctor functor( data );
1644   detector.Attach(actor);
1645
1646   // Connect to signal through type
1647   handle.ConnectSignal( &application, "tap-detected", functor );
1648
1649   // Render and notify
1650   application.SendNotification();
1651   application.Render();
1652
1653   // Emit gesture
1654   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1655   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1656   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1657   END_TEST;
1658 }
1659
1660 int UtcDaliTypeRegistryNamedType(void)
1661 {
1662   TestApplication application;
1663   TypeRegistry typeRegistry = TypeRegistry::Get();
1664
1665   // Create a normal actor
1666   BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1667   DALI_TEST_CHECK( actorHandle );
1668   Actor actor( Actor::DownCast( actorHandle ) );
1669   DALI_TEST_CHECK( actor );
1670   unsigned int actorPropertyCount( actor.GetPropertyCount() );
1671
1672   // Create Named Actor Type
1673   BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1674   DALI_TEST_CHECK( namedHandle );
1675   Actor namedActor( Actor::DownCast( namedHandle ) );
1676   DALI_TEST_CHECK( namedActor );
1677   unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1678
1679   DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1680   END_TEST;
1681 }
1682
1683 int UtcDaliTypeInfoGetActionNameP(void)
1684 {
1685   TestApplication application;
1686   TypeRegistry typeRegistry = TypeRegistry::Get();
1687
1688   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1689   DALI_TEST_CHECK( typeInfo );
1690
1691   DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
1692
1693   std::string name = typeInfo.GetActionName(0);
1694
1695   DALI_TEST_EQUALS( name, "show", TEST_LOCATION );
1696
1697   END_TEST;
1698 }
1699
1700 int UtcDaliTypeInfoGetActionNameN(void)
1701 {
1702   TestApplication application;
1703   TypeRegistry typeRegistry = TypeRegistry::Get();
1704
1705   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1706   DALI_TEST_CHECK( typeInfo );
1707
1708   DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
1709
1710   std::string name = typeInfo.GetActionName(std::numeric_limits<size_t>::max());
1711
1712   DALI_TEST_EQUALS( 0, name.size(), TEST_LOCATION );
1713
1714   END_TEST;
1715 }
1716
1717 int UtcDaliTypeInfoGetSignalNameP(void)
1718 {
1719   TestApplication application;
1720   TypeRegistry typeRegistry = TypeRegistry::Get();
1721
1722   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1723   DALI_TEST_CHECK( typeInfo );
1724
1725   DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
1726
1727   std::string name = typeInfo.GetSignalName(0);
1728
1729   DALI_TEST_EQUALS( name, "touched", TEST_LOCATION );
1730
1731   END_TEST;
1732 }
1733
1734 int UtcDaliTypeInfoGetSignalNameN(void)
1735 {
1736   TestApplication application;
1737   TypeRegistry typeRegistry = TypeRegistry::Get();
1738
1739   TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1740   DALI_TEST_CHECK( typeInfo );
1741
1742   DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
1743
1744   std::string name = typeInfo.GetSignalName(std::numeric_limits<size_t>::max());
1745
1746   DALI_TEST_EQUALS( 0, name.size(), TEST_LOCATION );
1747
1748   END_TEST;
1749 }