Migrating to new test framework
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-unmanaged / utc-Dali-TypeRegistry.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <iostream>
18 #include <stdlib.h>
19 #include <dali/dali.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
28 using namespace Dali;
29
30
31 namespace
32 {
33
34 // Stores data that is populated in the callback and will be read by the Test cases
35 struct SignalData
36 {
37   SignalData()
38   : functorCalled( false ),
39     voidFunctorCalled( false ),
40     receivedGesture( Gesture::Clear ),
41     pressedActor()
42   {}
43
44   void Reset()
45   {
46     functorCalled = false;
47     voidFunctorCalled = false;
48
49     receivedGesture.numberOfTouches = 0u;
50     receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
51     receivedGesture.localPoint = Vector2(0.0f, 0.0f);
52
53     pressedActor = NULL;
54   }
55
56   bool functorCalled;
57   bool voidFunctorCalled;
58   LongPressGesture receivedGesture;
59   Actor pressedActor;
60 };
61
62 // Functor that sets the data when called
63 struct GestureReceivedFunctor
64 {
65   GestureReceivedFunctor(SignalData& data) : signalData(data) { }
66
67   void operator()(Actor actor, LongPressGesture longPress)
68   {
69     signalData.functorCalled = true;
70     signalData.receivedGesture = longPress;
71     signalData.pressedActor = actor;
72   }
73
74   void operator()()
75   {
76     signalData.voidFunctorCalled = true;
77   }
78
79   SignalData& signalData;
80 };
81
82 // Generate a LongPressGestureEvent to send to Core
83 Integration::LongPressGestureEvent GenerateLongPress(
84     Gesture::State state,
85     unsigned int numberOfTouches,
86     Vector2 point)
87 {
88   Integration::LongPressGestureEvent longPress( state );
89
90   longPress.numberOfTouches = numberOfTouches;
91   longPress.point = point;
92
93   return longPress;
94 }
95
96 // Generate a PanGestureEvent to send to Core
97 Integration::PanGestureEvent GeneratePan(
98     Gesture::State state,
99     Vector2 previousPosition,
100     Vector2 currentPosition,
101     unsigned long timeDelta,
102     unsigned int numberOfTouches = 1,
103     unsigned int time = 1u)
104 {
105   Integration::PanGestureEvent pan(state);
106
107   pan.previousPosition = previousPosition;
108   pan.currentPosition = currentPosition;
109   pan.timeDelta = timeDelta;
110   pan.numberOfTouches = numberOfTouches;
111   pan.time = time;
112
113   return pan;
114 }
115 // Generate a PinchGestureEvent to send to Core
116 Integration::PinchGestureEvent GeneratePinch(
117     Gesture::State state,
118     float scale,
119     float speed,
120     Vector2 centerpoint)
121 {
122   Integration::PinchGestureEvent pinch(state);
123
124   pinch.scale = scale;
125   pinch.speed = speed;
126   pinch.centerPoint = centerpoint;
127
128   return pinch;
129 }
130 // Generate a TapGestureEvent to send to Core
131 Integration::TapGestureEvent GenerateTap(
132     Gesture::State state,
133     unsigned int numberOfTaps,
134     unsigned int numberOfTouches,
135     Vector2 point)
136 {
137   Integration::TapGestureEvent tap( state );
138
139   tap.numberOfTaps = numberOfTaps;
140   tap.numberOfTouches = numberOfTouches;
141   tap.point = point;
142
143   return tap;
144 }
145
146 //
147 // Create function as Init function called
148 //
149 static bool CreateCustomInitCalled = false;
150 BaseHandle CreateCustomInit(void)
151 {
152   CreateCustomInitCalled = true;
153   return BaseHandle();
154 }
155
156 static bool CreateCustomNamedInitCalled = false;
157 BaseHandle CreateCustomNamedInit(void)
158 {
159   CreateCustomNamedInitCalled = true;
160   return BaseHandle();
161 }
162
163 const std::string scriptedName("PopupStyle");
164 static TypeRegistration scriptedType( scriptedName, typeid(Dali::CustomActor), CreateCustomNamedInit );
165
166 // Property Registration
167 bool setPropertyCalled = false;
168 bool getPropertyCalled = false;
169 void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
170 {
171   setPropertyCalled = true;
172 }
173 Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex )
174 {
175   getPropertyCalled = true;
176   return Property::Value( true );
177 }
178
179
180
181 /*******************************************************************************
182  *
183  * Custom Actor
184  *
185  ******************************************************************************/
186 namespace Impl
187 {
188 struct MyTestCustomActor : public CustomActorImpl
189 {
190   typedef SignalV2< void ()> SignalType;
191   typedef SignalV2< void (float)> SignalTypeFloat;
192
193   MyTestCustomActor() : CustomActorImpl( true ) // requires touch
194   { }
195
196   virtual ~MyTestCustomActor()
197   { }
198
199   void ResetCallStack()
200   {
201   }
202
203   // From CustomActorImpl
204   virtual void OnStageConnection()
205   {
206   }
207   virtual void OnStageDisconnection()
208   {
209   }
210   virtual void OnChildAdd(Actor& child)
211   {
212   }
213   virtual void OnChildRemove(Actor& child)
214   {
215   }
216   virtual void OnSizeSet(const Vector3& targetSize)
217   {
218   }
219   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
220   {
221   }
222   virtual bool OnTouchEvent(const TouchEvent& event)
223   {
224     return true;
225   }
226   virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
227   {
228     return true;
229   }
230   virtual bool OnKeyEvent(const KeyEvent& event)
231   {
232     return true;
233   }
234   virtual void OnKeyInputFocusGained()
235   {
236   }
237   virtual void OnKeyInputFocusLost()
238   {
239   }
240   virtual Actor GetChildByAlias(const std::string& actorAlias)
241   {
242     return Actor::New();
243   }
244
245 public:
246
247   SignalType mSignal;
248 };
249
250 }; // namespace Impl
251
252 class MyTestCustomActor : public CustomActor
253 {
254 public:
255
256   typedef SignalV2< void ()> SignalType;
257   typedef SignalV2< void (float)> SignalTypeFloat;
258
259   MyTestCustomActor()
260   {
261   }
262
263   static MyTestCustomActor New()
264   {
265     Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
266     return MyTestCustomActor( *p ); // takes ownership
267   }
268
269   virtual ~MyTestCustomActor()
270   {
271   }
272
273   static MyTestCustomActor DownCast( BaseHandle handle )
274   {
275     MyTestCustomActor result;
276
277     CustomActor custom = Dali::CustomActor::DownCast( handle );
278     if ( custom )
279     {
280       CustomActorImpl& customImpl = custom.GetImplementation();
281
282       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
283
284       if (impl)
285       {
286         result = MyTestCustomActor(customImpl.GetOwner());
287       }
288     }
289
290     return result;
291   }
292
293   SignalType& GetCustomSignal()
294   {
295     Dali::RefObject& obj = GetImplementation();
296     return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
297   }
298
299 private:
300
301   MyTestCustomActor(Internal::CustomActor* internal)
302   : CustomActor(internal)
303   {
304   }
305
306   MyTestCustomActor( Impl::MyTestCustomActor& impl )
307   : CustomActor( impl )
308   {
309   }
310 };
311
312
313 class MyTestCustomActor2 : public CustomActor
314 {
315 public:
316
317   MyTestCustomActor2()
318   {
319   }
320
321   static MyTestCustomActor2 New()
322   {
323     return MyTestCustomActor2(); // takes ownership
324   }
325
326   virtual ~MyTestCustomActor2()
327   {
328   }
329
330   static MyTestCustomActor2 DownCast( BaseHandle handle )
331   {
332     MyTestCustomActor2 result;
333
334     CustomActor custom = Dali::CustomActor::DownCast( handle );
335     if ( custom )
336     {
337       CustomActorImpl& customImpl = custom.GetImplementation();
338
339       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
340
341       if (impl)
342       {
343         result = MyTestCustomActor2(customImpl.GetOwner());
344       }
345     }
346
347     return result;
348   }
349
350 private:
351
352   MyTestCustomActor2(Internal::CustomActor* internal)
353   : CustomActor(internal)
354   {
355   }
356
357   MyTestCustomActor2( Impl::MyTestCustomActor& impl )
358   : CustomActor( impl )
359   {
360   }
361 };
362
363 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
364
365
366 BaseHandle CreateCustom(void)
367 {
368   return MyTestCustomActor::New();
369 }
370
371 static std::string lastSignalConnectionCustom;
372
373 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
374 {
375   lastSignalConnectionCustom = signalName;
376
377   bool connected( true );
378
379   Dali::BaseHandle handle(object);
380   MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
381
382   if( "sig1" == signalName )
383   {
384     customActor.GetCustomSignal().Connect( tracker, functor );
385   }
386   else
387   {
388     // signalName does not match any signal
389     connected = false;
390   }
391
392   return connected;
393 }
394
395 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
396 {
397   lastSignalConnectionCustom = "failed";
398
399   return false; // This is supposed to fail
400 }
401
402 struct CustomTestFunctor
403 {
404   CustomTestFunctor()
405   {
406     ++mTotalInstanceCount;
407     ++mCurrentInstanceCount;
408   }
409
410   CustomTestFunctor( const CustomTestFunctor& copyMe )
411   {
412     ++mTotalInstanceCount;
413     ++mCurrentInstanceCount;
414   }
415
416   ~CustomTestFunctor()
417   {
418     --mCurrentInstanceCount;
419   }
420
421   void operator()()
422   {
423     ++mCallbackCount;
424   }
425
426   static int mTotalInstanceCount;
427   static int mCurrentInstanceCount;
428   static int mCallbackCount;
429 };
430
431 int CustomTestFunctor::mTotalInstanceCount = 0;
432 int CustomTestFunctor::mCurrentInstanceCount = 0;
433 int CustomTestFunctor::mCallbackCount = 0;
434
435 static void ResetFunctorCounts()
436 {
437   CustomTestFunctor::mTotalInstanceCount   = 0;
438   CustomTestFunctor::mCurrentInstanceCount = 0;
439   CustomTestFunctor::mCallbackCount        = 0;
440 }
441
442 static std::string lastActionCustom;
443 bool DoActionCustom(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
444 {
445   lastActionCustom = actionName;
446   return true;
447 }
448
449 // Custom type registration
450 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
451
452 // Custom signals
453 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
454 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
455 static const int TEST_SIGNAL_COUNT = 2;
456
457 // Custom actions
458 static TypeAction customAction1( customType1, "act1", DoActionCustom);
459 static const int TEST_ACTION_COUNT = 1;
460
461 class TestConnectionTracker : public ConnectionTracker
462 {
463 public:
464
465   TestConnectionTracker()
466   {
467   }
468 };
469
470 } // Anonymous namespace
471
472
473 // Positive test case for a method
474 int UtcDaliTypeRegistryCreateDaliObjects(void)
475 {
476   TestApplication application;
477
478   TypeRegistry registry; // like this for ctor test coverage
479   registry = TypeRegistry::Get();
480
481   TypeInfo type;
482
483   type = registry.GetTypeInfo( "ImageActor" );
484   DALI_TEST_CHECK( type );
485   DALI_TEST_CHECK( type.GetCreator() );
486   DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
487   ImageActor ia = ImageActor::DownCast(type.CreateInstance());
488   DALI_TEST_CHECK( ia );
489   Stage::GetCurrent().Add( ia );
490   application.Render();
491
492   type = registry.GetTypeInfo( "TextActor" );
493   DALI_TEST_CHECK( type );
494   TextActor ta = TextActor::DownCast(type.CreateInstance());
495   DALI_TEST_CHECK( ta );
496   Stage::GetCurrent().Add( ta );
497   application.Render();
498
499   type = registry.GetTypeInfo( "CameraActor" );
500   DALI_TEST_CHECK( type );
501   CameraActor ca = CameraActor::DownCast(type.CreateInstance());
502   DALI_TEST_CHECK( ca );
503   Stage::GetCurrent().Add( ca );
504   application.Render();
505
506   type = registry.GetTypeInfo( "LightActor" );
507   DALI_TEST_CHECK( type );
508   LightActor la = LightActor::DownCast(type.CreateInstance());
509   DALI_TEST_CHECK( la );
510   Stage::GetCurrent().Add( la );
511   application.Render();
512
513   // animations
514   type = registry.GetTypeInfo( "Animation" );
515   DALI_TEST_CHECK( type );
516   Animation an = Animation::DownCast(type.CreateInstance());
517   DALI_TEST_CHECK( an );
518   an.Play();
519   application.Render();
520
521   //
522   type = registry.GetTypeInfo( "ShaderEffect" );
523   DALI_TEST_CHECK( type );
524   ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
525   DALI_TEST_CHECK( ef );
526   application.Render();
527
528   END_TEST;
529 }
530
531 /*******************************************************************************
532  *
533  * Action through the base handle
534  *
535  ******************************************************************************/
536 int UtcDaliTypeRegistryActionViaBaseHandle(void)
537 {
538   TestApplication application;
539
540   TypeInfo type;
541
542   type = TypeRegistry::Get().GetTypeInfo( "Actor" );
543   DALI_TEST_CHECK( type );
544
545   BaseHandle hdl = type.CreateInstance();
546   DALI_TEST_CHECK( hdl );
547
548   Actor a = Actor::DownCast(hdl);
549   DALI_TEST_CHECK( a );
550
551   a.SetVisible(false);
552
553   application.SendNotification();
554   application.Render(0);
555   DALI_TEST_CHECK(!a.IsVisible());
556
557   std::vector<Property::Value> attributes;
558
559   DALI_TEST_CHECK(hdl.DoAction(Actor::ACTION_SHOW, attributes));
560
561   application.SendNotification();
562   application.Render(0);
563   DALI_TEST_CHECK(a.IsVisible());
564
565   DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
566   END_TEST;
567 }
568
569 int UtcDaliTypeRegistryNames(void)
570 {
571   TestApplication application;
572
573   TypeInfo type;
574
575   TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
576
577   for(TypeRegistry::NameContainer::iterator iter = names.begin();
578       iter != names.end(); ++iter)
579   {
580     type = TypeRegistry::Get().GetTypeInfo( *iter );
581     DALI_TEST_CHECK( type );
582   }
583
584   END_TEST;
585 }
586
587 // Check named and typeid are equivalent
588 int UtcDaliTypeRegistryNameEquivalence(void)
589 {
590   TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "TextActor" );
591   TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::TextActor) );
592
593   DALI_TEST_CHECK( named_type );
594   DALI_TEST_CHECK( typeinfo_type );
595
596   DALI_TEST_CHECK( named_type == typeinfo_type );
597
598   DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
599   DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
600
601   END_TEST;
602 }
603
604
605 int UtcDaliTypeRegistryCustomActor(void)
606 {
607   ResetFunctorCounts();
608
609   TestApplication application;
610
611   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
612   DALI_TEST_CHECK( type );
613
614   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
615   DALI_TEST_CHECK( baseType );
616
617   BaseHandle handle = type.CreateInstance();
618   DALI_TEST_CHECK( handle );
619
620   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
621   DALI_TEST_CHECK( customHandle );
622
623   DALI_TEST_EQUALS( type.GetActions().size(), TEST_ACTION_COUNT + baseType.GetActions().size(), TEST_LOCATION );
624   DALI_TEST_EQUALS( type.GetSignals().size(), TEST_SIGNAL_COUNT + baseType.GetSignals().size(), TEST_LOCATION );
625
626   {
627     TestConnectionTracker tracker;
628
629     bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
630     DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
631     DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
632     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
633     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
634
635     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
636     customHandle.GetCustomSignal().Emit();
637     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
638     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
639     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
640   }
641   // tracker should automatically disconnect here
642   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
643   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
644
645   // Test that functor is disconnected
646   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
647   customHandle.GetCustomSignal().Emit();
648   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
649   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
650   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
651
652   std::vector<Property::Value> attributes;
653   handle.DoAction("act1", attributes);
654   DALI_TEST_CHECK( lastActionCustom == "act1" );
655   END_TEST;
656 }
657
658 int UtcDaliTypeRegistryCustomSignalFailure(void)
659 {
660   // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
661
662   ResetFunctorCounts();
663
664   TestApplication application;
665
666   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
667   DALI_TEST_CHECK( type );
668
669   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
670   DALI_TEST_CHECK( baseType );
671
672   BaseHandle handle = type.CreateInstance();
673   DALI_TEST_CHECK( handle );
674
675   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
676   DALI_TEST_CHECK( customHandle );
677
678   DALI_TEST_EQUALS( type.GetActions().size(), TEST_ACTION_COUNT + baseType.GetActions().size(), TEST_LOCATION );
679   DALI_TEST_EQUALS( type.GetSignals().size(), TEST_SIGNAL_COUNT + baseType.GetSignals().size(), TEST_LOCATION );
680
681   {
682     TestConnectionTracker tracker;
683
684     bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
685     DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
686     DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
687     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
688     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
689
690     // Should be a NOOP
691     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
692     customHandle.GetCustomSignal().Emit();
693     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
694   }
695   // tracker should have nothing to disconnect here
696
697   // Should be a NOOP
698   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
699   customHandle.GetCustomSignal().Emit();
700   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
701   END_TEST;
702 }
703
704
705
706 int UtcDaliTypeRegistryInitFunctions(void)
707 {
708   TestApplication application;
709
710   DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
711
712   DALI_TEST_CHECK( true == CreateCustomInitCalled );
713   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
714   DALI_TEST_CHECK( type );
715   END_TEST;
716 }
717
718
719
720
721 int UtcDaliTypeRegistryNameInitFunctions(void)
722 {
723   TestApplication application;
724
725   DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
726
727   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
728   DALI_TEST_CHECK( baseType );
729
730   BaseHandle handle = baseType.CreateInstance();
731
732   DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
733   TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
734   DALI_TEST_CHECK( type );
735   END_TEST;
736 }
737
738
739 int UtcDaliPropertyRegistration(void)
740 {
741   TestApplication application;
742   TypeRegistry typeRegistry = TypeRegistry::Get();
743
744   // Check property count before property registration
745   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
746   DALI_TEST_CHECK( typeInfo );
747   BaseHandle handle = typeInfo.CreateInstance();
748   DALI_TEST_CHECK( handle );
749   Actor customActor = Actor::DownCast( handle );
750   DALI_TEST_CHECK( customActor );
751   unsigned int initialPropertyCount( customActor.GetPropertyCount() );
752
753   std::string propertyName( "prop-1" );
754   int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
755   Property::Type propertyType( Property::BOOLEAN );
756   PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
757
758   // Check property count after registration
759   unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
760   DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
761
762   // Add custom property and check property count
763   customActor.RegisterProperty( "custom-prop-1", true );
764   unsigned int customPropertyCount( customActor.GetPropertyCount() );
765   DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
766
767   // Set the property, ensure SetProperty called
768   DALI_TEST_CHECK( !setPropertyCalled );
769   customActor.SetProperty( propertyIndex, false );
770   DALI_TEST_CHECK( setPropertyCalled );
771
772   // Get the property, ensure GetProperty called
773   DALI_TEST_CHECK( !getPropertyCalled );
774   (void)customActor.GetProperty< bool >( propertyIndex );
775   DALI_TEST_CHECK( getPropertyCalled );
776
777   // Check the property name
778   DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
779   DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
780
781   // Check the property index
782   DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
783
784   // Check the property type
785   DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
786
787   // Check property count of type-info is 1
788   Property::IndexContainer indices;
789   typeInfo.GetPropertyIndices( indices );
790   DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
791
792   // Ensure indices returned from actor and customActor differ by two
793   Actor actor = Actor::New();
794   actor.GetPropertyIndices( indices );
795   unsigned int actorIndices = indices.size();
796   customActor.GetPropertyIndices( indices );
797   unsigned int customActorIndices = indices.size();
798   DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
799   END_TEST;
800 }
801
802 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
803 {
804   TestApplication application;
805   TypeRegistry typeRegistry = TypeRegistry::Get();
806
807   // Attempt to register a property type out-of-bounds index (less than)
808   try
809   {
810     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
811     tet_result( TET_FAIL );
812   }
813   catch ( DaliException& e )
814   {
815     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
816   }
817
818   // Attempt to register a property type out-of-bounds index (greater than)
819   try
820   {
821     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
822     tet_result( TET_FAIL );
823   }
824   catch ( DaliException& e )
825   {
826     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
827   }
828   END_TEST;
829 }
830
831 int UtcDaliPropertyRegistrationFunctions(void)
832 {
833   TestApplication application;
834   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
835
836   // Attempt to register a property without a setter
837   try
838   {
839     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
840     tet_result( TET_PASS );
841   }
842   catch ( DaliException& e )
843   {
844     tet_result( TET_FAIL );
845   }
846
847   // Attempt to register a property without a getter
848   try
849   {
850     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
851     tet_result( TET_FAIL );
852   }
853   catch ( DaliException& e )
854   {
855     DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
856   }
857   END_TEST;
858 }
859
860 int UtcDaliPropertyRegistrationAddSameIndex(void)
861 {
862   TestApplication application;
863   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
864
865   // Add one property with a valid property index
866   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
867
868   // Attempt to add another property with the same index
869   try
870   {
871     PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
872   }
873   catch ( DaliException& e )
874   {
875     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
876   }
877   END_TEST;
878 }
879
880 int UtcDaliPropertyRegistrationPropertyWritable(void)
881 {
882   TestApplication application;
883   int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
884   int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
885
886   // Add two properties, one with SetProperty, one without
887   PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
888   PropertyRegistration property2( customType1, "prop-name-readonly",  propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
889
890   // Create custom-actor
891   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
892   DALI_TEST_CHECK( typeInfo );
893   BaseHandle handle = typeInfo.CreateInstance();
894   DALI_TEST_CHECK( handle );
895   Actor customActor = Actor::DownCast( handle );
896   DALI_TEST_CHECK( customActor );
897
898   // Check whether properties are writable
899   DALI_TEST_CHECK(   customActor.IsPropertyWritable( propertyIndex1 ) );
900   DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
901   END_TEST;
902 }
903
904 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
905 {
906   TestApplication application;
907   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
908
909   // These properties are not animatable
910   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
911
912   // Create custom-actor
913   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
914   DALI_TEST_CHECK( typeInfo );
915   BaseHandle handle = typeInfo.CreateInstance();
916   DALI_TEST_CHECK( handle );
917   Actor customActor = Actor::DownCast( handle );
918   DALI_TEST_CHECK( customActor );
919
920   // Check if animatable
921   DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
922   END_TEST;
923 }
924
925 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
926 {
927   TestApplication application;
928   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
929
930   // Create custom-actor
931   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
932   DALI_TEST_CHECK( typeInfo );
933   BaseHandle handle = typeInfo.CreateInstance();
934   DALI_TEST_CHECK( handle );
935   Actor customActor = Actor::DownCast( handle );
936   DALI_TEST_CHECK( customActor );
937
938   // Try to set an index that hasn't been added
939   try
940   {
941     customActor.SetProperty( propertyIndex, true );
942     tet_result( TET_FAIL );
943   }
944   catch ( DaliException& e )
945   {
946     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
947   }
948
949   // Try to get an index that hasn't been added
950   try
951   {
952     (void) customActor.GetProperty< bool >( propertyIndex );
953     tet_result( TET_FAIL );
954   }
955   catch ( DaliException& e )
956   {
957     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
958   }
959   END_TEST;
960 }
961
962
963
964 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
965 {
966   TestApplication application;
967
968   Actor actor = Actor::New();
969   actor.SetSize(100.0f, 100.0f);
970   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
971   Stage::GetCurrent().Add(actor);
972
973   // Register Type
974   TypeInfo type;
975   type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
976   DALI_TEST_CHECK( type );
977   BaseHandle handle = type.CreateInstance();
978   DALI_TEST_CHECK( handle );
979   LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
980   DALI_TEST_CHECK( detector );
981
982   // Attach actor to detector
983   SignalData data;
984   GestureReceivedFunctor functor( data );
985   detector.Attach(actor);
986
987   // Connect to signal through type
988   handle.ConnectSignal( &application, LongPressGestureDetector::SIGNAL_LONG_PRESS_DETECTED, functor );
989
990   // Render and notify
991   application.SendNotification();
992   application.Render();
993
994   // Emit gesture
995   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
996   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
997   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
998   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
999   END_TEST;
1000 }
1001
1002 int UtcDaliPanGestureDetectorTypeRegistry(void)
1003 {
1004   TestApplication application;
1005
1006   Actor actor = Actor::New();
1007   actor.SetSize(100.0f, 100.0f);
1008   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1009   Stage::GetCurrent().Add(actor);
1010
1011   // Register Type
1012   TypeInfo type;
1013   type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1014   DALI_TEST_CHECK( type );
1015   BaseHandle handle = type.CreateInstance();
1016   DALI_TEST_CHECK( handle );
1017   PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1018   DALI_TEST_CHECK( detector );
1019
1020   // Attach actor to detector
1021   SignalData data;
1022   GestureReceivedFunctor functor( data );
1023   detector.Attach(actor);
1024
1025   // Connect to signal through type
1026   handle.ConnectSignal( &application, PanGestureDetector::SIGNAL_PAN_DETECTED, functor );
1027
1028   // Render and notify
1029   application.SendNotification();
1030   application.Render();
1031
1032   // Emit gesture
1033   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1034   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1035   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1036   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1037   END_TEST;
1038 }
1039
1040 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1041 {
1042   TestApplication application;
1043
1044   Actor actor = Actor::New();
1045   actor.SetSize(100.0f, 100.0f);
1046   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1047   Stage::GetCurrent().Add(actor);
1048
1049   // Register Type
1050   TypeInfo type;
1051   type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1052   DALI_TEST_CHECK( type );
1053   BaseHandle handle = type.CreateInstance();
1054   DALI_TEST_CHECK( handle );
1055   PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1056   DALI_TEST_CHECK( detector );
1057
1058   // Attach actor to detector
1059   SignalData data;
1060   GestureReceivedFunctor functor( data );
1061   detector.Attach(actor);
1062
1063   // Connect to signal through type
1064   handle.ConnectSignal( &application, PinchGestureDetector::SIGNAL_PINCH_DETECTED, functor );
1065
1066   // Render and notify
1067   application.SendNotification();
1068   application.Render();
1069
1070   // Emit gesture
1071   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1072   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1073   END_TEST;
1074 }
1075
1076 int UtcDaliTapGestureDetectorTypeRegistry(void)
1077 {
1078   TestApplication application;
1079
1080   Actor actor = Actor::New();
1081   actor.SetSize(100.0f, 100.0f);
1082   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1083   Stage::GetCurrent().Add(actor);
1084
1085   // Register Type
1086   TypeInfo type;
1087   type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1088   DALI_TEST_CHECK( type );
1089   BaseHandle handle = type.CreateInstance();
1090   DALI_TEST_CHECK( handle );
1091   TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1092   DALI_TEST_CHECK( detector );
1093
1094   // Attach actor to detector
1095   SignalData data;
1096   GestureReceivedFunctor functor( data );
1097   detector.Attach(actor);
1098
1099   // Connect to signal through type
1100   handle.ConnectSignal( &application, TapGestureDetector::SIGNAL_TAP_DETECTED, functor );
1101
1102   // Render and notify
1103   application.SendNotification();
1104   application.Render();
1105
1106   // Emit gesture
1107   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1108   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1109   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1110   END_TEST;
1111 }