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 );
257 class MyTestCustomActor : public CustomActor
261 typedef Signal< void ()> SignalType;
262 typedef Signal< void (float)> SignalTypeFloat;
268 static MyTestCustomActor New()
270 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
271 return MyTestCustomActor( *p ); // takes ownership
274 virtual ~MyTestCustomActor()
278 static MyTestCustomActor DownCast( BaseHandle handle )
280 MyTestCustomActor result;
282 CustomActor custom = Dali::CustomActor::DownCast( handle );
285 CustomActorImpl& customImpl = custom.GetImplementation();
287 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
291 result = MyTestCustomActor(customImpl.GetOwner());
298 SignalType& GetCustomSignal()
300 Dali::RefObject& obj = GetImplementation();
301 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
306 MyTestCustomActor(Internal::CustomActor* internal)
307 : CustomActor(internal)
311 MyTestCustomActor( Impl::MyTestCustomActor& impl )
312 : CustomActor( impl )
318 class MyTestCustomActor2 : public CustomActor
326 static MyTestCustomActor2 New()
328 return MyTestCustomActor2(); // takes ownership
331 virtual ~MyTestCustomActor2()
335 static MyTestCustomActor2 DownCast( BaseHandle handle )
337 MyTestCustomActor2 result;
339 CustomActor custom = Dali::CustomActor::DownCast( handle );
342 CustomActorImpl& customImpl = custom.GetImplementation();
344 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
348 result = MyTestCustomActor2(customImpl.GetOwner());
357 MyTestCustomActor2(Internal::CustomActor* internal)
358 : CustomActor(internal)
362 MyTestCustomActor2( Impl::MyTestCustomActor& impl )
363 : CustomActor( impl )
368 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
371 BaseHandle CreateCustom(void)
373 return MyTestCustomActor::New();
376 static std::string lastSignalConnectionCustom;
378 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
380 lastSignalConnectionCustom = signalName;
382 bool connected( true );
384 Dali::BaseHandle handle(object);
385 MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
387 if( "sig1" == signalName )
389 customActor.GetCustomSignal().Connect( tracker, functor );
393 // signalName does not match any signal
400 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
402 lastSignalConnectionCustom = "failed";
404 return false; // This is supposed to fail
407 struct CustomTestFunctor
411 ++mTotalInstanceCount;
412 ++mCurrentInstanceCount;
415 CustomTestFunctor( const CustomTestFunctor& copyMe )
417 ++mTotalInstanceCount;
418 ++mCurrentInstanceCount;
423 --mCurrentInstanceCount;
431 static int mTotalInstanceCount;
432 static int mCurrentInstanceCount;
433 static int mCallbackCount;
436 int CustomTestFunctor::mTotalInstanceCount = 0;
437 int CustomTestFunctor::mCurrentInstanceCount = 0;
438 int CustomTestFunctor::mCallbackCount = 0;
440 static void ResetFunctorCounts()
442 CustomTestFunctor::mTotalInstanceCount = 0;
443 CustomTestFunctor::mCurrentInstanceCount = 0;
444 CustomTestFunctor::mCallbackCount = 0;
447 static std::string lastActionCustom;
448 bool DoActionCustom(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
450 lastActionCustom = actionName;
454 // Custom type registration
455 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
458 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
459 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
460 static const int TEST_SIGNAL_COUNT = 2;
463 static TypeAction customAction1( customType1, "act1", DoActionCustom);
464 static const int TEST_ACTION_COUNT = 1;
466 class TestConnectionTracker : public ConnectionTracker
470 TestConnectionTracker()
475 BaseHandle CreateNamedActorType()
477 Actor actor = Actor::New();
478 actor.SetName( "NamedActor" );
482 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
483 PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
485 } // Anonymous namespace
488 // Positive test case for a method
489 int UtcDaliTypeRegistryCreateDaliObjects(void)
491 TestApplication application;
493 TypeRegistry registry; // like this for ctor test coverage
494 registry = TypeRegistry::Get();
498 type = registry.GetTypeInfo( "ImageActor" );
499 DALI_TEST_CHECK( type );
500 DALI_TEST_CHECK( type.GetCreator() );
501 DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
502 ImageActor ia = ImageActor::DownCast(type.CreateInstance());
503 DALI_TEST_CHECK( ia );
504 Stage::GetCurrent().Add( ia );
505 application.Render();
507 type = registry.GetTypeInfo( "TextActor" );
508 DALI_TEST_CHECK( type );
509 TextActor ta = TextActor::DownCast(type.CreateInstance());
510 DALI_TEST_CHECK( ta );
511 Stage::GetCurrent().Add( ta );
512 application.Render();
514 type = registry.GetTypeInfo( "CameraActor" );
515 DALI_TEST_CHECK( type );
516 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
517 DALI_TEST_CHECK( ca );
518 Stage::GetCurrent().Add( ca );
519 application.Render();
522 type = registry.GetTypeInfo( "Animation" );
523 DALI_TEST_CHECK( type );
524 Animation an = Animation::DownCast(type.CreateInstance());
525 DALI_TEST_CHECK( an );
527 application.Render();
530 type = registry.GetTypeInfo( "ShaderEffect" );
531 DALI_TEST_CHECK( type );
532 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
533 DALI_TEST_CHECK( ef );
534 application.Render();
539 /*******************************************************************************
541 * Action through the base handle
543 ******************************************************************************/
544 int UtcDaliTypeRegistryActionViaBaseHandle(void)
546 TestApplication application;
550 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
551 DALI_TEST_CHECK( type );
553 BaseHandle hdl = type.CreateInstance();
554 DALI_TEST_CHECK( hdl );
556 Actor a = Actor::DownCast(hdl);
557 DALI_TEST_CHECK( a );
561 application.SendNotification();
562 application.Render(0);
563 DALI_TEST_CHECK(!a.IsVisible());
565 std::vector<Property::Value> attributes;
567 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
569 application.SendNotification();
570 application.Render(0);
571 DALI_TEST_CHECK(a.IsVisible());
573 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
577 int UtcDaliTypeRegistryNames(void)
579 TestApplication application;
583 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
585 for(TypeRegistry::NameContainer::iterator iter = names.begin();
586 iter != names.end(); ++iter)
588 type = TypeRegistry::Get().GetTypeInfo( *iter );
589 DALI_TEST_CHECK( type );
595 // Check named and typeid are equivalent
596 int UtcDaliTypeRegistryNameEquivalence(void)
598 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "TextActor" );
599 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::TextActor) );
601 DALI_TEST_CHECK( named_type );
602 DALI_TEST_CHECK( typeinfo_type );
604 DALI_TEST_CHECK( named_type == typeinfo_type );
606 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
607 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
613 int UtcDaliTypeRegistryCustomActor(void)
615 ResetFunctorCounts();
617 TestApplication application;
619 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
620 DALI_TEST_CHECK( type );
622 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
623 DALI_TEST_CHECK( baseType );
625 BaseHandle handle = type.CreateInstance();
626 DALI_TEST_CHECK( handle );
628 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
629 DALI_TEST_CHECK( customHandle );
631 TypeInfo::NameContainer names;
632 type.GetActions(names);
633 TypeInfo::NameContainer baseNames;
634 baseType.GetActions(baseNames);
635 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
638 type.GetSignals(names);
641 baseType.GetSignals(baseNames);
643 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
646 TestConnectionTracker tracker;
648 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
649 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
650 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
651 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
652 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
654 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
655 customHandle.GetCustomSignal().Emit();
656 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
657 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
658 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
660 // tracker should automatically disconnect here
661 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
662 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
664 // Test that functor is disconnected
665 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
666 customHandle.GetCustomSignal().Emit();
667 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
668 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
669 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
671 std::vector<Property::Value> attributes;
672 handle.DoAction("act1", attributes);
673 DALI_TEST_CHECK( lastActionCustom == "act1" );
677 int UtcDaliTypeRegistryCustomSignalFailure(void)
679 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
681 ResetFunctorCounts();
683 TestApplication application;
685 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
686 DALI_TEST_CHECK( type );
688 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
689 DALI_TEST_CHECK( baseType );
691 BaseHandle handle = type.CreateInstance();
692 DALI_TEST_CHECK( handle );
694 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
695 DALI_TEST_CHECK( customHandle );
697 TypeInfo::NameContainer names;
698 TypeInfo::NameContainer baseNames;
700 type.GetActions(names);
701 baseType.GetActions(baseNames);
703 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
708 type.GetSignals(names);
709 baseType.GetSignals(baseNames);
711 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
714 TestConnectionTracker tracker;
716 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
717 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
718 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
719 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
720 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
723 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
724 customHandle.GetCustomSignal().Emit();
725 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
727 // tracker should have nothing to disconnect here
730 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
731 customHandle.GetCustomSignal().Emit();
732 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
738 int UtcDaliTypeRegistryInitFunctions(void)
740 TestApplication application;
742 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
744 DALI_TEST_CHECK( true == CreateCustomInitCalled );
745 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
746 DALI_TEST_CHECK( type );
753 int UtcDaliTypeRegistryNameInitFunctions(void)
755 TestApplication application;
757 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
759 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
760 DALI_TEST_CHECK( baseType );
762 BaseHandle handle = baseType.CreateInstance();
764 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
765 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
766 DALI_TEST_CHECK( type );
771 int UtcDaliPropertyRegistration(void)
773 TestApplication application;
774 TypeRegistry typeRegistry = TypeRegistry::Get();
776 // Check property count before property registration
777 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
778 DALI_TEST_CHECK( typeInfo );
779 BaseHandle handle = typeInfo.CreateInstance();
780 DALI_TEST_CHECK( handle );
781 Actor customActor = Actor::DownCast( handle );
782 DALI_TEST_CHECK( customActor );
783 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
785 std::string propertyName( "prop-1" );
786 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
787 Property::Type propertyType( Property::BOOLEAN );
788 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
790 // Check property count after registration
791 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
792 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
794 // Add custom property and check property count
795 customActor.RegisterProperty( "custom-prop-1", true );
796 unsigned int customPropertyCount( customActor.GetPropertyCount() );
797 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
799 // Set the property, ensure SetProperty called
800 DALI_TEST_CHECK( !setPropertyCalled );
801 customActor.SetProperty( propertyIndex, false );
802 DALI_TEST_CHECK( setPropertyCalled );
804 // Get the property, ensure GetProperty called
805 DALI_TEST_CHECK( !getPropertyCalled );
806 (void)customActor.GetProperty< bool >( propertyIndex );
807 DALI_TEST_CHECK( getPropertyCalled );
809 // Check the property name
810 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
811 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
813 // Check the property index
814 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
816 // Check the property type
817 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
819 // Check property count of type-info is 1
820 Property::IndexContainer indices;
821 typeInfo.GetPropertyIndices( indices );
822 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
824 // Ensure indices returned from actor and customActor differ by two
825 Actor actor = Actor::New();
826 actor.GetPropertyIndices( indices );
827 unsigned int actorIndices = indices.size();
828 customActor.GetPropertyIndices( indices );
829 unsigned int customActorIndices = indices.size();
830 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
834 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
836 TestApplication application;
837 TypeRegistry typeRegistry = TypeRegistry::Get();
839 // Attempt to register a property type out-of-bounds index (less than)
842 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
843 tet_result( TET_FAIL );
845 catch ( DaliException& e )
847 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
850 // Attempt to register a property type out-of-bounds index (greater than)
853 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
854 tet_result( TET_FAIL );
856 catch ( DaliException& e )
858 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
863 int UtcDaliPropertyRegistrationFunctions(void)
865 TestApplication application;
866 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
868 // Attempt to register a property without a setter
871 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
872 tet_result( TET_PASS );
874 catch ( DaliException& e )
876 tet_result( TET_FAIL );
879 // Attempt to register a property without a getter
882 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
883 tet_result( TET_FAIL );
885 catch ( DaliException& e )
887 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
892 int UtcDaliPropertyRegistrationAddSameIndex(void)
894 TestApplication application;
895 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
897 // Add one property with a valid property index
898 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
900 // Attempt to add another property with the same index
903 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
905 catch ( DaliException& e )
907 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
912 int UtcDaliPropertyRegistrationPropertyWritable(void)
914 TestApplication application;
915 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
916 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
918 // Add two properties, one with SetProperty, one without
919 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
920 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
922 // Create custom-actor
923 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
924 DALI_TEST_CHECK( typeInfo );
925 BaseHandle handle = typeInfo.CreateInstance();
926 DALI_TEST_CHECK( handle );
927 Actor customActor = Actor::DownCast( handle );
928 DALI_TEST_CHECK( customActor );
930 // Check whether properties are writable
931 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
932 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
936 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
938 TestApplication application;
939 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
941 // These properties are not animatable
942 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
944 // Create custom-actor
945 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
946 DALI_TEST_CHECK( typeInfo );
947 BaseHandle handle = typeInfo.CreateInstance();
948 DALI_TEST_CHECK( handle );
949 Actor customActor = Actor::DownCast( handle );
950 DALI_TEST_CHECK( customActor );
952 // Check if animatable
953 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
957 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
959 TestApplication application;
960 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
962 // Create custom-actor
963 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
964 DALI_TEST_CHECK( typeInfo );
965 BaseHandle handle = typeInfo.CreateInstance();
966 DALI_TEST_CHECK( handle );
967 Actor customActor = Actor::DownCast( handle );
968 DALI_TEST_CHECK( customActor );
970 // Try to set an index that hasn't been added
973 customActor.SetProperty( propertyIndex, true );
974 tet_result( TET_FAIL );
976 catch ( DaliException& e )
978 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
981 // Try to get an index that hasn't been added
984 (void) customActor.GetProperty< bool >( propertyIndex );
985 tet_result( TET_FAIL );
987 catch ( DaliException& e )
989 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
996 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
998 TestApplication application;
1000 Actor actor = Actor::New();
1001 actor.SetSize(100.0f, 100.0f);
1002 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1003 Stage::GetCurrent().Add(actor);
1007 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1008 DALI_TEST_CHECK( type );
1009 BaseHandle handle = type.CreateInstance();
1010 DALI_TEST_CHECK( handle );
1011 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1012 DALI_TEST_CHECK( detector );
1014 // Attach actor to detector
1016 GestureReceivedFunctor functor( data );
1017 detector.Attach(actor);
1019 // Connect to signal through type
1020 handle.ConnectSignal( &application, "long-press-detected", functor );
1022 // Render and notify
1023 application.SendNotification();
1024 application.Render();
1027 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1028 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1029 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1030 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1034 int UtcDaliPanGestureDetectorTypeRegistry(void)
1036 TestApplication application;
1038 Actor actor = Actor::New();
1039 actor.SetSize(100.0f, 100.0f);
1040 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1041 Stage::GetCurrent().Add(actor);
1045 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1046 DALI_TEST_CHECK( type );
1047 BaseHandle handle = type.CreateInstance();
1048 DALI_TEST_CHECK( handle );
1049 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1050 DALI_TEST_CHECK( detector );
1052 // Attach actor to detector
1054 GestureReceivedFunctor functor( data );
1055 detector.Attach(actor);
1057 // Connect to signal through type
1058 handle.ConnectSignal( &application, "pan-detected", functor );
1060 // Render and notify
1061 application.SendNotification();
1062 application.Render();
1065 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1066 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1067 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1068 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1072 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1074 TestApplication application;
1076 Actor actor = Actor::New();
1077 actor.SetSize(100.0f, 100.0f);
1078 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1079 Stage::GetCurrent().Add(actor);
1083 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1084 DALI_TEST_CHECK( type );
1085 BaseHandle handle = type.CreateInstance();
1086 DALI_TEST_CHECK( handle );
1087 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1088 DALI_TEST_CHECK( detector );
1090 // Attach actor to detector
1092 GestureReceivedFunctor functor( data );
1093 detector.Attach(actor);
1095 // Connect to signal through type
1096 handle.ConnectSignal( &application, "pinch-detected", functor );
1098 // Render and notify
1099 application.SendNotification();
1100 application.Render();
1103 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1104 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1108 int UtcDaliTapGestureDetectorTypeRegistry(void)
1110 TestApplication application;
1112 Actor actor = Actor::New();
1113 actor.SetSize(100.0f, 100.0f);
1114 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1115 Stage::GetCurrent().Add(actor);
1119 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1120 DALI_TEST_CHECK( type );
1121 BaseHandle handle = type.CreateInstance();
1122 DALI_TEST_CHECK( handle );
1123 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1124 DALI_TEST_CHECK( detector );
1126 // Attach actor to detector
1128 GestureReceivedFunctor functor( data );
1129 detector.Attach(actor);
1131 // Connect to signal through type
1132 handle.ConnectSignal( &application, "tap-detected", functor );
1134 // Render and notify
1135 application.SendNotification();
1136 application.Render();
1139 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1140 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1141 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1145 int UtcDaliTypeRegistryNamedType(void)
1147 TestApplication application;
1148 TypeRegistry typeRegistry = TypeRegistry::Get();
1150 // Create a normal actor
1151 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1152 DALI_TEST_CHECK( actorHandle );
1153 Actor actor( Actor::DownCast( actorHandle ) );
1154 DALI_TEST_CHECK( actor );
1155 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1157 // Create Named Actor Type
1158 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1159 DALI_TEST_CHECK( namedHandle );
1160 Actor namedActor( Actor::DownCast( namedHandle ) );
1161 DALI_TEST_CHECK( namedActor );
1162 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1164 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );