2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <dali/integration-api/events/long-press-gesture-event.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25 #include <dali/integration-api/events/pinch-gesture-event.h>
26 #include <dali/integration-api/events/tap-gesture-event.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28 #include <dali/integration-api/events/hover-event-integ.h>
36 // Stores data that is populated in the callback and will be read by the Test cases
40 : functorCalled( false ),
41 voidFunctorCalled( false ),
42 receivedGesture( Gesture::Clear ),
48 functorCalled = false;
49 voidFunctorCalled = false;
51 receivedGesture.numberOfTouches = 0u;
52 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
53 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
59 bool voidFunctorCalled;
60 LongPressGesture receivedGesture;
64 // Functor that sets the data when called
65 struct GestureReceivedFunctor
67 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
69 void operator()(Actor actor, LongPressGesture longPress)
71 signalData.functorCalled = true;
72 signalData.receivedGesture = longPress;
73 signalData.pressedActor = actor;
78 signalData.voidFunctorCalled = true;
81 SignalData& signalData;
84 // Generate a LongPressGestureEvent to send to Core
85 Integration::LongPressGestureEvent GenerateLongPress(
87 unsigned int numberOfTouches,
90 Integration::LongPressGestureEvent longPress( state );
92 longPress.numberOfTouches = numberOfTouches;
93 longPress.point = point;
98 // Generate a PanGestureEvent to send to Core
99 Integration::PanGestureEvent GeneratePan(
100 Gesture::State state,
101 Vector2 previousPosition,
102 Vector2 currentPosition,
103 unsigned long timeDelta,
104 unsigned int numberOfTouches = 1,
105 unsigned int time = 1u)
107 Integration::PanGestureEvent pan(state);
109 pan.previousPosition = previousPosition;
110 pan.currentPosition = currentPosition;
111 pan.timeDelta = timeDelta;
112 pan.numberOfTouches = numberOfTouches;
117 // Generate a PinchGestureEvent to send to Core
118 Integration::PinchGestureEvent GeneratePinch(
119 Gesture::State state,
124 Integration::PinchGestureEvent pinch(state);
128 pinch.centerPoint = centerpoint;
132 // Generate a TapGestureEvent to send to Core
133 Integration::TapGestureEvent GenerateTap(
134 Gesture::State state,
135 unsigned int numberOfTaps,
136 unsigned int numberOfTouches,
139 Integration::TapGestureEvent tap( state );
141 tap.numberOfTaps = numberOfTaps;
142 tap.numberOfTouches = numberOfTouches;
149 // Create function as Init function called
151 static bool CreateCustomInitCalled = false;
152 BaseHandle CreateCustomInit(void)
154 CreateCustomInitCalled = true;
158 static bool CreateCustomNamedInitCalled = false;
159 BaseHandle CreateCustomNamedInit(void)
161 CreateCustomNamedInitCalled = true;
165 const std::string scriptedName("PopupStyle");
166 static TypeRegistration scriptedType( scriptedName, typeid(Dali::CustomActor), CreateCustomNamedInit );
168 // Property Registration
169 bool setPropertyCalled = false;
170 bool getPropertyCalled = false;
171 void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
173 setPropertyCalled = true;
175 Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex )
177 getPropertyCalled = true;
178 return Property::Value( true );
183 /*******************************************************************************
187 ******************************************************************************/
190 struct MyTestCustomActor : public CustomActorImpl
192 typedef Signal< void ()> SignalType;
193 typedef Signal< void (float)> SignalTypeFloat;
195 MyTestCustomActor() : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS ) )
198 virtual ~MyTestCustomActor()
201 void ResetCallStack()
205 // From CustomActorImpl
206 virtual void OnStageConnection( int depth )
209 virtual void OnStageDisconnection()
212 virtual void OnChildAdd(Actor& child)
215 virtual void OnChildRemove(Actor& child)
218 virtual void OnSizeSet(const Vector3& targetSize)
221 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
224 virtual bool OnTouchEvent(const TouchEvent& event)
228 virtual bool OnHoverEvent(const HoverEvent& event)
232 virtual bool OnWheelEvent(const WheelEvent& event)
236 virtual bool OnKeyEvent(const KeyEvent& event)
240 virtual void OnKeyInputFocusGained()
243 virtual void OnKeyInputFocusLost()
246 virtual Vector3 GetNaturalSize()
248 return Vector3( 0.0f, 0.0f, 0.0f );
251 virtual float GetHeightForWidth( float width )
256 virtual float GetWidthForHeight( float height )
261 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
265 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
269 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
273 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
278 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
282 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
294 class MyTestCustomActor : public CustomActor
298 typedef Signal< void ()> SignalType;
299 typedef Signal< void (float)> SignalTypeFloat;
305 static MyTestCustomActor New()
307 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
308 return MyTestCustomActor( *p ); // takes ownership
311 virtual ~MyTestCustomActor()
315 static MyTestCustomActor DownCast( BaseHandle handle )
317 MyTestCustomActor result;
319 CustomActor custom = Dali::CustomActor::DownCast( handle );
322 CustomActorImpl& customImpl = custom.GetImplementation();
324 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
328 result = MyTestCustomActor(customImpl.GetOwner());
335 SignalType& GetCustomSignal()
337 Dali::RefObject& obj = GetImplementation();
338 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
343 MyTestCustomActor(Internal::CustomActor* internal)
344 : CustomActor(internal)
348 MyTestCustomActor( Impl::MyTestCustomActor& impl )
349 : CustomActor( impl )
355 class MyTestCustomActor2 : public CustomActor
363 static MyTestCustomActor2 New()
365 return MyTestCustomActor2(); // takes ownership
368 virtual ~MyTestCustomActor2()
372 static MyTestCustomActor2 DownCast( BaseHandle handle )
374 MyTestCustomActor2 result;
376 CustomActor custom = Dali::CustomActor::DownCast( handle );
379 CustomActorImpl& customImpl = custom.GetImplementation();
381 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
385 result = MyTestCustomActor2(customImpl.GetOwner());
394 MyTestCustomActor2(Internal::CustomActor* internal)
395 : CustomActor(internal)
399 MyTestCustomActor2( Impl::MyTestCustomActor& impl )
400 : CustomActor( impl )
405 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
408 BaseHandle CreateCustom(void)
410 return MyTestCustomActor::New();
413 static std::string lastSignalConnectionCustom;
415 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
417 lastSignalConnectionCustom = signalName;
419 bool connected( true );
421 Dali::BaseHandle handle(object);
422 MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
424 if( "sig1" == signalName )
426 customActor.GetCustomSignal().Connect( tracker, functor );
430 // signalName does not match any signal
437 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
439 lastSignalConnectionCustom = "failed";
441 return false; // This is supposed to fail
444 struct CustomTestFunctor
448 ++mTotalInstanceCount;
449 ++mCurrentInstanceCount;
452 CustomTestFunctor( const CustomTestFunctor& copyMe )
454 ++mTotalInstanceCount;
455 ++mCurrentInstanceCount;
460 --mCurrentInstanceCount;
468 static int mTotalInstanceCount;
469 static int mCurrentInstanceCount;
470 static int mCallbackCount;
473 int CustomTestFunctor::mTotalInstanceCount = 0;
474 int CustomTestFunctor::mCurrentInstanceCount = 0;
475 int CustomTestFunctor::mCallbackCount = 0;
477 static void ResetFunctorCounts()
479 CustomTestFunctor::mTotalInstanceCount = 0;
480 CustomTestFunctor::mCurrentInstanceCount = 0;
481 CustomTestFunctor::mCallbackCount = 0;
484 static std::string lastActionCustom;
485 bool DoActionCustom(BaseObject* object, const std::string& actionName, const Property::Map& /*attributes*/)
487 lastActionCustom = actionName;
491 // Custom type registration
492 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
495 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
496 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
497 static const int TEST_SIGNAL_COUNT = 2;
500 static TypeAction customAction1( customType1, "act1", DoActionCustom);
501 static const int TEST_ACTION_COUNT = 1;
503 class TestConnectionTracker : public ConnectionTracker
507 TestConnectionTracker()
512 BaseHandle CreateNamedActorType()
514 Actor actor = Actor::New();
515 actor.SetName( "NamedActor" );
519 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
520 PropertyRegistration namedActorPropertyOne( namedActorType, "propName", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
522 } // Anonymous namespace
524 // Note: No negative test case for UtcDaliTypeRegistryGet can be implemented.
525 int UtcDaliTypeRegistryGetP(void)
527 TestApplication application;
529 TypeRegistry registry = TypeRegistry::Get();
530 DALI_TEST_CHECK( registry );
535 // Note: No negative test case for UtcDaliTypeRegistryConstructor can be implemented.
536 int UtcDaliTypeRegistryConstructorP(void)
538 TestApplication application;
540 TypeRegistry registry;
541 DALI_TEST_CHECK( !registry );
545 // Note: No negative test case for UtcDaliTypeRegistryCopyConstructor can be implemented.
546 int UtcDaliTypeRegistryCopyConstructorP(void)
548 TestApplication application;
550 TypeRegistry registry = TypeRegistry::Get();
551 DALI_TEST_CHECK( registry );
553 TypeRegistry copy( registry );
554 DALI_TEST_CHECK( copy );
556 DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
561 // Note: No negative test case for UtcDaliTypeRegistryAssignmentOperator can be implemented.
562 int UtcDaliTypeRegistryAssignmentOperatorP(void)
564 TestApplication application;
566 TypeRegistry registry = TypeRegistry::Get();
567 DALI_TEST_CHECK( registry );
569 TypeRegistry copy = registry;
570 DALI_TEST_CHECK( copy );
571 DALI_TEST_CHECK( registry == copy );
573 DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
578 int UtcDaliTypeRegistryAssignP(void)
580 TestApplication application;
582 TypeRegistry registry = TypeRegistry::Get();
583 TypeRegistry registry2;
584 registry2 = registry;
585 DALI_TEST_CHECK( registry2 );
587 DALI_TEST_CHECK( registry2.GetTypeInfo( "Actor" ).GetName() == registry2.GetTypeInfo( "Actor" ).GetName() );
592 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameP(void)
594 TestApplication application;
596 TypeRegistry registry = TypeRegistry::Get();
601 type = registry.GetTypeInfo( "ImageActor" );
602 DALI_TEST_CHECK( type );
603 DALI_TEST_CHECK( type.GetCreator() );
604 DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
605 ImageActor ia = ImageActor::DownCast(type.CreateInstance());
606 DALI_TEST_CHECK( ia );
607 Stage::GetCurrent().Add( ia );
608 application.Render();
611 type = registry.GetTypeInfo( "CameraActor" );
612 DALI_TEST_CHECK( type );
613 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
614 DALI_TEST_CHECK( ca );
615 Stage::GetCurrent().Add( ca );
616 application.Render();
619 type = registry.GetTypeInfo( "Animation" );
620 DALI_TEST_CHECK( type );
621 Animation an = Animation::DownCast(type.CreateInstance());
622 DALI_TEST_CHECK( an );
624 application.Render();
627 type = registry.GetTypeInfo( "ShaderEffect" );
628 DALI_TEST_CHECK( type );
629 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
630 DALI_TEST_CHECK( ef );
631 application.Render();
636 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameN(void)
638 TestApplication application;
640 TypeRegistry registry = TypeRegistry::Get();
644 type = registry.GetTypeInfo( "MyDummyActor" );
645 DALI_TEST_CHECK( !type );
650 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdP(void)
652 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
653 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
655 DALI_TEST_CHECK( named_type );
656 DALI_TEST_CHECK( typeinfo_type );
658 // Check named and typeid are equivalent
659 DALI_TEST_CHECK( named_type == typeinfo_type );
661 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
662 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
667 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdN(void)
669 TestApplication application;
670 TypeRegistry typeRegistry = TypeRegistry::Get();
672 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(Vector2) );
673 DALI_TEST_CHECK( !typeInfo );
678 int UtcDaliTypeRegistryGetTypeNameCountP(void)
680 TestApplication application;
681 TypeRegistry typeRegistry = TypeRegistry::Get();
684 for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
686 type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
687 DALI_TEST_CHECK( type );
694 int UtcDaliTypeRegistryGetTypeNamesP(void)
696 TestApplication application;
697 TypeRegistry typeRegistry = TypeRegistry::Get();
700 for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
702 type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
703 DALI_TEST_CHECK( type );
710 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
711 int UtcDaliTypeRegistryTypeRegistrationNotCallingCreateOnInitP(void)
713 ResetFunctorCounts();
715 TestApplication application;
717 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
718 DALI_TEST_CHECK( type );
720 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
721 DALI_TEST_CHECK( baseType );
723 BaseHandle handle = type.CreateInstance();
724 DALI_TEST_CHECK( handle );
726 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
727 DALI_TEST_CHECK( customHandle );
729 DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
731 DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
734 TestConnectionTracker tracker;
736 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
737 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
738 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
739 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
740 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
742 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
743 customHandle.GetCustomSignal().Emit();
744 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
745 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
746 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
748 // tracker should automatically disconnect here
749 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
750 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
752 // Test that functor is disconnected
753 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
754 customHandle.GetCustomSignal().Emit();
755 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
756 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
757 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
759 Property::Map attributes;
760 handle.DoAction("act1", attributes);
761 DALI_TEST_CHECK( lastActionCustom == "act1" );
765 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
766 int UtcDaliTypeRegistryTypeRegistrationCallingCreateOnInitP(void)
768 TestApplication application;
770 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
772 DALI_TEST_CHECK( true == CreateCustomInitCalled );
773 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
774 DALI_TEST_CHECK( type );
778 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
779 int UtcDaliTypeRegistryTypeRegistrationForNamedTypeP(void)
781 TestApplication application;
783 // Create Named Actor Type
784 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyNamedActor" );
785 DALI_TEST_CHECK( type );
787 BaseHandle namedHandle = type.CreateInstance();
788 DALI_TEST_CHECK( namedHandle );
789 Actor namedActor( Actor::DownCast( namedHandle ) );
790 DALI_TEST_CHECK( namedActor );
792 DALI_TEST_CHECK( namedActor.GetName() == "NamedActor" );
793 DALI_TEST_CHECK( type.GetName() == "MyNamedActor" );
794 DALI_TEST_CHECK( type.GetBaseName() == "Actor" );
799 // Note: No negative test case for UtcDaliTypeRegistryRegisteredName can be implemented.
800 int UtcDaliTypeRegistryRegisteredNameP(void)
802 TestApplication application;
804 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
806 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
807 DALI_TEST_CHECK( baseType );
809 BaseHandle handle = baseType.CreateInstance();
811 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
812 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
813 DALI_TEST_CHECK( type );
817 int UtcDaliTypeRegistrySignalConnectorTypeP(void)
819 ResetFunctorCounts();
821 TestApplication application;
823 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
824 DALI_TEST_CHECK( type );
826 BaseHandle handle = type.CreateInstance();
827 DALI_TEST_CHECK( handle );
829 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
830 DALI_TEST_CHECK( customHandle );
833 TestConnectionTracker tracker;
835 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
836 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
837 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
838 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
839 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
841 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
842 customHandle.GetCustomSignal().Emit();
843 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
844 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
845 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
847 // tracker should automatically disconnect here
848 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
849 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
851 // Test that functor is disconnected
852 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
853 customHandle.GetCustomSignal().Emit();
854 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
855 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
856 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
861 int UtcDaliTypeRegistrySignalConnectorTypeN(void)
863 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
865 ResetFunctorCounts();
867 TestApplication application;
869 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
870 DALI_TEST_CHECK( type );
872 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
873 DALI_TEST_CHECK( baseType );
875 BaseHandle handle = type.CreateInstance();
876 DALI_TEST_CHECK( handle );
878 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
879 DALI_TEST_CHECK( customHandle );
881 DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
883 DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
886 TestConnectionTracker tracker;
888 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
889 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
890 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
891 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
892 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
895 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
896 customHandle.GetCustomSignal().Emit();
897 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
899 // tracker should have nothing to disconnect here
902 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
903 customHandle.GetCustomSignal().Emit();
904 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
908 int UtcDaliTypeRegistryTypeActionP(void)
910 ResetFunctorCounts();
912 TestApplication application;
914 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
915 DALI_TEST_CHECK( type );
917 BaseHandle handle = type.CreateInstance();
918 DALI_TEST_CHECK( handle );
920 Property::Map attributes;
921 DALI_TEST_CHECK( handle.DoAction("act1", attributes) );
922 DALI_TEST_CHECK( lastActionCustom == "act1" );
927 int UtcDaliTypeRegistryTypeActionN(void)
929 ResetFunctorCounts();
931 TestApplication application;
933 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
934 DALI_TEST_CHECK( type );
936 BaseHandle handle = type.CreateInstance();
937 DALI_TEST_CHECK( handle );
939 Property::Map attributes;
940 DALI_TEST_CHECK( !handle.DoAction( "unknownAction", attributes ) );
945 int UtcDaliTypeRegistryPropertyRegistrationP(void)
947 TestApplication application;
948 TypeRegistry typeRegistry = TypeRegistry::Get();
950 // Check property count before property registration
951 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
952 DALI_TEST_CHECK( typeInfo );
953 BaseHandle handle = typeInfo.CreateInstance();
954 DALI_TEST_CHECK( handle );
955 Actor customActor = Actor::DownCast( handle );
956 DALI_TEST_CHECK( customActor );
957 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
959 std::string propertyName( "prop1" );
960 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
961 Property::Type propertyType( Property::BOOLEAN );
962 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
964 // Check property count after registration
965 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
966 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
968 // Add custom property and check property count
969 customActor.RegisterProperty( "customProp1", true );
970 unsigned int customPropertyCount( customActor.GetPropertyCount() );
971 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
973 // Set the property, ensure SetProperty called
974 DALI_TEST_CHECK( !setPropertyCalled );
975 customActor.SetProperty( propertyIndex, false );
976 DALI_TEST_CHECK( setPropertyCalled );
978 // Get the property, ensure GetProperty called
979 DALI_TEST_CHECK( !getPropertyCalled );
980 (void)customActor.GetProperty< bool >( propertyIndex );
981 DALI_TEST_CHECK( getPropertyCalled );
983 // Check the property name
984 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
985 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
987 // Check the property index
988 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
990 // Check the property type
991 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
993 // Check property count of type-info is 1
994 Property::IndexContainer indices;
995 typeInfo.GetPropertyIndices( indices );
996 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
998 // Ensure indices returned from actor and customActor differ by two
999 Actor actor = Actor::New();
1000 actor.GetPropertyIndices( indices );
1001 unsigned int actorIndices = indices.Size();
1002 customActor.GetPropertyIndices( indices );
1003 unsigned int customActorIndices = indices.Size();
1004 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1008 int UtcDaliTypeRegistryPropertyRegistrationN(void)
1010 TestApplication application;
1011 TypeRegistry typeRegistry = TypeRegistry::Get();
1013 // Attempt to register a property type out-of-bounds index (less than)
1016 PropertyRegistration property1( customType1, "propName", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1017 tet_result( TET_FAIL );
1019 catch ( DaliException& e )
1021 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1024 // Attempt to register a property type out-of-bounds index (greater than)
1027 PropertyRegistration property1( customType1, "propName", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1028 tet_result( TET_FAIL );
1030 catch ( DaliException& e )
1032 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1038 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1040 TestApplication application;
1041 TypeRegistry typeRegistry = TypeRegistry::Get();
1043 // Check property count before property registration
1044 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1045 DALI_TEST_CHECK( typeInfo );
1046 BaseHandle handle = typeInfo.CreateInstance();
1047 DALI_TEST_CHECK( handle );
1048 Actor customActor = Actor::DownCast( handle );
1049 DALI_TEST_CHECK( customActor );
1050 Stage::GetCurrent().Add(customActor);
1052 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1054 // Register animatable property
1055 std::string animatablePropertyName( "animatableProp1" );
1056 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1057 Property::Type animatablePropertyType( Property::FLOAT );
1058 AnimatablePropertyRegistration animatableProperty( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1060 // Check property count after registration
1061 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1063 // Set the animatable property value
1064 customActor.SetProperty( animatablePropertyIndex, 25.0f );
1066 // Render and notify
1067 application.SendNotification();
1068 application.Render();
1070 // Check the animatable property value
1071 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.f, TEST_LOCATION );
1073 // Check the animatable property name
1074 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1076 // Check the animatable property index
1077 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1079 // Check the animatable property type
1080 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1082 // Check property count of type-info is 1
1083 Property::IndexContainer indices;
1084 typeInfo.GetPropertyIndices( indices );
1085 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1087 // Ensure indices returned from actor and customActor differ by one
1088 Actor actor = Actor::New();
1089 actor.GetPropertyIndices( indices );
1090 unsigned int actorIndices = indices.Size();
1091 customActor.GetPropertyIndices( indices );
1092 unsigned int customActorIndices = indices.Size();
1093 DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1095 // check that the property is animatable
1096 Animation animation = Animation::New(0.2f);
1097 animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 15.f, AlphaFunction::LINEAR );
1099 // Render and notify, animation play for 0.05 seconds
1100 application.SendNotification();
1101 application.Render(50);
1102 DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
1103 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 22.5f, TEST_LOCATION );
1104 // Render and notify, animation play for another 0.1 seconds
1105 application.SendNotification();
1106 application.Render(100);
1107 DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
1108 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
1113 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1115 TestApplication application;
1116 TypeRegistry typeRegistry = TypeRegistry::Get();
1118 // Attempt to register an animatable property type out-of-bounds index (less than)
1121 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1122 tet_result( TET_FAIL );
1124 catch ( DaliException& e )
1126 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1129 // Attempt to register an animatable property type out-of-bounds index (greater than)
1132 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1133 tet_result( TET_FAIL );
1135 catch ( DaliException& e )
1137 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1143 int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultP(void)
1145 TestApplication application;
1146 TypeRegistry typeRegistry = TypeRegistry::Get();
1148 // Check property count before property registration
1149 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1150 DALI_TEST_CHECK( typeInfo );
1151 BaseHandle handle = typeInfo.CreateInstance();
1152 DALI_TEST_CHECK( handle );
1153 Actor customActor = Actor::DownCast( handle );
1154 DALI_TEST_CHECK( customActor );
1155 Stage::GetCurrent().Add(customActor);
1157 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1159 // Register animatable property
1160 std::string animatablePropertyName( "animatableProp1" );
1161 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1162 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, 10.f );
1164 // Check property count after registration
1165 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1167 // Render and notify
1168 application.SendNotification();
1169 application.Render();
1171 // Check the animatable property value
1172 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 10.f, TEST_LOCATION );
1174 // Check the animatable property name
1175 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1177 // Check the animatable property index
1178 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1180 // Check the animatable property type
1181 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), Property::FLOAT, TEST_LOCATION );
1183 // Check property count of type-info is 1
1184 Property::IndexContainer indices;
1185 typeInfo.GetPropertyIndices( indices );
1186 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1188 // Ensure indices returned from actor and customActor differ by one
1189 Actor actor = Actor::New();
1190 actor.GetPropertyIndices( indices );
1191 unsigned int actorIndices = indices.Size();
1192 customActor.GetPropertyIndices( indices );
1193 unsigned int customActorIndices = indices.Size();
1194 DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1196 // check that the property is animatable
1197 Animation animation = Animation::New(0.2f);
1198 animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 20.f, AlphaFunction::LINEAR );
1200 // Render and notify, animation play for 0.05 seconds
1201 application.SendNotification();
1202 application.Render(50);
1203 DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
1204 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 12.5f, TEST_LOCATION );
1205 // Render and notify, animation play for another 0.1 seconds
1206 application.SendNotification();
1207 application.Render(100);
1208 DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
1209 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
1214 int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultN(void)
1216 TestApplication application;
1217 TypeRegistry typeRegistry = TypeRegistry::Get();
1219 // Attempt to register an animatable property type out-of-bounds index (less than)
1222 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, false );
1223 tet_result( TET_FAIL );
1225 catch ( DaliException& e )
1227 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1230 // Attempt to register an animatable property type out-of-bounds index (greater than)
1233 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, true );
1234 tet_result( TET_FAIL );
1236 catch ( DaliException& e )
1238 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1244 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1246 TestApplication application;
1247 TypeRegistry typeRegistry = TypeRegistry::Get();
1249 // Check property count before property registration
1250 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1251 DALI_TEST_CHECK( typeInfo );
1252 BaseHandle handle = typeInfo.CreateInstance();
1253 DALI_TEST_CHECK( handle );
1254 Actor customActor = Actor::DownCast( handle );
1255 DALI_TEST_CHECK( customActor );
1257 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1259 // Register animatable property
1260 std::string animatablePropertyName( "animatableProp1" );
1261 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1262 Property::Type animatablePropertyType( Property::VECTOR2 );
1263 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1265 // Check property count after registration
1266 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1268 // Set the animatable property value
1269 customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1271 // Render and notify
1272 application.SendNotification();
1273 application.Render();
1275 // Check the animatable property value
1276 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1278 // Check the animatable property name
1279 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1281 // Check the animatable property index
1282 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1284 // Check the animatable property type
1285 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1287 // Check property count of type-info is 1
1288 Property::IndexContainer indices;
1289 typeInfo.GetPropertyIndices( indices );
1290 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1292 // Register animatable property components
1293 std::string animatablePropertyComponentName1( "animatableProp1X" );
1294 int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1295 AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1297 std::string animatablePropertyComponentName2( "animatableProp1Y" );
1298 int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1299 AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1301 // Check property count after registration
1302 DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1304 // Check the animatable property component value
1305 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1306 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1308 // Set the animatable property component value
1309 customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1311 // Render and notify
1312 application.SendNotification();
1313 application.Render();
1315 // Check the animatable property value
1316 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1317 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1318 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1320 // Set the animatable property component value
1321 customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1323 // Render and notify
1324 application.SendNotification();
1325 application.Render();
1327 // Check the animatable property value
1328 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1329 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1330 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1332 // Ensure indices returned from actor and customActor differ by three
1333 Actor actor = Actor::New();
1334 actor.GetPropertyIndices( indices );
1335 unsigned int actorIndices = indices.Size();
1336 customActor.GetPropertyIndices( indices );
1337 unsigned int customActorIndices = indices.Size();
1338 DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1343 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1345 TestApplication application;
1346 TypeRegistry typeRegistry = TypeRegistry::Get();
1348 // Register animatable property with the type of Vector2
1349 int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1350 AnimatablePropertyRegistration animatableProperty1( customType1, "animatableProp1", animatablePropertyIndex1, Property::VECTOR2 );
1352 // Attempt to register an animatable property component out-of-bounds index (less than)
1355 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1356 tet_result( TET_FAIL );
1358 catch ( DaliException& e )
1360 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1363 // Attempt to register an animatable property component out-of-bounds index (greater than)
1366 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1367 tet_result( TET_FAIL );
1369 catch ( DaliException& e )
1371 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1374 // Register an animatable property component
1375 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1377 // Attempt to register another animatable property component with the same component index
1380 AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatableProp1Y", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1381 tet_result( TET_FAIL );
1383 catch ( DaliException& e )
1385 DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1388 // Register animatable property with the type of boolean
1389 int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1390 AnimatablePropertyRegistration animatableProperty2( customType1, "animatableProp2", animatablePropertyIndex2, Property::BOOLEAN );
1392 // Attempt to register an animatable property component for the above property with boolean type
1395 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp2X", animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1396 tet_result( TET_FAIL );
1398 catch ( DaliException& e )
1400 DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1407 /*******************************************************************************
1409 * Action through the base handle
1411 ******************************************************************************/
1412 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1414 TestApplication application;
1418 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1419 DALI_TEST_CHECK( type );
1421 BaseHandle hdl = type.CreateInstance();
1422 DALI_TEST_CHECK( hdl );
1424 Actor a = Actor::DownCast(hdl);
1425 DALI_TEST_CHECK( a );
1427 a.SetVisible(false);
1429 application.SendNotification();
1430 application.Render(0);
1431 DALI_TEST_CHECK(!a.IsVisible());
1433 Property::Map attributes;
1435 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1437 application.SendNotification();
1438 application.Render(0);
1439 DALI_TEST_CHECK(a.IsVisible());
1441 DALI_TEST_CHECK(!hdl.DoAction("unknownAction", attributes));
1445 int UtcDaliPropertyRegistrationFunctions(void)
1447 TestApplication application;
1448 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1450 // Attempt to register a property without a setter
1453 PropertyRegistration property1( customType1, "propName", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1454 tet_result( TET_PASS );
1456 catch ( DaliException& e )
1458 tet_result( TET_FAIL );
1461 // Attempt to register a property without a getter
1464 PropertyRegistration property1( customType1, "propName", propertyIndex++, Property::BOOLEAN, NULL, NULL );
1465 tet_result( TET_FAIL );
1467 catch ( DaliException& e )
1469 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1474 int UtcDaliPropertyRegistrationAddSameIndex(void)
1476 TestApplication application;
1477 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1479 // Add one property with a valid property index
1480 PropertyRegistration property1( customType1, "propName", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1482 // Attempt to add another property with the same index
1485 PropertyRegistration property2( customType1, "propName2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1487 catch ( DaliException& e )
1489 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1492 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1494 // Add one property with a valid property index
1495 AnimatablePropertyRegistration property3( customType1, "animPropName", animatablePropertyIndex, Property::BOOLEAN );
1497 // Attempt to add another property with the same index
1500 AnimatablePropertyRegistration property4( customType1, "animPropName2", animatablePropertyIndex, Property::BOOLEAN );
1502 catch ( DaliException& e )
1504 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1509 int UtcDaliPropertyRegistrationPropertyWritable(void)
1511 TestApplication application;
1512 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1513 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1515 // Add two properties, one with SetProperty, one without
1516 PropertyRegistration property1( customType1, "propNameReadwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1517 PropertyRegistration property2( customType1, "propNameReadonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1519 // Create custom-actor
1520 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1521 DALI_TEST_CHECK( typeInfo );
1522 BaseHandle handle = typeInfo.CreateInstance();
1523 DALI_TEST_CHECK( handle );
1524 Actor customActor = Actor::DownCast( handle );
1525 DALI_TEST_CHECK( customActor );
1527 // Check whether properties are writable
1528 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
1529 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1533 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1535 TestApplication application;
1536 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1537 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1539 // These properties are not animatable
1540 PropertyRegistration property1( customType1, "propName", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1542 // These properties are animatable
1543 AnimatablePropertyRegistration property2( customType1, "animPropName", animatablePropertyIndex, Property::BOOLEAN );
1545 // Create custom-actor
1546 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1547 DALI_TEST_CHECK( typeInfo );
1548 BaseHandle handle = typeInfo.CreateInstance();
1549 DALI_TEST_CHECK( handle );
1550 Actor customActor = Actor::DownCast( handle );
1551 DALI_TEST_CHECK( customActor );
1553 // Check if animatable
1554 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1555 DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1557 // Create another instance of custom-actor
1558 BaseHandle handle2 = typeInfo.CreateInstance();
1559 DALI_TEST_CHECK( handle2 );
1560 Actor customActor2 = Actor::DownCast( handle2 );
1561 DALI_TEST_CHECK( customActor2 );
1563 // Check if animatable
1564 DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1565 DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1569 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1571 TestApplication application;
1572 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1573 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1575 // Create custom-actor
1576 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1577 DALI_TEST_CHECK( typeInfo );
1578 BaseHandle handle = typeInfo.CreateInstance();
1579 DALI_TEST_CHECK( handle );
1580 Actor customActor = Actor::DownCast( handle );
1581 DALI_TEST_CHECK( customActor );
1583 // Try to set an index that hasn't been added
1586 customActor.SetProperty( propertyIndex, true );
1587 tet_result( TET_FAIL );
1589 catch ( DaliException& e )
1591 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1596 customActor.SetProperty( animatablePropertyIndex, true );
1597 tet_result( TET_FAIL );
1599 catch ( DaliException& e )
1601 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1604 // Try to get an index that hasn't been added
1607 (void) customActor.GetProperty< bool >( propertyIndex );
1608 tet_result( TET_FAIL );
1610 catch ( DaliException& e )
1612 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1617 (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1618 tet_result( TET_FAIL );
1620 catch ( DaliException& e )
1622 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1628 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1630 TestApplication application;
1632 Actor actor = Actor::New();
1633 actor.SetSize(100.0f, 100.0f);
1634 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1635 Stage::GetCurrent().Add(actor);
1639 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1640 DALI_TEST_CHECK( type );
1641 BaseHandle handle = type.CreateInstance();
1642 DALI_TEST_CHECK( handle );
1643 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1644 DALI_TEST_CHECK( detector );
1646 // Attach actor to detector
1648 GestureReceivedFunctor functor( data );
1649 detector.Attach(actor);
1651 // Connect to signal through type
1652 handle.ConnectSignal( &application, "longPressDetected", functor );
1654 // Render and notify
1655 application.SendNotification();
1656 application.Render();
1659 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1660 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1661 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1662 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1666 int UtcDaliPanGestureDetectorTypeRegistry(void)
1668 TestApplication application;
1670 Actor actor = Actor::New();
1671 actor.SetSize(100.0f, 100.0f);
1672 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1673 Stage::GetCurrent().Add(actor);
1677 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1678 DALI_TEST_CHECK( type );
1679 BaseHandle handle = type.CreateInstance();
1680 DALI_TEST_CHECK( handle );
1681 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1682 DALI_TEST_CHECK( detector );
1684 // Attach actor to detector
1686 GestureReceivedFunctor functor( data );
1687 detector.Attach(actor);
1689 // Connect to signal through type
1690 handle.ConnectSignal( &application, "panDetected", functor );
1692 // Render and notify
1693 application.SendNotification();
1694 application.Render();
1697 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1698 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1699 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1700 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1704 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1706 TestApplication application;
1708 Actor actor = Actor::New();
1709 actor.SetSize(100.0f, 100.0f);
1710 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1711 Stage::GetCurrent().Add(actor);
1715 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1716 DALI_TEST_CHECK( type );
1717 BaseHandle handle = type.CreateInstance();
1718 DALI_TEST_CHECK( handle );
1719 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1720 DALI_TEST_CHECK( detector );
1722 // Attach actor to detector
1724 GestureReceivedFunctor functor( data );
1725 detector.Attach(actor);
1727 // Connect to signal through type
1728 handle.ConnectSignal( &application, "pinchDetected", functor );
1730 // Render and notify
1731 application.SendNotification();
1732 application.Render();
1735 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1736 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1740 int UtcDaliTapGestureDetectorTypeRegistry(void)
1742 TestApplication application;
1744 Actor actor = Actor::New();
1745 actor.SetSize(100.0f, 100.0f);
1746 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1747 Stage::GetCurrent().Add(actor);
1751 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1752 DALI_TEST_CHECK( type );
1753 BaseHandle handle = type.CreateInstance();
1754 DALI_TEST_CHECK( handle );
1755 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1756 DALI_TEST_CHECK( detector );
1758 // Attach actor to detector
1760 GestureReceivedFunctor functor( data );
1761 detector.Attach(actor);
1763 // Connect to signal through type
1764 handle.ConnectSignal( &application, "tapDetected", functor );
1766 // Render and notify
1767 application.SendNotification();
1768 application.Render();
1771 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1772 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1773 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1777 int UtcDaliTypeRegistryNamedType(void)
1779 TestApplication application;
1780 TypeRegistry typeRegistry = TypeRegistry::Get();
1782 // Create a normal actor
1783 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1784 DALI_TEST_CHECK( actorHandle );
1785 Actor actor( Actor::DownCast( actorHandle ) );
1786 DALI_TEST_CHECK( actor );
1787 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1789 // Create Named Actor Type
1790 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1791 DALI_TEST_CHECK( namedHandle );
1792 Actor namedActor( Actor::DownCast( namedHandle ) );
1793 DALI_TEST_CHECK( namedActor );
1794 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1796 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1800 int UtcDaliTypeInfoGetActionNameP(void)
1802 TestApplication application;
1803 TypeRegistry typeRegistry = TypeRegistry::Get();
1805 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1806 DALI_TEST_CHECK( typeInfo );
1808 DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
1810 std::string name = typeInfo.GetActionName(0);
1812 DALI_TEST_EQUALS( name, "show", TEST_LOCATION );
1817 int UtcDaliTypeInfoGetActionNameN(void)
1819 TestApplication application;
1820 TypeRegistry typeRegistry = TypeRegistry::Get();
1822 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1823 DALI_TEST_CHECK( typeInfo );
1825 DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
1827 std::string name = typeInfo.GetActionName(std::numeric_limits<size_t>::max());
1829 DALI_TEST_EQUALS( 0u, name.size(), TEST_LOCATION );
1834 int UtcDaliTypeInfoGetSignalNameP(void)
1836 TestApplication application;
1837 TypeRegistry typeRegistry = TypeRegistry::Get();
1839 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1840 DALI_TEST_CHECK( typeInfo );
1842 DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
1844 std::string name = typeInfo.GetSignalName(0);
1846 DALI_TEST_EQUALS( name, "touched", TEST_LOCATION );
1851 int UtcDaliTypeInfoGetSignalNameN(void)
1853 TestApplication application;
1854 TypeRegistry typeRegistry = TypeRegistry::Get();
1856 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1857 DALI_TEST_CHECK( typeInfo );
1859 DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
1861 std::string name = typeInfo.GetSignalName(std::numeric_limits<size_t>::max());
1863 DALI_TEST_EQUALS( 0u, name.size(), TEST_LOCATION );