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