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()
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, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
522 } // Anonymous namespace
524 // Note: No negative test case for UtcDaliTypeRegistryGet can be implemented.
525 int UtcDaliTypeRegistryGetP(void)
527 TestApplication application;
529 TypeRegistry registry = TypeRegistry::Get();
530 DALI_TEST_CHECK( registry );
535 // Note: No negative test case for UtcDaliTypeRegistryConstructor can be implemented.
536 int UtcDaliTypeRegistryConstructorP(void)
538 TestApplication application;
540 TypeRegistry registry;
541 DALI_TEST_CHECK( !registry );
545 // Note: No negative test case for UtcDaliTypeRegistryCopyConstructor can be implemented.
546 int UtcDaliTypeRegistryCopyConstructorP(void)
548 TestApplication application;
550 TypeRegistry registry = TypeRegistry::Get();
551 DALI_TEST_CHECK( registry );
553 TypeRegistry copy( registry );
554 DALI_TEST_CHECK( copy );
556 DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
561 // Note: No negative test case for UtcDaliTypeRegistryAssignmentOperator can be implemented.
562 int UtcDaliTypeRegistryAssignmentOperatorP(void)
564 TestApplication application;
566 TypeRegistry registry = TypeRegistry::Get();
567 DALI_TEST_CHECK( registry );
569 TypeRegistry copy = registry;
570 DALI_TEST_CHECK( copy );
571 DALI_TEST_CHECK( registry == copy );
573 DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
578 int UtcDaliTypeRegistryAssignP(void)
580 TestApplication application;
582 TypeRegistry registry = TypeRegistry::Get();
583 TypeRegistry registry2;
584 registry2 = registry;
585 DALI_TEST_CHECK( registry2 );
587 DALI_TEST_CHECK( registry2.GetTypeInfo( "Actor" ).GetName() == registry2.GetTypeInfo( "Actor" ).GetName() );
592 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameP(void)
594 TestApplication application;
596 TypeRegistry registry = TypeRegistry::Get();
601 type = registry.GetTypeInfo( "ImageActor" );
602 DALI_TEST_CHECK( type );
603 DALI_TEST_CHECK( type.GetCreator() );
604 DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
605 ImageActor ia = ImageActor::DownCast(type.CreateInstance());
606 DALI_TEST_CHECK( ia );
607 Stage::GetCurrent().Add( ia );
608 application.Render();
611 type = registry.GetTypeInfo( "CameraActor" );
612 DALI_TEST_CHECK( type );
613 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
614 DALI_TEST_CHECK( ca );
615 Stage::GetCurrent().Add( ca );
616 application.Render();
619 type = registry.GetTypeInfo( "Animation" );
620 DALI_TEST_CHECK( type );
621 Animation an = Animation::DownCast(type.CreateInstance());
622 DALI_TEST_CHECK( an );
624 application.Render();
627 type = registry.GetTypeInfo( "ShaderEffect" );
628 DALI_TEST_CHECK( type );
629 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
630 DALI_TEST_CHECK( ef );
631 application.Render();
636 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameN(void)
638 TestApplication application;
640 TypeRegistry registry = TypeRegistry::Get();
644 type = registry.GetTypeInfo( "MyDummyActor" );
645 DALI_TEST_CHECK( !type );
650 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdP(void)
652 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
653 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
655 DALI_TEST_CHECK( named_type );
656 DALI_TEST_CHECK( typeinfo_type );
658 // Check named and typeid are equivalent
659 DALI_TEST_CHECK( named_type == typeinfo_type );
661 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
662 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
667 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdN(void)
669 TestApplication application;
670 TypeRegistry typeRegistry = TypeRegistry::Get();
672 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(Vector2) );
673 DALI_TEST_CHECK( !typeInfo );
678 int UtcDaliTypeRegistryGetTypeNameCountP(void)
680 TestApplication application;
681 TypeRegistry typeRegistry = TypeRegistry::Get();
684 for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
686 type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
687 DALI_TEST_CHECK( type );
694 int UtcDaliTypeRegistryGetTypeNamesP(void)
696 TestApplication application;
697 TypeRegistry typeRegistry = TypeRegistry::Get();
700 for(size_t i = 0; i < typeRegistry.GetTypeNameCount(); i++)
702 type = typeRegistry.GetTypeInfo( typeRegistry.GetTypeName(i) );
703 DALI_TEST_CHECK( type );
710 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
711 int UtcDaliTypeRegistryTypeRegistrationNotCallingCreateOnInitP(void)
713 ResetFunctorCounts();
715 TestApplication application;
717 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
718 DALI_TEST_CHECK( type );
720 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
721 DALI_TEST_CHECK( baseType );
723 BaseHandle handle = type.CreateInstance();
724 DALI_TEST_CHECK( handle );
726 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
727 DALI_TEST_CHECK( customHandle );
729 DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
731 DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
734 TestConnectionTracker tracker;
736 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
737 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
738 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
739 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
740 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
742 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
743 customHandle.GetCustomSignal().Emit();
744 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
745 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
746 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
748 // tracker should automatically disconnect here
749 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
750 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
752 // Test that functor is disconnected
753 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
754 customHandle.GetCustomSignal().Emit();
755 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
756 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
757 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
759 Property::Map attributes;
760 handle.DoAction("act1", attributes);
761 DALI_TEST_CHECK( lastActionCustom == "act1" );
765 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
766 int UtcDaliTypeRegistryTypeRegistrationCallingCreateOnInitP(void)
768 TestApplication application;
770 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
772 DALI_TEST_CHECK( true == CreateCustomInitCalled );
773 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
774 DALI_TEST_CHECK( type );
778 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
779 int UtcDaliTypeRegistryTypeRegistrationForNamedTypeP(void)
781 TestApplication application;
783 // Create Named Actor Type
784 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyNamedActor" );
785 DALI_TEST_CHECK( type );
787 BaseHandle namedHandle = type.CreateInstance();
788 DALI_TEST_CHECK( namedHandle );
789 Actor namedActor( Actor::DownCast( namedHandle ) );
790 DALI_TEST_CHECK( namedActor );
792 DALI_TEST_CHECK( namedActor.GetName() == "NamedActor" );
793 DALI_TEST_CHECK( type.GetName() == "MyNamedActor" );
794 DALI_TEST_CHECK( type.GetBaseName() == "Actor" );
799 // Note: No negative test case for UtcDaliTypeRegistryRegisteredName can be implemented.
800 int UtcDaliTypeRegistryRegisteredNameP(void)
802 TestApplication application;
804 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
806 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
807 DALI_TEST_CHECK( baseType );
809 BaseHandle handle = baseType.CreateInstance();
811 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
812 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
813 DALI_TEST_CHECK( type );
817 int UtcDaliTypeRegistrySignalConnectorTypeP(void)
819 ResetFunctorCounts();
821 TestApplication application;
823 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
824 DALI_TEST_CHECK( type );
826 BaseHandle handle = type.CreateInstance();
827 DALI_TEST_CHECK( handle );
829 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
830 DALI_TEST_CHECK( customHandle );
833 TestConnectionTracker tracker;
835 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
836 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
837 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
838 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
839 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
841 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
842 customHandle.GetCustomSignal().Emit();
843 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
844 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
845 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
847 // tracker should automatically disconnect here
848 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
849 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
851 // Test that functor is disconnected
852 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
853 customHandle.GetCustomSignal().Emit();
854 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
855 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
856 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
861 int UtcDaliTypeRegistrySignalConnectorTypeN(void)
863 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
865 ResetFunctorCounts();
867 TestApplication application;
869 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
870 DALI_TEST_CHECK( type );
872 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
873 DALI_TEST_CHECK( baseType );
875 BaseHandle handle = type.CreateInstance();
876 DALI_TEST_CHECK( handle );
878 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
879 DALI_TEST_CHECK( customHandle );
881 DALI_TEST_EQUALS( type.GetActionCount(), TEST_ACTION_COUNT + baseType.GetActionCount(), TEST_LOCATION );
883 DALI_TEST_EQUALS( type.GetSignalCount(), TEST_SIGNAL_COUNT + baseType.GetSignalCount(), TEST_LOCATION );
886 TestConnectionTracker tracker;
888 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
889 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
890 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
891 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
892 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
895 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
896 customHandle.GetCustomSignal().Emit();
897 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
899 // tracker should have nothing to disconnect here
902 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
903 customHandle.GetCustomSignal().Emit();
904 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
908 int UtcDaliTypeRegistryTypeActionP(void)
910 ResetFunctorCounts();
912 TestApplication application;
914 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
915 DALI_TEST_CHECK( type );
917 BaseHandle handle = type.CreateInstance();
918 DALI_TEST_CHECK( handle );
920 Property::Map attributes;
921 DALI_TEST_CHECK( handle.DoAction("act1", attributes) );
922 DALI_TEST_CHECK( lastActionCustom == "act1" );
927 int UtcDaliTypeRegistryTypeActionN(void)
929 ResetFunctorCounts();
931 TestApplication application;
933 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
934 DALI_TEST_CHECK( type );
936 BaseHandle handle = type.CreateInstance();
937 DALI_TEST_CHECK( handle );
939 Property::Map attributes;
940 DALI_TEST_CHECK( !handle.DoAction( "unknown-action", attributes ) );
945 int UtcDaliTypeRegistryPropertyRegistrationP(void)
947 TestApplication application;
948 TypeRegistry typeRegistry = TypeRegistry::Get();
950 // Check property count before property registration
951 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
952 DALI_TEST_CHECK( typeInfo );
953 BaseHandle handle = typeInfo.CreateInstance();
954 DALI_TEST_CHECK( handle );
955 Actor customActor = Actor::DownCast( handle );
956 DALI_TEST_CHECK( customActor );
957 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
959 std::string propertyName( "prop-1" );
960 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
961 Property::Type propertyType( Property::BOOLEAN );
962 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
964 // Check property count after registration
965 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
966 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
968 // Add custom property and check property count
969 customActor.RegisterProperty( "custom-prop-1", true );
970 unsigned int customPropertyCount( customActor.GetPropertyCount() );
971 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
973 // Set the property, ensure SetProperty called
974 DALI_TEST_CHECK( !setPropertyCalled );
975 customActor.SetProperty( propertyIndex, false );
976 DALI_TEST_CHECK( setPropertyCalled );
978 // Get the property, ensure GetProperty called
979 DALI_TEST_CHECK( !getPropertyCalled );
980 (void)customActor.GetProperty< bool >( propertyIndex );
981 DALI_TEST_CHECK( getPropertyCalled );
983 // Check the property name
984 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
985 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
987 // Check the property index
988 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
990 // Check the property type
991 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
993 // Check property count of type-info is 1
994 Property::IndexContainer indices;
995 typeInfo.GetPropertyIndices( indices );
996 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
998 // Ensure indices returned from actor and customActor differ by two
999 Actor actor = Actor::New();
1000 actor.GetPropertyIndices( indices );
1001 unsigned int actorIndices = indices.Size();
1002 customActor.GetPropertyIndices( indices );
1003 unsigned int customActorIndices = indices.Size();
1004 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1008 int UtcDaliTypeRegistryPropertyRegistrationN(void)
1010 TestApplication application;
1011 TypeRegistry typeRegistry = TypeRegistry::Get();
1013 // Attempt to register a property type out-of-bounds index (less than)
1016 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1017 tet_result( TET_FAIL );
1019 catch ( DaliException& e )
1021 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1024 // Attempt to register a property type out-of-bounds index (greater than)
1027 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1028 tet_result( TET_FAIL );
1030 catch ( DaliException& e )
1032 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1038 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1040 TestApplication application;
1041 TypeRegistry typeRegistry = TypeRegistry::Get();
1043 // Check property count before property registration
1044 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1045 DALI_TEST_CHECK( typeInfo );
1046 BaseHandle handle = typeInfo.CreateInstance();
1047 DALI_TEST_CHECK( handle );
1048 Actor customActor = Actor::DownCast( handle );
1049 DALI_TEST_CHECK( customActor );
1051 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1053 // Register animatable property
1054 std::string animatablePropertyName( "animatable-prop-1" );
1055 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1056 Property::Type animatablePropertyType( Property::FLOAT );
1057 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1059 // Check property count after registration
1060 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1062 // Set the animatable property value
1063 customActor.SetProperty( animatablePropertyIndex, 25.0f );
1065 // Render and notify
1066 application.SendNotification();
1067 application.Render();
1069 // Check the animatable property value
1070 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
1072 // Check the animatable property name
1073 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1075 // Check the animatable property index
1076 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1078 // Check the animatable property type
1079 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1081 // Check property count of type-info is 1
1082 Property::IndexContainer indices;
1083 typeInfo.GetPropertyIndices( indices );
1084 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1086 // Ensure indices returned from actor and customActor differ by one
1087 Actor actor = Actor::New();
1088 actor.GetPropertyIndices( indices );
1089 unsigned int actorIndices = indices.Size();
1090 customActor.GetPropertyIndices( indices );
1091 unsigned int customActorIndices = indices.Size();
1092 DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1097 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1099 TestApplication application;
1100 TypeRegistry typeRegistry = TypeRegistry::Get();
1102 // Attempt to register an animatable property type out-of-bounds index (less than)
1105 AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1106 tet_result( TET_FAIL );
1108 catch ( DaliException& e )
1110 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1113 // Attempt to register an animatable property type out-of-bounds index (greater than)
1116 AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1117 tet_result( TET_FAIL );
1119 catch ( DaliException& e )
1121 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1127 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1129 TestApplication application;
1130 TypeRegistry typeRegistry = TypeRegistry::Get();
1132 // Check property count before property registration
1133 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1134 DALI_TEST_CHECK( typeInfo );
1135 BaseHandle handle = typeInfo.CreateInstance();
1136 DALI_TEST_CHECK( handle );
1137 Actor customActor = Actor::DownCast( handle );
1138 DALI_TEST_CHECK( customActor );
1140 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1142 // Register animatable property
1143 std::string animatablePropertyName( "animatable-prop-1" );
1144 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1145 Property::Type animatablePropertyType( Property::VECTOR2 );
1146 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1148 // Check property count after registration
1149 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1151 // Set the animatable property value
1152 customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1154 // Render and notify
1155 application.SendNotification();
1156 application.Render();
1158 // Check the animatable property value
1159 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1161 // Check the animatable property name
1162 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1164 // Check the animatable property index
1165 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1167 // Check the animatable property type
1168 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1170 // Check property count of type-info is 1
1171 Property::IndexContainer indices;
1172 typeInfo.GetPropertyIndices( indices );
1173 DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
1175 // Register animatable property components
1176 std::string animatablePropertyComponentName1( "animatable-prop-1-x" );
1177 int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1178 AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1180 std::string animatablePropertyComponentName2( "animatable-prop-1-y" );
1181 int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1182 AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1184 // Check property count after registration
1185 DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1187 // Check the animatable property component value
1188 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1189 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1191 // Set the animatable property component value
1192 customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1194 // Render and notify
1195 application.SendNotification();
1196 application.Render();
1198 // Check the animatable property value
1199 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1200 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1201 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1203 // Set the animatable property component value
1204 customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1206 // Render and notify
1207 application.SendNotification();
1208 application.Render();
1210 // Check the animatable property value
1211 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1212 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1213 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1215 // Ensure indices returned from actor and customActor differ by three
1216 Actor actor = Actor::New();
1217 actor.GetPropertyIndices( indices );
1218 unsigned int actorIndices = indices.Size();
1219 customActor.GetPropertyIndices( indices );
1220 unsigned int customActorIndices = indices.Size();
1221 DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1226 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1228 TestApplication application;
1229 TypeRegistry typeRegistry = TypeRegistry::Get();
1231 // Register animatable property with the type of Vector2
1232 int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1233 AnimatablePropertyRegistration animatableProperty1( customType1, "animatable-prop-1", animatablePropertyIndex1, Property::VECTOR2 );
1235 // Attempt to register an animatable property component out-of-bounds index (less than)
1238 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1239 tet_result( TET_FAIL );
1241 catch ( DaliException& e )
1243 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1246 // Attempt to register an animatable property component out-of-bounds index (greater than)
1249 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1250 tet_result( TET_FAIL );
1252 catch ( DaliException& e )
1254 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1257 // Register an animatable property component
1258 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1260 // Attempt to register another animatable property component with the same component index
1263 AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatable-prop-1-y", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1264 tet_result( TET_FAIL );
1266 catch ( DaliException& e )
1268 DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1271 // Register animatable property with the type of boolean
1272 int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1273 AnimatablePropertyRegistration animatableProperty2( customType1, "animatable-prop-2", animatablePropertyIndex2, Property::BOOLEAN );
1275 // Attempt to register an animatable property component for the above property with boolean type
1278 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-2-x", animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1279 tet_result( TET_FAIL );
1281 catch ( DaliException& e )
1283 DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1290 /*******************************************************************************
1292 * Action through the base handle
1294 ******************************************************************************/
1295 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1297 TestApplication application;
1301 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1302 DALI_TEST_CHECK( type );
1304 BaseHandle hdl = type.CreateInstance();
1305 DALI_TEST_CHECK( hdl );
1307 Actor a = Actor::DownCast(hdl);
1308 DALI_TEST_CHECK( a );
1310 a.SetVisible(false);
1312 application.SendNotification();
1313 application.Render(0);
1314 DALI_TEST_CHECK(!a.IsVisible());
1316 Property::Map attributes;
1318 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1320 application.SendNotification();
1321 application.Render(0);
1322 DALI_TEST_CHECK(a.IsVisible());
1324 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
1328 int UtcDaliPropertyRegistrationFunctions(void)
1330 TestApplication application;
1331 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1333 // Attempt to register a property without a setter
1336 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1337 tet_result( TET_PASS );
1339 catch ( DaliException& e )
1341 tet_result( TET_FAIL );
1344 // Attempt to register a property without a getter
1347 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
1348 tet_result( TET_FAIL );
1350 catch ( DaliException& e )
1352 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1357 int UtcDaliPropertyRegistrationAddSameIndex(void)
1359 TestApplication application;
1360 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1362 // Add one property with a valid property index
1363 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1365 // Attempt to add another property with the same index
1368 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1370 catch ( DaliException& e )
1372 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1375 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1377 // Add one property with a valid property index
1378 AnimatablePropertyRegistration property3( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1380 // Attempt to add another property with the same index
1383 AnimatablePropertyRegistration property4( customType1, "anim-prop-name-2", animatablePropertyIndex, Property::BOOLEAN );
1385 catch ( DaliException& e )
1387 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1392 int UtcDaliPropertyRegistrationPropertyWritable(void)
1394 TestApplication application;
1395 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1396 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1398 // Add two properties, one with SetProperty, one without
1399 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1400 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1402 // Create custom-actor
1403 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1404 DALI_TEST_CHECK( typeInfo );
1405 BaseHandle handle = typeInfo.CreateInstance();
1406 DALI_TEST_CHECK( handle );
1407 Actor customActor = Actor::DownCast( handle );
1408 DALI_TEST_CHECK( customActor );
1410 // Check whether properties are writable
1411 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
1412 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1416 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1418 TestApplication application;
1419 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1420 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1422 // These properties are not animatable
1423 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1425 // These properties are animatable
1426 AnimatablePropertyRegistration property2( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1428 // Create custom-actor
1429 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1430 DALI_TEST_CHECK( typeInfo );
1431 BaseHandle handle = typeInfo.CreateInstance();
1432 DALI_TEST_CHECK( handle );
1433 Actor customActor = Actor::DownCast( handle );
1434 DALI_TEST_CHECK( customActor );
1436 // Check if animatable
1437 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1438 DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1440 // Create another instance of custom-actor
1441 BaseHandle handle2 = typeInfo.CreateInstance();
1442 DALI_TEST_CHECK( handle2 );
1443 Actor customActor2 = Actor::DownCast( handle2 );
1444 DALI_TEST_CHECK( customActor2 );
1446 // Check if animatable
1447 DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1448 DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1452 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1454 TestApplication application;
1455 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1456 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1458 // Create custom-actor
1459 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1460 DALI_TEST_CHECK( typeInfo );
1461 BaseHandle handle = typeInfo.CreateInstance();
1462 DALI_TEST_CHECK( handle );
1463 Actor customActor = Actor::DownCast( handle );
1464 DALI_TEST_CHECK( customActor );
1466 // Try to set an index that hasn't been added
1469 customActor.SetProperty( propertyIndex, true );
1470 tet_result( TET_FAIL );
1472 catch ( DaliException& e )
1474 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1479 customActor.SetProperty( animatablePropertyIndex, true );
1480 tet_result( TET_FAIL );
1482 catch ( DaliException& e )
1484 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1487 // Try to get an index that hasn't been added
1490 (void) customActor.GetProperty< bool >( propertyIndex );
1491 tet_result( TET_FAIL );
1493 catch ( DaliException& e )
1495 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1500 (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1501 tet_result( TET_FAIL );
1503 catch ( DaliException& e )
1505 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1511 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1513 TestApplication application;
1515 Actor actor = Actor::New();
1516 actor.SetSize(100.0f, 100.0f);
1517 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1518 Stage::GetCurrent().Add(actor);
1522 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1523 DALI_TEST_CHECK( type );
1524 BaseHandle handle = type.CreateInstance();
1525 DALI_TEST_CHECK( handle );
1526 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1527 DALI_TEST_CHECK( detector );
1529 // Attach actor to detector
1531 GestureReceivedFunctor functor( data );
1532 detector.Attach(actor);
1534 // Connect to signal through type
1535 handle.ConnectSignal( &application, "long-press-detected", functor );
1537 // Render and notify
1538 application.SendNotification();
1539 application.Render();
1542 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1543 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1544 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1545 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1549 int UtcDaliPanGestureDetectorTypeRegistry(void)
1551 TestApplication application;
1553 Actor actor = Actor::New();
1554 actor.SetSize(100.0f, 100.0f);
1555 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1556 Stage::GetCurrent().Add(actor);
1560 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1561 DALI_TEST_CHECK( type );
1562 BaseHandle handle = type.CreateInstance();
1563 DALI_TEST_CHECK( handle );
1564 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1565 DALI_TEST_CHECK( detector );
1567 // Attach actor to detector
1569 GestureReceivedFunctor functor( data );
1570 detector.Attach(actor);
1572 // Connect to signal through type
1573 handle.ConnectSignal( &application, "pan-detected", functor );
1575 // Render and notify
1576 application.SendNotification();
1577 application.Render();
1580 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1581 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1582 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1583 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1587 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1589 TestApplication application;
1591 Actor actor = Actor::New();
1592 actor.SetSize(100.0f, 100.0f);
1593 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1594 Stage::GetCurrent().Add(actor);
1598 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1599 DALI_TEST_CHECK( type );
1600 BaseHandle handle = type.CreateInstance();
1601 DALI_TEST_CHECK( handle );
1602 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1603 DALI_TEST_CHECK( detector );
1605 // Attach actor to detector
1607 GestureReceivedFunctor functor( data );
1608 detector.Attach(actor);
1610 // Connect to signal through type
1611 handle.ConnectSignal( &application, "pinch-detected", functor );
1613 // Render and notify
1614 application.SendNotification();
1615 application.Render();
1618 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1619 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1623 int UtcDaliTapGestureDetectorTypeRegistry(void)
1625 TestApplication application;
1627 Actor actor = Actor::New();
1628 actor.SetSize(100.0f, 100.0f);
1629 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1630 Stage::GetCurrent().Add(actor);
1634 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1635 DALI_TEST_CHECK( type );
1636 BaseHandle handle = type.CreateInstance();
1637 DALI_TEST_CHECK( handle );
1638 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1639 DALI_TEST_CHECK( detector );
1641 // Attach actor to detector
1643 GestureReceivedFunctor functor( data );
1644 detector.Attach(actor);
1646 // Connect to signal through type
1647 handle.ConnectSignal( &application, "tap-detected", functor );
1649 // Render and notify
1650 application.SendNotification();
1651 application.Render();
1654 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1655 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1656 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1660 int UtcDaliTypeRegistryNamedType(void)
1662 TestApplication application;
1663 TypeRegistry typeRegistry = TypeRegistry::Get();
1665 // Create a normal actor
1666 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1667 DALI_TEST_CHECK( actorHandle );
1668 Actor actor( Actor::DownCast( actorHandle ) );
1669 DALI_TEST_CHECK( actor );
1670 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1672 // Create Named Actor Type
1673 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1674 DALI_TEST_CHECK( namedHandle );
1675 Actor namedActor( Actor::DownCast( namedHandle ) );
1676 DALI_TEST_CHECK( namedActor );
1677 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1679 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );
1683 int UtcDaliTypeInfoGetActionNameP(void)
1685 TestApplication application;
1686 TypeRegistry typeRegistry = TypeRegistry::Get();
1688 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1689 DALI_TEST_CHECK( typeInfo );
1691 DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
1693 std::string name = typeInfo.GetActionName(0);
1695 DALI_TEST_EQUALS( name, "show", TEST_LOCATION );
1700 int UtcDaliTypeInfoGetActionNameN(void)
1702 TestApplication application;
1703 TypeRegistry typeRegistry = TypeRegistry::Get();
1705 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1706 DALI_TEST_CHECK( typeInfo );
1708 DALI_TEST_CHECK( 0 != typeInfo.GetActionCount() );
1710 std::string name = typeInfo.GetActionName(std::numeric_limits<size_t>::max());
1712 DALI_TEST_EQUALS( 0, name.size(), TEST_LOCATION );
1717 int UtcDaliTypeInfoGetSignalNameP(void)
1719 TestApplication application;
1720 TypeRegistry typeRegistry = TypeRegistry::Get();
1722 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1723 DALI_TEST_CHECK( typeInfo );
1725 DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
1727 std::string name = typeInfo.GetSignalName(0);
1729 DALI_TEST_EQUALS( name, "touched", TEST_LOCATION );
1734 int UtcDaliTypeInfoGetSignalNameN(void)
1736 TestApplication application;
1737 TypeRegistry typeRegistry = TypeRegistry::Get();
1739 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "Actor" );
1740 DALI_TEST_CHECK( typeInfo );
1742 DALI_TEST_CHECK( 0 != typeInfo.GetSignalCount() );
1744 std::string name = typeInfo.GetSignalName(std::numeric_limits<size_t>::max());
1746 DALI_TEST_EQUALS( 0, name.size(), TEST_LOCATION );