Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TypeRegistry.cpp
1 /*
2  * Copyright (c) 2014 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( true ) // requires touch
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 policy, Dimension dimension )
265   {
266   }
267
268   virtual void OnCalculateRelayoutSize( Dimension dimension )
269   {
270   }
271
272   virtual float CalculateChildSize( const Dali::Actor& child, Dimension dimension )
273   {
274     return 0.0f;
275   }
276
277   virtual void OnLayoutNegotiated( float size, Dimension dimension )
278   {
279   }
280
281   virtual bool RelayoutDependentOnChildren( 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
524 // Positive test case for a method
525 int UtcDaliTypeRegistryCreateDaliObjects(void)
526 {
527   TestApplication application;
528
529   TypeRegistry registry; // like this for ctor test coverage
530   registry = TypeRegistry::Get();
531
532   TypeInfo type;
533
534   type = registry.GetTypeInfo( "ImageActor" );
535   DALI_TEST_CHECK( type );
536   DALI_TEST_CHECK( type.GetCreator() );
537   DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
538   ImageActor ia = ImageActor::DownCast(type.CreateInstance());
539   DALI_TEST_CHECK( ia );
540   Stage::GetCurrent().Add( ia );
541   application.Render();
542
543   type = registry.GetTypeInfo( "CameraActor" );
544   DALI_TEST_CHECK( type );
545   CameraActor ca = CameraActor::DownCast(type.CreateInstance());
546   DALI_TEST_CHECK( ca );
547   Stage::GetCurrent().Add( ca );
548   application.Render();
549
550   // animations
551   type = registry.GetTypeInfo( "Animation" );
552   DALI_TEST_CHECK( type );
553   Animation an = Animation::DownCast(type.CreateInstance());
554   DALI_TEST_CHECK( an );
555   an.Play();
556   application.Render();
557
558   //
559   type = registry.GetTypeInfo( "ShaderEffect" );
560   DALI_TEST_CHECK( type );
561   ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
562   DALI_TEST_CHECK( ef );
563   application.Render();
564
565   END_TEST;
566 }
567
568 /*******************************************************************************
569  *
570  * Action through the base handle
571  *
572  ******************************************************************************/
573 int UtcDaliTypeRegistryActionViaBaseHandle(void)
574 {
575   TestApplication application;
576
577   TypeInfo type;
578
579   type = TypeRegistry::Get().GetTypeInfo( "Actor" );
580   DALI_TEST_CHECK( type );
581
582   BaseHandle hdl = type.CreateInstance();
583   DALI_TEST_CHECK( hdl );
584
585   Actor a = Actor::DownCast(hdl);
586   DALI_TEST_CHECK( a );
587
588   a.SetVisible(false);
589
590   application.SendNotification();
591   application.Render(0);
592   DALI_TEST_CHECK(!a.IsVisible());
593
594   std::vector<Property::Value> attributes;
595
596   DALI_TEST_CHECK(hdl.DoAction("show", attributes));
597
598   application.SendNotification();
599   application.Render(0);
600   DALI_TEST_CHECK(a.IsVisible());
601
602   DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
603   END_TEST;
604 }
605
606 int UtcDaliTypeRegistryNames(void)
607 {
608   TestApplication application;
609
610   TypeInfo type;
611
612   TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
613
614   for(TypeRegistry::NameContainer::iterator iter = names.begin();
615       iter != names.end(); ++iter)
616   {
617     type = TypeRegistry::Get().GetTypeInfo( *iter );
618     DALI_TEST_CHECK( type );
619   }
620
621   END_TEST;
622 }
623
624 // Check named and typeid are equivalent
625 int UtcDaliTypeRegistryNameEquivalence(void)
626 {
627   TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
628   TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
629
630   DALI_TEST_CHECK( named_type );
631   DALI_TEST_CHECK( typeinfo_type );
632
633   DALI_TEST_CHECK( named_type == typeinfo_type );
634
635   DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
636   DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
637
638   END_TEST;
639 }
640
641
642 int UtcDaliTypeRegistryCustomActor(void)
643 {
644   ResetFunctorCounts();
645
646   TestApplication application;
647
648   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
649   DALI_TEST_CHECK( type );
650
651   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
652   DALI_TEST_CHECK( baseType );
653
654   BaseHandle handle = type.CreateInstance();
655   DALI_TEST_CHECK( handle );
656
657   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
658   DALI_TEST_CHECK( customHandle );
659
660   TypeInfo::NameContainer names;
661   type.GetActions(names);
662   TypeInfo::NameContainer baseNames;
663   baseType.GetActions(baseNames);
664   DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
665
666   names.clear();
667   type.GetSignals(names);
668
669   baseNames.clear();
670   baseType.GetSignals(baseNames);
671
672   DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
673
674   {
675     TestConnectionTracker tracker;
676
677     bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
678     DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
679     DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
680     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
681     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
682
683     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
684     customHandle.GetCustomSignal().Emit();
685     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
686     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
687     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
688   }
689   // tracker should automatically disconnect here
690   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
691   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
692
693   // Test that functor is disconnected
694   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
695   customHandle.GetCustomSignal().Emit();
696   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
697   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
698   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
699
700   std::vector<Property::Value> attributes;
701   handle.DoAction("act1", attributes);
702   DALI_TEST_CHECK( lastActionCustom == "act1" );
703   END_TEST;
704 }
705
706 int UtcDaliTypeRegistryCustomSignalFailure(void)
707 {
708   // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
709
710   ResetFunctorCounts();
711
712   TestApplication application;
713
714   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
715   DALI_TEST_CHECK( type );
716
717   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
718   DALI_TEST_CHECK( baseType );
719
720   BaseHandle handle = type.CreateInstance();
721   DALI_TEST_CHECK( handle );
722
723   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
724   DALI_TEST_CHECK( customHandle );
725
726   TypeInfo::NameContainer names;
727   TypeInfo::NameContainer baseNames;
728
729   type.GetActions(names);
730   baseType.GetActions(baseNames);
731
732   DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
733
734   names.clear();
735   baseNames.clear();
736
737   type.GetSignals(names);
738   baseType.GetSignals(baseNames);
739
740   DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
741
742   {
743     TestConnectionTracker tracker;
744
745     bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
746     DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
747     DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
748     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
749     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
750
751     // Should be a NOOP
752     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
753     customHandle.GetCustomSignal().Emit();
754     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
755   }
756   // tracker should have nothing to disconnect here
757
758   // Should be a NOOP
759   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
760   customHandle.GetCustomSignal().Emit();
761   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
762   END_TEST;
763 }
764
765 int UtcDaliTypeRegistryInitFunctions(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
778 int UtcDaliTypeRegistryNameInitFunctions(void)
779 {
780   TestApplication application;
781
782   DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
783
784   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
785   DALI_TEST_CHECK( baseType );
786
787   BaseHandle handle = baseType.CreateInstance();
788
789   DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
790   TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
791   DALI_TEST_CHECK( type );
792   END_TEST;
793 }
794
795
796 int UtcDaliPropertyRegistration(void)
797 {
798   TestApplication application;
799   TypeRegistry typeRegistry = TypeRegistry::Get();
800
801   // Check property count before property registration
802   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
803   DALI_TEST_CHECK( typeInfo );
804   BaseHandle handle = typeInfo.CreateInstance();
805   DALI_TEST_CHECK( handle );
806   Actor customActor = Actor::DownCast( handle );
807   DALI_TEST_CHECK( customActor );
808   unsigned int initialPropertyCount( customActor.GetPropertyCount() );
809
810   std::string propertyName( "prop-1" );
811   int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
812   Property::Type propertyType( Property::BOOLEAN );
813   PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
814
815   // Check property count after registration
816   unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
817   DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
818
819   // Add custom property and check property count
820   customActor.RegisterProperty( "custom-prop-1", true );
821   unsigned int customPropertyCount( customActor.GetPropertyCount() );
822   DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
823
824   // Set the property, ensure SetProperty called
825   DALI_TEST_CHECK( !setPropertyCalled );
826   customActor.SetProperty( propertyIndex, false );
827   DALI_TEST_CHECK( setPropertyCalled );
828
829   // Get the property, ensure GetProperty called
830   DALI_TEST_CHECK( !getPropertyCalled );
831   (void)customActor.GetProperty< bool >( propertyIndex );
832   DALI_TEST_CHECK( getPropertyCalled );
833
834   // Check the property name
835   DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
836   DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
837
838   // Check the property index
839   DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
840
841   // Check the property type
842   DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
843
844   // Check property count of type-info is 1
845   Property::IndexContainer indices;
846   typeInfo.GetPropertyIndices( indices );
847   DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
848
849   // Register animatable property
850   std::string animatablePropertyName( "animatable-prop-1" );
851   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
852   Property::Type animatablePropertyType( Property::FLOAT );
853   AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
854
855   // Check property count after registration
856   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
857
858   // Set the animatable property value
859   customActor.SetProperty( animatablePropertyIndex, 25.0f );
860
861   // Render and notify
862   application.SendNotification();
863   application.Render();
864
865   // Check the animatable property value
866   DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
867
868   // Check the animatable property name
869   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
870 //  DALI_TEST_EQUALS( typeInfo.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
871
872   // Check the animatable property index
873   DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
874
875   // Check the animatable property type
876   DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
877
878   // Ensure indices returned from actor and customActor differ by three
879   Actor actor = Actor::New();
880   actor.GetPropertyIndices( indices );
881   unsigned int actorIndices = indices.size();
882   customActor.GetPropertyIndices( indices );
883   unsigned int customActorIndices = indices.size();
884   DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
885   END_TEST;
886 }
887
888 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
889 {
890   TestApplication application;
891   TypeRegistry typeRegistry = TypeRegistry::Get();
892
893   // Attempt to register a property type out-of-bounds index (less than)
894   try
895   {
896     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
897     tet_result( TET_FAIL );
898   }
899   catch ( DaliException& e )
900   {
901     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
902   }
903
904   // Attempt to register a property type out-of-bounds index (greater than)
905   try
906   {
907     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
908     tet_result( TET_FAIL );
909   }
910   catch ( DaliException& e )
911   {
912     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
913   }
914
915   // Attempt to register an animatable property type out-of-bounds index (less than)
916   try
917   {
918     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
919     tet_result( TET_FAIL );
920   }
921   catch ( DaliException& e )
922   {
923     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
924   }
925
926   // Attempt to register an animatable property type out-of-bounds index (greater than)
927   try
928   {
929     AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
930     tet_result( TET_FAIL );
931   }
932   catch ( DaliException& e )
933   {
934     DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
935   }
936   END_TEST;
937 }
938
939 int UtcDaliPropertyRegistrationFunctions(void)
940 {
941   TestApplication application;
942   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
943
944   // Attempt to register a property without a setter
945   try
946   {
947     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
948     tet_result( TET_PASS );
949   }
950   catch ( DaliException& e )
951   {
952     tet_result( TET_FAIL );
953   }
954
955   // Attempt to register a property without a getter
956   try
957   {
958     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
959     tet_result( TET_FAIL );
960   }
961   catch ( DaliException& e )
962   {
963     DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
964   }
965   END_TEST;
966 }
967
968 int UtcDaliPropertyRegistrationAddSameIndex(void)
969 {
970   TestApplication application;
971   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
972
973   // Add one property with a valid property index
974   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
975
976   // Attempt to add another property with the same index
977   try
978   {
979     PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
980   }
981   catch ( DaliException& e )
982   {
983     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
984   }
985
986   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
987
988   // Add one property with a valid property index
989   AnimatablePropertyRegistration property3( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
990
991   // Attempt to add another property with the same index
992   try
993   {
994     AnimatablePropertyRegistration property4( customType1, "anim-prop-name-2", animatablePropertyIndex, Property::BOOLEAN );
995   }
996   catch ( DaliException& e )
997   {
998     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
999   }
1000   END_TEST;
1001 }
1002
1003 int UtcDaliPropertyRegistrationPropertyWritable(void)
1004 {
1005   TestApplication application;
1006   int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1007   int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1008
1009   // Add two properties, one with SetProperty, one without
1010   PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1011   PropertyRegistration property2( customType1, "prop-name-readonly",  propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1012
1013   // Create custom-actor
1014   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1015   DALI_TEST_CHECK( typeInfo );
1016   BaseHandle handle = typeInfo.CreateInstance();
1017   DALI_TEST_CHECK( handle );
1018   Actor customActor = Actor::DownCast( handle );
1019   DALI_TEST_CHECK( customActor );
1020
1021   // Check whether properties are writable
1022   DALI_TEST_CHECK(   customActor.IsPropertyWritable( propertyIndex1 ) );
1023   DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1024   END_TEST;
1025 }
1026
1027 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1028 {
1029   TestApplication application;
1030   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1031   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1032
1033   // These properties are not animatable
1034   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1035
1036   // These properties are animatable
1037   AnimatablePropertyRegistration property2( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1038
1039   // Create custom-actor
1040   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1041   DALI_TEST_CHECK( typeInfo );
1042   BaseHandle handle = typeInfo.CreateInstance();
1043   DALI_TEST_CHECK( handle );
1044   Actor customActor = Actor::DownCast( handle );
1045   DALI_TEST_CHECK( customActor );
1046
1047   // Check if animatable
1048   DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1049   DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1050
1051   // Create another instance of custom-actor
1052   BaseHandle handle2 = typeInfo.CreateInstance();
1053   DALI_TEST_CHECK( handle2 );
1054   Actor customActor2 = Actor::DownCast( handle2 );
1055   DALI_TEST_CHECK( customActor2 );
1056
1057   // Check if animatable
1058   DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1059   DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1060   END_TEST;
1061 }
1062
1063 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1064 {
1065   TestApplication application;
1066   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1067   int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1068
1069   // Create custom-actor
1070   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1071   DALI_TEST_CHECK( typeInfo );
1072   BaseHandle handle = typeInfo.CreateInstance();
1073   DALI_TEST_CHECK( handle );
1074   Actor customActor = Actor::DownCast( handle );
1075   DALI_TEST_CHECK( customActor );
1076
1077   // Try to set an index that hasn't been added
1078   try
1079   {
1080     customActor.SetProperty( propertyIndex, true );
1081     tet_result( TET_FAIL );
1082   }
1083   catch ( DaliException& e )
1084   {
1085     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1086   }
1087
1088   try
1089   {
1090     customActor.SetProperty( animatablePropertyIndex, true );
1091     tet_result( TET_FAIL );
1092   }
1093   catch ( DaliException& e )
1094   {
1095     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1096   }
1097
1098   // Try to get an index that hasn't been added
1099   try
1100   {
1101     (void) customActor.GetProperty< bool >( propertyIndex );
1102     tet_result( TET_FAIL );
1103   }
1104   catch ( DaliException& e )
1105   {
1106     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1107   }
1108
1109   try
1110   {
1111     (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1112     tet_result( TET_FAIL );
1113   }
1114   catch ( DaliException& e )
1115   {
1116     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1117   }
1118   END_TEST;
1119 }
1120
1121
1122 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1123 {
1124   TestApplication application;
1125
1126   Actor actor = Actor::New();
1127   actor.SetSize(100.0f, 100.0f);
1128   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1129   Stage::GetCurrent().Add(actor);
1130
1131   // Register Type
1132   TypeInfo type;
1133   type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1134   DALI_TEST_CHECK( type );
1135   BaseHandle handle = type.CreateInstance();
1136   DALI_TEST_CHECK( handle );
1137   LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1138   DALI_TEST_CHECK( detector );
1139
1140   // Attach actor to detector
1141   SignalData data;
1142   GestureReceivedFunctor functor( data );
1143   detector.Attach(actor);
1144
1145   // Connect to signal through type
1146   handle.ConnectSignal( &application, "long-press-detected", functor );
1147
1148   // Render and notify
1149   application.SendNotification();
1150   application.Render();
1151
1152   // Emit gesture
1153   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1154   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1155   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1156   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1157   END_TEST;
1158 }
1159
1160 int UtcDaliPanGestureDetectorTypeRegistry(void)
1161 {
1162   TestApplication application;
1163
1164   Actor actor = Actor::New();
1165   actor.SetSize(100.0f, 100.0f);
1166   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1167   Stage::GetCurrent().Add(actor);
1168
1169   // Register Type
1170   TypeInfo type;
1171   type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1172   DALI_TEST_CHECK( type );
1173   BaseHandle handle = type.CreateInstance();
1174   DALI_TEST_CHECK( handle );
1175   PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1176   DALI_TEST_CHECK( detector );
1177
1178   // Attach actor to detector
1179   SignalData data;
1180   GestureReceivedFunctor functor( data );
1181   detector.Attach(actor);
1182
1183   // Connect to signal through type
1184   handle.ConnectSignal( &application, "pan-detected", functor );
1185
1186   // Render and notify
1187   application.SendNotification();
1188   application.Render();
1189
1190   // Emit gesture
1191   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1192   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1193   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1194   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1195   END_TEST;
1196 }
1197
1198 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1199 {
1200   TestApplication application;
1201
1202   Actor actor = Actor::New();
1203   actor.SetSize(100.0f, 100.0f);
1204   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1205   Stage::GetCurrent().Add(actor);
1206
1207   // Register Type
1208   TypeInfo type;
1209   type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1210   DALI_TEST_CHECK( type );
1211   BaseHandle handle = type.CreateInstance();
1212   DALI_TEST_CHECK( handle );
1213   PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1214   DALI_TEST_CHECK( detector );
1215
1216   // Attach actor to detector
1217   SignalData data;
1218   GestureReceivedFunctor functor( data );
1219   detector.Attach(actor);
1220
1221   // Connect to signal through type
1222   handle.ConnectSignal( &application, "pinch-detected", functor );
1223
1224   // Render and notify
1225   application.SendNotification();
1226   application.Render();
1227
1228   // Emit gesture
1229   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1230   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1231   END_TEST;
1232 }
1233
1234 int UtcDaliTapGestureDetectorTypeRegistry(void)
1235 {
1236   TestApplication application;
1237
1238   Actor actor = Actor::New();
1239   actor.SetSize(100.0f, 100.0f);
1240   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1241   Stage::GetCurrent().Add(actor);
1242
1243   // Register Type
1244   TypeInfo type;
1245   type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1246   DALI_TEST_CHECK( type );
1247   BaseHandle handle = type.CreateInstance();
1248   DALI_TEST_CHECK( handle );
1249   TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1250   DALI_TEST_CHECK( detector );
1251
1252   // Attach actor to detector
1253   SignalData data;
1254   GestureReceivedFunctor functor( data );
1255   detector.Attach(actor);
1256
1257   // Connect to signal through type
1258   handle.ConnectSignal( &application, "tap-detected", functor );
1259
1260   // Render and notify
1261   application.SendNotification();
1262   application.Render();
1263
1264   // Emit gesture
1265   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1266   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1267   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1268   END_TEST;
1269 }
1270
1271 int UtcDaliTypeRegistryNamedType(void)
1272 {
1273   TestApplication application;
1274   TypeRegistry typeRegistry = TypeRegistry::Get();
1275
1276   // Create a normal actor
1277   BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1278   DALI_TEST_CHECK( actorHandle );
1279   Actor actor( Actor::DownCast( actorHandle ) );
1280   DALI_TEST_CHECK( actor );
1281   unsigned int actorPropertyCount( actor.GetPropertyCount() );
1282
1283   // Create Named Actor Type
1284   BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1285   DALI_TEST_CHECK( namedHandle );
1286   Actor namedActor( Actor::DownCast( namedHandle ) );
1287   DALI_TEST_CHECK( namedActor );
1288   unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1289
1290   DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1291   END_TEST;
1292 }