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