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