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>
34 // Stores data that is populated in the callback and will be read by the Test cases
38 : functorCalled( false ),
39 voidFunctorCalled( false ),
40 receivedGesture( Gesture::Clear ),
46 functorCalled = false;
47 voidFunctorCalled = false;
49 receivedGesture.numberOfTouches = 0u;
50 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
51 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
57 bool voidFunctorCalled;
58 LongPressGesture receivedGesture;
62 // Functor that sets the data when called
63 struct GestureReceivedFunctor
65 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
67 void operator()(Actor actor, LongPressGesture longPress)
69 signalData.functorCalled = true;
70 signalData.receivedGesture = longPress;
71 signalData.pressedActor = actor;
76 signalData.voidFunctorCalled = true;
79 SignalData& signalData;
82 // Generate a LongPressGestureEvent to send to Core
83 Integration::LongPressGestureEvent GenerateLongPress(
85 unsigned int numberOfTouches,
88 Integration::LongPressGestureEvent longPress( state );
90 longPress.numberOfTouches = numberOfTouches;
91 longPress.point = point;
96 // Generate a PanGestureEvent to send to Core
97 Integration::PanGestureEvent GeneratePan(
99 Vector2 previousPosition,
100 Vector2 currentPosition,
101 unsigned long timeDelta,
102 unsigned int numberOfTouches = 1,
103 unsigned int time = 1u)
105 Integration::PanGestureEvent pan(state);
107 pan.previousPosition = previousPosition;
108 pan.currentPosition = currentPosition;
109 pan.timeDelta = timeDelta;
110 pan.numberOfTouches = numberOfTouches;
115 // Generate a PinchGestureEvent to send to Core
116 Integration::PinchGestureEvent GeneratePinch(
117 Gesture::State state,
122 Integration::PinchGestureEvent pinch(state);
126 pinch.centerPoint = centerpoint;
130 // Generate a TapGestureEvent to send to Core
131 Integration::TapGestureEvent GenerateTap(
132 Gesture::State state,
133 unsigned int numberOfTaps,
134 unsigned int numberOfTouches,
137 Integration::TapGestureEvent tap( state );
139 tap.numberOfTaps = numberOfTaps;
140 tap.numberOfTouches = numberOfTouches;
147 // Create function as Init function called
149 static bool CreateCustomInitCalled = false;
150 BaseHandle CreateCustomInit(void)
152 CreateCustomInitCalled = true;
156 static bool CreateCustomNamedInitCalled = false;
157 BaseHandle CreateCustomNamedInit(void)
159 CreateCustomNamedInitCalled = true;
163 const std::string scriptedName("PopupStyle");
164 static TypeRegistration scriptedType( scriptedName, typeid(Dali::CustomActor), CreateCustomNamedInit );
166 // Property Registration
167 bool setPropertyCalled = false;
168 bool getPropertyCalled = false;
169 void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
171 setPropertyCalled = true;
173 Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex )
175 getPropertyCalled = true;
176 return Property::Value( true );
181 /*******************************************************************************
185 ******************************************************************************/
188 struct MyTestCustomActor : public CustomActorImpl
190 typedef SignalV2< void ()> SignalType;
191 typedef SignalV2< void (float)> SignalTypeFloat;
193 MyTestCustomActor() : CustomActorImpl( true ) // requires touch
196 virtual ~MyTestCustomActor()
199 void ResetCallStack()
203 // From CustomActorImpl
204 virtual void OnStageConnection()
207 virtual void OnStageDisconnection()
210 virtual void OnChildAdd(Actor& child)
213 virtual void OnChildRemove(Actor& child)
216 virtual void OnSizeSet(const Vector3& targetSize)
219 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
222 virtual bool OnTouchEvent(const TouchEvent& event)
226 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
230 virtual bool OnKeyEvent(const KeyEvent& event)
234 virtual void OnKeyInputFocusGained()
237 virtual void OnKeyInputFocusLost()
240 virtual Actor GetChildByAlias(const std::string& actorAlias)
252 class MyTestCustomActor : public CustomActor
256 typedef SignalV2< void ()> SignalType;
257 typedef SignalV2< void (float)> SignalTypeFloat;
263 static MyTestCustomActor New()
265 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
266 return MyTestCustomActor( *p ); // takes ownership
269 virtual ~MyTestCustomActor()
273 static MyTestCustomActor DownCast( BaseHandle handle )
275 MyTestCustomActor result;
277 CustomActor custom = Dali::CustomActor::DownCast( handle );
280 CustomActorImpl& customImpl = custom.GetImplementation();
282 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
286 result = MyTestCustomActor(customImpl.GetOwner());
293 SignalType& GetCustomSignal()
295 Dali::RefObject& obj = GetImplementation();
296 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
301 MyTestCustomActor(Internal::CustomActor* internal)
302 : CustomActor(internal)
306 MyTestCustomActor( Impl::MyTestCustomActor& impl )
307 : CustomActor( impl )
313 class MyTestCustomActor2 : public CustomActor
321 static MyTestCustomActor2 New()
323 return MyTestCustomActor2(); // takes ownership
326 virtual ~MyTestCustomActor2()
330 static MyTestCustomActor2 DownCast( BaseHandle handle )
332 MyTestCustomActor2 result;
334 CustomActor custom = Dali::CustomActor::DownCast( handle );
337 CustomActorImpl& customImpl = custom.GetImplementation();
339 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
343 result = MyTestCustomActor2(customImpl.GetOwner());
352 MyTestCustomActor2(Internal::CustomActor* internal)
353 : CustomActor(internal)
357 MyTestCustomActor2( Impl::MyTestCustomActor& impl )
358 : CustomActor( impl )
363 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
366 BaseHandle CreateCustom(void)
368 return MyTestCustomActor::New();
371 static std::string lastSignalConnectionCustom;
373 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
375 lastSignalConnectionCustom = signalName;
377 bool connected( true );
379 Dali::BaseHandle handle(object);
380 MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
382 if( "sig1" == signalName )
384 customActor.GetCustomSignal().Connect( tracker, functor );
388 // signalName does not match any signal
395 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
397 lastSignalConnectionCustom = "failed";
399 return false; // This is supposed to fail
402 struct CustomTestFunctor
406 ++mTotalInstanceCount;
407 ++mCurrentInstanceCount;
410 CustomTestFunctor( const CustomTestFunctor& copyMe )
412 ++mTotalInstanceCount;
413 ++mCurrentInstanceCount;
418 --mCurrentInstanceCount;
426 static int mTotalInstanceCount;
427 static int mCurrentInstanceCount;
428 static int mCallbackCount;
431 int CustomTestFunctor::mTotalInstanceCount = 0;
432 int CustomTestFunctor::mCurrentInstanceCount = 0;
433 int CustomTestFunctor::mCallbackCount = 0;
435 static void ResetFunctorCounts()
437 CustomTestFunctor::mTotalInstanceCount = 0;
438 CustomTestFunctor::mCurrentInstanceCount = 0;
439 CustomTestFunctor::mCallbackCount = 0;
442 static std::string lastActionCustom;
443 bool DoActionCustom(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
445 lastActionCustom = actionName;
449 // Custom type registration
450 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
453 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
454 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
455 static const int TEST_SIGNAL_COUNT = 2;
458 static TypeAction customAction1( customType1, "act1", DoActionCustom);
459 static const int TEST_ACTION_COUNT = 1;
461 class TestConnectionTracker : public ConnectionTracker
465 TestConnectionTracker()
470 BaseHandle CreateNamedActorType()
472 Actor actor = Actor::New();
473 actor.SetName( "NamedActor" );
477 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
478 PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
480 } // Anonymous namespace
483 // Positive test case for a method
484 int UtcDaliTypeRegistryCreateDaliObjects(void)
486 TestApplication application;
488 TypeRegistry registry; // like this for ctor test coverage
489 registry = TypeRegistry::Get();
493 type = registry.GetTypeInfo( "ImageActor" );
494 DALI_TEST_CHECK( type );
495 DALI_TEST_CHECK( type.GetCreator() );
496 DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
497 ImageActor ia = ImageActor::DownCast(type.CreateInstance());
498 DALI_TEST_CHECK( ia );
499 Stage::GetCurrent().Add( ia );
500 application.Render();
502 type = registry.GetTypeInfo( "TextActor" );
503 DALI_TEST_CHECK( type );
504 TextActor ta = TextActor::DownCast(type.CreateInstance());
505 DALI_TEST_CHECK( ta );
506 Stage::GetCurrent().Add( ta );
507 application.Render();
509 type = registry.GetTypeInfo( "CameraActor" );
510 DALI_TEST_CHECK( type );
511 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
512 DALI_TEST_CHECK( ca );
513 Stage::GetCurrent().Add( ca );
514 application.Render();
516 type = registry.GetTypeInfo( "LightActor" );
517 DALI_TEST_CHECK( type );
518 LightActor la = LightActor::DownCast(type.CreateInstance());
519 DALI_TEST_CHECK( la );
520 Stage::GetCurrent().Add( la );
521 application.Render();
524 type = registry.GetTypeInfo( "Animation" );
525 DALI_TEST_CHECK( type );
526 Animation an = Animation::DownCast(type.CreateInstance());
527 DALI_TEST_CHECK( an );
529 application.Render();
532 type = registry.GetTypeInfo( "ShaderEffect" );
533 DALI_TEST_CHECK( type );
534 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
535 DALI_TEST_CHECK( ef );
536 application.Render();
541 /*******************************************************************************
543 * Action through the base handle
545 ******************************************************************************/
546 int UtcDaliTypeRegistryActionViaBaseHandle(void)
548 TestApplication application;
552 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
553 DALI_TEST_CHECK( type );
555 BaseHandle hdl = type.CreateInstance();
556 DALI_TEST_CHECK( hdl );
558 Actor a = Actor::DownCast(hdl);
559 DALI_TEST_CHECK( a );
563 application.SendNotification();
564 application.Render(0);
565 DALI_TEST_CHECK(!a.IsVisible());
567 std::vector<Property::Value> attributes;
569 DALI_TEST_CHECK(hdl.DoAction(Actor::ACTION_SHOW, attributes));
571 application.SendNotification();
572 application.Render(0);
573 DALI_TEST_CHECK(a.IsVisible());
575 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
579 int UtcDaliTypeRegistryNames(void)
581 TestApplication application;
585 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
587 for(TypeRegistry::NameContainer::iterator iter = names.begin();
588 iter != names.end(); ++iter)
590 type = TypeRegistry::Get().GetTypeInfo( *iter );
591 DALI_TEST_CHECK( type );
597 // Check named and typeid are equivalent
598 int UtcDaliTypeRegistryNameEquivalence(void)
600 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "TextActor" );
601 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::TextActor) );
603 DALI_TEST_CHECK( named_type );
604 DALI_TEST_CHECK( typeinfo_type );
606 DALI_TEST_CHECK( named_type == typeinfo_type );
608 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
609 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
615 int UtcDaliTypeRegistryCustomActor(void)
617 ResetFunctorCounts();
619 TestApplication application;
621 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
622 DALI_TEST_CHECK( type );
624 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
625 DALI_TEST_CHECK( baseType );
627 BaseHandle handle = type.CreateInstance();
628 DALI_TEST_CHECK( handle );
630 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
631 DALI_TEST_CHECK( customHandle );
633 DALI_TEST_EQUALS( type.GetActions().size(), TEST_ACTION_COUNT + baseType.GetActions().size(), TEST_LOCATION );
634 DALI_TEST_EQUALS( type.GetSignals().size(), TEST_SIGNAL_COUNT + baseType.GetSignals().size(), TEST_LOCATION );
637 TestConnectionTracker tracker;
639 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
640 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
641 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
642 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
643 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
645 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
646 customHandle.GetCustomSignal().Emit();
647 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
648 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
649 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
651 // tracker should automatically disconnect here
652 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
653 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
655 // Test that functor is disconnected
656 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
657 customHandle.GetCustomSignal().Emit();
658 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
659 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
660 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
662 std::vector<Property::Value> attributes;
663 handle.DoAction("act1", attributes);
664 DALI_TEST_CHECK( lastActionCustom == "act1" );
668 int UtcDaliTypeRegistryCustomSignalFailure(void)
670 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
672 ResetFunctorCounts();
674 TestApplication application;
676 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
677 DALI_TEST_CHECK( type );
679 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
680 DALI_TEST_CHECK( baseType );
682 BaseHandle handle = type.CreateInstance();
683 DALI_TEST_CHECK( handle );
685 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
686 DALI_TEST_CHECK( customHandle );
688 DALI_TEST_EQUALS( type.GetActions().size(), TEST_ACTION_COUNT + baseType.GetActions().size(), TEST_LOCATION );
689 DALI_TEST_EQUALS( type.GetSignals().size(), TEST_SIGNAL_COUNT + baseType.GetSignals().size(), TEST_LOCATION );
692 TestConnectionTracker tracker;
694 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
695 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
696 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
697 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
698 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
701 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
702 customHandle.GetCustomSignal().Emit();
703 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
705 // tracker should have nothing to disconnect here
708 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
709 customHandle.GetCustomSignal().Emit();
710 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
716 int UtcDaliTypeRegistryInitFunctions(void)
718 TestApplication application;
720 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
722 DALI_TEST_CHECK( true == CreateCustomInitCalled );
723 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
724 DALI_TEST_CHECK( type );
731 int UtcDaliTypeRegistryNameInitFunctions(void)
733 TestApplication application;
735 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
737 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
738 DALI_TEST_CHECK( baseType );
740 BaseHandle handle = baseType.CreateInstance();
742 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
743 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
744 DALI_TEST_CHECK( type );
749 int UtcDaliPropertyRegistration(void)
751 TestApplication application;
752 TypeRegistry typeRegistry = TypeRegistry::Get();
754 // Check property count before property registration
755 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
756 DALI_TEST_CHECK( typeInfo );
757 BaseHandle handle = typeInfo.CreateInstance();
758 DALI_TEST_CHECK( handle );
759 Actor customActor = Actor::DownCast( handle );
760 DALI_TEST_CHECK( customActor );
761 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
763 std::string propertyName( "prop-1" );
764 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
765 Property::Type propertyType( Property::BOOLEAN );
766 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
768 // Check property count after registration
769 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
770 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
772 // Add custom property and check property count
773 customActor.RegisterProperty( "custom-prop-1", true );
774 unsigned int customPropertyCount( customActor.GetPropertyCount() );
775 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
777 // Set the property, ensure SetProperty called
778 DALI_TEST_CHECK( !setPropertyCalled );
779 customActor.SetProperty( propertyIndex, false );
780 DALI_TEST_CHECK( setPropertyCalled );
782 // Get the property, ensure GetProperty called
783 DALI_TEST_CHECK( !getPropertyCalled );
784 (void)customActor.GetProperty< bool >( propertyIndex );
785 DALI_TEST_CHECK( getPropertyCalled );
787 // Check the property name
788 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
789 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
791 // Check the property index
792 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
794 // Check the property type
795 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
797 // Check property count of type-info is 1
798 Property::IndexContainer indices;
799 typeInfo.GetPropertyIndices( indices );
800 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
802 // Ensure indices returned from actor and customActor differ by two
803 Actor actor = Actor::New();
804 actor.GetPropertyIndices( indices );
805 unsigned int actorIndices = indices.size();
806 customActor.GetPropertyIndices( indices );
807 unsigned int customActorIndices = indices.size();
808 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
812 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
814 TestApplication application;
815 TypeRegistry typeRegistry = TypeRegistry::Get();
817 // Attempt to register a property type out-of-bounds index (less than)
820 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
821 tet_result( TET_FAIL );
823 catch ( DaliException& e )
825 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
828 // Attempt to register a property type out-of-bounds index (greater than)
831 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
832 tet_result( TET_FAIL );
834 catch ( DaliException& e )
836 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
841 int UtcDaliPropertyRegistrationFunctions(void)
843 TestApplication application;
844 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
846 // Attempt to register a property without a setter
849 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
850 tet_result( TET_PASS );
852 catch ( DaliException& e )
854 tet_result( TET_FAIL );
857 // Attempt to register a property without a getter
860 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
861 tet_result( TET_FAIL );
863 catch ( DaliException& e )
865 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
870 int UtcDaliPropertyRegistrationAddSameIndex(void)
872 TestApplication application;
873 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
875 // Add one property with a valid property index
876 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
878 // Attempt to add another property with the same index
881 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
883 catch ( DaliException& e )
885 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
890 int UtcDaliPropertyRegistrationPropertyWritable(void)
892 TestApplication application;
893 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
894 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
896 // Add two properties, one with SetProperty, one without
897 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
898 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
900 // Create custom-actor
901 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
902 DALI_TEST_CHECK( typeInfo );
903 BaseHandle handle = typeInfo.CreateInstance();
904 DALI_TEST_CHECK( handle );
905 Actor customActor = Actor::DownCast( handle );
906 DALI_TEST_CHECK( customActor );
908 // Check whether properties are writable
909 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
910 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
914 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
916 TestApplication application;
917 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
919 // These properties are not animatable
920 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &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 if animatable
931 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
935 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
937 TestApplication application;
938 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
940 // Create custom-actor
941 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
942 DALI_TEST_CHECK( typeInfo );
943 BaseHandle handle = typeInfo.CreateInstance();
944 DALI_TEST_CHECK( handle );
945 Actor customActor = Actor::DownCast( handle );
946 DALI_TEST_CHECK( customActor );
948 // Try to set an index that hasn't been added
951 customActor.SetProperty( propertyIndex, true );
952 tet_result( TET_FAIL );
954 catch ( DaliException& e )
956 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
959 // Try to get an index that hasn't been added
962 (void) customActor.GetProperty< bool >( propertyIndex );
963 tet_result( TET_FAIL );
965 catch ( DaliException& e )
967 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
974 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
976 TestApplication application;
978 Actor actor = Actor::New();
979 actor.SetSize(100.0f, 100.0f);
980 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
981 Stage::GetCurrent().Add(actor);
985 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
986 DALI_TEST_CHECK( type );
987 BaseHandle handle = type.CreateInstance();
988 DALI_TEST_CHECK( handle );
989 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
990 DALI_TEST_CHECK( detector );
992 // Attach actor to detector
994 GestureReceivedFunctor functor( data );
995 detector.Attach(actor);
997 // Connect to signal through type
998 handle.ConnectSignal( &application, LongPressGestureDetector::SIGNAL_LONG_PRESS_DETECTED, functor );
1000 // Render and notify
1001 application.SendNotification();
1002 application.Render();
1005 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1006 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1007 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1008 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1012 int UtcDaliPanGestureDetectorTypeRegistry(void)
1014 TestApplication application;
1016 Actor actor = Actor::New();
1017 actor.SetSize(100.0f, 100.0f);
1018 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1019 Stage::GetCurrent().Add(actor);
1023 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1024 DALI_TEST_CHECK( type );
1025 BaseHandle handle = type.CreateInstance();
1026 DALI_TEST_CHECK( handle );
1027 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1028 DALI_TEST_CHECK( detector );
1030 // Attach actor to detector
1032 GestureReceivedFunctor functor( data );
1033 detector.Attach(actor);
1035 // Connect to signal through type
1036 handle.ConnectSignal( &application, PanGestureDetector::SIGNAL_PAN_DETECTED, functor );
1038 // Render and notify
1039 application.SendNotification();
1040 application.Render();
1043 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1044 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1045 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1046 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1050 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1052 TestApplication application;
1054 Actor actor = Actor::New();
1055 actor.SetSize(100.0f, 100.0f);
1056 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1057 Stage::GetCurrent().Add(actor);
1061 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1062 DALI_TEST_CHECK( type );
1063 BaseHandle handle = type.CreateInstance();
1064 DALI_TEST_CHECK( handle );
1065 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1066 DALI_TEST_CHECK( detector );
1068 // Attach actor to detector
1070 GestureReceivedFunctor functor( data );
1071 detector.Attach(actor);
1073 // Connect to signal through type
1074 handle.ConnectSignal( &application, PinchGestureDetector::SIGNAL_PINCH_DETECTED, functor );
1076 // Render and notify
1077 application.SendNotification();
1078 application.Render();
1081 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1082 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1086 int UtcDaliTapGestureDetectorTypeRegistry(void)
1088 TestApplication application;
1090 Actor actor = Actor::New();
1091 actor.SetSize(100.0f, 100.0f);
1092 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1093 Stage::GetCurrent().Add(actor);
1097 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1098 DALI_TEST_CHECK( type );
1099 BaseHandle handle = type.CreateInstance();
1100 DALI_TEST_CHECK( handle );
1101 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1102 DALI_TEST_CHECK( detector );
1104 // Attach actor to detector
1106 GestureReceivedFunctor functor( data );
1107 detector.Attach(actor);
1109 // Connect to signal through type
1110 handle.ConnectSignal( &application, TapGestureDetector::SIGNAL_TAP_DETECTED, functor );
1112 // Render and notify
1113 application.SendNotification();
1114 application.Render();
1117 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1118 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1119 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1123 int UtcDaliTypeRegistryNamedType(void)
1125 TestApplication application;
1126 TypeRegistry typeRegistry = TypeRegistry::Get();
1128 // Create a normal actor
1129 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1130 DALI_TEST_CHECK( actorHandle );
1131 Actor actor( Actor::DownCast( actorHandle ) );
1132 DALI_TEST_CHECK( actor );
1133 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1135 // Create Named Actor Type
1136 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1137 DALI_TEST_CHECK( namedHandle );
1138 Actor namedActor( Actor::DownCast( namedHandle ) );
1139 DALI_TEST_CHECK( namedActor );
1140 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1142 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );