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.
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( ActorFlags( REQUIRES_TOUCH_EVENTS ) )
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
523 // Note: No negative test case for UtcDaliTypeRegistryGet can be implemented.
524 int UtcDaliTypeRegistryGetP(void)
526 TestApplication application;
528 TypeRegistry registry = TypeRegistry::Get();
529 DALI_TEST_CHECK( registry );
534 // Note: No negative test case for UtcDaliTypeRegistryConstructor can be implemented.
535 int UtcDaliTypeRegistryConstructorP(void)
537 TestApplication application;
539 TypeRegistry registry;
540 DALI_TEST_CHECK( !registry );
544 // Note: No negative test case for UtcDaliTypeRegistryCopyConstructor can be implemented.
545 int UtcDaliTypeRegistryCopyConstructorP(void)
547 TestApplication application;
549 TypeRegistry registry = TypeRegistry::Get();
550 DALI_TEST_CHECK( registry );
552 TypeRegistry copy( registry );
553 DALI_TEST_CHECK( copy );
555 DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
560 // Note: No negative test case for UtcDaliTypeRegistryAssignmentOperator can be implemented.
561 int UtcDaliTypeRegistryAssignmentOperatorP(void)
563 TestApplication application;
565 TypeRegistry registry = TypeRegistry::Get();
566 DALI_TEST_CHECK( registry );
568 TypeRegistry copy = registry;
569 DALI_TEST_CHECK( copy );
570 DALI_TEST_CHECK( registry == copy );
572 DALI_TEST_CHECK( registry.GetTypeInfo( "Actor" ).GetName() == copy.GetTypeInfo( "Actor" ).GetName() );
577 int UtcDaliTypeRegistryAssignP(void)
579 TestApplication application;
581 TypeRegistry registry = TypeRegistry::Get();
582 TypeRegistry registry2;
583 registry2 = registry;
584 DALI_TEST_CHECK( registry2 );
586 DALI_TEST_CHECK( registry2.GetTypeInfo( "Actor" ).GetName() == registry2.GetTypeInfo( "Actor" ).GetName() );
591 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameP(void)
593 TestApplication application;
595 TypeRegistry registry = TypeRegistry::Get();
600 type = registry.GetTypeInfo( "ImageActor" );
601 DALI_TEST_CHECK( type );
602 DALI_TEST_CHECK( type.GetCreator() );
603 DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
604 ImageActor ia = ImageActor::DownCast(type.CreateInstance());
605 DALI_TEST_CHECK( ia );
606 Stage::GetCurrent().Add( ia );
607 application.Render();
610 type = registry.GetTypeInfo( "CameraActor" );
611 DALI_TEST_CHECK( type );
612 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
613 DALI_TEST_CHECK( ca );
614 Stage::GetCurrent().Add( ca );
615 application.Render();
618 type = registry.GetTypeInfo( "Animation" );
619 DALI_TEST_CHECK( type );
620 Animation an = Animation::DownCast(type.CreateInstance());
621 DALI_TEST_CHECK( an );
623 application.Render();
626 type = registry.GetTypeInfo( "ShaderEffect" );
627 DALI_TEST_CHECK( type );
628 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
629 DALI_TEST_CHECK( ef );
630 application.Render();
635 int UtcDaliTypeRegistryGetTypeInfoFromTypeNameN(void)
637 TestApplication application;
639 TypeRegistry registry = TypeRegistry::Get();
643 type = registry.GetTypeInfo( "MyDummyActor" );
644 DALI_TEST_CHECK( !type );
649 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdP(void)
651 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
652 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
654 DALI_TEST_CHECK( named_type );
655 DALI_TEST_CHECK( typeinfo_type );
657 // Check named and typeid are equivalent
658 DALI_TEST_CHECK( named_type == typeinfo_type );
660 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
661 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
666 int UtcDaliTypeRegistryGetTypeInfoFromTypeIdN(void)
668 TestApplication application;
669 TypeRegistry typeRegistry = TypeRegistry::Get();
671 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(Vector2) );
672 DALI_TEST_CHECK( !typeInfo );
677 int UtcDaliTypeRegistryGetTypeNamesP(void)
679 TestApplication application;
683 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
685 for(TypeRegistry::NameContainer::iterator iter = names.begin();
686 iter != names.end(); ++iter)
688 type = TypeRegistry::Get().GetTypeInfo( *iter );
689 DALI_TEST_CHECK( type );
695 int UtcDaliTypeRegistryGetTypeNamesN(void)
697 TestApplication application;
701 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
703 for(TypeRegistry::NameContainer::iterator iter = names.begin();
704 iter != names.end(); ++iter)
706 type = TypeRegistry::Get().GetTypeInfo( *iter );
707 DALI_TEST_CHECK( type.GetName() != "MyDummyActor" );
713 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
714 int UtcDaliTypeRegistryTypeRegistrationNotCallingCreateOnInitP(void)
716 ResetFunctorCounts();
718 TestApplication application;
720 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
721 DALI_TEST_CHECK( type );
723 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
724 DALI_TEST_CHECK( baseType );
726 BaseHandle handle = type.CreateInstance();
727 DALI_TEST_CHECK( handle );
729 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
730 DALI_TEST_CHECK( customHandle );
732 TypeInfo::NameContainer names;
733 type.GetActions(names);
734 TypeInfo::NameContainer baseNames;
735 baseType.GetActions(baseNames);
736 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
739 type.GetSignals(names);
742 baseType.GetSignals(baseNames);
744 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
747 TestConnectionTracker tracker;
749 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
750 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
751 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
752 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
753 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
755 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
756 customHandle.GetCustomSignal().Emit();
757 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
758 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
759 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
761 // tracker should automatically disconnect here
762 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
763 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
765 // Test that functor is disconnected
766 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
767 customHandle.GetCustomSignal().Emit();
768 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
769 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
770 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
772 std::vector<Property::Value> attributes;
773 handle.DoAction("act1", attributes);
774 DALI_TEST_CHECK( lastActionCustom == "act1" );
778 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
779 int UtcDaliTypeRegistryTypeRegistrationCallingCreateOnInitP(void)
781 TestApplication application;
783 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
785 DALI_TEST_CHECK( true == CreateCustomInitCalled );
786 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
787 DALI_TEST_CHECK( type );
791 // Note: No negative test case for UtcDaliTypeRegistryTypeRegistration can be implemented.
792 int UtcDaliTypeRegistryTypeRegistrationForNamedTypeP(void)
794 TestApplication application;
796 // Create Named Actor Type
797 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyNamedActor" );
798 DALI_TEST_CHECK( type );
800 BaseHandle namedHandle = type.CreateInstance();
801 DALI_TEST_CHECK( namedHandle );
802 Actor namedActor( Actor::DownCast( namedHandle ) );
803 DALI_TEST_CHECK( namedActor );
805 DALI_TEST_CHECK( namedActor.GetName() == "NamedActor" );
806 DALI_TEST_CHECK( type.GetName() == "MyNamedActor" );
807 DALI_TEST_CHECK( type.GetBaseName() == "Actor" );
812 // Note: No negative test case for UtcDaliTypeRegistryRegisteredName can be implemented.
813 int UtcDaliTypeRegistryRegisteredNameP(void)
815 TestApplication application;
817 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
819 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
820 DALI_TEST_CHECK( baseType );
822 BaseHandle handle = baseType.CreateInstance();
824 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
825 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
826 DALI_TEST_CHECK( type );
830 int UtcDaliTypeRegistrySignalConnectorTypeP(void)
832 ResetFunctorCounts();
834 TestApplication application;
836 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
837 DALI_TEST_CHECK( type );
839 BaseHandle handle = type.CreateInstance();
840 DALI_TEST_CHECK( handle );
842 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
843 DALI_TEST_CHECK( customHandle );
846 TestConnectionTracker tracker;
848 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
849 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
850 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
851 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
852 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
854 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
855 customHandle.GetCustomSignal().Emit();
856 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
857 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
858 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
860 // tracker should automatically disconnect here
861 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
862 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
864 // Test that functor is disconnected
865 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
866 customHandle.GetCustomSignal().Emit();
867 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
868 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
869 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
874 int UtcDaliTypeRegistrySignalConnectorTypeN(void)
876 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
878 ResetFunctorCounts();
880 TestApplication application;
882 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
883 DALI_TEST_CHECK( type );
885 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
886 DALI_TEST_CHECK( baseType );
888 BaseHandle handle = type.CreateInstance();
889 DALI_TEST_CHECK( handle );
891 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
892 DALI_TEST_CHECK( customHandle );
894 TypeInfo::NameContainer names;
895 TypeInfo::NameContainer baseNames;
897 type.GetActions(names);
898 baseType.GetActions(baseNames);
900 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
905 type.GetSignals(names);
906 baseType.GetSignals(baseNames);
908 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
911 TestConnectionTracker tracker;
913 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
914 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
915 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
916 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
917 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
920 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
921 customHandle.GetCustomSignal().Emit();
922 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
924 // tracker should have nothing to disconnect here
927 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
928 customHandle.GetCustomSignal().Emit();
929 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
933 int UtcDaliTypeRegistryTypeActionP(void)
935 ResetFunctorCounts();
937 TestApplication application;
939 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
940 DALI_TEST_CHECK( type );
942 BaseHandle handle = type.CreateInstance();
943 DALI_TEST_CHECK( handle );
945 std::vector<Property::Value> attributes;
946 DALI_TEST_CHECK( handle.DoAction("act1", attributes) );
947 DALI_TEST_CHECK( lastActionCustom == "act1" );
952 int UtcDaliTypeRegistryTypeActionN(void)
954 ResetFunctorCounts();
956 TestApplication application;
958 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
959 DALI_TEST_CHECK( type );
961 BaseHandle handle = type.CreateInstance();
962 DALI_TEST_CHECK( handle );
964 std::vector<Property::Value> attributes;
965 DALI_TEST_CHECK( !handle.DoAction( "unknown-action", attributes ) );
970 int UtcDaliTypeRegistryPropertyRegistrationP(void)
972 TestApplication application;
973 TypeRegistry typeRegistry = TypeRegistry::Get();
975 // Check property count before property registration
976 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
977 DALI_TEST_CHECK( typeInfo );
978 BaseHandle handle = typeInfo.CreateInstance();
979 DALI_TEST_CHECK( handle );
980 Actor customActor = Actor::DownCast( handle );
981 DALI_TEST_CHECK( customActor );
982 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
984 std::string propertyName( "prop-1" );
985 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
986 Property::Type propertyType( Property::BOOLEAN );
987 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
989 // Check property count after registration
990 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
991 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
993 // Add custom property and check property count
994 customActor.RegisterProperty( "custom-prop-1", true );
995 unsigned int customPropertyCount( customActor.GetPropertyCount() );
996 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
998 // Set the property, ensure SetProperty called
999 DALI_TEST_CHECK( !setPropertyCalled );
1000 customActor.SetProperty( propertyIndex, false );
1001 DALI_TEST_CHECK( setPropertyCalled );
1003 // Get the property, ensure GetProperty called
1004 DALI_TEST_CHECK( !getPropertyCalled );
1005 (void)customActor.GetProperty< bool >( propertyIndex );
1006 DALI_TEST_CHECK( getPropertyCalled );
1008 // Check the property name
1009 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
1010 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
1012 // Check the property index
1013 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
1015 // Check the property type
1016 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
1018 // Check property count of type-info is 1
1019 Property::IndexContainer indices;
1020 typeInfo.GetPropertyIndices( indices );
1021 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
1023 // check property name count
1024 TypeInfo::NameContainer names;
1025 typeInfo.GetProperties(names);
1026 DALI_TEST_CHECK( 1 == names.size() );
1028 // Ensure indices returned from actor and customActor differ by two
1029 Actor actor = Actor::New();
1030 actor.GetPropertyIndices( indices );
1031 unsigned int actorIndices = indices.size();
1032 customActor.GetPropertyIndices( indices );
1033 unsigned int customActorIndices = indices.size();
1034 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1038 int UtcDaliTypeRegistryPropertyRegistrationN(void)
1040 TestApplication application;
1041 TypeRegistry typeRegistry = TypeRegistry::Get();
1043 // Attempt to register a property type out-of-bounds index (less than)
1046 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1047 tet_result( TET_FAIL );
1049 catch ( DaliException& e )
1051 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1054 // Attempt to register a property type out-of-bounds index (greater than)
1057 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
1058 tet_result( TET_FAIL );
1060 catch ( DaliException& e )
1062 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1068 int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
1070 TestApplication application;
1071 TypeRegistry typeRegistry = TypeRegistry::Get();
1073 // Check property count before property registration
1074 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1075 DALI_TEST_CHECK( typeInfo );
1076 BaseHandle handle = typeInfo.CreateInstance();
1077 DALI_TEST_CHECK( handle );
1078 Actor customActor = Actor::DownCast( handle );
1079 DALI_TEST_CHECK( customActor );
1081 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1083 // Register animatable property
1084 std::string animatablePropertyName( "animatable-prop-1" );
1085 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1086 Property::Type animatablePropertyType( Property::FLOAT );
1087 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1089 // Check property count after registration
1090 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1092 // Set the animatable property value
1093 customActor.SetProperty( animatablePropertyIndex, 25.0f );
1095 // Render and notify
1096 application.SendNotification();
1097 application.Render();
1099 // Check the animatable property value
1100 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
1102 // Check the animatable property name
1103 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1105 // Check the animatable property index
1106 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1108 // Check the animatable property type
1109 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1111 // Check property count of type-info is 1
1112 Property::IndexContainer indices;
1113 typeInfo.GetPropertyIndices( indices );
1114 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
1116 // Ensure indices returned from actor and customActor differ by one
1117 Actor actor = Actor::New();
1118 actor.GetPropertyIndices( indices );
1119 unsigned int actorIndices = indices.size();
1120 customActor.GetPropertyIndices( indices );
1121 unsigned int customActorIndices = indices.size();
1122 DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1127 int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
1129 TestApplication application;
1130 TypeRegistry typeRegistry = TypeRegistry::Get();
1132 // Attempt to register an animatable property type out-of-bounds index (less than)
1135 AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN );
1136 tet_result( TET_FAIL );
1138 catch ( DaliException& e )
1140 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1143 // Attempt to register an animatable property type out-of-bounds index (greater than)
1146 AnimatablePropertyRegistration property1( customType1, "anim-prop-name", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN );
1147 tet_result( TET_FAIL );
1149 catch ( DaliException& e )
1151 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1157 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
1159 TestApplication application;
1160 TypeRegistry typeRegistry = TypeRegistry::Get();
1162 // Check property count before property registration
1163 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
1164 DALI_TEST_CHECK( typeInfo );
1165 BaseHandle handle = typeInfo.CreateInstance();
1166 DALI_TEST_CHECK( handle );
1167 Actor customActor = Actor::DownCast( handle );
1168 DALI_TEST_CHECK( customActor );
1170 unsigned int customPropertyCount( customActor.GetPropertyCount() );
1172 // Register animatable property
1173 std::string animatablePropertyName( "animatable-prop-1" );
1174 int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1175 Property::Type animatablePropertyType( Property::VECTOR2 );
1176 AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
1178 // Check property count after registration
1179 DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
1181 // Set the animatable property value
1182 customActor.SetProperty( animatablePropertyIndex, Vector2(25.0f, 50.0f) );
1184 // Render and notify
1185 application.SendNotification();
1186 application.Render();
1188 // Check the animatable property value
1189 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(25.0f, 50.0f), TEST_LOCATION );
1191 // Check the animatable property name
1192 DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
1194 // Check the animatable property index
1195 DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
1197 // Check the animatable property type
1198 DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), animatablePropertyType, TEST_LOCATION );
1200 // Check property count of type-info is 1
1201 Property::IndexContainer indices;
1202 typeInfo.GetPropertyIndices( indices );
1203 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
1205 // Register animatable property components
1206 std::string animatablePropertyComponentName1( "animatable-prop-1-x" );
1207 int animatablePropertyComponentIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1 );
1208 AnimatablePropertyComponentRegistration animatablePropertyComponent1( customType1, animatablePropertyComponentName1, animatablePropertyComponentIndex1, animatablePropertyIndex, 0 );
1210 std::string animatablePropertyComponentName2( "animatable-prop-1-y" );
1211 int animatablePropertyComponentIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1212 AnimatablePropertyComponentRegistration animatablePropertyComponent2( customType1, animatablePropertyComponentName2, animatablePropertyComponentIndex2, animatablePropertyIndex, 1 );
1214 // Check property count after registration
1215 DALI_TEST_EQUALS( customPropertyCount + 3u, customActor.GetPropertyCount(), TEST_LOCATION );
1217 // Check the animatable property component value
1218 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 25.0f, TEST_LOCATION );
1219 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1221 // Set the animatable property component value
1222 customActor.SetProperty( animatablePropertyComponentIndex1, 150.0f );
1224 // Render and notify
1225 application.SendNotification();
1226 application.Render();
1228 // Check the animatable property value
1229 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 50.0f), TEST_LOCATION );
1230 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1231 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 50.0f, TEST_LOCATION );
1233 // Set the animatable property component value
1234 customActor.SetProperty( animatablePropertyComponentIndex2, 225.0f );
1236 // Render and notify
1237 application.SendNotification();
1238 application.Render();
1240 // Check the animatable property value
1241 DALI_TEST_EQUALS( customActor.GetProperty< Vector2 >( animatablePropertyIndex ), Vector2(150.0f, 225.0f), TEST_LOCATION );
1242 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex1 ), 150.0f, TEST_LOCATION );
1243 DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyComponentIndex2 ), 225.0f, TEST_LOCATION );
1245 // Ensure indices returned from actor and customActor differ by three
1246 Actor actor = Actor::New();
1247 actor.GetPropertyIndices( indices );
1248 unsigned int actorIndices = indices.size();
1249 customActor.GetPropertyIndices( indices );
1250 unsigned int customActorIndices = indices.size();
1251 DALI_TEST_EQUALS( actorIndices + 3u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
1256 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationN(void)
1258 TestApplication application;
1259 TypeRegistry typeRegistry = TypeRegistry::Get();
1261 // Register animatable property with the type of Vector2
1262 int animatablePropertyIndex1( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
1263 AnimatablePropertyRegistration animatableProperty1( customType1, "animatable-prop-1", animatablePropertyIndex1, Property::VECTOR2 );
1265 // Attempt to register an animatable property component out-of-bounds index (less than)
1268 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, animatablePropertyIndex1, 0 );
1269 tet_result( TET_FAIL );
1271 catch ( DaliException& e )
1273 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1276 // Attempt to register an animatable property component out-of-bounds index (greater than)
1279 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, animatablePropertyIndex1, 0 );
1280 tet_result( TET_FAIL );
1282 catch ( DaliException& e )
1284 DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
1287 // Register an animatable property component
1288 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-1-x", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1, animatablePropertyIndex1, 0 );
1290 // Attempt to register another animatable property component with the same component index
1293 AnimatablePropertyComponentRegistration propertyComponent2( customType1, "animatable-prop-1-y", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2, animatablePropertyIndex1, 0 );
1294 tet_result( TET_FAIL );
1296 catch ( DaliException& e )
1298 DALI_TEST_ASSERT( e, "Property component already registered", TEST_LOCATION );
1301 // Register animatable property with the type of boolean
1302 int animatablePropertyIndex2( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2 );
1303 AnimatablePropertyRegistration animatableProperty2( customType1, "animatable-prop-2", animatablePropertyIndex2, Property::BOOLEAN );
1305 // Attempt to register an animatable property component for the above property with boolean type
1308 AnimatablePropertyComponentRegistration propertyComponent1( customType1, "animatable-prop-2-x", animatablePropertyIndex2 + 1, animatablePropertyIndex2, 0 );
1309 tet_result( TET_FAIL );
1311 catch ( DaliException& e )
1313 DALI_TEST_ASSERT( e, "Base property does not support component", TEST_LOCATION );
1320 /*******************************************************************************
1322 * Action through the base handle
1324 ******************************************************************************/
1325 int UtcDaliTypeRegistryActionViaBaseHandle(void)
1327 TestApplication application;
1331 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
1332 DALI_TEST_CHECK( type );
1334 BaseHandle hdl = type.CreateInstance();
1335 DALI_TEST_CHECK( hdl );
1337 Actor a = Actor::DownCast(hdl);
1338 DALI_TEST_CHECK( a );
1340 a.SetVisible(false);
1342 application.SendNotification();
1343 application.Render(0);
1344 DALI_TEST_CHECK(!a.IsVisible());
1346 std::vector<Property::Value> attributes;
1348 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
1350 application.SendNotification();
1351 application.Render(0);
1352 DALI_TEST_CHECK(a.IsVisible());
1354 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
1358 int UtcDaliPropertyRegistrationFunctions(void)
1360 TestApplication application;
1361 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
1363 // Attempt to register a property without a setter
1366 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
1367 tet_result( TET_PASS );
1369 catch ( DaliException& e )
1371 tet_result( TET_FAIL );
1374 // Attempt to register a property without a getter
1377 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
1378 tet_result( TET_FAIL );
1380 catch ( DaliException& e )
1382 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
1387 int UtcDaliPropertyRegistrationAddSameIndex(void)
1389 TestApplication application;
1390 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
1392 // Add one property with a valid property index
1393 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1395 // Attempt to add another property with the same index
1398 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1400 catch ( DaliException& e )
1402 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1405 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 100;
1407 // Add one property with a valid property index
1408 AnimatablePropertyRegistration property3( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
1410 // Attempt to add another property with the same index
1413 AnimatablePropertyRegistration property4( customType1, "anim-prop-name-2", animatablePropertyIndex, Property::BOOLEAN );
1415 catch ( DaliException& e )
1417 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
1422 int UtcDaliPropertyRegistrationPropertyWritable(void)
1424 TestApplication application;
1425 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
1426 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
1428 // Add two properties, one with SetProperty, one without
1429 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
1430 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
1432 // Create custom-actor
1433 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1434 DALI_TEST_CHECK( typeInfo );
1435 BaseHandle handle = typeInfo.CreateInstance();
1436 DALI_TEST_CHECK( handle );
1437 Actor customActor = Actor::DownCast( handle );
1438 DALI_TEST_CHECK( customActor );
1440 // Check whether properties are writable
1441 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
1442 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
1446 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
1448 TestApplication application;
1449 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
1450 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 400;
1452 // These properties are not animatable
1453 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
1455 // These properties are animatable
1456 AnimatablePropertyRegistration property2( customType1, "anim-prop-name", animatablePropertyIndex, Property::BOOLEAN );
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 // Check if animatable
1467 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
1468 DALI_TEST_CHECK( customActor.IsPropertyAnimatable( animatablePropertyIndex ) );
1470 // Create another instance of custom-actor
1471 BaseHandle handle2 = typeInfo.CreateInstance();
1472 DALI_TEST_CHECK( handle2 );
1473 Actor customActor2 = Actor::DownCast( handle2 );
1474 DALI_TEST_CHECK( customActor2 );
1476 // Check if animatable
1477 DALI_TEST_CHECK( ! customActor2.IsPropertyAnimatable( propertyIndex ) );
1478 DALI_TEST_CHECK( customActor2.IsPropertyAnimatable( animatablePropertyIndex ) );
1482 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
1484 TestApplication application;
1485 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
1486 int animatablePropertyIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 2000;
1488 // Create custom-actor
1489 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
1490 DALI_TEST_CHECK( typeInfo );
1491 BaseHandle handle = typeInfo.CreateInstance();
1492 DALI_TEST_CHECK( handle );
1493 Actor customActor = Actor::DownCast( handle );
1494 DALI_TEST_CHECK( customActor );
1496 // Try to set an index that hasn't been added
1499 customActor.SetProperty( propertyIndex, true );
1500 tet_result( TET_FAIL );
1502 catch ( DaliException& e )
1504 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1509 customActor.SetProperty( animatablePropertyIndex, true );
1510 tet_result( TET_FAIL );
1512 catch ( DaliException& e )
1514 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1517 // Try to get an index that hasn't been added
1520 (void) customActor.GetProperty< bool >( propertyIndex );
1521 tet_result( TET_FAIL );
1523 catch ( DaliException& e )
1525 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1530 (void) customActor.GetProperty< bool >( animatablePropertyIndex );
1531 tet_result( TET_FAIL );
1533 catch ( DaliException& e )
1535 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1541 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1543 TestApplication application;
1545 Actor actor = Actor::New();
1546 actor.SetSize(100.0f, 100.0f);
1547 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1548 Stage::GetCurrent().Add(actor);
1552 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1553 DALI_TEST_CHECK( type );
1554 BaseHandle handle = type.CreateInstance();
1555 DALI_TEST_CHECK( handle );
1556 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1557 DALI_TEST_CHECK( detector );
1559 // Attach actor to detector
1561 GestureReceivedFunctor functor( data );
1562 detector.Attach(actor);
1564 // Connect to signal through type
1565 handle.ConnectSignal( &application, "long-press-detected", functor );
1567 // Render and notify
1568 application.SendNotification();
1569 application.Render();
1572 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1573 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1574 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1575 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1579 int UtcDaliPanGestureDetectorTypeRegistry(void)
1581 TestApplication application;
1583 Actor actor = Actor::New();
1584 actor.SetSize(100.0f, 100.0f);
1585 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1586 Stage::GetCurrent().Add(actor);
1590 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1591 DALI_TEST_CHECK( type );
1592 BaseHandle handle = type.CreateInstance();
1593 DALI_TEST_CHECK( handle );
1594 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1595 DALI_TEST_CHECK( detector );
1597 // Attach actor to detector
1599 GestureReceivedFunctor functor( data );
1600 detector.Attach(actor);
1602 // Connect to signal through type
1603 handle.ConnectSignal( &application, "pan-detected", functor );
1605 // Render and notify
1606 application.SendNotification();
1607 application.Render();
1610 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1611 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1612 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1613 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1617 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1619 TestApplication application;
1621 Actor actor = Actor::New();
1622 actor.SetSize(100.0f, 100.0f);
1623 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1624 Stage::GetCurrent().Add(actor);
1628 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1629 DALI_TEST_CHECK( type );
1630 BaseHandle handle = type.CreateInstance();
1631 DALI_TEST_CHECK( handle );
1632 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1633 DALI_TEST_CHECK( detector );
1635 // Attach actor to detector
1637 GestureReceivedFunctor functor( data );
1638 detector.Attach(actor);
1640 // Connect to signal through type
1641 handle.ConnectSignal( &application, "pinch-detected", functor );
1643 // Render and notify
1644 application.SendNotification();
1645 application.Render();
1648 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1649 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1653 int UtcDaliTapGestureDetectorTypeRegistry(void)
1655 TestApplication application;
1657 Actor actor = Actor::New();
1658 actor.SetSize(100.0f, 100.0f);
1659 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1660 Stage::GetCurrent().Add(actor);
1664 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1665 DALI_TEST_CHECK( type );
1666 BaseHandle handle = type.CreateInstance();
1667 DALI_TEST_CHECK( handle );
1668 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1669 DALI_TEST_CHECK( detector );
1671 // Attach actor to detector
1673 GestureReceivedFunctor functor( data );
1674 detector.Attach(actor);
1676 // Connect to signal through type
1677 handle.ConnectSignal( &application, "tap-detected", functor );
1679 // Render and notify
1680 application.SendNotification();
1681 application.Render();
1684 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1685 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1686 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1690 int UtcDaliTypeRegistryNamedType(void)
1692 TestApplication application;
1693 TypeRegistry typeRegistry = TypeRegistry::Get();
1695 // Create a normal actor
1696 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1697 DALI_TEST_CHECK( actorHandle );
1698 Actor actor( Actor::DownCast( actorHandle ) );
1699 DALI_TEST_CHECK( actor );
1700 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1702 // Create Named Actor Type
1703 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1704 DALI_TEST_CHECK( namedHandle );
1705 Actor namedActor( Actor::DownCast( namedHandle ) );
1706 DALI_TEST_CHECK( namedActor );
1707 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1709 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );