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 policy, Dimension dimension )
268 virtual void OnCalculateRelayoutSize( Dimension dimension )
272 virtual float CalculateChildSize( const Dali::Actor& child, Dimension dimension )
277 virtual void OnLayoutNegotiated( float size, Dimension dimension )
281 virtual bool RelayoutDependentOnChildren( 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( "TextActor" );
544 DALI_TEST_CHECK( type );
545 TextActor ta = TextActor::DownCast(type.CreateInstance());
546 DALI_TEST_CHECK( ta );
547 Stage::GetCurrent().Add( ta );
548 application.Render();
550 type = registry.GetTypeInfo( "CameraActor" );
551 DALI_TEST_CHECK( type );
552 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
553 DALI_TEST_CHECK( ca );
554 Stage::GetCurrent().Add( ca );
555 application.Render();
558 type = registry.GetTypeInfo( "Animation" );
559 DALI_TEST_CHECK( type );
560 Animation an = Animation::DownCast(type.CreateInstance());
561 DALI_TEST_CHECK( an );
563 application.Render();
566 type = registry.GetTypeInfo( "ShaderEffect" );
567 DALI_TEST_CHECK( type );
568 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
569 DALI_TEST_CHECK( ef );
570 application.Render();
575 /*******************************************************************************
577 * Action through the base handle
579 ******************************************************************************/
580 int UtcDaliTypeRegistryActionViaBaseHandle(void)
582 TestApplication application;
586 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
587 DALI_TEST_CHECK( type );
589 BaseHandle hdl = type.CreateInstance();
590 DALI_TEST_CHECK( hdl );
592 Actor a = Actor::DownCast(hdl);
593 DALI_TEST_CHECK( a );
597 application.SendNotification();
598 application.Render(0);
599 DALI_TEST_CHECK(!a.IsVisible());
601 std::vector<Property::Value> attributes;
603 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
605 application.SendNotification();
606 application.Render(0);
607 DALI_TEST_CHECK(a.IsVisible());
609 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
613 int UtcDaliTypeRegistryNames(void)
615 TestApplication application;
619 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
621 for(TypeRegistry::NameContainer::iterator iter = names.begin();
622 iter != names.end(); ++iter)
624 type = TypeRegistry::Get().GetTypeInfo( *iter );
625 DALI_TEST_CHECK( type );
631 // Check named and typeid are equivalent
632 int UtcDaliTypeRegistryNameEquivalence(void)
634 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "TextActor" );
635 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::TextActor) );
637 DALI_TEST_CHECK( named_type );
638 DALI_TEST_CHECK( typeinfo_type );
640 DALI_TEST_CHECK( named_type == typeinfo_type );
642 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
643 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
649 int UtcDaliTypeRegistryCustomActor(void)
651 ResetFunctorCounts();
653 TestApplication application;
655 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
656 DALI_TEST_CHECK( type );
658 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
659 DALI_TEST_CHECK( baseType );
661 BaseHandle handle = type.CreateInstance();
662 DALI_TEST_CHECK( handle );
664 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
665 DALI_TEST_CHECK( customHandle );
667 TypeInfo::NameContainer names;
668 type.GetActions(names);
669 TypeInfo::NameContainer baseNames;
670 baseType.GetActions(baseNames);
671 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
674 type.GetSignals(names);
677 baseType.GetSignals(baseNames);
679 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
682 TestConnectionTracker tracker;
684 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
685 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
686 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
687 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
688 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
690 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
691 customHandle.GetCustomSignal().Emit();
692 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
693 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
694 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
696 // tracker should automatically disconnect here
697 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
698 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
700 // Test that functor is disconnected
701 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
702 customHandle.GetCustomSignal().Emit();
703 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
704 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
705 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
707 std::vector<Property::Value> attributes;
708 handle.DoAction("act1", attributes);
709 DALI_TEST_CHECK( lastActionCustom == "act1" );
713 int UtcDaliTypeRegistryCustomSignalFailure(void)
715 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
717 ResetFunctorCounts();
719 TestApplication application;
721 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
722 DALI_TEST_CHECK( type );
724 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
725 DALI_TEST_CHECK( baseType );
727 BaseHandle handle = type.CreateInstance();
728 DALI_TEST_CHECK( handle );
730 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
731 DALI_TEST_CHECK( customHandle );
733 TypeInfo::NameContainer names;
734 TypeInfo::NameContainer baseNames;
736 type.GetActions(names);
737 baseType.GetActions(baseNames);
739 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
744 type.GetSignals(names);
745 baseType.GetSignals(baseNames);
747 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
750 TestConnectionTracker tracker;
752 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
753 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
754 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
755 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
756 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
759 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
760 customHandle.GetCustomSignal().Emit();
761 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
763 // tracker should have nothing to disconnect here
766 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
767 customHandle.GetCustomSignal().Emit();
768 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
772 int UtcDaliTypeRegistryInitFunctions(void)
774 TestApplication application;
776 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
778 DALI_TEST_CHECK( true == CreateCustomInitCalled );
779 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
780 DALI_TEST_CHECK( type );
785 int UtcDaliTypeRegistryNameInitFunctions(void)
787 TestApplication application;
789 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
791 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
792 DALI_TEST_CHECK( baseType );
794 BaseHandle handle = baseType.CreateInstance();
796 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
797 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
798 DALI_TEST_CHECK( type );
803 int UtcDaliPropertyRegistration(void)
805 TestApplication application;
806 TypeRegistry typeRegistry = TypeRegistry::Get();
808 // Check property count before property registration
809 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
810 DALI_TEST_CHECK( typeInfo );
811 BaseHandle handle = typeInfo.CreateInstance();
812 DALI_TEST_CHECK( handle );
813 Actor customActor = Actor::DownCast( handle );
814 DALI_TEST_CHECK( customActor );
815 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
817 std::string propertyName( "prop-1" );
818 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
819 Property::Type propertyType( Property::BOOLEAN );
820 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
822 // Check property count after registration
823 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
824 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
826 // Add custom property and check property count
827 customActor.RegisterProperty( "custom-prop-1", true );
828 unsigned int customPropertyCount( customActor.GetPropertyCount() );
829 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
831 // Set the property, ensure SetProperty called
832 DALI_TEST_CHECK( !setPropertyCalled );
833 customActor.SetProperty( propertyIndex, false );
834 DALI_TEST_CHECK( setPropertyCalled );
836 // Get the property, ensure GetProperty called
837 DALI_TEST_CHECK( !getPropertyCalled );
838 (void)customActor.GetProperty< bool >( propertyIndex );
839 DALI_TEST_CHECK( getPropertyCalled );
841 // Check the property name
842 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
843 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
845 // Check the property index
846 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
848 // Check the property type
849 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
851 // Check property count of type-info is 1
852 Property::IndexContainer indices;
853 typeInfo.GetPropertyIndices( indices );
854 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
856 // Register animatable property
857 std::string animatablePropertyName( "animatable-prop-1" );
858 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
859 Property::Type animatablePropertyType( Property::FLOAT );
860 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
862 // Check property count after registration
863 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
865 // Set the animatable property value
866 customActor.SetProperty( animatablePropertyIndex, 25.0f );
869 application.SendNotification();
870 application.Render();
872 // Check the animatable property value
873 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
875 // Check the animatable property name
876 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
877 // DALI_TEST_EQUALS( typeInfo.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
879 // Check the animatable property index
880 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
882 // Check the animatable property type
883 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
885 // Ensure indices returned from actor and customActor differ by three
886 Actor actor = Actor::New();
887 actor.GetPropertyIndices( indices );
888 unsigned int actorIndices = indices.size();
889 customActor.GetPropertyIndices( indices );
890 unsigned int customActorIndices = indices.size();
891 DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
895 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
897 TestApplication application;
898 TypeRegistry typeRegistry = TypeRegistry::Get();
900 // Attempt to register a property type out-of-bounds index (less than)
903 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
904 tet_result( TET_FAIL );
906 catch ( DaliException& e )
908 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
911 // Attempt to register a property type out-of-bounds index (greater than)
914 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
915 tet_result( TET_FAIL );
917 catch ( DaliException& e )
919 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
922 // Attempt to register an animatable property type out-of-bounds index (less than)
925 AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
926 tet_result( TET_FAIL );
928 catch ( DaliException& e )
930 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
933 // Attempt to register an animatable property type out-of-bounds index (greater than)
936 AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
937 tet_result( TET_FAIL );
939 catch ( DaliException& e )
941 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
946 int UtcDaliPropertyRegistrationFunctions(void)
948 TestApplication application;
949 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
951 // Attempt to register a property without a setter
954 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
955 tet_result( TET_PASS );
957 catch ( DaliException& e )
959 tet_result( TET_FAIL );
962 // Attempt to register a property without a getter
965 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
966 tet_result( TET_FAIL );
968 catch ( DaliException& e )
970 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
975 int UtcDaliPropertyRegistrationAddSameIndex(void)
977 TestApplication application;
978 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
980 // Add one property with a valid property index
981 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
983 // Attempt to add another property with the same index
986 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
988 catch ( DaliException& e )
990 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
993 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
995 // Add one property with a valid property index
996 AnimatablePropertyRegistration property3( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
998 // Attempt to add another property with the same index
1001 AnimatablePropertyRegistration property4( customType1, "anim-prop-name-2", animatablePropertyIndex, Property::BOOLEAN );
1003 catch ( DaliException& e )
1005 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1010 int UtcDaliPropertyRegistrationPropertyWritable(void)
1012 TestApplication application;
1013 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1014 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1016 // Add two properties, one with SetProperty, one without
1017 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1018 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1020 // Create custom-actor
1021 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1022 DALI_TEST_CHECK( typeInfo );
1023 BaseHandle handle = typeInfo.CreateInstance();
1024 DALI_TEST_CHECK( handle );
1025 Actor customActor = Actor::DownCast( handle );
1026 DALI_TEST_CHECK( customActor );
1028 // Check whether properties are writable
1029 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
1030 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1034 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1036 TestApplication application;
1037 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1038 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1040 // These properties are not animatable
1041 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1043 // These properties are animatable
1044 AnimatablePropertyRegistration property2( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1046 // Create custom-actor
1047 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1048 DALI_TEST_CHECK( typeInfo );
1049 BaseHandle handle = typeInfo.CreateInstance();
1050 DALI_TEST_CHECK( handle );
1051 Actor customActor = Actor::DownCast( handle );
1052 DALI_TEST_CHECK( customActor );
1054 // Check if animatable
1055 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1056 DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1058 // Create another instance of custom-actor
1059 BaseHandle handle2 = typeInfo.CreateInstance();
1060 DALI_TEST_CHECK( handle2 );
1061 Actor customActor2 = Actor::DownCast( handle2 );
1062 DALI_TEST_CHECK( customActor2 );
1064 // Check if animatable
1065 DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1066 DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1070 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1072 TestApplication application;
1073 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1074 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1076 // Create custom-actor
1077 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1078 DALI_TEST_CHECK( typeInfo );
1079 BaseHandle handle = typeInfo.CreateInstance();
1080 DALI_TEST_CHECK( handle );
1081 Actor customActor = Actor::DownCast( handle );
1082 DALI_TEST_CHECK( customActor );
1084 // Try to set an index that hasn't been added
1087 customActor.SetProperty( propertyIndex, true );
1088 tet_result( TET_FAIL );
1090 catch ( DaliException& e )
1092 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1097 customActor.SetProperty( animatablePropertyIndex, true );
1098 tet_result( TET_FAIL );
1100 catch ( DaliException& e )
1102 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1105 // Try to get an index that hasn't been added
1108 (void) customActor.GetProperty< bool >( propertyIndex );
1109 tet_result( TET_FAIL );
1111 catch ( DaliException& e )
1113 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1118 (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1119 tet_result( TET_FAIL );
1121 catch ( DaliException& e )
1123 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1129 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1131 TestApplication application;
1133 Actor actor = Actor::New();
1134 actor.SetSize(100.0f, 100.0f);
1135 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1136 Stage::GetCurrent().Add(actor);
1140 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1141 DALI_TEST_CHECK( type );
1142 BaseHandle handle = type.CreateInstance();
1143 DALI_TEST_CHECK( handle );
1144 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1145 DALI_TEST_CHECK( detector );
1147 // Attach actor to detector
1149 GestureReceivedFunctor functor( data );
1150 detector.Attach(actor);
1152 // Connect to signal through type
1153 handle.ConnectSignal( &application, "long-press-detected", functor );
1155 // Render and notify
1156 application.SendNotification();
1157 application.Render();
1160 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1161 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1162 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1163 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1167 int UtcDaliPanGestureDetectorTypeRegistry(void)
1169 TestApplication application;
1171 Actor actor = Actor::New();
1172 actor.SetSize(100.0f, 100.0f);
1173 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1174 Stage::GetCurrent().Add(actor);
1178 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1179 DALI_TEST_CHECK( type );
1180 BaseHandle handle = type.CreateInstance();
1181 DALI_TEST_CHECK( handle );
1182 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1183 DALI_TEST_CHECK( detector );
1185 // Attach actor to detector
1187 GestureReceivedFunctor functor( data );
1188 detector.Attach(actor);
1190 // Connect to signal through type
1191 handle.ConnectSignal( &application, "pan-detected", functor );
1193 // Render and notify
1194 application.SendNotification();
1195 application.Render();
1198 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1199 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1200 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1201 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1205 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1207 TestApplication application;
1209 Actor actor = Actor::New();
1210 actor.SetSize(100.0f, 100.0f);
1211 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1212 Stage::GetCurrent().Add(actor);
1216 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1217 DALI_TEST_CHECK( type );
1218 BaseHandle handle = type.CreateInstance();
1219 DALI_TEST_CHECK( handle );
1220 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1221 DALI_TEST_CHECK( detector );
1223 // Attach actor to detector
1225 GestureReceivedFunctor functor( data );
1226 detector.Attach(actor);
1228 // Connect to signal through type
1229 handle.ConnectSignal( &application, "pinch-detected", functor );
1231 // Render and notify
1232 application.SendNotification();
1233 application.Render();
1236 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1237 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1241 int UtcDaliTapGestureDetectorTypeRegistry(void)
1243 TestApplication application;
1245 Actor actor = Actor::New();
1246 actor.SetSize(100.0f, 100.0f);
1247 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1248 Stage::GetCurrent().Add(actor);
1252 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1253 DALI_TEST_CHECK( type );
1254 BaseHandle handle = type.CreateInstance();
1255 DALI_TEST_CHECK( handle );
1256 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1257 DALI_TEST_CHECK( detector );
1259 // Attach actor to detector
1261 GestureReceivedFunctor functor( data );
1262 detector.Attach(actor);
1264 // Connect to signal through type
1265 handle.ConnectSignal( &application, "tap-detected", functor );
1267 // Render and notify
1268 application.SendNotification();
1269 application.Render();
1272 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1273 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1274 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1278 int UtcDaliTypeRegistryNamedType(void)
1280 TestApplication application;
1281 TypeRegistry typeRegistry = TypeRegistry::Get();
1283 // Create a normal actor
1284 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1285 DALI_TEST_CHECK( actorHandle );
1286 Actor actor( Actor::DownCast( actorHandle ) );
1287 DALI_TEST_CHECK( actor );
1288 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1290 // Create Named Actor Type
1291 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1292 DALI_TEST_CHECK( namedHandle );
1293 Actor namedActor( Actor::DownCast( namedHandle ) );
1294 DALI_TEST_CHECK( namedActor );
1295 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1297 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );