2 * Copyright (c) 2014 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.
20 #include <dali/public-api/dali-core.h>
21 #include <dali-test-suite-utils.h>
22 #include <dali/integration-api/events/long-press-gesture-event.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24 #include <dali/integration-api/events/pinch-gesture-event.h>
25 #include <dali/integration-api/events/tap-gesture-event.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/integration-api/events/hover-event-integ.h>
35 // Stores data that is populated in the callback and will be read by the Test cases
39 : functorCalled( false ),
40 voidFunctorCalled( false ),
41 receivedGesture( Gesture::Clear ),
47 functorCalled = false;
48 voidFunctorCalled = false;
50 receivedGesture.numberOfTouches = 0u;
51 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
52 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
58 bool voidFunctorCalled;
59 LongPressGesture receivedGesture;
63 // Functor that sets the data when called
64 struct GestureReceivedFunctor
66 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
68 void operator()(Actor actor, LongPressGesture longPress)
70 signalData.functorCalled = true;
71 signalData.receivedGesture = longPress;
72 signalData.pressedActor = actor;
77 signalData.voidFunctorCalled = true;
80 SignalData& signalData;
83 // Generate a LongPressGestureEvent to send to Core
84 Integration::LongPressGestureEvent GenerateLongPress(
86 unsigned int numberOfTouches,
89 Integration::LongPressGestureEvent longPress( state );
91 longPress.numberOfTouches = numberOfTouches;
92 longPress.point = point;
97 // Generate a PanGestureEvent to send to Core
98 Integration::PanGestureEvent GeneratePan(
100 Vector2 previousPosition,
101 Vector2 currentPosition,
102 unsigned long timeDelta,
103 unsigned int numberOfTouches = 1,
104 unsigned int time = 1u)
106 Integration::PanGestureEvent pan(state);
108 pan.previousPosition = previousPosition;
109 pan.currentPosition = currentPosition;
110 pan.timeDelta = timeDelta;
111 pan.numberOfTouches = numberOfTouches;
116 // Generate a PinchGestureEvent to send to Core
117 Integration::PinchGestureEvent GeneratePinch(
118 Gesture::State state,
123 Integration::PinchGestureEvent pinch(state);
127 pinch.centerPoint = centerpoint;
131 // Generate a TapGestureEvent to send to Core
132 Integration::TapGestureEvent GenerateTap(
133 Gesture::State state,
134 unsigned int numberOfTaps,
135 unsigned int numberOfTouches,
138 Integration::TapGestureEvent tap( state );
140 tap.numberOfTaps = numberOfTaps;
141 tap.numberOfTouches = numberOfTouches;
148 // Create function as Init function called
150 static bool CreateCustomInitCalled = false;
151 BaseHandle CreateCustomInit(void)
153 CreateCustomInitCalled = true;
157 static bool CreateCustomNamedInitCalled = false;
158 BaseHandle CreateCustomNamedInit(void)
160 CreateCustomNamedInitCalled = true;
164 const std::string scriptedName("PopupStyle");
165 static TypeRegistration scriptedType( scriptedName, typeid(Dali::CustomActor), CreateCustomNamedInit );
167 // Property Registration
168 bool setPropertyCalled = false;
169 bool getPropertyCalled = false;
170 void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
172 setPropertyCalled = true;
174 Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex )
176 getPropertyCalled = true;
177 return Property::Value( true );
182 /*******************************************************************************
186 ******************************************************************************/
189 struct MyTestCustomActor : public CustomActorImpl
191 typedef Signal< void ()> SignalType;
192 typedef Signal< void (float)> SignalTypeFloat;
194 MyTestCustomActor() : CustomActorImpl( true ) // requires touch
197 virtual ~MyTestCustomActor()
200 void ResetCallStack()
204 // From CustomActorImpl
205 virtual void OnStageConnection()
208 virtual void OnStageDisconnection()
211 virtual void OnChildAdd(Actor& child)
214 virtual void OnChildRemove(Actor& child)
217 virtual void OnSizeSet(const Vector3& targetSize)
220 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
223 virtual bool OnTouchEvent(const TouchEvent& event)
227 virtual bool OnHoverEvent(const HoverEvent& event)
231 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
235 virtual bool OnKeyEvent(const KeyEvent& event)
239 virtual void OnKeyInputFocusGained()
242 virtual void OnKeyInputFocusLost()
245 virtual Vector3 GetNaturalSize()
247 return Vector3( 0.0f, 0.0f, 0.0f );
250 virtual float GetHeightForWidth( float width )
255 virtual float GetWidthForHeight( float height )
260 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
264 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
268 virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
272 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
277 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
281 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
293 class MyTestCustomActor : public CustomActor
297 typedef Signal< void ()> SignalType;
298 typedef Signal< void (float)> SignalTypeFloat;
304 static MyTestCustomActor New()
306 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
307 return MyTestCustomActor( *p ); // takes ownership
310 virtual ~MyTestCustomActor()
314 static MyTestCustomActor DownCast( BaseHandle handle )
316 MyTestCustomActor result;
318 CustomActor custom = Dali::CustomActor::DownCast( handle );
321 CustomActorImpl& customImpl = custom.GetImplementation();
323 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
327 result = MyTestCustomActor(customImpl.GetOwner());
334 SignalType& GetCustomSignal()
336 Dali::RefObject& obj = GetImplementation();
337 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
342 MyTestCustomActor(Internal::CustomActor* internal)
343 : CustomActor(internal)
347 MyTestCustomActor( Impl::MyTestCustomActor& impl )
348 : CustomActor( impl )
354 class MyTestCustomActor2 : public CustomActor
362 static MyTestCustomActor2 New()
364 return MyTestCustomActor2(); // takes ownership
367 virtual ~MyTestCustomActor2()
371 static MyTestCustomActor2 DownCast( BaseHandle handle )
373 MyTestCustomActor2 result;
375 CustomActor custom = Dali::CustomActor::DownCast( handle );
378 CustomActorImpl& customImpl = custom.GetImplementation();
380 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
384 result = MyTestCustomActor2(customImpl.GetOwner());
393 MyTestCustomActor2(Internal::CustomActor* internal)
394 : CustomActor(internal)
398 MyTestCustomActor2( Impl::MyTestCustomActor& impl )
399 : CustomActor( impl )
404 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
407 BaseHandle CreateCustom(void)
409 return MyTestCustomActor::New();
412 static std::string lastSignalConnectionCustom;
414 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
416 lastSignalConnectionCustom = signalName;
418 bool connected( true );
420 Dali::BaseHandle handle(object);
421 MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
423 if( "sig1" == signalName )
425 customActor.GetCustomSignal().Connect( tracker, functor );
429 // signalName does not match any signal
436 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
438 lastSignalConnectionCustom = "failed";
440 return false; // This is supposed to fail
443 struct CustomTestFunctor
447 ++mTotalInstanceCount;
448 ++mCurrentInstanceCount;
451 CustomTestFunctor( const CustomTestFunctor& copyMe )
453 ++mTotalInstanceCount;
454 ++mCurrentInstanceCount;
459 --mCurrentInstanceCount;
467 static int mTotalInstanceCount;
468 static int mCurrentInstanceCount;
469 static int mCallbackCount;
472 int CustomTestFunctor::mTotalInstanceCount = 0;
473 int CustomTestFunctor::mCurrentInstanceCount = 0;
474 int CustomTestFunctor::mCallbackCount = 0;
476 static void ResetFunctorCounts()
478 CustomTestFunctor::mTotalInstanceCount = 0;
479 CustomTestFunctor::mCurrentInstanceCount = 0;
480 CustomTestFunctor::mCallbackCount = 0;
483 static std::string lastActionCustom;
484 bool DoActionCustom(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
486 lastActionCustom = actionName;
490 // Custom type registration
491 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
494 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
495 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
496 static const int TEST_SIGNAL_COUNT = 2;
499 static TypeAction customAction1( customType1, "act1", DoActionCustom);
500 static const int TEST_ACTION_COUNT = 1;
502 class TestConnectionTracker : public ConnectionTracker
506 TestConnectionTracker()
511 BaseHandle CreateNamedActorType()
513 Actor actor = Actor::New();
514 actor.SetName( "NamedActor" );
518 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
519 PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
521 } // Anonymous namespace
524 // Positive test case for a method
525 int UtcDaliTypeRegistryCreateDaliObjects(void)
527 TestApplication application;
529 TypeRegistry registry; // like this for ctor test coverage
530 registry = TypeRegistry::Get();
534 type = registry.GetTypeInfo( "ImageActor" );
535 DALI_TEST_CHECK( type );
536 DALI_TEST_CHECK( type.GetCreator() );
537 DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
538 ImageActor ia = ImageActor::DownCast(type.CreateInstance());
539 DALI_TEST_CHECK( ia );
540 Stage::GetCurrent().Add( ia );
541 application.Render();
543 type = registry.GetTypeInfo( "CameraActor" );
544 DALI_TEST_CHECK( type );
545 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
546 DALI_TEST_CHECK( ca );
547 Stage::GetCurrent().Add( ca );
548 application.Render();
551 type = registry.GetTypeInfo( "Animation" );
552 DALI_TEST_CHECK( type );
553 Animation an = Animation::DownCast(type.CreateInstance());
554 DALI_TEST_CHECK( an );
556 application.Render();
559 type = registry.GetTypeInfo( "ShaderEffect" );
560 DALI_TEST_CHECK( type );
561 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
562 DALI_TEST_CHECK( ef );
563 application.Render();
568 /*******************************************************************************
570 * Action through the base handle
572 ******************************************************************************/
573 int UtcDaliTypeRegistryActionViaBaseHandle(void)
575 TestApplication application;
579 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
580 DALI_TEST_CHECK( type );
582 BaseHandle hdl = type.CreateInstance();
583 DALI_TEST_CHECK( hdl );
585 Actor a = Actor::DownCast(hdl);
586 DALI_TEST_CHECK( a );
590 application.SendNotification();
591 application.Render(0);
592 DALI_TEST_CHECK(!a.IsVisible());
594 std::vector<Property::Value> attributes;
596 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
598 application.SendNotification();
599 application.Render(0);
600 DALI_TEST_CHECK(a.IsVisible());
602 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
606 int UtcDaliTypeRegistryNames(void)
608 TestApplication application;
612 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
614 for(TypeRegistry::NameContainer::iterator iter = names.begin();
615 iter != names.end(); ++iter)
617 type = TypeRegistry::Get().GetTypeInfo( *iter );
618 DALI_TEST_CHECK( type );
624 // Check named and typeid are equivalent
625 int UtcDaliTypeRegistryNameEquivalence(void)
627 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
628 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
630 DALI_TEST_CHECK( named_type );
631 DALI_TEST_CHECK( typeinfo_type );
633 DALI_TEST_CHECK( named_type == typeinfo_type );
635 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
636 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
642 int UtcDaliTypeRegistryCustomActor(void)
644 ResetFunctorCounts();
646 TestApplication application;
648 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
649 DALI_TEST_CHECK( type );
651 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
652 DALI_TEST_CHECK( baseType );
654 BaseHandle handle = type.CreateInstance();
655 DALI_TEST_CHECK( handle );
657 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
658 DALI_TEST_CHECK( customHandle );
660 TypeInfo::NameContainer names;
661 type.GetActions(names);
662 TypeInfo::NameContainer baseNames;
663 baseType.GetActions(baseNames);
664 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
667 type.GetSignals(names);
670 baseType.GetSignals(baseNames);
672 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
675 TestConnectionTracker tracker;
677 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
678 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
679 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
680 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
681 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
683 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
684 customHandle.GetCustomSignal().Emit();
685 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
686 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
687 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
689 // tracker should automatically disconnect here
690 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
691 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
693 // Test that functor is disconnected
694 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
695 customHandle.GetCustomSignal().Emit();
696 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
697 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
698 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
700 std::vector<Property::Value> attributes;
701 handle.DoAction("act1", attributes);
702 DALI_TEST_CHECK( lastActionCustom == "act1" );
706 int UtcDaliTypeRegistryCustomSignalFailure(void)
708 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
710 ResetFunctorCounts();
712 TestApplication application;
714 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
715 DALI_TEST_CHECK( type );
717 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
718 DALI_TEST_CHECK( baseType );
720 BaseHandle handle = type.CreateInstance();
721 DALI_TEST_CHECK( handle );
723 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
724 DALI_TEST_CHECK( customHandle );
726 TypeInfo::NameContainer names;
727 TypeInfo::NameContainer baseNames;
729 type.GetActions(names);
730 baseType.GetActions(baseNames);
732 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
737 type.GetSignals(names);
738 baseType.GetSignals(baseNames);
740 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
743 TestConnectionTracker tracker;
745 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
746 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
747 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
748 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
749 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
752 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
753 customHandle.GetCustomSignal().Emit();
754 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
756 // tracker should have nothing to disconnect here
759 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
760 customHandle.GetCustomSignal().Emit();
761 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
765 int UtcDaliTypeRegistryInitFunctions(void)
767 TestApplication application;
769 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
771 DALI_TEST_CHECK( true == CreateCustomInitCalled );
772 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
773 DALI_TEST_CHECK( type );
778 int UtcDaliTypeRegistryNameInitFunctions(void)
780 TestApplication application;
782 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
784 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
785 DALI_TEST_CHECK( baseType );
787 BaseHandle handle = baseType.CreateInstance();
789 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
790 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
791 DALI_TEST_CHECK( type );
796 int UtcDaliPropertyRegistration(void)
798 TestApplication application;
799 TypeRegistry typeRegistry = TypeRegistry::Get();
801 // Check property count before property registration
802 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
803 DALI_TEST_CHECK( typeInfo );
804 BaseHandle handle = typeInfo.CreateInstance();
805 DALI_TEST_CHECK( handle );
806 Actor customActor = Actor::DownCast( handle );
807 DALI_TEST_CHECK( customActor );
808 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
810 std::string propertyName( "prop-1" );
811 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
812 Property::Type propertyType( Property::BOOLEAN );
813 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
815 // Check property count after registration
816 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
817 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
819 // Add custom property and check property count
820 customActor.RegisterProperty( "custom-prop-1", true );
821 unsigned int customPropertyCount( customActor.GetPropertyCount() );
822 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
824 // Set the property, ensure SetProperty called
825 DALI_TEST_CHECK( !setPropertyCalled );
826 customActor.SetProperty( propertyIndex, false );
827 DALI_TEST_CHECK( setPropertyCalled );
829 // Get the property, ensure GetProperty called
830 DALI_TEST_CHECK( !getPropertyCalled );
831 (void)customActor.GetProperty< bool >( propertyIndex );
832 DALI_TEST_CHECK( getPropertyCalled );
834 // Check the property name
835 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
836 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
838 // Check the property index
839 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
841 // Check the property type
842 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
844 // Check property count of type-info is 1
845 Property::IndexContainer indices;
846 typeInfo.GetPropertyIndices( indices );
847 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
849 // Register animatable property
850 std::string animatablePropertyName( "animatable-prop-1" );
851 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
852 Property::Type animatablePropertyType( Property::FLOAT );
853 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
855 // Check property count after registration
856 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
858 // Set the animatable property value
859 customActor.SetProperty( animatablePropertyIndex, 25.0f );
862 application.SendNotification();
863 application.Render();
865 // Check the animatable property value
866 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
868 // Check the animatable property name
869 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
870 // DALI_TEST_EQUALS( typeInfo.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
872 // Check the animatable property index
873 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
875 // Check the animatable property type
876 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
878 // Ensure indices returned from actor and customActor differ by three
879 Actor actor = Actor::New();
880 actor.GetPropertyIndices( indices );
881 unsigned int actorIndices = indices.size();
882 customActor.GetPropertyIndices( indices );
883 unsigned int customActorIndices = indices.size();
884 DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
888 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
890 TestApplication application;
891 TypeRegistry typeRegistry = TypeRegistry::Get();
893 // Attempt to register a property type out-of-bounds index (less than)
896 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
897 tet_result( TET_FAIL );
899 catch ( DaliException& e )
901 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
904 // Attempt to register a property type out-of-bounds index (greater than)
907 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
908 tet_result( TET_FAIL );
910 catch ( DaliException& e )
912 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
915 // Attempt to register an animatable property type out-of-bounds index (less than)
918 AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
919 tet_result( TET_FAIL );
921 catch ( DaliException& e )
923 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
926 // Attempt to register an animatable property type out-of-bounds index (greater than)
929 AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
930 tet_result( TET_FAIL );
932 catch ( DaliException& e )
934 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
939 int UtcDaliPropertyRegistrationFunctions(void)
941 TestApplication application;
942 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
944 // Attempt to register a property without a setter
947 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
948 tet_result( TET_PASS );
950 catch ( DaliException& e )
952 tet_result( TET_FAIL );
955 // Attempt to register a property without a getter
958 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
959 tet_result( TET_FAIL );
961 catch ( DaliException& e )
963 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
968 int UtcDaliPropertyRegistrationAddSameIndex(void)
970 TestApplication application;
971 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
973 // Add one property with a valid property index
974 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
976 // Attempt to add another property with the same index
979 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
981 catch ( DaliException& e )
983 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
986 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
988 // Add one property with a valid property index
989 AnimatablePropertyRegistration property3( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
991 // Attempt to add another property with the same index
994 AnimatablePropertyRegistration property4( customType1, "anim-prop-name-2", animatablePropertyIndex, Property::BOOLEAN );
996 catch ( DaliException& e )
998 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1003 int UtcDaliPropertyRegistrationPropertyWritable(void)
1005 TestApplication application;
1006 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1007 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1009 // Add two properties, one with SetProperty, one without
1010 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1011 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1013 // Create custom-actor
1014 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1015 DALI_TEST_CHECK( typeInfo );
1016 BaseHandle handle = typeInfo.CreateInstance();
1017 DALI_TEST_CHECK( handle );
1018 Actor customActor = Actor::DownCast( handle );
1019 DALI_TEST_CHECK( customActor );
1021 // Check whether properties are writable
1022 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
1023 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1027 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1029 TestApplication application;
1030 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1031 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1033 // These properties are not animatable
1034 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1036 // These properties are animatable
1037 AnimatablePropertyRegistration property2( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1039 // Create custom-actor
1040 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1041 DALI_TEST_CHECK( typeInfo );
1042 BaseHandle handle = typeInfo.CreateInstance();
1043 DALI_TEST_CHECK( handle );
1044 Actor customActor = Actor::DownCast( handle );
1045 DALI_TEST_CHECK( customActor );
1047 // Check if animatable
1048 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1049 DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1051 // Create another instance of custom-actor
1052 BaseHandle handle2 = typeInfo.CreateInstance();
1053 DALI_TEST_CHECK( handle2 );
1054 Actor customActor2 = Actor::DownCast( handle2 );
1055 DALI_TEST_CHECK( customActor2 );
1057 // Check if animatable
1058 DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1059 DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1063 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1065 TestApplication application;
1066 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1067 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1069 // Create custom-actor
1070 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1071 DALI_TEST_CHECK( typeInfo );
1072 BaseHandle handle = typeInfo.CreateInstance();
1073 DALI_TEST_CHECK( handle );
1074 Actor customActor = Actor::DownCast( handle );
1075 DALI_TEST_CHECK( customActor );
1077 // Try to set an index that hasn't been added
1080 customActor.SetProperty( propertyIndex, true );
1081 tet_result( TET_FAIL );
1083 catch ( DaliException& e )
1085 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1090 customActor.SetProperty( animatablePropertyIndex, true );
1091 tet_result( TET_FAIL );
1093 catch ( DaliException& e )
1095 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1098 // Try to get an index that hasn't been added
1101 (void) customActor.GetProperty< bool >( propertyIndex );
1102 tet_result( TET_FAIL );
1104 catch ( DaliException& e )
1106 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1111 (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1112 tet_result( TET_FAIL );
1114 catch ( DaliException& e )
1116 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1122 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1124 TestApplication application;
1126 Actor actor = Actor::New();
1127 actor.SetSize(100.0f, 100.0f);
1128 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1129 Stage::GetCurrent().Add(actor);
1133 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1134 DALI_TEST_CHECK( type );
1135 BaseHandle handle = type.CreateInstance();
1136 DALI_TEST_CHECK( handle );
1137 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1138 DALI_TEST_CHECK( detector );
1140 // Attach actor to detector
1142 GestureReceivedFunctor functor( data );
1143 detector.Attach(actor);
1145 // Connect to signal through type
1146 handle.ConnectSignal( &application, "long-press-detected", functor );
1148 // Render and notify
1149 application.SendNotification();
1150 application.Render();
1153 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1154 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1155 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1156 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1160 int UtcDaliPanGestureDetectorTypeRegistry(void)
1162 TestApplication application;
1164 Actor actor = Actor::New();
1165 actor.SetSize(100.0f, 100.0f);
1166 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1167 Stage::GetCurrent().Add(actor);
1171 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1172 DALI_TEST_CHECK( type );
1173 BaseHandle handle = type.CreateInstance();
1174 DALI_TEST_CHECK( handle );
1175 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1176 DALI_TEST_CHECK( detector );
1178 // Attach actor to detector
1180 GestureReceivedFunctor functor( data );
1181 detector.Attach(actor);
1183 // Connect to signal through type
1184 handle.ConnectSignal( &application, "pan-detected", functor );
1186 // Render and notify
1187 application.SendNotification();
1188 application.Render();
1191 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1192 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1193 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1194 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1198 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1200 TestApplication application;
1202 Actor actor = Actor::New();
1203 actor.SetSize(100.0f, 100.0f);
1204 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1205 Stage::GetCurrent().Add(actor);
1209 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1210 DALI_TEST_CHECK( type );
1211 BaseHandle handle = type.CreateInstance();
1212 DALI_TEST_CHECK( handle );
1213 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1214 DALI_TEST_CHECK( detector );
1216 // Attach actor to detector
1218 GestureReceivedFunctor functor( data );
1219 detector.Attach(actor);
1221 // Connect to signal through type
1222 handle.ConnectSignal( &application, "pinch-detected", functor );
1224 // Render and notify
1225 application.SendNotification();
1226 application.Render();
1229 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1230 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1234 int UtcDaliTapGestureDetectorTypeRegistry(void)
1236 TestApplication application;
1238 Actor actor = Actor::New();
1239 actor.SetSize(100.0f, 100.0f);
1240 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1241 Stage::GetCurrent().Add(actor);
1245 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1246 DALI_TEST_CHECK( type );
1247 BaseHandle handle = type.CreateInstance();
1248 DALI_TEST_CHECK( handle );
1249 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1250 DALI_TEST_CHECK( detector );
1252 // Attach actor to detector
1254 GestureReceivedFunctor functor( data );
1255 detector.Attach(actor);
1257 // Connect to signal through type
1258 handle.ConnectSignal( &application, "tap-detected", functor );
1260 // Render and notify
1261 application.SendNotification();
1262 application.Render();
1265 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1266 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1267 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1271 int UtcDaliTypeRegistryNamedType(void)
1273 TestApplication application;
1274 TypeRegistry typeRegistry = TypeRegistry::Get();
1276 // Create a normal actor
1277 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1278 DALI_TEST_CHECK( actorHandle );
1279 Actor actor( Actor::DownCast( actorHandle ) );
1280 DALI_TEST_CHECK( actor );
1281 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1283 // Create Named Actor Type
1284 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1285 DALI_TEST_CHECK( namedHandle );
1286 Actor namedActor( Actor::DownCast( namedHandle ) );
1287 DALI_TEST_CHECK( namedActor );
1288 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1290 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );