Merge "UTC coverage for MathUtils,Matrix,Uint16Pair,PropertyTypes" into tizen
[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 OnMouseWheelEvent(const MouseWheelEvent& 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 std::vector<Property::Value>& 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 UtcDaliTypeRegistryGetTypeInfoFromTypeNameP(void)
578 {
579   TestApplication application;
580
581   TypeRegistry registry = TypeRegistry::Get();
582
583   TypeInfo type;
584
585   // image actor
586   type = registry.GetTypeInfo( "ImageActor" );
587   DALI_TEST_CHECK( type );
588   DALI_TEST_CHECK( type.GetCreator() );
589   DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
590   ImageActor ia = ImageActor::DownCast(type.CreateInstance());
591   DALI_TEST_CHECK( ia );
592   Stage::GetCurrent().Add( ia );
593   application.Render();
594
595   // camera actor
596   type = registry.GetTypeInfo( "CameraActor" );
597   DALI_TEST_CHECK( type );
598   CameraActor ca = CameraActor::DownCast(type.CreateInstance());
599   DALI_TEST_CHECK( ca );
600   Stage::GetCurrent().Add( ca );
601   application.Render();
602
603   // animations
604   type = registry.GetTypeInfo( "Animation" );
605   DALI_TEST_CHECK( type );
606   Animation an = Animation::DownCast(type.CreateInstance());
607   DALI_TEST_CHECK( an );
608   an.Play();
609   application.Render();
610
611   // shader effect
612   type = registry.GetTypeInfo( "ShaderEffect" );
613   DALI_TEST_CHECK( type );
614   ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
615   DALI_TEST_CHECK( ef );
616   application.Render();
617
618   END_TEST;
619 }
620
621 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameN(void)
622 {
623   TestApplication application;
624
625   TypeRegistry registry = TypeRegistry::Get();
626
627   TypeInfo type;
628
629   type = registry.GetTypeInfo( "MyDummyActor" );
630   DALI_TEST_CHECK( !type );
631
632   END_TEST;
633 }
634
635 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdP(void)
636 {
637   TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
638   TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
639
640   DALI_TEST_CHECK( named_type );
641   DALI_TEST_CHECK( typeinfo_type );
642
643   // Check named and typeid are equivalent
644   DALI_TEST_CHECK( named_type == typeinfo_type );
645
646   DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
647   DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
648
649   END_TEST;
650 }
651
652 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdN(void)
653 {
654   TestApplication application;
655   TypeRegistry typeRegistry = TypeRegistry::Get();
656
657   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(Vector2) );
658   DALI_TEST_CHECK( !typeInfo );
659
660   END_TEST;
661 }
662
663 int UtcDaliTypeRegistryGetTypeNamesP(void)
664 {
665   TestApplication application;
666
667   TypeInfo type;
668
669   TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
670
671   for(TypeRegistry::NameContainer::iterator iter = names.begin();
672       iter != names.end(); ++iter)
673   {
674     type = TypeRegistry::Get().GetTypeInfo( *iter );
675     DALI_TEST_CHECK( type );
676   }
677
678   END_TEST;
679 }
680
681 int UtcDaliTypeRegistryGetTypeNamesN(void)
682 {
683   TestApplication application;
684
685   TypeInfo type;
686
687   TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
688
689   for(TypeRegistry::NameContainer::iterator iter = names.begin();
690       iter != names.end(); ++iter)
691   {
692     type = TypeRegistry::Get().GetTypeInfo( *iter );
693     DALI_TEST_CHECK( type.GetName() != "MyDummyActor" );
694   }
695
696   END_TEST;
697 }
698
699 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
700 int UtcDaliTypeRegistryTypeRegistrationNotCallingCreateOnInitP(void)
701 {
702   ResetFunctorCounts();
703
704   TestApplication application;
705
706   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
707   DALI_TEST_CHECK( type );
708
709   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
710   DALI_TEST_CHECK( baseType );
711
712   BaseHandle handle = type.CreateInstance();
713   DALI_TEST_CHECK( handle );
714
715   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
716   DALI_TEST_CHECK( customHandle );
717
718   TypeInfo::NameContainer names;
719   type.GetActions(names);
720   TypeInfo::NameContainer baseNames;
721   baseType.GetActions(baseNames);
722   DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
723
724   names.clear();
725   type.GetSignals(names);
726
727   baseNames.clear();
728   baseType.GetSignals(baseNames);
729
730   DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), 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   std::vector<Property::Value> 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   TypeInfo::NameContainer names;
881   TypeInfo::NameContainer baseNames;
882
883   type.GetActions(names);
884   baseType.GetActions(baseNames);
885
886   DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
887
888   names.clear();
889   baseNames.clear();
890
891   type.GetSignals(names);
892   baseType.GetSignals(baseNames);
893
894   DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
895
896   {
897     TestConnectionTracker tracker;
898
899     bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
900     DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
901     DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
902     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
903     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
904
905     // Should be a NOOP
906     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
907     customHandle.GetCustomSignal().Emit();
908     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
909   }
910   // tracker should have nothing to disconnect here
911
912   // Should be a NOOP
913   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
914   customHandle.GetCustomSignal().Emit();
915   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
916   END_TEST;
917 }
918
919 int UtcDaliTypeRegistryTypeActionP(void)
920 {
921   ResetFunctorCounts();
922
923   TestApplication application;
924
925   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
926   DALI_TEST_CHECK( type );
927
928   BaseHandle handle = type.CreateInstance();
929   DALI_TEST_CHECK( handle );
930
931   std::vector<Property::Value> attributes;
932   DALI_TEST_CHECK( handle.DoAction("act1", attributes) );
933   DALI_TEST_CHECK( lastActionCustom == "act1" );
934
935   END_TEST;
936 }
937
938 int UtcDaliTypeRegistryTypeActionN(void)
939 {
940   ResetFunctorCounts();
941
942   TestApplication application;
943
944   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
945   DALI_TEST_CHECK( type );
946
947   BaseHandle handle = type.CreateInstance();
948   DALI_TEST_CHECK( handle );
949
950   std::vector<Property::Value> attributes;
951   DALI_TEST_CHECK( !handle.DoAction( "unknown-action", attributes ) );
952
953   END_TEST;
954 }
955
956 int UtcDaliTypeRegistryPropertyRegistrationP(void)
957 {
958   TestApplication application;
959   TypeRegistry typeRegistry = TypeRegistry::Get();
960
961   // Check property count before property registration
962   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
963   DALI_TEST_CHECK( typeInfo );
964   BaseHandle handle = typeInfo.CreateInstance();
965   DALI_TEST_CHECK( handle );
966   Actor customActor = Actor::DownCast( handle );
967   DALI_TEST_CHECK( customActor );
968   unsigned int initialPropertyCount( customActor.GetPropertyCount() );
969
970   std::string propertyName( "prop-1" );
971   int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
972   Property::Type propertyType( Property::BOOLEAN );
973   PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
974
975   // Check property count after registration
976   unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
977   DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
978
979   // Add custom property and check property count
980   customActor.RegisterProperty( "custom-prop-1", true );
981   unsigned int customPropertyCount( customActor.GetPropertyCount() );
982   DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
983
984   // Set the property, ensure SetProperty called
985   DALI_TEST_CHECK( !setPropertyCalled );
986   customActor.SetProperty( propertyIndex, false );
987   DALI_TEST_CHECK( setPropertyCalled );
988
989   // Get the property, ensure GetProperty called
990   DALI_TEST_CHECK( !getPropertyCalled );
991   (void)customActor.GetProperty< bool >( propertyIndex );
992   DALI_TEST_CHECK( getPropertyCalled );
993
994   // Check the property name
995   DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
996   DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
997
998   // Check the property index
999   DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
1000
1001   // Check the property type
1002   DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
1003
1004   // Check property count of type-info is 1
1005   Property::IndexContainer indices;
1006   typeInfo.GetPropertyIndices( indices );
1007   DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
1008
1009   // check property name count
1010   TypeInfo::NameContainer names;
1011   typeInfo.GetProperties(names);
1012   DALI_TEST_CHECK( 1 == names.size() );
1013
1014   // Ensure indices returned from actor and customActor differ by two
1015   Actor actor = Actor::New();
1016   actor.GetPropertyIndices( indices );
1017   unsigned int actorIndices = indices.size();
1018   customActor.GetPropertyIndices( indices );
1019   unsigned int customActorIndices = indices.size();
1020   DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1021   END_TEST;
1022 }
1023
1024 int UtcDaliTypeRegistryPropertyRegistrationN(void)
1025 {
1026   TestApplication application;
1027   TypeRegistry typeRegistry = TypeRegistry::Get();
1028
1029   // Attempt to register a property type out-of-bounds index (less than)
1030   try
1031   {
1032     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1033     tet_result( TET_FAIL );
1034   }
1035   catch ( DaliException& e )
1036   {
1037     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1038   }
1039
1040   // Attempt to register a property type out-of-bounds index (greater than)
1041   try
1042   {
1043     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1044     tet_result( TET_FAIL );
1045   }
1046   catch ( DaliException& e )
1047   {
1048     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1049   }
1050
1051   END_TEST;
1052 }
1053
1054 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1055 {
1056   TestApplication application;
1057   TypeRegistry typeRegistry = TypeRegistry::Get();
1058
1059   // Check property count before property registration
1060   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1061   DALI_TEST_CHECK( typeInfo );
1062   BaseHandle handle = typeInfo.CreateInstance();
1063   DALI_TEST_CHECK( handle );
1064   Actor customActor = Actor::DownCast( handle );
1065   DALI_TEST_CHECK( customActor );
1066
1067   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1068
1069   // Register animatable property
1070   std::string animatablePropertyName( "animatable-prop-1" );
1071   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1072   Property::Type animatablePropertyType( Property::FLOAT );
1073   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1074
1075   // Check property count after registration
1076   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1077
1078   // Set the animatable property value
1079   customActor.SetProperty( animatablePropertyIndex, 25.0f );
1080
1081   // Render and notify
1082   application.SendNotification();
1083   application.Render();
1084
1085   // Check the animatable property value
1086   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
1087
1088   // Check the animatable property name
1089   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1090
1091   // Check the animatable property index
1092   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1093
1094   // Check the animatable property type
1095   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1096
1097   // Check property count of type-info is 1
1098   Property::IndexContainer indices;
1099   typeInfo.GetPropertyIndices( indices );
1100   DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
1101
1102   // Ensure indices returned from actor and customActor differ by one
1103   Actor actor = Actor::New();
1104   actor.GetPropertyIndices( indices );
1105   unsigned int actorIndices = indices.size();
1106   customActor.GetPropertyIndices( indices );
1107   unsigned int customActorIndices = indices.size();
1108   DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1109
1110   END_TEST;
1111 }
1112
1113 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1114 {
1115   TestApplication application;
1116   TypeRegistry typeRegistry = TypeRegistry::Get();
1117
1118   // Attempt to register an animatable property type out-of-bounds index (less than)
1119   try
1120   {
1121     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1122     tet_result( TET_FAIL );
1123   }
1124   catch ( DaliException& e )
1125   {
1126     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1127   }
1128
1129   // Attempt to register an animatable property type out-of-bounds index (greater than)
1130   try
1131   {
1132     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1133     tet_result( TET_FAIL );
1134   }
1135   catch ( DaliException& e )
1136   {
1137     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1138   }
1139
1140   END_TEST;
1141 }
1142
1143 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1144 {
1145   TestApplication application;
1146   TypeRegistry typeRegistry = TypeRegistry::Get();
1147
1148   // Check property count before property registration
1149   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1150   DALI_TEST_CHECK( typeInfo );
1151   BaseHandle handle = typeInfo.CreateInstance();
1152   DALI_TEST_CHECK( handle );
1153   Actor customActor = Actor::DownCast( handle );
1154   DALI_TEST_CHECK( customActor );
1155
1156   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1157
1158   // Register animatable property
1159   std::string animatablePropertyName( "animatable-prop-1" );
1160   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1161   Property::Type animatablePropertyType( Property::VECTOR2 );
1162   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1163
1164   // Check property count after registration
1165   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1166
1167   // Set the animatable property value
1168   customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1169
1170   // Render and notify
1171   application.SendNotification();
1172   application.Render();
1173
1174   // Check the animatable property value
1175   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1176
1177   // Check the animatable property name
1178   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1179
1180   // Check the animatable property index
1181   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1182
1183   // Check the animatable property type
1184   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1185
1186   // Check property count of type-info is 1
1187   Property::IndexContainer indices;
1188   typeInfo.GetPropertyIndices( indices );
1189   DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
1190
1191   // Register animatable property components
1192   std::string animatablePropertyComponentName1( "animatable-prop-1-x" );
1193   int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1194   AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1195
1196   std::string animatablePropertyComponentName2( "animatable-prop-1-y" );
1197   int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1198   AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1199
1200   // Check property count after registration
1201   DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1202
1203   // Check the animatable property component value
1204   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1205   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1206
1207   // Set the animatable property component value
1208   customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1209
1210   // Render and notify
1211   application.SendNotification();
1212   application.Render();
1213
1214   // Check the animatable property value
1215   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1216   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1217   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1218
1219   // Set the animatable property component value
1220   customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1221
1222   // Render and notify
1223   application.SendNotification();
1224   application.Render();
1225
1226   // Check the animatable property value
1227   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1228   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1229   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1230
1231   // Ensure indices returned from actor and customActor differ by three
1232   Actor actor = Actor::New();
1233   actor.GetPropertyIndices( indices );
1234   unsigned int actorIndices = indices.size();
1235   customActor.GetPropertyIndices( indices );
1236   unsigned int customActorIndices = indices.size();
1237   DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1238
1239   END_TEST;
1240 }
1241
1242 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1243 {
1244   TestApplication application;
1245   TypeRegistry typeRegistry = TypeRegistry::Get();
1246
1247   // Register animatable property with the type of Vector2
1248   int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1249   AnimatablePropertyRegistration animatableProperty1( customType1, "animatable-prop-1", animatablePropertyIndex1, Property::VECTOR2 );
1250
1251   // Attempt to register an animatable property component out-of-bounds index (less than)
1252   try
1253   {
1254     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1255     tet_result( TET_FAIL );
1256   }
1257   catch ( DaliException& e )
1258   {
1259     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1260   }
1261
1262   // Attempt to register an animatable property component out-of-bounds index (greater than)
1263   try
1264   {
1265     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1266     tet_result( TET_FAIL );
1267   }
1268   catch ( DaliException& e )
1269   {
1270     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1271   }
1272
1273   // Register an animatable property component
1274   AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1275
1276   // Attempt to register another animatable property component with the same component index
1277   try
1278   {
1279     AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatable-prop-1-y", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1280     tet_result( TET_FAIL );
1281   }
1282   catch ( DaliException& e )
1283   {
1284     DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1285   }
1286
1287   // Register animatable property with the type of boolean
1288   int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1289   AnimatablePropertyRegistration animatableProperty2( customType1, "animatable-prop-2", animatablePropertyIndex2, Property::BOOLEAN );
1290
1291   // Attempt to register an animatable property component for the above property with boolean type
1292   try
1293   {
1294     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-2-x", animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1295     tet_result( TET_FAIL );
1296   }
1297   catch ( DaliException& e )
1298   {
1299     DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1300   }
1301
1302   END_TEST;
1303 }
1304
1305
1306 /*******************************************************************************
1307  *
1308  * Action through the base handle
1309  *
1310  ******************************************************************************/
1311 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1312 {
1313   TestApplication application;
1314
1315   TypeInfo type;
1316
1317   type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1318   DALI_TEST_CHECK( type );
1319
1320   BaseHandle hdl = type.CreateInstance();
1321   DALI_TEST_CHECK( hdl );
1322
1323   Actor a = Actor::DownCast(hdl);
1324   DALI_TEST_CHECK( a );
1325
1326   a.SetVisible(false);
1327
1328   application.SendNotification();
1329   application.Render(0);
1330   DALI_TEST_CHECK(!a.IsVisible());
1331
1332   std::vector<Property::Value> attributes;
1333
1334   DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1335
1336   application.SendNotification();
1337   application.Render(0);
1338   DALI_TEST_CHECK(a.IsVisible());
1339
1340   DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
1341   END_TEST;
1342 }
1343
1344 int UtcDaliPropertyRegistrationFunctions(void)
1345 {
1346   TestApplication application;
1347   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1348
1349   // Attempt to register a property without a setter
1350   try
1351   {
1352     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1353     tet_result( TET_PASS );
1354   }
1355   catch ( DaliException& e )
1356   {
1357     tet_result( TET_FAIL );
1358   }
1359
1360   // Attempt to register a property without a getter
1361   try
1362   {
1363     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
1364     tet_result( TET_FAIL );
1365   }
1366   catch ( DaliException& e )
1367   {
1368     DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1369   }
1370   END_TEST;
1371 }
1372
1373 int UtcDaliPropertyRegistrationAddSameIndex(void)
1374 {
1375   TestApplication application;
1376   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1377
1378   // Add one property with a valid property index
1379   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1380
1381   // Attempt to add another property with the same index
1382   try
1383   {
1384     PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1385   }
1386   catch ( DaliException& e )
1387   {
1388     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1389   }
1390
1391   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1392
1393   // Add one property with a valid property index
1394   AnimatablePropertyRegistration property3( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1395
1396   // Attempt to add another property with the same index
1397   try
1398   {
1399     AnimatablePropertyRegistration property4( customType1, "anim-prop-name-2", animatablePropertyIndex, Property::BOOLEAN );
1400   }
1401   catch ( DaliException& e )
1402   {
1403     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1404   }
1405   END_TEST;
1406 }
1407
1408 int UtcDaliPropertyRegistrationPropertyWritable(void)
1409 {
1410   TestApplication application;
1411   int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1412   int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1413
1414   // Add two properties, one with SetProperty, one without
1415   PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1416   PropertyRegistration property2( customType1, "prop-name-readonly",  propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1417
1418   // Create custom-actor
1419   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1420   DALI_TEST_CHECK( typeInfo );
1421   BaseHandle handle = typeInfo.CreateInstance();
1422   DALI_TEST_CHECK( handle );
1423   Actor customActor = Actor::DownCast( handle );
1424   DALI_TEST_CHECK( customActor );
1425
1426   // Check whether properties are writable
1427   DALI_TEST_CHECK(   customActor.IsPropertyWritable( propertyIndex1 ) );
1428   DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1429   END_TEST;
1430 }
1431
1432 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1433 {
1434   TestApplication application;
1435   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1436   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1437
1438   // These properties are not animatable
1439   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1440
1441   // These properties are animatable
1442   AnimatablePropertyRegistration property2( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1443
1444   // Create custom-actor
1445   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1446   DALI_TEST_CHECK( typeInfo );
1447   BaseHandle handle = typeInfo.CreateInstance();
1448   DALI_TEST_CHECK( handle );
1449   Actor customActor = Actor::DownCast( handle );
1450   DALI_TEST_CHECK( customActor );
1451
1452   // Check if animatable
1453   DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1454   DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1455
1456   // Create another instance of custom-actor
1457   BaseHandle handle2 = typeInfo.CreateInstance();
1458   DALI_TEST_CHECK( handle2 );
1459   Actor customActor2 = Actor::DownCast( handle2 );
1460   DALI_TEST_CHECK( customActor2 );
1461
1462   // Check if animatable
1463   DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1464   DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1465   END_TEST;
1466 }
1467
1468 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1469 {
1470   TestApplication application;
1471   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1472   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1473
1474   // Create custom-actor
1475   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1476   DALI_TEST_CHECK( typeInfo );
1477   BaseHandle handle = typeInfo.CreateInstance();
1478   DALI_TEST_CHECK( handle );
1479   Actor customActor = Actor::DownCast( handle );
1480   DALI_TEST_CHECK( customActor );
1481
1482   // Try to set an index that hasn't been added
1483   try
1484   {
1485     customActor.SetProperty( propertyIndex, true );
1486     tet_result( TET_FAIL );
1487   }
1488   catch ( DaliException& e )
1489   {
1490     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1491   }
1492
1493   try
1494   {
1495     customActor.SetProperty( animatablePropertyIndex, true );
1496     tet_result( TET_FAIL );
1497   }
1498   catch ( DaliException& e )
1499   {
1500     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1501   }
1502
1503   // Try to get an index that hasn't been added
1504   try
1505   {
1506     (void) customActor.GetProperty< bool >( propertyIndex );
1507     tet_result( TET_FAIL );
1508   }
1509   catch ( DaliException& e )
1510   {
1511     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1512   }
1513
1514   try
1515   {
1516     (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1517     tet_result( TET_FAIL );
1518   }
1519   catch ( DaliException& e )
1520   {
1521     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1522   }
1523   END_TEST;
1524 }
1525
1526
1527 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1528 {
1529   TestApplication application;
1530
1531   Actor actor = Actor::New();
1532   actor.SetSize(100.0f, 100.0f);
1533   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1534   Stage::GetCurrent().Add(actor);
1535
1536   // Register Type
1537   TypeInfo type;
1538   type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1539   DALI_TEST_CHECK( type );
1540   BaseHandle handle = type.CreateInstance();
1541   DALI_TEST_CHECK( handle );
1542   LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1543   DALI_TEST_CHECK( detector );
1544
1545   // Attach actor to detector
1546   SignalData data;
1547   GestureReceivedFunctor functor( data );
1548   detector.Attach(actor);
1549
1550   // Connect to signal through type
1551   handle.ConnectSignal( &application, "long-press-detected", functor );
1552
1553   // Render and notify
1554   application.SendNotification();
1555   application.Render();
1556
1557   // Emit gesture
1558   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1559   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1560   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1561   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1562   END_TEST;
1563 }
1564
1565 int UtcDaliPanGestureDetectorTypeRegistry(void)
1566 {
1567   TestApplication application;
1568
1569   Actor actor = Actor::New();
1570   actor.SetSize(100.0f, 100.0f);
1571   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1572   Stage::GetCurrent().Add(actor);
1573
1574   // Register Type
1575   TypeInfo type;
1576   type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1577   DALI_TEST_CHECK( type );
1578   BaseHandle handle = type.CreateInstance();
1579   DALI_TEST_CHECK( handle );
1580   PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1581   DALI_TEST_CHECK( detector );
1582
1583   // Attach actor to detector
1584   SignalData data;
1585   GestureReceivedFunctor functor( data );
1586   detector.Attach(actor);
1587
1588   // Connect to signal through type
1589   handle.ConnectSignal( &application, "pan-detected", functor );
1590
1591   // Render and notify
1592   application.SendNotification();
1593   application.Render();
1594
1595   // Emit gesture
1596   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1597   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1598   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1599   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1600   END_TEST;
1601 }
1602
1603 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1604 {
1605   TestApplication application;
1606
1607   Actor actor = Actor::New();
1608   actor.SetSize(100.0f, 100.0f);
1609   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1610   Stage::GetCurrent().Add(actor);
1611
1612   // Register Type
1613   TypeInfo type;
1614   type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1615   DALI_TEST_CHECK( type );
1616   BaseHandle handle = type.CreateInstance();
1617   DALI_TEST_CHECK( handle );
1618   PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1619   DALI_TEST_CHECK( detector );
1620
1621   // Attach actor to detector
1622   SignalData data;
1623   GestureReceivedFunctor functor( data );
1624   detector.Attach(actor);
1625
1626   // Connect to signal through type
1627   handle.ConnectSignal( &application, "pinch-detected", functor );
1628
1629   // Render and notify
1630   application.SendNotification();
1631   application.Render();
1632
1633   // Emit gesture
1634   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1635   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1636   END_TEST;
1637 }
1638
1639 int UtcDaliTapGestureDetectorTypeRegistry(void)
1640 {
1641   TestApplication application;
1642
1643   Actor actor = Actor::New();
1644   actor.SetSize(100.0f, 100.0f);
1645   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1646   Stage::GetCurrent().Add(actor);
1647
1648   // Register Type
1649   TypeInfo type;
1650   type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1651   DALI_TEST_CHECK( type );
1652   BaseHandle handle = type.CreateInstance();
1653   DALI_TEST_CHECK( handle );
1654   TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1655   DALI_TEST_CHECK( detector );
1656
1657   // Attach actor to detector
1658   SignalData data;
1659   GestureReceivedFunctor functor( data );
1660   detector.Attach(actor);
1661
1662   // Connect to signal through type
1663   handle.ConnectSignal( &application, "tap-detected", functor );
1664
1665   // Render and notify
1666   application.SendNotification();
1667   application.Render();
1668
1669   // Emit gesture
1670   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1671   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1672   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1673   END_TEST;
1674 }
1675
1676 int UtcDaliTypeRegistryNamedType(void)
1677 {
1678   TestApplication application;
1679   TypeRegistry typeRegistry = TypeRegistry::Get();
1680
1681   // Create a normal actor
1682   BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1683   DALI_TEST_CHECK( actorHandle );
1684   Actor actor( Actor::DownCast( actorHandle ) );
1685   DALI_TEST_CHECK( actor );
1686   unsigned int actorPropertyCount( actor.GetPropertyCount() );
1687
1688   // Create Named Actor Type
1689   BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1690   DALI_TEST_CHECK( namedHandle );
1691   Actor namedActor( Actor::DownCast( namedHandle ) );
1692   DALI_TEST_CHECK( namedActor );
1693   unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1694
1695   DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1696   END_TEST;
1697 }