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( "CameraActor" );
602 DALI_TEST_CHECK( type );
603 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
604 DALI_TEST_CHECK( ca );
605 Stage::GetCurrent().Add( ca );
606 application.Render();
609 type = registry.GetTypeInfo( "Animation" );
610 DALI_TEST_CHECK( type );
611 Animation an = Animation::DownCast(type.CreateInstance());
612 DALI_TEST_CHECK( an );
614 application.Render();
617 type = registry.GetTypeInfo( "ShaderEffect" );
618 DALI_TEST_CHECK( type );
619 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
620 DALI_TEST_CHECK( ef );
621 application.Render();
626 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameN(void)
628 TestApplication application;
630 TypeRegistry registry = TypeRegistry::Get();
634 type = registry.GetTypeInfo( "MyDummyActor" );
635 DALI_TEST_CHECK( !type );
640 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdP(void)
642 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "CameraActor" );
643 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::CameraActor) );
645 DALI_TEST_CHECK( named_type );
646 DALI_TEST_CHECK( typeinfo_type );
648 // Check named and typeid are equivalent
649 DALI_TEST_CHECK( named_type == typeinfo_type );
651 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
652 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
657 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdN(void)
659 TestApplication application;
660 TypeRegistry typeRegistry = TypeRegistry::Get();
662 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(Vector2) );
663 DALI_TEST_CHECK( !typeInfo );
668 int UtcDaliTypeRegistryGetTypeNameCountP(void)
670 TestApplication application;
671 TypeRegistry typeRegistry = TypeRegistry::Get();
674 for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
676 type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
677 DALI_TEST_CHECK( type );
684 int UtcDaliTypeRegistryGetTypeNamesP(void)
686 TestApplication application;
687 TypeRegistry typeRegistry = TypeRegistry::Get();
690 for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
692 type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
693 DALI_TEST_CHECK( type );
700 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
701 int UtcDaliTypeRegistryTypeRegistrationNotCallingCreateOnInitP(void)
703 ResetFunctorCounts();
705 TestApplication application;
707 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
708 DALI_TEST_CHECK( type );
710 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
711 DALI_TEST_CHECK( baseType );
713 BaseHandle handle = type.CreateInstance();
714 DALI_TEST_CHECK( handle );
716 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
717 DALI_TEST_CHECK( customHandle );
719 DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
721 DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
724 TestConnectionTracker tracker;
726 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
727 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
728 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
729 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
730 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
732 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
733 customHandle.GetCustomSignal().Emit();
734 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
735 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
736 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
738 // tracker should automatically disconnect here
739 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
740 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
742 // Test that functor is disconnected
743 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
744 customHandle.GetCustomSignal().Emit();
745 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
746 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
747 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
749 Property::Map attributes;
750 handle.DoAction("act1", attributes);
751 DALI_TEST_CHECK( lastActionCustom == "act1" );
755 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
756 int UtcDaliTypeRegistryTypeRegistrationCallingCreateOnInitP(void)
758 TestApplication application;
760 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
762 DALI_TEST_CHECK( true == CreateCustomInitCalled );
763 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
764 DALI_TEST_CHECK( type );
768 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
769 int UtcDaliTypeRegistryTypeRegistrationForNamedTypeP(void)
771 TestApplication application;
773 // Create Named Actor Type
774 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyNamedActor" );
775 DALI_TEST_CHECK( type );
777 BaseHandle namedHandle = type.CreateInstance();
778 DALI_TEST_CHECK( namedHandle );
779 Actor namedActor( Actor::DownCast( namedHandle ) );
780 DALI_TEST_CHECK( namedActor );
782 DALI_TEST_CHECK( namedActor.GetName() == "NamedActor" );
783 DALI_TEST_CHECK( type.GetName() == "MyNamedActor" );
784 DALI_TEST_CHECK( type.GetBaseName() == "Actor" );
789 // Note: No negative test case for UtcDaliTypeRegistryRegisteredName can be implemented.
790 int UtcDaliTypeRegistryRegisteredNameP(void)
792 TestApplication application;
794 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
796 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
797 DALI_TEST_CHECK( baseType );
799 BaseHandle handle = baseType.CreateInstance();
801 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
802 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
803 DALI_TEST_CHECK( type );
807 int UtcDaliTypeRegistrySignalConnectorTypeP(void)
809 ResetFunctorCounts();
811 TestApplication application;
813 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
814 DALI_TEST_CHECK( type );
816 BaseHandle handle = type.CreateInstance();
817 DALI_TEST_CHECK( handle );
819 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
820 DALI_TEST_CHECK( customHandle );
823 TestConnectionTracker tracker;
825 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
826 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
827 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
828 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
829 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
831 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
832 customHandle.GetCustomSignal().Emit();
833 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
834 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
835 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
837 // tracker should automatically disconnect here
838 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
839 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
841 // Test that functor is disconnected
842 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
843 customHandle.GetCustomSignal().Emit();
844 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
845 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
846 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
851 int UtcDaliTypeRegistrySignalConnectorTypeN(void)
853 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
855 ResetFunctorCounts();
857 TestApplication application;
859 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
860 DALI_TEST_CHECK( type );
862 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
863 DALI_TEST_CHECK( baseType );
865 BaseHandle handle = type.CreateInstance();
866 DALI_TEST_CHECK( handle );
868 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
869 DALI_TEST_CHECK( customHandle );
871 DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
873 DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
876 TestConnectionTracker tracker;
878 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
879 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
880 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
881 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
882 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
885 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
886 customHandle.GetCustomSignal().Emit();
887 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
889 // tracker should have nothing to disconnect here
892 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
893 customHandle.GetCustomSignal().Emit();
894 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
898 int UtcDaliTypeRegistryTypeActionP(void)
900 ResetFunctorCounts();
902 TestApplication application;
904 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
905 DALI_TEST_CHECK( type );
907 BaseHandle handle = type.CreateInstance();
908 DALI_TEST_CHECK( handle );
910 Property::Map attributes;
911 DALI_TEST_CHECK( handle.DoAction("act1", attributes) );
912 DALI_TEST_CHECK( lastActionCustom == "act1" );
917 int UtcDaliTypeRegistryTypeActionN(void)
919 ResetFunctorCounts();
921 TestApplication application;
923 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
924 DALI_TEST_CHECK( type );
926 BaseHandle handle = type.CreateInstance();
927 DALI_TEST_CHECK( handle );
929 Property::Map attributes;
930 DALI_TEST_CHECK( !handle.DoAction( "unknownAction", attributes ) );
935 int UtcDaliTypeRegistryPropertyRegistrationP(void)
937 TestApplication application;
938 TypeRegistry typeRegistry = TypeRegistry::Get();
940 // Check property count before property registration
941 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
942 DALI_TEST_CHECK( typeInfo );
943 BaseHandle handle = typeInfo.CreateInstance();
944 DALI_TEST_CHECK( handle );
945 Actor customActor = Actor::DownCast( handle );
946 DALI_TEST_CHECK( customActor );
947 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
949 std::string propertyName( "prop1" );
950 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
951 Property::Type propertyType( Property::BOOLEAN );
952 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
954 // Check property count after registration
955 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
956 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
958 // Add custom property and check property count
959 customActor.RegisterProperty( "customProp1", true );
960 unsigned int customPropertyCount( customActor.GetPropertyCount() );
961 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
963 // Set the property, ensure SetProperty called
964 DALI_TEST_CHECK( !setPropertyCalled );
965 customActor.SetProperty( propertyIndex, false );
966 DALI_TEST_CHECK( setPropertyCalled );
968 // Get the property, ensure GetProperty called
969 DALI_TEST_CHECK( !getPropertyCalled );
970 (void)customActor.GetProperty< bool >( propertyIndex );
971 DALI_TEST_CHECK( getPropertyCalled );
973 // Check the property name
974 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
975 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
977 // Check the property index
978 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
980 // Check the property type
981 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
983 // Check property count of type-info is 1
984 Property::IndexContainer indices;
985 typeInfo.GetPropertyIndices( indices );
986 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
988 // Ensure indices returned from actor and customActor differ by two
989 Actor actor = Actor::New();
990 actor.GetPropertyIndices( indices );
991 unsigned int actorIndices = indices.Size();
992 customActor.GetPropertyIndices( indices );
993 unsigned int customActorIndices = indices.Size();
994 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
998 int UtcDaliTypeRegistryPropertyRegistrationN(void)
1000 TestApplication application;
1001 TypeRegistry typeRegistry = TypeRegistry::Get();
1003 // Attempt to register a property type out-of-bounds index (less than)
1006 PropertyRegistration property1( customType1, "propName", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1007 tet_result( TET_FAIL );
1009 catch ( DaliException& e )
1011 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1014 // Attempt to register a property type out-of-bounds index (greater than)
1017 PropertyRegistration property1( customType1, "propName", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1018 tet_result( TET_FAIL );
1020 catch ( DaliException& e )
1022 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1028 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1030 TestApplication application;
1031 TypeRegistry typeRegistry = TypeRegistry::Get();
1033 // Check property count before property registration
1034 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1035 DALI_TEST_CHECK( typeInfo );
1036 BaseHandle handle = typeInfo.CreateInstance();
1037 DALI_TEST_CHECK( handle );
1038 Actor customActor = Actor::DownCast( handle );
1039 DALI_TEST_CHECK( customActor );
1040 Stage::GetCurrent().Add(customActor);
1042 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1044 // Register animatable property
1045 std::string animatablePropertyName( "animatableProp1" );
1046 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1047 Property::Type animatablePropertyType( Property::FLOAT );
1048 AnimatablePropertyRegistration animatableProperty( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1050 // Check property count after registration
1051 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1053 // Set the animatable property value
1054 customActor.SetProperty( animatablePropertyIndex, 25.0f );
1056 // Render and notify
1057 application.SendNotification();
1058 application.Render();
1060 // Check the animatable property value
1061 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.f, TEST_LOCATION );
1063 // Check the animatable property name
1064 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1066 // Check the animatable property index
1067 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1069 // Check the animatable property type
1070 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1072 // Check property count of type-info is 1
1073 Property::IndexContainer indices;
1074 typeInfo.GetPropertyIndices( indices );
1075 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1077 // Ensure indices returned from actor and customActor differ by one
1078 Actor actor = Actor::New();
1079 actor.GetPropertyIndices( indices );
1080 unsigned int actorIndices = indices.Size();
1081 customActor.GetPropertyIndices( indices );
1082 unsigned int customActorIndices = indices.Size();
1083 DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1085 // check that the property is animatable
1086 Animation animation = Animation::New(0.2f);
1087 animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 15.f, AlphaFunction::LINEAR );
1089 // Render and notify, animation play for 0.05 seconds
1090 application.SendNotification();
1091 application.Render(50);
1092 DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
1093 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 22.5f, TEST_LOCATION );
1094 // Render and notify, animation play for another 0.1 seconds
1095 application.SendNotification();
1096 application.Render(100);
1097 DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
1098 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
1103 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1105 TestApplication application;
1106 TypeRegistry typeRegistry = TypeRegistry::Get();
1108 // Attempt to register an animatable property type out-of-bounds index (less than)
1111 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1112 tet_result( TET_FAIL );
1114 catch ( DaliException& e )
1116 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1119 // Attempt to register an animatable property type out-of-bounds index (greater than)
1122 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1123 tet_result( TET_FAIL );
1125 catch ( DaliException& e )
1127 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1133 int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultP(void)
1135 TestApplication application;
1136 TypeRegistry typeRegistry = TypeRegistry::Get();
1138 // Check property count before property registration
1139 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1140 DALI_TEST_CHECK( typeInfo );
1141 BaseHandle handle = typeInfo.CreateInstance();
1142 DALI_TEST_CHECK( handle );
1143 Actor customActor = Actor::DownCast( handle );
1144 DALI_TEST_CHECK( customActor );
1145 Stage::GetCurrent().Add(customActor);
1147 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1149 // Register animatable property
1150 std::string animatablePropertyName( "animatableProp1" );
1151 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1152 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, 10.f );
1154 // Check property count after registration
1155 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1157 // Render and notify
1158 application.SendNotification();
1159 application.Render();
1161 // Check the animatable property value
1162 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 10.f, TEST_LOCATION );
1164 // Check the animatable property name
1165 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1167 // Check the animatable property index
1168 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1170 // Check the animatable property type
1171 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), Property::FLOAT, TEST_LOCATION );
1173 // Check property count of type-info is 1
1174 Property::IndexContainer indices;
1175 typeInfo.GetPropertyIndices( indices );
1176 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1178 // Ensure indices returned from actor and customActor differ by one
1179 Actor actor = Actor::New();
1180 actor.GetPropertyIndices( indices );
1181 unsigned int actorIndices = indices.Size();
1182 customActor.GetPropertyIndices( indices );
1183 unsigned int customActorIndices = indices.Size();
1184 DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1186 // check that the property is animatable
1187 Animation animation = Animation::New(0.2f);
1188 animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 20.f, AlphaFunction::LINEAR );
1190 // Render and notify, animation play for 0.05 seconds
1191 application.SendNotification();
1192 application.Render(50);
1193 DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
1194 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 12.5f, TEST_LOCATION );
1195 // Render and notify, animation play for another 0.1 seconds
1196 application.SendNotification();
1197 application.Render(100);
1198 DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
1199 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
1204 int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultN(void)
1206 TestApplication application;
1207 TypeRegistry typeRegistry = TypeRegistry::Get();
1209 // Attempt to register an animatable property type out-of-bounds index (less than)
1212 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, false );
1213 tet_result( TET_FAIL );
1215 catch ( DaliException& e )
1217 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1220 // Attempt to register an animatable property type out-of-bounds index (greater than)
1223 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, true );
1224 tet_result( TET_FAIL );
1226 catch ( DaliException& e )
1228 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1234 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1236 TestApplication application;
1237 TypeRegistry typeRegistry = TypeRegistry::Get();
1239 // Check property count before property registration
1240 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1241 DALI_TEST_CHECK( typeInfo );
1242 BaseHandle handle = typeInfo.CreateInstance();
1243 DALI_TEST_CHECK( handle );
1244 Actor customActor = Actor::DownCast( handle );
1245 DALI_TEST_CHECK( customActor );
1247 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1249 // Register animatable property
1250 std::string animatablePropertyName( "animatableProp1" );
1251 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1252 Property::Type animatablePropertyType( Property::VECTOR2 );
1253 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1255 // Check property count after registration
1256 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1258 // Set the animatable property value
1259 customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1261 // Render and notify
1262 application.SendNotification();
1263 application.Render();
1265 // Check the animatable property value
1266 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1268 // Check the animatable property name
1269 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1271 // Check the animatable property index
1272 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1274 // Check the animatable property type
1275 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1277 // Check property count of type-info is 1
1278 Property::IndexContainer indices;
1279 typeInfo.GetPropertyIndices( indices );
1280 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1282 // Register animatable property components
1283 std::string animatablePropertyComponentName1( "animatableProp1X" );
1284 int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1285 AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1287 std::string animatablePropertyComponentName2( "animatableProp1Y" );
1288 int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1289 AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1291 // Check property count after registration
1292 DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1294 // Check the animatable property component value
1295 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1296 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1298 // Set the animatable property component value
1299 customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1301 // Render and notify
1302 application.SendNotification();
1303 application.Render();
1305 // Check the animatable property value
1306 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1307 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1308 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1310 // Set the animatable property component value
1311 customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1313 // Render and notify
1314 application.SendNotification();
1315 application.Render();
1317 // Check the animatable property value
1318 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1319 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1320 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1322 // Ensure indices returned from actor and customActor differ by three
1323 Actor actor = Actor::New();
1324 actor.GetPropertyIndices( indices );
1325 unsigned int actorIndices = indices.Size();
1326 customActor.GetPropertyIndices( indices );
1327 unsigned int customActorIndices = indices.Size();
1328 DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1333 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1335 TestApplication application;
1336 TypeRegistry typeRegistry = TypeRegistry::Get();
1338 // Register animatable property with the type of Vector2
1339 int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1340 AnimatablePropertyRegistration animatableProperty1( customType1, "animatableProp1", animatablePropertyIndex1, Property::VECTOR2 );
1342 // Attempt to register an animatable property component out-of-bounds index (less than)
1345 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1346 tet_result( TET_FAIL );
1348 catch ( DaliException& e )
1350 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1353 // Attempt to register an animatable property component out-of-bounds index (greater than)
1356 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1357 tet_result( TET_FAIL );
1359 catch ( DaliException& e )
1361 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1364 // Register an animatable property component
1365 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1367 // Attempt to register another animatable property component with the same component index
1370 AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatableProp1Y", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1371 tet_result( TET_FAIL );
1373 catch ( DaliException& e )
1375 DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1378 // Register animatable property with the type of boolean
1379 int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1380 AnimatablePropertyRegistration animatableProperty2( customType1, "animatableProp2", animatablePropertyIndex2, Property::BOOLEAN );
1382 // Attempt to register an animatable property component for the above property with boolean type
1385 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp2X", animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1386 tet_result( TET_FAIL );
1388 catch ( DaliException& e )
1390 DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1397 /*******************************************************************************
1399 * Action through the base handle
1401 ******************************************************************************/
1402 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1404 TestApplication application;
1408 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1409 DALI_TEST_CHECK( type );
1411 BaseHandle hdl = type.CreateInstance();
1412 DALI_TEST_CHECK( hdl );
1414 Actor a = Actor::DownCast(hdl);
1415 DALI_TEST_CHECK( a );
1417 a.SetVisible(false);
1419 application.SendNotification();
1420 application.Render(0);
1421 DALI_TEST_CHECK(!a.IsVisible());
1423 Property::Map attributes;
1425 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1427 application.SendNotification();
1428 application.Render(0);
1429 DALI_TEST_CHECK(a.IsVisible());
1431 DALI_TEST_CHECK(!hdl.DoAction("unknownAction", attributes));
1435 int UtcDaliPropertyRegistrationFunctions(void)
1437 TestApplication application;
1438 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1440 // Attempt to register a property without a setter
1443 PropertyRegistration property1( customType1, "propName", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1444 tet_result( TET_PASS );
1446 catch ( DaliException& e )
1448 tet_result( TET_FAIL );
1451 // Attempt to register a property without a getter
1454 PropertyRegistration property1( customType1, "propName", propertyIndex++, Property::BOOLEAN, NULL, NULL );
1455 tet_result( TET_FAIL );
1457 catch ( DaliException& e )
1459 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1464 int UtcDaliPropertyRegistrationAddSameIndex(void)
1466 TestApplication application;
1467 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1469 // Add one property with a valid property index
1470 PropertyRegistration property1( customType1, "propName", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1472 // Attempt to add another property with the same index
1475 PropertyRegistration property2( customType1, "propName2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1477 catch ( DaliException& e )
1479 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1482 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1484 // Add one property with a valid property index
1485 AnimatablePropertyRegistration property3( customType1, "animPropName", animatablePropertyIndex, Property::BOOLEAN );
1487 // Attempt to add another property with the same index
1490 AnimatablePropertyRegistration property4( customType1, "animPropName2", animatablePropertyIndex, Property::BOOLEAN );
1492 catch ( DaliException& e )
1494 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1499 int UtcDaliPropertyRegistrationPropertyWritable(void)
1501 TestApplication application;
1502 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1503 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1505 // Add two properties, one with SetProperty, one without
1506 PropertyRegistration property1( customType1, "propNameReadwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1507 PropertyRegistration property2( customType1, "propNameReadonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1509 // Create custom-actor
1510 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1511 DALI_TEST_CHECK( typeInfo );
1512 BaseHandle handle = typeInfo.CreateInstance();
1513 DALI_TEST_CHECK( handle );
1514 Actor customActor = Actor::DownCast( handle );
1515 DALI_TEST_CHECK( customActor );
1517 // Check whether properties are writable
1518 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
1519 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1523 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1525 TestApplication application;
1526 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1527 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1529 // These properties are not animatable
1530 PropertyRegistration property1( customType1, "propName", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1532 // These properties are animatable
1533 AnimatablePropertyRegistration property2( customType1, "animPropName", animatablePropertyIndex, Property::BOOLEAN );
1535 // Create custom-actor
1536 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1537 DALI_TEST_CHECK( typeInfo );
1538 BaseHandle handle = typeInfo.CreateInstance();
1539 DALI_TEST_CHECK( handle );
1540 Actor customActor = Actor::DownCast( handle );
1541 DALI_TEST_CHECK( customActor );
1543 // Check if animatable
1544 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1545 DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1547 // Create another instance of custom-actor
1548 BaseHandle handle2 = typeInfo.CreateInstance();
1549 DALI_TEST_CHECK( handle2 );
1550 Actor customActor2 = Actor::DownCast( handle2 );
1551 DALI_TEST_CHECK( customActor2 );
1553 // Check if animatable
1554 DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1555 DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1559 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1561 TestApplication application;
1562 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1563 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1565 // Create custom-actor
1566 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1567 DALI_TEST_CHECK( typeInfo );
1568 BaseHandle handle = typeInfo.CreateInstance();
1569 DALI_TEST_CHECK( handle );
1570 Actor customActor = Actor::DownCast( handle );
1571 DALI_TEST_CHECK( customActor );
1573 // Try to set an index that hasn't been added
1576 customActor.SetProperty( propertyIndex, true );
1577 tet_result( TET_FAIL );
1579 catch ( DaliException& e )
1581 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1586 customActor.SetProperty( animatablePropertyIndex, true );
1587 tet_result( TET_FAIL );
1589 catch ( DaliException& e )
1591 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1594 // Try to get an index that hasn't been added
1597 (void) customActor.GetProperty< bool >( propertyIndex );
1598 tet_result( TET_FAIL );
1600 catch ( DaliException& e )
1602 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1607 (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1608 tet_result( TET_FAIL );
1610 catch ( DaliException& e )
1612 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1618 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1620 TestApplication application;
1622 Actor actor = Actor::New();
1623 actor.SetSize(100.0f, 100.0f);
1624 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1625 Stage::GetCurrent().Add(actor);
1629 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1630 DALI_TEST_CHECK( type );
1631 BaseHandle handle = type.CreateInstance();
1632 DALI_TEST_CHECK( handle );
1633 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1634 DALI_TEST_CHECK( detector );
1636 // Attach actor to detector
1638 GestureReceivedFunctor functor( data );
1639 detector.Attach(actor);
1641 // Connect to signal through type
1642 handle.ConnectSignal( &application, "longPressDetected", functor );
1644 // Render and notify
1645 application.SendNotification();
1646 application.Render();
1649 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1650 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1651 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1652 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1656 int UtcDaliPanGestureDetectorTypeRegistry(void)
1658 TestApplication application;
1660 Actor actor = Actor::New();
1661 actor.SetSize(100.0f, 100.0f);
1662 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1663 Stage::GetCurrent().Add(actor);
1667 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1668 DALI_TEST_CHECK( type );
1669 BaseHandle handle = type.CreateInstance();
1670 DALI_TEST_CHECK( handle );
1671 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1672 DALI_TEST_CHECK( detector );
1674 // Attach actor to detector
1676 GestureReceivedFunctor functor( data );
1677 detector.Attach(actor);
1679 // Connect to signal through type
1680 handle.ConnectSignal( &application, "panDetected", functor );
1682 // Render and notify
1683 application.SendNotification();
1684 application.Render();
1687 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1688 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1689 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1690 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1694 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1696 TestApplication application;
1698 Actor actor = Actor::New();
1699 actor.SetSize(100.0f, 100.0f);
1700 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1701 Stage::GetCurrent().Add(actor);
1705 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1706 DALI_TEST_CHECK( type );
1707 BaseHandle handle = type.CreateInstance();
1708 DALI_TEST_CHECK( handle );
1709 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1710 DALI_TEST_CHECK( detector );
1712 // Attach actor to detector
1714 GestureReceivedFunctor functor( data );
1715 detector.Attach(actor);
1717 // Connect to signal through type
1718 handle.ConnectSignal( &application, "pinchDetected", functor );
1720 // Render and notify
1721 application.SendNotification();
1722 application.Render();
1725 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1726 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1730 int UtcDaliTapGestureDetectorTypeRegistry(void)
1732 TestApplication application;
1734 Actor actor = Actor::New();
1735 actor.SetSize(100.0f, 100.0f);
1736 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1737 Stage::GetCurrent().Add(actor);
1741 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1742 DALI_TEST_CHECK( type );
1743 BaseHandle handle = type.CreateInstance();
1744 DALI_TEST_CHECK( handle );
1745 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1746 DALI_TEST_CHECK( detector );
1748 // Attach actor to detector
1750 GestureReceivedFunctor functor( data );
1751 detector.Attach(actor);
1753 // Connect to signal through type
1754 handle.ConnectSignal( &application, "tapDetected", functor );
1756 // Render and notify
1757 application.SendNotification();
1758 application.Render();
1761 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1762 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1763 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1767 int UtcDaliTypeRegistryNamedType(void)
1769 TestApplication application;
1770 TypeRegistry typeRegistry = TypeRegistry::Get();
1772 // Create a normal actor
1773 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1774 DALI_TEST_CHECK( actorHandle );
1775 Actor actor( Actor::DownCast( actorHandle ) );
1776 DALI_TEST_CHECK( actor );
1777 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1779 // Create Named Actor Type
1780 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1781 DALI_TEST_CHECK( namedHandle );
1782 Actor namedActor( Actor::DownCast( namedHandle ) );
1783 DALI_TEST_CHECK( namedActor );
1784 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1786 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1790 int UtcDaliTypeInfoGetActionNameP(void)
1792 TestApplication application;
1793 TypeRegistry typeRegistry = TypeRegistry::Get();
1795 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1796 DALI_TEST_CHECK( typeInfo );
1798 DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
1800 std::string name = typeInfo.GetActionName(0);
1802 DALI_TEST_EQUALS( name, "show", TEST_LOCATION );
1807 int UtcDaliTypeInfoGetActionNameN(void)
1809 TestApplication application;
1810 TypeRegistry typeRegistry = TypeRegistry::Get();
1812 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1813 DALI_TEST_CHECK( typeInfo );
1815 DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
1817 std::string name = typeInfo.GetActionName(std::numeric_limits<size_t>::max());
1819 DALI_TEST_EQUALS( 0u, name.size(), TEST_LOCATION );
1824 int UtcDaliTypeInfoGetSignalNameP(void)
1826 TestApplication application;
1827 TypeRegistry typeRegistry = TypeRegistry::Get();
1829 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1830 DALI_TEST_CHECK( typeInfo );
1832 DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
1834 std::string name = typeInfo.GetSignalName(0);
1836 DALI_TEST_EQUALS( name, "touched", TEST_LOCATION );
1841 int UtcDaliTypeInfoGetSignalNameN(void)
1843 TestApplication application;
1844 TypeRegistry typeRegistry = TypeRegistry::Get();
1846 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1847 DALI_TEST_CHECK( typeInfo );
1849 DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
1851 std::string name = typeInfo.GetSignalName(std::numeric_limits<size_t>::max());
1853 DALI_TEST_EQUALS( 0u, name.size(), TEST_LOCATION );