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 Actor GetChildByAlias(const std::string& actorAlias)
246   {
247     return Actor::New();
248   }
249
250   virtual Vector3 GetNaturalSize()
251   {
252     return Vector3( 0.0f, 0.0f, 0.0f );
253   }
254
255 public:
256
257   SignalType mSignal;
258 };
259
260 }; // namespace Impl
261
262 class MyTestCustomActor : public CustomActor
263 {
264 public:
265
266   typedef Signal< void ()> SignalType;
267   typedef Signal< void (float)> SignalTypeFloat;
268
269   MyTestCustomActor()
270   {
271   }
272
273   static MyTestCustomActor New()
274   {
275     Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
276     return MyTestCustomActor( *p ); // takes ownership
277   }
278
279   virtual ~MyTestCustomActor()
280   {
281   }
282
283   static MyTestCustomActor DownCast( BaseHandle handle )
284   {
285     MyTestCustomActor result;
286
287     CustomActor custom = Dali::CustomActor::DownCast( handle );
288     if ( custom )
289     {
290       CustomActorImpl& customImpl = custom.GetImplementation();
291
292       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
293
294       if (impl)
295       {
296         result = MyTestCustomActor(customImpl.GetOwner());
297       }
298     }
299
300     return result;
301   }
302
303   SignalType& GetCustomSignal()
304   {
305     Dali::RefObject& obj = GetImplementation();
306     return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
307   }
308
309 private:
310
311   MyTestCustomActor(Internal::CustomActor* internal)
312   : CustomActor(internal)
313   {
314   }
315
316   MyTestCustomActor( Impl::MyTestCustomActor& impl )
317   : CustomActor( impl )
318   {
319   }
320 };
321
322
323 class MyTestCustomActor2 : public CustomActor
324 {
325 public:
326
327   MyTestCustomActor2()
328   {
329   }
330
331   static MyTestCustomActor2 New()
332   {
333     return MyTestCustomActor2(); // takes ownership
334   }
335
336   virtual ~MyTestCustomActor2()
337   {
338   }
339
340   static MyTestCustomActor2 DownCast( BaseHandle handle )
341   {
342     MyTestCustomActor2 result;
343
344     CustomActor custom = Dali::CustomActor::DownCast( handle );
345     if ( custom )
346     {
347       CustomActorImpl& customImpl = custom.GetImplementation();
348
349       Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
350
351       if (impl)
352       {
353         result = MyTestCustomActor2(customImpl.GetOwner());
354       }
355     }
356
357     return result;
358   }
359
360 private:
361
362   MyTestCustomActor2(Internal::CustomActor* internal)
363   : CustomActor(internal)
364   {
365   }
366
367   MyTestCustomActor2( Impl::MyTestCustomActor& impl )
368   : CustomActor( impl )
369   {
370   }
371 };
372
373 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
374
375
376 BaseHandle CreateCustom(void)
377 {
378   return MyTestCustomActor::New();
379 }
380
381 static std::string lastSignalConnectionCustom;
382
383 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
384 {
385   lastSignalConnectionCustom = signalName;
386
387   bool connected( true );
388
389   Dali::BaseHandle handle(object);
390   MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
391
392   if( "sig1" == signalName )
393   {
394     customActor.GetCustomSignal().Connect( tracker, functor );
395   }
396   else
397   {
398     // signalName does not match any signal
399     connected = false;
400   }
401
402   return connected;
403 }
404
405 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
406 {
407   lastSignalConnectionCustom = "failed";
408
409   return false; // This is supposed to fail
410 }
411
412 struct CustomTestFunctor
413 {
414   CustomTestFunctor()
415   {
416     ++mTotalInstanceCount;
417     ++mCurrentInstanceCount;
418   }
419
420   CustomTestFunctor( const CustomTestFunctor& copyMe )
421   {
422     ++mTotalInstanceCount;
423     ++mCurrentInstanceCount;
424   }
425
426   ~CustomTestFunctor()
427   {
428     --mCurrentInstanceCount;
429   }
430
431   void operator()()
432   {
433     ++mCallbackCount;
434   }
435
436   static int mTotalInstanceCount;
437   static int mCurrentInstanceCount;
438   static int mCallbackCount;
439 };
440
441 int CustomTestFunctor::mTotalInstanceCount = 0;
442 int CustomTestFunctor::mCurrentInstanceCount = 0;
443 int CustomTestFunctor::mCallbackCount = 0;
444
445 static void ResetFunctorCounts()
446 {
447   CustomTestFunctor::mTotalInstanceCount   = 0;
448   CustomTestFunctor::mCurrentInstanceCount = 0;
449   CustomTestFunctor::mCallbackCount        = 0;
450 }
451
452 static std::string lastActionCustom;
453 bool DoActionCustom(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
454 {
455   lastActionCustom = actionName;
456   return true;
457 }
458
459 // Custom type registration
460 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
461
462 // Custom signals
463 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
464 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
465 static const int TEST_SIGNAL_COUNT = 2;
466
467 // Custom actions
468 static TypeAction customAction1( customType1, "act1", DoActionCustom);
469 static const int TEST_ACTION_COUNT = 1;
470
471 class TestConnectionTracker : public ConnectionTracker
472 {
473 public:
474
475   TestConnectionTracker()
476   {
477   }
478 };
479
480 BaseHandle CreateNamedActorType()
481 {
482   Actor actor = Actor::New();
483   actor.SetName( "NamedActor" );
484   return actor;
485 }
486
487 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
488 PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
489
490 } // Anonymous namespace
491
492
493 // Positive test case for a method
494 int UtcDaliTypeRegistryCreateDaliObjects(void)
495 {
496   TestApplication application;
497
498   TypeRegistry registry; // like this for ctor test coverage
499   registry = TypeRegistry::Get();
500
501   TypeInfo type;
502
503   type = registry.GetTypeInfo( "ImageActor" );
504   DALI_TEST_CHECK( type );
505   DALI_TEST_CHECK( type.GetCreator() );
506   DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
507   ImageActor ia = ImageActor::DownCast(type.CreateInstance());
508   DALI_TEST_CHECK( ia );
509   Stage::GetCurrent().Add( ia );
510   application.Render();
511
512   type = registry.GetTypeInfo( "CameraActor" );
513   DALI_TEST_CHECK( type );
514   CameraActor ca = CameraActor::DownCast(type.CreateInstance());
515   DALI_TEST_CHECK( ca );
516   Stage::GetCurrent().Add( ca );
517   application.Render();
518
519   // animations
520   type = registry.GetTypeInfo( "Animation" );
521   DALI_TEST_CHECK( type );
522   Animation an = Animation::DownCast(type.CreateInstance());
523   DALI_TEST_CHECK( an );
524   an.Play();
525   application.Render();
526
527   //
528   type = registry.GetTypeInfo( "ShaderEffect" );
529   DALI_TEST_CHECK( type );
530   ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
531   DALI_TEST_CHECK( ef );
532   application.Render();
533
534   END_TEST;
535 }
536
537 /*******************************************************************************
538  *
539  * Action through the base handle
540  *
541  ******************************************************************************/
542 int UtcDaliTypeRegistryActionViaBaseHandle(void)
543 {
544   TestApplication application;
545
546   TypeInfo type;
547
548   type = TypeRegistry::Get().GetTypeInfo( "Actor" );
549   DALI_TEST_CHECK( type );
550
551   BaseHandle hdl = type.CreateInstance();
552   DALI_TEST_CHECK( hdl );
553
554   Actor a = Actor::DownCast(hdl);
555   DALI_TEST_CHECK( a );
556
557   a.SetVisible(false);
558
559   application.SendNotification();
560   application.Render(0);
561   DALI_TEST_CHECK(!a.IsVisible());
562
563   std::vector<Property::Value> attributes;
564
565   DALI_TEST_CHECK(hdl.DoAction("show", attributes));
566
567   application.SendNotification();
568   application.Render(0);
569   DALI_TEST_CHECK(a.IsVisible());
570
571   DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
572   END_TEST;
573 }
574
575 int UtcDaliTypeRegistryNames(void)
576 {
577   TestApplication application;
578
579   TypeInfo type;
580
581   TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
582
583   for(TypeRegistry::NameContainer::iterator iter = names.begin();
584       iter != names.end(); ++iter)
585   {
586     type = TypeRegistry::Get().GetTypeInfo( *iter );
587     DALI_TEST_CHECK( type );
588   }
589
590   END_TEST;
591 }
592
593 // Check named and typeid are equivalent
594 int UtcDaliTypeRegistryNameEquivalence(void)
595 {
596   TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
597   TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
598
599   DALI_TEST_CHECK( named_type );
600   DALI_TEST_CHECK( typeinfo_type );
601
602   DALI_TEST_CHECK( named_type == typeinfo_type );
603
604   DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
605   DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
606
607   END_TEST;
608 }
609
610
611 int UtcDaliTypeRegistryCustomActor(void)
612 {
613   ResetFunctorCounts();
614
615   TestApplication application;
616
617   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
618   DALI_TEST_CHECK( type );
619
620   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
621   DALI_TEST_CHECK( baseType );
622
623   BaseHandle handle = type.CreateInstance();
624   DALI_TEST_CHECK( handle );
625
626   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
627   DALI_TEST_CHECK( customHandle );
628
629   TypeInfo::NameContainer names;
630   type.GetActions(names);
631   TypeInfo::NameContainer baseNames;
632   baseType.GetActions(baseNames);
633   DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
634
635   names.clear();
636   type.GetSignals(names);
637
638   baseNames.clear();
639   baseType.GetSignals(baseNames);
640
641   DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
642
643   {
644     TestConnectionTracker tracker;
645
646     bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
647     DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
648     DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
649     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
650     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
651
652     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
653     customHandle.GetCustomSignal().Emit();
654     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
655     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
656     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
657   }
658   // tracker should automatically disconnect here
659   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
660   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
661
662   // Test that functor is disconnected
663   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
664   customHandle.GetCustomSignal().Emit();
665   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
666   DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
667   DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
668
669   std::vector<Property::Value> attributes;
670   handle.DoAction("act1", attributes);
671   DALI_TEST_CHECK( lastActionCustom == "act1" );
672   END_TEST;
673 }
674
675 int UtcDaliTypeRegistryCustomSignalFailure(void)
676 {
677   // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
678
679   ResetFunctorCounts();
680
681   TestApplication application;
682
683   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
684   DALI_TEST_CHECK( type );
685
686   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
687   DALI_TEST_CHECK( baseType );
688
689   BaseHandle handle = type.CreateInstance();
690   DALI_TEST_CHECK( handle );
691
692   MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
693   DALI_TEST_CHECK( customHandle );
694
695   TypeInfo::NameContainer names;
696   TypeInfo::NameContainer baseNames;
697
698   type.GetActions(names);
699   baseType.GetActions(baseNames);
700
701   DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
702
703   names.clear();
704   baseNames.clear();
705
706   type.GetSignals(names);
707   baseType.GetSignals(baseNames);
708
709   DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
710
711   {
712     TestConnectionTracker tracker;
713
714     bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
715     DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
716     DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
717     DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
718     DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
719
720     // Should be a NOOP
721     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
722     customHandle.GetCustomSignal().Emit();
723     DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
724   }
725   // tracker should have nothing to disconnect here
726
727   // Should be a NOOP
728   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
729   customHandle.GetCustomSignal().Emit();
730   DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
731   END_TEST;
732 }
733
734
735
736 int UtcDaliTypeRegistryInitFunctions(void)
737 {
738   TestApplication application;
739
740   DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
741
742   DALI_TEST_CHECK( true == CreateCustomInitCalled );
743   TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
744   DALI_TEST_CHECK( type );
745   END_TEST;
746 }
747
748
749
750
751 int UtcDaliTypeRegistryNameInitFunctions(void)
752 {
753   TestApplication application;
754
755   DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
756
757   TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
758   DALI_TEST_CHECK( baseType );
759
760   BaseHandle handle = baseType.CreateInstance();
761
762   DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
763   TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
764   DALI_TEST_CHECK( type );
765   END_TEST;
766 }
767
768
769 int UtcDaliPropertyRegistration(void)
770 {
771   TestApplication application;
772   TypeRegistry typeRegistry = TypeRegistry::Get();
773
774   // Check property count before property registration
775   TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
776   DALI_TEST_CHECK( typeInfo );
777   BaseHandle handle = typeInfo.CreateInstance();
778   DALI_TEST_CHECK( handle );
779   Actor customActor = Actor::DownCast( handle );
780   DALI_TEST_CHECK( customActor );
781   unsigned int initialPropertyCount( customActor.GetPropertyCount() );
782
783   std::string propertyName( "prop-1" );
784   int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
785   Property::Type propertyType( Property::BOOLEAN );
786   PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
787
788   // Check property count after registration
789   unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
790   DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
791
792   // Add custom property and check property count
793   customActor.RegisterProperty( "custom-prop-1", true );
794   unsigned int customPropertyCount( customActor.GetPropertyCount() );
795   DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
796
797   // Set the property, ensure SetProperty called
798   DALI_TEST_CHECK( !setPropertyCalled );
799   customActor.SetProperty( propertyIndex, false );
800   DALI_TEST_CHECK( setPropertyCalled );
801
802   // Get the property, ensure GetProperty called
803   DALI_TEST_CHECK( !getPropertyCalled );
804   (void)customActor.GetProperty< bool >( propertyIndex );
805   DALI_TEST_CHECK( getPropertyCalled );
806
807   // Check the property name
808   DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
809   DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
810
811   // Check the property index
812   DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
813
814   // Check the property type
815   DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
816
817   // Check property count of type-info is 1
818   Property::IndexContainer indices;
819   typeInfo.GetPropertyIndices( indices );
820   DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
821
822   // Ensure indices returned from actor and customActor differ by two
823   Actor actor = Actor::New();
824   actor.GetPropertyIndices( indices );
825   unsigned int actorIndices = indices.size();
826   customActor.GetPropertyIndices( indices );
827   unsigned int customActorIndices = indices.size();
828   DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
829   END_TEST;
830 }
831
832 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
833 {
834   TestApplication application;
835   TypeRegistry typeRegistry = TypeRegistry::Get();
836
837   // Attempt to register a property type out-of-bounds index (less than)
838   try
839   {
840     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
841     tet_result( TET_FAIL );
842   }
843   catch ( DaliException& e )
844   {
845     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
846   }
847
848   // Attempt to register a property type out-of-bounds index (greater than)
849   try
850   {
851     PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
852     tet_result( TET_FAIL );
853   }
854   catch ( DaliException& e )
855   {
856     DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
857   }
858   END_TEST;
859 }
860
861 int UtcDaliPropertyRegistrationFunctions(void)
862 {
863   TestApplication application;
864   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
865
866   // Attempt to register a property without a setter
867   try
868   {
869     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
870     tet_result( TET_PASS );
871   }
872   catch ( DaliException& e )
873   {
874     tet_result( TET_FAIL );
875   }
876
877   // Attempt to register a property without a getter
878   try
879   {
880     PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
881     tet_result( TET_FAIL );
882   }
883   catch ( DaliException& e )
884   {
885     DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
886   }
887   END_TEST;
888 }
889
890 int UtcDaliPropertyRegistrationAddSameIndex(void)
891 {
892   TestApplication application;
893   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
894
895   // Add one property with a valid property index
896   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
897
898   // Attempt to add another property with the same index
899   try
900   {
901     PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
902   }
903   catch ( DaliException& e )
904   {
905     DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
906   }
907   END_TEST;
908 }
909
910 int UtcDaliPropertyRegistrationPropertyWritable(void)
911 {
912   TestApplication application;
913   int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
914   int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
915
916   // Add two properties, one with SetProperty, one without
917   PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
918   PropertyRegistration property2( customType1, "prop-name-readonly",  propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
919
920   // Create custom-actor
921   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
922   DALI_TEST_CHECK( typeInfo );
923   BaseHandle handle = typeInfo.CreateInstance();
924   DALI_TEST_CHECK( handle );
925   Actor customActor = Actor::DownCast( handle );
926   DALI_TEST_CHECK( customActor );
927
928   // Check whether properties are writable
929   DALI_TEST_CHECK(   customActor.IsPropertyWritable( propertyIndex1 ) );
930   DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
931   END_TEST;
932 }
933
934 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
935 {
936   TestApplication application;
937   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
938
939   // These properties are not animatable
940   PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
941
942   // Create custom-actor
943   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
944   DALI_TEST_CHECK( typeInfo );
945   BaseHandle handle = typeInfo.CreateInstance();
946   DALI_TEST_CHECK( handle );
947   Actor customActor = Actor::DownCast( handle );
948   DALI_TEST_CHECK( customActor );
949
950   // Check if animatable
951   DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
952   END_TEST;
953 }
954
955 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
956 {
957   TestApplication application;
958   int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
959
960   // Create custom-actor
961   TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
962   DALI_TEST_CHECK( typeInfo );
963   BaseHandle handle = typeInfo.CreateInstance();
964   DALI_TEST_CHECK( handle );
965   Actor customActor = Actor::DownCast( handle );
966   DALI_TEST_CHECK( customActor );
967
968   // Try to set an index that hasn't been added
969   try
970   {
971     customActor.SetProperty( propertyIndex, true );
972     tet_result( TET_FAIL );
973   }
974   catch ( DaliException& e )
975   {
976     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
977   }
978
979   // Try to get an index that hasn't been added
980   try
981   {
982     (void) customActor.GetProperty< bool >( propertyIndex );
983     tet_result( TET_FAIL );
984   }
985   catch ( DaliException& e )
986   {
987     DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
988   }
989   END_TEST;
990 }
991
992
993
994 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
995 {
996   TestApplication application;
997
998   Actor actor = Actor::New();
999   actor.SetSize(100.0f, 100.0f);
1000   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1001   Stage::GetCurrent().Add(actor);
1002
1003   // Register Type
1004   TypeInfo type;
1005   type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1006   DALI_TEST_CHECK( type );
1007   BaseHandle handle = type.CreateInstance();
1008   DALI_TEST_CHECK( handle );
1009   LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1010   DALI_TEST_CHECK( detector );
1011
1012   // Attach actor to detector
1013   SignalData data;
1014   GestureReceivedFunctor functor( data );
1015   detector.Attach(actor);
1016
1017   // Connect to signal through type
1018   handle.ConnectSignal( &application, "long-press-detected", functor );
1019
1020   // Render and notify
1021   application.SendNotification();
1022   application.Render();
1023
1024   // Emit gesture
1025   application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1026   application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1027   application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1028   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1029   END_TEST;
1030 }
1031
1032 int UtcDaliPanGestureDetectorTypeRegistry(void)
1033 {
1034   TestApplication application;
1035
1036   Actor actor = Actor::New();
1037   actor.SetSize(100.0f, 100.0f);
1038   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1039   Stage::GetCurrent().Add(actor);
1040
1041   // Register Type
1042   TypeInfo type;
1043   type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1044   DALI_TEST_CHECK( type );
1045   BaseHandle handle = type.CreateInstance();
1046   DALI_TEST_CHECK( handle );
1047   PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1048   DALI_TEST_CHECK( detector );
1049
1050   // Attach actor to detector
1051   SignalData data;
1052   GestureReceivedFunctor functor( data );
1053   detector.Attach(actor);
1054
1055   // Connect to signal through type
1056   handle.ConnectSignal( &application, "pan-detected", functor );
1057
1058   // Render and notify
1059   application.SendNotification();
1060   application.Render();
1061
1062   // Emit gesture
1063   application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1064   application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1065   application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1066   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1067   END_TEST;
1068 }
1069
1070 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1071 {
1072   TestApplication application;
1073
1074   Actor actor = Actor::New();
1075   actor.SetSize(100.0f, 100.0f);
1076   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1077   Stage::GetCurrent().Add(actor);
1078
1079   // Register Type
1080   TypeInfo type;
1081   type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1082   DALI_TEST_CHECK( type );
1083   BaseHandle handle = type.CreateInstance();
1084   DALI_TEST_CHECK( handle );
1085   PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1086   DALI_TEST_CHECK( detector );
1087
1088   // Attach actor to detector
1089   SignalData data;
1090   GestureReceivedFunctor functor( data );
1091   detector.Attach(actor);
1092
1093   // Connect to signal through type
1094   handle.ConnectSignal( &application, "pinch-detected", functor );
1095
1096   // Render and notify
1097   application.SendNotification();
1098   application.Render();
1099
1100   // Emit gesture
1101   application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1102   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1103   END_TEST;
1104 }
1105
1106 int UtcDaliTapGestureDetectorTypeRegistry(void)
1107 {
1108   TestApplication application;
1109
1110   Actor actor = Actor::New();
1111   actor.SetSize(100.0f, 100.0f);
1112   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1113   Stage::GetCurrent().Add(actor);
1114
1115   // Register Type
1116   TypeInfo type;
1117   type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1118   DALI_TEST_CHECK( type );
1119   BaseHandle handle = type.CreateInstance();
1120   DALI_TEST_CHECK( handle );
1121   TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1122   DALI_TEST_CHECK( detector );
1123
1124   // Attach actor to detector
1125   SignalData data;
1126   GestureReceivedFunctor functor( data );
1127   detector.Attach(actor);
1128
1129   // Connect to signal through type
1130   handle.ConnectSignal( &application, "tap-detected", functor );
1131
1132   // Render and notify
1133   application.SendNotification();
1134   application.Render();
1135
1136   // Emit gesture
1137   application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1138   application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1139   DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1140   END_TEST;
1141 }
1142
1143 int UtcDaliTypeRegistryNamedType(void)
1144 {
1145   TestApplication application;
1146   TypeRegistry typeRegistry = TypeRegistry::Get();
1147
1148   // Create a normal actor
1149   BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1150   DALI_TEST_CHECK( actorHandle );
1151   Actor actor( Actor::DownCast( actorHandle ) );
1152   DALI_TEST_CHECK( actor );
1153   unsigned int actorPropertyCount( actor.GetPropertyCount() );
1154
1155   // Create Named Actor Type
1156   BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1157   DALI_TEST_CHECK( namedHandle );
1158   Actor namedActor( Actor::DownCast( namedHandle ) );
1159   DALI_TEST_CHECK( namedActor );
1160   unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1161
1162   DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1163   END_TEST;
1164 }