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