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();
619 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameN(void)
621 TestApplication application;
623 TypeRegistry registry = TypeRegistry::Get();
627 type = registry.GetTypeInfo( "MyDummyActor" );
628 DALI_TEST_CHECK( !type );
633 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdP(void)
635 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "CameraActor" );
636 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::CameraActor) );
638 DALI_TEST_CHECK( named_type );
639 DALI_TEST_CHECK( typeinfo_type );
641 // Check named and typeid are equivalent
642 DALI_TEST_CHECK( named_type == typeinfo_type );
644 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
645 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
650 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdN(void)
652 TestApplication application;
653 TypeRegistry typeRegistry = TypeRegistry::Get();
655 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(Vector2) );
656 DALI_TEST_CHECK( !typeInfo );
661 int UtcDaliTypeRegistryGetTypeNameCountP(void)
663 TestApplication application;
664 TypeRegistry typeRegistry = TypeRegistry::Get();
667 for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
669 type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
670 DALI_TEST_CHECK( type );
677 int UtcDaliTypeRegistryGetTypeNamesP(void)
679 TestApplication application;
680 TypeRegistry typeRegistry = TypeRegistry::Get();
683 for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
685 type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
686 DALI_TEST_CHECK( type );
693 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
694 int UtcDaliTypeRegistryTypeRegistrationNotCallingCreateOnInitP(void)
696 ResetFunctorCounts();
698 TestApplication application;
700 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
701 DALI_TEST_CHECK( type );
703 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
704 DALI_TEST_CHECK( baseType );
706 BaseHandle handle = type.CreateInstance();
707 DALI_TEST_CHECK( handle );
709 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
710 DALI_TEST_CHECK( customHandle );
712 DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
714 DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
717 TestConnectionTracker tracker;
719 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
720 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
721 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
722 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
723 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
725 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
726 customHandle.GetCustomSignal().Emit();
727 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
728 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
729 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
731 // tracker should automatically disconnect here
732 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
733 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
735 // Test that functor is disconnected
736 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
737 customHandle.GetCustomSignal().Emit();
738 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
739 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
740 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
742 Property::Map attributes;
743 handle.DoAction("act1", attributes);
744 DALI_TEST_CHECK( lastActionCustom == "act1" );
748 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
749 int UtcDaliTypeRegistryTypeRegistrationCallingCreateOnInitP(void)
751 TestApplication application;
753 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
755 DALI_TEST_CHECK( true == CreateCustomInitCalled );
756 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
757 DALI_TEST_CHECK( type );
761 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
762 int UtcDaliTypeRegistryTypeRegistrationForNamedTypeP(void)
764 TestApplication application;
766 // Create Named Actor Type
767 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyNamedActor" );
768 DALI_TEST_CHECK( type );
770 BaseHandle namedHandle = type.CreateInstance();
771 DALI_TEST_CHECK( namedHandle );
772 Actor namedActor( Actor::DownCast( namedHandle ) );
773 DALI_TEST_CHECK( namedActor );
775 DALI_TEST_CHECK( namedActor.GetName() == "NamedActor" );
776 DALI_TEST_CHECK( type.GetName() == "MyNamedActor" );
777 DALI_TEST_CHECK( type.GetBaseName() == "Actor" );
782 // Note: No negative test case for UtcDaliTypeRegistryRegisteredName can be implemented.
783 int UtcDaliTypeRegistryRegisteredNameP(void)
785 TestApplication application;
787 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
789 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
790 DALI_TEST_CHECK( baseType );
792 BaseHandle handle = baseType.CreateInstance();
794 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
795 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
796 DALI_TEST_CHECK( type );
800 int UtcDaliTypeRegistrySignalConnectorTypeP(void)
802 ResetFunctorCounts();
804 TestApplication application;
806 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
807 DALI_TEST_CHECK( type );
809 BaseHandle handle = type.CreateInstance();
810 DALI_TEST_CHECK( handle );
812 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
813 DALI_TEST_CHECK( customHandle );
816 TestConnectionTracker tracker;
818 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
819 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
820 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
821 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
822 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
824 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
825 customHandle.GetCustomSignal().Emit();
826 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
827 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
828 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
830 // tracker should automatically disconnect here
831 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
832 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
834 // Test that functor is disconnected
835 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
836 customHandle.GetCustomSignal().Emit();
837 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
838 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
839 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
844 int UtcDaliTypeRegistrySignalConnectorTypeN(void)
846 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
848 ResetFunctorCounts();
850 TestApplication application;
852 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
853 DALI_TEST_CHECK( type );
855 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
856 DALI_TEST_CHECK( baseType );
858 BaseHandle handle = type.CreateInstance();
859 DALI_TEST_CHECK( handle );
861 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
862 DALI_TEST_CHECK( customHandle );
864 DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
866 DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
869 TestConnectionTracker tracker;
871 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
872 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
873 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
874 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
875 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
878 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
879 customHandle.GetCustomSignal().Emit();
880 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
882 // tracker should have nothing to disconnect here
885 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
886 customHandle.GetCustomSignal().Emit();
887 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
891 int UtcDaliTypeRegistryTypeActionP(void)
893 ResetFunctorCounts();
895 TestApplication application;
897 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
898 DALI_TEST_CHECK( type );
900 BaseHandle handle = type.CreateInstance();
901 DALI_TEST_CHECK( handle );
903 Property::Map attributes;
904 DALI_TEST_CHECK( handle.DoAction("act1", attributes) );
905 DALI_TEST_CHECK( lastActionCustom == "act1" );
910 int UtcDaliTypeRegistryTypeActionN(void)
912 ResetFunctorCounts();
914 TestApplication application;
916 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
917 DALI_TEST_CHECK( type );
919 BaseHandle handle = type.CreateInstance();
920 DALI_TEST_CHECK( handle );
922 Property::Map attributes;
923 DALI_TEST_CHECK( !handle.DoAction( "unknownAction", attributes ) );
928 int UtcDaliTypeRegistryPropertyRegistrationP(void)
930 TestApplication application;
931 TypeRegistry typeRegistry = TypeRegistry::Get();
933 // Check property count before property registration
934 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
935 DALI_TEST_CHECK( typeInfo );
936 BaseHandle handle = typeInfo.CreateInstance();
937 DALI_TEST_CHECK( handle );
938 Actor customActor = Actor::DownCast( handle );
939 DALI_TEST_CHECK( customActor );
940 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
942 std::string propertyName( "prop1" );
943 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
944 Property::Type propertyType( Property::BOOLEAN );
945 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
947 // Check property count after registration
948 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
949 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
951 // Add custom property and check property count
952 customActor.RegisterProperty( "customProp1", true );
953 unsigned int customPropertyCount( customActor.GetPropertyCount() );
954 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
956 // Set the property, ensure SetProperty called
957 DALI_TEST_CHECK( !setPropertyCalled );
958 customActor.SetProperty( propertyIndex, false );
959 DALI_TEST_CHECK( setPropertyCalled );
961 // Get the property, ensure GetProperty called
962 DALI_TEST_CHECK( !getPropertyCalled );
963 (void)customActor.GetProperty< bool >( propertyIndex );
964 DALI_TEST_CHECK( getPropertyCalled );
966 // Check the property name
967 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
968 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
970 // Check the property index
971 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
973 // Check the property type
974 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
976 // Check property count of type-info is 1
977 Property::IndexContainer indices;
978 typeInfo.GetPropertyIndices( indices );
979 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
981 // Ensure indices returned from actor and customActor differ by two
982 Actor actor = Actor::New();
983 actor.GetPropertyIndices( indices );
984 unsigned int actorIndices = indices.Size();
985 customActor.GetPropertyIndices( indices );
986 unsigned int customActorIndices = indices.Size();
987 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
991 int UtcDaliTypeRegistryPropertyRegistrationN(void)
993 TestApplication application;
994 TypeRegistry typeRegistry = TypeRegistry::Get();
996 // Attempt to register a property type out-of-bounds index (less than)
999 PropertyRegistration property1( customType1, "propName", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1000 tet_result( TET_FAIL );
1002 catch ( DaliException& e )
1004 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1007 // Attempt to register a property type out-of-bounds index (greater than)
1010 PropertyRegistration property1( customType1, "propName", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1011 tet_result( TET_FAIL );
1013 catch ( DaliException& e )
1015 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1021 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1023 TestApplication application;
1024 TypeRegistry typeRegistry = TypeRegistry::Get();
1026 // Check property count before property registration
1027 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1028 DALI_TEST_CHECK( typeInfo );
1029 BaseHandle handle = typeInfo.CreateInstance();
1030 DALI_TEST_CHECK( handle );
1031 Actor customActor = Actor::DownCast( handle );
1032 DALI_TEST_CHECK( customActor );
1033 Stage::GetCurrent().Add(customActor);
1035 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1037 // Register animatable property
1038 std::string animatablePropertyName( "animatableProp1" );
1039 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1040 Property::Type animatablePropertyType( Property::FLOAT );
1041 AnimatablePropertyRegistration animatableProperty( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1043 // Check property count after registration
1044 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1046 // Set the animatable property value
1047 customActor.SetProperty( animatablePropertyIndex, 25.0f );
1049 // Render and notify
1050 application.SendNotification();
1051 application.Render();
1053 // Check the animatable property value
1054 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.f, TEST_LOCATION );
1056 // Check the animatable property name
1057 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1059 // Check the animatable property index
1060 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1062 // Check the animatable property type
1063 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1065 // Check property count of type-info is 1
1066 Property::IndexContainer indices;
1067 typeInfo.GetPropertyIndices( indices );
1068 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1070 // Ensure indices returned from actor and customActor differ by one
1071 Actor actor = Actor::New();
1072 actor.GetPropertyIndices( indices );
1073 unsigned int actorIndices = indices.Size();
1074 customActor.GetPropertyIndices( indices );
1075 unsigned int customActorIndices = indices.Size();
1076 DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1078 // check that the property is animatable
1079 Animation animation = Animation::New(0.2f);
1080 animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 15.f, AlphaFunction::LINEAR );
1082 // Render and notify, animation play for 0.05 seconds
1083 application.SendNotification();
1084 application.Render(50);
1085 DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
1086 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 22.5f, TEST_LOCATION );
1087 // Render and notify, animation play for another 0.1 seconds
1088 application.SendNotification();
1089 application.Render(100);
1090 DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
1091 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
1096 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1098 TestApplication application;
1099 TypeRegistry typeRegistry = TypeRegistry::Get();
1101 // Attempt to register an animatable property type out-of-bounds index (less than)
1104 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1105 tet_result( TET_FAIL );
1107 catch ( DaliException& e )
1109 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1112 // Attempt to register an animatable property type out-of-bounds index (greater than)
1115 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1116 tet_result( TET_FAIL );
1118 catch ( DaliException& e )
1120 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1126 int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultP(void)
1128 TestApplication application;
1129 TypeRegistry typeRegistry = TypeRegistry::Get();
1131 // Check property count before property registration
1132 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1133 DALI_TEST_CHECK( typeInfo );
1134 BaseHandle handle = typeInfo.CreateInstance();
1135 DALI_TEST_CHECK( handle );
1136 Actor customActor = Actor::DownCast( handle );
1137 DALI_TEST_CHECK( customActor );
1138 Stage::GetCurrent().Add(customActor);
1140 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1142 // Register animatable property
1143 std::string animatablePropertyName( "animatableProp1" );
1144 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1145 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, 10.f );
1147 // Check property count after registration
1148 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1150 // Render and notify
1151 application.SendNotification();
1152 application.Render();
1154 // Check the animatable property value
1155 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 10.f, TEST_LOCATION );
1157 // Check the animatable property name
1158 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1160 // Check the animatable property index
1161 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1163 // Check the animatable property type
1164 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), Property::FLOAT, TEST_LOCATION );
1166 // Check property count of type-info is 1
1167 Property::IndexContainer indices;
1168 typeInfo.GetPropertyIndices( indices );
1169 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1171 // Ensure indices returned from actor and customActor differ by one
1172 Actor actor = Actor::New();
1173 actor.GetPropertyIndices( indices );
1174 unsigned int actorIndices = indices.Size();
1175 customActor.GetPropertyIndices( indices );
1176 unsigned int customActorIndices = indices.Size();
1177 DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1179 // check that the property is animatable
1180 Animation animation = Animation::New(0.2f);
1181 animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 20.f, AlphaFunction::LINEAR );
1183 // Render and notify, animation play for 0.05 seconds
1184 application.SendNotification();
1185 application.Render(50);
1186 DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
1187 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 12.5f, TEST_LOCATION );
1188 // Render and notify, animation play for another 0.1 seconds
1189 application.SendNotification();
1190 application.Render(100);
1191 DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
1192 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
1197 int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultN(void)
1199 TestApplication application;
1200 TypeRegistry typeRegistry = TypeRegistry::Get();
1202 // Attempt to register an animatable property type out-of-bounds index (less than)
1205 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, false );
1206 tet_result( TET_FAIL );
1208 catch ( DaliException& e )
1210 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1213 // Attempt to register an animatable property type out-of-bounds index (greater than)
1216 AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, true );
1217 tet_result( TET_FAIL );
1219 catch ( DaliException& e )
1221 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1227 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1229 TestApplication application;
1230 TypeRegistry typeRegistry = TypeRegistry::Get();
1232 // Check property count before property registration
1233 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1234 DALI_TEST_CHECK( typeInfo );
1235 BaseHandle handle = typeInfo.CreateInstance();
1236 DALI_TEST_CHECK( handle );
1237 Actor customActor = Actor::DownCast( handle );
1238 DALI_TEST_CHECK( customActor );
1240 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1242 // Register animatable property
1243 std::string animatablePropertyName( "animatableProp1" );
1244 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1245 Property::Type animatablePropertyType( Property::VECTOR2 );
1246 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1248 // Check property count after registration
1249 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1251 // Set the animatable property value
1252 customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1254 // Render and notify
1255 application.SendNotification();
1256 application.Render();
1258 // Check the animatable property value
1259 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1261 // Check the animatable property name
1262 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1264 // Check the animatable property index
1265 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1267 // Check the animatable property type
1268 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1270 // Check property count of type-info is 1
1271 Property::IndexContainer indices;
1272 typeInfo.GetPropertyIndices( indices );
1273 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1275 // Register animatable property components
1276 std::string animatablePropertyComponentName1( "animatableProp1X" );
1277 int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1278 AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1280 std::string animatablePropertyComponentName2( "animatableProp1Y" );
1281 int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1282 AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1284 // Check property count after registration
1285 DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1287 // Check the animatable property component value
1288 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1289 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1291 // Set the animatable property component value
1292 customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1294 // Render and notify
1295 application.SendNotification();
1296 application.Render();
1298 // Check the animatable property value
1299 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1300 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1301 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1303 // Set the animatable property component value
1304 customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1306 // Render and notify
1307 application.SendNotification();
1308 application.Render();
1310 // Check the animatable property value
1311 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1312 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1313 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1315 // Ensure indices returned from actor and customActor differ by three
1316 Actor actor = Actor::New();
1317 actor.GetPropertyIndices( indices );
1318 unsigned int actorIndices = indices.Size();
1319 customActor.GetPropertyIndices( indices );
1320 unsigned int customActorIndices = indices.Size();
1321 DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1326 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1328 TestApplication application;
1329 TypeRegistry typeRegistry = TypeRegistry::Get();
1331 // Register animatable property with the type of Vector2
1332 int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1333 AnimatablePropertyRegistration animatableProperty1( customType1, "animatableProp1", animatablePropertyIndex1, Property::VECTOR2 );
1335 // Attempt to register an animatable property component out-of-bounds index (less than)
1338 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1339 tet_result( TET_FAIL );
1341 catch ( DaliException& e )
1343 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1346 // Attempt to register an animatable property component out-of-bounds index (greater than)
1349 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1350 tet_result( TET_FAIL );
1352 catch ( DaliException& e )
1354 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1357 // Register an animatable property component
1358 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp1X", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1360 // Attempt to register another animatable property component with the same component index
1363 AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatableProp1Y", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1364 tet_result( TET_FAIL );
1366 catch ( DaliException& e )
1368 DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1371 // Register animatable property with the type of boolean
1372 int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1373 AnimatablePropertyRegistration animatableProperty2( customType1, "animatableProp2", animatablePropertyIndex2, Property::BOOLEAN );
1375 // Attempt to register an animatable property component for the above property with boolean type
1378 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatableProp2X", animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1379 tet_result( TET_FAIL );
1381 catch ( DaliException& e )
1383 DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1390 /*******************************************************************************
1392 * Action through the base handle
1394 ******************************************************************************/
1395 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1397 TestApplication application;
1401 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1402 DALI_TEST_CHECK( type );
1404 BaseHandle hdl = type.CreateInstance();
1405 DALI_TEST_CHECK( hdl );
1407 Actor a = Actor::DownCast(hdl);
1408 DALI_TEST_CHECK( a );
1410 a.SetVisible(false);
1412 application.SendNotification();
1413 application.Render(0);
1414 DALI_TEST_CHECK(!a.IsVisible());
1416 Property::Map attributes;
1418 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1420 application.SendNotification();
1421 application.Render(0);
1422 DALI_TEST_CHECK(a.IsVisible());
1424 DALI_TEST_CHECK(!hdl.DoAction("unknownAction", attributes));
1428 int UtcDaliPropertyRegistrationFunctions(void)
1430 TestApplication application;
1431 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1433 // Attempt to register a property without a setter
1436 PropertyRegistration property1( customType1, "propName", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1437 tet_result( TET_PASS );
1439 catch ( DaliException& e )
1441 tet_result( TET_FAIL );
1444 // Attempt to register a property without a getter
1447 PropertyRegistration property1( customType1, "propName", propertyIndex++, Property::BOOLEAN, NULL, NULL );
1448 tet_result( TET_FAIL );
1450 catch ( DaliException& e )
1452 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1457 int UtcDaliPropertyRegistrationAddSameIndex(void)
1459 TestApplication application;
1460 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1462 // Add one property with a valid property index
1463 PropertyRegistration property1( customType1, "propName", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1465 // Attempt to add another property with the same index
1468 PropertyRegistration property2( customType1, "propName2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1470 catch ( DaliException& e )
1472 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1475 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1477 // Add one property with a valid property index
1478 AnimatablePropertyRegistration property3( customType1, "animPropName", animatablePropertyIndex, Property::BOOLEAN );
1480 // Attempt to add another property with the same index
1483 AnimatablePropertyRegistration property4( customType1, "animPropName2", animatablePropertyIndex, Property::BOOLEAN );
1485 catch ( DaliException& e )
1487 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1492 int UtcDaliPropertyRegistrationPropertyWritable(void)
1494 TestApplication application;
1495 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1496 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1498 // Add two properties, one with SetProperty, one without
1499 PropertyRegistration property1( customType1, "propNameReadwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1500 PropertyRegistration property2( customType1, "propNameReadonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1502 // Create custom-actor
1503 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1504 DALI_TEST_CHECK( typeInfo );
1505 BaseHandle handle = typeInfo.CreateInstance();
1506 DALI_TEST_CHECK( handle );
1507 Actor customActor = Actor::DownCast( handle );
1508 DALI_TEST_CHECK( customActor );
1510 // Check whether properties are writable
1511 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
1512 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1516 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1518 TestApplication application;
1519 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1520 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1522 // These properties are not animatable
1523 PropertyRegistration property1( customType1, "propName", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1525 // These properties are animatable
1526 AnimatablePropertyRegistration property2( customType1, "animPropName", animatablePropertyIndex, Property::BOOLEAN );
1528 // Create custom-actor
1529 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1530 DALI_TEST_CHECK( typeInfo );
1531 BaseHandle handle = typeInfo.CreateInstance();
1532 DALI_TEST_CHECK( handle );
1533 Actor customActor = Actor::DownCast( handle );
1534 DALI_TEST_CHECK( customActor );
1536 // Check if animatable
1537 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1538 DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1540 // Create another instance of custom-actor
1541 BaseHandle handle2 = typeInfo.CreateInstance();
1542 DALI_TEST_CHECK( handle2 );
1543 Actor customActor2 = Actor::DownCast( handle2 );
1544 DALI_TEST_CHECK( customActor2 );
1546 // Check if animatable
1547 DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1548 DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1552 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1554 TestApplication application;
1555 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1556 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1558 // Create custom-actor
1559 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1560 DALI_TEST_CHECK( typeInfo );
1561 BaseHandle handle = typeInfo.CreateInstance();
1562 DALI_TEST_CHECK( handle );
1563 Actor customActor = Actor::DownCast( handle );
1564 DALI_TEST_CHECK( customActor );
1566 // Try to set an index that hasn't been added
1569 customActor.SetProperty( propertyIndex, true );
1570 tet_result( TET_FAIL );
1572 catch ( DaliException& e )
1574 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1579 customActor.SetProperty( animatablePropertyIndex, true );
1580 tet_result( TET_FAIL );
1582 catch ( DaliException& e )
1584 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1587 // Try to get an index that hasn't been added
1590 (void) customActor.GetProperty< bool >( propertyIndex );
1591 tet_result( TET_FAIL );
1593 catch ( DaliException& e )
1595 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1600 (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1601 tet_result( TET_FAIL );
1603 catch ( DaliException& e )
1605 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1611 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1613 TestApplication application;
1615 Actor actor = Actor::New();
1616 actor.SetSize(100.0f, 100.0f);
1617 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1618 Stage::GetCurrent().Add(actor);
1622 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1623 DALI_TEST_CHECK( type );
1624 BaseHandle handle = type.CreateInstance();
1625 DALI_TEST_CHECK( handle );
1626 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1627 DALI_TEST_CHECK( detector );
1629 // Attach actor to detector
1631 GestureReceivedFunctor functor( data );
1632 detector.Attach(actor);
1634 // Connect to signal through type
1635 handle.ConnectSignal( &application, "longPressDetected", functor );
1637 // Render and notify
1638 application.SendNotification();
1639 application.Render();
1642 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1643 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1644 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1645 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1649 int UtcDaliPanGestureDetectorTypeRegistry(void)
1651 TestApplication application;
1653 Actor actor = Actor::New();
1654 actor.SetSize(100.0f, 100.0f);
1655 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1656 Stage::GetCurrent().Add(actor);
1660 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1661 DALI_TEST_CHECK( type );
1662 BaseHandle handle = type.CreateInstance();
1663 DALI_TEST_CHECK( handle );
1664 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1665 DALI_TEST_CHECK( detector );
1667 // Attach actor to detector
1669 GestureReceivedFunctor functor( data );
1670 detector.Attach(actor);
1672 // Connect to signal through type
1673 handle.ConnectSignal( &application, "panDetected", functor );
1675 // Render and notify
1676 application.SendNotification();
1677 application.Render();
1680 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1681 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1682 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1683 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1687 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1689 TestApplication application;
1691 Actor actor = Actor::New();
1692 actor.SetSize(100.0f, 100.0f);
1693 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1694 Stage::GetCurrent().Add(actor);
1698 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1699 DALI_TEST_CHECK( type );
1700 BaseHandle handle = type.CreateInstance();
1701 DALI_TEST_CHECK( handle );
1702 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1703 DALI_TEST_CHECK( detector );
1705 // Attach actor to detector
1707 GestureReceivedFunctor functor( data );
1708 detector.Attach(actor);
1710 // Connect to signal through type
1711 handle.ConnectSignal( &application, "pinchDetected", functor );
1713 // Render and notify
1714 application.SendNotification();
1715 application.Render();
1718 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1719 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1723 int UtcDaliTapGestureDetectorTypeRegistry(void)
1725 TestApplication application;
1727 Actor actor = Actor::New();
1728 actor.SetSize(100.0f, 100.0f);
1729 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1730 Stage::GetCurrent().Add(actor);
1734 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1735 DALI_TEST_CHECK( type );
1736 BaseHandle handle = type.CreateInstance();
1737 DALI_TEST_CHECK( handle );
1738 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1739 DALI_TEST_CHECK( detector );
1741 // Attach actor to detector
1743 GestureReceivedFunctor functor( data );
1744 detector.Attach(actor);
1746 // Connect to signal through type
1747 handle.ConnectSignal( &application, "tapDetected", functor );
1749 // Render and notify
1750 application.SendNotification();
1751 application.Render();
1754 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1755 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1756 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1760 int UtcDaliTypeRegistryNamedType(void)
1762 TestApplication application;
1763 TypeRegistry typeRegistry = TypeRegistry::Get();
1765 // Create a normal actor
1766 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1767 DALI_TEST_CHECK( actorHandle );
1768 Actor actor( Actor::DownCast( actorHandle ) );
1769 DALI_TEST_CHECK( actor );
1770 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1772 // Create Named Actor Type
1773 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1774 DALI_TEST_CHECK( namedHandle );
1775 Actor namedActor( Actor::DownCast( namedHandle ) );
1776 DALI_TEST_CHECK( namedActor );
1777 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1779 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1783 int UtcDaliTypeInfoGetActionNameP(void)
1785 TestApplication application;
1786 TypeRegistry typeRegistry = TypeRegistry::Get();
1788 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1789 DALI_TEST_CHECK( typeInfo );
1791 DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
1793 std::string name = typeInfo.GetActionName(0);
1795 DALI_TEST_EQUALS( name, "show", TEST_LOCATION );
1800 int UtcDaliTypeInfoGetActionNameN(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(std::numeric_limits<size_t>::max());
1812 DALI_TEST_EQUALS( 0u, name.size(), TEST_LOCATION );
1817 int UtcDaliTypeInfoGetSignalNameP(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.GetSignalCount() );
1827 std::string name = typeInfo.GetSignalName(0);
1829 DALI_TEST_EQUALS( name, "touched", TEST_LOCATION );
1834 int UtcDaliTypeInfoGetSignalNameN(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(std::numeric_limits<size_t>::max());
1846 DALI_TEST_EQUALS( 0u, name.size(), TEST_LOCATION );