Merge "Allow registering property components for animatable properties" 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   // Ensure indices returned from actor and customActor differ by two
1010   Actor actor = Actor::New();
1011   actor.GetPropertyIndices( indices );
1012   unsigned int actorIndices = indices.size();
1013   customActor.GetPropertyIndices( indices );
1014   unsigned int customActorIndices = indices.size();
1015   DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1016   END_TEST;
1017 }
1018
1019 int UtcDaliTypeRegistryPropertyRegistrationN(void)
1020 {
1021   TestApplication application;
1022   TypeRegistry typeRegistry = TypeRegistry::Get();
1023
1024   // Attempt to register a property type out-of-bounds index (less than)
1025   try
1026   {
1027     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1028     tet_result( TET_FAIL );
1029   }
1030   catch ( DaliException& e )
1031   {
1032     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1033   }
1034
1035   // Attempt to register a property type out-of-bounds index (greater than)
1036   try
1037   {
1038     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1039     tet_result( TET_FAIL );
1040   }
1041   catch ( DaliException& e )
1042   {
1043     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1044   }
1045
1046   END_TEST;
1047 }
1048
1049 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1050 {
1051   TestApplication application;
1052   TypeRegistry typeRegistry = TypeRegistry::Get();
1053
1054   // Check property count before property registration
1055   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1056   DALI_TEST_CHECK( typeInfo );
1057   BaseHandle handle = typeInfo.CreateInstance();
1058   DALI_TEST_CHECK( handle );
1059   Actor customActor = Actor::DownCast( handle );
1060   DALI_TEST_CHECK( customActor );
1061
1062   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1063
1064   // Register animatable property
1065   std::string animatablePropertyName( "animatable-prop-1" );
1066   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1067   Property::Type animatablePropertyType( Property::FLOAT );
1068   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1069
1070   // Check property count after registration
1071   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1072
1073   // Set the animatable property value
1074   customActor.SetProperty( animatablePropertyIndex, 25.0f );
1075
1076   // Render and notify
1077   application.SendNotification();
1078   application.Render();
1079
1080   // Check the animatable property value
1081   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
1082
1083   // Check the animatable property name
1084   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1085
1086   // Check the animatable property index
1087   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1088
1089   // Check the animatable property type
1090   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1091
1092   // Check property count of type-info is 1
1093   Property::IndexContainer indices;
1094   typeInfo.GetPropertyIndices( indices );
1095   DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
1096
1097   // Ensure indices returned from actor and customActor differ by one
1098   Actor actor = Actor::New();
1099   actor.GetPropertyIndices( indices );
1100   unsigned int actorIndices = indices.size();
1101   customActor.GetPropertyIndices( indices );
1102   unsigned int customActorIndices = indices.size();
1103   DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1104
1105   END_TEST;
1106 }
1107
1108 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1109 {
1110   TestApplication application;
1111   TypeRegistry typeRegistry = TypeRegistry::Get();
1112
1113   // Attempt to register an animatable property type out-of-bounds index (less than)
1114   try
1115   {
1116     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1117     tet_result( TET_FAIL );
1118   }
1119   catch ( DaliException& e )
1120   {
1121     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1122   }
1123
1124   // Attempt to register an animatable property type out-of-bounds index (greater than)
1125   try
1126   {
1127     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1128     tet_result( TET_FAIL );
1129   }
1130   catch ( DaliException& e )
1131   {
1132     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1133   }
1134
1135   END_TEST;
1136 }
1137
1138 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1139 {
1140   TestApplication application;
1141   TypeRegistry typeRegistry = TypeRegistry::Get();
1142
1143   // Check property count before property registration
1144   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1145   DALI_TEST_CHECK( typeInfo );
1146   BaseHandle handle = typeInfo.CreateInstance();
1147   DALI_TEST_CHECK( handle );
1148   Actor customActor = Actor::DownCast( handle );
1149   DALI_TEST_CHECK( customActor );
1150
1151   unsigned int customPropertyCount( customActor.GetPropertyCount() );
1152
1153   // Register animatable property
1154   std::string animatablePropertyName( "animatable-prop-1" );
1155   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1156   Property::Type animatablePropertyType( Property::VECTOR2 );
1157   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1158
1159   // Check property count after registration
1160   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1161
1162   // Set the animatable property value
1163   customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1164
1165   // Render and notify
1166   application.SendNotification();
1167   application.Render();
1168
1169   // Check the animatable property value
1170   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1171
1172   // Check the animatable property name
1173   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1174
1175   // Check the animatable property index
1176   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1177
1178   // Check the animatable property type
1179   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1180
1181   // Check property count of type-info is 1
1182   Property::IndexContainer indices;
1183   typeInfo.GetPropertyIndices( indices );
1184   DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
1185
1186   // Register animatable property components
1187   std::string animatablePropertyComponentName1( "animatable-prop-1-x" );
1188   int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1189   AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1190
1191   std::string animatablePropertyComponentName2( "animatable-prop-1-y" );
1192   int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1193   AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1194
1195   // Check property count after registration
1196   DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1197
1198   // Check the animatable property component value
1199   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1200   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1201
1202   // Set the animatable property component value
1203   customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1204
1205   // Render and notify
1206   application.SendNotification();
1207   application.Render();
1208
1209   // Check the animatable property value
1210   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1211   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1212   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1213
1214   // Set the animatable property component value
1215   customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1216
1217   // Render and notify
1218   application.SendNotification();
1219   application.Render();
1220
1221   // Check the animatable property value
1222   DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1223   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1224   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1225
1226   // Ensure indices returned from actor and customActor differ by three
1227   Actor actor = Actor::New();
1228   actor.GetPropertyIndices( indices );
1229   unsigned int actorIndices = indices.size();
1230   customActor.GetPropertyIndices( indices );
1231   unsigned int customActorIndices = indices.size();
1232   DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1233
1234   END_TEST;
1235 }
1236
1237 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1238 {
1239   TestApplication application;
1240   TypeRegistry typeRegistry = TypeRegistry::Get();
1241
1242   // Register animatable property with the type of Vector2
1243   int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1244   AnimatablePropertyRegistration animatableProperty1( customType1, "animatable-prop-1", animatablePropertyIndex1, Property::VECTOR2 );
1245
1246   // Attempt to register an animatable property component out-of-bounds index (less than)
1247   try
1248   {
1249     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1250     tet_result( TET_FAIL );
1251   }
1252   catch ( DaliException& e )
1253   {
1254     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1255   }
1256
1257   // Attempt to register an animatable property component out-of-bounds index (greater than)
1258   try
1259   {
1260     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1261     tet_result( TET_FAIL );
1262   }
1263   catch ( DaliException& e )
1264   {
1265     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1266   }
1267
1268   // Register an animatable property component
1269   AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1270
1271   // Attempt to register another animatable property component with the same component index
1272   try
1273   {
1274     AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatable-prop-1-y", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1275     tet_result( TET_FAIL );
1276   }
1277   catch ( DaliException& e )
1278   {
1279     DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1280   }
1281
1282   // Register animatable property with the type of boolean
1283   int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1284   AnimatablePropertyRegistration animatableProperty2( customType1, "animatable-prop-2", animatablePropertyIndex2, Property::BOOLEAN );
1285
1286   // Attempt to register an animatable property component for the above property with boolean type
1287   try
1288   {
1289     AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-2-x", animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1290     tet_result( TET_FAIL );
1291   }
1292   catch ( DaliException& e )
1293   {
1294     DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1295   }
1296
1297   END_TEST;
1298 }
1299
1300
1301 /*******************************************************************************
1302  *
1303  * Action through the base handle
1304  *
1305  ******************************************************************************/
1306 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1307 {
1308   TestApplication application;
1309
1310   TypeInfo type;
1311
1312   type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1313   DALI_TEST_CHECK( type );
1314
1315   BaseHandle hdl = type.CreateInstance();
1316   DALI_TEST_CHECK( hdl );
1317
1318   Actor a = Actor::DownCast(hdl);
1319   DALI_TEST_CHECK( a );
1320
1321   a.SetVisible(false);
1322
1323   application.SendNotification();
1324   application.Render(0);
1325   DALI_TEST_CHECK(!a.IsVisible());
1326
1327   std::vector<Property::Value> attributes;
1328
1329   DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1330
1331   application.SendNotification();
1332   application.Render(0);
1333   DALI_TEST_CHECK(a.IsVisible());
1334
1335   DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
1336   END_TEST;
1337 }
1338
1339 int UtcDaliPropertyRegistrationFunctions(void)
1340 {
1341   TestApplication application;
1342   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1343
1344   // Attempt to register a property without a setter
1345   try
1346   {
1347     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1348     tet_result( TET_PASS );
1349   }
1350   catch ( DaliException& e )
1351   {
1352     tet_result( TET_FAIL );
1353   }
1354
1355   // Attempt to register a property without a getter
1356   try
1357   {
1358     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
1359     tet_result( TET_FAIL );
1360   }
1361   catch ( DaliException& e )
1362   {
1363     DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1364   }
1365   END_TEST;
1366 }
1367
1368 int UtcDaliPropertyRegistrationAddSameIndex(void)
1369 {
1370   TestApplication application;
1371   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1372
1373   // Add one property with a valid property index
1374   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1375
1376   // Attempt to add another property with the same index
1377   try
1378   {
1379     PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1380   }
1381   catch ( DaliException& e )
1382   {
1383     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1384   }
1385
1386   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1387
1388   // Add one property with a valid property index
1389   AnimatablePropertyRegistration property3( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1390
1391   // Attempt to add another property with the same index
1392   try
1393   {
1394     AnimatablePropertyRegistration property4( customType1, "anim-prop-name-2", animatablePropertyIndex, Property::BOOLEAN );
1395   }
1396   catch ( DaliException& e )
1397   {
1398     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1399   }
1400   END_TEST;
1401 }
1402
1403 int UtcDaliPropertyRegistrationPropertyWritable(void)
1404 {
1405   TestApplication application;
1406   int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1407   int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1408
1409   // Add two properties, one with SetProperty, one without
1410   PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1411   PropertyRegistration property2( customType1, "prop-name-readonly",  propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1412
1413   // Create custom-actor
1414   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1415   DALI_TEST_CHECK( typeInfo );
1416   BaseHandle handle = typeInfo.CreateInstance();
1417   DALI_TEST_CHECK( handle );
1418   Actor customActor = Actor::DownCast( handle );
1419   DALI_TEST_CHECK( customActor );
1420
1421   // Check whether properties are writable
1422   DALI_TEST_CHECK(   customActor.IsPropertyWritable( propertyIndex1 ) );
1423   DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1424   END_TEST;
1425 }
1426
1427 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1428 {
1429   TestApplication application;
1430   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1431   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1432
1433   // These properties are not animatable
1434   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1435
1436   // These properties are animatable
1437   AnimatablePropertyRegistration property2( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1438
1439   // Create custom-actor
1440   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1441   DALI_TEST_CHECK( typeInfo );
1442   BaseHandle handle = typeInfo.CreateInstance();
1443   DALI_TEST_CHECK( handle );
1444   Actor customActor = Actor::DownCast( handle );
1445   DALI_TEST_CHECK( customActor );
1446
1447   // Check if animatable
1448   DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1449   DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1450
1451   // Create another instance of custom-actor
1452   BaseHandle handle2 = typeInfo.CreateInstance();
1453   DALI_TEST_CHECK( handle2 );
1454   Actor customActor2 = Actor::DownCast( handle2 );
1455   DALI_TEST_CHECK( customActor2 );
1456
1457   // Check if animatable
1458   DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1459   DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1460   END_TEST;
1461 }
1462
1463 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1464 {
1465   TestApplication application;
1466   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1467   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1468
1469   // Create custom-actor
1470   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1471   DALI_TEST_CHECK( typeInfo );
1472   BaseHandle handle = typeInfo.CreateInstance();
1473   DALI_TEST_CHECK( handle );
1474   Actor customActor = Actor::DownCast( handle );
1475   DALI_TEST_CHECK( customActor );
1476
1477   // Try to set an index that hasn't been added
1478   try
1479   {
1480     customActor.SetProperty( propertyIndex, true );
1481     tet_result( TET_FAIL );
1482   }
1483   catch ( DaliException& e )
1484   {
1485     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1486   }
1487
1488   try
1489   {
1490     customActor.SetProperty( animatablePropertyIndex, true );
1491     tet_result( TET_FAIL );
1492   }
1493   catch ( DaliException& e )
1494   {
1495     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1496   }
1497
1498   // Try to get an index that hasn't been added
1499   try
1500   {
1501     (void) customActor.GetProperty< bool >( propertyIndex );
1502     tet_result( TET_FAIL );
1503   }
1504   catch ( DaliException& e )
1505   {
1506     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1507   }
1508
1509   try
1510   {
1511     (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1512     tet_result( TET_FAIL );
1513   }
1514   catch ( DaliException& e )
1515   {
1516     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1517   }
1518   END_TEST;
1519 }
1520
1521
1522 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1523 {
1524   TestApplication application;
1525
1526   Actor actor = Actor::New();
1527   actor.SetSize(100.0f, 100.0f);
1528   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1529   Stage::GetCurrent().Add(actor);
1530
1531   // Register Type
1532   TypeInfo type;
1533   type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1534   DALI_TEST_CHECK( type );
1535   BaseHandle handle = type.CreateInstance();
1536   DALI_TEST_CHECK( handle );
1537   LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1538   DALI_TEST_CHECK( detector );
1539
1540   // Attach actor to detector
1541   SignalData data;
1542   GestureReceivedFunctor functor( data );
1543   detector.Attach(actor);
1544
1545   // Connect to signal through type
1546   handle.ConnectSignal( &application, "long-press-detected", functor );
1547
1548   // Render and notify
1549   application.SendNotification();
1550   application.Render();
1551
1552   // Emit gesture
1553   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1554   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1555   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1556   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1557   END_TEST;
1558 }
1559
1560 int UtcDaliPanGestureDetectorTypeRegistry(void)
1561 {
1562   TestApplication application;
1563
1564   Actor actor = Actor::New();
1565   actor.SetSize(100.0f, 100.0f);
1566   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1567   Stage::GetCurrent().Add(actor);
1568
1569   // Register Type
1570   TypeInfo type;
1571   type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1572   DALI_TEST_CHECK( type );
1573   BaseHandle handle = type.CreateInstance();
1574   DALI_TEST_CHECK( handle );
1575   PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1576   DALI_TEST_CHECK( detector );
1577
1578   // Attach actor to detector
1579   SignalData data;
1580   GestureReceivedFunctor functor( data );
1581   detector.Attach(actor);
1582
1583   // Connect to signal through type
1584   handle.ConnectSignal( &application, "pan-detected", functor );
1585
1586   // Render and notify
1587   application.SendNotification();
1588   application.Render();
1589
1590   // Emit gesture
1591   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1592   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1593   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1594   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1595   END_TEST;
1596 }
1597
1598 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1599 {
1600   TestApplication application;
1601
1602   Actor actor = Actor::New();
1603   actor.SetSize(100.0f, 100.0f);
1604   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1605   Stage::GetCurrent().Add(actor);
1606
1607   // Register Type
1608   TypeInfo type;
1609   type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1610   DALI_TEST_CHECK( type );
1611   BaseHandle handle = type.CreateInstance();
1612   DALI_TEST_CHECK( handle );
1613   PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1614   DALI_TEST_CHECK( detector );
1615
1616   // Attach actor to detector
1617   SignalData data;
1618   GestureReceivedFunctor functor( data );
1619   detector.Attach(actor);
1620
1621   // Connect to signal through type
1622   handle.ConnectSignal( &application, "pinch-detected", functor );
1623
1624   // Render and notify
1625   application.SendNotification();
1626   application.Render();
1627
1628   // Emit gesture
1629   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1630   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1631   END_TEST;
1632 }
1633
1634 int UtcDaliTapGestureDetectorTypeRegistry(void)
1635 {
1636   TestApplication application;
1637
1638   Actor actor = Actor::New();
1639   actor.SetSize(100.0f, 100.0f);
1640   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1641   Stage::GetCurrent().Add(actor);
1642
1643   // Register Type
1644   TypeInfo type;
1645   type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1646   DALI_TEST_CHECK( type );
1647   BaseHandle handle = type.CreateInstance();
1648   DALI_TEST_CHECK( handle );
1649   TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1650   DALI_TEST_CHECK( detector );
1651
1652   // Attach actor to detector
1653   SignalData data;
1654   GestureReceivedFunctor functor( data );
1655   detector.Attach(actor);
1656
1657   // Connect to signal through type
1658   handle.ConnectSignal( &application, "tap-detected", functor );
1659
1660   // Render and notify
1661   application.SendNotification();
1662   application.Render();
1663
1664   // Emit gesture
1665   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1666   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1667   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1668   END_TEST;
1669 }
1670
1671 int UtcDaliTypeRegistryNamedType(void)
1672 {
1673   TestApplication application;
1674   TypeRegistry typeRegistry = TypeRegistry::Get();
1675
1676   // Create a normal actor
1677   BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1678   DALI_TEST_CHECK( actorHandle );
1679   Actor actor( Actor::DownCast( actorHandle ) );
1680   DALI_TEST_CHECK( actor );
1681   unsigned int actorPropertyCount( actor.GetPropertyCount() );
1682
1683   // Create Named Actor Type
1684   BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1685   DALI_TEST_CHECK( namedHandle );
1686   Actor namedActor( Actor::DownCast( namedHandle ) );
1687   DALI_TEST_CHECK( namedActor );
1688   unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1689
1690   DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1691   END_TEST;
1692 }