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